Files
rea/tests/fixtures/javascript-recovery/producer.mjs
T
ded59689ce fix(javascript): accept the Wakaru 1.x release line and verify 1.14.0 (#1540)
* fix(javascript): accept the Wakaru 1.x release line and verify 1.14.0

Exact --version equality rejected every Wakaru build except 1.13.0, and
strict report schemas rejected any added field, so each upstream release
broke recovery until REA re-pinned. Wakaru now documents that --version,
--json and provenance.json change only by addition within a major version.

Admit ^1.13.0 with the verified/compatible split used for Binwalk and
Unblob, report the observed version instead of the pinned constant, and
add a limitation for unverified releases. Parse reports with loose
objects and keep the reported module status as a string; path, identity,
range and file-set checks stay exact.

Move the audited pin, submodule, CI binary and verifier to 1.14.0, and
document where to get the binary from the refusal message.

* fix(javascript): project known Wakaru warning fields

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-10-10 23:02:15 +08:00

129 lines
3.9 KiB
JavaScript

import { readFile, symlink, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
const args = process.argv.slice(2);
const mode = process.env.REA_RECOVERY_FIXTURE_MODE ?? "normal";
if (args.includes("--version")) {
console.log(
mode === "wrong-version"
? "wakaru 0.0.0"
: mode === "additive"
? "wakaru 1.99.0"
: "wakaru 1.14.0",
);
} else {
const input = args[0];
const output = args[args.indexOf("-o") + 1];
const bytes = await readFile(input);
await writeFile(join(dirname(output), "recovery-started"), "started");
if (mode === "hang") await new Promise(() => setInterval(() => {}, 1000));
if (mode === "startup-error") {
console.error("fixture: unsupported producer dependency");
process.exit(2);
}
if (mode === "snapshot-change")
await writeFile(input, Buffer.alloc(bytes.length, 0x61));
if (mode === "engine-change")
await writeFile(
process.env.REA_RECOVERY_ENGINE_PATH,
"#!/bin/sh\nexit 1\n",
);
if (mode === "source-change")
await writeFile(process.env.REA_RECOVERY_ORIGINAL_PATH, "changed original");
const filename = mode === "escaping" ? "../escaped.js" : "module.js";
const modules = [
mode === "additive"
? {
filename,
kind: "javascript",
status: "future_status",
future_module_field: true,
}
: { filename, kind: "javascript", status: "decompiled" },
];
if (mode === "duplicate") modules.push(modules[0]);
if (mode !== "missing-file" && mode !== "escaping") {
if (mode === "symlink") await symlink(input, join(output, filename));
else
await writeFile(join(output, filename), "export const recovered = 42;\n");
}
if (mode === "extra-file")
await writeFile(join(output, "extra.js"), "unreported");
if (mode === "directory-symlink")
await symlink(dirname(input), join(output, "nested"));
if (mode === "bad-map") await writeFile(join(output, "module.js.map"), "{}");
if (mode === "normal")
await writeFile(
join(output, "module.js.map"),
JSON.stringify({
version: 3,
file: "module.js",
sources: ["../inputs/bundle.js"],
names: [],
mappings: "AAAA",
}),
);
const ranges =
mode === "overflow-range"
? [[0, bytes.length + 1]]
: mode === "utf8-range"
? [[0, 2]]
: [[0, bytes.length]];
const provenance = {
format: "unknown",
strategy: "structural",
modules: {
[filename]: {
input: mode === "source-mismatch" ? "/different.js" : input,
ranges,
extraction: "structural",
},
},
};
if (mode === "additive") {
provenance.future_top_field = "added";
provenance.modules[filename].future_entry_field = [1];
}
if (mode === "extra-provenance")
provenance.modules["extra.js"] = provenance.modules[filename];
if (mode !== "missing-provenance")
await writeFile(
join(output, "provenance.json"),
JSON.stringify(provenance),
);
const report = {
detected_formats: [],
safety: "normal",
modules,
warnings:
mode === "partial"
? [
{
filename,
kind: "parse_error",
is_error: true,
message: "fixture transform failed; retained source",
},
]
: mode === "additive"
? [
{
filename,
kind: "notice",
is_error: false,
message: "future warning",
code: "W001",
},
]
: [],
...(mode === "additive" ? { future_report_field: { nested: true } } : {}),
total: modules.length,
failed: mode === "partial" ? 1 : 0,
elapsed_ms: 1,
};
console.log(
mode === "malformed-report" ? "{invalid}" : JSON.stringify(report),
);
if (mode === "partial") process.exitCode = 1;
}