Files
reverse-engineering-anything/tests/acceptance/tools/unavailableNativeCollectionViews.test.ts
T
morluto b138f52e12 refactor: prune internal seams and preserve configuration ownership (#10430)
* refactor: prune internal seams and preserve configuration ownership

* fix(setup): keep YAML aliases and inherited registration settings on refresh

- Reuse an unchanged YAML collection only while every alias in it still
  resolves after the edit; otherwise rebuild it so the alias becomes its
  value. A sibling anchor replaced or moved in the same refresh no longer
  leaves an unresolved alias in Hermes or Goose output.
- Keep a connection selector whose existing value already chooses stdio
  (for example an inherited Hermes transport: stdio) instead of superseding
  it; remote selectors are still replaced. Explicit stdio selectors are
  therefore no longer rewritten (Kimi expectation updated).
- When the whole Hermes registration is inherited through a merge,
  override it with that merge and write only the changed fields.

* fix(setup): edit registration fields whose YAML key is an alias

A key written as an alias to a string scalar (for example *field with
field: &field env) was treated as a source-only key, so any change to
its value was refused in Hermes and Goose. Resolve such keys to their
string, keep the aliased spelling while its anchor survives the edit,
and write the plain key when the same edit rebuilds the anchor.

* test(process): bound cleanup-boundary waits and always release gates

Both cancellation tests awaited a bare started promise and released
their gates only on success, so a missed boundary waited for the outer
deadline and could leave cleanup parked. Use awaitAcknowledgement and
release and join the cleanup in finally.

* fix(setup): repair only aliases an edit leaves unresolved

Replace the pre-edit alias survival guess, which expanded aliases to
sibling anchors that survive unchanged, with an exact repair: record
what each alias in the replaced value resolves to, write the edit, then
replace only aliases left without a preceding anchor by that value.

- Keep an aliased key's source position, so its anchor stays ahead of
  later aliases.
- Treat an aliased key as its string only when no other key in the map
  resolves to the same string; an ambiguous one stays guarded.
- Override an inherited Hermes registration only when the requested
  entry keeps every inherited field, so an explicit replacement can drop
  remote selectors.

* fix(setup): repair aliases whose binding an edit changes, keeping comments

An alias whose own anchor was removed could resolve to an earlier anchor
with the same name and silently change value. Record the node each alias
resolved to and repair any alias that no longer resolves to that node.
Carry the alias's comments and spacing onto the repaired value.

* test(setup): split the Hermes anchor and merge refresh cases

* fix(setup): refuse removing an overridden key its merge would restore

The merge-retention check skipped keys the mapping also overrides, so
dropping such a key (for example a remote url during an explicit stdio
replacement) let the retained merge restore it. Check removal before
skipping overridden keys, so the edit is refused with the existing
message instead of producing a registration that cannot be applied.
2026-11-14 04:08:37 -05:00

155 lines
4.7 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect } from "vitest";
import { analysisViewResultSchema } from "../../../src/domain/analysisView/analysisViewResult.js";
import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js";
import {
nativeLoadImageObservationFixture,
nativeRawLoadImageFixture,
} from "../../fixtures/nativeLoadImage.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
cliTest(
"distinguishes unavailable native collections from empty selections through CLI and MCP",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-unavailable-native-view-");
const provider = {
id: "fixture",
name: "Retained native fixture",
version: "1",
};
const load = (result: unknown) =>
createEvidence(undefined, provider, {
operation: "inspect_native_load_image",
parameters: {},
result,
limitations: [
"Synthetic retained Evidence; no native provider was run.",
],
});
const unsupported = load({
status: "unsupported",
reason: "Independent ELF load verification was not recorded.",
observations: {
...nativeLoadImageObservationFixture(),
executable_format: "Executable and Linking Format (ELF)",
},
limitations: [],
});
const raw = load(nativeRawLoadImageFixture());
const primitive = createEvidence(undefined, provider, {
operation: "procedure_callees",
parameters: {},
result: [],
});
const graph = createEvidence(undefined, provider, {
operation: "get_call_graph",
parameters: {},
result: { graph: {}, limitations: [] },
});
const unavailable = {
status: "unavailable",
examined: 0,
total: null,
next_offset: null,
exhausted: false,
};
const empty = (total: number) => ({
status: "empty",
examined: 0,
total,
next_offset: null,
exhausted: true,
});
const cases = [
{
label: "checks-unrecorded",
evidence: unsupported,
view: { kind: "native-load-image", collection: "checks" },
rows: null,
coverage: unavailable,
},
{
label: "sections-unrecorded-despite-empty-selection",
evidence: unsupported,
view: {
kind: "native-load-image",
collection: "sections",
offset: 5,
indices: [],
},
rows: null,
coverage: unavailable,
},
{
label: "checks-recorded-empty",
evidence: raw,
view: { kind: "native-load-image", collection: "checks" },
rows: [],
coverage: empty(0),
},
{
label: "mappings-empty-selection",
evidence: unsupported,
view: {
kind: "native-load-image",
collection: "mappings",
indices: [],
},
rows: [],
coverage: empty(0),
},
{
label: "mappings-past-end",
evidence: unsupported,
view: { kind: "native-load-image", collection: "mappings", offset: 5 },
rows: [],
coverage: empty(1),
},
{
label: "primitive-result-limitations-inapplicable",
evidence: primitive,
view: { kind: "native-context", facet: "result-limitations" },
rows: null,
coverage: unavailable,
},
{
label: "graph-result-limitations-recorded-empty",
evidence: graph,
view: { kind: "native-context", facet: "result-limitations" },
rows: [],
coverage: empty(0),
},
];
const call = await cli.sharedMcpCall!();
const run = cli.run.bind(cli);
for (const test of cases) {
const request = {
source: { kind: "inline", evidence: test.evidence },
view: test.view,
};
const path = join(root, `${test.label}.json`);
await writeFile(path, JSON.stringify(request));
const output = await run({
arguments: ["inspect-analysis-view", path, "--json"],
});
expect(output.exitCode, output.stderr || output.stdout).toBe(0);
const page = analysisViewResultSchema.parse(
parseEvidence(output.json).normalized_result,
);
const response = await call("inspect_analysis_view", request);
expect(response.isError).not.toBe(true);
expect(
parseEvidence(response.structuredContent).normalized_result,
).toEqual(page);
expect(page, test.label).toMatchObject({
parent_evidence_id: test.evidence.evidence_id,
items: { rows: test.rows },
coverage: test.coverage,
});
}
},
);