chore: merge main and resolve PR #902 conflicts
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user