Files
rea/scripts/fixtures/android/fetch.mjs
Xiangfang Chen 3ca89d8272 feat(android): pin jadx-headless-mcp 0.8.0
Move the audited engine release and its submodule gitlink from v0.7.1 to
v0.8.0 (commit 2b2a560e, sha256 4b9a01c2...). Upstream only changed
source-window paging and metadata-only field reads, so the six tools REA
consumes and the bridge identity stay unchanged.

Hand-copied version numbers now derive from JADX_RELEASE: the fixture
download name, the metadata-bridge workflow path and the fake MCP
server's reported engine version. The composition fallback availability
text no longer names a release, because the Android boundary owns the
versioned remediation.

Validation: build:cached, check:fast, docs:check, test:focused over the
16 Android test files (296 tests), and verify:android against the real
0.8.0 JAR and ApiDemos 6.0.18.
2026-11-22 16:01:00 +08:00

73 lines
2.3 KiB
JavaScript

import { createHash, randomUUID } from "node:crypto";
import { createReadStream } from "node:fs";
import { link, mkdir, open, rm } from "node:fs/promises";
import { resolve, join } from "node:path";
import { fileURLToPath } from "node:url";
import { JADX_RELEASE } from "../../../src/android/JadxRelease.ts";
import fixture from "./apidemos.json" with { type: "json" };
const args = process.argv.slice(2);
if (args.length > 1)
throw new Error("Usage: npm run fixtures:android -- [DIRECTORY]");
const directory = resolve(
args[0] ??
fileURLToPath(
new URL("../../../_reference/apk-integration/", import.meta.url),
),
);
await mkdir(directory, { recursive: true });
const hashFile = async (path) => {
const hash = createHash("sha256");
for await (const chunk of createReadStream(path)) hash.update(chunk);
return hash.digest("hex");
};
for (const item of [
{
url: JADX_RELEASE.url,
sha256: JADX_RELEASE.sha256,
filename: `jadx-headless-mcp-${JADX_RELEASE.version}-all.jar`,
},
fixture,
]) {
const path = join(directory, item.filename);
try {
const digest = await hashFile(path);
if (digest !== item.sha256)
throw new Error(
`Existing ${path} has a different SHA-256; it was not overwritten`,
);
console.log(`Verified existing ${path}: ${digest}`);
continue;
} catch (cause) {
if (!(cause instanceof Error && "code" in cause && cause.code === "ENOENT"))
throw cause;
}
const temporary = `${path}.${randomUUID()}.partial`;
try {
const response = await fetch(item.url, {
signal: AbortSignal.timeout(120_000),
});
if (!response.ok || response.body === null)
throw new Error(`Download failed: ${item.url}: HTTP ${response.status}`);
const handle = await open(temporary, "wx", 0o600);
const hash = createHash("sha256");
try {
for await (const chunk of response.body) {
hash.update(chunk);
await handle.writeFile(chunk);
}
} finally {
await handle.close();
}
const digest = hash.digest("hex");
if (digest !== item.sha256)
throw new Error(
`SHA-256 mismatch for ${item.filename}: expected ${item.sha256}, received ${digest}`,
);
await link(temporary, path);
console.log(`Downloaded and verified ${path}: ${digest}`);
} finally {
await rm(temporary, { force: true });
}
}