fix(docs): resolve captured main conflicts and review findings
This commit is contained in:
@@ -173,6 +173,50 @@ try {
|
||||
assert.deepEqual(structured.normalized_result, evidence.normalized_result);
|
||||
console.log(`PASS MCP/CLI parity ${task.name}`);
|
||||
}
|
||||
const overloadedInput = {
|
||||
path,
|
||||
class_name: "androidx.activity.ComponentActivity",
|
||||
method_name: "setContentView",
|
||||
overload_index: 0,
|
||||
};
|
||||
const overloadedCli = await execute(
|
||||
process.execPath,
|
||||
[
|
||||
entrypoint,
|
||||
"trace-android-references",
|
||||
path,
|
||||
overloadedInput.class_name,
|
||||
"--method-name",
|
||||
overloadedInput.method_name,
|
||||
"--overload-index",
|
||||
"0",
|
||||
"--format",
|
||||
"json",
|
||||
],
|
||||
{
|
||||
cwd: repository,
|
||||
env: environment,
|
||||
timeout: 150_000,
|
||||
maxBuffer: 8 * 1024 * 1024,
|
||||
},
|
||||
);
|
||||
const overloadedEvidence = parseEvidence(JSON.parse(overloadedCli.stdout));
|
||||
assert.equal(overloadedEvidence.normalized_result.overload_index, 0);
|
||||
assert.equal(
|
||||
overloadedEvidence.normalized_result.reported_signature,
|
||||
"setContentView(int): void",
|
||||
);
|
||||
assert.equal(overloadedEvidence.normalized_result.total, 1);
|
||||
const overloadedMcp = await client.callTool(
|
||||
{ name: "trace_android_references", arguments: overloadedInput },
|
||||
{ timeout: 150_000 },
|
||||
);
|
||||
assert.notEqual(overloadedMcp.isError, true, JSON.stringify(overloadedMcp));
|
||||
assert.deepEqual(
|
||||
parseEvidence(overloadedMcp.structuredContent).normalized_result,
|
||||
overloadedEvidence.normalized_result,
|
||||
);
|
||||
console.log("PASS real overloaded method references through CLI/MCP");
|
||||
} catch (cause) {
|
||||
process.stderr.write(stderr);
|
||||
throw cause;
|
||||
@@ -205,7 +249,7 @@ assert.equal(method.body_status, "available");
|
||||
assert.equal(method.source.status, "complete");
|
||||
assert.ok(method.source.text.includes("getIntent()"));
|
||||
assert.ok(method.source.text.includes("setListAdapter"));
|
||||
assert.equal(method.method.dex_descriptor, null);
|
||||
assert.equal(method.method.dex_descriptor, "(Landroid/os/Bundle;)V");
|
||||
const references = cliResults.get("trace_android_references").normalized_result;
|
||||
assert.ok(references.total > 0);
|
||||
assert.ok(
|
||||
@@ -264,3 +308,8 @@ if (process.env.REA_ANDROID_REPORT !== undefined)
|
||||
JSON.stringify(report, null, 2) + "\n",
|
||||
);
|
||||
console.log(JSON.stringify(report, null, 2));
|
||||
assert.notEqual(
|
||||
windowsLifecycle?.cli_abrupt_owner_exit_workspace_cleanup,
|
||||
false,
|
||||
"Android workspace remained after abrupt owner exit",
|
||||
);
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { parseEvidence } from "../../../dist/domain/evidence.js";
|
||||
import { hashAndroidFile } from "./digest.mjs";
|
||||
|
||||
/** The public result keeps one using node and exposes its two raw DEX invokes. */
|
||||
export const verifyAndroidDirectInvokes = async ({
|
||||
apk,
|
||||
dexEntry,
|
||||
repository,
|
||||
entrypoint,
|
||||
environment,
|
||||
execute,
|
||||
}) => {
|
||||
const digest = await hashAndroidFile(apk);
|
||||
const check = (value) => {
|
||||
const evidence = parseEvidence(value);
|
||||
assert.equal(evidence.subject.digest.sha256, digest);
|
||||
assert.equal(evidence.operation, "trace_android_references");
|
||||
const result = evidence.normalized_result;
|
||||
assert.equal(result.class_name, "fixture.Target");
|
||||
assert.equal(result.method_name, "mark");
|
||||
assert.equal(result.dex_descriptor, "()V");
|
||||
assert.equal(result.reference_unit, "using_node");
|
||||
assert.equal(result.total, 1);
|
||||
assert.equal(result.references.length, 1);
|
||||
const source = result.references[0];
|
||||
assert.equal(source.reported_full_name, "fixture.Caller.twice");
|
||||
assert.deepEqual(
|
||||
source.direct_invokes.map((site) => site.dex_code_unit_offset),
|
||||
[0, 3],
|
||||
);
|
||||
for (const site of source.direct_invokes) {
|
||||
assert.equal(site.dex_entry, dexEntry);
|
||||
assert.equal(site.source_raw_method_id, "fixture.Caller.twice()V");
|
||||
assert.equal(site.opcode, "INVOKE_STATIC");
|
||||
}
|
||||
assert.equal(
|
||||
source.direct_invokes[0].dex_method_index,
|
||||
source.direct_invokes[1].dex_method_index,
|
||||
);
|
||||
return evidence;
|
||||
};
|
||||
const cliResponse = await execute(
|
||||
process.execPath,
|
||||
[
|
||||
entrypoint,
|
||||
"trace-android-references",
|
||||
apk,
|
||||
"fixture.Target",
|
||||
"--method-name",
|
||||
"mark",
|
||||
"--format",
|
||||
"json",
|
||||
],
|
||||
{
|
||||
cwd: repository,
|
||||
env: environment,
|
||||
timeout: 150_000,
|
||||
maxBuffer: 8 * 1024 * 1024,
|
||||
},
|
||||
);
|
||||
const cli = check(JSON.parse(cliResponse.stdout));
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
cwd: repository,
|
||||
env: environment,
|
||||
stderr: "pipe",
|
||||
});
|
||||
let stderr = "";
|
||||
transport.stderr?.on("data", (chunk) => {
|
||||
stderr += chunk.toString();
|
||||
});
|
||||
const client = new Client({
|
||||
name: "rea-real-android-direct-invokes",
|
||||
version: "1",
|
||||
});
|
||||
try {
|
||||
await client.connect(transport, { timeout: 30_000 });
|
||||
const response = await client.callTool(
|
||||
{
|
||||
name: "trace_android_references",
|
||||
arguments: {
|
||||
path: apk,
|
||||
class_name: "fixture.Target",
|
||||
method_name: "mark",
|
||||
},
|
||||
},
|
||||
{ timeout: 150_000 },
|
||||
);
|
||||
assert.notEqual(response.isError, true, JSON.stringify(response));
|
||||
const mcp = check(response.structuredContent);
|
||||
assert.deepEqual(mcp.normalized_result, cli.normalized_result);
|
||||
assert.deepEqual(mcp.parameters, cli.parameters);
|
||||
assert.deepEqual(mcp.provider, cli.provider);
|
||||
} catch (cause) {
|
||||
process.stderr.write(stderr);
|
||||
throw cause;
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
assert.equal(
|
||||
await hashAndroidFile(apk),
|
||||
digest,
|
||||
"Static inspection changed fixture bytes",
|
||||
);
|
||||
console.log(
|
||||
`PASS real CLI/MCP direct-invoke offsets from ${dexEntry}, parity and unchanged APK`,
|
||||
);
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { delimiter, join, resolve } from "node:path";
|
||||
import { verifyAndroidInitializers } from "./initializers.mjs";
|
||||
import { verifyAndroidDirectInvokes } from "./direct-invokes.mjs";
|
||||
|
||||
/** Prove cold metadata stays unmaterialized and overload identities survive code generation. */
|
||||
export const verifyAndroidMetadata = async ({
|
||||
@@ -60,6 +61,7 @@ export const verifyAndroidMetadata = async ({
|
||||
apk,
|
||||
resolve(repository, "tests/fixtures/android/static-initializers"),
|
||||
classes,
|
||||
resolve(repository, "tests/fixtures/android/direct-invokes"),
|
||||
],
|
||||
{ timeout: 120_000, maxBuffer: 8 * 1024 * 1024 },
|
||||
);
|
||||
@@ -71,12 +73,19 @@ export const verifyAndroidMetadata = async ({
|
||||
result.stdout,
|
||||
/INITIALIZER_REGRESSION_PASS folded=2 bounded=true/u,
|
||||
);
|
||||
assert.match(
|
||||
result.stdout,
|
||||
/DIRECT_INVOKE_REGRESSION_PASS nodes=1 offsets=0,3 cross_dex=true/u,
|
||||
);
|
||||
console.log(
|
||||
"PASS real cold metadata, full generic types and stable overloaded method selection",
|
||||
);
|
||||
console.log(
|
||||
"PASS real folded and mixed static initializers, absent bodies and bounded smali",
|
||||
);
|
||||
console.log(
|
||||
"PASS real raw DEX direct-invoke offsets and cross-DEX source identity",
|
||||
);
|
||||
await verifyAndroidInitializers({
|
||||
apk: resolve(classes, "initializers.apk"),
|
||||
repository,
|
||||
@@ -84,6 +93,22 @@ export const verifyAndroidMetadata = async ({
|
||||
environment,
|
||||
execute,
|
||||
});
|
||||
await verifyAndroidDirectInvokes({
|
||||
apk: resolve(classes, "direct-invokes.apk"),
|
||||
dexEntry: "classes.dex",
|
||||
repository,
|
||||
entrypoint,
|
||||
environment,
|
||||
execute,
|
||||
});
|
||||
await verifyAndroidDirectInvokes({
|
||||
apk: resolve(classes, "direct-invokes-multidex.apk"),
|
||||
dexEntry: "classes2.dex",
|
||||
repository,
|
||||
entrypoint,
|
||||
environment,
|
||||
execute,
|
||||
});
|
||||
} finally {
|
||||
await rm(classes, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { spawn } from "node:child_process";
|
||||
import { stat, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
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";
|
||||
|
||||
const source = fileURLToPath(import.meta.url);
|
||||
const marker = "REA synthetic guardian isolation test\n";
|
||||
const exists = (path) =>
|
||||
stat(path).then(
|
||||
() => true,
|
||||
() => false,
|
||||
);
|
||||
|
||||
if (process.argv[1] === source && process.argv[2] === "owner") {
|
||||
const root = await createJadxWorkspaceRoot();
|
||||
await writeFile(join(root.path, "synthetic.txt"), marker);
|
||||
process.stdout.write(JSON.stringify({ path: root.path }) + "\n");
|
||||
await new Promise(() => {});
|
||||
}
|
||||
|
||||
const bounded = async (promise, milliseconds, label) => {
|
||||
let timer;
|
||||
try {
|
||||
return await Promise.race([
|
||||
promise,
|
||||
new Promise((_, reject) => {
|
||||
timer = setTimeout(() => reject(new Error(label)), milliseconds);
|
||||
}),
|
||||
]);
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
};
|
||||
|
||||
const launch = async () => {
|
||||
const child = spawn(process.execPath, [source, "owner"], {
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
windowsHide: true,
|
||||
});
|
||||
let stderr = "";
|
||||
child.stderr.on("data", (chunk) => {
|
||||
stderr = (stderr + chunk.toString()).slice(-8192);
|
||||
});
|
||||
const exit = new Promise((resolve, reject) => {
|
||||
child.once("close", resolve);
|
||||
child.once("error", reject);
|
||||
});
|
||||
const lines = createInterface({ input: child.stdout, crlfDelay: Infinity });
|
||||
try {
|
||||
const ready = await bounded(
|
||||
lines[Symbol.asyncIterator]().next(),
|
||||
20000,
|
||||
`Android guardian owner readiness timed out: ${stderr}`,
|
||||
);
|
||||
assert.equal(ready.done, false, stderr);
|
||||
const { path } = JSON.parse(ready.value);
|
||||
assert.equal(typeof path, "string");
|
||||
assert.equal(await exists(join(path, "synthetic.txt")), true);
|
||||
return { child, exit, path };
|
||||
} catch (cause) {
|
||||
child.kill();
|
||||
await bounded(exit, 15000, "Android guardian owner did not exit");
|
||||
throw cause;
|
||||
}
|
||||
};
|
||||
|
||||
const stop = async ({ child, exit, path }) => {
|
||||
assert.equal(child.kill(), true);
|
||||
await bounded(exit, 15000, "Android guardian owner did not exit");
|
||||
for (let attempt = 0; attempt < 100; attempt++) {
|
||||
if (!(await exists(path))) return;
|
||||
await delay(100);
|
||||
}
|
||||
throw new Error(`Android guardian retained ${path} after owner death`);
|
||||
};
|
||||
|
||||
/** Two independent owners must never delete one another's private workspace. */
|
||||
export async function verifyWindowsGuardianIsolation() {
|
||||
assert.equal(process.platform, "win32");
|
||||
const first = await launch();
|
||||
let second;
|
||||
try {
|
||||
second = await launch();
|
||||
assert.notEqual(first.path, second.path);
|
||||
await stop(first);
|
||||
assert.equal(
|
||||
await exists(join(second.path, "synthetic.txt")),
|
||||
true,
|
||||
"First owner deleted the second owner's workspace",
|
||||
);
|
||||
await stop(second);
|
||||
console.log("PASS Windows Android guardian two-owner cleanup isolation");
|
||||
} finally {
|
||||
for (const owner of [first, second]) {
|
||||
if (owner === undefined) continue;
|
||||
if (owner.child.exitCode === null && owner.child.signalCode === null)
|
||||
owner.child.kill();
|
||||
await bounded(owner.exit, 15000, "Android guardian owner did not exit");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
resolveJadxConfigurationInputs,
|
||||
validateJadxConfiguration,
|
||||
} from "../../../dist/android/JadxConfiguration.js";
|
||||
import { verifyWindowsGuardianIsolation } from "./windows-guardian-isolation.mjs";
|
||||
|
||||
/** Verify real Windows cancellation, disconnect and abrupt CLI owner exit. */
|
||||
export async function verifyWindowsAndroidLifecycle(options) {
|
||||
@@ -24,15 +25,16 @@ export async function verifyWindowsAndroidLifecycle(options) {
|
||||
await verifyJavaSelection(options.environment);
|
||||
const cancellation = await verifyMcp(options, "cancel");
|
||||
await verifyMcp(options, "disconnect");
|
||||
await verifyCliOwnerExit(options);
|
||||
const abruptWorkspaceRemoved = await verifyCliOwnerExit(options);
|
||||
await verifyWindowsGuardianIsolation();
|
||||
return {
|
||||
mcp_cancelled_engine_exited: true,
|
||||
mcp_cancelled_workspace_removed: true,
|
||||
mcp_ping_and_next_call: true,
|
||||
mcp_disconnect_engine_exited: true,
|
||||
cli_abrupt_owner_exit_engine_exited: true,
|
||||
// A forced Windows process exit cannot execute JavaScript workspace cleanup.
|
||||
cli_abrupt_owner_exit_workspace_cleanup: false,
|
||||
cli_abrupt_owner_exit_workspace_cleanup: abruptWorkspaceRemoved,
|
||||
guardian_two_owner_isolation: true,
|
||||
observed_resources: cancellation,
|
||||
java_home_and_quoted_case_insensitive_path: true,
|
||||
};
|
||||
@@ -161,6 +163,7 @@ async function verifyCliOwnerExit({
|
||||
path,
|
||||
repository,
|
||||
}) {
|
||||
const baseline = new Set(await runtimeRoots());
|
||||
const child = spawn(
|
||||
process.execPath,
|
||||
[entrypoint, "inspect-android-package", path, "--format", "json"],
|
||||
@@ -185,7 +188,40 @@ async function verifyCliOwnerExit({
|
||||
await deadline(exited, 15000);
|
||||
await observer.verifyExit();
|
||||
assert.equal(output, "", "Aborted CLI published successful Evidence");
|
||||
console.log("PASS Windows CLI abrupt owner exit: real Java job cleanup");
|
||||
const created = (await runtimeRoots()).filter(
|
||||
(name) => !baseline.has(name),
|
||||
);
|
||||
assert.ok(
|
||||
created.length <= 1,
|
||||
"Concurrent Android workspaces make abrupt cleanup observation ambiguous",
|
||||
);
|
||||
if (created.length === 0) {
|
||||
console.log(
|
||||
"PASS Windows CLI abrupt owner exit: real Java job and workspace cleanup",
|
||||
);
|
||||
return true;
|
||||
}
|
||||
const ownedName = created[0];
|
||||
try {
|
||||
await waitFor(
|
||||
async () => !(await runtimeRoots()).includes(ownedName),
|
||||
5000,
|
||||
"Android workspace remained after abrupt owner exit",
|
||||
);
|
||||
} catch (cause) {
|
||||
if (
|
||||
!(cause instanceof Error) ||
|
||||
cause.message !== "Android workspace remained after abrupt owner exit"
|
||||
)
|
||||
throw cause;
|
||||
}
|
||||
const removed = !(await runtimeRoots()).includes(ownedName);
|
||||
console.log(
|
||||
removed
|
||||
? "PASS Windows CLI abrupt owner exit: real Java job and workspace cleanup"
|
||||
: "OBSERVED Windows CLI abrupt owner exit: Java job cleaned, workspace residue remains",
|
||||
);
|
||||
return removed;
|
||||
} finally {
|
||||
if (child.exitCode === null && child.signalCode === null) child.kill();
|
||||
await deadline(exited, 15000);
|
||||
|
||||
Reference in New Issue
Block a user