mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
* feat(native): page retained feature traces * fix(snapshot): retain linked source evidence for replay * test(snapshot): verify linked foreign evidence stays scoped * feat(native): page retained procedure references * docs(mcp): clarify imported residual questions * docs(mcp): guide trace reference classification * fix(cli): report result sources when Evidence publication fails A trace keeps linked sources on the result. Use those records for the undelivered source closure as well as the bundle, so a refused output does not report them as not captured. * ci: rerun pull request checks The merge of origin/main did not start the CI workflow for this head. * fix(native): document shared procedure endpoints and the required selector Describe kind shared and items.endpoints instead of inline procedure copies. State that procedure-references requires a positional selector or --procedure. * fix(native): count procedure-reference endpoints before keeping a row Include the shared endpoint table in the page budget, with JSON punctuation, and store a new procedure only when its row is accepted. * fix(native): measure a procedure endpoint once before its comparison key Size the candidate before building one canonical identity, and reuse that key for the selected-procedure and shared-endpoint checks. * fix(native): reject an oversized procedure endpoint before canonicalizing it When the JSON size already exceeds every stored identity, skip the canonical string and keep the row out of the page. * fix(native): describe procedure-reference direction and coverage Avoid execution wording in the tool description, and give the CLI direction option the help text the catalog requires. * fix(native): compare endpoint size with UTF-8 identity length Keep one running maximum of stored identity bytes. A multibyte selected procedure is recognized when its JSON no longer fits the page. * test(cli): count procedure-references as a dedicated command The MCP tool has a CLI command, so it is no longer an MCP-only exception. * test(native): catch the string-length endpoint comparison Use a 200,000-character multibyte selected procedure and a shorter ASCII endpoint so the old JavaScript length check drops the selected row. * ci: rerun after the binary-layout toolchain timeout The required check failed because the toolchain install exceeded 15 minutes. The same job completed on the previous head, and this commit does not change the procedure-reference behavior. * test: stabilize capture decoder exhaustion coverage --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
142 lines
4.3 KiB
TypeScript
142 lines
4.3 KiB
TypeScript
import { expect, it } from "vitest";
|
|
|
|
import type { AnalysisViewParent } from "./analysisViewParent.js";
|
|
import {
|
|
procedureReferenceViewRequests,
|
|
projectNativeProcedureReferencesView,
|
|
} from "./nativeProcedureReferencesView.js";
|
|
|
|
const PAGE_BYTES = 1024 * 1024;
|
|
const selected = {
|
|
address: "0x1000",
|
|
name: "selected",
|
|
classification: null,
|
|
body: { available: false as const, reason: "not reported" },
|
|
};
|
|
const parentFor = (
|
|
references: readonly Record<string, unknown>[],
|
|
): AnalysisViewParent => ({
|
|
evidenceId: `ev_${"a".repeat(64)}`,
|
|
operation: "procedure_references",
|
|
predicateType: "rea.analysis",
|
|
limitations: [],
|
|
parameters: {},
|
|
normalizedResult: {
|
|
procedure: selected,
|
|
direction: "outgoing",
|
|
reference_kinds_available: false,
|
|
unresolved_calls: [],
|
|
references,
|
|
},
|
|
});
|
|
const edge = (
|
|
sourceAddress: string,
|
|
target: Record<string, unknown> | null,
|
|
) => ({
|
|
source_address: sourceAddress,
|
|
target_address: "0x2000",
|
|
source_procedure: selected,
|
|
target_procedure: target,
|
|
kind: { available: false as const, reason: "not reported" },
|
|
});
|
|
const viewFor = (limit: number) =>
|
|
procedureReferenceViewRequests.references.parse({
|
|
kind: "native-procedure-references",
|
|
collection: "references",
|
|
offset: 0,
|
|
limit,
|
|
});
|
|
const pageBytes = (value: unknown) => Buffer.byteLength(JSON.stringify(value));
|
|
|
|
it("omits an endpoint that no accepted row uses", () => {
|
|
const projected = projectNativeProcedureReferencesView(
|
|
parentFor([
|
|
edge("0x1001", null),
|
|
edge("0x1002", {
|
|
...selected,
|
|
address: "0x3000",
|
|
name: "x".repeat(1_048_000),
|
|
}),
|
|
]),
|
|
viewFor(8),
|
|
);
|
|
if (!projected.ok) throw projected.error;
|
|
if (projected.value.kind !== "native-procedure-references")
|
|
throw new Error("Expected a procedure-reference page");
|
|
if (projected.value.items.collection !== "references")
|
|
throw new Error("Expected reference rows");
|
|
expect(projected.value.byte_limited).toBe(true);
|
|
expect(projected.value.items.rows).toHaveLength(1);
|
|
expect(projected.value.items.endpoints).toEqual([]);
|
|
expect(pageBytes(projected.value)).toBeLessThanOrEqual(PAGE_BYTES);
|
|
});
|
|
|
|
it("recognizes a multibyte selected procedure after the page is partly full", () => {
|
|
const multibyte = {
|
|
...selected,
|
|
name: "雪".repeat(200_000),
|
|
};
|
|
const filler = {
|
|
...selected,
|
|
address: "0x3000",
|
|
name: "y".repeat(150_000),
|
|
};
|
|
const projected = projectNativeProcedureReferencesView(
|
|
{
|
|
...parentFor([edge("0x1001", filler), edge("0x1002", multibyte)]),
|
|
normalizedResult: {
|
|
procedure: multibyte,
|
|
direction: "outgoing",
|
|
reference_kinds_available: false,
|
|
unresolved_calls: [],
|
|
references: [
|
|
{
|
|
...edge("0x1001", filler),
|
|
source_procedure: null,
|
|
},
|
|
{
|
|
...edge("0x1002", multibyte),
|
|
source_procedure: null,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
viewFor(8),
|
|
);
|
|
if (!projected.ok) throw projected.error;
|
|
if (projected.value.kind !== "native-procedure-references")
|
|
throw new Error("Expected a procedure-reference page");
|
|
if (projected.value.items.collection !== "references")
|
|
throw new Error("Expected reference rows");
|
|
expect(projected.value.items.rows).toHaveLength(2);
|
|
expect(projected.value.items.rows[1]?.target_procedure).toEqual({
|
|
kind: "selected-procedure",
|
|
});
|
|
expect(projected.value.items.endpoints).toHaveLength(1);
|
|
});
|
|
|
|
it("counts distinct shared endpoints inside the page allowance", () => {
|
|
const projected = projectNativeProcedureReferencesView(
|
|
parentFor(
|
|
Array.from({ length: 40 }, (_, index) =>
|
|
edge(`0x${(0x2000 + index).toString(16)}`, {
|
|
...selected,
|
|
address: `0x${(0x8000 + index).toString(16)}`,
|
|
name: "endpoint".repeat(4_000),
|
|
}),
|
|
),
|
|
),
|
|
viewFor(40),
|
|
);
|
|
if (!projected.ok) throw projected.error;
|
|
if (projected.value.kind !== "native-procedure-references")
|
|
throw new Error("Expected a procedure-reference page");
|
|
if (projected.value.items.collection !== "references")
|
|
throw new Error("Expected reference rows");
|
|
expect(projected.value.byte_limited).toBe(true);
|
|
expect(projected.value.items.endpoints).toHaveLength(
|
|
projected.value.items.rows.length,
|
|
);
|
|
expect(pageBytes(projected.value)).toBeLessThanOrEqual(PAGE_BYTES);
|
|
});
|