refactor: add incremental capability migration safeguards (#819)

This commit is contained in:
N0zoM1z0
2026-10-07 10:56:06 +08:00
committed by GitHub
parent 6caa38a0ca
commit 75f50d86f6
17 changed files with 421 additions and 66 deletions
@@ -0,0 +1,48 @@
import { describe, expect, it } from "vitest";
import { createCli } from "../../../src/cli.js";
import { createCliInventory } from "../../../scripts/lib/product-catalog.mjs";
import { TOOL_CONTRACTS } from "../../../src/contracts/toolContracts.js";
import {
CLI_COMMAND_ALIASES,
CLI_COMMAND_NAMES,
CLI_COMMAND_TOOL_ALIASES,
MCP_TOOLS_WITHOUT_DEDICATED_CLI,
} from "../../../src/cliCommandNames.js";
describe("CLI canonical tool coverage", () => {
it("accounts for every MCP tool on the CLI or marks it intentionally MCP-only", () => {
const registeredCli = createCliInventory(createCli());
const registeredCommandNames = new Set([
...registeredCli.primary,
...registeredCli.aliases.map(({ name }) => name),
]);
const cliToolNames = new Set(
registeredCli.primary.map((command) => command.replaceAll("-", "_")),
);
for (const [command, names] of Object.entries(CLI_COMMAND_TOOL_ALIASES)) {
expect(registeredCommandNames.has(command)).toBe(true);
for (const name of names) cliToolNames.add(name);
}
for (const command of CLI_COMMAND_NAMES)
expect(registeredCommandNames.has(command)).toBe(true);
for (const command of CLI_COMMAND_ALIASES)
expect(registeredCommandNames.has(command)).toBe(true);
const intentionalMcpOnly = new Set<string>(MCP_TOOLS_WITHOUT_DEDICATED_CLI);
expect(
[...intentionalMcpOnly].filter((name) => cliToolNames.has(name)).sort(),
).toEqual([]);
const unaccounted = TOOL_CONTRACTS.map(({ name }) => name).filter(
(name) => !cliToolNames.has(name) && !intentionalMcpOnly.has(name),
);
expect(unaccounted).toEqual([]);
expect(new Set(MCP_TOOLS_WITHOUT_DEDICATED_CLI).size).toBe(
MCP_TOOLS_WITHOUT_DEDICATED_CLI.length,
);
expect(
MCP_TOOLS_WITHOUT_DEDICATED_CLI.every((name) =>
TOOL_CONTRACTS.some((contract) => contract.name === name),
),
).toBe(true);
});
});
+44
View File
@@ -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");
});
});
+56
View File
@@ -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);
});
});