From b5219e7d93e8fb146679afff67dfecccb8493c71 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Wed, 25 Nov 2026 21:28:42 +0800 Subject: [PATCH] test(clients): reuse setup verification for three more clients (#14460) --- scripts/verify-commandcode-client.mjs | 73 ++++------------ scripts/verify-grok-client.mjs | 78 ++++------------- scripts/verify-omp-client.mjs | 115 ++++++++++---------------- scripts/verify/clients/setup.mjs | 11 ++- 4 files changed, 85 insertions(+), 192 deletions(-) diff --git a/scripts/verify-commandcode-client.mjs b/scripts/verify-commandcode-client.mjs index 152a2114753..c196eab8f7c 100644 --- a/scripts/verify-commandcode-client.mjs +++ b/scripts/verify-commandcode-client.mjs @@ -6,7 +6,7 @@ import { isAbsolute, join, relative } from "node:path"; import { fileURLToPath } from "node:url"; import Ajv2020 from "ajv/dist/2020.js"; import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js"; -import { isPathWithinRoot } from "../dist/domain/localPath.js"; +import { verifyClientSetup } from "./verify/clients/setup.mjs"; import { createVerifierCommands } from "./lib/verify-commands.mjs"; import { withVerifierCleanup } from "./lib/verifier-cleanup.mjs"; import { publishClientReceipt } from "./verify/clients/receipt.mjs"; @@ -301,12 +301,6 @@ await withVerifierCleanup(async () => { 2, ) + "\n"; await writeFile(configPath, original); - const rea = (args) => - commands.exec( - process.execPath, - [join(runtimeRoot, "scripts/rea.mjs"), ...args, "--json"], - { env: environment, cwd: workspace, timeout: 60_000, stdin: "pipe" }, - ); clientVersion = ( await commands.exec(command, ["--version"], { env: environment, @@ -315,54 +309,23 @@ await withVerifierCleanup(async () => { stdin: "pipe", }) ).stdout.trim(); - for (const args of [ - ["setup", "--client", "commandcode", "--dry-run"], - ["setup", "--client", "commandcode", "--yes"], - ["doctor", "--client", "commandcode", "--skill"], - ]) { - const response = await rea(args); - await writeFile( - join( - lab, - `${args[0]}${args.includes("--dry-run") ? "-plan" : ""}.json`, - ), - response.stdout, - ); - const result = JSON.parse(response.stdout); - if (args[0] === "doctor") assert.equal(result.healthy, true); - else - assert.equal( - result.status, - args.includes("--dry-run") ? "planned" : "ready", - ); - if (args.includes("--dry-run")) { - assert( - result.plannedActions.some((action) => action.target === configPath), - ); - assert( - result.plannedActions.every( - (action) => - action.target === configPath || - (isAbsolute(action.target) && - isPathWithinRoot(skillDirectory, action.target)), - ), - "Refuse setup writes outside the disposable account's configuration and skill", - ); - } - } - assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original); - const configured = await readFile(configPath, "utf8"); - assert.equal(JSON.parse(configured).preserved, "keep unrelated settings"); - assert.equal( - JSON.parse(configured).mcpServers.other.command, - "unrelated-server", - ); - const repeated = JSON.parse( - (await rea(["setup", "--client", "commandcode", "--yes"])).stdout, - ); - assert.deepEqual(repeated.appliedActions, []); - assert.equal(await readFile(configPath, "utf8"), configured); - assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original); + await verifyClientSetup({ + client: "commandcode", + commands, + runtimeRoot, + environment, + workspace, + lab, + configPath, + original, + skillDirectory, + requiredPlanTargets: [configPath], + checkConfigured: (configured) => { + const registration = JSON.parse(configured); + assert.equal(registration.preserved, "keep unrelated settings"); + assert.equal(registration.mcpServers.other.command, "unrelated-server"); + }, + }); const installedSkill = await readFile( join(skillDirectory, "SKILL.md"), "utf8", diff --git a/scripts/verify-grok-client.mjs b/scripts/verify-grok-client.mjs index c366bb8fd8d..ca4ee5cfcde 100644 --- a/scripts/verify-grok-client.mjs +++ b/scripts/verify-grok-client.mjs @@ -6,7 +6,7 @@ import { isAbsolute, join, relative } from "node:path"; import { fileURLToPath } from "node:url"; import Ajv2020 from "ajv/dist/2020.js"; import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js"; -import { isPathWithinRoot } from "../dist/domain/localPath.js"; +import { verifyClientSetup } from "./verify/clients/setup.mjs"; import { createVerifierCommands } from "./lib/verify-commands.mjs"; import { withVerifierCleanup } from "./lib/verifier-cleanup.mjs"; import { containsText } from "./verify/clients/result-discovery.mjs"; @@ -375,12 +375,6 @@ command = "unrelated-server" enabled = false `; await writeFile(configPath, original); - const rea = async (args) => - commands.exec( - process.execPath, - [join(runtimeRoot, "scripts/rea.mjs"), ...args, "--json"], - { env: environment, cwd: workspace, timeout: 60_000, stdin: "pipe" }, - ); clientVersion = ( await commands.exec(command, ["--version"], { env: environment, @@ -388,61 +382,23 @@ enabled = false stdin: "pipe", }) ).stdout.trim(); - for (const args of [ - ["setup", "--client", "grok_build", "--dry-run"], - ["setup", "--client", "grok_build", "--yes"], - ["doctor", "--client", "grok_build", "--skill"], - ]) { - const result = await rea(args); - await writeFile( - join( - lab, - `${args[0]}${args.includes("--dry-run") ? "-plan" : ""}.json`, - ), - result.stdout, - ); - const parsed = JSON.parse(result.stdout); - if (args[0] === "doctor") assert.equal(parsed.healthy, true); - else { - assert.equal( - parsed.status, - args.includes("--dry-run") ? "planned" : "ready", + await verifyClientSetup({ + client: "grok_build", + commands, + runtimeRoot, + environment, + workspace, + lab, + configPath, + original, + skillDirectory, + checkConfigured: (configured) => { + assert( + configured.includes("unrelated-server") && + configured.includes("# Keep unrelated settings"), ); - if (args.includes("--dry-run")) { - assert( - parsed.plannedActions.some( - (action) => action.target === configPath, - ), - ); - assert( - parsed.plannedActions.some( - (action) => action.target === skillDirectory, - ), - ); - assert( - parsed.plannedActions.every( - (action) => - action.target === configPath || - (isAbsolute(action.target) && - isPathWithinRoot(skillDirectory, action.target)), - ), - "Refuse writes outside the owned profile/skill", - ); - } - } - } - assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original); - const configured = await readFile(configPath, "utf8"); - assert( - configured.includes("unrelated-server") && - configured.includes("# Keep unrelated settings"), - ); - const repeated = JSON.parse( - (await rea(["setup", "--client", "grok_build", "--yes"])).stdout, - ); - assert.deepEqual(repeated.appliedActions, []); - assert.equal(await readFile(configPath, "utf8"), configured); - assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original); + }, + }); const skill = await readFile(join(skillDirectory, "SKILL.md"), "utf8"); expectedSkill = skill .trimEnd() diff --git a/scripts/verify-omp-client.mjs b/scripts/verify-omp-client.mjs index c370239401a..0ae041243aa 100644 --- a/scripts/verify-omp-client.mjs +++ b/scripts/verify-omp-client.mjs @@ -2,10 +2,10 @@ import assert from "node:assert/strict"; import { createHash } from "node:crypto"; import { mkdir, readFile, writeFile } from "node:fs/promises"; import { homedir } from "node:os"; -import { isAbsolute, join, relative } from "node:path"; +import { join, relative } from "node:path"; import { fileURLToPath } from "node:url"; import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js"; -import { isPathWithinRoot } from "../dist/domain/localPath.js"; +import { verifyClientSetup } from "./verify/clients/setup.mjs"; import { createVerifierCommands } from "./lib/verify-commands.mjs"; import { withVerifierCleanup } from "./lib/verifier-cleanup.mjs"; import { containsText } from "./verify/clients/result-discovery.mjs"; @@ -211,12 +211,6 @@ await withVerifierCleanup(async () => { }, }), ); - const rea = async (args, env = environment) => - commands.exec( - process.execPath, - [join(runtimeRoot, "scripts/rea.mjs"), ...args, "--json"], - { env, cwd: workspace, timeout: 60_000, stdin: "pipe" }, - ); clientVersion = ( await commands.exec(command, ["--version"], { env: environment, @@ -249,16 +243,31 @@ await withVerifierCleanup(async () => { join(lab, "invalid-profile-native.stderr"), nativeRejected.snapshot.stderr.text, ); - const setupRejected = await rea( - ["setup", "--client", "omp", "--dry-run"], - invalidEnvironment, - ).then( - () => undefined, - (cause) => { - if (typeof cause?.code !== "number" || cause.code === 0) throw cause; - return cause; - }, - ); + const setupRejected = await commands + .exec( + process.execPath, + [ + join(runtimeRoot, "scripts/rea.mjs"), + "setup", + "--client", + "omp", + "--dry-run", + "--json", + ], + { + env: invalidEnvironment, + cwd: workspace, + timeout: 60_000, + stdin: "pipe", + }, + ) + .then( + () => undefined, + (cause) => { + if (typeof cause?.code !== "number" || cause.code === 0) throw cause; + return cause; + }, + ); assert(typeof setupRejected?.code === "number" && setupRejected.code !== 0); const rejected = JSON.parse(setupRejected.snapshot.stdout.text); assert.equal(rejected.status, "needs_human"); @@ -271,60 +280,22 @@ await withVerifierCleanup(async () => { setupRejected.snapshot.stdout.text, ); invalidProfileRejected = true; - for (const args of [ - ["setup", "--client", "omp", "--dry-run"], - ["setup", "--client", "omp", "--yes"], - ["doctor", "--client", "omp", "--skill"], - ]) { - const result = await rea(args); - await writeFile( - join( - lab, - `${args[0]}${args.includes("--dry-run") ? "-plan" : ""}.json`, - ), - result.stdout, - ); - const parsed = JSON.parse(result.stdout); - if (args[0] === "doctor") assert.equal(parsed.healthy, true); - else { - assert.equal( - parsed.status, - args.includes("--dry-run") ? "planned" : "ready", - ); - if (args.includes("--dry-run")) { - assert( - parsed.plannedActions.some( - (action) => action.target === configPath, - ), - ); - assert( - parsed.plannedActions.some( - (action) => action.target === skillDirectory, - ), - ); - assert( - parsed.plannedActions.every( - (action) => - action.target === configPath || - (isAbsolute(action.target) && - isPathWithinRoot(skillDirectory, action.target)), - ), - "Refuse setup writes outside the owned config/skill", - ); - } - } - } - assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original); - const configured = await readFile(configPath, "utf8"); - const registration = JSON.parse(configured); - assert.equal(registration.mcpServers.other.command, "unrelated-server"); - assert.deepEqual(registration.disabledServers, ["other"]); - const repeated = JSON.parse( - (await rea(["setup", "--client", "omp", "--yes"])).stdout, - ); - assert.deepEqual(repeated.appliedActions, []); - assert.equal(await readFile(configPath, "utf8"), configured); - assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original); + await verifyClientSetup({ + client: "omp", + commands, + runtimeRoot, + environment, + workspace, + lab, + configPath, + original, + skillDirectory, + checkConfigured: (configured) => { + const registration = JSON.parse(configured); + assert.equal(registration.mcpServers.other.command, "unrelated-server"); + assert.deepEqual(registration.disabledServers, ["other"]); + }, + }); expectedSkillBody = await readFile( join(skillDirectory, "SKILL.md"), "utf8", diff --git a/scripts/verify/clients/setup.mjs b/scripts/verify/clients/setup.mjs index e218a34292e..2c0105ac925 100644 --- a/scripts/verify/clients/setup.mjs +++ b/scripts/verify/clients/setup.mjs @@ -14,6 +14,7 @@ export async function verifyClientSetup({ configPath, original, skillDirectory, + requiredPlanTargets = [configPath, skillDirectory], checkConfigured, }) { const run = async (command, flag, output) => { @@ -34,10 +35,11 @@ export async function verifyClientSetup({ }; const plan = await run("setup", "--dry-run", "setup-plan.json"); assert.equal(plan.status, "planned"); - assert(plan.plannedActions.some((action) => action.target === configPath)); - assert( - plan.plannedActions.some((action) => action.target === skillDirectory), - ); + for (const target of requiredPlanTargets) + assert( + plan.plannedActions.some((action) => action.target === target), + `Missing planned setup destination: ${target}`, + ); assert( plan.plannedActions.every( (action) => @@ -45,6 +47,7 @@ export async function verifyClientSetup({ (isAbsolute(action.target) && isPathWithinRoot(skillDirectory, action.target)), ), + "Setup writes must stay within the selected configuration and skill directory", ); const applied = await run("setup", "--yes", "setup.json");