test(artifacts): consolidate inventory view coverage (#12871)

This commit is contained in:
morluto authored and GitHub committed 2026-11-20 15:48:58 +00:00
1 parent 234cae0592
commit 5486394715
2 files changed
+72 -100

No files matched your search

@@ -135,73 +135,72 @@ it.each(["node_count", "occurrence_count", "edge_count"] as const)(
},
);
it("batches exact occurrence IDs in source order while retaining linkage with no selected fields", () => {
it("intersects and deduplicates exact occurrence IDs and paths before paging in source order", () => {
const inventory = freshInventory();
const selected = inventory.occurrences.slice(0, 2);
expect(selected).toHaveLength(2);
const result = page(parent(inventory), {
const [root, child] = inventory.occurrences;
if (root === undefined || child === undefined)
throw new Error("Expected root and child occurrences");
const source = parent(inventory);
const selection = {
kind: "inventory",
collection: "occurrences",
occurrence_ids: [...selected]
.reverse()
.flatMap((row) => [row.occurrence_id, row.occurrence_id]),
fields: [],
occurrence_ids: [
child.occurrence_id,
root.occurrence_id,
child.occurrence_id,
],
logical_paths: [child.logical_path, root.logical_path],
limit: 1,
};
const first = page(source, { ...selection, fields: [] });
expect(first.items).toEqual([
{
occurrence_id: root.occurrence_id,
artifact_id: root.artifact_id,
parent_occurrence_id: root.parent_occurrence_id,
},
]);
expect(first.coverage).toMatchObject({
total: 2,
examined: 1,
next_offset: 1,
});
expect(result.items).toEqual(
selected.map((row) => ({
occurrence_id: row.occurrence_id,
artifact_id: row.artifact_id,
parent_occurrence_id: row.parent_occurrence_id,
})),
);
expect(result.coverage.total).toBe(2);
});
it("intersects exact IDs and paths, then pages the filtered order", () => {
const inventory = freshInventory();
const selected = inventory.occurrences.slice(0, 2);
const result = page(parent(inventory), {
kind: "inventory",
collection: "occurrences",
occurrence_ids: selected.map((row) => row.occurrence_id),
logical_paths: selected.map((row) => row.logical_path),
const next = page(source, {
...selection,
fields: ["logical_path"],
offset: 1,
limit: 1,
});
expect(result.items).toEqual([
expect.objectContaining({
occurrence_id: selected[1]?.occurrence_id,
logical_path: selected[1]?.logical_path,
}),
expect(next.items).toEqual([
{
occurrence_id: child.occurrence_id,
artifact_id: child.artifact_id,
parent_occurrence_id: root.occurrence_id,
logical_path: child.logical_path,
},
]);
expect(result.coverage).toMatchObject({
expect(next.coverage).toMatchObject({
total: 2,
examined: 1,
next_offset: null,
});
expect(
page(parent(inventory), {
kind: "inventory",
collection: "occurrences",
occurrence_ids: [selected[0]!.occurrence_id],
logical_paths: [selected[1]!.logical_path],
page(source, {
...selection,
occurrence_ids: [root.occurrence_id],
logical_paths: [child.logical_path],
}).items,
).toEqual([]);
});
it.each([{ occurrence_ids: [] }, { logical_paths: [] }])(
"keeps an explicitly empty occurrence selection empty",
(filter) => {
expect(
page(parent(freshInventory()), {
kind: "inventory",
collection: "occurrences",
...filter,
}).items,
).toEqual([]);
},
);
it("keeps an explicitly empty occurrence ID selection empty", () => {
expect(
page(parent(freshInventory()), {
kind: "inventory",
collection: "occurrences",
occurrence_ids: [],
}).items,
).toEqual([]);
});
it("fetches only selected content identities and fields, in canonical node order", () => {
const inventory = freshInventory();
@@ -274,25 +273,6 @@ it("reads absent historical relationship coverage as unknown without changing th
expect(inventory.occurrences[0]).not.toHaveProperty("relationship_coverage");
});
it("borrows authenticated immutable facts and validates once across retained queries", () => {
const inventory = freezeJsonSnapshot(freshInventory());
const source = parent(inventory);
const parse = vi.spyOn(artifactInventoryResultSchema, "parse");
const first = page(source, {
kind: "inventory",
collection: "occurrences",
limit: 1,
});
expect(first.items[0]).toBe(inventory.occurrences[0]);
expect(parse).toHaveBeenCalledOnce();
page(source, {
kind: "inventory",
collection: "nodes",
artifact_ids: [inventory.nodes[0]!.artifact_id],
});
expect(parse).toHaveBeenCalledOnce();
});
it("does not reuse validation for a mutable object carrying a forged sealing flag", () => {
const inventory = freshInventory();
const source = parent(inventory);
@@ -303,30 +283,26 @@ it("does not reuse validation for a mutable object carrying a forged sealing fla
).toThrow();
});
it("keeps a missing match unknown when retained inventory pages are partial", () => {
const inventory = freshInventory();
inventory.occurrences = inventory.occurrences.slice(0, 1);
const result = page(parent(inventory), {
kind: "inventory",
collection: "occurrences",
logical_paths: ["not-recorded"],
});
expect(result.source_complete).toBe(false);
expect(result.items).toEqual([]);
expect(result.unknowns.join(" ")).toContain(
"Missing matches do not establish absence",
);
});
it("binds reused facts to the current Evidence ID and validates its subject on every projection", () => {
it("reuses immutable facts while binding each view to its current Evidence identity", () => {
const inventory = freezeJsonSnapshot(freshInventory());
const first = parent(inventory);
page(first, { kind: "inventory", collection: "nodes", fields: [] });
const parse = vi.spyOn(artifactInventoryResultSchema, "parse");
const projected = page(first, {
kind: "inventory",
collection: "occurrences",
limit: 1,
});
expect(projected.items[0]).toBe(inventory.occurrences[0]);
const next = { ...first, evidenceId: `ev_${"f".repeat(64)}` };
expect(
page(next, { kind: "inventory", collection: "nodes", fields: [] })
.inventory_evidence_ids,
page(next, {
kind: "inventory",
collection: "nodes",
artifact_ids: [inventory.nodes[0]!.artifact_id],
fields: [],
}).inventory_evidence_ids,
).toEqual([next.evidenceId]);
expect(parse).toHaveBeenCalledOnce();
const subject = next.subject;
if (subject === undefined || subject.identity.kind !== "file")
throw new Error("Expected a subject");
@@ -195,11 +195,7 @@ mcpTest(
},
);
const createInventoryViewReader = async (
client: Client,
parent: Evidence,
profile: "compact",
) => {
const createInventoryViewReader = async (client: Client, parent: Evidence) => {
const advertised = (await client.listTools()).tools.find(
(tool) => tool.name === "inspect_analysis_view",
);
@@ -211,8 +207,8 @@ const createInventoryViewReader = async (
source: { kind: "retained-evidence", evidence_id: parent.evidence_id },
view: { kind: "inventory", collection: "nodes", logical_paths: [] },
};
// The canonical contract refuses the empty selection; the compact
// advertisement may not, so the server's refusal below is what callers see.
// The canonical contract disallows path filters for nodes. The server
// also enforces this when clients use the compact advertisement.
expect(ajv.validate(canonicalInputSchema(advertised.name), malformed)).toBe(
false,
);
@@ -384,9 +380,9 @@ const assertOccurrencePages = async (
});
};
mcpTest.for(["compact"] as const)(
"keeps complete ZIP output and reads retained inventory views after the source is removed (%s)",
async (profile, { mcp, onTestFinished }) => {
mcpTest(
"keeps complete ZIP output and reads retained inventory views after the source is removed",
async ({ mcp, onTestFinished }) => {
const directory = await createTestTempDirectory("rea-artifact-inline-");
const archive = join(directory, "many.zip");
const writer = new ZipWriter(new Uint8ArrayWriter());
@@ -407,7 +403,7 @@ mcpTest.for(["compact"] as const)(
environment: {
...process.env,
...INLINE_EVIDENCE_MCP_ENVIRONMENT,
REA_MCP_INPUT_SCHEMA_PROFILE: profile,
REA_MCP_INPUT_SCHEMA_PROFILE: "compact",
},
},
),
@@ -444,7 +440,7 @@ mcpTest.for(["compact"] as const)(
expect(graph.occurrences).toHaveLength(fileCount + 1);
// Follow-ups must use retained source facts, not reopen this archive.
await unlink(archive);
const readView = await createInventoryViewReader(client, parent, profile);
const readView = await createInventoryViewReader(client, parent);
const summary = await readView({ kind: "summary" });
expect(summary.result).toMatchObject({
kind: "summary",