@powerhousedao/switchboard 6.2.3-dev.8 → 6.2.3-dev.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.tsbuild/test/attachments/byte-grants.test.d.ts +2 -0
- package/.tsbuild/test/attachments/byte-grants.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts +2 -0
- package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts +2 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/url-signer.test.d.ts +2 -0
- package/.tsbuild/test/attachments/url-signer.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts +2 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-create-signature-policy.test.d.ts +2 -0
- package/.tsbuild/test/boot-create-signature-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts +2 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-helpers.d.ts +5 -0
- package/.tsbuild/test/boot-helpers.d.ts.map +1 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-mcp-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-mcp-auth.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-mcp-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-mcp-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-port-zero.test.d.ts +2 -0
- package/.tsbuild/test/boot-port-zero.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts +2 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-privacy.test.d.ts +2 -0
- package/.tsbuild/test/boot-privacy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts +2 -0
- package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-without-renown.test.d.ts +2 -0
- package/.tsbuild/test/boot-without-renown.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-without-require-signatures.test.d.ts +2 -0
- package/.tsbuild/test/boot-without-require-signatures.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-worker-trust-policy.test.d.ts +2 -0
- package/.tsbuild/test/boot-worker-trust-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts.map +1 -0
- package/.tsbuild/test/builder-defaults.test.d.ts +2 -0
- package/.tsbuild/test/builder-defaults.test.d.ts.map +1 -0
- package/.tsbuild/test/config-from-env.test.d.ts +2 -0
- package/.tsbuild/test/config-from-env.test.d.ts.map +1 -0
- package/.tsbuild/test/config-merge.test.d.ts +2 -0
- package/.tsbuild/test/config-merge.test.d.ts.map +1 -0
- package/.tsbuild/test/config-schema.test.d.ts +2 -0
- package/.tsbuild/test/config-schema.test.d.ts.map +1 -0
- package/.tsbuild/test/create-signature-policy.test.d.ts +2 -0
- package/.tsbuild/test/create-signature-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts +2 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts.map +1 -0
- package/.tsbuild/test/fatal-shutdown.test.d.ts +2 -0
- package/.tsbuild/test/fatal-shutdown.test.d.ts.map +1 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts +2 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
- package/.tsbuild/test/observability-signals.test.d.ts +2 -0
- package/.tsbuild/test/observability-signals.test.d.ts.map +1 -0
- package/.tsbuild/test/permissions-backfill.test.d.ts +2 -0
- package/.tsbuild/test/permissions-backfill.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts +2 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts +2 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-store.test.d.ts +2 -0
- package/.tsbuild/test/pglite-store.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
- package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
- package/.tsbuild/test/port-probe.test.d.ts +2 -0
- package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts.map +1 -0
- package/.tsbuild/test/renown-trust-policy.test.d.ts +2 -0
- package/.tsbuild/test/renown-trust-policy.test.d.ts.map +1 -0
- package/.tsbuild/test/served-schemas.test.d.ts +2 -0
- package/.tsbuild/test/served-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/shutdown.test.d.ts +2 -0
- package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
- package/.tsbuild/test/snapshot-writer.d.ts +18 -0
- package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
- package/.tsbuild/test/store-lock.test.d.ts +2 -0
- package/.tsbuild/test/store-lock.test.d.ts.map +1 -0
- package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
- package/.tsbuild/test/two-switchboards.test.d.ts.map +1 -0
- package/.tsbuild/test/unsupported-stored-documents.test.d.ts +2 -0
- package/.tsbuild/test/unsupported-stored-documents.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/harness.d.ts +56 -0
- package/.tsbuild/test/workflow/harness.d.ts.map +1 -0
- package/.tsbuild/test/workflow/oauth.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/resolvers.test.d.ts +2 -0
- package/.tsbuild/test/workflow/resolvers.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/runtime-host.test.d.ts +2 -0
- package/.tsbuild/test/workflow/runtime-host.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-signed.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-signed.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts +2 -0
- package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-reactor-access.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-read-gate.test.d.ts +2 -0
- package/.tsbuild/test/workflow-read-gate.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-runtime.test.d.ts +2 -0
- package/.tsbuild/test/workflow-runtime.test.d.ts.map +1 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/.tsbuild/tsdown.config.d.ts.map +1 -1
- package/.tsbuild/vitest.config.d.ts.map +1 -1
- package/Auth.md +144 -2
- package/CHANGELOG.md +1074 -0
- package/README.md +55 -14
- package/dist/boot.d.mts +46 -0
- package/dist/boot.d.mts.map +1 -0
- package/dist/boot.mjs +67 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/config/from-env.d.mts +15 -0
- package/dist/config/from-env.d.mts.map +1 -0
- package/dist/config/from-env.mjs +4 -0
- package/dist/config/schema.d.mts +3 -0
- package/dist/config/schema.mjs +4 -0
- package/dist/from-env-BO0n9R02.mjs +401 -0
- package/dist/from-env-BO0n9R02.mjs.map +1 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +76 -79
- package/dist/index.mjs.map +1 -1
- package/dist/install-packages.d.mts +2 -1
- package/dist/install-packages.mjs +2 -2
- package/dist/install-packages.mjs.map +1 -1
- package/dist/mcp-SsBK14Jm.mjs +32 -0
- package/dist/mcp-SsBK14Jm.mjs.map +1 -0
- package/dist/migrate.d.mts +2 -1
- package/dist/migrate.mjs +7 -5
- package/dist/migrate.mjs.map +1 -1
- package/dist/plugin-host-C1sYEm8g.d.mts +46 -0
- package/dist/plugin-host-C1sYEm8g.d.mts.map +1 -0
- package/dist/plugins/attachments.d.mts +33 -0
- package/dist/plugins/attachments.d.mts.map +1 -0
- package/dist/plugins/attachments.mjs +4 -0
- package/dist/plugins/mcp.d.mts +31 -0
- package/dist/plugins/mcp.d.mts.map +1 -0
- package/dist/plugins/mcp.mjs +4 -0
- package/dist/plugins/privacy.d.mts +22 -0
- package/dist/plugins/privacy.d.mts.map +1 -0
- package/dist/plugins/privacy.mjs +4 -0
- package/dist/plugins/workflows.d.mts +79 -0
- package/dist/plugins/workflows.d.mts.map +1 -0
- package/dist/plugins/workflows.mjs +4 -0
- package/dist/postgres-url-DTDhBjXX.mjs +11 -0
- package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
- package/dist/privacy-BO8Q25xI.mjs +44 -0
- package/dist/privacy-BO8Q25xI.mjs.map +1 -0
- package/dist/privacy-DxIJGH4P.mjs +91 -0
- package/dist/privacy-DxIJGH4P.mjs.map +1 -0
- package/dist/renown-layers-COZsrGQT.mjs +40 -0
- package/dist/renown-layers-COZsrGQT.mjs.map +1 -0
- package/dist/schema-0g_QdOWn.mjs +267 -0
- package/dist/schema-0g_QdOWn.mjs.map +1 -0
- package/dist/schema-ivUWPQOn.d.mts +202 -0
- package/dist/schema-ivUWPQOn.d.mts.map +1 -0
- package/dist/server-cE1BWLQu.mjs +2518 -0
- package/dist/server-cE1BWLQu.mjs.map +1 -0
- package/dist/server.d.mts +270 -48
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +5 -5
- package/dist/utils-C6AIF38Z.mjs +133 -0
- package/dist/utils-C6AIF38Z.mjs.map +1 -0
- package/dist/utils.d.mts +12 -5
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +4 -3
- package/dist/worker-pool-BWHBLBJd.mjs +304 -0
- package/dist/worker-pool-BWHBLBJd.mjs.map +1 -0
- package/dist/workflow-runtime-7GaJ13c9.d.mts +30 -0
- package/dist/workflow-runtime-7GaJ13c9.d.mts.map +1 -0
- package/dist/workflows-COM3MKfD.mjs +1437 -0
- package/dist/workflows-COM3MKfD.mjs.map +1 -0
- package/package.json +68 -23
- package/scripts/install-packages.sh +0 -0
- package/test/attachment-reference-read-model.test.ts +28 -20
- package/test/attachments/auth.test.ts +85 -0
- package/test/attachments/byte-grants.test.ts +290 -0
- package/test/attachments/byte-routes-read-gate.integration.test.ts +314 -0
- package/test/attachments/download-target.test.ts +211 -32
- package/test/attachments/index.test.ts +47 -4
- package/test/attachments/reserve-metadata-parity.test.ts +96 -0
- package/test/attachments/routes-integration.test.ts +60 -4
- package/test/attachments/routes.test.ts +297 -35
- package/test/attachments/service-config.test.ts +41 -19
- package/test/attachments/url-signer.test.ts +105 -0
- package/test/boot-auth-config.test.ts +109 -0
- package/test/boot-create-signature-policy.test.ts +110 -0
- package/test/boot-env-isolation.test.ts +26 -0
- package/test/boot-helpers.ts +19 -0
- package/test/boot-inspection-enabled.test.ts +140 -0
- package/test/boot-mcp-auth.test.ts +449 -0
- package/test/boot-mcp-enabled.test.ts +119 -0
- package/test/boot-port-zero.test.ts +101 -0
- package/test/boot-preconditions.test.ts +200 -0
- package/test/boot-privacy.test.ts +232 -0
- package/test/boot-unsupported-stored-documents.test.ts +214 -0
- package/test/boot-without-renown.test.ts +83 -0
- package/test/boot-without-require-signatures.test.ts +76 -0
- package/test/boot-worker-trust-policy.test.ts +91 -0
- package/test/boot-workflow-singleton-conflict.test.ts +109 -0
- package/test/boot-workflow-singleton-retry.test.ts +122 -0
- package/test/builder-defaults.test.ts +80 -0
- package/test/config-from-env.test.ts +758 -0
- package/test/config-merge.test.ts +215 -0
- package/test/config-schema.test.ts +128 -0
- package/test/create-signature-policy.test.ts +69 -0
- package/test/default-drive-protocol-versions.test.ts +102 -0
- package/test/default-drive-slug.test.ts +97 -0
- package/test/durable-node-fs-pg16.test.ts +80 -0
- package/test/fatal-shutdown.test.ts +165 -0
- package/test/goldens/packages.graphql +797 -0
- package/test/goldens/privacy.graphql +853 -0
- package/test/goldens/reactor-drive-nodes.graphql +827 -0
- package/test/goldens/resolvers.json +322 -0
- package/test/goldens/supergraph.graphql +5652 -0
- package/test/goldens/workflow-runtime.graphql +1419 -0
- package/test/inspection-throttle.test.ts +23 -0
- package/test/observability-signals.test.ts +131 -0
- package/test/permissions-backfill.test.ts +486 -0
- package/test/pglite-dialect.test.ts +237 -2
- package/test/pglite-preflight.test.ts +313 -0
- package/test/pglite-storage-dirs.test.ts +113 -0
- package/test/pglite-store.test.ts +264 -0
- package/test/pglite-version.test.ts +9 -1
- package/test/plugin-config-schemas.test.ts +83 -0
- package/test/plugin-presence.test.ts +262 -0
- package/test/port-probe.test.ts +45 -0
- package/test/renown-storage-path.test.ts +40 -0
- package/test/renown-trust-policy.test.ts +313 -0
- package/test/served-schemas.test.ts +134 -0
- package/test/shutdown.test.ts +278 -0
- package/test/snapshot-writer.ts +94 -0
- package/test/store-lock.test.ts +65 -0
- package/test/two-switchboards.test.ts +146 -0
- package/test/unsupported-stored-documents.test.ts +72 -0
- package/test/worker-pool.test.ts +27 -1
- package/test/workflow/harness.ts +289 -0
- package/test/workflow/oauth.test.ts +205 -0
- package/test/workflow/resolvers.test.ts +369 -0
- package/test/workflow/runtime-host.test.ts +19 -0
- package/test/workflow/webhook-dedupe.test.ts +295 -0
- package/test/workflow/webhook-signed.test.ts +509 -0
- package/test/workflow/webhook-trigger-test.test.ts +82 -0
- package/test/workflow/webhook-unsigned.test.ts +345 -0
- package/test/workflow-reactor-access.test.ts +384 -0
- package/test/workflow-reactor-enforcement.test.ts +808 -0
- package/test/workflow-read-gate.test.ts +213 -0
- package/test/workflow-runtime.test.ts +1135 -0
- package/test/workflows-plugin-config.test.ts +77 -0
- package/tsconfig.json +11 -2
- package/tsdown.config.ts +12 -1
- package/vitest.config.ts +65 -0
- package/dist/server-CiKkVE6g.mjs +0 -1555
- package/dist/server-CiKkVE6g.mjs.map +0 -1
- package/dist/utils-Baw7rThP.mjs +0 -80
- package/dist/utils-Baw7rThP.mjs.map +0 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
installFatalErrorShutdown,
|
|
5
|
+
triggerFatalShutdown,
|
|
6
|
+
} from "../src/fatal-shutdown.mjs";
|
|
7
|
+
|
|
8
|
+
function makeProc() {
|
|
9
|
+
const emitter = new EventEmitter();
|
|
10
|
+
const proc = Object.assign(emitter, {
|
|
11
|
+
pid: 1234,
|
|
12
|
+
exitCode: undefined as number | undefined,
|
|
13
|
+
kill: vi.fn((_pid: number, signal: string) => {
|
|
14
|
+
emitter.emit(signal);
|
|
15
|
+
return true;
|
|
16
|
+
}),
|
|
17
|
+
exit: vi.fn(),
|
|
18
|
+
});
|
|
19
|
+
return proc;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const logger = {
|
|
23
|
+
error: vi.fn(),
|
|
24
|
+
} as unknown as Parameters<typeof installFatalErrorShutdown>[0];
|
|
25
|
+
|
|
26
|
+
describe("installFatalErrorShutdown", () => {
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
vi.useRealTimers();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it.each(["uncaughtException", "unhandledRejection"])(
|
|
32
|
+
"routes %s through SIGTERM with exit code 1",
|
|
33
|
+
(event) => {
|
|
34
|
+
const proc = makeProc();
|
|
35
|
+
const onSigterm = vi.fn();
|
|
36
|
+
proc.on("SIGTERM", onSigterm);
|
|
37
|
+
installFatalErrorShutdown(logger, proc as never);
|
|
38
|
+
|
|
39
|
+
proc.emit(event, new Error("boom"));
|
|
40
|
+
|
|
41
|
+
expect(proc.kill).toHaveBeenCalledWith(1234, "SIGTERM");
|
|
42
|
+
expect(onSigterm).toHaveBeenCalledOnce();
|
|
43
|
+
expect(proc.exitCode).toBe(1);
|
|
44
|
+
expect(proc.exit).not.toHaveBeenCalled();
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
it("leaves an unhandled rejection to another listener, such as Sentry's", () => {
|
|
49
|
+
const proc = makeProc();
|
|
50
|
+
const other = vi.fn();
|
|
51
|
+
proc.on("unhandledRejection", other);
|
|
52
|
+
installFatalErrorShutdown(logger, proc as never);
|
|
53
|
+
|
|
54
|
+
proc.emit("unhandledRejection", new Error("boom"));
|
|
55
|
+
|
|
56
|
+
expect(other).toHaveBeenCalledOnce();
|
|
57
|
+
expect(proc.kill).not.toHaveBeenCalled();
|
|
58
|
+
expect(proc.exitCode).toBeUndefined();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("still shuts down on an uncaught exception when another listener exists", () => {
|
|
62
|
+
const proc = makeProc();
|
|
63
|
+
proc.on("uncaughtException", vi.fn());
|
|
64
|
+
installFatalErrorShutdown(logger, proc as never);
|
|
65
|
+
|
|
66
|
+
proc.emit("uncaughtException", new Error("boom"));
|
|
67
|
+
|
|
68
|
+
expect(proc.kill).toHaveBeenCalledWith(1234, "SIGTERM");
|
|
69
|
+
expect(proc.exitCode).toBe(1);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("signals once when a second fatal error arrives during shutdown", () => {
|
|
73
|
+
const proc = makeProc();
|
|
74
|
+
installFatalErrorShutdown(logger, proc as never);
|
|
75
|
+
|
|
76
|
+
proc.emit("unhandledRejection", new Error("first"));
|
|
77
|
+
proc.emit("uncaughtException", new Error("second"));
|
|
78
|
+
|
|
79
|
+
expect(proc.kill).toHaveBeenCalledOnce();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("forces exit 1 through the original exit when shutdown hangs", () => {
|
|
83
|
+
vi.useFakeTimers();
|
|
84
|
+
const proc = makeProc();
|
|
85
|
+
const originalExit = proc.exit;
|
|
86
|
+
installFatalErrorShutdown(logger, proc as never);
|
|
87
|
+
// The builder swaps process.exit for a recording shim during shutdown.
|
|
88
|
+
proc.exit = vi.fn();
|
|
89
|
+
|
|
90
|
+
proc.emit("unhandledRejection", new Error("boom"));
|
|
91
|
+
vi.advanceTimersByTime(15_000);
|
|
92
|
+
|
|
93
|
+
expect(originalExit).toHaveBeenCalledWith(1);
|
|
94
|
+
expect(proc.exit).not.toHaveBeenCalled();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("still reaches exit when the logger itself throws EPIPE inside onFatal", () => {
|
|
98
|
+
vi.useFakeTimers();
|
|
99
|
+
const proc = makeProc();
|
|
100
|
+
const onSigterm = vi.fn();
|
|
101
|
+
proc.on("SIGTERM", onSigterm);
|
|
102
|
+
const error = vi.fn(() => {
|
|
103
|
+
throw Object.assign(new Error("write EPIPE"), { code: "EPIPE" });
|
|
104
|
+
});
|
|
105
|
+
const throwingLogger = { error } as unknown as Parameters<
|
|
106
|
+
typeof installFatalErrorShutdown
|
|
107
|
+
>[0];
|
|
108
|
+
installFatalErrorShutdown(throwingLogger, proc as never);
|
|
109
|
+
|
|
110
|
+
// Without the guard the EPIPE propagates out of the uncaughtException
|
|
111
|
+
// listener, which in a real process re-enters fatal handling instead of
|
|
112
|
+
// running the shutdown.
|
|
113
|
+
expect(() =>
|
|
114
|
+
proc.emit("uncaughtException", new Error("boom")),
|
|
115
|
+
).not.toThrow();
|
|
116
|
+
|
|
117
|
+
expect(proc.kill).toHaveBeenCalledOnce();
|
|
118
|
+
expect(onSigterm).toHaveBeenCalledOnce();
|
|
119
|
+
expect(proc.exitCode).toBe(1);
|
|
120
|
+
|
|
121
|
+
vi.advanceTimersByTime(15_000);
|
|
122
|
+
|
|
123
|
+
expect(proc.exit).toHaveBeenCalledTimes(1);
|
|
124
|
+
expect(proc.exit).toHaveBeenCalledWith(1);
|
|
125
|
+
// Exactly the two guarded log attempts: the fatal report and the
|
|
126
|
+
// forced-exit notice. A re-entered handler would log again.
|
|
127
|
+
expect(error).toHaveBeenCalledTimes(2);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("routes a triggered fatal error through SIGTERM with exit code 1", () => {
|
|
131
|
+
const proc = makeProc();
|
|
132
|
+
const onSigterm = vi.fn();
|
|
133
|
+
proc.on("SIGTERM", onSigterm);
|
|
134
|
+
installFatalErrorShutdown(logger, proc as never);
|
|
135
|
+
|
|
136
|
+
expect(
|
|
137
|
+
triggerFatalShutdown("Flush failed", new Error("ENOSPC"), proc as never),
|
|
138
|
+
).toBe(true);
|
|
139
|
+
triggerFatalShutdown("Flush failed", new Error("ENOSPC"), proc as never);
|
|
140
|
+
proc.emit("uncaughtException", new Error("later"));
|
|
141
|
+
|
|
142
|
+
expect(proc.kill).toHaveBeenCalledOnce();
|
|
143
|
+
expect(onSigterm).toHaveBeenCalledOnce();
|
|
144
|
+
expect(proc.exitCode).toBe(1);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("ignores a trigger when shutdown on fatal errors is not installed", () => {
|
|
148
|
+
const proc = makeProc();
|
|
149
|
+
|
|
150
|
+
expect(
|
|
151
|
+
triggerFatalShutdown("Flush failed", new Error("ENOSPC"), proc as never),
|
|
152
|
+
).toBe(false);
|
|
153
|
+
expect(proc.kill).not.toHaveBeenCalled();
|
|
154
|
+
expect(proc.exitCode).toBeUndefined();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("installs its listeners once per process", () => {
|
|
158
|
+
const proc = makeProc();
|
|
159
|
+
installFatalErrorShutdown(logger, proc as never);
|
|
160
|
+
installFatalErrorShutdown(logger, proc as never);
|
|
161
|
+
|
|
162
|
+
expect(proc.listenerCount("uncaughtException")).toBe(1);
|
|
163
|
+
expect(proc.listenerCount("unhandledRejection")).toBe(1);
|
|
164
|
+
});
|
|
165
|
+
});
|