From 0534651e0aecd129fb57abc15e82204be236e2dc Mon Sep 17 00:00:00 2001 From: yunyingk Date: Fri, 11 Sep 2026 10:05:19 +0800 Subject: [PATCH] Refine runner test for domain unknown subcommands --- src/cli/runner.test.ts | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/cli/runner.test.ts b/src/cli/runner.test.ts index 0262c06..1719108 100644 --- a/src/cli/runner.test.ts +++ b/src/cli/runner.test.ts @@ -1,3 +1,6 @@ +import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; import { describe, expect, test } from "bun:test"; import { runCli } from "./runner.js"; @@ -29,11 +32,37 @@ describe("CLI runner", () => { expect(result.stderr).toContain("Invalid JSON:"); }); - test("returns usage exit code 2 for unknown subcommands across domains", async () => { - const result = await runCli(["contacts", "not-a-subcommand"]); + test("returns usage exit code 2 for unknown subcommands across standalone domains", async () => { + const result = await runCli(["skill", "not-a-subcommand"]); expect(result.isError).toBe(true); expect(result.exitCode).toBe(2); - expect(result.stderr).toContain("Unknown contacts command: not-a-subcommand"); + expect(result.stderr).toContain("Unknown skill command: not-a-subcommand"); + }); + + test("returns usage exit code 2 for unknown subcommands with an active enterprise", async () => { + const tempDir = mkdtempSync(join(tmpdir(), "seal-use-runner-test-")); + const originalEnv = process.env.SEAL_USE_ENTERPRISES_DIR; + try { + process.env.SEAL_USE_ENTERPRISES_DIR = tempDir; + writeFileSync( + join(tempDir, "test.json"), + JSON.stringify({ + id: "test", + name: "Test Corp", + source: { type: "seal", token: "dummy-token", sealUrl: "https://test.sealai.cc" }, + seal: { url: "https://test.sealai.cc" } + }) + ); + + const result = await runCli(["contacts", "not-a-subcommand", "--corp", "test"]); + expect(result.isError).toBe(true); + expect(result.exitCode).toBe(2); + expect(result.stderr).toContain("Unknown contacts command: not-a-subcommand"); + } finally { + if (originalEnv === undefined) delete process.env.SEAL_USE_ENTERPRISES_DIR; + else process.env.SEAL_USE_ENTERPRISES_DIR = originalEnv; + rmSync(tempDir, { recursive: true, force: true }); + } }); });