mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 06:21:12 +00:00
test(decompile): reuse the directory index fixture reader (#16576)
This commit is contained in:
1 parent
4f0ede3153
commit
0ea33dde6f
1 file changed
+34
-149
@@ -60,6 +60,13 @@ import type { JsonValue } from "../../domain/jsonValue.js";
|
||||
import { err, ok } from "../../domain/result.js";
|
||||
import { sha256Hex } from "../../kernel/sha256Hex.js";
|
||||
|
||||
const readIndex = async (root: string) =>
|
||||
decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(join(root, DECOMPILE_DIRECTORY_INDEX_NAME), "utf8"),
|
||||
),
|
||||
);
|
||||
|
||||
const provider = { id: "fixture", name: "Fixture", version: "1" };
|
||||
const profile = createAnalysisProfile(provider, { decompiler: "fixture" });
|
||||
const otherProfile = createAnalysisProfile(provider, { decompiler: "other" });
|
||||
@@ -417,13 +424,6 @@ describe("decompile_all manifest", () => {
|
||||
describe("decompile_all inventory limitations", () => {
|
||||
const directory = useOutputDirectory();
|
||||
|
||||
const readIndex = async (root: string) =>
|
||||
decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(join(root, DECOMPILE_DIRECTORY_INDEX_NAME), "utf8"),
|
||||
),
|
||||
);
|
||||
|
||||
it("keeps the latest selection's limitations without attaching them to historical files", async () => {
|
||||
const created = await run(
|
||||
harness({ listLimitations: ["first inventory limitation"] }).tools,
|
||||
@@ -559,14 +559,7 @@ describe("decompile_all external functions", () => {
|
||||
await expect(
|
||||
stat(join(directory(), "functions", `${address}.c`)),
|
||||
).rejects.toMatchObject({ code: "ENOENT" });
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
expect(index.functions.find((entry) => entry.address === "0x2000")).toEqual(
|
||||
{
|
||||
address: "0x2000",
|
||||
@@ -612,14 +605,7 @@ describe("decompile_all external functions", () => {
|
||||
counts: { requested: 1, skipped: 2, failed: 0, external: 1 },
|
||||
failures: [],
|
||||
});
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
expect(
|
||||
index.functions.find((entry) => entry.address === "0x2000")?.status,
|
||||
).toBe("external");
|
||||
@@ -708,14 +694,7 @@ describe("decompile_all pseudocode absence", () => {
|
||||
expect(failure).not.toHaveProperty("name");
|
||||
expect(failure).not.toHaveProperty("pseudocode_absence");
|
||||
}
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
expect(
|
||||
index.functions.find(({ address }) => address === "0x2000"),
|
||||
).toMatchObject({ pseudocode_absence: absence });
|
||||
@@ -773,14 +752,7 @@ describe("decompile_all resume", () => {
|
||||
expect(resumed.value).toMatchObject({
|
||||
failures: [{ address: "0x1000", code: "output_exists" }],
|
||||
});
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
expect(
|
||||
index.functions.find((record) => record.address === "0x1000")?.body,
|
||||
).toEqual({
|
||||
@@ -857,16 +829,6 @@ describe("decompile_all retained body coverage", () => {
|
||||
index.functions.flatMap(({ body }) =>
|
||||
!body.available && body.reason !== undefined ? [body.reason] : [],
|
||||
);
|
||||
const indexOf = async () =>
|
||||
decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
it("keeps the caveat of retained records through no-op and empty resumes", async () => {
|
||||
const created = await run(
|
||||
harness({ info: "unavailable" }).tools,
|
||||
@@ -877,7 +839,7 @@ describe("decompile_all retained body coverage", () => {
|
||||
const createdLimitations = limitationsOf(created.value);
|
||||
// One caveat counts the retained records and repeats their shared reason.
|
||||
expect(createdLimitations).toHaveLength(1);
|
||||
const createdReason = unavailableReasons(await indexOf())[0];
|
||||
const createdReason = unavailableReasons(await readIndex(directory()))[0];
|
||||
expect(createdReason).toBeDefined();
|
||||
expect(createdLimitations[0]).toMatch(/^3 exported function record/u);
|
||||
expect(createdLimitations[0]).toContain(createdReason);
|
||||
@@ -894,12 +856,16 @@ describe("decompile_all retained body coverage", () => {
|
||||
if (!result.ok) return;
|
||||
expect(result.value).toMatchObject({ counts: { requested: 0 } });
|
||||
expect(limitationsOf(result.value)).toEqual(createdLimitations);
|
||||
expect((await indexOf()).limitations).toEqual(createdLimitations);
|
||||
expect((await readIndex(directory())).limitations).toEqual(
|
||||
createdLimitations,
|
||||
);
|
||||
expect(of(resumed.calls, "procedure_info")).toHaveLength(0);
|
||||
}
|
||||
expect(await readFile(file, "utf8")).toBe(before);
|
||||
expect(
|
||||
(await indexOf()).functions.map((record) => record.body.available),
|
||||
(await readIndex(directory())).functions.map(
|
||||
(record) => record.body.available,
|
||||
),
|
||||
).toEqual([false, false, false]);
|
||||
});
|
||||
|
||||
@@ -917,7 +883,7 @@ describe("decompile_all retained body coverage", () => {
|
||||
counts: { written: 1, skipped: 2 },
|
||||
});
|
||||
// Differing reasons are counted together without naming either one.
|
||||
const reasons = new Set(unavailableReasons(await indexOf()));
|
||||
const reasons = new Set(unavailableReasons(await readIndex(directory())));
|
||||
expect(reasons.size).toBe(2);
|
||||
const mixedCaveats = limitationsOf(mixed.value).filter((limitation) =>
|
||||
limitation.startsWith("3 exported function record"),
|
||||
@@ -932,7 +898,7 @@ describe("decompile_all retained body coverage", () => {
|
||||
if (!known.ok) return;
|
||||
expect(known.value).toMatchObject({ counts: { written: 3 } });
|
||||
expect(limitationsOf(known.value).join("\n")).not.toContain("body");
|
||||
expect((await indexOf()).limitations).toEqual([]);
|
||||
expect((await readIndex(directory())).limitations).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1206,14 +1172,7 @@ describe("decompile_all partial results", () => {
|
||||
expect(shown.length).toBeGreaterThan(0);
|
||||
expect(shown.length).toBeLessThanOrEqual(32);
|
||||
expect(result.value).toMatchObject({ failures_omitted: 33 - shown.length });
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
expect(
|
||||
index.functions.filter((record) => record.status === "failed"),
|
||||
).toHaveLength(33);
|
||||
@@ -1368,14 +1327,7 @@ describe("decompile_all partial results", () => {
|
||||
await expect(
|
||||
readFile(join(directory(), "functions/0x2000.c")),
|
||||
).rejects.toMatchObject({ code: "ENOENT" });
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
expect(index.functions.map((record) => record.address)).toEqual(["0x1000"]);
|
||||
const next = harness({ procedures });
|
||||
const resumed = await run(next.tools, directory(), { resume: true });
|
||||
@@ -1421,14 +1373,7 @@ describe("decompile_all caller coordinates", () => {
|
||||
expect(result.value).toMatchObject({
|
||||
counts: { selected: 1, excluded: 2, written: 1 },
|
||||
});
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
expect(index.functions).toMatchObject([
|
||||
{ address: "RAM%3Aoverlay:0xabcd", name: "in_range", status: "written" },
|
||||
]);
|
||||
@@ -1475,14 +1420,7 @@ describe("decompile_all portable function paths", () => {
|
||||
expect(result.value).toMatchObject({
|
||||
counts: { selected: 2, written: 2, failed: 0 },
|
||||
});
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
const names = index.functions.map((record) =>
|
||||
record.relative_path!.toLowerCase(),
|
||||
);
|
||||
@@ -1676,14 +1614,7 @@ describe("decompile_all untrusted directory and provider facts", () => {
|
||||
await expect(
|
||||
readFile(join(directory(), "functions/0x1000.c"), "utf8"),
|
||||
).resolves.toContain(sentinel);
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
expect(
|
||||
index.functions.find((record) => record.address === "0x1000")
|
||||
?.relative_path,
|
||||
@@ -1715,16 +1646,9 @@ describe("decompile_all journal recovery", () => {
|
||||
const directory = useOutputDirectory();
|
||||
|
||||
const indexRecord = async (address: string) =>
|
||||
decompileDirectoryIndexSchema
|
||||
.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
)
|
||||
.functions.find((record) => record.address === address);
|
||||
(await readIndex(directory())).functions.find(
|
||||
(record) => record.address === address,
|
||||
);
|
||||
|
||||
it("keeps a written file's checksum through a read error and skips it once readable", async () => {
|
||||
expect((await run(harness().tools, directory())).ok).toBe(true);
|
||||
@@ -2099,14 +2023,7 @@ describe("decompile_all output directory lease", () => {
|
||||
expect(resumed.ok).toBe(true);
|
||||
if (!resumed.ok) return;
|
||||
expect(resumed.value).toMatchObject({ counts: { skipped: 3, written: 0 } });
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
expect(index.functions.map((record) => record.status)).toEqual([
|
||||
"written",
|
||||
"written",
|
||||
@@ -2164,14 +2081,7 @@ describe("decompile_all repeated output failures", () => {
|
||||
).toBeLessThan(4_096);
|
||||
// The index was still written and records the five failures; the sixth
|
||||
// and seventh blocked functions were not attempted.
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
expect(
|
||||
index.functions
|
||||
.filter((record) => record.failure?.code === "output_io")
|
||||
@@ -2313,14 +2223,7 @@ describe("decompile_all provider cleanup ownership", () => {
|
||||
expect(failure.capturedOutput?.stdout).toBe("retained provider output");
|
||||
expect(failure.cleanupIncomplete).toBe(true);
|
||||
expect(observed.at(-1)).toBe(operation);
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
expect(index.functions).toHaveLength(1);
|
||||
expect(index.functions[0]).toMatchObject({
|
||||
address: "0x1000",
|
||||
@@ -2672,14 +2575,7 @@ describe("decompile_all settled function outcome precedence", () => {
|
||||
expect(result.error).toBeInstanceOf(AnalysisCancelledError);
|
||||
expect(result.error.cause).toBe(reason);
|
||||
expect(calls).toBe(independent ? 2 : 1);
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
if (!typedCancellation)
|
||||
expect(index.functions).toMatchObject([
|
||||
{
|
||||
@@ -2754,11 +2650,7 @@ it("keeps a settled null failure but starts no independent retry after caller ab
|
||||
expect(result.error).toBeInstanceOf(AnalysisCancelledError);
|
||||
expect(result.error.cause).toBe(reason);
|
||||
expect(calls).toBe(1);
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(join(directory, DECOMPILE_DIRECTORY_INDEX_NAME), "utf8"),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory);
|
||||
expect(index.functions).toMatchObject([
|
||||
{
|
||||
status: "failed",
|
||||
@@ -3139,14 +3031,7 @@ describe("decompile_all grouped commits", () => {
|
||||
COMMIT_GROUP_SIZE,
|
||||
);
|
||||
expect(await stagingDirectories()).toEqual([]);
|
||||
const index = decompileDirectoryIndexSchema.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
join(directory(), DECOMPILE_DIRECTORY_INDEX_NAME),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const index = await readIndex(directory());
|
||||
expect(index.functions.map((record) => record.address)).toEqual(kept);
|
||||
const resumed = await run(harness({ procedures }).tools, directory(), {
|
||||
resume: true,
|
||||
|
||||
Reference in new issue
Block a user