diff --git a/src/cli/program/preaction.test.ts b/src/cli/program/preaction.test.ts index d85d48d9bd0..ec8ce0a848f 100644 --- a/src/cli/program/preaction.test.ts +++ b/src/cli/program/preaction.test.ts @@ -74,38 +74,38 @@ afterEach(() => { describe("registerPreActionHooks", () => { function buildProgram() { const program = new Command().name("openclaw"); - program.command("status").action(async () => {}); - program.command("doctor").action(async () => {}); - program.command("completion").action(async () => {}); - program.command("secrets").action(async () => {}); + program.command("status").action(() => {}); + program.command("doctor").action(() => {}); + program.command("completion").action(() => {}); + program.command("secrets").action(() => {}); program .command("update") .command("status") .option("--json") - .action(async () => {}); + .action(() => {}); const config = program.command("config"); config .command("set") .argument("") .argument("") .option("--json") - .action(async () => {}); - program.command("channels").action(async () => {}); - program.command("directory").action(async () => {}); - program.command("agents").action(async () => {}); - program.command("configure").action(async () => {}); - program.command("onboard").action(async () => {}); + .action(() => {}); + program.command("agents").action(() => {}); + program.command("configure").action(() => {}); + program.command("onboard").action(() => {}); program .command("message") .command("send") .option("--json") - .action(async () => {}); + .action(() => {}); registerPreActionHooks(program, "9.9.9-test"); return program; } - async function runCommand(params: { parseArgv: string[]; processArgv?: string[] }) { - const program = buildProgram(); + async function runCommand( + params: { parseArgv: string[]; processArgv?: string[] }, + program = buildProgram(), + ) { process.argv = params.processArgv ?? [...params.parseArgv]; await program.parseAsync(params.parseArgv, { from: "user" }); } @@ -143,29 +143,43 @@ describe("registerPreActionHooks", () => { it("loads plugin registry for configure/onboard/agents commands", async () => { const commands = ["configure", "onboard", "agents"] as const; + const program = buildProgram(); for (const command of commands) { vi.clearAllMocks(); - await runCommand({ - parseArgv: [command], - processArgv: ["node", "openclaw", command], - }); + await runCommand( + { + parseArgv: [command], + processArgv: ["node", "openclaw", command], + }, + program, + ); expect(ensurePluginRegistryLoadedMock, command).toHaveBeenCalledTimes(1); } }); it("skips config guard for doctor, completion, and secrets commands", async () => { - await runCommand({ - parseArgv: ["doctor"], - processArgv: ["node", "openclaw", "doctor"], - }); - await runCommand({ - parseArgv: ["completion"], - processArgv: ["node", "openclaw", "completion"], - }); - await runCommand({ - parseArgv: ["secrets"], - processArgv: ["node", "openclaw", "secrets"], - }); + const program = buildProgram(); + await runCommand( + { + parseArgv: ["doctor"], + processArgv: ["node", "openclaw", "doctor"], + }, + program, + ); + await runCommand( + { + parseArgv: ["completion"], + processArgv: ["node", "openclaw", "completion"], + }, + program, + ); + await runCommand( + { + parseArgv: ["secrets"], + processArgv: ["node", "openclaw", "secrets"], + }, + program, + ); expect(ensureConfigReadyMock).not.toHaveBeenCalled(); }); @@ -193,10 +207,14 @@ describe("registerPreActionHooks", () => { }); it("suppresses doctor stdout for any --json output command", async () => { - await runCommand({ - parseArgv: ["message", "send", "--json"], - processArgv: ["node", "openclaw", "message", "send", "--json"], - }); + const program = buildProgram(); + await runCommand( + { + parseArgv: ["message", "send", "--json"], + processArgv: ["node", "openclaw", "message", "send", "--json"], + }, + program, + ); expect(ensureConfigReadyMock).toHaveBeenCalledWith({ runtime: runtimeMock, @@ -206,10 +224,13 @@ describe("registerPreActionHooks", () => { vi.clearAllMocks(); - await runCommand({ - parseArgv: ["update", "status", "--json"], - processArgv: ["node", "openclaw", "update", "status", "--json"], - }); + await runCommand( + { + parseArgv: ["update", "status", "--json"], + processArgv: ["node", "openclaw", "update", "status", "--json"], + }, + program, + ); expect(ensureConfigReadyMock).toHaveBeenCalledWith({ runtime: runtimeMock, diff --git a/src/security/audit.test.ts b/src/security/audit.test.ts index 88dc8962d49..49606982358 100644 --- a/src/security/audit.test.ts +++ b/src/security/audit.test.ts @@ -11,6 +11,10 @@ import { runSecurityAudit } from "./audit.js"; import * as skillScanner from "./skill-scanner.js"; const isWindows = process.platform === "win32"; +const windowsAuditEnv = { + USERNAME: "Tester", + USERDOMAIN: "DESKTOP-TEST", +}; function stubChannelPlugin(params: { id: "discord" | "slack" | "telegram"; @@ -603,7 +607,7 @@ description: test skill stateDir, configPath, platform: "win32", - env: { ...process.env, USERNAME: "Tester", USERDOMAIN: "DESKTOP-TEST" }, + env: windowsAuditEnv, execIcacls, }); @@ -649,7 +653,7 @@ description: test skill stateDir, configPath, platform: "win32", - env: { ...process.env, USERNAME: "Tester", USERDOMAIN: "DESKTOP-TEST" }, + env: windowsAuditEnv, execIcacls, }); diff --git a/test/scripts/ios-team-id.test.ts b/test/scripts/ios-team-id.test.ts index 6e3e87f5a70..f6459d759da 100644 --- a/test/scripts/ios-team-id.test.ts +++ b/test/scripts/ios-team-id.test.ts @@ -70,6 +70,24 @@ exit 0`, await writeExecutable( path.join(sharedBinDir, "security"), `#!/usr/bin/env bash +if [[ "$1" == "cms" && "$2" == "-D" ]]; then + if [[ "$4" == *"one.mobileprovision" ]]; then + cat <<'PLIST' + + +TeamIdentifierAAAAA11111 +PLIST + exit 0 + fi + if [[ "$4" == *"two.mobileprovision" ]]; then + cat <<'PLIST' + + +TeamIdentifierBBBBB22222 +PLIST + exit 0 + fi +fi exit 1`, ); }); @@ -92,7 +110,7 @@ exit 1`, } it("falls back to Xcode-managed provisioning profiles when preference teams are empty", async () => { - const { homeDir, binDir } = await createHomeDir(); + const { homeDir } = await createHomeDir(); await mkdir(path.join(homeDir, "Library", "MobileDevice", "Provisioning Profiles"), { recursive: true, }); @@ -101,30 +119,9 @@ exit 1`, "stub", ); - await writeExecutable( - path.join(binDir, "security"), - `#!/usr/bin/env bash -if [[ "$1" == "cms" && "$2" == "-D" ]]; then - cat <<'PLIST' - - - - - TeamIdentifier - - ABCDE12345 - - - -PLIST - exit 0 -fi -exit 0`, - ); - const result = runScript(homeDir); expect(result.ok).toBe(true); - expect(result.stdout).toBe("ABCDE12345"); + expect(result.stdout).toBe("AAAAA11111"); }); it("prints actionable guidance when Xcode account exists but no Team ID is resolvable", async () => { @@ -152,7 +149,7 @@ exit 1`, }); it("honors IOS_PREFERRED_TEAM_ID when multiple profile teams are available", async () => { - const { homeDir, binDir } = await createHomeDir(); + const { homeDir } = await createHomeDir(); await mkdir(path.join(homeDir, "Library", "MobileDevice", "Provisioning Profiles"), { recursive: true, }); @@ -165,28 +162,6 @@ exit 1`, "stub2", ); - await writeExecutable( - path.join(binDir, "security"), - `#!/usr/bin/env bash -if [[ "$1" == "cms" && "$2" == "-D" ]]; then - if [[ "$4" == *"one.mobileprovision" ]]; then - cat <<'PLIST' - - -TeamIdentifierAAAAA11111 -PLIST - exit 0 - fi - cat <<'PLIST' - - -TeamIdentifierBBBBB22222 -PLIST - exit 0 -fi -exit 0`, - ); - const result = runScript(homeDir, { IOS_PREFERRED_TEAM_ID: "BBBBB22222" }); expect(result.ok).toBe(true); expect(result.stdout).toBe("BBBBB22222");