Files
reverse-engineering-anything/src/domain/analysisView/pcapCaptureView.test.ts
T
morluto 3afd8a16ee feat(evidence)!: give Evidence bundles a format revision owned by one module (#10861)
* 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.
2026-11-15 17:25:31 +08:00

193 lines
5.5 KiB
TypeScript

import { expect, it } from "vitest";
import { createEvidence } from "../evidence.js";
import { projectAnalysisView } from "./analysisView.js";
import type { AnalysisViewParent } from "./analysisViewParent.js";
const capture = (
tsharkStderr: string,
dnsQueries: {
query: string;
query_labels_hex: string[] | null;
response_addresses: string[];
response_address_count: number;
}[] = [],
): AnalysisViewParent => {
const target = {
path: "/recordings/input.pcap",
sha256: "c".repeat(64),
bytes: 24,
};
const report = {
client: {
tshark_command: "/usr/bin/tshark",
tshark_source: "path",
tshark_version: "4.6.6",
tshark_resolved_path: null,
tshark_sha256: null,
tshark_identity_status: "unresolved",
capinfos_command: "/usr/bin/capinfos",
capinfos_source: "path",
capinfos_version: "4.6.6",
capinfos_resolved_path: null,
capinfos_sha256: null,
capinfos_identity_status: "unresolved",
},
target,
file_type: "pcap",
encapsulation: "Ethernet",
packet_count: 0,
capture_start: null,
capture_end: null,
capture_duration_seconds: null,
snapshot_length: null,
endpoints: [],
endpoint_count: 0,
dns_queries: dnsQueries,
dns_query_count: dnsQueries.length,
tls_sni_values: [],
tls_sni_count: 0,
protocol_distribution: [],
protocol_count: 0,
http_request_uris: [],
http_request_uri_count: 0,
http_uri_redaction_count: 0,
unattributed_dns_addresses: [],
unattributed_dns_address_count: 0,
unattributed_dns_packet_count: 0,
coverage: "complete",
diagnostics: { capinfos_stderr: "", tshark_stderr: tsharkStderr },
};
const evidence = createEvidence(
{ ...target, format: "file" },
{ id: "fixture", name: "Fixture", version: "1" },
{
operation: "inspect_pcap_capture",
parameters: { path: target.path },
result: report,
confidence: "derived",
authority: "historical-reference",
},
);
return {
predicateType: evidence.predicate_type,
evidenceId: evidence.evidence_id,
operation: evidence.operation,
normalizedResult: report,
subject: evidence.subject,
limitations: evidence.limitations,
};
};
const diagnostics = (offset: number, limit: number) =>
({
kind: "pcap",
facet: "diagnostics",
stream: "tshark",
offset,
limit,
}) as const;
it("pages diagnostics without splitting a surrogate pair", () => {
const parent = capture("ab😀cd");
expect(projectAnalysisView(parent, diagnostics(3, 2))).toMatchObject({
ok: false,
error: { _tag: "AnalysisInputError" },
});
const first = projectAnalysisView(parent, diagnostics(0, 3));
if (!first.ok) throw first.error;
expect(first.value).toMatchObject({
page: { facet: "diagnostics", text: "ab", status: "retained" },
coverage: { examined: 2, total: 6, next_offset: 2 },
});
let text = "";
for (let offset: number | null = 0; offset !== null;) {
const page = projectAnalysisView(parent, diagnostics(offset, 3));
if (!page.ok) throw page.error;
if (page.value.kind !== "pcap" || page.value.page.facet !== "diagnostics")
throw new Error("Expected a diagnostics page.");
text += page.value.page.text;
offset = page.value.coverage.next_offset;
}
expect(text).toBe("ab😀cd");
});
it("selects colliding DNS displays by label identity and retains unknown occurrences", () => {
const parent = capture("", [
{
query: "a.b",
query_labels_hex: ["612e62"],
response_addresses: ["192.0.2.1"],
response_address_count: 1,
},
{
query: "a.b",
query_labels_hex: ["61", "62"],
response_addresses: ["192.0.2.2"],
response_address_count: 1,
},
{
query: "a.b",
query_labels_hex: null,
response_addresses: ["192.0.2.3"],
response_address_count: 1,
},
{
query: "a.b",
query_labels_hex: null,
response_addresses: ["192.0.2.4"],
response_address_count: 1,
},
]);
const view = {
kind: "pcap",
facet: "dns-addresses",
query: "a.b",
offset: 0,
limit: 64,
} as const;
expect(projectAnalysisView(parent, view)).toMatchObject({ ok: false });
expect(
projectAnalysisView(parent, { ...view, query_labels_hex: ["61", "62"] }),
).toMatchObject({ ok: true, value: { page: { items: ["192.0.2.2"] } } });
expect(
projectAnalysisView(parent, { ...view, query_index: 3 }),
).toMatchObject({ ok: true, value: { page: { items: ["192.0.2.4"] } } });
});
it.each([
["executable identity", ["client", "tshark_identity_status"]],
["DNS label identity", ["dns_queries", 0, "query_labels_hex"]],
] as const)(
"refuses capture Evidence that omits %s instead of defaulting it",
(_label, path) => {
const parent = capture("", [
{
query: "a.example",
query_labels_hex: ["61", "6578616d706c65"],
response_addresses: ["192.0.2.9"],
response_address_count: 1,
},
]);
const report = structuredClone(parent.normalizedResult) as Record<
string,
unknown
>;
let owner: unknown = report;
for (const key of path.slice(0, -1))
owner = (owner as Record<string | number, unknown>)[key];
delete (owner as Record<string | number, unknown>)[path.at(-1)!];
expect(
projectAnalysisView(
{ ...parent, normalizedResult: report },
{ kind: "summary" },
),
).toMatchObject({
ok: false,
error: {
_tag: "AnalysisInputError",
issues: [{ path: ["source", "normalized_result", ...path] }],
},
});
},
);