diff --git a/src/browser/history/CaptureFailures.test.ts b/src/browser/history/CaptureFailures.test.ts index e016994df9f..18fe9c8d6a1 100644 --- a/src/browser/history/CaptureFailures.test.ts +++ b/src/browser/history/CaptureFailures.test.ts @@ -1,3 +1,4 @@ +import { v8HeapExhaustionFailure } from "../../../tests/fixtures/providerProcess.js"; import { writeFile } from "node:fs/promises"; import { join } from "node:path"; import { expect, it } from "vitest"; @@ -66,24 +67,9 @@ it.each([ }); const stderr = "FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory\r\n"; - const cause = new OwnedCommandFailure("process", "Decoder failed", { - stdout: { text: "", bytes: 0, observedBytes: 0 }, - stderr: { - text: stderr, - bytes: Buffer.byteLength(stderr), - observedBytes: Buffer.byteLength(stderr), - }, + const cause = v8HeapExhaustionFailure("Decoder failed", stderr, { exitCode, signal, - runtimeExhaustion: { - runtime: "v8", - area: "heap", - stream: "stderr", - line: stderr.trim(), - lineComplete: true, - truncated: false, - invalidUtf8: false, - }, }); const projected = analysisErrorProjectionSchema.parse( projectAnalysisError(historicalCaptureFailure(input, cause, "decoder")), diff --git a/src/config/captureDecoderHeap.test.ts b/src/config/captureDecoderHeap.test.ts index 780c81b296b..e3d199f3734 100644 --- a/src/config/captureDecoderHeap.test.ts +++ b/src/config/captureDecoderHeap.test.ts @@ -11,7 +11,7 @@ import { historicalCaptureFailure } from "../browser/history/CaptureFailures.js" import { ConfigurationError } from "../domain/configurationErrors.js"; import { projectAnalysisError } from "../domain/analysisErrorProjection.js"; import { inspectWebNetworkCaptureInputSchema } from "../domain/webNetworkCapture.js"; -import { OwnedCommandFailure } from "../process/OwnedCommand.js"; +import { v8HeapExhaustionFailure } from "../../tests/fixtures/providerProcess.js"; import { createWebNetworkCaptureService } from "../composition/webNetworkCaptures.js"; import { createCli } from "../cli.js"; import { historicalHar } from "../../tests/fixtures/historicalHar.js"; @@ -34,25 +34,7 @@ const configured = (oldGenerationMiB: number) => const heapExhaustion = () => { const stderr = "FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory\n"; - return new OwnedCommandFailure("process", "Decoder failed", { - stdout: { text: "", bytes: 0, observedBytes: 0 }, - stderr: { - text: stderr, - bytes: Buffer.byteLength(stderr), - observedBytes: Buffer.byteLength(stderr), - }, - exitCode: null, - signal: "SIGABRT", - runtimeExhaustion: { - runtime: "v8", - area: "heap", - stream: "stderr", - line: stderr.trim(), - lineComplete: true, - truncated: false, - invalidUtf8: false, - }, - }); + return v8HeapExhaustionFailure("Decoder failed", stderr); }; it("keeps the 192 MiB decoder heap when the setting is unset", async () => { diff --git a/tests/boundary/sqlite/sqliteDatabaseFailures.test.ts b/tests/boundary/sqlite/sqliteDatabaseFailures.test.ts index 8207fa99e01..1d32d9a9ba1 100644 --- a/tests/boundary/sqlite/sqliteDatabaseFailures.test.ts +++ b/tests/boundary/sqlite/sqliteDatabaseFailures.test.ts @@ -1,3 +1,4 @@ +import { v8HeapExhaustionFailure } from "../../fixtures/providerProcess.js"; import { SqliteDatabaseProvider } from "../../../src/sqlite/SqliteDatabaseProvider.js"; import { createSqliteDatabaseFixture } from "../../fixtures/sqlite/database.js"; import { spawnFailure } from "../../support/process/spawnFailure.js"; @@ -145,25 +146,7 @@ it.each(["/selected.db", "./Database files/another.db"])( (path) => { const stderr = "FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory"; - const cause = new OwnedCommandFailure("process", "Worker exited.", { - stdout: { text: "", bytes: 0, observedBytes: 0 }, - stderr: { - text: stderr, - bytes: Buffer.byteLength(stderr), - observedBytes: Buffer.byteLength(stderr), - }, - exitCode: null, - signal: "SIGABRT", - runtimeExhaustion: { - runtime: "v8", - area: "heap", - stream: "stderr", - line: stderr.trim(), - lineComplete: true, - truncated: false, - invalidUtf8: false, - }, - }); + const cause = v8HeapExhaustionFailure("Worker exited.", stderr); const failure = classifyProviderFailure( cause, sqliteDatabaseDialect(path, "worker"), diff --git a/tests/fixtures/providerProcess.ts b/tests/fixtures/providerProcess.ts index f35e232f63a..f385595295b 100644 --- a/tests/fixtures/providerProcess.ts +++ b/tests/fixtures/providerProcess.ts @@ -1,6 +1,10 @@ import { spawn, type ChildProcess } from "node:child_process"; import { fileURLToPath } from "node:url"; -import type { ProviderProcessHandle } from "../../src/process/ProviderProcess.js"; +import { OwnedCommandFailure } from "../../src/process/OwnedCommand.js"; +import type { + ProviderProcessHandle, + ProviderProcessSnapshot, +} from "../../src/process/ProviderProcess.js"; import { testWaitDeadline } from "../support/testWait.js"; const fixturePath = fileURLToPath( @@ -114,3 +118,30 @@ export const stopProviderProcessFixture = async ( child.kill("SIGKILL"); await exited; }; + +/** Build an owned-process snapshot with a complete V8 heap diagnostic. */ +export const v8HeapExhaustionFailure = ( + message: string, + stderr: string, + termination: Pick = { + exitCode: null, + signal: "SIGABRT", + }, +): OwnedCommandFailure => { + const bytes = Buffer.byteLength(stderr); + return new OwnedCommandFailure("process", message, { + stdout: { text: "", bytes: 0, observedBytes: 0 }, + stderr: { text: stderr, bytes, observedBytes: bytes }, + exitCode: termination.exitCode, + signal: termination.signal, + runtimeExhaustion: { + runtime: "v8", + area: "heap", + stream: "stderr", + line: stderr.trim(), + lineComplete: true, + truncated: false, + invalidUtf8: false, + }, + }); +};