Add stateful and stateless enterprise selection
This commit is contained in:
1 parent
d383b3aad8
commit
0959cef1cc
22 files changed
+609
-187
No files matched your search
+86
-3
@@ -1,16 +1,26 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { afterEach, describe, expect, test } from "bun:test";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { VERSION } from "./version.js";
|
||||
|
||||
const CLI_PATH = join(import.meta.dirname, "cli.ts");
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
function runCli(args: string[]) {
|
||||
function runCli(args: string[], env: Record<string, string> = {}) {
|
||||
return spawnSync("bun", [CLI_PATH, ...args], {
|
||||
encoding: "utf-8"
|
||||
encoding: "utf-8",
|
||||
env: { ...process.env, ...env }
|
||||
});
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
for (const dir of tempDirs.splice(0)) {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
describe("CLI version & help handling", () => {
|
||||
test.each([
|
||||
["version"],
|
||||
@@ -46,4 +56,77 @@ describe("CLI version & help handling", () => {
|
||||
expect(result.status).toBe(1);
|
||||
expect(result.stderr).toContain("Unknown command: invalid-command. Run 'seal-home help' for available commands.");
|
||||
});
|
||||
|
||||
test("requires --corp in the default stateless mode", () => {
|
||||
const env = makeConfigEnv();
|
||||
const result = runCli(["corps", "current"], env);
|
||||
|
||||
expect(result.status).toBe(1);
|
||||
expect(result.stderr).toContain("Stateless mode is enabled");
|
||||
expect(result.stderr).toContain("--corp <corpId>");
|
||||
});
|
||||
|
||||
test("allows an explicit corp in stateless mode", () => {
|
||||
const env = makeConfigEnv();
|
||||
const result = runCli(["corps", "current", "--corp", "corp-a"], env);
|
||||
|
||||
expect(result.status).toBe(0);
|
||||
expect(JSON.parse(result.stdout)).toMatchObject({ id: "corp-a" });
|
||||
});
|
||||
|
||||
test("keeps the fine-grained tool command reachable in stateless mode", () => {
|
||||
const env = makeConfigEnv();
|
||||
const result = runCli(["tool", "unknown-tool", "--corp", "corp-a"], env);
|
||||
|
||||
expect(result.status).toBe(1);
|
||||
expect(result.stderr).toContain("Unknown Seal tool: unknown-tool");
|
||||
});
|
||||
|
||||
test("can enable stateful mode and select a default corp", () => {
|
||||
const env = makeConfigEnv();
|
||||
const mode = runCli(["config", "mode", "stateful", "--corp", "corp-a"], env);
|
||||
const current = runCli(["corps", "current"], env);
|
||||
|
||||
expect(mode.status).toBe(0);
|
||||
expect(JSON.parse(mode.stdout)).toMatchObject({
|
||||
mode: "stateful",
|
||||
defaultCorpId: "corp-a"
|
||||
});
|
||||
expect(current.status).toBe(0);
|
||||
expect(JSON.parse(current.stdout)).toMatchObject({ id: "corp-a" });
|
||||
});
|
||||
|
||||
test("removes the default when switching back to stateless mode", () => {
|
||||
const env = makeConfigEnv();
|
||||
runCli(["config", "mode", "stateful", "--corp", "corp-a"], env);
|
||||
|
||||
const mode = runCli(["config", "mode", "stateless"], env);
|
||||
const current = runCli(["corps", "current"], env);
|
||||
|
||||
expect(mode.status).toBe(0);
|
||||
expect(JSON.parse(mode.stdout)).toMatchObject({ mode: "stateless" });
|
||||
expect(JSON.parse(mode.stdout)).not.toHaveProperty("defaultCorpId");
|
||||
expect(current.status).toBe(1);
|
||||
expect(current.stderr).toContain("Stateless mode is enabled");
|
||||
});
|
||||
});
|
||||
|
||||
function makeConfigEnv(): Record<string, string> {
|
||||
const root = mkdtempSync(join(tmpdir(), "seal-home-cli-"));
|
||||
tempDirs.push(root);
|
||||
const enterprises = join(root, "enterprises");
|
||||
mkdirSync(enterprises, { recursive: true });
|
||||
writeFileSync(join(enterprises, "corp-a.json"), JSON.stringify({
|
||||
id: "corp-a",
|
||||
name: "Corp A",
|
||||
source: {
|
||||
type: "direct",
|
||||
token: "seal-token",
|
||||
sealUrl: "https://corp-a.seal.test"
|
||||
}
|
||||
}));
|
||||
return {
|
||||
SEAL_HOME_ENTERPRISES_DIR: enterprises,
|
||||
SEAL_HOME_CONFIG_FILE: join(root, "config.json")
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user