refactor: add incremental capability migration safeguards (#819)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { copyFile, mkdir, writeFile } from "node:fs/promises";
|
||||
import { dirname, join, resolve } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||
|
||||
describe("incremental module import boundaries", () => {
|
||||
it.each([
|
||||
["src/domain/probe.ts", "../application/Workflow.js", false],
|
||||
["src/domain/probe.ts", "../browser/Provider.js", false],
|
||||
["src/contracts/probe.ts", "../android/Provider.js", false],
|
||||
["src/contracts/probe.ts", "../cli.js", false],
|
||||
["src/domain/probe.ts", "./result.js", true],
|
||||
["src/contracts/probe.ts", "../domain/result.js", true],
|
||||
["src/application/probe.ts", "../domain/result.js", true],
|
||||
["src/composition/probe.ts", "../ghidra/Provider.js", true],
|
||||
])("checks %s importing %s", async (file, dependency, allowed) => {
|
||||
const temporary = await createTestTempDirectory("rea-module-boundary-");
|
||||
const config = join(temporary, ".oxlintrc.json");
|
||||
await copyFile(resolve(".oxlintrc.json"), config);
|
||||
const fixture = join(temporary, file);
|
||||
await mkdir(dirname(fixture), { recursive: true });
|
||||
await writeFile(
|
||||
fixture,
|
||||
`import { value } from ${JSON.stringify(dependency)}; export { value };\n`,
|
||||
);
|
||||
const result = spawnSync(
|
||||
process.execPath,
|
||||
[
|
||||
resolve("node_modules/oxlint/bin/oxlint"),
|
||||
"-c",
|
||||
config,
|
||||
"--format",
|
||||
"json",
|
||||
file,
|
||||
],
|
||||
{ cwd: temporary, encoding: "utf8" },
|
||||
);
|
||||
if (result.error !== undefined) throw result.error;
|
||||
expect(result.status).toBe(allowed ? 0 : 1);
|
||||
if (!allowed) expect(result.stdout).toContain("no-restricted-imports");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import { resolve } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { compareTestDiscovery } from "../../scripts/lib/test-discovery.mjs";
|
||||
|
||||
const root = resolve("test-discovery-fixture");
|
||||
const first = "src/domain/sample.test.ts";
|
||||
const second = "src/new-provider/sample.test.ts";
|
||||
|
||||
describe("test discovery migration guard", () => {
|
||||
it("accepts absolute discovered paths without changing their project ownership", () => {
|
||||
expect(
|
||||
compareTestDiscovery(
|
||||
[first],
|
||||
[{ file: resolve(root, first), projectName: "domain" }],
|
||||
root,
|
||||
),
|
||||
).toEqual({ missing: [], unexpected: [], duplicates: [], discovered: 1 });
|
||||
});
|
||||
|
||||
it("reports a new provider test omitted by the current project globs", () => {
|
||||
expect(
|
||||
compareTestDiscovery(
|
||||
[first, second],
|
||||
[{ file: first, projectName: "domain" }],
|
||||
root,
|
||||
).missing,
|
||||
).toEqual([second]);
|
||||
});
|
||||
|
||||
it("reports overlapping project discovery and unexpected files separately", () => {
|
||||
const report = compareTestDiscovery(
|
||||
[first],
|
||||
[
|
||||
{ file: first, projectName: "domain" },
|
||||
{ file: first, projectName: "adapters" },
|
||||
{ file: second, projectName: "adapters" },
|
||||
],
|
||||
root,
|
||||
);
|
||||
expect(report.duplicates).toEqual([
|
||||
{ file: first, projects: ["adapters", "domain"] },
|
||||
]);
|
||||
expect(report.unexpected).toEqual([second]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
null,
|
||||
{},
|
||||
[{ file: "", projectName: "domain" }],
|
||||
[{ file: first }],
|
||||
[{ file: first, projectName: null }],
|
||||
])("rejects malformed producer output: %j", (input) => {
|
||||
expect(() => compareTestDiscovery([first], input, root)).toThrow(TypeError);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user