Files
rea/tests/evaluation/importCycleGuard.test.ts
morluto fb5b6d4abb test: assert the refusal each MCP, boundary and verifier check expects (#15531)
Replace bare toThrow() across the MCP, CLI and other boundary tests, the
Hopper and fixture conformance verifiers, the evaluation guards and the
process-global tests with the SDK cancellation code and reason, schema
issue paths, tagged error reasons, cleanup facts, errno codes and
verifier messages each case is meant to refuse.
2026-12-01 17:02:41 +00:00

36 lines
1.4 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it } from "vitest";
import { expectImportCycles } from "../fixtures/importCycles.js";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
it.each(["./self.js", "./%73elf.js?view=1#fragment"])(
"detects self-import %s and tracks its allowed edge",
async (specifier) => {
const root = await createTestTempDirectory("rea-import-cycle-");
await writeFile(
join(root, "self.ts"),
`import ${JSON.stringify(specifier)};\n`,
);
expect(() => expectImportCycles(root, [], [])).toThrow(
expect.objectContaining({ actual: ["self.ts"], expected: [] }),
);
expectImportCycles(root, [["self.ts"]], ["self.ts -> self.ts"]);
expect(() => expectImportCycles(root, [["self.ts"]], [])).toThrow(
expect.objectContaining({ actual: ["self.ts -> self.ts"], expected: [] }),
);
},
);
it("does not include cycles in test-only fixtures", async () => {
const root = await createTestTempDirectory("rea-import-cycle-");
await writeFile(
join(root, "sample.fixture.ts"),
'import "./sample.fixture.js";\n',
);
await writeFile(join(root, "sample.test.ts"), 'import "./sample.test.js";\n');
await writeFile(join(root, "sample.spec.ts"), 'import "./sample.spec.js";\n');
await writeFile(join(root, "production.ts"), "export const value = 1;\n");
expectImportCycles(root, [], []);
});