mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
test(perf): dedupe setup in cli/security script suites
This commit is contained in:
@@ -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("<path>")
|
||||
.argument("<value>")
|
||||
.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,
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
@@ -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'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0"><dict><key>TeamIdentifier</key><array><string>AAAAA11111</string></array></dict></plist>
|
||||
PLIST
|
||||
exit 0
|
||||
fi
|
||||
if [[ "$4" == *"two.mobileprovision" ]]; then
|
||||
cat <<'PLIST'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0"><dict><key>TeamIdentifier</key><array><string>BBBBB22222</string></array></dict></plist>
|
||||
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'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>TeamIdentifier</key>
|
||||
<array>
|
||||
<string>ABCDE12345</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
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'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0"><dict><key>TeamIdentifier</key><array><string>AAAAA11111</string></array></dict></plist>
|
||||
PLIST
|
||||
exit 0
|
||||
fi
|
||||
cat <<'PLIST'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0"><dict><key>TeamIdentifier</key><array><string>BBBBB22222</string></array></dict></plist>
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user