diff --git a/src/application/python/PythonPycService.test.ts b/src/application/python/PythonPycService.test.ts index 8ae0d90224b..d79766974a9 100644 --- a/src/application/python/PythonPycService.test.ts +++ b/src/application/python/PythonPycService.test.ts @@ -6,6 +6,7 @@ import { } from "../../domain/analysisErrorCore.js"; import type { PythonPyc } from "../../domain/python/pythonPyc.js"; import { ok } from "../../domain/result.js"; +import type { PythonPycPort } from "../../ports/python/PythonPycPort.js"; import { PythonPycService } from "./PythonPycService.js"; const identity = { @@ -14,6 +15,9 @@ const identity = { version: "1", }; +const serviceWithInspect = (inspect: PythonPycPort["inspect"]) => + new PythonPycService({ close: async () => {}, identity, inspect }); + const report: PythonPyc = { artifact: { path: "/artifacts/sample.pyc", @@ -68,13 +72,9 @@ const report: PythonPyc = { it("rejects a relative path and extra arguments before reading", async () => { let calls = 0; - const service = new PythonPycService({ - close: async () => {}, - identity, - inspect: () => { - calls += 1; - return Promise.resolve(ok(report)); - }, + const service = serviceWithInspect(() => { + calls += 1; + return Promise.resolve(ok(report)); }); const relative = await service.inspect({ path: "sample.pyc" }); const extra = await service.inspect({ @@ -91,13 +91,9 @@ it("rejects a relative path and extra arguments before reading", async () => { it("retains completed pyc Evidence and the opaque caller reason on late cancellation", async () => { const controller = new AbortController(); const reason = new AnalysisInputError("opaque caller metadata"); - const service = new PythonPycService({ - close: async () => {}, - identity, - inspect: () => { - controller.abort(reason); - return Promise.resolve(ok(report)); - }, + const service = serviceWithInspect(() => { + controller.abort(reason); + return Promise.resolve(ok(report)); }); const result = await service.inspect( { path: report.artifact.path }, @@ -116,13 +112,9 @@ it("retains completed pyc Evidence and the opaque caller reason on late cancella it("retains a pre-admission cancellation reason without calling the pyc provider", async () => { const reason = new Error("caller stopped before pyc admission"); let calls = 0; - const service = new PythonPycService({ - close: async () => {}, - identity, - inspect: async () => { - calls++; - return ok(report); - }, + const service = serviceWithInspect(async () => { + calls++; + return ok(report); }); const result = await service.inspect( { path: report.artifact.path }, @@ -145,13 +137,9 @@ it.each([ "preserves a provider %s failure instead of relabeling it as a late abort", async (_name, badReport) => { const controller = new AbortController(); - const service = new PythonPycService({ - close: async () => {}, - identity, - inspect: async () => { - controller.abort(new Error("later caller stop")); - return ok(badReport); - }, + const service = serviceWithInspect(async () => { + controller.abort(new Error("later caller stop")); + return ok(badReport); }); const result = await service.inspect( { path: report.artifact.path },