refactor(verify): share client setup and idempotence checks (#14326)

* refactor(verify): share client setup and idempotence checks

* refactor(verify): select OpenCode configuration from fixed filenames
This commit is contained in:
Vincent Koc authored and GitHub committed 2026-11-24 06:29:17 -05:00
1 parent 0fa803e7e8
commit d7846f2834
4 files changed
+118 -183

No files matched your search

+16 -60
View File
@@ -1,7 +1,8 @@
import assert from "node:assert/strict";
import { verifyClientSetup } from "./verify/clients/setup.mjs";
import { createHash } from "node:crypto";
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { isAbsolute, join } from "node:path";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import Ajv2020 from "ajv/dist/2020.js";
import { createCatalogIdentity } from "../dist/contracts/catalog/catalogIdentity.js";
@@ -10,7 +11,6 @@ import {
TOOL_CONTRACTS,
toolContract,
} from "../dist/contracts/toolContracts.js";
import { isPathWithinRoot } from "../dist/domain/localPath.js";
import { createVerifierCommands } from "./lib/verify-commands.mjs";
import { withVerifierCleanup } from "./lib/verifier-cleanup.mjs";
import { saveVerifierCommandOutput } from "./lib/verifier-command-output.mjs";
@@ -268,64 +268,20 @@ await withVerifierCleanup(async () => {
2,
);
await writeFile(configPath, original);
for (const args of [
["setup", "--client", "claude_code", "--dry-run"],
["setup", "--client", "claude_code", "--yes"],
["doctor", "--client", "claude_code", "--skill"],
]) {
const result = await commands.exec(
process.execPath,
[join(runtimeRoot, "scripts/rea.mjs"), ...args, "--json"],
{ env: environment, cwd: workspace, timeout: 60_000, stdin: "pipe" },
);
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((a) => a.target === configPath));
assert(
parsed.plannedActions.some((a) => a.target === skillDirectory),
);
assert(
parsed.plannedActions.every(
(a) =>
a.target === configPath ||
(isAbsolute(a.target) &&
isPathWithinRoot(skillDirectory, a.target)),
),
);
}
}
}
assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original);
const configured = await readFile(configPath, "utf8");
assert.equal(JSON.parse(configured).theme, "light");
const repeated = await commands.exec(
process.execPath,
[
join(runtimeRoot, "scripts/rea.mjs"),
"setup",
"--client",
"claude_code",
"--yes",
"--json",
],
{ env: environment, cwd: workspace, timeout: 60_000, stdin: "pipe" },
);
assert.deepEqual(JSON.parse(repeated.stdout).appliedActions, []);
assert.equal(await readFile(configPath, "utf8"), configured);
assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original);
await verifyClientSetup({
client: "claude_code",
commands,
runtimeRoot,
environment,
workspace,
lab,
configPath,
original,
skillDirectory,
checkConfigured: (configured) => {
assert.equal(JSON.parse(configured).theme, "light");
},
});
const installedSkill = await readFile(
join(skillDirectory, "SKILL.md"),
"utf8",
+15 -60
View File
@@ -1,4 +1,5 @@
import assert from "node:assert/strict";
import { verifyClientSetup } from "./verify/clients/setup.mjs";
import { createHash } from "node:crypto";
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { basename, isAbsolute, join } from "node:path";
@@ -10,7 +11,6 @@ import {
} from "../dist/contracts/toolContracts.js";
import { advertisedInputJsonSchema } from "../dist/contracts/toolSchemaMetadata.js";
import { advertiseTool } from "../dist/contracts/advertisedTool.js";
import { isPathWithinRoot } from "../dist/domain/localPath.js";
import { createVerifierCommands } from "./lib/verify-commands.mjs";
import { withVerifierCleanup } from "./lib/verifier-cleanup.mjs";
import { saveVerifierCommandOutput } from "./lib/verifier-command-output.mjs";
@@ -260,65 +260,20 @@ await withVerifierCleanup(async () => {
2,
);
await writeFile(configPath, original);
for (const args of [
["setup", "--client", "copilot_cli", "--dry-run"],
["setup", "--client", "copilot_cli", "--yes"],
["doctor", "--client", "copilot_cli", "--skill"],
]) {
const result = await commands.exec(
process.execPath,
[join(runtimeRoot, "scripts/rea.mjs"), ...args, "--json"],
{ env: environment, cwd: workspace, timeout: 60_000, stdin: "pipe" },
);
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((a) => a.target === configPath));
assert(
parsed.plannedActions.some((a) => a.target === skillDirectory),
);
assert(
parsed.plannedActions.every(
(a) =>
a.target === configPath ||
(isAbsolute(a.target) &&
isPathWithinRoot(skillDirectory, a.target)),
),
);
}
}
}
assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original);
const configured = await readFile(configPath, "utf8");
assert(configured.includes("unrelated-server"));
const repeated = await commands.exec(
process.execPath,
[
join(runtimeRoot, "scripts/rea.mjs"),
"setup",
"--client",
"copilot_cli",
"--yes",
"--json",
],
{ env: environment, cwd: workspace, timeout: 60_000, stdin: "pipe" },
);
assert.deepEqual(JSON.parse(repeated.stdout).appliedActions, []);
assert.equal(await readFile(configPath, "utf8"), configured);
assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original);
await verifyClientSetup({
client: "copilot_cli",
commands,
runtimeRoot,
environment,
workspace,
lab,
configPath,
original,
skillDirectory,
checkConfigured: (configured) => {
assert(configured.includes("unrelated-server"));
},
});
const installedSkill = await readFile(
join(skillDirectory, "SKILL.md"),
"utf8",
+24 -63
View File
@@ -1,7 +1,8 @@
import assert from "node:assert/strict";
import { verifyClientSetup } from "./verify/clients/setup.mjs";
import { createHash } from "node:crypto";
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { isAbsolute, join } from "node:path";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import Ajv2020 from "ajv/dist/2020.js";
import { TOOL_CONTRACTS } from "../dist/contracts/toolContracts.js";
@@ -37,8 +38,12 @@ assert(
["chat", "call"].includes(mode),
"Usage: verify-opencode-client.mjs [chat|call]",
);
const configFilename = new Map([
["json", "opencode.json"],
["jsonc", "opencode.jsonc"],
]).get(configFormat);
assert(
["json", "jsonc"].includes(configFormat),
configFilename !== undefined,
"REA_VERIFY_OPENCODE_CONFIG_FORMAT must be json or jsonc",
);
const verifier = createVerifierRun();
@@ -48,7 +53,7 @@ const { path: lab } = await VerifierFixture.keepArtifacts({
const account = join(lab, "account");
const profile = join(lab, "selected profile");
const workspace = join(lab, "workspace");
const configPath = join(profile, `opencode.${configFormat}`);
const configPath = join(profile, configFilename);
const skillDirectory = join(
account,
".agents",
@@ -233,66 +238,22 @@ await withVerifierCleanup(async () => {
2,
);
await writeFile(configPath, original);
for (const args of [
["setup", "--client", "opencode", "--dry-run"],
["setup", "--client", "opencode", "--yes"],
["doctor", "--client", "opencode", "--skill"],
]) {
const result = await commands.exec(
process.execPath,
[join(runtimeRoot, "scripts/rea.mjs"), ...args, "--json"],
{ env: environment, cwd: workspace, timeout: 60_000, stdin: "pipe" },
);
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((a) => a.target === configPath));
assert(
parsed.plannedActions.some((a) => a.target === skillDirectory),
);
assert(
parsed.plannedActions.every(
(a) =>
a.target === configPath ||
(isAbsolute(a.target) &&
isPathWithinRoot(skillDirectory, a.target)),
),
);
}
}
}
assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original);
const configured = await readFile(configPath, "utf8");
assert(configured.includes("unrelated-server"));
if (configFormat === "jsonc")
assert(configured.includes("// Keep caller configuration."));
const repeated = await commands.exec(
process.execPath,
[
join(runtimeRoot, "scripts/rea.mjs"),
"setup",
"--client",
"opencode",
"--yes",
"--json",
],
{ env: environment, cwd: workspace, timeout: 60_000, stdin: "pipe" },
);
assert.deepEqual(JSON.parse(repeated.stdout).appliedActions, []);
assert.equal(await readFile(configPath, "utf8"), configured);
assert.equal(await readFile(`${configPath}.rea.backup`, "utf8"), original);
await verifyClientSetup({
client: "opencode",
commands,
runtimeRoot,
environment,
workspace,
lab,
configPath,
original,
skillDirectory,
checkConfigured: (configured) => {
assert(configured.includes("unrelated-server"));
if (configFormat === "jsonc")
assert(configured.includes("// Keep caller configuration."));
},
});
const installedSkill = await readFile(
join(skillDirectory, "SKILL.md"),
"utf8",
+63
View File
@@ -0,0 +1,63 @@
import assert from "node:assert/strict";
import { readFile, writeFile } from "node:fs/promises";
import { isAbsolute, join } from "node:path";
import { isPathWithinRoot } from "#dist/domain/localPath.js";
/** Exercise the registration plan, its application, doctor and a repeat application. */
export async function verifyClientSetup({
client,
commands,
runtimeRoot,
environment,
workspace,
lab,
configPath,
original,
skillDirectory,
checkConfigured,
}) {
const run = async (command, flag, output) => {
const result = await commands.exec(
process.execPath,
[
join(runtimeRoot, "scripts/rea.mjs"),
command,
"--client",
client,
flag,
"--json",
],
{ env: environment, cwd: workspace, timeout: 60_000, stdin: "pipe" },
);
if (output !== undefined) await writeFile(join(lab, output), result.stdout);
return JSON.parse(result.stdout);
};
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),
);
assert(
plan.plannedActions.every(
(action) =>
action.target === configPath ||
(isAbsolute(action.target) &&
isPathWithinRoot(skillDirectory, action.target)),
),
);
const applied = await run("setup", "--yes", "setup.json");
assert.equal(applied.status, "ready");
const doctor = await run("doctor", "--skill", "doctor.json");
assert.equal(doctor.healthy, true);
const backup = `${configPath}.rea.backup`;
assert.equal(await readFile(backup, "utf8"), original);
const configured = await readFile(configPath, "utf8");
checkConfigured(configured);
const repeated = await run("setup", "--yes");
assert.deepEqual(repeated.appliedActions, []);
assert.equal(await readFile(configPath, "utf8"), configured);
assert.equal(await readFile(backup, "utf8"), original);
}