chore: merge main and resolve PR #902 conflicts
This commit is contained in:
@@ -40,5 +40,43 @@ it("accepts a verified explicit java binary and canonicalizes the JAR", async ()
|
||||
{ REA_JADX_MCP_JAR: jar, JAVA_HOME: javaHome },
|
||||
"inspect_android_package",
|
||||
),
|
||||
).resolves.toEqual({ jar: await realpath(jar), java });
|
||||
).resolves.toEqual({ jar: await realpath(jar), java, jvmArguments: [] });
|
||||
});
|
||||
|
||||
it("configures heap and visible processors independently without forcing either", async () => {
|
||||
const root = await createTestTempDirectory("rea-jadx-config-");
|
||||
const jar = join(root, "engine.jar");
|
||||
await writeFile(jar, "fixture jar");
|
||||
const configuration = await resolveJadxConfiguration(
|
||||
{
|
||||
REA_JADX_MCP_JAR: jar,
|
||||
REA_JADX_HEAP_MIB: "8192",
|
||||
REA_JADX_ACTIVE_PROCESSOR_COUNT: "4",
|
||||
},
|
||||
"inspect_android_package",
|
||||
);
|
||||
expect(configuration.jvmArguments).toEqual([
|
||||
"-Xmx8192m",
|
||||
"-XX:ActiveProcessorCount=4",
|
||||
]);
|
||||
await expect(
|
||||
resolveJadxConfiguration(
|
||||
{ REA_JADX_MCP_JAR: jar, REA_JADX_ACTIVE_PROCESSOR_COUNT: "2147483648" },
|
||||
"inspect_android_package",
|
||||
),
|
||||
).rejects.toMatchObject({
|
||||
_tag: "AnalysisCapabilityUnavailableError",
|
||||
reason: expect.stringContaining("32-bit"),
|
||||
});
|
||||
for (const name of ["REA_JADX_HEAP_MIB", "REA_JADX_ACTIVE_PROCESSOR_COUNT"])
|
||||
for (const value of ["", "0", "-1", "1.5", "8g", " 4", "9007199254740992"])
|
||||
await expect(
|
||||
resolveJadxConfiguration(
|
||||
{ REA_JADX_MCP_JAR: jar, [name]: value },
|
||||
"inspect_android_package",
|
||||
),
|
||||
).rejects.toMatchObject({
|
||||
_tag: "AnalysisCapabilityUnavailableError",
|
||||
reason: expect.stringContaining(name),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import { expect, it as test } from "vitest";
|
||||
import { expect, it as test, vi } from "vitest";
|
||||
import { access, readFile, writeFile } from "node:fs/promises";
|
||||
import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
|
||||
import { AndroidAnalysisService } from "../../../src/application/android/AndroidAnalysisService.js";
|
||||
import { JadxProvider } from "../../../src/android/JadxProvider.js";
|
||||
import { androidResultSchemas } from "../../../src/domain/android/androidAnalysis.js";
|
||||
import {
|
||||
hashAndroidFile,
|
||||
snapshotAndroidEngine,
|
||||
} from "../../../src/android/AndroidTargetSnapshot.js";
|
||||
import { PrivateRuntimeRoot } from "../../../src/process/PrivateRuntimeRoot.js";
|
||||
import {
|
||||
createJadxProtocolFixture as setup,
|
||||
verifyJadxFixtureCleanup as verifyCleanup,
|
||||
@@ -11,6 +16,182 @@ import {
|
||||
|
||||
const it = test.skipIf(process.platform === "win32");
|
||||
|
||||
it("rejects a copied JAR that differs from its admitted session identity", async () => {
|
||||
const { jar } = await setup();
|
||||
const admitted = await hashAndroidFile(jar);
|
||||
await writeFile(jar, "engine changed between hashing and copying");
|
||||
const root = await PrivateRuntimeRoot.create({
|
||||
prefix: "rea-jadx-admission-",
|
||||
});
|
||||
try {
|
||||
await expect(
|
||||
snapshotAndroidEngine(
|
||||
jar,
|
||||
admitted,
|
||||
root.path,
|
||||
"inspect_android_package",
|
||||
),
|
||||
).rejects.toMatchObject({
|
||||
_tag: "AnalysisCapabilityUnavailableError",
|
||||
reason: expect.stringContaining("bytes changed"),
|
||||
});
|
||||
} finally {
|
||||
await root.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("reuses immutable engine state while keeping each Evidence observation separate", async () => {
|
||||
const { service, apk, launches, provider } = await setup();
|
||||
const first = await service.execute("inspect_android_package", { path: apk });
|
||||
if (!first.ok) throw first.error;
|
||||
const preserved = JSON.stringify(first.value);
|
||||
const second = await service.execute("inspect_android_class", {
|
||||
path: apk,
|
||||
class_name: "fixture.Target",
|
||||
});
|
||||
if (!second.ok) throw second.error;
|
||||
expect(launches).toHaveLength(1);
|
||||
expect(JSON.stringify(first.value)).toBe(preserved);
|
||||
expect(second.value.raw_result).toMatchObject({
|
||||
loaded: { class_count: 401 },
|
||||
calls: [
|
||||
expect.objectContaining({ operation: "rea_jvm_status" }),
|
||||
expect.objectContaining({ operation: "get_class_summary" }),
|
||||
],
|
||||
});
|
||||
expect(
|
||||
androidResultSchemas.inspect_android_class.parse(
|
||||
second.value.normalized_result,
|
||||
).engine.heap_limit_mib,
|
||||
).toBe(8192);
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
});
|
||||
|
||||
it("bounds output per operation across a retained session rather than accumulating earlier captures", async () => {
|
||||
const { service, apk, launches, provider } = await setup("large-manifest");
|
||||
for (let index = 0; index < 34; index += 1) {
|
||||
const result = await service.execute("inspect_android_package", {
|
||||
path: apk,
|
||||
});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(
|
||||
androidResultSchemas.inspect_android_package.parse(
|
||||
result.value.normalized_result,
|
||||
).manifest.text.length,
|
||||
).toBe(1024 * 1024);
|
||||
}
|
||||
expect(launches).toHaveLength(1);
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
});
|
||||
|
||||
it("retire sessions when APK bytes, engine bytes or JVM options change", async () => {
|
||||
const { service, apk, jar, launches, provider, environment } = await setup();
|
||||
const inspect = async () => {
|
||||
const result = await service.execute("inspect_android_package", {
|
||||
path: apk,
|
||||
});
|
||||
if (!result.ok) throw result.error;
|
||||
return result.value;
|
||||
};
|
||||
const first = await inspect();
|
||||
await writeFile(
|
||||
apk,
|
||||
Buffer.concat([await readFile(apk), Buffer.from("new artifact bytes")]),
|
||||
);
|
||||
const changed = await inspect();
|
||||
expect(changed.subject?.digest.sha256).not.toBe(first.subject?.digest.sha256);
|
||||
await verifyCleanup(launches.slice(0, 1));
|
||||
await writeFile(jar, "new engine bytes");
|
||||
await inspect();
|
||||
environment.JAVA_TOOL_OPTIONS = "-Xmx8g";
|
||||
environment._JAVA_OPTIONS = "-XX:+UseG1GC";
|
||||
await inspect();
|
||||
expect(launches).toHaveLength(4);
|
||||
expect(launches[3]).toMatchObject({
|
||||
javaToolOptions: "-Xmx8g",
|
||||
legacyJavaOptions: "-XX:+UseG1GC",
|
||||
});
|
||||
expect(launches[3]?.arguments).not.toContain("-Xmx512m");
|
||||
expect(launches[3]?.arguments).not.toContain("-XX:ActiveProcessorCount=1");
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
});
|
||||
|
||||
it("retires an idle engine and starts a fresh one for a later request", async () => {
|
||||
const { service, apk, launches, provider } = await setup();
|
||||
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
|
||||
try {
|
||||
const first = await service.execute("inspect_android_package", {
|
||||
path: apk,
|
||||
});
|
||||
if (!first.ok) throw first.error;
|
||||
vi.advanceTimersByTime(60_000);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
await expect
|
||||
.poll(async () => {
|
||||
try {
|
||||
await verifyCleanup(launches);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.toBe(true);
|
||||
const later = await service.execute("inspect_android_package", { path: apk });
|
||||
if (!later.ok) throw later.error;
|
||||
expect(launches).toHaveLength(2);
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
});
|
||||
|
||||
it("completes large class inventories with exact case-sensitive search semantics", async () => {
|
||||
const { service, apk, provider } = await setup("large-inventory");
|
||||
const full = await service.execute("search_android_classes", {
|
||||
path: apk,
|
||||
query: "",
|
||||
});
|
||||
if (!full.ok) throw full.error;
|
||||
const inventory = androidResultSchemas.search_android_classes.parse(
|
||||
full.value.normalized_result,
|
||||
);
|
||||
expect(inventory.matches).toHaveLength(9001);
|
||||
expect(inventory.matches.at(-1)).toBe("fixture.Class8999");
|
||||
const mixedCase = await service.execute("search_android_classes", {
|
||||
path: apk,
|
||||
query: "target",
|
||||
});
|
||||
if (!mixedCase.ok) throw mixedCase.error;
|
||||
expect(
|
||||
androidResultSchemas.search_android_classes.parse(
|
||||
mixedCase.value.normalized_result,
|
||||
).matches,
|
||||
).toEqual([]);
|
||||
await provider.close();
|
||||
});
|
||||
|
||||
it("close cancels active and queued work and prevents later acquisition", async () => {
|
||||
const { service, apk, launches, provider } = await setup("stall");
|
||||
const active = service.execute("inspect_android_package", { path: apk });
|
||||
await expect.poll(() => launches.length).toBe(1);
|
||||
const queued = service.execute("inspect_android_package", { path: apk });
|
||||
await provider.close();
|
||||
for (const result of [
|
||||
await active,
|
||||
await queued,
|
||||
await service.execute("inspect_android_package", { path: apk }),
|
||||
])
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCancelledError" },
|
||||
});
|
||||
expect(launches).toHaveLength(1);
|
||||
await verifyCleanup(launches);
|
||||
});
|
||||
|
||||
it("does not carry a factory instance's cleanup failure into another instance", async () => {
|
||||
const failed = await setup("cleanup-failure");
|
||||
const healthy = await setup();
|
||||
@@ -25,11 +206,12 @@ it("does not carry a factory instance's cleanup failure into another instance",
|
||||
path: healthy.apk,
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
await healthy.provider.close();
|
||||
await verifyCleanup(healthy.launches);
|
||||
});
|
||||
|
||||
it("retains APK identity, original input, raw producer data and normalized observations", async () => {
|
||||
const { service, apk, launches } = await setup();
|
||||
const { service, apk, launches, provider } = await setup();
|
||||
const outcome = await service.execute("inspect_android_package", {
|
||||
path: apk,
|
||||
});
|
||||
@@ -47,11 +229,12 @@ it("retains APK identity, original input, raw producer data and normalized obser
|
||||
expect.objectContaining({ operation: "get_android_manifest" }),
|
||||
]),
|
||||
});
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
});
|
||||
|
||||
it("fetches all class pages rather than silently retaining the first upstream page", async () => {
|
||||
const { service, apk, launches } = await setup();
|
||||
const { service, apk, launches, provider } = await setup();
|
||||
const outcome = await service.execute("search_android_classes", {
|
||||
path: apk,
|
||||
query: "",
|
||||
@@ -63,11 +246,12 @@ it("fetches all class pages rather than silently retaining the first upstream pa
|
||||
expect(result.total_classes).toBe(401);
|
||||
expect(result.matches).toHaveLength(401);
|
||||
expect(result.matches.at(-1)).toBe("fixture.Class399");
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
});
|
||||
|
||||
it("exposes overload candidates and executes only an explicitly selected ambiguous method", async () => {
|
||||
const { service, apk, launches } = await setup();
|
||||
const { service, apk, launches, provider } = await setup();
|
||||
const input = {
|
||||
path: apk,
|
||||
class_name: "fixture.Target",
|
||||
@@ -105,9 +289,10 @@ it("exposes overload candidates and executes only an explicitly selected ambiguo
|
||||
ok: false,
|
||||
error: {
|
||||
_tag: "AnalysisCapabilityUnavailableError",
|
||||
reason: expect.stringContaining("first same-name"),
|
||||
reason: expect.stringContaining("unique method name"),
|
||||
},
|
||||
});
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
});
|
||||
|
||||
@@ -121,7 +306,7 @@ it.each([
|
||||
])(
|
||||
"rejects producer failure %s rather than claiming complete analysis",
|
||||
async (mode) => {
|
||||
const { service, apk, launches } = await setup(mode);
|
||||
const { service, apk, launches, provider } = await setup(mode);
|
||||
const operation =
|
||||
mode === "wrong-apk"
|
||||
? "inspect_android_package"
|
||||
@@ -142,13 +327,14 @@ it.each([
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisOutputError" },
|
||||
});
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
},
|
||||
);
|
||||
|
||||
it("rejects fuzzy class resolution and unsupported upstream versions", async () => {
|
||||
for (const mode of ["wrong-class", "version"]) {
|
||||
const { service, apk, launches } = await setup(mode);
|
||||
for (const mode of ["wrong-class", "version", "engine-version"]) {
|
||||
const { service, apk, launches, provider } = await setup(mode);
|
||||
const outcome = await service.execute("inspect_android_class", {
|
||||
path: apk,
|
||||
class_name: "fixture.Target",
|
||||
@@ -157,11 +343,12 @@ it("rejects fuzzy class resolution and unsupported upstream versions", async ()
|
||||
ok: false,
|
||||
error: {
|
||||
_tag:
|
||||
mode === "version"
|
||||
mode === "version" || mode === "engine-version"
|
||||
? "AnalysisCapabilityUnavailableError"
|
||||
: "AnalysisInputError",
|
||||
},
|
||||
});
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
}
|
||||
});
|
||||
@@ -169,7 +356,7 @@ it("rejects fuzzy class resolution and unsupported upstream versions", async ()
|
||||
it.each(["truncated", "smali"])(
|
||||
"retains %s source coverage instead of presenting it as successful complete Java",
|
||||
async (mode) => {
|
||||
const { service, apk, launches } = await setup(mode);
|
||||
const { service, apk, launches, provider } = await setup(mode);
|
||||
const outcome = await service.execute("inspect_android_method", {
|
||||
path: apk,
|
||||
class_name: "fixture.Target",
|
||||
@@ -186,12 +373,13 @@ it.each(["truncated", "smali"])(
|
||||
if (mode === "truncated")
|
||||
expect(result.source.reported_total_bytes).toBe(100);
|
||||
else expect(result.fell_back).toBe(true);
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
},
|
||||
);
|
||||
|
||||
it("cancels active and queued requests, cleans ownership and never launches a queued cancelled request", async () => {
|
||||
const { service, apk, launches } = await setup("stall");
|
||||
const { service, apk, launches, provider } = await setup("stall");
|
||||
const activeController = new AbortController();
|
||||
const active = service.execute(
|
||||
"inspect_android_package",
|
||||
@@ -216,6 +404,7 @@ it("cancels active and queued requests, cleans ownership and never launches a qu
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCancelledError" },
|
||||
});
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
});
|
||||
|
||||
@@ -240,7 +429,7 @@ it("reports missing explicit tools without trying to install or launch them", as
|
||||
it.each(["tool-error", "frame-overflow"])(
|
||||
"preserves the actual failed provider constraint for %s",
|
||||
async (mode) => {
|
||||
const { service, apk, launches } = await setup(mode);
|
||||
const { service, apk, launches, provider } = await setup(mode);
|
||||
const outcome = await service.execute("inspect_android_package", {
|
||||
path: apk,
|
||||
});
|
||||
@@ -257,6 +446,7 @@ it.each(["tool-error", "frame-overflow"])(
|
||||
_tag: "AnalysisOutputError",
|
||||
reason: expect.stringContaining("MCP frame exceeds"),
|
||||
});
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
},
|
||||
);
|
||||
@@ -287,7 +477,7 @@ it("rejects bytes changed after target admission without launching an engine", a
|
||||
});
|
||||
|
||||
it("retains an uncertain workspace and blocks later launches after cleanup cannot be verified", async () => {
|
||||
const { service, apk, launches } = await setup("cleanup-failure");
|
||||
const { service, apk, launches, provider } = await setup("cleanup-failure");
|
||||
const outcome = await service.execute("inspect_android_package", {
|
||||
path: apk,
|
||||
});
|
||||
@@ -305,7 +495,7 @@ it("retains an uncertain workspace and blocks later launches after cleanup canno
|
||||
});
|
||||
|
||||
it("does not attribute upstream smali containing all overloads to the selected method", async () => {
|
||||
const { service, apk, launches } = await setup("overloaded-smali");
|
||||
const { service, apk, launches, provider } = await setup("overloaded-smali");
|
||||
const outcome = await service.execute("inspect_android_method", {
|
||||
path: apk,
|
||||
class_name: "fixture.Target",
|
||||
@@ -319,11 +509,12 @@ it("does not attribute upstream smali containing all overloads to the selected m
|
||||
reason: expect.stringContaining("joins all same-name overloads"),
|
||||
},
|
||||
});
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
});
|
||||
|
||||
it("reports missing native/abstract method source without claiming an empty implementation", async () => {
|
||||
const { service, apk, launches } = await setup("no-body");
|
||||
const { service, apk, launches, provider } = await setup("no-body");
|
||||
const outcome = await service.execute("inspect_android_method", {
|
||||
path: apk,
|
||||
class_name: "fixture.Target",
|
||||
@@ -335,5 +526,6 @@ it("reports missing native/abstract method source without claiming an empty impl
|
||||
);
|
||||
expect(result.body_status).toBe("not_available");
|
||||
expect(result.source.text).toContain("no decompiled body");
|
||||
await provider.close();
|
||||
await verifyCleanup(launches);
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import { expect, it, onTestFinished, vi } from "vitest";
|
||||
import { CdpBrowserProvider } from "../../../src/browser/CdpBrowserProvider.js";
|
||||
import { CdpElectronProvider } from "../../../src/browser/CdpElectronProvider.js";
|
||||
import { observeWebSessionInputSchema } from "../../../src/domain/browserSession.js";
|
||||
import { inspectElectronPageInputSchema } from "../../../src/domain/electronObservation.js";
|
||||
import { inspectElectronPageInputSchema } from "../../../src/domain/javascript/electronObservation.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { startFakeCdpBrowser } from "../../fixtures/fakeCdpBrowser.js";
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import { CdpElectronProvider } from "../../../src/browser/CdpElectronProvider.js
|
||||
import {
|
||||
inspectElectronPageInputSchema,
|
||||
listElectronTargetsInputSchema,
|
||||
} from "../../../src/domain/electronObservation.js";
|
||||
} from "../../../src/domain/javascript/electronObservation.js";
|
||||
import {
|
||||
startFakeCdpBrowser,
|
||||
type FakeCdpBrowser,
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
type FakeCdpBrowser,
|
||||
} from "../../fixtures/fakeCdpBrowser.js";
|
||||
import { writeElectronBoundaryFixture } from "../../fixtures/electronBoundaryApplication.js";
|
||||
import { JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE } from "../../../src/contracts/javascriptRuntimeReconciliationExample.js";
|
||||
import { JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE } from "../../../src/contracts/javascript/javascriptRuntimeReconciliationExample.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
const INTEGRATION_TEST_TIMEOUT_MS = 20_000;
|
||||
|
||||
@@ -8,7 +8,7 @@ import { afterEach, describe, expect, test } from "vitest";
|
||||
|
||||
import { observeJavaScriptRuntime } from "../../../src/application/javascript/JavaScriptRuntimeObservationService.js";
|
||||
import { V8InspectorProvider } from "../../../src/inspector/V8InspectorProvider.js";
|
||||
import { observeJavaScriptRuntimeInputSchema } from "../../../src/domain/javascriptRuntimeObservation.js";
|
||||
import { observeJavaScriptRuntimeInputSchema } from "../../../src/domain/javascript/javascriptRuntimeObservation.js";
|
||||
import { startFakeV8Inspector } from "../../fixtures/inspector/fakeV8Inspector.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
|
||||
@@ -111,6 +111,34 @@ describe("bounded Interface Builder archive decoding", () => {
|
||||
expect(result.graph.truncated).toBe(true);
|
||||
});
|
||||
|
||||
it("marks archive decoding partial when __proto__ entries are omitted", async () => {
|
||||
const root = await createTestTempDirectory("rea-ib-test-");
|
||||
const bundle = join(root, "Example.app");
|
||||
const resources = join(bundle, "Contents", "Resources");
|
||||
await mkdir(resources, { recursive: true });
|
||||
await writeFile(
|
||||
join(resources, "Prototype.nib"),
|
||||
'<?xml version="1.0"?><plist version="1.0"><dict><key>$archiver</key><string>NSKeyedArchiver</string><key>__proto__</key><string>hidden</string><key>$objects</key><array><string>$null</string></array><key>$top</key><dict/></dict></plist>',
|
||||
);
|
||||
|
||||
const result = await analyzeInterfaceBuilderBundle({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "f".repeat(64),
|
||||
});
|
||||
|
||||
expect(result.graph.coverage).toContainEqual(
|
||||
expect.objectContaining({
|
||||
facet: "archive_decode",
|
||||
status: "partial",
|
||||
reason: "dictionary_entries_omitted",
|
||||
}),
|
||||
);
|
||||
expect(result.graph.truncated).toBe(true);
|
||||
expect(result.limitations).toContain(
|
||||
"Contents/Resources/Prototype.nib: 1 dictionary entry keyed __proto__ was omitted because REA results cannot represent that key.",
|
||||
);
|
||||
});
|
||||
|
||||
it.skipIf(process.platform !== "darwin" || !existsSync("/usr/bin/ibtool"))(
|
||||
"decodes an Xcode-compiled storyboard NIB and recovers its UI routes",
|
||||
async () => {
|
||||
|
||||
@@ -9,7 +9,7 @@ import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import {
|
||||
javaScriptExportShapeComparisonResultSchema,
|
||||
projectedExportReturnShapesSchema,
|
||||
} from "../../../src/domain/javascriptExportShapeComparisonSchemas.js";
|
||||
} from "../../../src/domain/javascript/javascriptExportShapeComparisonSchemas.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { writeFixtureFiles } from "../../support/javascriptApplicationFixture.js";
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/javascript/JavaScriptApplicationService.js";
|
||||
import { parseApplicationGraphEvidence } from "../../../src/application/javascript/JavaScriptApplicationEvidenceGraph.js";
|
||||
import { compareJavaScriptExportShapes } from "../../../src/domain/javascriptExportShapeComparison.js";
|
||||
import { javaScriptExportShapeComparisonResultSchema } from "../../../src/domain/javascriptExportShapeComparisonSchemas.js";
|
||||
import { compareJavaScriptExportShapes } from "../../../src/domain/javascript/javascriptExportShapeComparison.js";
|
||||
import { javaScriptExportShapeComparisonResultSchema } from "../../../src/domain/javascript/javascriptExportShapeComparisonSchemas.js";
|
||||
import {
|
||||
createJavaScriptApplicationGraph,
|
||||
createJavaScriptApplicationNode,
|
||||
} from "../../../src/domain/javascriptApplicationGraph.js";
|
||||
} from "../../../src/domain/javascript/javascriptApplicationGraph.js";
|
||||
|
||||
describe("JavaScript export return-shape comparison", () => {
|
||||
it("reports exactly the heading depth addition from source-owned parser fixtures", async () => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/javascript/JavaScriptApplicationService.js";
|
||||
import { parseApplicationGraphEvidence } from "../../../src/application/javascript/JavaScriptApplicationEvidenceGraph.js";
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascriptApplicationAnalysis.js";
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const analyze = async (root: string) => {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { expect, it } from "vitest";
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/javascript/JavaScriptApplicationService.js";
|
||||
import { parseApplicationGraphEvidence } from "../../../src/application/javascript/JavaScriptApplicationEvidenceGraph.js";
|
||||
import { importReferenceSource } from "../../../src/application/ReferenceSourceImport.js";
|
||||
import { compareSourceToBundle } from "../../../src/domain/sourceToBundleComparison.js";
|
||||
import { compareSourceToBundle } from "../../../src/domain/javascript/sourceToBundleComparison.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
it("keeps literal hash characters in historical/current filesystem paths", async () => {
|
||||
|
||||
@@ -14,7 +14,7 @@ import { analyzeJavaScriptApplication } from "../../../src/application/javascrip
|
||||
import { exportWebScripts } from "../../../src/application/WebScriptExportService.js";
|
||||
import { publishWebScripts } from "../../../src/browser/assets/PublishWebScripts.js";
|
||||
import { selectScriptCapture } from "../../../src/browser/assets/ScriptCaptureAdapters.js";
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascriptApplicationAnalysis.js";
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
|
||||
import { webScriptExportResultSchema } from "../../../src/domain/webScriptExport.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import {
|
||||
|
||||
@@ -12,13 +12,13 @@ import {
|
||||
import { reconcileJavaScriptRuntimeEvidence } from "../../../src/application/javascript/JavaScriptRuntimeReconciliationService.js";
|
||||
import { V8_INSPECTOR_PROVIDER_IDENTITY } from "../../../src/inspector/V8InspectorProvider.js";
|
||||
import { V8InspectorProvider } from "../../../src/inspector/V8InspectorProvider.js";
|
||||
import { JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE } from "../../../src/contracts/javascriptRuntimeReconciliationExample.js";
|
||||
import { JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE } from "../../../src/contracts/javascript/javascriptRuntimeReconciliationExample.js";
|
||||
import type {
|
||||
JavaScriptRuntimeObservation,
|
||||
ObserveJavaScriptRuntimeInput,
|
||||
} from "../../../src/domain/javascriptRuntimeObservation.js";
|
||||
import { observeJavaScriptRuntimeInputSchema } from "../../../src/domain/javascriptRuntimeObservation.js";
|
||||
import { javascriptRuntimeReconciliationResultSchema } from "../../../src/domain/javascriptRuntimeReconciliationSchemas.js";
|
||||
} from "../../../src/domain/javascript/javascriptRuntimeObservation.js";
|
||||
import { observeJavaScriptRuntimeInputSchema } from "../../../src/domain/javascript/javascriptRuntimeObservation.js";
|
||||
import { javascriptRuntimeReconciliationResultSchema } from "../../../src/domain/javascript/javascriptRuntimeReconciliationSchemas.js";
|
||||
import { startFakeV8Inspector } from "../../fixtures/inspector/fakeV8Inspector.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { expect, test } from "vitest";
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/javascript/JavaScriptApplicationService.js";
|
||||
import { createJavaScriptRuntimeObservationEvidence } from "../../../src/application/javascript/JavaScriptRuntimeObservationEvidence.js";
|
||||
import { V8InspectorProvider } from "../../../src/inspector/V8InspectorProvider.js";
|
||||
import { reconcileJavaScriptRuntime } from "../../../src/domain/javascriptRuntimeReconciliation.js";
|
||||
import { reconcileJavaScriptRuntime } from "../../../src/domain/javascript/javascriptRuntimeReconciliation.js";
|
||||
import { startFakeV8Inspector } from "../../fixtures/inspector/fakeV8Inspector.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { javascriptRecoveryResultSchema } from "../../../src/domain/javascriptRecovery.js";
|
||||
import { javascriptRecoveryResultSchema } from "../../../src/domain/javascript/javascriptRecovery.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
||||
import {
|
||||
|
||||
@@ -4,6 +4,11 @@ import { access } from "node:fs/promises";
|
||||
import { ANDROID_TOOL_CONTRACTS } from "../../../src/contracts/android/androidToolContracts.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import { startMcpTransport } from "../../../src/main/transport.js";
|
||||
import type { RuntimeDependencies } from "../../../src/main/types.js";
|
||||
import type { AndroidAnalysisPort } from "../../../src/application/android/AndroidAnalysisPort.js";
|
||||
import { silentLogger } from "../../../src/logger.js";
|
||||
import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import {
|
||||
createJadxProtocolFixture,
|
||||
@@ -12,6 +17,61 @@ import {
|
||||
|
||||
const it = test.skipIf(process.platform === "win32");
|
||||
|
||||
it("keeps a replacement server usable after the SDK discards its discovery probe", async () => {
|
||||
const { apk } = await createJadxProtocolFixture();
|
||||
const session = createTestBinarySession(() => {
|
||||
throw new Error("Unexpected deep provider");
|
||||
});
|
||||
const factories: Parameters<RuntimeDependencies["serve"]>[0][] = [];
|
||||
const providers: AndroidAnalysisPort[] = [];
|
||||
const runtime: RuntimeDependencies = {
|
||||
env: {},
|
||||
serve: (factory) => {
|
||||
factories.push(factory);
|
||||
return { close: async () => undefined };
|
||||
},
|
||||
createServer: (analysis, binary, options) => {
|
||||
if (options?.androidAnalysis === undefined)
|
||||
throw new Error("Expected owned Android provider");
|
||||
providers.push(options.androidAnalysis);
|
||||
return createServer(analysis, binary, options);
|
||||
},
|
||||
writeStderr: () => undefined,
|
||||
setExitCode: () => undefined,
|
||||
registerShutdown: () => () => undefined,
|
||||
};
|
||||
const transport = await startMcpTransport(runtime, session, {
|
||||
logger: silentLogger,
|
||||
serverLogger: silentLogger,
|
||||
loadOptionalProviders: async () => ({}),
|
||||
});
|
||||
if (!transport.ok) throw new Error("Transport failed");
|
||||
const factory = factories[0];
|
||||
if (factory === undefined) throw new Error("Missing SDK server factory");
|
||||
const probe = await factory({ era: "modern" });
|
||||
await probe.close();
|
||||
const replacement = await factory({ era: "legacy" });
|
||||
const provider = providers[1];
|
||||
if (provider === undefined) throw new Error("Missing replacement provider");
|
||||
const target = await parseBinaryTarget(apk);
|
||||
if (!target.ok) throw target.error;
|
||||
try {
|
||||
expect(
|
||||
await provider.execute(target.value, {
|
||||
operation: "inspect_android_package",
|
||||
input: { path: apk },
|
||||
}),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCapabilityUnavailableError" },
|
||||
});
|
||||
} finally {
|
||||
await replacement.close();
|
||||
await transport.closeAndroid();
|
||||
await session.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("publishes and executes all APK contracts with inline Evidence and no active binary", async () => {
|
||||
const { provider, apk, launches } = await createJadxProtocolFixture();
|
||||
const session = createTestBinarySession(() => {
|
||||
@@ -67,7 +127,9 @@ it("publishes and executes all APK contracts with inline Evidence and no active
|
||||
expect(evidence.operation).toBe(contract.name);
|
||||
expect(evidence.raw_result).not.toBeNull();
|
||||
}
|
||||
expect(launches).toHaveLength(5);
|
||||
expect(launches).toHaveLength(1);
|
||||
await client.close();
|
||||
await server.close();
|
||||
await verifyJadxFixtureCleanup(launches);
|
||||
});
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { z } from "zod";
|
||||
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import { CdpBrowserProvider } from "../../../src/browser/CdpBrowserProvider.js";
|
||||
import { JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE } from "../../../src/contracts/javascriptRuntimeReconciliationExample.js";
|
||||
import { JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE } from "../../../src/contracts/javascript/javascriptRuntimeReconciliationExample.js";
|
||||
import { TOOL_CONTRACTS } from "../../../src/contracts/toolContracts.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import { observed } from "../../fixtures/analysisExecution.js";
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
type FakeCdpBrowser,
|
||||
} from "../../fixtures/fakeCdpBrowser.js";
|
||||
import { writeElectronBoundaryFixture } from "../../fixtures/electronBoundaryApplication.js";
|
||||
import { createElectronActiveObservationFixtureResult } from "../../../src/domain/electronActiveObservation.fixture.js";
|
||||
import { createElectronActiveObservationFixtureResult } from "../../../src/domain/javascript/electronActiveObservation.fixture.js";
|
||||
|
||||
const browsers: FakeCdpBrowser[] = [];
|
||||
const resources: Array<{ close(): Promise<unknown> }> = [];
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
javascriptRuntimeObservationSchema,
|
||||
javascriptRuntimeTargetListSchema,
|
||||
observeJavaScriptRuntimeInputSchema,
|
||||
} from "../../../src/domain/javascriptRuntimeObservation.js";
|
||||
} from "../../../src/domain/javascript/javascriptRuntimeObservation.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import { observed } from "../../fixtures/analysisExecution.js";
|
||||
import { startFakeV8Inspector } from "../../fixtures/inspector/fakeV8Inspector.js";
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
JAVASCRIPT_APPLICATION_VERSION_COMPARISON_EXAMPLE,
|
||||
JAVASCRIPT_EXPORT_SHAPE_COMPARISON_EXAMPLE,
|
||||
SOURCE_TO_BUNDLE_COMPARISON_EXAMPLE,
|
||||
} from "../../../src/contracts/javascriptApplicationWorkflowExamples.js";
|
||||
} from "../../../src/contracts/javascript/javascriptApplicationWorkflowExamples.js";
|
||||
import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js";
|
||||
|
||||
const resources: Array<{ close(): Promise<unknown> }> = [];
|
||||
|
||||
@@ -12,6 +12,7 @@ it("keeps shutdown output stable while logging the rejected cause at debug level
|
||||
const output: string[] = [];
|
||||
const exitCodes: number[] = [];
|
||||
const requests: Array<() => void> = [];
|
||||
let androidClosed = false;
|
||||
const failure = Object.assign(
|
||||
new TypeError("fixture transport close failed"),
|
||||
{
|
||||
@@ -36,6 +37,9 @@ it("keeps shutdown output stable while logging the rejected cause at debug level
|
||||
const logger = pino({ level: "debug" }, { write: (line) => logs.push(line) });
|
||||
createShutdown({
|
||||
handle,
|
||||
closeAndroid: async () => {
|
||||
androidClosed = true;
|
||||
},
|
||||
session: createManagedBinarySession(),
|
||||
unregisterReload: () => undefined,
|
||||
dependencies,
|
||||
@@ -46,6 +50,7 @@ it("keeps shutdown output stable while logging the rejected cause at debug level
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
|
||||
expect(exitCodes).toEqual([1]);
|
||||
expect(androidClosed).toBe(true);
|
||||
expect(output).toEqual([`${MCP_SHUTDOWN_FAILED}\n`]);
|
||||
expect(logs.map((line) => JSON.parse(line))).toContainEqual(
|
||||
expect.objectContaining({
|
||||
|
||||
@@ -9,8 +9,8 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { createElectronEvidence } from "../../../src/application/javascript/ElectronEvidence.js";
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/javascript/JavaScriptApplicationService.js";
|
||||
import { reconcileJavaScriptRuntime } from "../../../src/domain/javascriptRuntimeReconciliation.js";
|
||||
import { inspectElectronPageInputSchema } from "../../../src/domain/electronObservation.js";
|
||||
import { reconcileJavaScriptRuntime } from "../../../src/domain/javascript/javascriptRuntimeReconciliation.js";
|
||||
import { inspectElectronPageInputSchema } from "../../../src/domain/javascript/electronObservation.js";
|
||||
import { createWebTextArtifact } from "../../../src/domain/webContentArtifact.js";
|
||||
|
||||
const SOURCE = `const worker = new Worker("./worker.js");\nexport const observed = worker;\n`;
|
||||
|
||||
@@ -278,6 +278,41 @@ describe("native macOS provider inspection", () => {
|
||||
});
|
||||
});
|
||||
|
||||
/** Emit entitlements whose dictionary also holds a legal `__proto__` key. */
|
||||
class PrototypeEntitlementsRunner extends FixtureRunner {
|
||||
override async run(tool: string, arguments_: readonly string[]) {
|
||||
const result = await super.run(tool, arguments_);
|
||||
if (!result.ok || !arguments_.includes("--entitlements")) return result;
|
||||
const stdout =
|
||||
'<?xml version="1.0" encoding="UTF-8"?><plist version="1.0"><dict><key>com.apple.security.app-sandbox</key><true/><key>__proto__</key><dict><key>com.apple.security.get-task-allow</key><true/></dict></dict></plist>';
|
||||
return ok({
|
||||
...result.value,
|
||||
stdout,
|
||||
stdoutBytes: Buffer.byteLength(stdout),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
describe("native signature entitlements", () => {
|
||||
it("reports entitlement entries keyed __proto__ that the result omits", async () => {
|
||||
const client = new NativeMacOSProvider(
|
||||
new PrototypeEntitlementsRunner(),
|
||||
"darwin",
|
||||
).createClient(machoTarget("/private/fixture"));
|
||||
|
||||
const signature = await client.execute("inspect_signature", {});
|
||||
|
||||
expect(signature.ok).toBe(true);
|
||||
if (!signature.ok) return;
|
||||
expect(signature.value.result).toMatchObject({
|
||||
entitlements: { "com.apple.security.app-sandbox": true },
|
||||
});
|
||||
expect(signature.value.limitations).toContain(
|
||||
"Entitlements: 1 dictionary entry keyed __proto__ was omitted because REA results cannot represent that key.",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("native dispatch metadata error results", () => {
|
||||
it("preserves tagged cancellation and integrity failures", async () => {
|
||||
directory = await createTestTempDirectory("rea-dispatch-errors-");
|
||||
|
||||
Reference in New Issue
Block a user