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.8 KiB
TypeScript
168 lines
5.8 KiB
TypeScript
import { join } from "node:path";
|
|
import { expect, it } from "vitest";
|
|
import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js";
|
|
import { analysisViewResultSchema } from "../../../src/domain/analysisView/analysisViewResult.js";
|
|
import { createApplicationMcpHarness } from "../../fixtures/applicationMcpHarness.js";
|
|
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
const traceFixture = () => ({
|
|
query: "goal",
|
|
search_mode: "literal" as const,
|
|
matches: [{ type: "procedure" as const, address: "0x1000", value: "goal" }],
|
|
references: ["0x1010", "0x1020", "0x1010"].map((source_address) => ({
|
|
target_address: "0x1000",
|
|
source_address,
|
|
containing_procedure: {
|
|
query_address: source_address,
|
|
status: "unavailable" as const,
|
|
provider_id: "kuna",
|
|
reason: "unsupported",
|
|
},
|
|
})),
|
|
truncated: true,
|
|
residual_unknowns: ["0x1010 owner unknown", "0x1020 owner unknown"],
|
|
});
|
|
|
|
it.each(["full", "compact"] as const)(
|
|
"pages retained native trace rows and preserves source coverage across %s offline handoff",
|
|
async (profile) => {
|
|
const result = traceFixture();
|
|
const parent = createEvidence(
|
|
undefined,
|
|
{ id: "rea-workflow", name: "REA workflow", version: "1" },
|
|
{
|
|
operation: "trace_feature",
|
|
parameters: { query: "goal", case_sensitive: false },
|
|
result,
|
|
confidence: "derived",
|
|
limitations: ["fixture provider coverage"],
|
|
},
|
|
);
|
|
const setup = async () => {
|
|
const session = createTestBinarySession(() => {
|
|
throw new Error("View must not open a provider");
|
|
});
|
|
const harness = await createApplicationMcpHarness({
|
|
session,
|
|
clientIdentity: { name: "native-feature-view", version: "1" },
|
|
serverOptions: {
|
|
environment: {
|
|
...process.env,
|
|
REA_MCP_INPUT_SCHEMA_PROFILE: profile,
|
|
REA_MCP_OUTPUT_SCHEMA_PROFILE: profile,
|
|
},
|
|
},
|
|
});
|
|
return { ...harness, session };
|
|
};
|
|
const first = await setup();
|
|
const call = async (
|
|
client: typeof first.client,
|
|
name: string,
|
|
args: Record<string, unknown>,
|
|
) => {
|
|
const reply = await client.callTool({ name, arguments: args });
|
|
expect(reply.isError, JSON.stringify(reply)).not.toBe(true);
|
|
return reply.structuredContent;
|
|
};
|
|
const source = {
|
|
kind: "retained-evidence",
|
|
evidence_id: parent.evidence_id,
|
|
};
|
|
const view = async (
|
|
client: typeof first.client,
|
|
collection: "matches" | "references" | "unknowns",
|
|
offset: number,
|
|
limit: number,
|
|
) => {
|
|
const response = parseEvidence(
|
|
await call(client, "inspect_analysis_view", {
|
|
source,
|
|
view: { kind: "native-feature-trace", collection, offset, limit },
|
|
}),
|
|
);
|
|
return analysisViewResultSchema.parse(response.normalized_result);
|
|
};
|
|
const root = await createTestTempDirectory(
|
|
"rea-native-feature-trace-view-",
|
|
);
|
|
const path = join(root, "evidence.json");
|
|
try {
|
|
expect(first.session.recordEvidence(parent).ok).toBe(true);
|
|
const summary = analysisViewResultSchema.parse(
|
|
parseEvidence(
|
|
await call(first.client, "inspect_analysis_view", {
|
|
source,
|
|
view: { kind: "summary" },
|
|
}),
|
|
).normalized_result,
|
|
);
|
|
expect(summary).toMatchObject({
|
|
parent_evidence_id: parent.evidence_id,
|
|
summary: { matches: 1, references: 3, unknowns: 2, truncated: true },
|
|
});
|
|
const firstPage = await view(first.client, "references", 0, 2);
|
|
const lastPage = await view(first.client, "references", 2, 2);
|
|
expect(
|
|
analysisViewResultSchema.safeParse({
|
|
...firstPage,
|
|
items: { collection: "unknowns", rows: [] },
|
|
}).success,
|
|
).toBe(false);
|
|
expect(firstPage).toMatchObject({
|
|
coverage: { total: 3, next_offset: 2, exhausted: false },
|
|
items: {
|
|
rows: [
|
|
{ source_index: 0, value: result.references[0] },
|
|
{ source_index: 1, value: result.references[1] },
|
|
],
|
|
},
|
|
});
|
|
expect(lastPage).toMatchObject({
|
|
coverage: { total: 3, next_offset: null, exhausted: true },
|
|
items: { rows: [{ source_index: 2, value: result.references[2] }] },
|
|
});
|
|
const filtered = analysisViewResultSchema.parse(
|
|
parseEvidence(
|
|
await call(first.client, "inspect_analysis_view", {
|
|
source,
|
|
view: {
|
|
kind: "native-feature-trace",
|
|
collection: "references",
|
|
source_address: "0x1010",
|
|
offset: 1,
|
|
limit: 1,
|
|
},
|
|
}),
|
|
).normalized_result,
|
|
);
|
|
expect(filtered).toMatchObject({
|
|
coverage: { total: 2, next_offset: null, exhausted: true },
|
|
items: { rows: [{ source_index: 2, value: result.references[2] }] },
|
|
});
|
|
expect(await view(first.client, "unknowns", 1, 5)).toMatchObject({
|
|
items: {
|
|
rows: [{ source_index: 1, value: result.residual_unknowns[1] }],
|
|
},
|
|
});
|
|
expect(await view(first.client, "matches", 9, 1)).toMatchObject({
|
|
coverage: { status: "empty", total: 1, next_offset: null },
|
|
});
|
|
await call(first.client, "export_evidence_bundle", { path });
|
|
} finally {
|
|
await first.close();
|
|
}
|
|
const second = await setup();
|
|
try {
|
|
await call(second.client, "import_evidence_bundle", { path });
|
|
expect(await view(second.client, "references", 2, 1)).toMatchObject({
|
|
parent_evidence_id: parent.evidence_id,
|
|
items: { rows: [{ source_index: 2, value: result.references[2] }] },
|
|
});
|
|
} finally {
|
|
await second.close();
|
|
}
|
|
},
|
|
);
|