Files
reverse-engineering-anything/scripts/lib/development-tests.mjs
T
morluto 0a9e736aea refactor(mcp): bind web script export, guidance, Cutter discovery and session status through the shared binding table (#11400)
* refactor(mcp): bind web script export through the shared service binding table

* refactor(mcp): give SDK-admitted bindings their contract's parsed input type

* refactor(mcp): type SDK-admitted bindings by the contract's request frame

* refactor(mcp): bind guidance, Cutter discovery and session status as value-returning bindings (#11439)

The shared binding table gains a value binding kind for contracts that return a plain JSON value rather than Evidence. It logs and delivers against the contract's output schema, records no Evidence and runs outside analysis admission, so provider-free guidance stays outside admission even though the shared dependencies carry one.

search_guidance, read_guidance_section, list_cutter_sessions and binary_session move onto it; registerGuidanceTools.ts is deleted and registerSessionStatusTool.ts becomes the sessionStatusTool.ts reader its binding calls.
2026-11-16 04:50:58 +08:00

98 lines
3.6 KiB
JavaScript

import { SOURCE_TEST_PROJECTS, projectForTest } from "./test-projects.mjs";
/** Parse explicit test paths and an optional branch-comparison base. */
export const parseDevelopmentTestRequest = (mode, arguments_) => {
if (!["local", "changed", "focused"].includes(mode))
throw new Error("Expected local, changed, or focused test mode");
const paths = [];
let base = "origin/main";
let dryRun = false;
for (let index = 0; index < arguments_.length; index += 1) {
const argument = arguments_[index];
if (argument === "--dry-run") dryRun = true;
else if (argument === "--base" || argument.startsWith("--base=")) {
if (mode !== "changed") throw new Error("--base requires changed mode");
base = argument === "--base" ? arguments_[++index] : argument.slice(7);
if (!base || base.startsWith("-") || base.includes("\0"))
throw new Error("--base requires a Git revision");
} else {
const path = argument.replaceAll("\\", "/").replace(/^\.\//u, "");
if (
!/^(?:src|tests)\/.+\.test\.ts$/u.test(path) ||
path.split("/").some((part) => part === ".." || part === ".")
)
throw new Error(`Expected an exact repository test path: ${argument}`);
const project = projectForTest(path);
if (mode !== "focused" && project.group !== "source")
throw new Error(`Use test:focused for built test projects: ${path}`);
paths.push(path);
}
}
if (mode === "focused" && paths.length === 0)
throw new Error("test:focused requires at least one exact test path");
if (mode === "changed" && paths.length > 0)
throw new Error("Use test:focused for explicit test paths");
return { mode, paths: [...new Set(paths)], base, dryRun };
};
// Test-only outputs are declared beside the test planner rather than becoming
// runtime or typecheck prerequisites. Add a consumer here when it reads one.
const artifactConsumers = {
"artifacts:skills": [
"tests/boundary/cli/guidanceCli.test.ts",
"tests/boundary/guidanceSearch.test.ts",
"tests/boundary/mcp/guidanceMcp.test.ts",
],
"artifacts:mcp-catalog": [
"tests/boundary/mcp/deferredRuntime.test.ts",
"tests/boundary/mcp/contractPresentation.test.ts",
"tests/boundary/mcp/generatedToolCatalog.test.ts",
],
"artifacts:product-catalog": [
"tests/boundary/filesystem/documentationFacts.test.ts",
"tests/boundary/filesystem/productCatalog.test.ts",
],
"artifacts:managed-evidence": [
"tests/boundary/filesystem/setupSkill.test.ts",
],
};
/** Plan source feedback or explicit tests with their runtime/artifact prerequisites. */
export const developmentTestPlan = (
request,
baseCommit,
resolvedPaths = request.paths,
) => {
const explicit = request.paths.length > 0;
if (
request.mode === "changed" &&
!/^[a-f0-9]{40,64}$/u.test(baseCommit ?? "")
)
throw new Error("Changed tests require a resolved Git merge base");
const projects =
request.mode === "focused"
? []
: SOURCE_TEST_PROJECTS.map(({ name }) => name);
return {
needsBuild: resolvedPaths.some(
(path) => projectForTest(path).group === "built",
),
artifactTasks: Object.entries(artifactConsumers).flatMap(
([task, consumers]) =>
resolvedPaths.some((path) => consumers.includes(path)) ? [task] : [],
),
vitestArguments: [
"run",
...projects.flatMap((project) => ["--project", project]),
...(explicit
? request.paths
: [
request.mode === "changed"
? `--changed=${baseCommit}`
: "--changed",
"--passWithNoTests",
]),
],
};
};