mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 17:23:37 +08:00
fix(test): resolve filesystem aliases before planning prerequisites (#10213)
This commit is contained in:
@@ -15,6 +15,7 @@ export function parseDevelopmentTestRequest(
|
||||
export function developmentTestPlan(
|
||||
request: DevelopmentTestRequest,
|
||||
baseCommit?: string,
|
||||
resolvedPaths?: readonly string[],
|
||||
): {
|
||||
readonly needsBuild: boolean;
|
||||
readonly artifactTasks: readonly string[];
|
||||
|
||||
@@ -58,7 +58,11 @@ const artifactConsumers = {
|
||||
};
|
||||
|
||||
/** Plan source feedback or explicit tests with their runtime/artifact prerequisites. */
|
||||
export const developmentTestPlan = (request, baseCommit) => {
|
||||
export const developmentTestPlan = (
|
||||
request,
|
||||
baseCommit,
|
||||
resolvedPaths = request.paths,
|
||||
) => {
|
||||
const explicit = request.paths.length > 0;
|
||||
if (
|
||||
request.mode === "changed" &&
|
||||
@@ -70,12 +74,12 @@ export const developmentTestPlan = (request, baseCommit) => {
|
||||
? []
|
||||
: SOURCE_TEST_PROJECTS.map(({ name }) => name);
|
||||
return {
|
||||
needsBuild: request.paths.some(
|
||||
needsBuild: resolvedPaths.some(
|
||||
(path) => projectForTest(path).group === "built",
|
||||
),
|
||||
artifactTasks: Object.entries(artifactConsumers).flatMap(
|
||||
([task, consumers]) =>
|
||||
request.paths.some((path) => consumers.includes(path)) ? [task] : [],
|
||||
resolvedPaths.some((path) => consumers.includes(path)) ? [task] : [],
|
||||
),
|
||||
vitestArguments: [
|
||||
"run",
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { stat } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import { realpath, stat } from "node:fs/promises";
|
||||
import { relative, resolve, sep } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import {
|
||||
developmentTestPlan,
|
||||
parseDevelopmentTestRequest,
|
||||
} from "./lib/development-tests.mjs";
|
||||
import { projectForTest } from "./lib/test-projects.mjs";
|
||||
|
||||
let child;
|
||||
let forceTimer;
|
||||
@@ -29,9 +30,22 @@ for (const signal of Object.keys(signalExitCodes))
|
||||
try {
|
||||
const [mode, ...arguments_] = process.argv.slice(2);
|
||||
const request = parseDevelopmentTestRequest(mode, arguments_);
|
||||
const resolvedPaths = [];
|
||||
const repository = await realpath(".");
|
||||
for (const path of request.paths) {
|
||||
if (!(await stat(path)).isFile())
|
||||
throw new Error(`Test path is not a file: ${path}`);
|
||||
// Ownership follows the filesystem's canonical spelling. Execution keeps
|
||||
// the caller path so exact discovery still rejects excluded symlink aliases.
|
||||
const resolvedPath = relative(repository, await realpath(path))
|
||||
.split(sep)
|
||||
.join("/");
|
||||
if (
|
||||
request.mode !== "focused" &&
|
||||
projectForTest(resolvedPath).group !== "source"
|
||||
)
|
||||
throw new Error(`Use test:focused for built test projects: ${path}`);
|
||||
resolvedPaths.push(resolvedPath);
|
||||
}
|
||||
let baseCommit;
|
||||
if (request.mode === "changed") {
|
||||
@@ -42,7 +56,7 @@ try {
|
||||
);
|
||||
baseCommit = base.output.trim();
|
||||
}
|
||||
const plan = developmentTestPlan(request, baseCommit);
|
||||
const plan = developmentTestPlan(request, baseCommit, resolvedPaths);
|
||||
if (request.dryRun) {
|
||||
console.log(JSON.stringify({ ...request, baseCommit, ...plan }, null, 2));
|
||||
} else {
|
||||
|
||||
@@ -163,6 +163,74 @@ describe("development test runner symlink aliases", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("development test runner prerequisite ownership", () => {
|
||||
it("prepares artifacts for filesystem aliases without folding distinct filenames", async () => {
|
||||
const root = await fixture();
|
||||
const canonical = "tests/boundary/mcp/deferredRuntime.test.ts";
|
||||
const selected = "tests/boundary/mcp/DEFERREDRuntime.test.ts";
|
||||
await mkdir(join(root, "tests/boundary/mcp"), { recursive: true });
|
||||
await writeFile(
|
||||
join(root, canonical),
|
||||
"// Artifact-consuming test fixture\n",
|
||||
);
|
||||
let sameFile = true;
|
||||
try {
|
||||
await lstat(join(root, selected));
|
||||
} catch (cause) {
|
||||
if (
|
||||
!(cause instanceof Error) ||
|
||||
!("code" in cause) ||
|
||||
cause.code !== "ENOENT"
|
||||
)
|
||||
throw cause;
|
||||
sameFile = false;
|
||||
await writeFile(join(root, selected), "// Distinct test fixture\n");
|
||||
}
|
||||
for (const path of [canonical, selected]) {
|
||||
const result = await testCommand(root, "focused", path, "--dry-run");
|
||||
expect(JSON.parse(result.stdout)).toMatchObject({
|
||||
paths: [path],
|
||||
needsBuild: true,
|
||||
artifactTasks:
|
||||
path === canonical || sameFile ? ["artifacts:mcp-catalog"] : [],
|
||||
vitestArguments: ["run", path],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("retains built-project admission for an aliased provider conformance test", async ({
|
||||
skip,
|
||||
}) => {
|
||||
const root = await fixture();
|
||||
const directory = "tests/conformance/providers/hopper";
|
||||
const canonical = `${directory}/realHopperSearch.test.ts`;
|
||||
const selected = `${directory}/REALHopperSearch.test.ts`;
|
||||
await mkdir(join(root, directory), { recursive: true });
|
||||
await writeFile(join(root, canonical), "// Built conformance fixture\n");
|
||||
try {
|
||||
await lstat(join(root, selected));
|
||||
} catch (cause) {
|
||||
if (cause instanceof Error && "code" in cause && cause.code === "ENOENT")
|
||||
skip("The host distinguishes the selected filename casing");
|
||||
throw cause;
|
||||
}
|
||||
const result = await testCommand(root, "focused", selected, "--dry-run");
|
||||
expect(JSON.parse(result.stdout)).toMatchObject({
|
||||
paths: [selected],
|
||||
needsBuild: true,
|
||||
vitestArguments: ["run", selected],
|
||||
});
|
||||
await expect(
|
||||
testCommand(root, "local", selected, "--dry-run"),
|
||||
).rejects.toMatchObject({
|
||||
code: 1,
|
||||
stderr: expect.stringContaining(
|
||||
`Use test:focused for built test projects: ${selected}`,
|
||||
),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("development test runner exact selection", () => {
|
||||
it("matches selected path casing to the host filesystem", async () => {
|
||||
const root = await fixture();
|
||||
|
||||
Reference in New Issue
Block a user