Files
reverse-engineering-anything/src/domain/analysisView/androidPackageView.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

307 lines
8.6 KiB
TypeScript

import { expect, it } from "vitest";
import { createEvidence } from "../evidence.js";
import { projectAnalysisError } from "../analysisErrorProjection.js";
import type { JsonValue } from "../jsonValue.js";
import { projectAnalysisView } from "./analysisView.js";
import type { AnalysisViewParent } from "./analysisViewParent.js";
import {
androidComponentsViewResultSchema,
androidComponentSummaryViewResultSchema,
} from "./analysisViewResult.js";
import { analysisViewRequestSchema } from "./analysisViewRequest.js";
const component = (name: string, extra: Record<string, JsonValue> = {}) => ({
kind: "activity",
declared_name: name,
name,
exported: null,
exported_default: null,
permission: null,
permission_source: "none",
intent_filter_count: 0,
actions: [] as string[],
categories: [],
foreground_service_type: null,
authorities: null,
target_activity: null,
declaration_coverage: "complete",
declaration_index: 0,
location: null,
enabled: null,
enabled_declaration: null,
process: null,
grant_uri_permissions: null,
grant_uri_permissions_declaration: null,
intent_filters: [],
meta_data: [],
...extra,
});
const report = (
items = [
component("example.One", {
declared_name: ".One",
exported: true,
actions: ["VIEW"],
declaration_index: 10,
declaration_coverage: "complete",
}),
component("example.Boot", {
kind: "receiver",
exported_default: true,
actions: ["BOOT"],
declaration_index: 20,
}),
component("example.One", {
declared_name: ".One",
exported: false,
actions: ["VIEW"],
declaration_index: 30,
declaration_coverage: "partial",
}),
],
) => ({
engine: {
name: "jadx",
version: null,
artifact_sha256: "e".repeat(64),
source_revision: null,
worker_count: 1,
heap_limit_mib: null,
},
package_name: "example",
version_name: null,
version_code: null,
min_sdk: null,
target_sdk: "35",
permissions: [],
manifest: {
status: "complete",
text: "<manifest/>",
reported_total_bytes: 11,
},
components: {
status: "partial",
items,
limitations: ["Producer component limit"],
},
class_count: 3,
resource_count: 0,
signature_verification: "not_performed",
});
const parent = (value = report()): AnalysisViewParent => {
const evidence = createEvidence(
{ path: "/retained.apk", sha256: "a".repeat(64), format: "apk" },
{ id: "jadx", name: "JADX", version: "0.7.1" },
{
operation: "inspect_android_package",
parameters: {},
result: value,
limitations: ["Parent condition"],
},
);
return {
predicateType: evidence.predicate_type,
evidenceId: evidence.evidence_id,
operation: evidence.operation,
normalizedResult: value,
subject: evidence.subject,
limitations: evidence.limitations,
};
};
const project = (source: AnalysisViewParent, view: unknown) => {
const result = projectAnalysisView(
source,
analysisViewRequestSchema.parse(view),
);
if (!result.ok) throw result.error;
return result.value;
};
it("keeps parent ordinals, duplicate declarations and coverage after filtering, paging and field selection", () => {
const source = parent();
const before = JSON.stringify(source);
const page = androidComponentsViewResultSchema.parse(
project(source, {
kind: "android",
facet: "components",
names: [".One"],
actions: ["VIEW"],
kinds: ["activity"],
offset: 1,
limit: 1,
fields: ["name", "declaration_index"],
}),
);
expect(page.items).toEqual([
{
source_index: 2,
name: "example.One",
declaration_index: 30,
declaration_coverage: "partial",
},
]);
expect(page.coverage).toMatchObject({
total: 2,
examined: 1,
exhausted: true,
});
expect(page.source_components).toBe(3);
expect(page.source_status).toBe("partial");
expect(page.artifact).toEqual({
path: "/retained.apk",
sha256: "a".repeat(64),
});
expect(page.parent_evidence_id).toBe(source.evidenceId);
expect(page.limitations).toEqual(
expect.arrayContaining(["Parent condition", "Producer component limit"]),
);
expect(JSON.stringify(source)).toBe(before);
});
it("refuses a component without its declaration facets instead of reporting them unknown", () => {
const { declaration_coverage: _coverage, ...unrecorded } =
component("unrecorded.Class");
const result = projectAnalysisView(
parent({
...report(),
components: { status: "complete", items: [unrecorded], limitations: [] },
} as unknown as ReturnType<typeof report>),
analysisViewRequestSchema.parse({ kind: "android", facet: "components" }),
);
expect(result).toMatchObject({
ok: false,
error: {
_tag: "AnalysisInputError",
issues: [
{
path: [
"source",
"normalized_result",
"components",
"items",
0,
"declaration_coverage",
],
},
],
},
});
});
it("counts explicit exported declarations separately from defaults and declaration coverage", () => {
const source = parent();
const summary = androidComponentSummaryViewResultSchema.parse(
project(source, { kind: "android", facet: "component-summary" }),
);
expect(summary.summary).toEqual({
matching_components: 3,
by_kind: {
activity: 2,
"activity-alias": 0,
service: 0,
receiver: 1,
provider: 0,
},
exported_declarations: { true: 1, false: 1, unknown: 1 },
exported_defaults: { true: 1, false: 0, unknown: 2 },
declaration_coverage: { complete: 2, partial: 1 },
});
const explicit = androidComponentsViewResultSchema.parse(
project(source, {
kind: "android",
facet: "components",
exported: true,
fields: [],
}),
);
expect(explicit.items.map((row) => row.source_index)).toEqual([0]);
const unknown = androidComponentSummaryViewResultSchema.parse(
project(source, {
kind: "android",
facet: "component-summary",
exported: null,
}),
);
expect(unknown.summary.matching_components).toBe(1);
expect(unknown.summary.exported_defaults.true).toBe(1);
});
it("preserves partial source coverage on empty filtered pages and never turns empty filters into all rows", () => {
for (const selection of [
{ actions: [] },
{ names: [] },
{ kinds: [] },
{ actions: ["absent"] },
]) {
const page = androidComponentsViewResultSchema.parse(
project(parent(), { kind: "android", facet: "components", ...selection }),
);
expect(page.items).toEqual([]);
expect(page.coverage.total).toBe(0);
expect(page.source_status).toBe("partial");
expect(page.unknowns.join(" ")).toContain("does not establish absence");
}
});
it("bounds selected row serialization and lets field selection recover without changing the source", () => {
const source = parent(
report([
component("large.Class", { process: "x".repeat(2 * 1024 * 1024) }),
]),
);
const wide = projectAnalysisView(
source,
analysisViewRequestSchema.parse({ kind: "android", facet: "components" }),
);
expect(wide).toMatchObject({
ok: false,
error: { _tag: "AnalysisResourceConstraintError" },
});
if (wide.ok) throw new Error("Expected an oversized-row refusal");
expect(projectAnalysisError(wide.error).remediation.action).toContain(
"select fewer fields",
);
const small = androidComponentsViewResultSchema.parse(
project(source, { kind: "android", facet: "components", fields: ["name"] }),
);
expect(small.items).toEqual([
{ source_index: 0, name: "large.Class", declaration_coverage: "complete" },
]);
});
it("returns a resumable byte-limited page instead of silently omitting later rows", () => {
const source = parent(
report(
Array.from({ length: 3 }, (_, index) =>
component(`large.${index}`, { process: "x".repeat(400_000) }),
),
),
);
const first = androidComponentsViewResultSchema.parse(
project(source, {
kind: "android",
facet: "components",
limit: 3,
fields: ["process"],
}),
);
expect(first.byte_limited).toBe(true);
expect(first.items.map((row) => row.source_index)).toEqual([0, 1]);
expect(first.coverage).toMatchObject({
total: 3,
next_offset: 2,
exhausted: false,
});
const last = androidComponentsViewResultSchema.parse(
project(source, {
kind: "android",
facet: "components",
offset: 2,
limit: 3,
fields: ["process"],
}),
);
expect(last.items.map((row) => row.source_index)).toEqual([2]);
expect(last.coverage.exhausted).toBe(true);
});