diff --git a/src/native/NativeMacOSProvider.ts b/src/native/NativeMacOSProvider.ts index 130505ff9..8ae004c45 100644 --- a/src/native/NativeMacOSProvider.ts +++ b/src/native/NativeMacOSProvider.ts @@ -129,6 +129,8 @@ class NativeMacOSClient implements AnalysisClient { parameters: Readonly>, options?: { readonly signal?: AbortSignal }, ) { + if (options?.signal?.aborted === true) + return err(new AnalysisCancelledError(operation)); if (operation === "health") return ok(createAnalysisExecution(null, IDENTITY)); if (!isNativeOperation(operation)) diff --git a/tests/nativeProvider.test.ts b/tests/nativeProvider.test.ts index 95ad3389a..b15077d28 100644 --- a/tests/nativeProvider.test.ts +++ b/tests/nativeProvider.test.ts @@ -137,6 +137,26 @@ describe("native macOS provider", () => { } }); + it("classifies pre-aborted requests before operation or runner discovery", async () => { + const controller = new AbortController(); + controller.abort(); + const runner = new CountingRunner(); + const client = new NativeMacOSProvider(runner, "linux").createClient( + machoTarget("/fixture"), + ); + + const result = await client.execute( + "list_architectures", + {}, + { + signal: controller.signal, + }, + ); + + expect(!result.ok && result.error._tag).toBe("AnalysisCancelledError"); + expect(runner.calls).toBe(0); + }); + it("parses thin and universal lipo fixtures", async () => { expect( parseLipoArchitectures(await fixture("lipo-thin.txt")), @@ -169,6 +189,15 @@ class FailingRunner implements NativeCommandRunner { } } +class CountingRunner implements NativeCommandRunner { + calls = 0; + + run(tool: string) { + this.calls += 1; + return Promise.resolve(err(new NativeCommandFailure(tool, "unavailable"))); + } +} + const outputFor = async ( tool: string, arguments_: readonly string[],