Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

test(ci): keep module mocks in isolated test projects (#5886)

Kaoru08226d356b843446
diff --git a/tests/boundary/filesystem/ciTestProjects.test.ts b/tests/boundary/filesystem/ciTestProjects.test.ts
index 0159a3910..1f20ef2d9 100644
--- a/tests/boundary/filesystem/ciTestProjects.test.ts
+++ b/tests/boundary/filesystem/ciTestProjects.test.ts
@@ -141,3 +141,44 @@ describe("canonical test-project ownership", () => {
},
);
});
+
+describe("test module isolation", () => {
+ it("keeps module mocks out of projects that share one module graph", async () => {
+ // A mock registered after another file in the same worker loaded the
+ // module never applies, so the test's outcome depends on file scheduling.
+ const root = await createTestTempDirectory("rea-vitest-mock-isolation-");
+ const script = join(root, "project-isolation.mjs");
+ await writeFile(
+ script,
+ `
+ import config from ${JSON.stringify(pathToFileURL(join(repository, "vitest.config.ts")).href)};
+ console.log(JSON.stringify(Object.fromEntries(
+ config.test.projects.map(project => [project.test.name, project.test.isolate !== false]),
+ )));
+ `,
+ );
+ const result = await execFileOutput(
+ process.execPath,
+ ["--import", "tsx", script],
+ {
+ cwd: repository,
+ timeout: 10_000,
+ maxBuffer: 64 * 1024,
+ stopSignal: "SIGTERM",
+ },
+ );
+ const isolated = JSON.parse(result.stdout) as Record<string, boolean>;
+ const mocking = execFileSync(
+ "git",
+ ["grep", "-l", "-E", String.raw`vi\.(mock|doMock)\(`, "--", "*.test.ts"],
+ { cwd: repository, encoding: "utf8" },
+ )
+ .trim()
+ .split("\n")
+ .filter(Boolean);
+ expect(mocking.length).toBeGreaterThan(0);
+ expect(
+ mocking.filter((file) => isolated[projectForTest(file).name] !== true),
+ ).toEqual([]);
+ });
+});
diff --git a/src/application/DirectAnalysisStatFailure.test.ts b/tests/process-global/directAnalysisStatFailure.test.ts
similarity index 90%
rename from src/application/DirectAnalysisStatFailure.test.ts
rename to tests/process-global/directAnalysisStatFailure.test.ts
index 0d82f7b49..510cc8eea 100644
--- a/src/application/DirectAnalysisStatFailure.test.ts
+++ b/tests/process-global/directAnalysisStatFailure.test.ts
@@ -14,11 +14,11 @@ vi.mock("node:fs/promises", async (importOriginal) => {
};
});
-import { parseConfig } from "../config/parseConfig.js";
-import { classifyBinaryTargetFilesystemFailure } from "./BinaryTargetResolver.js";
-import type { BinarySession } from "./binary/BinarySession.js";
-import type { DirectAnalysisDependencies } from "./DirectAnalysisDependencies.js";
-import { runProviderAnalysis } from "./DirectAnalysis.js";
+import { parseConfig } from "../../src/config/parseConfig.js";
+import { classifyBinaryTargetFilesystemFailure } from "../../src/application/BinaryTargetResolver.js";
+import type { BinarySession } from "../../src/application/binary/BinarySession.js";
+import type { DirectAnalysisDependencies } from "../../src/application/DirectAnalysisDependencies.js";
+import { runProviderAnalysis } from "../../src/application/DirectAnalysis.js";
afterEach(() => statFailures.clear());