mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 03:02:56 +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.
209 lines
7.1 KiB
TypeScript
209 lines
7.1 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { readFile, rm, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
|
|
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
|
import { analysisViewResultSchema } from "../../../src/domain/analysisView/analysisViewResult.js";
|
|
import { createEvidence } from "../../../src/domain/evidence.js";
|
|
import {
|
|
applicationFeatureTraceResultSchema,
|
|
type ApplicationFeatureTraceResult,
|
|
} from "../../../src/domain/javascript/javascriptFeatureTraceSchemas.js";
|
|
import { fileLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
|
|
import { createStrippedAsarAddon } from "../../fixtures/strippedAsarAddon.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
|
|
const mcp = fileLocalToolsMcp();
|
|
|
|
const sha256 = (value: Uint8Array) =>
|
|
createHash("sha256").update(value).digest("hex");
|
|
const nativeObservation = (path: string, sha256: string) =>
|
|
createEvidence(
|
|
{ path, sha256, format: "raw-binary" },
|
|
{ id: "ghidra", name: "Ghidra", version: "simulated" },
|
|
{
|
|
operation: "binary_overview",
|
|
parameters: {},
|
|
result: {
|
|
summary: "Simulated native Evidence for subject identity only.",
|
|
},
|
|
limitations: ["No native provider executed."],
|
|
},
|
|
);
|
|
|
|
interface ExpectedIdentity {
|
|
readonly available: boolean;
|
|
readonly addon: string;
|
|
readonly archiveDigest: string;
|
|
readonly nativeDigest: string;
|
|
readonly parentId: string;
|
|
readonly nativeId: string;
|
|
readonly linked: boolean;
|
|
}
|
|
|
|
const expectHandoffIdentity = (
|
|
trace: ApplicationFeatureTraceResult,
|
|
expected: ExpectedIdentity,
|
|
) => {
|
|
const node = trace.graph?.nodes.find(({ kind }) => kind === "native-addon");
|
|
expect(node).toBeDefined();
|
|
expect(trace.evidence_links).toEqual(
|
|
[
|
|
expected.parentId,
|
|
...(expected.available && expected.linked ? [expected.nativeId] : []),
|
|
].sort(),
|
|
);
|
|
if (expected.available) {
|
|
expect(node?.identity).toMatchObject({
|
|
strategy: "content-digest",
|
|
sha256: expected.nativeDigest,
|
|
});
|
|
expect(trace.native_handoffs).toHaveLength(1);
|
|
expect(trace.native_handoffs[0]).toMatchObject({
|
|
native_node_id: node?.node_id,
|
|
artifact_sha256: expected.nativeDigest,
|
|
artifact_path: expected.addon,
|
|
status: expected.linked
|
|
? "evidence-linked"
|
|
: "requires-provider-analysis",
|
|
evidence_ids: expected.linked ? [expected.nativeId] : [],
|
|
});
|
|
} else {
|
|
expect(node?.identity).toMatchObject({
|
|
strategy: "canonical-path",
|
|
artifact_sha256: expected.archiveDigest,
|
|
path: expected.addon,
|
|
});
|
|
expect(node?.observations).toContainEqual(
|
|
expect.objectContaining({
|
|
properties: expect.objectContaining({
|
|
availability: "unavailable",
|
|
hash_status: "unavailable",
|
|
inventory_artifact_id: null,
|
|
}),
|
|
}),
|
|
);
|
|
expect(trace.coverage.status).toBe("partial");
|
|
expect(trace.graph?.coverage.status).toBe("partial");
|
|
expect(trace.native_handoffs).toEqual([]);
|
|
expect(trace.summary.native_handoffs).toBe(0);
|
|
}
|
|
};
|
|
|
|
for (const available of [false, true]) {
|
|
cliTest(
|
|
`keeps native handoff byte identity ${available ? "exact when available" : "unknown for a missing ASAR companion"}`,
|
|
async ({ cli }) => {
|
|
const { root, archive, addon, original } =
|
|
await createStrippedAsarAddon();
|
|
const companion = join(`${archive}.unpacked`, addon);
|
|
if (available) await writeFile(companion, original);
|
|
else await rm(companion);
|
|
const archiveDigest = sha256(await readFile(archive));
|
|
const nativeDigest = sha256(original);
|
|
const containerEvidence = nativeObservation(archive, archiveDigest);
|
|
const nativeEvidence = nativeObservation(companion, nativeDigest);
|
|
const analysis = await cli.run({
|
|
arguments: ["analyze-javascript-application", archive, "--json"],
|
|
});
|
|
expect(analysis.exitCode, analysis.stderr).toBe(0);
|
|
const parent = toolContract(
|
|
"analyze_javascript_application",
|
|
).outputSchema.parse(analysis.json);
|
|
const summary = await mcp.client.callTool({
|
|
name: "analyze_javascript_application",
|
|
arguments: { input_path: archive, detail: "summary" },
|
|
});
|
|
expect(summary.isError).not.toBe(true);
|
|
const summaryEvidence = toolContract(
|
|
"analyze_javascript_application",
|
|
).outputSchema.parse(summary.structuredContent);
|
|
expect(
|
|
analysisViewResultSchema.parse(summaryEvidence.normalized_result)
|
|
.parent_evidence_id,
|
|
).toBe(parent.evidence_id);
|
|
const observed: {
|
|
trace: ApplicationFeatureTraceResult;
|
|
linked: boolean;
|
|
}[] = [];
|
|
for (const native_observations of [
|
|
[containerEvidence, nativeEvidence],
|
|
[],
|
|
]) {
|
|
const query = {
|
|
seed: {
|
|
kind: "string",
|
|
value: addon,
|
|
match: "exact",
|
|
case_sensitive: true,
|
|
},
|
|
direction: "outgoing",
|
|
native_observations,
|
|
};
|
|
const request = join(
|
|
root,
|
|
`trace-${String(native_observations.length)}.json`,
|
|
);
|
|
await writeFile(
|
|
request,
|
|
JSON.stringify({
|
|
...query,
|
|
application: parent,
|
|
}),
|
|
);
|
|
const cliTrace = await cli.run({
|
|
arguments: ["trace-application-feature", request, "--json"],
|
|
});
|
|
expect(
|
|
cliTrace.exitCode,
|
|
cliTrace.exitCode === 0
|
|
? undefined
|
|
: JSON.stringify(cliTrace.json ?? cliTrace.stderr),
|
|
).toBe(0);
|
|
const cliEvidence = toolContract(
|
|
"trace_application_feature",
|
|
).outputSchema.parse(cliTrace.json);
|
|
const response = await mcp.client.callTool({
|
|
name: "trace_application_feature",
|
|
arguments: {
|
|
...query,
|
|
application: {
|
|
kind: "retained-evidence",
|
|
evidence_id: parent.evidence_id,
|
|
},
|
|
},
|
|
});
|
|
expect(response.isError).not.toBe(true);
|
|
const evidence = toolContract(
|
|
"trace_application_feature",
|
|
).outputSchema.parse(response.structuredContent);
|
|
expect(evidence.evidence_id).toBe(cliEvidence.evidence_id);
|
|
for (const value of [cliEvidence, evidence])
|
|
observed.push({
|
|
trace: applicationFeatureTraceResultSchema.parse(
|
|
value.normalized_result,
|
|
),
|
|
linked: native_observations.length > 0,
|
|
});
|
|
}
|
|
// Exercise both provider-evidence selections and adapters before checking
|
|
// the missing-byte outcome; a failed baseline still observes both paths.
|
|
for (const { trace, linked } of observed)
|
|
expectHandoffIdentity(trace, {
|
|
available,
|
|
addon,
|
|
archiveDigest,
|
|
nativeDigest,
|
|
parentId: parent.evidence_id,
|
|
nativeId: nativeEvidence.evidence_id,
|
|
linked,
|
|
});
|
|
expect(sha256(await readFile(archive))).toBe(archiveDigest);
|
|
if (available)
|
|
expect(sha256(await readFile(companion))).toBe(nativeDigest);
|
|
await mcp.client.ping();
|
|
},
|
|
);
|
|
}
|