mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 15:33:56 +08:00
test(analysis): share native view page requests (#17393)
This commit is contained in:
@@ -77,6 +77,12 @@ const nativeParent = (
|
||||
artifact: { path: "/fixtures/example.exe", sha256: "a".repeat(64) },
|
||||
});
|
||||
|
||||
const nativePage = (
|
||||
facet: Extract<AnalysisViewRequest, { kind: "native" }>["facet"],
|
||||
offset: number,
|
||||
limit: number,
|
||||
) => ({ kind: "native", facet, offset, limit }) as const;
|
||||
|
||||
it("returns input errors for malformed parent Evidence identifiers before projection", () => {
|
||||
for (const evidenceId of [`xx_${"a".repeat(64)}`, "ev_bad"])
|
||||
expect(
|
||||
@@ -92,12 +98,7 @@ it("returns input errors for malformed parent Evidence identifiers before projec
|
||||
|
||||
it("projects native procedure and bounded assembly and high-pcode with exact parent identity", () => {
|
||||
const parent = nativeParent();
|
||||
const procedure = projectAnalysisView(parent, {
|
||||
kind: "native",
|
||||
facet: "procedure",
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
});
|
||||
const procedure = projectAnalysisView(parent, nativePage("procedure", 0, 64));
|
||||
if (!procedure.ok) throw procedure.error;
|
||||
expect(procedure.value).toMatchObject({
|
||||
kind: "native",
|
||||
@@ -106,23 +107,16 @@ it("projects native procedure and bounded assembly and high-pcode with exact par
|
||||
item: { address: "0x401000" },
|
||||
});
|
||||
expect(procedure.value.view_digest).not.toBe(parent.evidenceId.slice(3));
|
||||
const assembly = projectAnalysisView(parent, {
|
||||
kind: "native",
|
||||
facet: "assembly",
|
||||
offset: 0,
|
||||
limit: 1,
|
||||
});
|
||||
const assembly = projectAnalysisView(parent, nativePage("assembly", 0, 1));
|
||||
if (!assembly.ok) throw assembly.error;
|
||||
expect(assembly.value).toMatchObject({
|
||||
coverage: { examined: 1, total: 2, next_offset: 1 },
|
||||
item: ["0x401000: CALL 0x401020"],
|
||||
});
|
||||
const flow = projectAnalysisView(parent, {
|
||||
kind: "native",
|
||||
facet: "value_flow_operations",
|
||||
offset: 0,
|
||||
limit: 1,
|
||||
});
|
||||
const flow = projectAnalysisView(
|
||||
parent,
|
||||
nativePage("value_flow_operations", 0, 1),
|
||||
);
|
||||
if (!flow.ok) throw flow.error;
|
||||
expect(flow.value).toMatchObject({ item: [{ opcode: "COPY" }] });
|
||||
});
|
||||
@@ -322,12 +316,7 @@ it("keeps provider-unavailable facets unknown in the analyze_function summary",
|
||||
});
|
||||
|
||||
it("rejects invalid native parents, unsupported source operations and singleton offsets", () => {
|
||||
const view = {
|
||||
kind: "native",
|
||||
facet: "assembly",
|
||||
offset: 0,
|
||||
limit: 4,
|
||||
} as const;
|
||||
const view = nativePage("assembly", 0, 4);
|
||||
expect(projectAnalysisView(nativeParent({}), view)).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisInputError" },
|
||||
@@ -347,23 +336,13 @@ it("rejects invalid native parents, unsupported source operations and singleton
|
||||
error: { _tag: "AnalysisInputError" },
|
||||
});
|
||||
expect(
|
||||
projectAnalysisView(nativeParent(), {
|
||||
kind: "native",
|
||||
facet: "procedure",
|
||||
offset: 1,
|
||||
limit: 2,
|
||||
}),
|
||||
projectAnalysisView(nativeParent(), nativePage("procedure", 1, 2)),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||
});
|
||||
|
||||
it("preserves native API limitations and unavailable residual unknowns", () => {
|
||||
const original = functionDossierSchema.parse(ghidraFunctionDossier());
|
||||
const view = {
|
||||
kind: "native",
|
||||
facet: "procedure",
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
} as const;
|
||||
const view = nativePage("procedure", 0, 64);
|
||||
const unavailable = projectAnalysisView(
|
||||
nativeParent({
|
||||
...original,
|
||||
@@ -420,12 +399,10 @@ it("pages every retained dossier collection and the native API record", () => {
|
||||
| "swift_string_literals",
|
||||
result: unknown = original,
|
||||
) => {
|
||||
const view = projectAnalysisView(nativeParent(result), {
|
||||
kind: "native",
|
||||
facet,
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
});
|
||||
const view = projectAnalysisView(
|
||||
nativeParent(result),
|
||||
nativePage(facet, 0, 64),
|
||||
);
|
||||
if (!view.ok) throw view.error;
|
||||
return view.value;
|
||||
};
|
||||
@@ -472,12 +449,10 @@ it("pages every retained dossier collection and the native API record", () => {
|
||||
},
|
||||
}),
|
||||
).toMatchObject({ item: { available: false, reason: "not recorded" } });
|
||||
const api = projectAnalysisView(nativeParent(), {
|
||||
kind: "native",
|
||||
facet: "native_api",
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
});
|
||||
const api = projectAnalysisView(
|
||||
nativeParent(),
|
||||
nativePage("native_api", 0, 64),
|
||||
);
|
||||
if (!api.ok) throw api.error;
|
||||
expect(api.value).toMatchObject({
|
||||
item: original.native_api,
|
||||
@@ -491,12 +466,7 @@ it("reports the malformed native dossier field", () => {
|
||||
...functionDossierSchema.parse(ghidraFunctionDossier()),
|
||||
pseudocode: 12,
|
||||
}),
|
||||
{
|
||||
kind: "native",
|
||||
facet: "pseudocode",
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
},
|
||||
nativePage("pseudocode", 0, 64),
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
@@ -536,19 +506,9 @@ it("native pseudocode pages do not split surrogate pairs", () => {
|
||||
const original = functionDossierSchema.parse(ghidraFunctionDossier());
|
||||
const parent = nativeParent({ ...original, pseudocode: "ab😀cd" });
|
||||
expect(
|
||||
projectAnalysisView(parent, {
|
||||
kind: "native",
|
||||
facet: "pseudocode",
|
||||
offset: 3,
|
||||
limit: 2,
|
||||
}),
|
||||
projectAnalysisView(parent, nativePage("pseudocode", 3, 2)),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||
const safe = projectAnalysisView(parent, {
|
||||
kind: "native",
|
||||
facet: "pseudocode",
|
||||
offset: 2,
|
||||
limit: 3,
|
||||
});
|
||||
const safe = projectAnalysisView(parent, nativePage("pseudocode", 2, 3));
|
||||
if (!safe.ok) throw safe.error;
|
||||
expect(safe.value).toMatchObject({
|
||||
item: { text: "😀c", unit: "utf16-code-units" },
|
||||
@@ -558,7 +518,7 @@ it("native pseudocode pages do not split surrogate pairs", () => {
|
||||
|
||||
it.each([
|
||||
{ kind: "page", collection: "sections", offset: 0, limit: 500 },
|
||||
{ kind: "native", facet: "assembly", offset: 0, limit: 500 },
|
||||
nativePage("assembly", 0, 500),
|
||||
])(
|
||||
"accepts caller-selected page sizes and rejects malformed bounds: $kind",
|
||||
(view) => {
|
||||
@@ -1759,12 +1719,7 @@ it("preserves selected native facet unavailability instead of an exhausted empty
|
||||
["comments", "Typed comments unavailable"],
|
||||
["incoming_references", "Typed references unavailable"],
|
||||
] as const) {
|
||||
const result = projectAnalysisView(parent, {
|
||||
kind: "native",
|
||||
facet,
|
||||
offset: 0,
|
||||
limit: 8,
|
||||
});
|
||||
const result = projectAnalysisView(parent, nativePage(facet, 0, 8));
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value).toMatchObject({
|
||||
item: { available: false, reason },
|
||||
@@ -2702,10 +2657,8 @@ it("caches sealed inspect_byte_entropy and analyze_function parents across repea
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
projectAnalysisView(
|
||||
{ ...sealedNative },
|
||||
{ kind: "native", facet: "procedure", offset: 0, limit: 64 },
|
||||
).ok,
|
||||
projectAnalysisView({ ...sealedNative }, nativePage("procedure", 0, 64))
|
||||
.ok,
|
||||
).toBe(true);
|
||||
expect(dossierSpy).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user