mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 11:13:21 +00:00
* 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.
168 lines
5.7 KiB
TypeScript
168 lines
5.7 KiB
TypeScript
import { rm, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
import { z } from "zod";
|
|
import { readEvidenceBundle } from "../../../src/application/EvidenceBundleFiles.js";
|
|
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
|
import { evidenceSchema } from "../../../src/domain/evidence.js";
|
|
import { digestCanonicalValue } from "../../../src/domain/canonicalDigest.js";
|
|
import { analysisViewResultSchema } from "../../../src/domain/analysisView/analysisViewResult.js";
|
|
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
|
|
import {
|
|
elfExportImage,
|
|
peExportImage,
|
|
} from "../../fixtures/binaryDiagnostics/nativeExports.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
|
|
const exportsContract = toolContract("inspect_native_exports");
|
|
const viewContract = toolContract("inspect_analysis_view");
|
|
|
|
cliTest.for(["pe", "elf"] as const)(
|
|
"queries retained %s exports through CLI and actual stdio MCP after the source is deleted",
|
|
async (format, { cli }) => {
|
|
const root = await createTestTempDirectory("rea-export-views-");
|
|
const path = join(root, `library.${format}`);
|
|
const bytes =
|
|
format === "pe"
|
|
? peExportImage({
|
|
functions: [{ rva: 0x2000 }, { forwarder: "other.Target" }],
|
|
names: [
|
|
{ name: "selected", index: 0 },
|
|
{ name: "selected", index: 1 },
|
|
],
|
|
})
|
|
: elfExportImage({
|
|
symbols: [
|
|
{ name: "selected", version: 2 },
|
|
{ name: "selected", version: 0x8002 },
|
|
],
|
|
versionDefinitions: ["fixture", "V1"],
|
|
});
|
|
await writeFile(path, bytes);
|
|
const run = cli.run.bind(cli);
|
|
const complete = await run({
|
|
arguments: ["inspect-native-exports", path, "--json"],
|
|
});
|
|
expect(complete.exitCode, complete.stderr).toBe(0);
|
|
const parent = exportsContract.outputSchema.parse(complete.json);
|
|
const bundle = join(root, "complete.bundle.json");
|
|
const summarized = await run({
|
|
arguments: [
|
|
"inspect-native-exports",
|
|
path,
|
|
"--detail",
|
|
"summary",
|
|
"--evidence_output",
|
|
bundle,
|
|
"--json",
|
|
],
|
|
});
|
|
expect(summarized.exitCode, summarized.stderr).toBe(0);
|
|
const delivered = z
|
|
.object({ summary: evidenceSchema })
|
|
.parse(summarized.json).summary;
|
|
expect(delivered.operation).toBe("inspect_analysis_view");
|
|
expect(delivered.normalized_result).toMatchObject({
|
|
parent_evidence_id: parent.evidence_id,
|
|
summary: { format, export_count: 2, coverage: { status: "complete" } },
|
|
});
|
|
const loaded = await readEvidenceBundle(bundle);
|
|
if (!loaded.ok) throw loaded.error;
|
|
expect(loaded.value.records).toEqual([parent]);
|
|
|
|
const call =
|
|
cli.sharedMcpCall === undefined
|
|
? (await connectLocalToolsMcp()).call
|
|
: await cli.sharedMcpCall();
|
|
const response = await call("inspect_native_exports", {
|
|
path,
|
|
detail: "summary",
|
|
});
|
|
expect(response.isError).not.toBe(true);
|
|
expect(
|
|
exportsContract.outputSchema.parse(response.structuredContent)
|
|
.normalized_result,
|
|
).toEqual(delivered.normalized_result);
|
|
await rm(path);
|
|
const source = {
|
|
kind: "retained-evidence",
|
|
evidence_id: parent.evidence_id,
|
|
};
|
|
const request = {
|
|
source,
|
|
view: {
|
|
kind: "native-exports",
|
|
collection: "exports",
|
|
names: ["selected"],
|
|
fields: ["name"],
|
|
offset: 1,
|
|
limit: 1,
|
|
},
|
|
};
|
|
const viewed = await call("inspect_analysis_view", request);
|
|
expect(viewed.isError).not.toBe(true);
|
|
const page = viewContract.outputSchema.parse(viewed.structuredContent);
|
|
expect(page.evidence_links).toContain(parent.evidence_id);
|
|
expect(page.normalized_result).toMatchObject({
|
|
kind: "native-exports",
|
|
items: [{ source_index: 1, name: "selected" }],
|
|
exports: { coverage: { status: "complete" } },
|
|
coverage: { examined: 1, total: 2, next_offset: null, exhausted: true },
|
|
});
|
|
const offline = await run({
|
|
arguments: [
|
|
"inspect-analysis-view",
|
|
JSON.stringify(request),
|
|
"--evidence-bundle",
|
|
bundle,
|
|
"--json",
|
|
],
|
|
});
|
|
expect(offline.exitCode, offline.stderr).toBe(0);
|
|
expect(viewContract.outputSchema.parse(offline.json)).toEqual(page);
|
|
const projected = await call("inspect_analysis_view", {
|
|
...request,
|
|
view: {
|
|
...request.view,
|
|
fields: [format === "elf" ? "value" : "ordinal"],
|
|
},
|
|
});
|
|
expect(projected.isError).not.toBe(true);
|
|
const projectedView = analysisViewResultSchema.parse(
|
|
viewContract.outputSchema.parse(projected.structuredContent)
|
|
.normalized_result,
|
|
);
|
|
expect(projectedView).toHaveProperty("items", [
|
|
{
|
|
source_index: 1,
|
|
...(format === "elf"
|
|
? { value: expect.any(String) }
|
|
: { ordinal: expect.any(Number) }),
|
|
},
|
|
]);
|
|
const { view_digest, ...content } = projectedView;
|
|
expect(view_digest).toBe(digestCanonicalValue(content, "Analysis view"));
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"refuses CLI summary without a durable Evidence destination before reading",
|
|
async ({ cli }) => {
|
|
const result = await cli.run({
|
|
arguments: [
|
|
"inspect-native-exports",
|
|
"/rea-nonexistent/export.so",
|
|
"--detail",
|
|
"summary",
|
|
"--json",
|
|
],
|
|
});
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.json).toMatchObject({
|
|
code: "invalid_request",
|
|
details: { issues: [{ path: ["evidence_output"] }] },
|
|
});
|
|
},
|
|
);
|