mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 06:21:12 +00:00
refactor(application): unify 5 pass-through analysis services into ProviderOperationService (#13856)
Closes #13855
This commit is contained in:
1 parent
9ec23ad03b
commit
2cf600fc7f
31 files changed
+237
-257
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFile, stat } from "node:fs/promises";
|
||||
|
||||
import { ApktoolResourceAnalysisService } from "../dist/application/apktool/ApktoolResourceAnalysisService.js";
|
||||
import { createApktoolResourceAnalysisService } from "../dist/application/ProviderOperationServices.js";
|
||||
import { createApktoolResourceAnalysisProvider } from "../dist/composition/apktool.js";
|
||||
|
||||
const options = parseArguments(process.argv.slice(2));
|
||||
@@ -16,7 +16,7 @@ if (options.help) {
|
||||
}
|
||||
|
||||
const provider = createApktoolResourceAnalysisProvider(process.env);
|
||||
const service = new ApktoolResourceAnalysisService(provider);
|
||||
const service = createApktoolResourceAnalysisService(provider);
|
||||
let failures = 0;
|
||||
const check = (name, condition, detail = "") => {
|
||||
const mark = condition ? "ok" : "FAIL";
|
||||
|
||||
@@ -3,7 +3,7 @@ import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { JebAnalysisService } from "../dist/application/jeb/JebAnalysisService.js";
|
||||
import { createJebAnalysisService } from "../dist/application/ProviderOperationServices.js";
|
||||
import { createJebAnalysisProvider } from "../dist/composition/jeb.js";
|
||||
import {
|
||||
verifierFailureReasons,
|
||||
@@ -28,7 +28,7 @@ if (options.help) {
|
||||
}
|
||||
|
||||
const provider = createJebAnalysisProvider(process.env);
|
||||
const service = new JebAnalysisService(provider);
|
||||
const service = createJebAnalysisService(provider);
|
||||
let fixture;
|
||||
let fixtureDirectory;
|
||||
try {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { join } from "node:path";
|
||||
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
|
||||
import { ApktoolResourceAnalysisService } from "../application/apktool/ApktoolResourceAnalysisService.js";
|
||||
import { createApktoolResourceAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { DEFAULT_APKTOOL_DECODE_TIMEOUT_MS } from "../domain/apktool/apktoolResourceAnalysis.js";
|
||||
import {
|
||||
@@ -88,7 +88,7 @@ const decode = async (
|
||||
path: string,
|
||||
decodeTimeoutMs?: number,
|
||||
) =>
|
||||
new ApktoolResourceAnalysisService(provider).execute(
|
||||
createApktoolResourceAnalysisService(provider).execute(
|
||||
"decode_android_resources",
|
||||
{
|
||||
path,
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
systemProcessOwnershipHost,
|
||||
} from "../process/ProcessOwnershipObservation.js";
|
||||
import { ApktoolWorkspace } from "./ApktoolWorkspace.js";
|
||||
import { ApktoolResourceAnalysisService } from "../application/apktool/ApktoolResourceAnalysisService.js";
|
||||
import { createApktoolResourceAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import {
|
||||
apktoolRequestSchema,
|
||||
@@ -183,7 +183,7 @@ it("recovers later string pages and an exhausted XML admission on the same APK",
|
||||
const apk = await apkFixture(root);
|
||||
const provider = providerOver(command);
|
||||
onTestFinished(() => provider.close());
|
||||
const service = new ApktoolResourceAnalysisService(provider);
|
||||
const service = createApktoolResourceAnalysisService(provider);
|
||||
const inspect = async (input: Record<string, unknown>) => {
|
||||
const outcome = await service.execute("decode_android_resources", {
|
||||
path: apk.path,
|
||||
@@ -240,7 +240,7 @@ it("returns table-only facts for a single selected primary table", async () => {
|
||||
const apk = await apkFixture(root);
|
||||
const provider = providerOver(command);
|
||||
onTestFinished(() => provider.close());
|
||||
const outcome = await new ApktoolResourceAnalysisService(provider).execute(
|
||||
const outcome = await createApktoolResourceAnalysisService(provider).execute(
|
||||
"decode_android_resources",
|
||||
{ path: apk.path, string_tables_only: true },
|
||||
);
|
||||
@@ -291,7 +291,7 @@ sdkInfo:
|
||||
const original = await readFile(apk.path);
|
||||
const provider = providerOver(command);
|
||||
onTestFinished(() => provider.close());
|
||||
const outcome = await new ApktoolResourceAnalysisService(provider).execute(
|
||||
const outcome = await createApktoolResourceAnalysisService(provider).execute(
|
||||
"decode_android_resources",
|
||||
{ path: apk.path },
|
||||
);
|
||||
@@ -594,7 +594,7 @@ it("preserves primary strings and reports markup omissions in default and locali
|
||||
const apk = await apkFixture(root);
|
||||
const provider = providerOver(command);
|
||||
onTestFinished(() => provider.close());
|
||||
const observation = await new ApktoolResourceAnalysisService(
|
||||
const observation = await createApktoolResourceAnalysisService(
|
||||
provider,
|
||||
).execute("decode_android_resources", {
|
||||
path: apk.path,
|
||||
@@ -838,7 +838,7 @@ it("uses an owned APK snapshot and framework cache and resolves regional locales
|
||||
),
|
||||
);
|
||||
const apk = await apkFixture(root);
|
||||
const observation = await new ApktoolResourceAnalysisService(
|
||||
const observation = await createApktoolResourceAnalysisService(
|
||||
providerOver(command),
|
||||
).execute("decode_android_resources", {
|
||||
path: apk.path,
|
||||
@@ -877,7 +877,7 @@ it("shares one decode across default and selected locale tables", async () => {
|
||||
),
|
||||
);
|
||||
const apk = await apkFixture(root);
|
||||
const observation = await new ApktoolResourceAnalysisService(
|
||||
const observation = await createApktoolResourceAnalysisService(
|
||||
providerOver(command),
|
||||
).execute("decode_android_resources", {
|
||||
path: apk.path,
|
||||
@@ -944,7 +944,7 @@ it("reuses normalized directory table for locale aliases without extra reads", a
|
||||
),
|
||||
);
|
||||
const apk = await apkFixture(root);
|
||||
const observation = await new ApktoolResourceAnalysisService(
|
||||
const observation = await createApktoolResourceAnalysisService(
|
||||
providerOver(command),
|
||||
).execute("decode_android_resources", {
|
||||
path: apk.path,
|
||||
@@ -1007,7 +1007,7 @@ it.each([2000, 2001])(
|
||||
const apk = await apkFixture(root);
|
||||
const provider = providerOver(command);
|
||||
try {
|
||||
const observation = await new ApktoolResourceAnalysisService(
|
||||
const observation = await createApktoolResourceAnalysisService(
|
||||
provider,
|
||||
).execute("decode_android_resources", {
|
||||
path: apk.path,
|
||||
@@ -1050,7 +1050,7 @@ it("skips all string tables when include_strings is false despite locales reques
|
||||
),
|
||||
);
|
||||
const apk = await apkFixture(root);
|
||||
const observation = await new ApktoolResourceAnalysisService(
|
||||
const observation = await createApktoolResourceAnalysisService(
|
||||
providerOver(command),
|
||||
).execute("decode_android_resources", {
|
||||
path: apk.path,
|
||||
@@ -1083,7 +1083,7 @@ it("skips remaining tables without reading or parsing once aggregate string budg
|
||||
const bigStrings = `<resources>${Array.from({ length: 2000 }, (_, i) => `<string name="s_${String(i)}">val</string>`).join("")}</resources>`;
|
||||
await writeFile(join(root, "big-strings.xml"), bigStrings);
|
||||
const apk = await apkFixture(root);
|
||||
const observation = await new ApktoolResourceAnalysisService(
|
||||
const observation = await createApktoolResourceAnalysisService(
|
||||
providerOver(command),
|
||||
).execute("decode_android_resources", {
|
||||
path: apk.path,
|
||||
|
||||
@@ -81,6 +81,57 @@ export const executeProviderOperation = async <
|
||||
return completeProviderEvidence(evidence, options?.signal);
|
||||
};
|
||||
|
||||
/**
|
||||
* Shared single-request provider service wrapping {@link executeProviderOperation}
|
||||
* and optional provider cleanup. Replaces per-provider pass-through service classes.
|
||||
*/
|
||||
export class ProviderOperationService<
|
||||
TOperation extends string,
|
||||
TRequest extends ProviderOperationRequest,
|
||||
TPort extends ProviderOperationPort<TRequest> =
|
||||
ProviderOperationPort<TRequest>,
|
||||
> {
|
||||
constructor(
|
||||
readonly provider: TPort,
|
||||
private readonly schema: z.ZodType<TRequest>,
|
||||
private readonly confidence:
|
||||
| "observed"
|
||||
| "derived"
|
||||
| ((operation: TOperation) => "observed" | "derived") = "observed",
|
||||
private readonly buildEvidence?: (
|
||||
request: TRequest,
|
||||
execution: AnalysisExecution,
|
||||
) => Evidence,
|
||||
) {}
|
||||
|
||||
close(): Promise<void> {
|
||||
return (
|
||||
(this.provider as { close?: () => Promise<void> }).close?.() ??
|
||||
Promise.resolve()
|
||||
);
|
||||
}
|
||||
|
||||
execute(
|
||||
operation: TOperation,
|
||||
input: unknown,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
const resolvedConfidence =
|
||||
typeof this.confidence === "function"
|
||||
? this.confidence(operation)
|
||||
: this.confidence;
|
||||
return executeProviderOperation(
|
||||
operation,
|
||||
input,
|
||||
options,
|
||||
this.schema,
|
||||
this.provider,
|
||||
resolvedConfidence,
|
||||
this.buildEvidence,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** Classify completion after Evidence assembly, preserving facts on late abort. */
|
||||
export const completeProviderEvidence = (
|
||||
evidence: Evidence,
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import type { RequestAnalysisPort } from "../ports/AnalysisProvider.js";
|
||||
import type { JebAnalysisPort } from "../ports/jeb/JebAnalysisPort.js";
|
||||
import type { UefiAnalysisPort } from "../ports/uefi/UefiAnalysisPort.js";
|
||||
import {
|
||||
apktoolRequestSchema,
|
||||
type ApktoolOperation,
|
||||
type ApktoolRequest,
|
||||
} from "../domain/apktool/apktoolResourceAnalysis.js";
|
||||
import {
|
||||
flutterRequestSchema,
|
||||
type FlutterOperation,
|
||||
type FlutterRequest,
|
||||
} from "../domain/flutter/flutterBuildAnalysis.js";
|
||||
import {
|
||||
jebRequestSchema,
|
||||
type JebOperation,
|
||||
type JebRequest,
|
||||
} from "../domain/jeb/jebAnalysis.js";
|
||||
import {
|
||||
pcapRequestSchema,
|
||||
type PcapOperation,
|
||||
type PcapRequest,
|
||||
} from "../domain/pcap/pcapAnalysis.js";
|
||||
import { createPcapEvidence } from "../domain/pcap/pcapEvidence.js";
|
||||
import {
|
||||
uefiRequestSchema,
|
||||
type UefiOperation,
|
||||
type UefiRequest,
|
||||
} from "../domain/uefi/uefiFirmwareAnalysis.js";
|
||||
import { ProviderOperationService } from "./ProviderOperationExecution.js";
|
||||
|
||||
export type ApktoolResourceAnalysisService = ProviderOperationService<
|
||||
ApktoolOperation,
|
||||
ApktoolRequest,
|
||||
RequestAnalysisPort<ApktoolRequest>
|
||||
>;
|
||||
|
||||
export type FlutterBuildAnalysisService = ProviderOperationService<
|
||||
FlutterOperation,
|
||||
FlutterRequest,
|
||||
RequestAnalysisPort<FlutterRequest>
|
||||
>;
|
||||
|
||||
export type JebAnalysisService = ProviderOperationService<
|
||||
JebOperation,
|
||||
JebRequest,
|
||||
JebAnalysisPort
|
||||
>;
|
||||
|
||||
export type UefiAnalysisService = ProviderOperationService<
|
||||
UefiOperation,
|
||||
UefiRequest,
|
||||
UefiAnalysisPort
|
||||
>;
|
||||
|
||||
export type PcapAnalysisService = ProviderOperationService<
|
||||
PcapOperation,
|
||||
PcapRequest,
|
||||
RequestAnalysisPort<PcapRequest>
|
||||
>;
|
||||
|
||||
export const createApktoolResourceAnalysisService = (
|
||||
provider: RequestAnalysisPort<ApktoolRequest>,
|
||||
): ApktoolResourceAnalysisService =>
|
||||
new ProviderOperationService(provider, apktoolRequestSchema, "observed");
|
||||
|
||||
export const createFlutterBuildAnalysisService = (
|
||||
provider: RequestAnalysisPort<FlutterRequest>,
|
||||
): FlutterBuildAnalysisService =>
|
||||
new ProviderOperationService(provider, flutterRequestSchema, "observed");
|
||||
|
||||
export const createJebAnalysisService = (
|
||||
provider: JebAnalysisPort,
|
||||
): JebAnalysisService =>
|
||||
new ProviderOperationService(provider, jebRequestSchema, (operation) =>
|
||||
operation === "decompile_jeb_item" ? "derived" : "observed",
|
||||
);
|
||||
|
||||
export const createUefiAnalysisService = (
|
||||
provider: UefiAnalysisPort,
|
||||
): UefiAnalysisService =>
|
||||
new ProviderOperationService(provider, uefiRequestSchema, "observed");
|
||||
|
||||
export const createPcapAnalysisService = (
|
||||
provider: RequestAnalysisPort<PcapRequest>,
|
||||
): PcapAnalysisService =>
|
||||
new ProviderOperationService(
|
||||
provider,
|
||||
pcapRequestSchema,
|
||||
"observed",
|
||||
createPcapEvidence,
|
||||
);
|
||||
@@ -2,7 +2,7 @@ import type { RequestAnalysisPort } from "../../ports/AnalysisProvider.js";
|
||||
import type { ApktoolRequest } from "../../domain/apktool/apktoolResourceAnalysis.js";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { ApktoolResourceAnalysisService } from "./ApktoolResourceAnalysisService.js";
|
||||
import { createApktoolResourceAnalysisService } from "../ProviderOperationServices.js";
|
||||
import { createAnalysisExecution } from "../../ports/AnalysisProvider.js";
|
||||
import { AnalysisCancelledError } from "../../domain/analysisErrorCore.js";
|
||||
import { parseEvidence } from "../../domain/evidence.js";
|
||||
@@ -45,7 +45,7 @@ it.each([
|
||||
],
|
||||
[{ path: "/targets/app.apk", extra: true }],
|
||||
])("rejects invalid decode selection before any effect: %j", async (input) => {
|
||||
const service = new ApktoolResourceAnalysisService(refusedPort);
|
||||
const service = createApktoolResourceAnalysisService(refusedPort);
|
||||
expect(
|
||||
await service.execute("decode_android_resources", input),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||
@@ -69,7 +69,7 @@ it("admits valid batched locales and forwards them to provider", async () => {
|
||||
return ok(execution);
|
||||
},
|
||||
};
|
||||
const result = await new ApktoolResourceAnalysisService(port).execute(
|
||||
const result = await createApktoolResourceAnalysisService(port).execute(
|
||||
"decode_android_resources",
|
||||
{
|
||||
path: "/targets/app.apk",
|
||||
@@ -100,7 +100,7 @@ it("composes observed Evidence with the caller parameters inline", async () => {
|
||||
return ok(execution);
|
||||
},
|
||||
};
|
||||
const result = await new ApktoolResourceAnalysisService(port).execute(
|
||||
const result = await createApktoolResourceAnalysisService(port).execute(
|
||||
"decode_android_resources",
|
||||
{ path: "/targets/app.apk", include_strings: true },
|
||||
);
|
||||
@@ -118,7 +118,7 @@ it("composes observed Evidence with the caller parameters inline", async () => {
|
||||
it("preserves cancellation before execution", async () => {
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
const service = new ApktoolResourceAnalysisService(refusedPort);
|
||||
const service = createApktoolResourceAnalysisService(refusedPort);
|
||||
const result = await service.execute(
|
||||
"decode_android_resources",
|
||||
{ path: "/targets/app.apk", include_strings: true },
|
||||
@@ -143,7 +143,7 @@ it("preserves a cancellation that races a completed observation", async () => {
|
||||
return ok(execution);
|
||||
},
|
||||
};
|
||||
const result = await new ApktoolResourceAnalysisService(racingPort).execute(
|
||||
const result = await createApktoolResourceAnalysisService(racingPort).execute(
|
||||
"decode_android_resources",
|
||||
{ path: "/targets/app.apk", include_strings: true },
|
||||
{ signal: controller.signal },
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import type { RequestAnalysisPort } from "../../ports/AnalysisProvider.js";
|
||||
import type { ApktoolRequest } from "../../domain/apktool/apktoolResourceAnalysis.js";
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import {
|
||||
apktoolRequestSchema,
|
||||
type ApktoolOperation,
|
||||
} from "../../domain/apktool/apktoolResourceAnalysis.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { executeProviderOperation } from "../ProviderOperationExecution.js";
|
||||
|
||||
/** Shared CLI/MCP admission, execution, and Evidence composition for Apktool. */
|
||||
export class ApktoolResourceAnalysisService {
|
||||
constructor(readonly provider: RequestAnalysisPort<ApktoolRequest>) {}
|
||||
|
||||
/** Run one caller-selected Apktool request and retain target identity inline. */
|
||||
async execute(
|
||||
operation: ApktoolOperation,
|
||||
input: unknown,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
return executeProviderOperation(
|
||||
operation,
|
||||
input,
|
||||
options,
|
||||
apktoolRequestSchema,
|
||||
this.provider,
|
||||
"observed",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import type { RequestAnalysisPort } from "../../ports/AnalysisProvider.js";
|
||||
import type { FlutterRequest } from "../../domain/flutter/flutterBuildAnalysis.js";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { FlutterBuildAnalysisService } from "./FlutterBuildAnalysisService.js";
|
||||
import { createFlutterBuildAnalysisService } from "../ProviderOperationServices.js";
|
||||
import { createAnalysisExecution } from "../../ports/AnalysisProvider.js";
|
||||
import { AnalysisCancelledError } from "../../domain/analysisErrorCore.js";
|
||||
import { parseEvidence } from "../../domain/evidence.js";
|
||||
@@ -41,7 +41,7 @@ const malformedSelections: readonly unknown[] = [
|
||||
{ path: "/targets/app.apk", abi: "not a locale" },
|
||||
];
|
||||
it.each(malformedSelections)("refuses %j at admission", async (input) => {
|
||||
const settled = await new FlutterBuildAnalysisService(refusing).execute(
|
||||
const settled = await createFlutterBuildAnalysisService(refusing).execute(
|
||||
"identify_flutter_build",
|
||||
input,
|
||||
);
|
||||
@@ -62,7 +62,7 @@ it("passes the validated request to the provider and seals Evidence", async () =
|
||||
return ok(execution);
|
||||
},
|
||||
};
|
||||
const result = await new FlutterBuildAnalysisService(recording).execute(
|
||||
const result = await createFlutterBuildAnalysisService(recording).execute(
|
||||
"identify_flutter_build",
|
||||
{ path: "/targets/app.apk" },
|
||||
);
|
||||
@@ -81,7 +81,7 @@ it("passes the validated request to the provider and seals Evidence", async () =
|
||||
it("settles an already-aborted call as cancellation before execution", async () => {
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
const settled = await new FlutterBuildAnalysisService(refusing).execute(
|
||||
const settled = await createFlutterBuildAnalysisService(refusing).execute(
|
||||
"identify_flutter_build",
|
||||
{ path: "/targets/app.apk" },
|
||||
{
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import type { RequestAnalysisPort } from "../../ports/AnalysisProvider.js";
|
||||
import type { FlutterRequest } from "../../domain/flutter/flutterBuildAnalysis.js";
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import {
|
||||
flutterRequestSchema,
|
||||
type FlutterOperation,
|
||||
} from "../../domain/flutter/flutterBuildAnalysis.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import { executeProviderOperation } from "../ProviderOperationExecution.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
|
||||
/** Shared CLI/MCP admission, execution, and Evidence composition for Flutter. */
|
||||
export class FlutterBuildAnalysisService {
|
||||
constructor(readonly provider: RequestAnalysisPort<FlutterRequest>) {}
|
||||
|
||||
/** Run one caller-selected Flutter request and retain target identity inline. */
|
||||
execute(
|
||||
operation: FlutterOperation,
|
||||
input: unknown,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
return executeProviderOperation(
|
||||
operation,
|
||||
input,
|
||||
options,
|
||||
flutterRequestSchema,
|
||||
this.provider,
|
||||
"observed",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { JebAnalysisService } from "./JebAnalysisService.js";
|
||||
import { createJebAnalysisService } from "../ProviderOperationServices.js";
|
||||
import type { JebAnalysisPort } from "../../ports/jeb/JebAnalysisPort.js";
|
||||
import type { JebRequest } from "../../domain/jeb/jebAnalysis.js";
|
||||
import { createAnalysisExecution } from "../../ports/AnalysisProvider.js";
|
||||
@@ -48,7 +48,7 @@ const fakePort = (
|
||||
describe("JebAnalysisService admission", () => {
|
||||
it("rejects malformed input before any provider call", async () => {
|
||||
const requests: JebRequest[] = [];
|
||||
const service = new JebAnalysisService(fakePort(requests));
|
||||
const service = createJebAnalysisService(fakePort(requests));
|
||||
const result = await service.execute("list_jeb_units", {
|
||||
count: 101,
|
||||
index: -1,
|
||||
@@ -68,7 +68,7 @@ describe("JebAnalysisService admission", () => {
|
||||
|
||||
it("returns cancellation without provider effects when already aborted", async () => {
|
||||
const requests: JebRequest[] = [];
|
||||
const service = new JebAnalysisService(fakePort(requests));
|
||||
const service = createJebAnalysisService(fakePort(requests));
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
const result = await service.execute(
|
||||
@@ -84,7 +84,7 @@ describe("JebAnalysisService admission", () => {
|
||||
|
||||
it("applies protocol defaults and composes provider evidence", async () => {
|
||||
const requests: JebRequest[] = [];
|
||||
const service = new JebAnalysisService(fakePort(requests));
|
||||
const service = createJebAnalysisService(fakePort(requests));
|
||||
const result = await service.execute("list_jeb_units", {});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(requests).toHaveLength(1);
|
||||
@@ -100,7 +100,7 @@ describe("JebAnalysisService admission", () => {
|
||||
});
|
||||
|
||||
it("preserves provider failure reasons", async () => {
|
||||
const service = new JebAnalysisService(
|
||||
const service = createJebAnalysisService(
|
||||
fakePort([], err(new AnalysisCancelledError("open_jeb_project"))),
|
||||
);
|
||||
const result = await service.execute("open_jeb_project", {
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
import type { JebAnalysisPort } from "../../ports/jeb/JebAnalysisPort.js";
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import {
|
||||
jebRequestSchema,
|
||||
type JebOperation,
|
||||
} from "../../domain/jeb/jebAnalysis.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { executeProviderOperation } from "../ProviderOperationExecution.js";
|
||||
|
||||
/** Shared CLI/MCP admission, execution and Evidence composition for JEB. */
|
||||
export class JebAnalysisService {
|
||||
constructor(readonly provider: JebAnalysisPort) {}
|
||||
|
||||
/** Run one caller-selected JEB request and retain engine provenance inline. */
|
||||
async execute(
|
||||
operation: JebOperation,
|
||||
input: unknown,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
return executeProviderOperation(
|
||||
operation,
|
||||
input,
|
||||
options,
|
||||
jebRequestSchema,
|
||||
this.provider,
|
||||
operation === "decompile_jeb_item" ? "derived" : "observed",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,14 +7,14 @@ import { parseEvidence } from "../../domain/evidence.js";
|
||||
import { pcapResultSchemas } from "../../domain/pcap/pcapAnalysis.js";
|
||||
import { err, ok } from "../../domain/result.js";
|
||||
|
||||
import { PcapAnalysisService } from "./PcapAnalysisService.js";
|
||||
import { createPcapAnalysisService } from "../ProviderOperationServices.js";
|
||||
|
||||
it("preserves the exact caller reason when pcap admission is already aborted", async () => {
|
||||
const reason = Object.freeze({ requested: "stop" });
|
||||
const controller = new AbortController();
|
||||
controller.abort(reason);
|
||||
let calls = 0;
|
||||
const service = new PcapAnalysisService({
|
||||
const service = createPcapAnalysisService({
|
||||
inspectAvailability: () => Promise.reject(new Error("unused")),
|
||||
close: () => Promise.resolve(),
|
||||
execute: () => {
|
||||
@@ -107,7 +107,7 @@ it.each(["inspect_pcap_client", "inspect_pcap_capture"] as const)(
|
||||
rawResult: { selected_output: "preserved" },
|
||||
},
|
||||
);
|
||||
const service = new PcapAnalysisService({
|
||||
const service = createPcapAnalysisService({
|
||||
inspectAvailability: () => Promise.reject(new Error("unused")),
|
||||
close: async () => {},
|
||||
execute: async () => {
|
||||
@@ -166,7 +166,7 @@ it.each(["inspect_pcap_client", "inspect_pcap_capture"] as const)(
|
||||
"The provider could not decode its output",
|
||||
{ diagnostics: { provider_detail: "retained" } },
|
||||
);
|
||||
const service = new PcapAnalysisService({
|
||||
const service = createPcapAnalysisService({
|
||||
inspectAvailability: () => Promise.reject(new Error("unused")),
|
||||
close: async () => {},
|
||||
execute: async () => {
|
||||
@@ -187,7 +187,7 @@ it.each(["inspect_pcap_client", "inspect_pcap_capture"] as const)(
|
||||
|
||||
it("preserves pcap caller field constraints before provider execution", async () => {
|
||||
let calls = 0;
|
||||
const service = new PcapAnalysisService({
|
||||
const service = createPcapAnalysisService({
|
||||
inspectAvailability: () => Promise.reject(new Error("unused")),
|
||||
close: () => Promise.resolve(),
|
||||
execute: () => {
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import type {
|
||||
ExecutionOptions,
|
||||
RequestAnalysisPort,
|
||||
} from "../../ports/AnalysisProvider.js";
|
||||
import {
|
||||
pcapRequestSchema,
|
||||
type PcapOperation,
|
||||
type PcapRequest,
|
||||
} from "../../domain/pcap/pcapAnalysis.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import { createPcapEvidence } from "../../domain/pcap/pcapEvidence.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { executeProviderOperation } from "../ProviderOperationExecution.js";
|
||||
|
||||
/** Shared CLI/MCP admission, execution, and Evidence composition for pcap. */
|
||||
export class PcapAnalysisService {
|
||||
constructor(readonly provider: RequestAnalysisPort<PcapRequest>) {}
|
||||
|
||||
/** Run one caller-selected pcap request and retain capture identity inline. */
|
||||
execute(
|
||||
operation: PcapOperation,
|
||||
input: unknown,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
return executeProviderOperation(
|
||||
operation,
|
||||
input,
|
||||
options,
|
||||
pcapRequestSchema,
|
||||
this.provider,
|
||||
"observed",
|
||||
createPcapEvidence,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { UefiAnalysisPort } from "../../ports/uefi/UefiAnalysisPort.js";
|
||||
import {
|
||||
uefiRequestSchema,
|
||||
type UefiOperation,
|
||||
} from "../../domain/uefi/uefiFirmwareAnalysis.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import { executeProviderOperation } from "../ProviderOperationExecution.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
|
||||
/** Shared CLI/MCP admission, execution, and Evidence composition for UEFI. */
|
||||
export class UefiAnalysisService {
|
||||
constructor(readonly provider: UefiAnalysisPort) {}
|
||||
|
||||
close(): Promise<void> {
|
||||
return this.provider.close?.() ?? Promise.resolve();
|
||||
}
|
||||
|
||||
/** Run one caller-selected UEFI request and retain image identity inline. */
|
||||
execute(
|
||||
operation: UefiOperation,
|
||||
input: unknown,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
return executeProviderOperation(
|
||||
operation,
|
||||
input,
|
||||
options,
|
||||
uefiRequestSchema,
|
||||
this.provider,
|
||||
"observed",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { RequestAnalysisPort } from "../ports/AnalysisProvider.js";
|
||||
import type { ApktoolRequest } from "../domain/apktool/apktoolResourceAnalysis.js";
|
||||
import { ApktoolResourceAnalysisService } from "../application/apktool/ApktoolResourceAnalysisService.js";
|
||||
import { createApktoolResourceAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import { createApktoolResourceAnalysisProvider } from "../composition/apktool.js";
|
||||
import { APKTOOL_TOOL_CONTRACTS } from "../contracts/apktool/apktoolToolContracts.js";
|
||||
import type { ApktoolOperation } from "../domain/apktool/apktoolResourceAnalysis.js";
|
||||
@@ -24,7 +24,7 @@ export const registerApktoolCommands = (
|
||||
environment,
|
||||
),
|
||||
): void => {
|
||||
const service = new ApktoolResourceAnalysisService(provider);
|
||||
const service = createApktoolResourceAnalysisService(provider);
|
||||
const run =
|
||||
(operation: ApktoolOperation) => (): EvidenceInspectionService => ({
|
||||
inspect: (input, { signal }) =>
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { FlutterRequest } from "../domain/flutter/flutterBuildAnalysis.js";
|
||||
import { projectCliAnalysisResult } from "./projectCliAnalysisResult.js";
|
||||
import { withEvidenceCallerInputPath } from "../domain/evidence.js";
|
||||
import { recognizeEvidence } from "../domain/evidenceValidation.js";
|
||||
import { FlutterBuildAnalysisService } from "../application/flutter/FlutterBuildAnalysisService.js";
|
||||
import { createFlutterBuildAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import { createFlutterBuildAnalysisProvider } from "../composition/flutter.js";
|
||||
import { FLUTTER_TOOL_CONTRACTS } from "../contracts/flutter/flutterToolContracts.js";
|
||||
import type { FlutterOperation } from "../domain/flutter/flutterBuildAnalysis.js";
|
||||
@@ -34,9 +34,13 @@ export const registerFlutterCommands = (
|
||||
(input: { readonly path: string }, { signal }: ContractCommandContext) =>
|
||||
finishAnalysisCommand(
|
||||
bindCliEvidenceCallerPath(input.path, () =>
|
||||
new FlutterBuildAnalysisService(provider).execute(operation, input, {
|
||||
signal,
|
||||
}),
|
||||
createFlutterBuildAnalysisService(provider).execute(
|
||||
operation,
|
||||
input,
|
||||
{
|
||||
signal,
|
||||
},
|
||||
),
|
||||
),
|
||||
{ close: () => provider.close() },
|
||||
"flutter",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { JebAnalysisService } from "../application/jeb/JebAnalysisService.js";
|
||||
import { createJebAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import type { JebAnalysisPort } from "../ports/jeb/JebAnalysisPort.js";
|
||||
import { createJebAnalysisProvider } from "../composition/jeb.js";
|
||||
import { JEB_TOOL_CONTRACTS } from "../contracts/jeb/jebToolContracts.js";
|
||||
@@ -21,7 +21,7 @@ export const registerJebCommands = (
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
provider: JebAnalysisPort = createJebAnalysisProvider(environment),
|
||||
): void => {
|
||||
const service = new JebAnalysisService(provider);
|
||||
const service = createJebAnalysisService(provider);
|
||||
const run = (operation: JebOperation) => (): EvidenceInspectionService => ({
|
||||
inspect: (input, { signal }) =>
|
||||
service.execute(operation, input, { signal }),
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { RequestAnalysisPort } from "../ports/AnalysisProvider.js";
|
||||
import type { PcapRequest } from "../domain/pcap/pcapAnalysis.js";
|
||||
import type { Logger } from "pino";
|
||||
|
||||
import { PcapAnalysisService } from "../application/pcap/PcapAnalysisService.js";
|
||||
import { createPcapAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import { createPcapAnalysisProvider } from "../composition/pcap.js";
|
||||
import { PCAP_TOOL_CONTRACTS } from "../contracts/pcap/pcapToolContracts.js";
|
||||
import type { PcapOperation } from "../domain/pcap/pcapAnalysis.js";
|
||||
@@ -24,7 +24,7 @@ export const registerPcapCommands = (
|
||||
environment,
|
||||
),
|
||||
): void => {
|
||||
const pcap = new PcapAnalysisService(provider);
|
||||
const pcap = createPcapAnalysisService(provider);
|
||||
// Each command releases the shared provider's tools when it finishes.
|
||||
const service =
|
||||
(operation: PcapOperation) => (): EvidenceInspectionService => ({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Logger } from "pino";
|
||||
import { z } from "zod";
|
||||
|
||||
import { UefiAnalysisService } from "../application/uefi/UefiAnalysisService.js";
|
||||
import { createUefiAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import { createUefiAnalysisProvider } from "../composition/uefi.js";
|
||||
import { UEFI_TOOL_CONTRACTS } from "../contracts/uefi/uefiToolContracts.js";
|
||||
import { AnalysisInputError } from "../domain/analysisErrorCore.js";
|
||||
@@ -29,7 +29,7 @@ export const registerUefiCommands = (
|
||||
cli: CliInstance,
|
||||
logger: Logger,
|
||||
): void => {
|
||||
const service = new UefiAnalysisService(createUefiAnalysisProvider());
|
||||
const service = createUefiAnalysisService(createUefiAnalysisProvider());
|
||||
const run = (operation: UefiOperation) =>
|
||||
inspectWithService(
|
||||
() => ({
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { ApktoolRequest } from "../domain/apktool/apktoolResourceAnalysis.j
|
||||
import type { FlutterRequest } from "../domain/flutter/flutterBuildAnalysis.js";
|
||||
import type { PcapRequest } from "../domain/pcap/pcapAnalysis.js";
|
||||
import type { AdbRequest } from "../domain/adb/adbDeviceAnalysis.js";
|
||||
import { UefiAnalysisService } from "../application/uefi/UefiAnalysisService.js";
|
||||
import { createUefiAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import type { UefiAnalysisPort } from "../ports/uefi/UefiAnalysisPort.js";
|
||||
import { createUefiAnalysisProvider } from "./uefi.js";
|
||||
import type { OptionalProviderLoadFailures } from "../ports/OptionalObservationProviders.js";
|
||||
@@ -491,11 +491,10 @@ const modules = {
|
||||
},
|
||||
}),
|
||||
),
|
||||
uefiAnalysis: service(
|
||||
({ options }) =>
|
||||
new UefiAnalysisService(
|
||||
options.uefiAnalysis ?? createUefiAnalysisProvider(),
|
||||
),
|
||||
uefiAnalysis: service(({ options }) =>
|
||||
createUefiAnalysisService(
|
||||
options.uefiAnalysis ?? createUefiAnalysisProvider(),
|
||||
),
|
||||
),
|
||||
gdbSessions: capability(
|
||||
({ providerEnvironment, platform }) =>
|
||||
|
||||
@@ -45,10 +45,10 @@ import { silentLogger } from "../logger.js";
|
||||
import type { Logger } from "pino";
|
||||
import { JavaScriptRecoveryService } from "../application/javascript/JavaScriptRecoveryService.js";
|
||||
import { AndroidAnalysisService } from "../application/android/AndroidAnalysisService.js";
|
||||
import { JebAnalysisService } from "../application/jeb/JebAnalysisService.js";
|
||||
import { PcapAnalysisService } from "../application/pcap/PcapAnalysisService.js";
|
||||
import { ApktoolResourceAnalysisService } from "../application/apktool/ApktoolResourceAnalysisService.js";
|
||||
import { FlutterBuildAnalysisService } from "../application/flutter/FlutterBuildAnalysisService.js";
|
||||
import { createJebAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import { createPcapAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import { createApktoolResourceAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import { createFlutterBuildAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import { AdbDeviceAnalysisService } from "../application/adb/AdbDeviceAnalysisService.js";
|
||||
import { registerGuidedPrompts } from "./registerPrompts.js";
|
||||
import { registerSessionTools } from "./registerSessionTools.js";
|
||||
@@ -500,14 +500,14 @@ export const createServer = (
|
||||
pcap: () => {
|
||||
registerServiceTools(
|
||||
server,
|
||||
{ pcapAnalysis: new PcapAnalysisService(pcap) },
|
||||
{ pcapAnalysis: createPcapAnalysisService(pcap) },
|
||||
contractTools,
|
||||
);
|
||||
},
|
||||
flutter: () => {
|
||||
registerServiceTools(
|
||||
server,
|
||||
{ flutterAnalysis: new FlutterBuildAnalysisService(flutter) },
|
||||
{ flutterAnalysis: createFlutterBuildAnalysisService(flutter) },
|
||||
contractTools,
|
||||
);
|
||||
},
|
||||
@@ -522,13 +522,13 @@ export const createServer = (
|
||||
apktool: () =>
|
||||
registerServiceTools(
|
||||
server,
|
||||
{ apktoolAnalysis: new ApktoolResourceAnalysisService(apktool) },
|
||||
{ apktoolAnalysis: createApktoolResourceAnalysisService(apktool) },
|
||||
contractTools,
|
||||
),
|
||||
jeb: () =>
|
||||
registerServiceTools(
|
||||
server,
|
||||
{ jebAnalysis: new JebAnalysisService(jeb) },
|
||||
{ jebAnalysis: createJebAnalysisService(jeb) },
|
||||
contractTools,
|
||||
),
|
||||
adb: () =>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { UefiAnalysisService } from "../application/uefi/UefiAnalysisService.js";
|
||||
import type { UefiAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import type { MavenGradleMetadataService } from "../application/java/MavenGradleMetadataService.js";
|
||||
|
||||
import type { NugetNupkgService } from "../application/nuget/NugetNupkgService.js";
|
||||
@@ -38,7 +38,7 @@ import {
|
||||
import { z } from "zod";
|
||||
import { analysisViewSourceSchema } from "../domain/analysisView/analysisViewRequest.js";
|
||||
import type { ApkSignatureService } from "../application/apkSignature/ApkSignatureService.js";
|
||||
import type { ApktoolResourceAnalysisService } from "../application/apktool/ApktoolResourceAnalysisService.js";
|
||||
import type { ApktoolResourceAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import type { DesktopApplicationService } from "../application/artifacts/DesktopApplicationService.js";
|
||||
import type { AppleIpsService } from "../application/binaryDiagnostics/AppleIpsService.js";
|
||||
import type { BinaryHardeningService } from "../application/binaryDiagnostics/BinaryHardeningService.js";
|
||||
@@ -61,7 +61,7 @@ import type { PacketCaptureService } from "../application/captures/PacketCapture
|
||||
import type { BeamService } from "../application/erlang/BeamService.js";
|
||||
import type { EvmInterfaceService } from "../application/evm/EvmInterfaceService.js";
|
||||
import type { FirmwareAnalysisService } from "../application/firmware/FirmwareAnalysisService.js";
|
||||
import type { FlutterBuildAnalysisService } from "../application/flutter/FlutterBuildAnalysisService.js";
|
||||
import type { FlutterBuildAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import type { GoBinaryService } from "../application/go/GoBinaryService.js";
|
||||
import type { GpuCodeObjectsService } from "../application/gpu/GpuCodeObjectsService.js";
|
||||
import type { Il2cppMetadataService } from "../application/il2cpp/Il2cppMetadataService.js";
|
||||
@@ -70,9 +70,9 @@ import {
|
||||
recordEvidenceSources,
|
||||
} from "../application/investigation/recordEvidenceSources.js";
|
||||
import type { JavaScriptRecoveryService } from "../application/javascript/JavaScriptRecoveryService.js";
|
||||
import type { JebAnalysisService } from "../application/jeb/JebAnalysisService.js";
|
||||
import type { JebAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import type { ModelArtifactService } from "../application/model/ModelArtifactService.js";
|
||||
import type { PcapAnalysisService } from "../application/pcap/PcapAnalysisService.js";
|
||||
import type { PcapAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import type { PythonPycService } from "../application/python/PythonPycService.js";
|
||||
import type { ReleaseExposureService } from "../application/releaseExposure/ReleaseExposureService.js";
|
||||
import type { RustBinaryService } from "../application/rust/RustBinaryService.js";
|
||||
|
||||
@@ -13,7 +13,7 @@ import { PrivateRuntimeRoot } from "../process/PrivateRuntimeRoot.js";
|
||||
import { UEFI_FIRMWARE_LIMITS } from "../domain/uefi/uefiLimits.js";
|
||||
import { createDeferred } from "../../tests/fixtures/binarySession.js";
|
||||
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
|
||||
import { UefiAnalysisService } from "../application/uefi/UefiAnalysisService.js";
|
||||
import { createUefiAnalysisService } from "../application/ProviderOperationServices.js";
|
||||
import { AMD_ZLIB_HEADER_LENGTH } from "./FfsSections.js";
|
||||
import {
|
||||
buildCompressionSection,
|
||||
@@ -566,7 +566,7 @@ it("extracts embedded raw-file volume files and targets the nested volume by off
|
||||
|
||||
it("validates requests through the service before execution", async () => {
|
||||
const provider = new UefiAnalysisProvider();
|
||||
const service = new UefiAnalysisService(provider);
|
||||
const service = createUefiAnalysisService(provider);
|
||||
const rejected = await service.execute("inspect_uefi_firmware", {
|
||||
path: "relative/image.fi",
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
unifiedAotFixtureImage,
|
||||
} from "../../../src/flutter/FlutterBuild.fixture.js";
|
||||
import { FlutterBuildProvider } from "../../../src/flutter/FlutterBuildProvider.js";
|
||||
import { FlutterBuildAnalysisService } from "../../../src/application/flutter/FlutterBuildAnalysisService.js";
|
||||
import { createFlutterBuildAnalysisService } from "../../../src/application/ProviderOperationServices.js";
|
||||
import { finishAnalysisCommand } from "../../../src/cli/finishAnalysisCommand.js";
|
||||
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
||||
import { ProviderCleanupError } from "../../../src/domain/providerCleanupError.js";
|
||||
@@ -511,7 +511,7 @@ it.each(["identify_flutter_build", "inspect_dart_aot"] as const)(
|
||||
]);
|
||||
const controlProvider = new FlutterBuildProvider();
|
||||
onTestFinished(() => controlProvider.close());
|
||||
const control = await new FlutterBuildAnalysisService(
|
||||
const control = await createFlutterBuildAnalysisService(
|
||||
controlProvider,
|
||||
).execute(operation, { path });
|
||||
if (!control.ok) throw control.error;
|
||||
@@ -525,7 +525,7 @@ it.each(["identify_flutter_build", "inspect_dart_aot"] as const)(
|
||||
controller.abort(reason);
|
||||
});
|
||||
const provider = new FlutterBuildProvider();
|
||||
const result = await new FlutterBuildAnalysisService(provider).execute(
|
||||
const result = await createFlutterBuildAnalysisService(provider).execute(
|
||||
operation,
|
||||
{ path },
|
||||
{ signal: controller.signal },
|
||||
@@ -728,7 +728,7 @@ it("retains failed snapshot cleanup and retries it on close", async () => {
|
||||
failing = false;
|
||||
await provider.close();
|
||||
});
|
||||
const service = new FlutterBuildAnalysisService(provider);
|
||||
const service = createFlutterBuildAnalysisService(provider);
|
||||
const result = await finishAnalysisCommand(
|
||||
() =>
|
||||
service.execute("identify_flutter_build", {
|
||||
@@ -1818,7 +1818,7 @@ it.each([false, true])(
|
||||
const controller = new AbortController();
|
||||
const reason = { caller: "cancel during refused cleanup" };
|
||||
const controlProvider = new FlutterBuildProvider();
|
||||
const control = await new FlutterBuildAnalysisService(
|
||||
const control = await createFlutterBuildAnalysisService(
|
||||
controlProvider,
|
||||
).execute("identify_flutter_build", { path });
|
||||
await controlProvider.close();
|
||||
@@ -2236,7 +2236,7 @@ it("recovers omitted Dart pool strings through selection and per-call admission
|
||||
]);
|
||||
const provider = new FlutterBuildProvider();
|
||||
onTestFinished(() => provider.close());
|
||||
const service = new FlutterBuildAnalysisService(provider);
|
||||
const service = createFlutterBuildAnalysisService(provider);
|
||||
const inspect = async (pool_policy?: Record<string, unknown>) => {
|
||||
const result = await service.execute("inspect_dart_aot", {
|
||||
path,
|
||||
|
||||
@@ -7,7 +7,7 @@ import { unlink } from "node:fs/promises";
|
||||
import { createHash } from "node:crypto";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { expect, it, onTestFinished, vi } from "vitest";
|
||||
import { FlutterBuildAnalysisService } from "../../../src/application/flutter/FlutterBuildAnalysisService.js";
|
||||
import { createFlutterBuildAnalysisService } from "../../../src/application/ProviderOperationServices.js";
|
||||
import {
|
||||
executeRetainedSummaryOperation,
|
||||
inspectAnalysisView,
|
||||
@@ -319,7 +319,7 @@ it("rejects unavailable retention, invalid delivery and cancellation before prod
|
||||
const provider = createFlutterBuildAnalysisProvider();
|
||||
onTestFinished(() => provider.close());
|
||||
const execute = vi.spyOn(provider, "execute");
|
||||
const service = new FlutterBuildAnalysisService(provider);
|
||||
const service = createFlutterBuildAnalysisService(provider);
|
||||
const retention = { recordEvidence: undefined, evidenceById: undefined };
|
||||
expect(
|
||||
await executeRetainedSummaryOperation(
|
||||
|
||||
@@ -24,7 +24,7 @@ import { expect, it, onTestFinished, vi } from "vitest";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { PcapProvider } from "../../../src/pcap/PcapProvider.js";
|
||||
import { PcapAnalysisService } from "../../../src/application/pcap/PcapAnalysisService.js";
|
||||
import { createPcapAnalysisService } from "../../../src/application/ProviderOperationServices.js";
|
||||
import {
|
||||
CAPINFOS_COMMAND_ENV,
|
||||
TSHARK_COMMAND_ENV,
|
||||
@@ -97,7 +97,7 @@ printf '%s|%s|%s\\n' "$PCAP_TEST_PROFILE" "$PCAP_TEST_EMPTY" "\${PCAP_TEST_ABSEN
|
||||
}
|
||||
const provider = new PcapProvider({ environment });
|
||||
onTestFinished(() => provider.close());
|
||||
const service = new PcapAnalysisService(provider);
|
||||
const service = createPcapAnalysisService(provider);
|
||||
const first = await service.execute("inspect_pcap_client", {});
|
||||
if (!first.ok) throw first.error;
|
||||
expect(first.value.normalized_result).toMatchObject({
|
||||
|
||||
@@ -15,7 +15,7 @@ it("reports a decompile marker only when a nonempty requested marker was observe
|
||||
`
|
||||
import { registerHooks } from 'node:module';
|
||||
const service = \`
|
||||
export class JebAnalysisService {
|
||||
export const createJebAnalysisService = () => ({
|
||||
async execute(name) {
|
||||
if (name === 'inspect_jeb_client') return { ok: true, value: { normalized_result: { engine: { version: 'fixture', gui_client: false, endpoint: 'fixture' } } } };
|
||||
if (name === 'open_jeb_project') return { ok: false, error: { message: 'not available' } };
|
||||
@@ -23,11 +23,11 @@ export class JebAnalysisService {
|
||||
if (name === 'decompile_jeb_item') return { ok: true, value: { normalized_result: { text: process.env.REA_JEB_PROBE_TEXT ?? '' } } };
|
||||
throw new Error('unexpected operation');
|
||||
}
|
||||
}\`;
|
||||
});\`;
|
||||
const provider = \`export const createJebAnalysisProvider = () => ({ close: async () => {} });\`;
|
||||
registerHooks({ resolve(specifier, context, next) {
|
||||
if (context.parentURL?.endsWith('/scripts/verify-jeb.mjs')) {
|
||||
if (specifier.endsWith('/JebAnalysisService.js')) return { shortCircuit: true, url: 'data:text/javascript,' + encodeURIComponent(service) };
|
||||
if (specifier.endsWith('/ProviderOperationServices.js')) return { shortCircuit: true, url: 'data:text/javascript,' + encodeURIComponent(service) };
|
||||
if (specifier.endsWith('/composition/jeb.js')) return { shortCircuit: true, url: 'data:text/javascript,' + encodeURIComponent(provider) };
|
||||
}
|
||||
return next(specifier, context);
|
||||
|
||||
@@ -110,8 +110,8 @@ export const createJebAnalysisProvider = () => ({
|
||||
`,
|
||||
);
|
||||
await writeFile(
|
||||
join(root, "dist", "application", "jeb", "JebAnalysisService.js"),
|
||||
`export class JebAnalysisService {
|
||||
join(root, "dist", "application", "ProviderOperationServices.js"),
|
||||
`export const createJebAnalysisService = () => ({
|
||||
async execute(operation) {
|
||||
${primaryBody}
|
||||
const result = {
|
||||
@@ -122,8 +122,8 @@ export const createJebAnalysisProvider = () => ({
|
||||
}[operation];
|
||||
if (result === undefined) throw new Error("Unexpected simulated operation: " + operation);
|
||||
return { ok: true, value: { normalized_result: result } };
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
AnalysisProtocolError,
|
||||
AnalysisCancelledError,
|
||||
} from "../../../src/domain/analysisErrorCore.js";
|
||||
import { JebAnalysisService } from "../../../src/application/jeb/JebAnalysisService.js";
|
||||
import { createJebAnalysisService } from "../../../src/application/ProviderOperationServices.js";
|
||||
import {
|
||||
startJebMcpFixture,
|
||||
jebPrimaryResponses,
|
||||
@@ -165,7 +165,7 @@ it("retains completed JEB Evidence when the caller aborts after the tool returns
|
||||
environment: { REA_JEB_MCP_URL: fixture.endpoint },
|
||||
});
|
||||
await withVerifierCleanup(async () => {
|
||||
const service = new JebAnalysisService(provider);
|
||||
const service = createJebAnalysisService(provider);
|
||||
const result = await service.execute(
|
||||
"inspect_jeb_client",
|
||||
{},
|
||||
|
||||
@@ -4,7 +4,7 @@ import { afterEach, expect, it, onTestFinished, vi } from "vitest";
|
||||
|
||||
import { createCli } from "../../src/cli.js";
|
||||
import { ApktoolProvider } from "../../src/apktool/ApktoolProvider.js";
|
||||
import { ApktoolResourceAnalysisService } from "../../src/application/apktool/ApktoolResourceAnalysisService.js";
|
||||
import { createApktoolResourceAnalysisService } from "../../src/application/ProviderOperationServices.js";
|
||||
import { parseEvidence } from "../../src/domain/evidence.js";
|
||||
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||
|
||||
@@ -77,7 +77,7 @@ it.skipIf(process.platform === "win32")(
|
||||
const provider = new ApktoolProvider();
|
||||
onTestFinished(() => provider.close());
|
||||
vi.stubEnv("REA_APKTOOL_COMMAND", command);
|
||||
const result = await new ApktoolResourceAnalysisService(provider).execute(
|
||||
const result = await createApktoolResourceAnalysisService(provider).execute(
|
||||
"inspect_apktool_client",
|
||||
{},
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user