perf(tests): reuse stateless workflows and immutable fixtures

This commit is contained in:
morluto
2026-10-11 13:20:15 +08:00
parent 13e03e9436
commit 5f4c7ff6df
8 changed files with 526 additions and 444 deletions
@@ -0,0 +1,160 @@
import { access, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
const cases = [
{
client: "gemini_cli",
env: { GEMINI_CLI_HOME: "profile" },
config: "profile/.gemini/settings.json",
skill: "profile/.agents/skills",
},
{
client: "opencode",
env: { OPENCODE_CONFIG_DIR: "profile" },
config: "profile/opencode.json",
skill: ".agents/skills",
},
{
client: "opencode",
env: { OPENCODE_CONFIG_DIR: "" },
config: ".config/opencode/opencode.json",
skill: ".agents/skills",
},
{
client: "codex",
env: { CODEX_HOME: "" },
config: ".codex/config.toml",
skill: ".agents/skills",
},
{
client: "grok_build",
env: { GROK_HOME: "" },
config: ".grok/config.toml",
skill: ".agents/skills",
},
{
client: "omp",
env: { PI_CODING_AGENT_DIR: "profile" },
config: "profile/mcp.json",
skill: ".agents/skills",
},
{
client: "devin",
env: { XDG_CONFIG_HOME: "profile" },
config: "profile/devin/mcp_config.json",
skill: ".agents/skills",
},
{
client: "antigravity",
env: {},
config: ".gemini/config/mcp_config.json",
skill: ".gemini/config/skills",
},
];
for (const testCase of cases.filter(
({ client }) => process.platform !== "win32" || client !== "devin",
)) {
cliTest(
`${testCase.client} lifecycle follows the selected roots (${testCase.config})`,
async ({ cli }) => {
const home = await createTestTempDirectory("rea-client-profile-");
const environment: NodeJS.ProcessEnv = { HOME: home, USERPROFILE: home };
for (const [key, value] of Object.entries(testCase.env))
environment[key] = value === "profile" ? join(home, value) : value;
// OMP's relative override is relative to the caller, not silently ignored.
if (testCase.client === "omp")
environment.PI_CODING_AGENT_DIR = "profile";
const config = join(home, testCase.config);
const skillDirectory = join(
home,
testCase.skill,
"reverse-engineer-anything",
);
const run = (arguments_: readonly string[]) =>
cli.run({
arguments: arguments_,
cwd: home,
environment,
timeoutMs: 20_000,
});
const planned = await run([
"setup",
"--client",
testCase.client,
"--dry-run",
"--json",
]);
expect(planned.exitCode).toBe(0);
expect(planned.json).toMatchObject({
status: "planned",
plannedActions: expect.arrayContaining([
expect.objectContaining({ target: config }),
expect.objectContaining({ target: skillDirectory }),
]),
});
await expect(access(config)).rejects.toMatchObject({ code: "ENOENT" });
const setup = await run([
"setup",
"--client",
testCase.client,
"--yes",
"--json",
]);
expect(setup.exitCode).toBe(0);
expect(setup.json).toMatchObject({ status: "ready" });
await expect(access(config)).resolves.toBeUndefined();
expect(
await readFile(join(skillDirectory, "SKILL.md"), "utf8"),
).toContain("reverse-engineer-anything");
await expect(access(join(home, "config.toml"))).rejects.toMatchObject({
code: "ENOENT",
});
const doctor = await run([
"doctor",
"--client",
testCase.client,
"--skill",
"--json",
]);
expect(doctor.exitCode).toBe(0);
expect(doctor.json).toMatchObject({
healthy: true,
identity: { skill: { state: "aligned" } },
});
if (testCase.client === "grok_build") {
const original = await readFile(config, "utf8");
await writeFile(
config,
original.replace(
"[mcp_servers.rea]",
"[mcp_servers.rea]\ndisabled = true",
),
);
expect(
(await run(["doctor", "--client", "grok_build", "--json"])).exitCode,
).toBe(0);
await writeFile(config, original);
}
const repeat = await run([
"setup",
"--client",
testCase.client,
"--yes",
"--json",
]);
expect(repeat.json).toMatchObject({
status: "ready",
appliedActions: [],
});
const uninstall = await run(["uninstall", "--json"]);
expect(uninstall.exitCode).toBe(0);
expect(uninstall.json).toMatchObject({ status: "complete" });
await expect(
access(join(skillDirectory, "SKILL.md")),
).rejects.toMatchObject({ code: "ENOENT" });
},
);
}
-155
View File
@@ -6,161 +6,6 @@ import { PRODUCT_IDENTITY } from "../../../src/identity.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
const cases = [
{
client: "gemini_cli",
env: { GEMINI_CLI_HOME: "profile" },
config: "profile/.gemini/settings.json",
skill: "profile/.agents/skills",
},
{
client: "opencode",
env: { OPENCODE_CONFIG_DIR: "profile" },
config: "profile/opencode.json",
skill: ".agents/skills",
},
{
client: "opencode",
env: { OPENCODE_CONFIG_DIR: "" },
config: ".config/opencode/opencode.json",
skill: ".agents/skills",
},
{
client: "codex",
env: { CODEX_HOME: "" },
config: ".codex/config.toml",
skill: ".agents/skills",
},
{
client: "grok_build",
env: { GROK_HOME: "" },
config: ".grok/config.toml",
skill: ".agents/skills",
},
{
client: "omp",
env: { PI_CODING_AGENT_DIR: "profile" },
config: "profile/mcp.json",
skill: ".agents/skills",
},
{
client: "devin",
env: { XDG_CONFIG_HOME: "profile" },
config: "profile/devin/mcp_config.json",
skill: ".agents/skills",
},
{
client: "antigravity",
env: {},
config: ".gemini/config/mcp_config.json",
skill: ".gemini/config/skills",
},
];
for (const testCase of cases.filter(
({ client }) => process.platform !== "win32" || client !== "devin",
)) {
cliTest(
`${testCase.client} lifecycle follows the selected roots (${testCase.config})`,
async ({ cli }) => {
const home = await createTestTempDirectory("rea-client-profile-");
const environment: NodeJS.ProcessEnv = { HOME: home, USERPROFILE: home };
for (const [key, value] of Object.entries(testCase.env))
environment[key] = value === "profile" ? join(home, value) : value;
// OMP's relative override is relative to the caller, not silently ignored.
if (testCase.client === "omp")
environment.PI_CODING_AGENT_DIR = "profile";
const config = join(home, testCase.config);
const skillDirectory = join(
home,
testCase.skill,
"reverse-engineer-anything",
);
const run = (arguments_: readonly string[]) =>
cli.run({
arguments: arguments_,
cwd: home,
environment,
timeoutMs: 20_000,
});
const planned = await run([
"setup",
"--client",
testCase.client,
"--dry-run",
"--json",
]);
expect(planned.exitCode).toBe(0);
expect(planned.json).toMatchObject({
status: "planned",
plannedActions: expect.arrayContaining([
expect.objectContaining({ target: config }),
expect.objectContaining({ target: skillDirectory }),
]),
});
await expect(access(config)).rejects.toMatchObject({ code: "ENOENT" });
const setup = await run([
"setup",
"--client",
testCase.client,
"--yes",
"--json",
]);
expect(setup.exitCode).toBe(0);
expect(setup.json).toMatchObject({ status: "ready" });
await expect(access(config)).resolves.toBeUndefined();
expect(
await readFile(join(skillDirectory, "SKILL.md"), "utf8"),
).toContain("reverse-engineer-anything");
await expect(access(join(home, "config.toml"))).rejects.toMatchObject({
code: "ENOENT",
});
const doctor = await run([
"doctor",
"--client",
testCase.client,
"--skill",
"--json",
]);
expect(doctor.exitCode).toBe(0);
expect(doctor.json).toMatchObject({
healthy: true,
identity: { skill: { state: "aligned" } },
});
if (testCase.client === "grok_build") {
const original = await readFile(config, "utf8");
await writeFile(
config,
original.replace(
"[mcp_servers.rea]",
"[mcp_servers.rea]\ndisabled = true",
),
);
expect(
(await run(["doctor", "--client", "grok_build", "--json"])).exitCode,
).toBe(0);
await writeFile(config, original);
}
const repeat = await run([
"setup",
"--client",
testCase.client,
"--yes",
"--json",
]);
expect(repeat.json).toMatchObject({
status: "ready",
appliedActions: [],
});
const uninstall = await run(["uninstall", "--json"]);
expect(uninstall.exitCode).toBe(0);
expect(uninstall.json).toMatchObject({ status: "complete" });
await expect(
access(join(skillDirectory, "SKILL.md")),
).rejects.toMatchObject({ code: "ENOENT" });
},
);
}
for (const policy of [{ excluded: ["rea"] }, { allowed: ["other"] }]) {
cliTest(
`Gemini refuses a registration blocked by ${Object.keys(policy)[0]}`,
@@ -1,10 +1,15 @@
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { cp, mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
import { afterAll, expect, it } from "vitest";
import { z } from "zod";
import { parse } from "yaml";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import {
createTestWorkspace,
removeTestWorkspace,
type TestWorkspace,
} from "../../support/workspace/workspaceFixture.js";
import {
executeWorkflowFixture as execFileAsync,
workflowGit as git,
@@ -52,27 +57,72 @@ async function metadata(
);
}
interface ReleaseSeed {
readonly directory: string;
readonly releasedSha: string;
}
const seedWorkspaces: TestWorkspace[] = [];
const seedPromises = new Map<string, Promise<ReleaseSeed>>();
const releaseSeed = (versioning?: string): Promise<ReleaseSeed> => {
const key = versioning ?? "default";
const existing = seedPromises.get(key);
if (existing !== undefined) return existing;
const pending = (async (): Promise<ReleaseSeed> => {
const workspace = await createTestWorkspace("rea-release-checkpoint-seed-");
seedWorkspaces.push(workspace);
const directory = workspace.path(key);
await mkdir(directory, { recursive: true });
await git(directory, ["init", "--initial-branch=main"]);
await metadata(directory, "4.0.0", "Initial release", versioning);
await git(directory, ["add", "."]);
await git(
directory,
["commit", "-m", "chore: seed"],
"2026-01-01T00:00:00Z",
);
await git(directory, ["switch", "-c", "release/5.0.0"]);
await metadata(directory, "5.0.0", "Previous release", versioning);
await git(directory, ["add", "."]);
await git(
directory,
["commit", "-m", "chore: release 5.0.0"],
"2026-01-03T00:00:00Z",
);
const releasedSha = await git(directory, ["rev-parse", "HEAD"]);
await git(directory, ["tag", "rea-agents-5.0.0"]);
await git(directory, ["switch", "main"]);
return { directory, releasedSha };
})();
seedPromises.set(key, pending);
return pending;
};
afterAll(async () => {
await Promise.allSettled(seedPromises.values());
const cleanup = await Promise.allSettled(
seedWorkspaces.map(({ root }) => removeTestWorkspace(root)),
);
const failures = cleanup.flatMap((result) =>
result.status === "rejected" ? [result.reason] : [],
);
if (failures.length > 0)
throw new AggregateError(
failures,
"Could not remove release checkpoint seeds",
);
});
async function fixture(
subject = "fix(contracts)!: require absolute paths (#948)",
footer = "",
options: { mergePullRequest?: boolean; versioning?: string } = {},
) {
const seed = await releaseSeed(options.versioning);
const directory = await createTestTempDirectory("rea-release-ancestry-");
await git(directory, ["init", "--initial-branch=main"]);
await metadata(directory, "4.0.0", "Initial release", options.versioning);
await git(directory, ["add", "."]);
await git(directory, ["commit", "-m", "chore: seed"], "2026-01-01T00:00:00Z");
await git(directory, ["switch", "-c", "release/5.0.0"]);
await metadata(directory, "5.0.0", "Previous release", options.versioning);
await git(directory, ["add", "."]);
await git(
directory,
["commit", "-m", "chore: release 5.0.0"],
"2026-01-03T00:00:00Z",
);
const releasedSha = await git(directory, ["rev-parse", "HEAD"]);
await git(directory, ["tag", "rea-agents-5.0.0"]);
await git(directory, ["switch", "main"]);
await cp(seed.directory, directory, { recursive: true, dereference: true });
if (options.mergePullRequest) {
await git(directory, ["switch", "-c", "change/contracts"]);
}
@@ -115,7 +165,7 @@ async function fixture(
directory,
sourceSha,
changedSha,
releasedSha,
releasedSha: seed.releasedSha,
versioning: options.versioning,
};
}
+46 -4
View File
@@ -1,9 +1,20 @@
import { access, chmod, mkdir, readFile, writeFile } from "node:fs/promises";
import {
access,
chmod,
cp,
mkdir,
readFile,
writeFile,
} from "node:fs/promises";
import { delimiter, join } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
import { afterAll, beforeAll, expect, it } from "vitest";
import { z } from "zod";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import {
createTestWorkspace,
removeTestWorkspace,
} from "../../support/workspace/workspaceFixture.js";
import {
executeWorkflowFixture as exec,
workflowGit as git,
@@ -23,8 +34,20 @@ const page = (nodes: unknown[], cursor: string | null = null) => ({
pageInfo: { hasNextPage: cursor !== null, endCursor: cursor },
});
async function fixture() {
const directory = await createTestTempDirectory("rea-release-notes-");
interface ReleaseNotesSeed {
readonly directory: string;
readonly base: string;
readonly target: string;
}
let seed: ReleaseNotesSeed | undefined;
let seedWorkspaceRoot: string | undefined;
beforeAll(async () => {
const workspace = await createTestWorkspace("rea-release-notes-seed-");
seedWorkspaceRoot = workspace.root;
const directory = workspace.path("repository");
await mkdir(directory, { recursive: true });
await git(directory, ["init", "--initial-branch=main"]);
await writeFile(join(directory, "product.txt"), "base");
await writeFile(
@@ -142,6 +165,25 @@ process.stdout.write(JSON.stringify({data:{repository:result}}));
`,
);
await chmod(join(bin, "gh"), 0o755);
seed = { directory, base, target };
});
afterAll(async () => {
if (seedWorkspaceRoot !== undefined)
await removeTestWorkspace(seedWorkspaceRoot);
});
async function fixture() {
const initial = seed;
if (initial === undefined)
throw new Error("Release notes seed was not initialized");
const directory = await createTestTempDirectory("rea-release-notes-");
await cp(initial.directory, directory, {
recursive: true,
dereference: true,
});
const { base, target } = initial;
const bin = join(directory, "bin");
const manifest = join(directory, "inventory.json");
const invoke = (args: string[]) =>
exec(process.execPath, [cli, ...args], {