test(cli): consolidate JSON document admission and path checks (#13052)

* test(cli): consolidate JSON document admission checks

* test(cli): retain caller path checks at the provider boundary
This commit is contained in:
morluto authored and GitHub committed 2026-11-21 04:03:19 -05:00
1 parent 243b9a37f6
commit cf87e474eb
3 files changed
+51 -131

No files matched your search

+15 -68
View File
@@ -1,8 +1,6 @@
import { mkdir, symlink } from "node:fs/promises";
import { join, resolve } from "node:path";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";
import { createTestTempDirectory } from "../tests/fixtures/temporaryDirectory.js";
import {
cliJsonCallerPathSchema,
@@ -26,31 +24,23 @@ describe("CLI JSON path normalization", () => {
});
},
);
it.each([
["executable_path", ""],
["executable_path", " \t "],
["application_path", ""],
["application_path", " \t "],
["application_root", ""],
["application_root", " \t "],
])(
"keeps blank %s (%j) invalid at the shared input boundary",
(field, value) => {
const input = {
executable_path: "/synthetic/electron",
application_path: "/synthetic/app",
application_root: "/synthetic",
[field]: value,
};
const parsed = electronActiveObservationInputSchema.safeParse(
resolveCliJsonPaths(input, paths),
);
expect(parsed.success).toBe(false);
it.each(["", " \t "])(
"keeps blank Electron paths %j invalid after normalization",
(value) => {
const input = Object.freeze({
executable_path: value,
application_path: value,
application_root: value,
});
const normalized = resolveCliJsonPaths(input, paths);
expect(normalized).toEqual(input);
const parsed = electronActiveObservationInputSchema.safeParse(normalized);
if (parsed.success) throw new Error("Expected blank path rejection");
expect(parsed.error.issues).toEqual(
expect.arrayContaining([expect.objectContaining({ path: [field] })]),
expect.arrayContaining(
paths.map((path) => expect.objectContaining({ path })),
),
);
expect(input).toHaveProperty(field, value);
},
);
@@ -71,49 +61,6 @@ describe("CLI JSON path normalization", () => {
expect(input.browser.executable_path).toBe(" browser ");
});
it.skipIf(process.platform === "win32")(
"keeps POSIX symlink-parent traversal for each selected JSON path",
async () => {
const root = await createTestTempDirectory("rea-json-caller-path-");
const originalCwd = process.cwd();
try {
await mkdir(join(root, "real/inner"), { recursive: true });
await symlink(join(root, "real/inner"), join(root, "link"));
process.chdir(root);
const electronInput = {
executable_path: "link/../tool",
application_path: "link/../app",
application_root: "link/../root",
};
const normalizedElectron = resolveCliJsonPaths(electronInput, paths);
expect(normalizedElectron).toEqual({
executable_path: `${root}/link/../tool`,
application_path: `${root}/link/../app`,
application_root: `${root}/link/../root`,
});
expect(electronInput.executable_path).toBe("link/../tool");
expect(
electronActiveObservationInputSchema.safeParse(normalizedElectron)
.success,
).toBe(true);
const browserInput = {
browser: { executable_path: "link/../browser", label: "keep" },
};
expect(
resolveCliJsonPaths(browserInput, [["browser", "executable_path"]]),
).toEqual({
browser: {
executable_path: `${root}/link/../browser`,
label: "keep",
},
});
expect(browserInput.browser.executable_path).toBe("link/../browser");
} finally {
process.chdir(originalCwd);
}
},
);
it.each([
"file:///opt/electron",
"FILE:electron",
+5 -24
View File
@@ -342,7 +342,7 @@ it("advertises caller paths as local spellings the CLI resolves, not URLs", asyn
expect(validate(document(path)), path).toBe(false);
});
it("validates representative parsed documents with the advertised schema", async () => {
it("advertises coverage input that admits a complete document and checks its boundary", async () => {
const input = advertisedInput(
(
await serve([
@@ -380,8 +380,11 @@ it("validates representative parsed documents with the advertised schema", async
boundaries: [],
};
const accepted = { coverage, boundary_id: "main" };
const { boundaries: _boundaries, ...withoutBoundaries } = coverage;
const rejected = [
{ coverage, boundary_id: "" },
{ coverage, boundary_id: "main section" },
{ ...accepted, coverage: withoutBoundaries },
{ coverage },
{ coverage, boundary_id: "main", extra: true },
{ coverage: { arbitrary: true }, boundary_id: "main" },
@@ -458,29 +461,7 @@ it("names the feature-trace, semantic-query, and browser-scenario fields", async
);
});
it("advertises the reconstruction documents their readers admit", async () => {
const coverage = advertisedInput(
(
await serve([
cliCommandFor("evaluate_reconstruction_coverage"),
"--schema",
"--json",
])
).stdout,
);
// The reader authenticates the embedded bundle, but --schema still shows
// the document it admits, as the MCP contract does.
expect(coverage.contentSchema?.properties?.coverage).toMatchObject({
type: "object",
required: expect.arrayContaining(["evidence_bundle", "boundaries"]),
});
// boundary_id is a stable identifier (#9919), so its pattern is advertised.
expect(coverage.contentSchema?.properties?.boundary_id).toMatchObject({
type: "string",
pattern: expect.any(String),
});
expect(coverage.contentSchema?.required).toEqual(["coverage", "boundary_id"]);
it("advertises the reconstruction obligation ledger its reader admits", async () => {
const ledger = advertisedInput(
(
await serve([
+31 -39
View File
@@ -136,45 +136,36 @@ describe("compiled CLI JSON document omissions", () => {
expect(result.exitCode).toBe(1);
});
// Delivery is chosen by options beside the document; a delivery field in
// the document names its option instead of being dropped or misread.
for (const [command, operation, field, message] of [
[
"compare-static-and-observed-endpoints",
"compare_static_and_observed_endpoints",
"detail",
"pass --detail beside it",
],
[
"compare-static-and-observed-endpoints",
"compare_static_and_observed_endpoints",
"view",
"pass --view beside it",
],
[
"capture-browser-scenario",
"capture_browser_scenario",
"detail",
"pass --detail beside it",
],
[
"validate-browser-scenario",
"capture_browser_scenario",
"detail",
"pass --detail to capture-browser-scenario",
],
] as const)
// Delivery fields belong beside the document. The endpoints command
// reports both misplacements together, while validation points to capture.
for (const { command, operation, document, hints } of [
{
command: "compare-static-and-observed-endpoints",
operation: "compare_static_and_observed_endpoints",
document: { detail: "summary", view: { collection: "matches" } },
hints: {
detail: "pass --detail beside it",
view: "pass --view beside it",
},
},
{
command: "capture-browser-scenario",
operation: "capture_browser_scenario",
document: { detail: "summary" },
hints: { detail: "pass --detail beside it" },
},
{
command: "validate-browser-scenario",
operation: "capture_browser_scenario",
document: { detail: "summary" },
hints: { detail: "pass --detail to capture-browser-scenario" },
},
])
cliTest(
`${command} refuses ${field} inside the document`,
`${command} reports each misplaced delivery field`,
async ({ cli }) => {
const result = await cli.run({
arguments: [
command,
JSON.stringify({
[field]: field === "view" ? { collection: "matches" } : "summary",
}),
"--json",
],
arguments: [command, JSON.stringify(document), "--json"],
environment: isolatedHomeEnvironment,
});
expect(result.json).toMatchObject({
@@ -182,9 +173,10 @@ describe("compiled CLI JSON document omissions", () => {
category: "invalid_input",
details: {
operation,
issues: [
{ path: [field], message: expect.stringContaining(message) },
],
issues: Object.entries(hints).map(([field, message]) => ({
path: [field],
message: expect.stringContaining(message),
})),
},
});
expect(result.exitCode).toBe(1);