chore: merge main and resolve PR #899 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;
|
||||
|
||||
@@ -6,9 +6,9 @@ import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, describe, expect, test } from "vitest";
|
||||
|
||||
import { observeJavaScriptRuntime } from "../../../src/application/JavaScriptRuntimeObservationService.js";
|
||||
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";
|
||||
|
||||
|
||||
@@ -153,6 +153,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 () => {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { createPackage } from "@electron/asar";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { scanArtifactInventory } from "../../../src/application/ArtifactInventory.js";
|
||||
import { readJavaScriptArtifactFiles } from "../../../src/application/JavaScriptArtifactFiles.js";
|
||||
import { readJavaScriptArtifactFiles } from "../../../src/application/javascript/JavaScriptArtifactFiles.js";
|
||||
import { AsarArtifactReader } from "../../../src/artifacts/AsarArtifactReader.js";
|
||||
import { DirectoryArtifactReader } from "../../../src/artifacts/DirectoryArtifactReader.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
@@ -6,8 +6,8 @@ import { expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { readJavaScriptArtifactFiles } from "../../../src/application/JavaScriptArtifactFiles.js";
|
||||
import { reconstructJavaScriptArtifact } from "../../../src/application/JavaScriptArtifactReconstruction.js";
|
||||
import { readJavaScriptArtifactFiles } from "../../../src/application/javascript/JavaScriptArtifactFiles.js";
|
||||
import { reconstructJavaScriptArtifact } from "../../../src/application/javascript/JavaScriptArtifactReconstruction.js";
|
||||
import { scanArtifactInventory } from "../../../src/application/ArtifactInventory.js";
|
||||
import {
|
||||
type ArtifactEntry,
|
||||
|
||||
@@ -2,14 +2,14 @@ import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { parseApplicationGraphEvidence } from "../../../src/application/JavaScriptApplicationEvidenceGraph.js";
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/JavaScriptApplicationService.js";
|
||||
import { compareJavaScriptExportShapesEvidence } from "../../../src/application/JavaScriptApplicationWorkflowService.js";
|
||||
import { parseApplicationGraphEvidence } from "../../../src/application/javascript/JavaScriptApplicationEvidenceGraph.js";
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/javascript/JavaScriptApplicationService.js";
|
||||
import { compareJavaScriptExportShapesEvidence } from "../../../src/application/javascript/JavaScriptApplicationWorkflowService.js";
|
||||
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";
|
||||
|
||||
|
||||
@@ -5,14 +5,14 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/JavaScriptApplicationService.js";
|
||||
import { parseApplicationGraphEvidence } from "../../../src/application/JavaScriptApplicationEvidenceGraph.js";
|
||||
import { compareJavaScriptExportShapes } from "../../../src/domain/javascriptExportShapeComparison.js";
|
||||
import { javaScriptExportShapeComparisonResultSchema } from "../../../src/domain/javascriptExportShapeComparisonSchemas.js";
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/javascript/JavaScriptApplicationService.js";
|
||||
import { parseApplicationGraphEvidence } from "../../../src/application/javascript/JavaScriptApplicationEvidenceGraph.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 () => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { dirname, join, relative, sep } from "node:path";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { reconstructJavaScriptArtifact } from "../../../src/application/JavaScriptArtifactReconstruction.js";
|
||||
import { reconstructJavaScriptArtifact } from "../../../src/application/javascript/JavaScriptArtifactReconstruction.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const cases: readonly {
|
||||
|
||||
@@ -4,9 +4,9 @@ import { join, relative, sep } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/JavaScriptApplicationService.js";
|
||||
import { parseApplicationGraphEvidence } from "../../../src/application/JavaScriptApplicationEvidenceGraph.js";
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascriptApplicationAnalysis.js";
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/javascript/JavaScriptApplicationService.js";
|
||||
import { parseApplicationGraphEvidence } from "../../../src/application/javascript/JavaScriptApplicationEvidenceGraph.js";
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const analyze = async (root: string) => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { join } from "node:path";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { reconstructJavaScriptArtifact } from "../../../src/application/JavaScriptArtifactReconstruction.js";
|
||||
import { reconstructJavaScriptArtifact } from "../../../src/application/javascript/JavaScriptArtifactReconstruction.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
it("creates source-map graph relationships only for real comments", async () => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { join } from "node:path";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { reconstructJavaScriptArtifact } from "../../../src/application/JavaScriptArtifactReconstruction.js";
|
||||
import { reconstructJavaScriptArtifact } from "../../../src/application/javascript/JavaScriptArtifactReconstruction.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
it.each(["\n", "\r\n", "\r", "\u2028", "\u2029"])(
|
||||
|
||||
@@ -2,10 +2,10 @@ import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/JavaScriptApplicationService.js";
|
||||
import { parseApplicationGraphEvidence } from "../../../src/application/JavaScriptApplicationEvidenceGraph.js";
|
||||
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 () => {
|
||||
|
||||
@@ -10,11 +10,11 @@ import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/JavaScriptApplicationService.js";
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/javascript/JavaScriptApplicationService.js";
|
||||
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 {
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect, it } from "vitest";
|
||||
import { LocalWebSourceLocationArtifacts } from "../../../src/browser/assets/WebSourceLocationArtifacts.js";
|
||||
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
||||
import { ok } from "../../../src/domain/result.js";
|
||||
import { WEB_SOURCE_MAP_LIMITS } from "../../../src/domain/webSourceLocation.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import {
|
||||
webSourceLocationArgs,
|
||||
webSourceLocationFixture,
|
||||
} from "../../fixtures/webSourceLocation.js";
|
||||
|
||||
const reader = () => {
|
||||
const { sourceMap: _sourceMap, ...script } = webSourceLocationFixture();
|
||||
return new LocalWebSourceLocationArtifacts({
|
||||
load: () => Promise.resolve(ok(script)),
|
||||
});
|
||||
};
|
||||
it("reads exact selected map bytes, retaining a BOM and explicitly selected URL context", async () => {
|
||||
const root = await createTestTempDirectory("rea-map-artifacts-");
|
||||
const path = join(root, "app.map");
|
||||
const text = '\uFEFF{"version":3,"sources":[],"names":[],"mappings":""}';
|
||||
await writeFile(path, text);
|
||||
const response = await reader().load({
|
||||
...webSourceLocationArgs,
|
||||
source_map: { ...webSourceLocationArgs.source_map, path },
|
||||
});
|
||||
if (!response.ok) throw response.error;
|
||||
expect(response.value.sourceMap).toEqual({
|
||||
file: {
|
||||
path,
|
||||
sha256: createHash("sha256").update(text).digest("hex"),
|
||||
bytes: Buffer.byteLength(text),
|
||||
},
|
||||
url: webSourceLocationArgs.source_map.url,
|
||||
text,
|
||||
});
|
||||
});
|
||||
it.each(["unavailable", "invalid-utf8", "oversized"])(
|
||||
"preserves the selected map reader failure: %s",
|
||||
async (variant) => {
|
||||
const root = await createTestTempDirectory("rea-map-artifacts-");
|
||||
const path = join(root, "app.map");
|
||||
if (variant === "invalid-utf8")
|
||||
await writeFile(path, Buffer.from([255, 254]));
|
||||
if (variant === "oversized")
|
||||
await writeFile(
|
||||
path,
|
||||
Buffer.alloc(WEB_SOURCE_MAP_LIMITS.mapBytes + 1, 32),
|
||||
);
|
||||
const response = await reader().load({
|
||||
...webSourceLocationArgs,
|
||||
source_map: { ...webSourceLocationArgs.source_map, path },
|
||||
});
|
||||
if (response.ok) throw new Error("expected map failure");
|
||||
const projection = projectAnalysisError(response.error);
|
||||
if (variant === "invalid-utf8")
|
||||
expect(projection).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: [
|
||||
{
|
||||
path: ["source_map", "path"],
|
||||
message: expect.stringContaining("UTF-8"),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
else
|
||||
expect(response.error).toMatchObject({
|
||||
_tag: "ArtifactOperationError",
|
||||
reason: variant === "oversized" ? "limit" : "io",
|
||||
detail: expect.stringContaining(path),
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -4,21 +4,21 @@ import { pathToFileURL } from "node:url";
|
||||
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { createJavaScriptRuntimeObservationEvidence } from "../../../src/application/JavaScriptRuntimeObservationEvidence.js";
|
||||
import { createJavaScriptRuntimeObservationEvidence } from "../../../src/application/javascript/JavaScriptRuntimeObservationEvidence.js";
|
||||
import {
|
||||
listJavaScriptRuntimeTargets,
|
||||
observeJavaScriptRuntime,
|
||||
} from "../../../src/application/JavaScriptRuntimeObservationService.js";
|
||||
import { reconcileJavaScriptRuntimeEvidence } from "../../../src/application/JavaScriptRuntimeReconciliationService.js";
|
||||
} from "../../../src/application/javascript/JavaScriptRuntimeObservationService.js";
|
||||
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";
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ import { pathToFileURL } from "node:url";
|
||||
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/JavaScriptApplicationService.js";
|
||||
import { createJavaScriptRuntimeObservationEvidence } from "../../../src/application/JavaScriptRuntimeObservationEvidence.js";
|
||||
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 {
|
||||
|
||||
@@ -7,8 +7,8 @@ import { z } from "zod";
|
||||
import {
|
||||
resolveArtifactPathByContext,
|
||||
type ArtifactPathResolution,
|
||||
} from "../../../src/application/JavaScriptArtifactPathResolution.js";
|
||||
import type { JavaScriptArtifactFile } from "../../../src/application/JavaScriptArtifactFiles.js";
|
||||
} from "../../../src/application/javascript/JavaScriptArtifactPathResolution.js";
|
||||
import type { JavaScriptArtifactFile } from "../../../src/application/javascript/JavaScriptArtifactFiles.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
const execute = promisify(execFile);
|
||||
const TARGETS = [
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import type { SourceMapDecoderDependencies } from "../../../src/javascript/sourceMaps/SourceMapDecoder.js";
|
||||
import { access } from "node:fs/promises";
|
||||
import { expect, it } from "vitest";
|
||||
import { SourceMapDecoder } from "../../../src/javascript/sourceMaps/SourceMapDecoder.js";
|
||||
import { PrivateRuntimeRoot } from "../../../src/process/PrivateRuntimeRoot.js";
|
||||
import { spawnOwnedProviderProcess } from "../../../src/process/ProviderProcess.js";
|
||||
import { waitForProviderProcessReady } from "../../fixtures/providerProcess.js";
|
||||
import {
|
||||
webSourceLocationArgs,
|
||||
webSourceLocationFixture,
|
||||
} from "../../fixtures/webSourceLocation.js";
|
||||
|
||||
const realDecoder = (dependencies: SourceMapDecoderDependencies = {}) =>
|
||||
new SourceMapDecoder({
|
||||
...dependencies,
|
||||
launcher:
|
||||
dependencies.launcher ??
|
||||
((options) =>
|
||||
spawnOwnedProviderProcess({
|
||||
...options,
|
||||
arguments: options.arguments.map((argument) =>
|
||||
argument.endsWith("/SourceMapCodecProcess.js") ||
|
||||
argument.endsWith("\\SourceMapCodecProcess.js")
|
||||
? fileURLToPath(
|
||||
new URL(
|
||||
"../../../dist/javascript/sourceMaps/SourceMapCodecProcess.js",
|
||||
import.meta.url,
|
||||
),
|
||||
)
|
||||
: argument,
|
||||
),
|
||||
})),
|
||||
});
|
||||
|
||||
const fixture = webSourceLocationFixture();
|
||||
const input = {
|
||||
text: fixture.sourceMap.text,
|
||||
url: fixture.sourceMap.url,
|
||||
path: fixture.sourceMap.file.path,
|
||||
position: webSourceLocationArgs.generated_position,
|
||||
};
|
||||
|
||||
it("runs the real pinned codec with an independent heap and removes its private request directory", async () => {
|
||||
let path: string | undefined;
|
||||
const environment = {
|
||||
...process.env,
|
||||
NODE_OPTIONS: "--require=/rea-file-that-does-not-exist",
|
||||
};
|
||||
const decoder = realDecoder({
|
||||
environment,
|
||||
createRuntime: async () => {
|
||||
const root = await PrivateRuntimeRoot.create();
|
||||
path = root.path;
|
||||
return root;
|
||||
},
|
||||
});
|
||||
const response = await decoder.trace(input);
|
||||
if (!response.ok) throw response.error;
|
||||
expect(response.value).toMatchObject({
|
||||
engine: { id: "jridgewell-trace-mapping", version: "0.3.31" },
|
||||
runtime: { id: "node-v8" },
|
||||
matches: [{ content: { text: "original" } }],
|
||||
});
|
||||
expect(response.value.runtime.v8_heap_limit_bytes).toBeLessThanOrEqual(
|
||||
256 * 1024 * 1024,
|
||||
);
|
||||
expect(environment.NODE_OPTIONS).toBe(
|
||||
"--require=/rea-file-that-does-not-exist",
|
||||
);
|
||||
if (path === undefined) throw new Error("runtime not acquired");
|
||||
await expect(access(path)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
});
|
||||
it.each([
|
||||
{ text: "{", tag: "AnalysisInputError" },
|
||||
{
|
||||
text: JSON.stringify({
|
||||
version: 3,
|
||||
sections: [
|
||||
{
|
||||
offset: { line: 0, column: 0 },
|
||||
url: "https://app.test/external.map",
|
||||
},
|
||||
],
|
||||
}),
|
||||
tag: "AnalysisCapabilityUnavailableError",
|
||||
},
|
||||
{
|
||||
text: JSON.stringify({
|
||||
version: 3,
|
||||
sections: [{ offset: { line: 1000000000, column: 0 }, map: {} }],
|
||||
}),
|
||||
tag: "ArtifactOperationError",
|
||||
},
|
||||
])("preserves actual producer failures: $tag", async ({ text, tag }) => {
|
||||
const response = await realDecoder().trace({ ...input, text });
|
||||
if (response.ok) throw new Error("expected failed map");
|
||||
expect(response.error._tag).toBe(tag);
|
||||
});
|
||||
it("reports cleanup failure with the actual owning operation", async () => {
|
||||
const response = await realDecoder({
|
||||
createRuntime: async () => {
|
||||
const root = await PrivateRuntimeRoot.create();
|
||||
return {
|
||||
path: root.path,
|
||||
close: async () => {
|
||||
await root.close();
|
||||
throw new Error("observed cleanup failure");
|
||||
},
|
||||
};
|
||||
},
|
||||
}).trace(input);
|
||||
if (response.ok) throw new Error("expected cleanup failure");
|
||||
expect(response.error).toMatchObject({
|
||||
cleanupIncomplete: true,
|
||||
operation: "trace_web_source_location",
|
||||
diagnostics: { cleanup_failures: ["observed cleanup failure"] },
|
||||
});
|
||||
});
|
||||
it("cancels a real owned process and removes the runtime request", async () => {
|
||||
const controller = new AbortController();
|
||||
let path: string | undefined;
|
||||
const response = await realDecoder({
|
||||
createRuntime: async () => {
|
||||
const root = await PrivateRuntimeRoot.create();
|
||||
path = root.path;
|
||||
return root;
|
||||
},
|
||||
launcher: async (options) => {
|
||||
const child = await spawnOwnedProviderProcess({
|
||||
...options,
|
||||
arguments: [
|
||||
"-e",
|
||||
'process.stdout.write("ready\\n"); setInterval(() => undefined, 1000)',
|
||||
],
|
||||
});
|
||||
await waitForProviderProcessReady(child.process);
|
||||
setImmediate(() => controller.abort());
|
||||
return child;
|
||||
},
|
||||
}).trace(input, { signal: controller.signal });
|
||||
if (response.ok) throw new Error("expected cancellation");
|
||||
expect(response.error._tag).toBe("AnalysisCancelledError");
|
||||
if (path === undefined) throw new Error("runtime not acquired");
|
||||
await expect(access(path)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
});
|
||||
it("retains final diagnostic bytes for an actual failed codec process", async () => {
|
||||
const response = await realDecoder({
|
||||
launcher: (options) =>
|
||||
spawnOwnedProviderProcess({
|
||||
...options,
|
||||
arguments: [
|
||||
"-e",
|
||||
'process.stderr.write("final diagnostic"); process.exitCode = 7',
|
||||
],
|
||||
}),
|
||||
}).trace(input);
|
||||
if (response.ok) throw new Error("expected exit failure");
|
||||
expect(response.error).toMatchObject({
|
||||
diagnostics: { exit_code: 7, stderr: "final diagnostic" },
|
||||
});
|
||||
});
|
||||
it("reports complete evidence amplification as a resource failure before serializing an oversized reply", async () => {
|
||||
const text = JSON.stringify({
|
||||
version: 3,
|
||||
sources: ["large.ts"],
|
||||
sourcesContent: ["a".repeat(600000)],
|
||||
names: [],
|
||||
mappings: Array.from({ length: 60 }, () => "AAAA").join(","),
|
||||
});
|
||||
const response = await realDecoder().trace({ ...input, text });
|
||||
if (response.ok) throw new Error("expected complete-evidence budget failure");
|
||||
expect(response.error).toMatchObject({
|
||||
_tag: "ArtifactOperationError",
|
||||
reason: "limit",
|
||||
detail: expect.stringContaining("no partial"),
|
||||
});
|
||||
});
|
||||
it("rejects a malformed actual subprocess reply", async () => {
|
||||
const response = await realDecoder({
|
||||
launcher: (options) =>
|
||||
spawnOwnedProviderProcess({
|
||||
...options,
|
||||
arguments: ["-e", 'process.stdout.write("not JSON")'],
|
||||
}),
|
||||
}).trace(input);
|
||||
if (response.ok) throw new Error("expected malformed reply");
|
||||
expect(response.error._tag).toBe("AnalysisOutputError");
|
||||
});
|
||||
it("removes the private request when launching the codec fails", async () => {
|
||||
let path: string | undefined;
|
||||
const response = await realDecoder({
|
||||
createRuntime: async () => {
|
||||
const root = await PrivateRuntimeRoot.create();
|
||||
path = root.path;
|
||||
return root;
|
||||
},
|
||||
launcher: () => Promise.reject(new Error("observed launch failure")),
|
||||
}).trace(input);
|
||||
if (response.ok) throw new Error("expected launch failure");
|
||||
expect(response.error).toMatchObject({
|
||||
diagnostics: { error_message: "observed launch failure" },
|
||||
});
|
||||
if (path === undefined) throw new Error("runtime not acquired");
|
||||
await expect(access(path)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
});
|
||||
@@ -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";
|
||||
|
||||
@@ -9,7 +9,7 @@ import { z } from "zod";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import type { ElectronActiveObservationPort } from "../../../src/application/ElectronActiveObservationPort.js";
|
||||
import type { ElectronActiveObservationPort } from "../../../src/application/javascript/ElectronActiveObservationPort.js";
|
||||
import { CdpElectronProvider } from "../../../src/browser/CdpElectronProvider.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> }> = [];
|
||||
|
||||
@@ -6,13 +6,13 @@ import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { afterEach, describe, expect, test } from "vitest";
|
||||
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import { observeJavaScriptRuntime } from "../../../src/application/JavaScriptRuntimeObservationService.js";
|
||||
import { observeJavaScriptRuntime } from "../../../src/application/javascript/JavaScriptRuntimeObservationService.js";
|
||||
import { V8InspectorProvider } from "../../../src/inspector/V8InspectorProvider.js";
|
||||
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({
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import { traceSourceMap } from "../../../src/javascript/sourceMaps/TraceSourceMap.js";
|
||||
import { webSourceLocationArgs as args } from "../../fixtures/webSourceLocation.js";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { expect, it, onTestFinished } from "vitest";
|
||||
import { WebSourceLocationService } from "../../../src/application/WebSourceLocationService.js";
|
||||
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { ok } from "../../../src/domain/result.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import { webSourceLocationFixture } from "../../fixtures/webSourceLocation.js";
|
||||
|
||||
it("publishes valid SDK schemas and records the named module trace without a binary target", async () => {
|
||||
const service = new WebSourceLocationService(
|
||||
{
|
||||
load: () => Promise.resolve(ok(webSourceLocationFixture())),
|
||||
},
|
||||
{
|
||||
trace: (input) =>
|
||||
Promise.resolve(
|
||||
ok(traceSourceMap(input.text, input.url, input.position)),
|
||||
),
|
||||
},
|
||||
);
|
||||
const session = createTestBinarySession(() => {
|
||||
throw new Error("binary provider must not start");
|
||||
});
|
||||
const server = createServer(session, session, { webSourceLocation: service });
|
||||
const client = new Client({ name: "module-contract", version: "1" });
|
||||
onTestFinished(async () => {
|
||||
await client.close();
|
||||
await server.close();
|
||||
await session.close();
|
||||
});
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const advertised = (await client.listTools()).tools.find(
|
||||
(tool) => tool.name === "trace_web_source_location",
|
||||
);
|
||||
if (advertised?.outputSchema === undefined)
|
||||
throw new Error("module trace must advertise both schemas");
|
||||
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
||||
const inputSchema: Record<string, unknown> = advertised.inputSchema;
|
||||
const outputSchema: Record<string, unknown> = advertised.outputSchema;
|
||||
expect(ajv.validateSchema(inputSchema)).toBe(true);
|
||||
expect(ajv.validateSchema(outputSchema)).toBe(true);
|
||||
expect(ajv.validate(inputSchema, args)).toBe(true);
|
||||
const response = await client.callTool({
|
||||
name: "trace_web_source_location",
|
||||
arguments: args,
|
||||
});
|
||||
expect(response.isError).not.toBe(true);
|
||||
expect(
|
||||
ajv.validate(outputSchema, response.structuredContent),
|
||||
JSON.stringify(ajv.errors),
|
||||
).toBe(true);
|
||||
const parsed = toolContract("trace_web_source_location").outputSchema.parse(
|
||||
response.structuredContent,
|
||||
);
|
||||
const evidence = parseEvidence(parsed.evidence);
|
||||
expect(parsed.result).toEqual(evidence.normalized_result);
|
||||
expect(session.evidenceById(evidence.evidence_id)).toEqual(evidence);
|
||||
const invalid = await client.callTool({
|
||||
name: "trace_web_source_location",
|
||||
arguments: { ...args, manifest_path: "relative.json" },
|
||||
});
|
||||
expect(invalid.isError).toBe(true);
|
||||
});
|
||||
@@ -7,10 +7,10 @@ import { afterEach, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { createElectronEvidence } from "../../../src/application/ElectronEvidence.js";
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/JavaScriptApplicationService.js";
|
||||
import { reconcileJavaScriptRuntime } from "../../../src/domain/javascriptRuntimeReconciliation.js";
|
||||
import { inspectElectronPageInputSchema } from "../../../src/domain/electronObservation.js";
|
||||
import { createElectronEvidence } from "../../../src/application/javascript/ElectronEvidence.js";
|
||||
import { analyzeJavaScriptApplication } from "../../../src/application/javascript/JavaScriptApplicationService.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`;
|
||||
@@ -167,7 +167,7 @@ it("runs the local verifier from operator-provided paths without emitting source
|
||||
const { stdout } = await execute(
|
||||
process.execPath,
|
||||
[
|
||||
"scripts/verify-local-javascript-runtime.mjs",
|
||||
"scripts/verify/javascript/runtime-observation.mjs",
|
||||
"--application",
|
||||
fixture,
|
||||
"--runtime-evidence",
|
||||
|
||||
@@ -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