mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
* fix(process): classify every launcher failure once by errno in the shared launch owner * fix(process): keep the launch owner's syscall, cause and facts in RE and pwntools unavailable reports
224 lines
7.8 KiB
TypeScript
224 lines
7.8 KiB
TypeScript
import { SqliteDatabaseProvider } from "../../../src/sqlite/SqliteDatabaseProvider.js";
|
|
import { createSqliteDatabaseFixture } from "../../fixtures/sqlite/database.js";
|
|
import { spawnFailure } from "../../support/process/spawnFailure.js";
|
|
import {
|
|
createTestWorkspace,
|
|
removeTestWorkspace,
|
|
} from "../../support/workspace/workspaceFixture.js";
|
|
import { ArtifactReaderFailure } from "../../../src/resources/ArtifactReader.js";
|
|
import { classifyProviderFailure } from "../../../src/providers/classifyProviderFailure.js";
|
|
import { expect, it, onTestFinished } from "vitest";
|
|
import { OwnedCommandFailure } from "../../../src/process/OwnedCommand.js";
|
|
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
|
import { sqliteDatabaseDialect } from "../../../src/sqlite/SqliteDatabaseFailures.js";
|
|
import { SQLITE_DATABASE_LIMITS } from "../../../src/sqlite/SqliteDatabaseLimits.js";
|
|
import { releaseOwnedCleanup } from "../../support/cleanupRelease.js";
|
|
|
|
it.each([null, "owned stop unconfirmed"])(
|
|
"preserves a selected worker deadline with cleanup=%s",
|
|
(cleanup) => {
|
|
const cause = new OwnedCommandFailure(
|
|
"timeout",
|
|
"Command deadline elapsed.",
|
|
{
|
|
stdout: { text: "partial-owned-output", bytes: 20, observedBytes: 20 },
|
|
stderr: { text: "", bytes: 0, observedBytes: 0 },
|
|
exitCode: null,
|
|
signal: null,
|
|
},
|
|
cleanup,
|
|
undefined,
|
|
["pid:owned-fixture"],
|
|
);
|
|
const failure = classifyProviderFailure(
|
|
cause,
|
|
sqliteDatabaseDialect("/selected.db", "worker", undefined, 1234),
|
|
);
|
|
expect(failure.cause).toBe(cause);
|
|
const projected = projectAnalysisError(failure);
|
|
if (cleanup === null)
|
|
expect(projected).toMatchObject({
|
|
code: "provider_timeout",
|
|
details: {
|
|
timeout_ms: 1234,
|
|
limit: {
|
|
control_kind: "parameter",
|
|
parameter: "worker_timeout_ms",
|
|
effective_value: 1234,
|
|
},
|
|
},
|
|
remediation: {
|
|
action: expect.not.stringContaining("--"),
|
|
},
|
|
});
|
|
else
|
|
expect(projected).toMatchObject({
|
|
code: "cleanup_incomplete",
|
|
retryable: false,
|
|
details: {
|
|
resources: ["pid:owned-fixture"],
|
|
diagnostics: {
|
|
previous_error: {
|
|
code: "provider_timeout",
|
|
details: { timeout_ms: 1234 },
|
|
remediation: {
|
|
action: expect.stringContaining("worker_timeout_ms"),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
expect(
|
|
JSON.stringify(projected).split("partial-owned-output"),
|
|
).toHaveLength(2);
|
|
if (cleanup !== null) {
|
|
expect(failure.cleanupPrimary).toMatchObject({
|
|
_tag: "AnalysisTimeoutError",
|
|
timeoutMs: 1234,
|
|
});
|
|
releaseOwnedCleanup(failure);
|
|
const resolved = projectAnalysisError(failure);
|
|
expect(resolved).toMatchObject({
|
|
code: "provider_timeout",
|
|
details: { timeout_ms: 1234 },
|
|
});
|
|
expect(
|
|
JSON.stringify(resolved).split("partial-owned-output"),
|
|
).toHaveLength(2);
|
|
}
|
|
},
|
|
);
|
|
|
|
it("does not recommend a timer above the supported maximum", () => {
|
|
const failure = projectAnalysisError(
|
|
classifyProviderFailure(
|
|
new OwnedCommandFailure("timeout", "deadline"),
|
|
sqliteDatabaseDialect("/selected.db", "worker", undefined, 2_147_483_647),
|
|
),
|
|
);
|
|
expect(failure.details).toMatchObject({ timeout_ms: 2_147_483_647 });
|
|
expect(failure.remediation.action).toContain("no higher worker deadline");
|
|
expect(failure.remediation.action).not.toContain("Increase");
|
|
});
|
|
|
|
it("says diagnostic capture has no runtime override", () => {
|
|
const projected = projectAnalysisError(
|
|
classifyProviderFailure(
|
|
new OwnedCommandFailure("output-limit", "diagnostics exceeded"),
|
|
sqliteDatabaseDialect("/selected.db", "worker"),
|
|
),
|
|
);
|
|
expect(projected.remediation.action).toContain(
|
|
String(SQLITE_DATABASE_LIMITS.diagnosticBytes),
|
|
);
|
|
expect(projected.remediation.action).toContain("no runtime override");
|
|
expect(projected.remediation.action).toContain(
|
|
"worker_timeout_ms does not raise it",
|
|
);
|
|
});
|
|
|
|
it.each(["/selected.db", "./Database files/another.db"])(
|
|
"retains the caller-selected path %s when the owned worker reports V8 heap exhaustion",
|
|
(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 failure = classifyProviderFailure(
|
|
cause,
|
|
sqliteDatabaseDialect(path, "worker"),
|
|
);
|
|
expect(failure.cause).toBe(cause);
|
|
expect(projectAnalysisError(failure)).toMatchObject({
|
|
code: "resource_constraint",
|
|
details: {
|
|
operation: "inspect_sqlite_database",
|
|
resource: "memory",
|
|
reported_limits: { javascript_heap_bytes: 256 * 1024 * 1024 },
|
|
diagnostics: {
|
|
selected_path: path,
|
|
// The runtime's report survives even when retention dropped it.
|
|
runtime_exhaustion_report: {
|
|
runtime: "v8",
|
|
area: "heap",
|
|
stream: "stderr",
|
|
line: stderr.trim(),
|
|
line_complete: true,
|
|
},
|
|
},
|
|
captured_output: { stderr },
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
it("does not infer cancellation from a later signal when cleanup carries no cancellation fact", () => {
|
|
const controller = new AbortController();
|
|
const cause = new ArtifactReaderFailure("io", "cleanup remains owned", {
|
|
cleanup: { reason: "close failed", resources: ["/owned/reply.json"] },
|
|
});
|
|
controller.abort(new Error("later caller cancellation"));
|
|
const failure = classifyProviderFailure(
|
|
cause,
|
|
sqliteDatabaseDialect("/selected.db", "worker", controller.signal),
|
|
);
|
|
expect(failure.cleanupIncomplete).toBe(true);
|
|
expect(failure.cleanupPrimary).toBeUndefined();
|
|
expect(projectAnalysisError(failure)).toMatchObject({
|
|
code: "cleanup_incomplete",
|
|
details: { resources: ["/owned/reply.json"] },
|
|
});
|
|
});
|
|
|
|
// A worker launch failure reaches the shared launch owner even though the
|
|
// SQLite dialect describes no command reports.
|
|
it.each([
|
|
["EAGAIN", "resource_constraint", { resource: "capacity" }],
|
|
["E2BIG", "resource_constraint", { resource: "transport" }],
|
|
["EIO", "capability_unavailable", { provider_id: "sqlite" }],
|
|
] as const)(
|
|
"classifies a SQLite worker launch failure %s once by errno",
|
|
async (code, projectedCode, details) => {
|
|
const workspace = await createTestWorkspace("rea-sqlite-launch-");
|
|
onTestFinished(() => removeTestWorkspace(workspace.root));
|
|
const database = createSqliteDatabaseFixture(workspace.root);
|
|
database.close();
|
|
const provider = new SqliteDatabaseProvider({}, async (input) => {
|
|
throw spawnFailure(code, input.command);
|
|
});
|
|
onTestFinished(() => provider.close());
|
|
const result = await provider.inspect({ path: database.path });
|
|
if (result.ok) throw new Error("Expected the worker launch to fail");
|
|
const projected = projectAnalysisError(result.error);
|
|
expect(projected).toMatchObject({
|
|
code: projectedCode,
|
|
details: {
|
|
...details,
|
|
diagnostics: {
|
|
system_code: code,
|
|
syscall: `spawn ${process.execPath}`,
|
|
},
|
|
},
|
|
});
|
|
expect(projected.message).toContain(code);
|
|
expect((await provider.inspect({ path: database.path })).ok).toBe(false);
|
|
},
|
|
);
|