mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 21:53:51 +00:00
test: own temporary directories through createTestTempDirectory in remaining tests/ (#12727)
* test: own temporary directories through createTestTempDirectory in remaining tests/ Give per-test directories in the remaining tests/ suites to createTestTempDirectory so onTestFinished removes them through removeTestWorkspace. Keep suite-scoped roots and child-process directories whose removal is the assertion. * test: drop empty cleanup callbacks and keep the capture skip reason visible Remove the no-op withVerifierCleanup steps left after directory removal moved to createTestTempDirectory. Put the native capture skip explanation in the Linux sample test name, because it.skipIf only tests truthiness. Co-authored-by: morluto <morluto@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
This commit is contained in:
46 files changed
+1487
-1738
No files matched your search
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { expect, it } from "vitest";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const posix = it.skipIf(process.platform === "win32");
|
||||
posix.each([
|
||||
@@ -16,15 +17,14 @@ posix.each([
|
||||
] as const)(
|
||||
"requires CommandCode skill proof for %s",
|
||||
async (mode, allowed) => {
|
||||
const state = await mkdtemp(join(tmpdir(), "rea-commandcode-skill-"));
|
||||
try {
|
||||
const account = join(state, "account");
|
||||
await mkdir(account);
|
||||
await writeFile(
|
||||
join(account, ".rea-client-verification"),
|
||||
"Disposable REA client verification account\n",
|
||||
);
|
||||
const commands = String.raw`
|
||||
const state = await createTestTempDirectory("rea-commandcode-skill-");
|
||||
const account = join(state, "account");
|
||||
await mkdir(account);
|
||||
await writeFile(
|
||||
join(account, ".rea-client-verification"),
|
||||
"Disposable REA client verification account\n",
|
||||
);
|
||||
const commands = String.raw`
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { TOOL_CONTRACTS } from REPLACE_CONTRACTS;
|
||||
@@ -74,66 +74,61 @@ export async function createVerifierCommands() {
|
||||
};
|
||||
}
|
||||
`.replace(
|
||||
"REPLACE_CONTRACTS",
|
||||
JSON.stringify(
|
||||
new URL("../../../dist/contracts/toolContracts.js", import.meta.url)
|
||||
.href,
|
||||
),
|
||||
);
|
||||
await writeFile(join(state, "commands.mjs"), commands);
|
||||
await writeFile(
|
||||
join(state, "fixture.mjs"),
|
||||
"export async function createOpenAiModelFixture({onRequest}){globalThis.fakeRequest=onRequest;return {baseUrl:'http://127.0.0.1:1',async close(){}};}\n",
|
||||
);
|
||||
await writeFile(
|
||||
join(state, "hook.mjs"),
|
||||
"import{registerHooks}from'node:module';import{pathToFileURL}from'node:url';registerHooks({resolve(specifier,context,next){if(context.parentURL?.endsWith('/scripts/verify-commandcode-client.mjs')){let f;if(specifier==='node:os')f='os.mjs';if(specifier==='./lib/verify-commands.mjs')f='commands.mjs';if(specifier==='./verify/clients/model-fixture.mjs')f='fixture.mjs';if(f)return{url:pathToFileURL(process.env.STATE+'/'+f).href,shortCircuit:true};}return next(specifier,context);}});\n",
|
||||
);
|
||||
await writeFile(
|
||||
join(state, "os.mjs"),
|
||||
"export * from 'node:os';export function homedir(){return process.env.REA_VERIFY_COMMANDCODE_ACCOUNT_HOME;}\n",
|
||||
);
|
||||
const script = fileURLToPath(
|
||||
new URL(
|
||||
"../../../scripts/verify-commandcode-client.mjs",
|
||||
import.meta.url,
|
||||
),
|
||||
);
|
||||
const result = spawnSync(
|
||||
process.execPath,
|
||||
["--import", join(state, "hook.mjs"), script],
|
||||
{
|
||||
encoding: "utf8",
|
||||
timeout: 10_000,
|
||||
env: {
|
||||
...process.env,
|
||||
STATE: state,
|
||||
MODE: mode,
|
||||
REA_VERIFY_COMMANDCODE_ACCOUNT_HOME: account,
|
||||
},
|
||||
"REPLACE_CONTRACTS",
|
||||
JSON.stringify(
|
||||
new URL("../../../dist/contracts/toolContracts.js", import.meta.url)
|
||||
.href,
|
||||
),
|
||||
);
|
||||
await writeFile(join(state, "commands.mjs"), commands);
|
||||
await writeFile(
|
||||
join(state, "fixture.mjs"),
|
||||
"export async function createOpenAiModelFixture({onRequest}){globalThis.fakeRequest=onRequest;return {baseUrl:'http://127.0.0.1:1',async close(){}};}\n",
|
||||
);
|
||||
await writeFile(
|
||||
join(state, "hook.mjs"),
|
||||
"import{registerHooks}from'node:module';import{pathToFileURL}from'node:url';registerHooks({resolve(specifier,context,next){if(context.parentURL?.endsWith('/scripts/verify-commandcode-client.mjs')){let f;if(specifier==='node:os')f='os.mjs';if(specifier==='./lib/verify-commands.mjs')f='commands.mjs';if(specifier==='./verify/clients/model-fixture.mjs')f='fixture.mjs';if(f)return{url:pathToFileURL(process.env.STATE+'/'+f).href,shortCircuit:true};}return next(specifier,context);}});\n",
|
||||
);
|
||||
await writeFile(
|
||||
join(state, "os.mjs"),
|
||||
"export * from 'node:os';export function homedir(){return process.env.REA_VERIFY_COMMANDCODE_ACCOUNT_HOME;}\n",
|
||||
);
|
||||
const script = fileURLToPath(
|
||||
new URL(
|
||||
"../../../scripts/verify-commandcode-client.mjs",
|
||||
import.meta.url,
|
||||
),
|
||||
);
|
||||
const result = spawnSync(
|
||||
process.execPath,
|
||||
["--import", join(state, "hook.mjs"), script],
|
||||
{
|
||||
encoding: "utf8",
|
||||
timeout: 10_000,
|
||||
env: {
|
||||
...process.env,
|
||||
STATE: state,
|
||||
MODE: mode,
|
||||
REA_VERIFY_COMMANDCODE_ACCOUNT_HOME: account,
|
||||
},
|
||||
);
|
||||
expect(result.status).not.toBe(0);
|
||||
const observed = await readFile(
|
||||
join(state, "observed.json"),
|
||||
"utf8",
|
||||
).then(JSON.parse, () => null);
|
||||
expect(observed !== null).toBe(allowed);
|
||||
if (allowed)
|
||||
expect(observed.second.tool_calls[0].function.name).toBe(
|
||||
"search_tools",
|
||||
);
|
||||
expect(result.stderr).toContain(
|
||||
allowed
|
||||
? "intentional stop before client output"
|
||||
: mode === "empty"
|
||||
? "Installed skill must have authored frontmatter"
|
||||
: mode === "empty body"
|
||||
? "Installed skill body must not be empty"
|
||||
: "The model must receive the complete activated skill body",
|
||||
);
|
||||
} finally {
|
||||
await rm(state, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
);
|
||||
expect(result.status).not.toBe(0);
|
||||
const observed = await readFile(join(state, "observed.json"), "utf8").then(
|
||||
JSON.parse,
|
||||
() => null,
|
||||
);
|
||||
expect(observed !== null).toBe(allowed);
|
||||
if (allowed)
|
||||
expect(observed.second.tool_calls[0].function.name).toBe("search_tools");
|
||||
expect(result.stderr).toContain(
|
||||
allowed
|
||||
? "intentional stop before client output"
|
||||
: mode === "empty"
|
||||
? "Installed skill must have authored frontmatter"
|
||||
: mode === "empty body"
|
||||
? "Installed skill body must not be empty"
|
||||
: "The model must receive the complete activated skill body",
|
||||
);
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user