refactor(android): take the host in JADX configuration, doctor and workspace roots (#11086)

* refactor(android): take the host in JADX configuration, doctor and workspace roots

* fix(android): pass the host in verifiers, follow it for JAVA_HOME, and test the native cache split

* test(platform): count tests that redefine process.platform or process.arch (#11102)

Tests select a host by injection. A redefined process.platform stops exercising its branch once the module under test reads HOST_PLATFORM, and still passes. A counted baseline (105 sites in 20 files) may only shrink; each module migration switches its tests to injection.
This commit is contained in:
morluto authored and GitHub committed 2026-11-15 20:52:58 +08:00
1 parent eab8abe948
commit 5d4e9b8532
18 files changed
+220 -147

No files matched your search

+2
View File
@@ -16,6 +16,7 @@ import { verifyAndroidMetadata } from "./metadata.mjs";
import { verifyAndroidClassSearch } from "./class-search.mjs";
import { verifyAndroidFailureRecovery } from "./failure-recovery.mjs";
import { resolveJadxConfigurationInputs } from "../../../dist/android/JadxConfiguration.js";
import { HOST_PLATFORM } from "../../../dist/platform/HostPlatform.js";
import { validateVerifierJadxConfiguration } from "../../lib/jadx-configuration-inspection.mjs";
import { verifyWindowsAndroidLifecycle } from "./windows-lifecycle.mjs";
@@ -41,6 +42,7 @@ assert.equal(
const configuration = await resolveJadxConfigurationInputs(
process.env,
"inspect_android_package",
HOST_PLATFORM,
);
await validateVerifierJadxConfiguration(
configuration,
@@ -6,6 +6,7 @@ import { createInterface } from "node:readline";
import { setTimeout as delay } from "node:timers/promises";
import { fileURLToPath } from "node:url";
import { createJadxWorkspaceRoot } from "../../../dist/android/JadxWorkspaceRoot.js";
import { HOST_PLATFORM } from "../../../dist/platform/HostPlatform.js";
const source = fileURLToPath(import.meta.url);
const marker = "REA synthetic guardian isolation test\n";
@@ -19,7 +20,7 @@ const exists = (path) =>
);
if (process.argv[1] === source && process.argv[2] === "owner") {
const root = await createJadxWorkspaceRoot();
const root = await createJadxWorkspaceRoot(HOST_PLATFORM.platform);
await writeFile(join(root.path, "synthetic.txt"), marker);
process.stdout.write(JSON.stringify({ path: root.path }) + "\n");
await new Promise(() => {});
@@ -82,8 +83,10 @@ const stop = async ({ child, exit, path }) => {
};
/** Two independent owners must never delete one another's private workspace. */
export async function verifyWindowsGuardianIsolation() {
assert.equal(process.platform, "win32");
export async function verifyWindowsGuardianIsolation(
platform = HOST_PLATFORM.platform,
) {
assert.equal(platform, "win32");
const first = await launch();
let second;
try {
@@ -7,6 +7,7 @@ import { setTimeout as delay } from "node:timers/promises";
import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { resolveJadxConfigurationInputs } from "../../../dist/android/JadxConfiguration.js";
import { HOST_PLATFORM } from "../../../dist/platform/HostPlatform.js";
import { validateVerifierJadxConfiguration } from "../../lib/jadx-configuration-inspection.mjs";
import { verifyWindowsGuardianIsolation } from "./windows-guardian-isolation.mjs";
import {
@@ -39,6 +40,7 @@ async function verifyJavaSelection(environment) {
const selected = await resolveJadxConfigurationInputs(
environment,
"inspect_android_package",
HOST_PLATFORM,
);
await validateVerifierJadxConfiguration(
selected,
@@ -70,6 +72,7 @@ async function verifyJavaSelection(environment) {
const onPath = await resolveJadxConfigurationInputs(
pathEnvironment,
"inspect_android_package",
HOST_PLATFORM,
);
await validateVerifierJadxConfiguration(
onPath,
@@ -280,8 +280,6 @@
"src/adb/AdbDeviceOutput.ts": 1,
"src/adb/AdbHostFileName.ts": 1,
"src/adb/AdbProvider.ts": 1,
"src/android/JadxConfiguration.ts": 10,
"src/android/JadxWorkspaceRoot.ts": 1,
"src/apktool/ApktoolConfiguration.ts": 4,
"src/apktool/ApktoolProvider.ts": 2,
"src/application/BinaryTargetResolver.ts": 1,
@@ -358,11 +356,9 @@
"src/server/registerSessionTools.ts": 3,
"src/serverIdentity.ts": 1,
"src/signals/SigrokRecordingProvider.ts": 1,
"src/wasm/WabtArtifactProvider.ts": 1,
"src/windows/WindowsNativeLoader.ts": 1
"src/wasm/WabtArtifactProvider.ts": 1
},
"ambient-host-architecture": {
"src/android/JadxConfiguration.ts": 4,
"src/application/BinaryTargetResolver.ts": 1,
"src/application/Doctor.ts": 1,
"src/application/LinuxHopper.ts": 1,
@@ -370,8 +366,7 @@
"src/evm/EvmoleInterfaceProvider.ts": 2,
"src/javascript/recovery/WakaruCommand.ts": 1,
"src/native/pwntools/PwntoolsDecoder.ts": 2,
"src/server/createServer.ts": 1,
"src/windows/WindowsNativeLoader.ts": 1
"src/server/createServer.ts": 1
},
"hand-caught-configuration-error": {
"src/application/binary/BinarySession.ts": 3,
@@ -459,5 +454,26 @@
"lifecycle-plain-throw": {
"src/android/JadxWorkspaceRoot.ts": 4,
"src/native/pwntools/PwntoolsDecoder.ts": 1
},
"test-host-platform-stub": {
"src/application/binaryDiagnostics/ByteEntropyService.test.ts": 1,
"src/browser/ElectronCaptureCleanup.test.ts": 2,
"src/browser/PlaywrightElectronActiveProvider.test.ts": 2,
"src/browser/PlaywrightScenarioBrowser.test.ts": 3,
"src/browser/modules/NativeModuleResolver.test.ts": 3,
"src/pcap/PcapNativeBound.test.ts": 2,
"tests/boundary/browser/historicalCaptureDecoder.test.ts": 2,
"tests/boundary/cli/debuggerOneShotExit.test.ts": 1,
"tests/boundary/evm/evmCleanupRetry.test.ts": 52,
"tests/boundary/filesystem/webScriptExport.test.ts": 2,
"tests/boundary/filesystem/webScriptManifestPaths.test.ts": 2,
"tests/boundary/native/pwntoolsArtifactCleanup.test.ts": 4,
"tests/boundary/process/artifactSelectedCommand.test.ts": 6,
"tests/boundary/process/nativeUiVerifierActions.test.ts": 1,
"tests/process-global/hostRestrictedAvailabilityMcp.test.ts": 4,
"tests/process-global/pwntoolsCleanup.test.ts": 4,
"tests/process-global/pwntoolsCliFinalization.test.ts": 4,
"tests/process-global/pwntoolsCliRemediation.test.ts": 4,
"tests/process-global/pwntoolsStageRetirement.test.ts": 4
}
}
+33
View File
@@ -567,6 +567,39 @@ checkCounted(
["src/platform/HostPlatform.ts"],
);
// Tests select a platform or architecture by injecting it (a parameter, a
// `host` option, or a mock of src/platform/HostPlatform). Redefining
// process.platform or process.arch stops exercising its branch once the module
// under test takes the host from HostPlatform, and still passes. Each module
// migration switches its tests to injection and lowers this baseline.
const listTestFiles = async (dir) => {
const output = [];
for (const entry of await readdir(dir, { withFileTypes: true })) {
const path = join(dir, entry.name);
if (entry.isDirectory()) output.push(...(await listTestFiles(path)));
else if (/\.(?:test|spec|fixture)\.ts$/u.test(entry.name))
output.push(path);
}
return output;
};
const testFiles = await Promise.all(
[
...(await listTestFiles(join(root, "src"))),
...(await listFiles(join(root, "tests"))),
...(await listTestFiles(join(root, "tests"))),
].map(async (path) => ({
path: relative(root, path).split(sep).join("/"),
content: await readFile(path, "utf8"),
})),
);
checkCounted(
"test redefines process.platform or process.arch (inject the platform: pass it as a parameter or host option, or mock src/platform/HostPlatform)",
"test-host-platform-stub",
testFiles,
/\b(?:defineProperty|spyOn)\(\s*(?:globalThis\.)?process\s*,\s*["'`](?:platform|arch)["'`]/gu,
[],
);
// `find` on a parsed section, program-header or load-command table silently
// keeps the first of repeated declarations. Select keyed entries through
// src/domain/keyedCollection (`uniqueKeyed`, `allKeyed`, or