@powerhousedao/switchboard 6.2.3-staging.0 → 6.3.0-dev.1
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/ai-gateway.test.d.ts +2 -0
- package/.tsbuild/test/ai-gateway.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/boot-auth-config.test.d.ts +2 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-desktop-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-desktop-auth.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-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-ready-drives.test.d.ts +2 -0
- package/.tsbuild/test/boot-ready-drives.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-undo-v3-flag.test.d.ts +2 -0
- package/.tsbuild/test/boot-undo-v3-flag.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/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/default-composition.test.d.ts +2 -0
- package/.tsbuild/test/default-composition.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/delegated-publish.test.d.ts +2 -0
- package/.tsbuild/test/delegated-publish.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/fixtures/mixed-subgraphs/subgraphs/greetings/index.d.ts +13 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.d.ts.map +1 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/index.d.ts +3 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/index.d.ts.map +1 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/tally/index.d.ts +7 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/tally/index.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/keyframe-reclaim-store.test.d.ts +2 -0
- package/.tsbuild/test/keyframe-reclaim-store.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/processor-timing-log.test.d.ts +2 -0
- package/.tsbuild/test/processor-timing-log.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/served-schemas-mixed-package.test.d.ts +2 -0
- package/.tsbuild/test/served-schemas-mixed-package.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/workflow/oauth-apps-config.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth-apps-config.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/waitpoint-routes.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.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/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/Auth.md +108 -2
- package/CHANGELOG.md +1065 -1
- package/README.md +69 -24
- 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-DKK_wPrO.mjs +497 -0
- package/dist/from-env-DKK_wPrO.mjs.map +1 -0
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +40 -219
- package/dist/index.mjs.map +1 -1
- package/dist/mcp-VW52B8KD.mjs +32 -0
- package/dist/mcp-VW52B8KD.mjs.map +1 -0
- package/dist/migrate.mjs +5 -4
- package/dist/migrate.mjs.map +1 -1
- package/dist/observability-CldagyT_.mjs +224 -0
- package/dist/observability-CldagyT_.mjs.map +1 -0
- package/dist/observability.d.mts +30 -0
- package/dist/observability.d.mts.map +1 -0
- package/dist/observability.mjs +4 -0
- package/dist/plugin-host-tTjDTNz0.d.mts +46 -0
- package/dist/plugin-host-tTjDTNz0.d.mts.map +1 -0
- package/dist/plugins/ai.d.mts +37 -0
- package/dist/plugins/ai.d.mts.map +1 -0
- package/dist/plugins/ai.mjs +400 -0
- package/dist/plugins/ai.mjs.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 +80 -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-HQnhqf2H.mjs +91 -0
- package/dist/privacy-HQnhqf2H.mjs.map +1 -0
- package/dist/privacy-UodgY0i_.mjs +44 -0
- package/dist/privacy-UodgY0i_.mjs.map +1 -0
- package/dist/renown-layers-DmbWLt46.mjs +42 -0
- package/dist/renown-layers-DmbWLt46.mjs.map +1 -0
- package/dist/schema-BJ-OFAox.mjs +359 -0
- package/dist/schema-BJ-OFAox.mjs.map +1 -0
- package/dist/schema-w1lShimw.d.mts +258 -0
- package/dist/schema-w1lShimw.d.mts.map +1 -0
- package/dist/server-BS-PFzoK.mjs +2752 -0
- package/dist/server-BS-PFzoK.mjs.map +1 -0
- package/dist/server.d.mts +94 -228
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +5 -4
- package/dist/types-Bk4T4D9F.d.mts +318 -0
- package/dist/types-Bk4T4D9F.d.mts.map +1 -0
- package/dist/utils-Cm0TE6dP.mjs +148 -0
- package/dist/utils-Cm0TE6dP.mjs.map +1 -0
- package/dist/utils.d.mts +29 -3
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +5 -4
- package/dist/worker-pool-gyxJnCxA.mjs +304 -0
- package/dist/worker-pool-gyxJnCxA.mjs.map +1 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts +33 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts.map +1 -0
- package/dist/workflows-mdYUh3Us.mjs +1947 -0
- package/dist/workflows-mdYUh3Us.mjs.map +1 -0
- package/package.json +86 -24
- package/scripts/install-packages.sh +0 -0
- package/test/ai-gateway.test.ts +612 -0
- package/test/attachment-reference-read-model.test.ts +28 -20
- package/test/attachments/byte-grants.test.ts +4 -1
- package/test/attachments/download-target.test.ts +36 -20
- package/test/attachments/index.test.ts +13 -1
- package/test/attachments/reserve-metadata-parity.test.ts +96 -0
- package/test/attachments/routes-integration.test.ts +1 -0
- package/test/attachments/routes.test.ts +132 -12
- package/test/attachments/service-config.test.ts +28 -16
- package/test/boot-auth-config.test.ts +146 -0
- package/test/boot-create-signature-policy.test.ts +15 -13
- package/test/boot-desktop-auth.test.ts +278 -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 +27 -27
- package/test/boot-port-zero.test.ts +101 -0
- package/test/boot-preconditions.test.ts +213 -0
- package/test/boot-privacy.test.ts +232 -0
- package/test/boot-ready-drives.test.ts +141 -0
- package/test/boot-undo-v3-flag.test.ts +120 -0
- package/test/boot-unsupported-stored-documents.test.ts +23 -19
- package/test/boot-without-renown.test.ts +11 -9
- package/test/boot-without-require-signatures.test.ts +12 -10
- package/test/boot-worker-trust-policy.test.ts +11 -10
- package/test/boot-workflow-singleton-conflict.test.ts +109 -0
- package/test/boot-workflow-singleton-retry.test.ts +122 -0
- package/test/config-from-env.test.ts +968 -0
- package/test/config-merge.test.ts +351 -0
- package/test/config-schema.test.ts +183 -0
- package/test/default-composition.test.ts +290 -0
- package/test/default-drive-protocol-versions.test.ts +79 -0
- package/test/default-drive-slug.test.ts +265 -0
- package/test/delegated-publish.test.ts +435 -0
- package/test/durable-node-fs-pg16.test.ts +80 -0
- package/test/fatal-shutdown.test.ts +104 -1
- package/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.ts +16 -0
- package/test/fixtures/mixed-subgraphs/subgraphs/index.ts +3 -0
- package/test/fixtures/mixed-subgraphs/subgraphs/tally/index.ts +73 -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 +327 -0
- package/test/goldens/supergraph.graphql +5918 -0
- package/test/goldens/workflow-runtime.graphql +1548 -0
- package/test/inspection-throttle.test.ts +23 -0
- package/test/keyframe-reclaim-store.test.ts +156 -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 +441 -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/processor-timing-log.test.ts +109 -0
- package/test/reactor-feature-flags.test.ts +20 -0
- package/test/redact-webhook-path.test.ts +9 -0
- package/test/renown-storage-path.test.ts +40 -0
- package/test/renown-trust-policy.test.ts +7 -9
- package/test/served-schemas-mixed-package.test.ts +251 -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/worker-pool.test.ts +27 -1
- package/test/workflow/oauth-apps-config.test.ts +66 -0
- package/test/workflow/oauth.test.ts +82 -10
- package/test/workflow/resolvers.test.ts +230 -38
- package/test/workflow/runtime-host.test.ts +19 -0
- package/test/workflow/waitpoint-routes.test.ts +306 -0
- package/test/workflow/waitpoint-runtime.test.ts +204 -0
- package/test/workflow/webhook-trigger-test.test.ts +8 -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 +128 -60
- package/test/workflow-runtime.test.ts +1005 -237
- package/test/workflows-plugin-config.test.ts +77 -0
- package/tsconfig.json +5 -2
- package/tsdown.config.ts +12 -0
- package/vitest.config.ts +66 -1
- package/.tsbuild/test/mcp-flag.test.d.ts +0 -2
- package/.tsbuild/test/mcp-flag.test.d.ts.map +0 -1
- package/dist/server-sQoWp21G.mjs +0 -2939
- package/dist/server-sQoWp21G.mjs.map +0 -1
- package/dist/utils-uaBlzyjS.mjs +0 -86
- package/dist/utils-uaBlzyjS.mjs.map +0 -1
- package/test/mcp-flag.test.ts +0 -56
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
-
import {
|
|
2
|
+
import { NodeFS } from "@electric-sql/pglite/nodefs";
|
|
3
3
|
import {
|
|
4
4
|
JobStatus,
|
|
5
5
|
ReactorBuilder,
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
vi,
|
|
27
27
|
} from "vitest";
|
|
28
28
|
import { ClosablePGliteDialect } from "../src/pglite-dialect.js";
|
|
29
|
-
import {
|
|
29
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
30
30
|
import { StoredDocumentsRefusedError } from "../src/unsupported-stored-documents.mjs";
|
|
31
31
|
|
|
32
32
|
const ENV_KEYS = [
|
|
@@ -65,9 +65,7 @@ function stubLogger(): StubLogger {
|
|
|
65
65
|
/** A reactor store holding one drive created at base-reducer 7. */
|
|
66
66
|
async function seedStore(dir: string): Promise<void> {
|
|
67
67
|
const db = new Kysely<Database>({
|
|
68
|
-
dialect: new ClosablePGliteDialect(
|
|
69
|
-
new PGlite({ fs: new AtomicNodeFs(dir) }),
|
|
70
|
-
),
|
|
68
|
+
dialect: new ClosablePGliteDialect(new PGlite({ fs: new NodeFS(dir) })),
|
|
71
69
|
});
|
|
72
70
|
const module = await new ReactorBuilder()
|
|
73
71
|
.withKysely(db)
|
|
@@ -89,17 +87,22 @@ async function seedStore(dir: string): Promise<void> {
|
|
|
89
87
|
const { status } = await module.reactor.getJobStatus(created.id);
|
|
90
88
|
return status === JobStatus.READ_READY || status === JobStatus.FAILED;
|
|
91
89
|
},
|
|
92
|
-
|
|
90
|
+
// PGlite is several times slower on the Windows runner.
|
|
91
|
+
{ timeout: BOOT_TIMEOUT, interval: 5 },
|
|
93
92
|
);
|
|
94
93
|
expect((await module.reactor.getJobStatus(created.id)).status).toBe(
|
|
95
94
|
JobStatus.READ_READY,
|
|
96
95
|
);
|
|
97
96
|
await module.reactor.kill().completed;
|
|
98
97
|
await db.destroy();
|
|
98
|
+
// PGlite leaves its lockfile behind after a clean close.
|
|
99
|
+
await rm(join(dir, "postmaster.pid"), { force: true });
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
// PGlite boots are several times slower on Windows runners.
|
|
102
103
|
const BOOT_TIMEOUT = 120_000;
|
|
104
|
+
// Windows can briefly keep just-closed store files locked (EBUSY/EPERM).
|
|
105
|
+
const RM_OPTIONS = { recursive: true, force: true, maxRetries: 10 };
|
|
103
106
|
|
|
104
107
|
describe("booting over documents this build does not run", () => {
|
|
105
108
|
let seeded: string;
|
|
@@ -112,8 +115,8 @@ describe("booting over documents this build does not run", () => {
|
|
|
112
115
|
}, BOOT_TIMEOUT);
|
|
113
116
|
|
|
114
117
|
afterAll(async () => {
|
|
115
|
-
await rm(seeded,
|
|
116
|
-
});
|
|
118
|
+
await rm(seeded, RM_OPTIONS);
|
|
119
|
+
}, BOOT_TIMEOUT);
|
|
117
120
|
|
|
118
121
|
beforeEach(async () => {
|
|
119
122
|
tempRoot = await mkdtemp(join(tmpdir(), "switchboard-stored-protocol-"));
|
|
@@ -126,7 +129,7 @@ describe("booting over documents this build does not run", () => {
|
|
|
126
129
|
process.env.PH_REACTOR_DATABASE_URL,
|
|
127
130
|
{ recursive: true },
|
|
128
131
|
);
|
|
129
|
-
});
|
|
132
|
+
}, BOOT_TIMEOUT);
|
|
130
133
|
|
|
131
134
|
afterEach(async () => {
|
|
132
135
|
for (const key of ENV_KEYS) {
|
|
@@ -136,18 +139,19 @@ describe("booting over documents this build does not run", () => {
|
|
|
136
139
|
process.env[key] = previous[key];
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
|
-
await rm(tempRoot,
|
|
140
|
-
});
|
|
142
|
+
await rm(tempRoot, RM_OPTIONS);
|
|
143
|
+
}, BOOT_TIMEOUT);
|
|
141
144
|
|
|
142
145
|
function boot(logger: ILogger) {
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
return bootSwitchboard(
|
|
147
|
+
{
|
|
148
|
+
server: { port: 0 },
|
|
149
|
+
features: { workflows: false, mcp: false },
|
|
150
|
+
packages: { disableLocal: true },
|
|
151
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
152
|
+
},
|
|
153
|
+
{ logger },
|
|
154
|
+
);
|
|
151
155
|
}
|
|
152
156
|
|
|
153
157
|
it(
|
|
@@ -8,7 +8,8 @@ import { join } from "node:path";
|
|
|
8
8
|
import type { ILogger } from "document-model";
|
|
9
9
|
import { describe, expect, it, vi } from "vitest";
|
|
10
10
|
import type * as RenownModule from "../src/renown.js";
|
|
11
|
-
import { startSwitchboard } from "../src/server.mjs";
|
|
11
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
12
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
12
13
|
|
|
13
14
|
vi.mock("../src/renown.js", async (importOriginal) => ({
|
|
14
15
|
...(await importOriginal<typeof RenownModule>()),
|
|
@@ -37,14 +38,15 @@ describe("booting Switchboard without Renown", () => {
|
|
|
37
38
|
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
38
39
|
|
|
39
40
|
try {
|
|
40
|
-
switchboard = await
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
switchboard = await bootSwitchboard(
|
|
42
|
+
{
|
|
43
|
+
server: { port: 0 },
|
|
44
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
45
|
+
features: { workflows: false, mcp: false },
|
|
46
|
+
packages: { disableLocal: true },
|
|
47
|
+
},
|
|
48
|
+
{ logger },
|
|
49
|
+
);
|
|
48
50
|
|
|
49
51
|
expect(
|
|
50
52
|
logger.warn.mock.calls.some(
|
|
@@ -3,7 +3,8 @@ import { tmpdir } from "node:os";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import type { ILogger } from "document-model";
|
|
5
5
|
import { describe, expect, it, vi } from "vitest";
|
|
6
|
-
import { startSwitchboard } from "../src/server.mjs";
|
|
6
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
7
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
7
8
|
|
|
8
9
|
function stubLogger(): ILogger & { info: ReturnType<typeof vi.fn> } {
|
|
9
10
|
const logger = {
|
|
@@ -31,15 +32,16 @@ describe("booting Switchboard", () => {
|
|
|
31
32
|
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
32
33
|
|
|
33
34
|
try {
|
|
34
|
-
switchboard = await
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
switchboard = await bootSwitchboard(
|
|
36
|
+
{
|
|
37
|
+
server: { port: 0 },
|
|
38
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
39
|
+
features: { workflows: false, mcp: false },
|
|
40
|
+
packages: { disableLocal: true },
|
|
41
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
42
|
+
},
|
|
43
|
+
{ logger },
|
|
44
|
+
);
|
|
43
45
|
|
|
44
46
|
const flagLog = logger.info.mock.calls.find(
|
|
45
47
|
([message]) => message === "Feature flags: @flags",
|
|
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
6
|
import type * as RenownModule from "../src/renown.js";
|
|
7
|
-
import {
|
|
7
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
8
8
|
|
|
9
9
|
vi.mock("../src/renown.js", async (importOriginal) => ({
|
|
10
10
|
...(await importOriginal<typeof RenownModule>()),
|
|
@@ -57,15 +57,16 @@ describe("booting with pooled workers under authEnforcement", () => {
|
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
function boot(numWorkers: number) {
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
return bootSwitchboard(
|
|
61
|
+
{
|
|
62
|
+
server: { port: 0 },
|
|
63
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
64
|
+
features: { workflows: false, mcp: false },
|
|
65
|
+
packages: { disableLocal: true },
|
|
66
|
+
workers: { executor: { count: numWorkers } },
|
|
67
|
+
},
|
|
68
|
+
{ logger: stubLogger() },
|
|
69
|
+
);
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
it("fails with a self Renown source", async () => {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Losing the workflow singleton claim must not take the whole API down.
|
|
2
|
+
//
|
|
3
|
+
// It used to: WorkflowSingletonConflictError propagated out of startSwitchboard
|
|
4
|
+
// and aborted the boot. With the old random per-process owner name, an unclean
|
|
5
|
+
// kill left a lease nobody could re-claim, so every restart inside the 60s TTL
|
|
6
|
+
// crash-looped the entire Switchboard — inspection, GraphQL, sync and all —
|
|
7
|
+
// over a component this host is merely not allowed to run.
|
|
8
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import type * as WorkflowEngine from "@powerhousedao/reactor-workflow";
|
|
12
|
+
import type { ILogger } from "document-model";
|
|
13
|
+
import { describe, expect, it, vi } from "vitest";
|
|
14
|
+
|
|
15
|
+
const HOLDER = "another-live-replica";
|
|
16
|
+
const HELD_UNTIL = "2030-01-01T00:00:00.000Z";
|
|
17
|
+
|
|
18
|
+
// The lease itself is the engine's to test (reactor-workflow,
|
|
19
|
+
// singleton-lease.test.ts). What is under test here is what THIS host does
|
|
20
|
+
// when the claim is refused, so only the claim is faked.
|
|
21
|
+
vi.mock("@powerhousedao/reactor-workflow", async (importOriginal) => {
|
|
22
|
+
const actual = await importOriginal<typeof WorkflowEngine>();
|
|
23
|
+
return {
|
|
24
|
+
...actual,
|
|
25
|
+
acquireWorkflowSingletonLease: () => {
|
|
26
|
+
const error = new Error(
|
|
27
|
+
`Workflow execution is a singleton and "${HOLDER}" holds it until ${HELD_UNTIL}`,
|
|
28
|
+
);
|
|
29
|
+
error.name = "WorkflowSingletonConflictError";
|
|
30
|
+
return Promise.reject(
|
|
31
|
+
Object.assign(error, {
|
|
32
|
+
owner: HOLDER,
|
|
33
|
+
expiresAt: HELD_UNTIL,
|
|
34
|
+
wouldBe: "this-host",
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const { startSwitchboard } = await import("../src/server.mjs");
|
|
42
|
+
const { bootSwitchboard } = await import("./boot-helpers.js");
|
|
43
|
+
|
|
44
|
+
function stubLogger(): ILogger & { warn: ReturnType<typeof vi.fn> } {
|
|
45
|
+
const logger = {
|
|
46
|
+
verbose: vi.fn(),
|
|
47
|
+
debug: vi.fn(),
|
|
48
|
+
info: vi.fn(),
|
|
49
|
+
warn: vi.fn(),
|
|
50
|
+
error: vi.fn(),
|
|
51
|
+
child: vi.fn(),
|
|
52
|
+
};
|
|
53
|
+
logger.child.mockReturnValue(logger);
|
|
54
|
+
return logger as unknown as ILogger & { warn: ReturnType<typeof vi.fn> };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
describe("booting Switchboard when another process holds the singleton", () => {
|
|
58
|
+
it("boots the API without the workflow runtime, naming the owner", async () => {
|
|
59
|
+
const tempRoot = await mkdtemp(join(tmpdir(), "switchboard-wf-conflict-"));
|
|
60
|
+
const previousReactorDb = process.env.PH_REACTOR_DATABASE_URL;
|
|
61
|
+
process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
|
|
62
|
+
const logger = stubLogger();
|
|
63
|
+
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
// The boot RESOLVES. That is the whole finding.
|
|
67
|
+
switchboard = await bootSwitchboard(
|
|
68
|
+
{
|
|
69
|
+
server: { port: 0 },
|
|
70
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
71
|
+
features: { workflows: true, mcp: false },
|
|
72
|
+
packages: { disableLocal: true },
|
|
73
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
74
|
+
},
|
|
75
|
+
{ logger },
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// The API is up and serving: the reactor answers, the document models
|
|
79
|
+
// are registered, everything but workflows works.
|
|
80
|
+
const { results } = await switchboard.reactor.getDocumentModelModules();
|
|
81
|
+
expect(results.length).toBeGreaterThan(0);
|
|
82
|
+
|
|
83
|
+
// And the runtime is absent, said so rather than half-present.
|
|
84
|
+
expect(switchboard.workflowTriggers).toBeUndefined();
|
|
85
|
+
|
|
86
|
+
// Warned, not errored into silence, and the warning names who holds it
|
|
87
|
+
// and how to get workflows back.
|
|
88
|
+
const warning = logger.warn.mock.calls
|
|
89
|
+
.map((call) => String(call[0]))
|
|
90
|
+
.find((line) => line.includes("workflow singleton"));
|
|
91
|
+
expect(warning).toBeDefined();
|
|
92
|
+
expect(warning).toContain(HOLDER);
|
|
93
|
+
expect(warning).toContain(HELD_UNTIL);
|
|
94
|
+
expect(warning).toContain("WITHOUT the workflow runtime");
|
|
95
|
+
expect(warning).toContain("PH_WORKFLOWS_SINGLETON_OWNER");
|
|
96
|
+
|
|
97
|
+
await switchboard.shutdown();
|
|
98
|
+
switchboard = undefined;
|
|
99
|
+
} finally {
|
|
100
|
+
await switchboard?.shutdown();
|
|
101
|
+
if (previousReactorDb === undefined) {
|
|
102
|
+
delete process.env.PH_REACTOR_DATABASE_URL;
|
|
103
|
+
} else {
|
|
104
|
+
process.env.PH_REACTOR_DATABASE_URL = previousReactorDb;
|
|
105
|
+
}
|
|
106
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
107
|
+
}
|
|
108
|
+
}, 60_000);
|
|
109
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// A Switchboard refused the workflow singleton at boot retries the claim and
|
|
2
|
+
// starts workflows once the holder lets go. The runtime it composes then has
|
|
3
|
+
// to be reachable: its GraphQL face mounted, not only registered.
|
|
4
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import {
|
|
8
|
+
acquireWorkflowSingletonLease,
|
|
9
|
+
type WorkflowSingletonLease,
|
|
10
|
+
} from "@powerhousedao/reactor-workflow";
|
|
11
|
+
import {
|
|
12
|
+
createRelationalDb,
|
|
13
|
+
type IRelationalDb,
|
|
14
|
+
} from "@powerhousedao/shared/processors";
|
|
15
|
+
import type { ILogger } from "document-model";
|
|
16
|
+
import { Kysely, PostgresDialect } from "kysely";
|
|
17
|
+
import pg from "pg";
|
|
18
|
+
import { describe, expect, it, vi } from "vitest";
|
|
19
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
20
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
21
|
+
|
|
22
|
+
const PG_URL = process.env.REACTOR_TEST_PG_URL;
|
|
23
|
+
const DATABASE = "switchboard_workflow_retry";
|
|
24
|
+
|
|
25
|
+
function stubLogger(): ILogger {
|
|
26
|
+
const logger = {
|
|
27
|
+
verbose: vi.fn(),
|
|
28
|
+
debug: vi.fn(),
|
|
29
|
+
info: vi.fn(),
|
|
30
|
+
warn: vi.fn(),
|
|
31
|
+
error: vi.fn(),
|
|
32
|
+
child: vi.fn(),
|
|
33
|
+
};
|
|
34
|
+
logger.child.mockReturnValue(logger);
|
|
35
|
+
return logger as unknown as ILogger;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function queryHealth(port: number): Promise<string | undefined> {
|
|
39
|
+
const response = await fetch(`http://127.0.0.1:${port}/graphql`, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: { "content-type": "application/json" },
|
|
42
|
+
body: JSON.stringify({ query: "{ workflowRuntime { health } }" }),
|
|
43
|
+
});
|
|
44
|
+
const body = (await response.json()) as {
|
|
45
|
+
data?: { workflowRuntime?: { health?: string } };
|
|
46
|
+
};
|
|
47
|
+
return body.data?.workflowRuntime?.health;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe.skipIf(!PG_URL)(
|
|
51
|
+
"a Switchboard that claims the workflow singleton after boot [Postgres]",
|
|
52
|
+
() => {
|
|
53
|
+
it("serves the workflow GraphQL API once it has the claim", async () => {
|
|
54
|
+
const admin = new pg.Pool({ connectionString: PG_URL });
|
|
55
|
+
await admin.query(`DROP DATABASE IF EXISTS "${DATABASE}" WITH (FORCE)`);
|
|
56
|
+
await admin.query(`CREATE DATABASE "${DATABASE}"`);
|
|
57
|
+
const url = new URL(PG_URL!);
|
|
58
|
+
url.pathname = `/${DATABASE}`;
|
|
59
|
+
const readModelUrl = url.toString();
|
|
60
|
+
const holderDb = new Kysely<unknown>({
|
|
61
|
+
dialect: new PostgresDialect({
|
|
62
|
+
pool: new pg.Pool({ connectionString: readModelUrl, max: 2 }),
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
const tempRoot = await mkdtemp(join(tmpdir(), "switchboard-wf-retry-"));
|
|
66
|
+
const previousReactorDb = process.env.PH_REACTOR_DATABASE_URL;
|
|
67
|
+
process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
|
|
68
|
+
let holder: WorkflowSingletonLease | undefined;
|
|
69
|
+
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
70
|
+
try {
|
|
71
|
+
// Another live host holds the singleton over the same journal.
|
|
72
|
+
holder = await acquireWorkflowSingletonLease({
|
|
73
|
+
relationalDb: createRelationalDb(holderDb) as IRelationalDb,
|
|
74
|
+
logger: stubLogger(),
|
|
75
|
+
owner: "the-other-host",
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
switchboard = await bootSwitchboard(
|
|
79
|
+
{
|
|
80
|
+
server: { port: 0 },
|
|
81
|
+
storage: { readModel: { url: readModelUrl } },
|
|
82
|
+
features: { workflows: true, mcp: false },
|
|
83
|
+
packages: { disableLocal: true },
|
|
84
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
85
|
+
},
|
|
86
|
+
{ logger: stubLogger() },
|
|
87
|
+
);
|
|
88
|
+
expect(switchboard.workflowTriggers).toBeUndefined();
|
|
89
|
+
expect(await queryHealth(switchboard.port)).toBeUndefined();
|
|
90
|
+
|
|
91
|
+
await holder.release();
|
|
92
|
+
holder = undefined;
|
|
93
|
+
|
|
94
|
+
const port = switchboard.port;
|
|
95
|
+
await vi.waitFor(
|
|
96
|
+
async () => expect(await queryHealth(port)).toBe("ok"),
|
|
97
|
+
{ timeout: 60_000, interval: 500 },
|
|
98
|
+
);
|
|
99
|
+
expect(switchboard.workflowTriggers).toEqual({ status: "available" });
|
|
100
|
+
|
|
101
|
+
await switchboard.shutdown();
|
|
102
|
+
switchboard = undefined;
|
|
103
|
+
} finally {
|
|
104
|
+
await holder?.release();
|
|
105
|
+
await switchboard?.shutdown();
|
|
106
|
+
await holderDb.destroy();
|
|
107
|
+
if (previousReactorDb === undefined) {
|
|
108
|
+
delete process.env.PH_REACTOR_DATABASE_URL;
|
|
109
|
+
} else {
|
|
110
|
+
process.env.PH_REACTOR_DATABASE_URL = previousReactorDb;
|
|
111
|
+
}
|
|
112
|
+
// Not forced: terminating a pool's idle connections under it raises
|
|
113
|
+
// an unhandled error. A database left behind is dropped next run.
|
|
114
|
+
await admin
|
|
115
|
+
.query(`DROP DATABASE IF EXISTS "${DATABASE}"`)
|
|
116
|
+
.catch(() => undefined);
|
|
117
|
+
await admin.end();
|
|
118
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
119
|
+
}
|
|
120
|
+
}, 120_000);
|
|
121
|
+
},
|
|
122
|
+
);
|