mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 03:33:25 +00:00
* feat(evidence)!: give Evidence bundles a format revision owned by one module `src/domain/evidenceFormat.ts` owns Evidence format evolution. Bundles now carry `evidence_format: 1`; every bundle reader admits only the current revision and refuses an unmarked or other-revision bundle once, with the single recreate-observations guidance, instead of admitting earlier shapes one optional field at a time. The 6.7-era artifact inventory summary identities are no longer rebuilt: compare_artifacts checks the current projection only and reports a mismatch with the owner's guidance. The pre-6.6 identity diagnosis uses the same guidance. SQLite `worker_timeout_ms` and Dart AOT `string_pool.policy`, optional only for historical Evidence, are now required. BREAKING CHANGE: Evidence bundles written by REA 6.x (no `evidence_format`) are refused by import, comparison, reconstruction and analysis-snapshot readers as an integrity mismatch telling the caller to recreate the observations; re-exporting an earlier bundle does not update its format or identities. Bundles constructed by hand must include `"evidence_format": 1`. 6.7-era artifact summaries are refused by compare_artifacts, and SQLite and Dart AOT Evidence without the newly required fields fails validation. * fix(evidence): let the ledger application admit its bundle's format build_reconstruction_obligation_ledger registered the full bundle schema with the SDK, so an unmarked or other-revision bundle was refused as invalid_request before the format owner ran. Register it like coverage: the application parses the request envelope and admits the bundle. * feat(pcap)!: read capture Evidence through the current result schema only (#10879) Delete the pcap read-compatibility schema that defaulted executable identity for historical capture Evidence, and require query_labels_hex (null when unknown) now that every producer writes it. Evidence from an earlier format is refused at the bundle format owner; a record that omits these fields is reported as malformed instead of defaulted. BREAKING CHANGE: inspect_pcap_capture results always carry query_labels_hex, and analysis views no longer default missing tshark/capinfos identity fields. * feat(desktop)!: require the effective view policy in desktop state Evidence (#10886) inspect_desktop_application_state always records the complete policy it used, including sqlite_view_bytes. Drop the optional historical shape and the task draft's absent-policy branch. BREAKING CHANGE: desktop application state results without effective_view_policy, or with a policy missing sqlite_view_bytes, are refused as malformed. * feat(android)!: require component declaration facets and reference aggregates in Android Evidence (#10904) * feat(android)!: require component declaration facets and reference aggregates in Android Evidence The JADX producers always write the manifest component projection with every declaration facet, target_definition and direct_invokes_coverage. Require them, delete the duplicate observed component schema, drop the unknown declaration coverage that only described historical omission, and give manifest view results their explicit facet. BREAKING CHANGE: Android package, component and reference results missing these fields are refused as malformed; component declaration_coverage and its summary counts no longer include unknown; manifest view results always carry facet manifest. * refactor(android): parse package results with the domain schema directly * feat(browser)!: require the DOM length unit and redirect-scoped prior-hop facts (#10897) * feat(browser)!: require the DOM length unit and redirect-scoped prior-hop facts Both CDP producers always declare node_value_length_unit, and the observation session writes redirect_response on every redirect event and no other. Require the unit, drop the diff's absent-unit branch, and admit redirect_response exactly on redirect rows. BREAKING CHANGE: DOM snapshots without node_value_length_unit and redirect timeline rows without redirect_response are refused as malformed, including inline inspections passed to compare_web_captures. * docs(browser): drop the historical redirect_response omission note * feat(native)!: require native Evidence fields that were optional only for historical Evidence (#10946) Mach-O encryption, slice malformed cause, symbol runtime names and import facts; ELF export encoding facts and visibility; value-flow limits; load-image permissions and relocation symbols; Swift type-reference kind and GPU AMD target metadata are required. Legacy enum values (unrecorded, unknown visibility, undecodable, modinfo_field_exceeds_limit) and the retained schemas, view defaults and reinterpretations that served historical Evidence are deleted. BREAKING CHANGE: native records missing these fields are refused as malformed; recreate the observation.
238 lines
8.4 KiB
TypeScript
238 lines
8.4 KiB
TypeScript
import { writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
import { expect } from "vitest";
|
|
|
|
import { parseEvidence } from "../../../src/domain/evidence.js";
|
|
import { webPageInspectionSchema } from "../../../src/domain/browserObservationSchemas.js";
|
|
import { electronPageInspectionSchema } from "../../../src/domain/javascript/electronObservation.js";
|
|
import { startFakeCdpBrowser } from "../../fixtures/fakeCdpBrowser.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
import { passiveNetworkCapture } from "../../fixtures/passiveNetworkCapture.js";
|
|
import { webCaptureDiffSchema } from "../../../src/domain/webCaptureDiffSchemas.js";
|
|
|
|
for (const electron of [false, true])
|
|
cliTest(
|
|
`declares ${electron ? "Electron UTF-8" : "web UTF-16"} DOM value lengths through CLI and MCP and refuses snapshots without a unit`,
|
|
async ({ cli, onTestFinished }) => {
|
|
const root = await createTestTempDirectory("rea-dom-value-units-");
|
|
const path = join(root, "index.html");
|
|
await writeFile(path, "<html/>");
|
|
const fileUrl = pathToFileURL(path).href;
|
|
const values = ["ASCII", "ééé😀", "漢字", "e\u0301"];
|
|
let missingStrings = false;
|
|
const browser = await startFakeCdpBrowser({
|
|
...(electron ? { electronFileUrl: fileUrl } : {}),
|
|
commandResult: ({ method }, origin) => {
|
|
if (method !== "DOMSnapshot.captureSnapshot") return undefined;
|
|
if (missingStrings) return { documents: [] };
|
|
return {
|
|
strings: [
|
|
electron ? fileUrl : `${origin}/app`,
|
|
"#document",
|
|
"#text",
|
|
...values,
|
|
],
|
|
documents: [
|
|
{
|
|
documentURL: 0,
|
|
nodes: {
|
|
nodeType: [9, 3, 3, 3, 3],
|
|
nodeName: [1, 2, 2, 2, 2],
|
|
nodeValue: [-1, 3, 4, 5, 6],
|
|
parentIndex: [-1, 0, 0, 0, 0],
|
|
attributes: [[], [], [], [], []],
|
|
},
|
|
},
|
|
],
|
|
};
|
|
},
|
|
});
|
|
onTestFinished(() => browser.close());
|
|
const command = electron ? "inspect-electron-page" : "inspect-web-page";
|
|
const target = electron ? "electron-page" : "allowed-page";
|
|
const input = {
|
|
cdp_endpoint: browser.endpoint,
|
|
target_id: target,
|
|
observation_ms: 0,
|
|
...(electron ? {} : { allowed_origins: [browser.allowedOrigin] }),
|
|
};
|
|
const result = await cli.run({
|
|
arguments: [
|
|
command,
|
|
browser.endpoint,
|
|
target,
|
|
"--observation-ms",
|
|
"0",
|
|
...(electron ? [] : ["--allowed-origins", browser.allowedOrigin]),
|
|
"--json",
|
|
],
|
|
});
|
|
expect(result.exitCode, result.stderr).toBe(0);
|
|
expect(result.stderr).toBe("");
|
|
const schema = electron
|
|
? electronPageInspectionSchema
|
|
: webPageInspectionSchema;
|
|
const check = (value: unknown) => {
|
|
const evidence = parseEvidence(value);
|
|
const report = schema.parse(evidence.normalized_result);
|
|
expect(report.dom).toMatchObject({
|
|
node_value_length_unit: electron ? "utf8-bytes" : "utf16-code-units",
|
|
total_nodes: 5,
|
|
});
|
|
expect(report.dom.nodes.map((node) => node.node_value_length)).toEqual([
|
|
0,
|
|
...(electron ? [5, 10, 6, 3] : [5, 5, 2, 2]),
|
|
]);
|
|
expect(report.dom.nodes.map((node) => node.index)).toEqual([
|
|
0, 1, 2, 3, 4,
|
|
]);
|
|
expect(report.dom.nodes[1]).not.toHaveProperty(
|
|
"node_value_length_unit",
|
|
);
|
|
expect(JSON.stringify(report.dom)).not.toContain("ééé😀");
|
|
const unmarked = {
|
|
total_nodes: report.dom.total_nodes,
|
|
nodes: report.dom.nodes,
|
|
};
|
|
for (const dom of [
|
|
unmarked,
|
|
{ ...unmarked, node_value_length_unit: "characters" },
|
|
])
|
|
expect(schema.safeParse({ ...report, dom }).success).toBe(false);
|
|
};
|
|
check(result.json);
|
|
const call = await cli.sharedMcpCall!();
|
|
const mcp = await call(command.replaceAll("-", "_"), input);
|
|
expect(mcp.isError).not.toBe(true);
|
|
check(mcp.structuredContent);
|
|
|
|
missingStrings = true;
|
|
const partial = await call(command.replaceAll("-", "_"), input);
|
|
expect(partial.isError).not.toBe(true);
|
|
const report = schema.parse(
|
|
parseEvidence(partial.structuredContent).normalized_result,
|
|
);
|
|
expect(report.dom).toEqual({
|
|
node_value_length_unit: electron ? "utf8-bytes" : "utf16-code-units",
|
|
total_nodes: 0,
|
|
nodes: [],
|
|
});
|
|
expect(report.completeness.excluded).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
section: "dom",
|
|
reason: "invalid_protocol_value",
|
|
}),
|
|
]),
|
|
);
|
|
},
|
|
);
|
|
|
|
cliTest(
|
|
"compares only commensurable DOM lengths while retaining structural changes through CLI and MCP",
|
|
async ({ cli }) => {
|
|
const call = await cli.sharedMcpCall!();
|
|
for (const [beforeUnit, afterUnit, length, variation, status] of [
|
|
["utf16-code-units", "utf16-code-units", 5, "none", "unchanged"],
|
|
["utf8-bytes", "utf8-bytes", 10, "none", "changed"],
|
|
["utf16-code-units", "utf8-bytes", 5, "none", "unknown"],
|
|
["utf16-code-units", "utf8-bytes", 10, "none", "unknown"],
|
|
["utf16-code-units", "utf8-bytes", 5, "node", "changed"],
|
|
["utf16-code-units", "utf8-bytes", 10, "frame", "changed"],
|
|
["utf16-code-units", "utf8-bytes", 5, "empty", "unchanged"],
|
|
] as const) {
|
|
const before = passiveNetworkCapture();
|
|
before.dom = {
|
|
total_nodes: 2,
|
|
node_value_length_unit: beforeUnit,
|
|
nodes: [
|
|
{
|
|
index: 0,
|
|
parent_index: -1,
|
|
node_type: 9,
|
|
node_name: "#document",
|
|
node_value_length: 0,
|
|
attribute_names: [],
|
|
},
|
|
{
|
|
index: 1,
|
|
parent_index: 0,
|
|
node_type: 3,
|
|
node_name: "#text",
|
|
node_value_length: 5,
|
|
attribute_names: [],
|
|
},
|
|
],
|
|
};
|
|
const after = structuredClone(before);
|
|
after.dom.node_value_length_unit = afterUnit;
|
|
after.dom.nodes[1]!.node_value_length = length;
|
|
if (variation === "node") {
|
|
after.dom.nodes[1]!.node_type = 8;
|
|
after.dom.nodes[1]!.node_name = "#comment";
|
|
}
|
|
if (variation === "frame")
|
|
after.frames.push({
|
|
frame_id: "frame",
|
|
parent_frame_id: null,
|
|
url: "https://app.example.test/other",
|
|
origin: "https://app.example.test",
|
|
});
|
|
if (variation === "empty") {
|
|
before.dom = {
|
|
total_nodes: 0,
|
|
node_value_length_unit: beforeUnit,
|
|
nodes: [],
|
|
};
|
|
after.dom = {
|
|
total_nodes: 0,
|
|
node_value_length_unit: afterUnit,
|
|
nodes: [],
|
|
};
|
|
}
|
|
const result = await cli.run({
|
|
arguments: [
|
|
"compare-web-captures",
|
|
JSON.stringify({ inspection: before }),
|
|
JSON.stringify({ inspection: after }),
|
|
"--json",
|
|
],
|
|
});
|
|
expect(result.exitCode, result.stderr).toBe(0);
|
|
const mcp = await call("compare_web_captures", {
|
|
before: { inspection: after },
|
|
after: { inspection: before },
|
|
});
|
|
expect(mcp.isError).not.toBe(true);
|
|
const label = JSON.stringify({
|
|
beforeUnit,
|
|
afterUnit,
|
|
length,
|
|
variation,
|
|
});
|
|
for (const output of [result.json, mcp.structuredContent]) {
|
|
const diff = webCaptureDiffSchema.parse(
|
|
parseEvidence(output).normalized_result,
|
|
);
|
|
expect(diff.dimensions.dom_structure.status, label).toBe(status);
|
|
if (status === "unknown")
|
|
expect(diff.dimensions.dom_structure.reason).toContain("unit");
|
|
}
|
|
}
|
|
const unmarked = passiveNetworkCapture();
|
|
const { node_value_length_unit: _unit, ...dom } = unmarked.dom;
|
|
const refused = await cli.run({
|
|
arguments: [
|
|
"compare-web-captures",
|
|
JSON.stringify({ inspection: { ...unmarked, dom } }),
|
|
JSON.stringify({ inspection: unmarked }),
|
|
"--json",
|
|
],
|
|
});
|
|
expect(refused.exitCode).not.toBe(0);
|
|
expect(refused.stderr + refused.stdout).toContain("node_value_length_unit");
|
|
},
|
|
);
|