Files
reverse-engineering-anything/tests/boundary/filesystem/evidenceExportCleanupRetry.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

127 lines
4.1 KiB
TypeScript

import { EVIDENCE_FORMAT_REVISION } from "../../../src/domain/evidenceFormat.js";
import { readdir, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it, vi } from "vitest";
import { exportEvidenceBundleCommand } from "../../../src/application/EvidenceBundleCommands.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
// Host filesystems cannot fail publication and then one staging removal on
// demand; every other export step runs on the real filesystem.
const fault = vi.hoisted(() => ({
publication: false,
stagingRemovalFailures: 0,
stagingRemovals: 0,
}));
vi.mock("node:fs/promises", async (importOriginal) => {
const filesystem = await importOriginal<typeof import("node:fs/promises")>();
return {
...filesystem,
link: async (...args: Parameters<typeof filesystem.link>) => {
if (fault.publication)
throw Object.assign(new Error("injected publication EACCES"), {
code: "EACCES",
});
return filesystem.link(...args);
},
rmdir: async (...args: Parameters<typeof filesystem.rmdir>) => {
if (String(args[0]).includes(".rea-write-")) {
fault.stagingRemovals += 1;
if (fault.stagingRemovals <= fault.stagingRemovalFailures)
throw Object.assign(new Error("injected staging removal EBUSY"), {
code: "EBUSY",
});
}
return filesystem.rmdir(...args);
},
};
});
const emptyBundle = JSON.stringify({
evidence_format: EVIDENCE_FORMAT_REVISION,
artifacts: [],
providers: [],
environments: [],
scenarios: [],
captures: [],
unknowns: [],
records: [],
});
it.each([
{
name: "restores the publication failure after a confirmed staging retry",
publication: true,
stagingRemovalFailures: 1,
stagingRemovals: 2,
code: "execution_failure",
retained: false,
},
{
name: "keeps cleanup incomplete with its stage when the retry also fails",
publication: true,
stagingRemovalFailures: 2,
stagingRemovals: 2,
code: "cleanup_incomplete",
retained: true,
},
{
name: "returns the published receipt after a confirmed staging retry",
publication: false,
stagingRemovalFailures: 1,
stagingRemovals: 2,
code: undefined,
retained: false,
},
])("$name", async (scenario) => {
const root = await createTestTempDirectory("rea-export-cleanup-retry-");
const source = join(root, "source.json");
const output = join(root, "out.json");
await writeFile(source, emptyBundle);
Object.assign(fault, {
publication: scenario.publication,
stagingRemovalFailures: scenario.stagingRemovalFailures,
stagingRemovals: 0,
});
try {
const result = await exportEvidenceBundleCommand(source, output, false);
expect(fault.stagingRemovals).toBe(scenario.stagingRemovals);
const entries = await readdir(root);
const stages = entries.filter((entry) => entry.startsWith(".rea-write-"));
expect(stages).toHaveLength(scenario.retained ? 1 : 0);
expect(entries.includes("out.json")).toBe(!scenario.publication);
if (scenario.code === undefined) {
expect(result).toMatchObject({
ok: true,
value: { path: output, records: 0 },
});
return;
}
if (result.ok) throw new Error("Expected export failure");
const projected = projectAnalysisError(result.error);
expect(projected.code).toBe(scenario.code);
expect(projected.details).toMatchObject({
operation: "write",
reason: "io",
path: output,
});
if (!scenario.retained) {
expect(projected.details).not.toHaveProperty("cleanup");
expect(projected.details).not.toHaveProperty("resources");
return;
}
expect(projected.details).toMatchObject({
cleanup: "incomplete",
cleanup_reason: "injected staging removal EBUSY",
execution_failure: "execution_failure",
resources: [join(root, stages[0]!)],
});
} finally {
Object.assign(fault, { publication: false, stagingRemovalFailures: 0 });
await rm(root, { recursive: true, force: true });
}
});