@powerhousedao/switchboard 6.2.3-dev.10 → 6.2.3-dev.100
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/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-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-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-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-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/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/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/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/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-apps-config.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth-apps-config.test.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/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/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 +1284 -0
- package/README.md +102 -22
- 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-FH4fPeIE.mjs +481 -0
- package/dist/from-env-FH4fPeIE.mjs.map +1 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +84 -84
- 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-CK9_tVak.d.mts +46 -0
- package/dist/plugin-host-CK9_tVak.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 +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-DmbWLt46.mjs +42 -0
- package/dist/renown-layers-DmbWLt46.mjs.map +1 -0
- package/dist/schema-CsY8bjsu.mjs +329 -0
- package/dist/schema-CsY8bjsu.mjs.map +1 -0
- package/dist/schema-MAUTnmj1.d.mts +251 -0
- package/dist/schema-MAUTnmj1.d.mts.map +1 -0
- package/dist/server-CirQ9hyu.mjs +2732 -0
- package/dist/server-CirQ9hyu.mjs.map +1 -0
- package/dist/server.d.mts +129 -189
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +5 -5
- package/dist/types-CidZdkhU.d.mts +314 -0
- package/dist/types-CidZdkhU.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 +30 -5
- 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-C9BQlyT0.mjs +1943 -0
- package/dist/workflows-C9BQlyT0.mjs.map +1 -0
- package/package.json +85 -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/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-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 +119 -0
- 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 +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 +963 -0
- package/test/config-merge.test.ts +248 -0
- package/test/config-schema.test.ts +167 -0
- package/test/create-signature-policy.test.ts +69 -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 +205 -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 +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-apps-config.test.ts +66 -0
- package/test/workflow/oauth.test.ts +286 -0
- package/test/workflow/resolvers.test.ts +488 -0
- 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-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 +1254 -0
- package/test/workflows-plugin-config.test.ts +77 -0
- package/tsconfig.json +11 -2
- package/tsdown.config.ts +13 -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,248 @@
|
|
|
1
|
+
import type { ILogger } from "document-model";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { switchboardConfigFromEnv } from "../src/config/from-env.js";
|
|
4
|
+
import {
|
|
5
|
+
callerOverEnv,
|
|
6
|
+
mergeSwitchboardConfig,
|
|
7
|
+
switchboardConfigSchema,
|
|
8
|
+
type SwitchboardConfig,
|
|
9
|
+
type SwitchboardConfigInput,
|
|
10
|
+
} from "../src/config/schema.js";
|
|
11
|
+
|
|
12
|
+
type Env = Record<string, string | undefined>;
|
|
13
|
+
|
|
14
|
+
const silent = { warn: () => undefined } as unknown as ILogger;
|
|
15
|
+
|
|
16
|
+
function resolved(env: Env, caller: SwitchboardConfigInput): SwitchboardConfig {
|
|
17
|
+
return switchboardConfigSchema.parse(
|
|
18
|
+
callerOverEnv(switchboardConfigFromEnv(env, { logger: silent }), caller),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe("mergeSwitchboardConfig", () => {
|
|
23
|
+
it("lets a later layer win per key and keeps the rest", () => {
|
|
24
|
+
expect(
|
|
25
|
+
mergeSwitchboardConfig(
|
|
26
|
+
{ server: { port: 1, basePath: "/a" }, logLevel: "debug" },
|
|
27
|
+
{ server: { port: 2 } },
|
|
28
|
+
{ server: { port: undefined } },
|
|
29
|
+
),
|
|
30
|
+
).toEqual({ server: { port: 2, basePath: "/a" }, logLevel: "debug" });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("replaces arrays, maps and the attachment storage whole", () => {
|
|
34
|
+
const s3 = {
|
|
35
|
+
kind: "s3" as const,
|
|
36
|
+
s3: {
|
|
37
|
+
endpoint: "e",
|
|
38
|
+
region: "r",
|
|
39
|
+
bucket: "b",
|
|
40
|
+
accessKeyId: "a",
|
|
41
|
+
secretAccessKey: "s",
|
|
42
|
+
prefix: "p",
|
|
43
|
+
forcePathStyle: false,
|
|
44
|
+
uploadTtlSeconds: 1,
|
|
45
|
+
downloadTtlSeconds: 1,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
const processorConfig = new Map([["b", 2]]);
|
|
49
|
+
expect(
|
|
50
|
+
mergeSwitchboardConfig(
|
|
51
|
+
{
|
|
52
|
+
auth: { admins: ["0xa", "0xb"] },
|
|
53
|
+
attachments: { storage: s3 },
|
|
54
|
+
processorConfig: new Map([["a", 1]]),
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
auth: { admins: ["0xc"] },
|
|
58
|
+
attachments: { storage: { kind: "filesystem" } },
|
|
59
|
+
processorConfig,
|
|
60
|
+
},
|
|
61
|
+
),
|
|
62
|
+
).toEqual({
|
|
63
|
+
auth: { admins: ["0xc"] },
|
|
64
|
+
attachments: { storage: { kind: "filesystem" } },
|
|
65
|
+
processorConfig,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("callerOverEnv keeps each key's precedence", () => {
|
|
71
|
+
it("lets the caller win an ordinary key", () => {
|
|
72
|
+
const config = resolved(
|
|
73
|
+
{
|
|
74
|
+
PH_REGISTRY_URL: "https://env",
|
|
75
|
+
PH_PGLITE_WORKERS: "true",
|
|
76
|
+
PH_WORKFLOWS_ENABLED: "1",
|
|
77
|
+
DATABASE_URL: "/env/read",
|
|
78
|
+
PH_REACTOR_DATABASE_URL: "/env/reactor",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
packages: { registryUrl: "https://caller" },
|
|
82
|
+
storage: {
|
|
83
|
+
pglite: { workers: false },
|
|
84
|
+
readModel: { url: "/caller" },
|
|
85
|
+
reactor: { url: "/caller" },
|
|
86
|
+
},
|
|
87
|
+
features: { workflows: false },
|
|
88
|
+
},
|
|
89
|
+
);
|
|
90
|
+
expect(config.packages.registryUrl).toBe("https://caller");
|
|
91
|
+
expect(config.storage.pglite.workers).toBe(false);
|
|
92
|
+
expect(config.features.workflows).toBe(false);
|
|
93
|
+
expect(config.storage.readModel.url).toBe("/caller");
|
|
94
|
+
expect(config.storage.reactor.url).toBe("/caller");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("falls back to the env where the caller says nothing", () => {
|
|
98
|
+
const config = resolved(
|
|
99
|
+
{ PH_PGLITE_WORKERS: "false", PH_WORKFLOWS_ENABLED: "0" },
|
|
100
|
+
{},
|
|
101
|
+
);
|
|
102
|
+
expect(config.storage.pglite.workers).toBe(false);
|
|
103
|
+
expect(config.features.workflows).toBe(false);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("lets DOCUMENT_MODEL_SUBGRAPHS_ENABLED win over the caller", () => {
|
|
107
|
+
expect(
|
|
108
|
+
resolved(
|
|
109
|
+
{ DOCUMENT_MODEL_SUBGRAPHS_ENABLED: "false" },
|
|
110
|
+
{ features: { documentModelSubgraphs: true } },
|
|
111
|
+
).features.documentModelSubgraphs,
|
|
112
|
+
).toBe(false);
|
|
113
|
+
expect(
|
|
114
|
+
resolved({}, { features: { documentModelSubgraphs: false } }).features
|
|
115
|
+
.documentModelSubgraphs,
|
|
116
|
+
).toBe(false);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("lets reactor-api's overriding auth env vars win over the caller", () => {
|
|
120
|
+
const { auth } = resolved(
|
|
121
|
+
{
|
|
122
|
+
AUTH_ENABLED: "false",
|
|
123
|
+
ADMINS: "0xEnv",
|
|
124
|
+
RESOLVE_CALLER_IDENTITY: "false",
|
|
125
|
+
REQUIRE_AUTHENTICATED_CALLER: "false",
|
|
126
|
+
REQUIRE_AUTHENTICATED_CALLER_EXEMPT_PATHS: "/env",
|
|
127
|
+
ATTACHMENT_READS_FOLLOW_DOCUMENT_POLICY: "false",
|
|
128
|
+
DEFAULT_PROTECTION: "false",
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
auth: {
|
|
132
|
+
enabled: true,
|
|
133
|
+
admins: ["0xcaller"],
|
|
134
|
+
resolveIdentity: true,
|
|
135
|
+
requireAuthenticatedCaller: true,
|
|
136
|
+
requireAuthenticatedCallerExemptPaths: ["/caller"],
|
|
137
|
+
attachmentReadsFollowDocumentPolicy: true,
|
|
138
|
+
defaultProtection: true,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
);
|
|
142
|
+
expect(auth).toMatchObject({
|
|
143
|
+
enabled: false,
|
|
144
|
+
admins: ["0xenv"],
|
|
145
|
+
resolveIdentity: false,
|
|
146
|
+
requireAuthenticatedCaller: false,
|
|
147
|
+
requireAuthenticatedCallerExemptPaths: ["/env"],
|
|
148
|
+
attachmentReadsFollowDocumentPolicy: false,
|
|
149
|
+
// An ordinary key: the caller wins.
|
|
150
|
+
defaultProtection: true,
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it.each([
|
|
155
|
+
[{}, undefined, true],
|
|
156
|
+
[{ MCP_ENABLED: "false" }, undefined, false],
|
|
157
|
+
[{ MCP_ENABLED: "false" }, true, false],
|
|
158
|
+
[{ MCP_ENABLED: "true" }, false, false],
|
|
159
|
+
[{ MCP_ENABLED: "yes" }, undefined, true],
|
|
160
|
+
[{}, false, false],
|
|
161
|
+
] as const)(
|
|
162
|
+
"MCP: env %o with the caller's %s mounts it: %s",
|
|
163
|
+
(env, mcp, mounted) => {
|
|
164
|
+
expect(resolved(env, { features: { mcp } }).features.mcp ?? true).toBe(
|
|
165
|
+
mounted,
|
|
166
|
+
);
|
|
167
|
+
},
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
it.each([
|
|
171
|
+
[{}, undefined, true],
|
|
172
|
+
[{ INSPECTION_ENABLED: "false" }, undefined, false],
|
|
173
|
+
[{ INSPECTION_ENABLED: "false" }, true, false],
|
|
174
|
+
[{ INSPECTION_ENABLED: "true" }, false, false],
|
|
175
|
+
[{ INSPECTION_ENABLED: "0" }, undefined, true],
|
|
176
|
+
[{ INSPECTION_ENABLED: "true" }, undefined, true],
|
|
177
|
+
] as const)(
|
|
178
|
+
"inspection: env %o with the caller's %s mounts it: %s",
|
|
179
|
+
(env, enabled, mounted) => {
|
|
180
|
+
expect(
|
|
181
|
+
resolved(env, { inspection: { enabled } }).inspection.enabled,
|
|
182
|
+
).toBe(mounted);
|
|
183
|
+
},
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
it("lets PH_WORKFLOWS_ENABLED switch workflows off under the plugin host", () => {
|
|
187
|
+
const env = {
|
|
188
|
+
FEATURE_PLUGIN_HOST_ENABLED: "1",
|
|
189
|
+
PH_WORKFLOWS_ENABLED: "false",
|
|
190
|
+
};
|
|
191
|
+
expect(resolved(env, {}).features.workflows).toBe(false);
|
|
192
|
+
expect(
|
|
193
|
+
resolved(env, { features: { workflows: true } }).features.workflows,
|
|
194
|
+
).toBe(false);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("ignores MCP_ENABLED and PH_WORKFLOWS_ENABLED under the plugin host", () => {
|
|
198
|
+
const env = {
|
|
199
|
+
FEATURE_PLUGIN_HOST_ENABLED: "1",
|
|
200
|
+
MCP_ENABLED: "false",
|
|
201
|
+
PH_WORKFLOWS_ENABLED: "true",
|
|
202
|
+
};
|
|
203
|
+
const host = resolved(env, {});
|
|
204
|
+
expect(host.features.pluginHost).toBe(true);
|
|
205
|
+
expect(host.features.mcp).toBeUndefined();
|
|
206
|
+
expect(host.features.workflows).toBeUndefined();
|
|
207
|
+
const withCaller = resolved(env, {
|
|
208
|
+
features: { mcp: false, workflows: true },
|
|
209
|
+
});
|
|
210
|
+
expect(withCaller.features.mcp).toBe(false);
|
|
211
|
+
expect(withCaller.features.workflows).toBe(true);
|
|
212
|
+
// Not carved: classic on both paths.
|
|
213
|
+
expect(
|
|
214
|
+
resolved({ ...env, INSPECTION_ENABLED: "false" }, {}).inspection.enabled,
|
|
215
|
+
).toBe(false);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe("startSwitchboard", () => {
|
|
220
|
+
it("refuses the old options shape instead of booting on defaults", async () => {
|
|
221
|
+
const { startSwitchboard } = await import("../src/server.mjs");
|
|
222
|
+
await expect(
|
|
223
|
+
startSwitchboard({ port: 0, dbPath: "x" } as SwitchboardConfigInput),
|
|
224
|
+
).rejects.toThrow("unknown config keys: port, dbPath");
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe("packages.hostValidation", () => {
|
|
229
|
+
it("defaults to log", () => {
|
|
230
|
+
expect(resolved({}, {}).packages.hostValidation).toBe("log");
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("reads PH_HOST_VALIDATION and a caller's config", () => {
|
|
234
|
+
expect(
|
|
235
|
+
resolved({ PH_HOST_VALIDATION: " refuse " }, {}).packages.hostValidation,
|
|
236
|
+
).toBe("refuse");
|
|
237
|
+
expect(
|
|
238
|
+
resolved({}, { packages: { hostValidation: "refuse" } }).packages
|
|
239
|
+
.hostValidation,
|
|
240
|
+
).toBe("refuse");
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("refuses an unknown PH_HOST_VALIDATION", () => {
|
|
244
|
+
expect(() => resolved({ PH_HOST_VALIDATION: "strict" }, {})).toThrow(
|
|
245
|
+
'PH_HOST_VALIDATION must be "log" or "refuse", got "strict"',
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import {
|
|
4
|
+
switchboardConfigLayerSchema,
|
|
5
|
+
switchboardConfigSchema,
|
|
6
|
+
type SwitchboardConfigInput,
|
|
7
|
+
} from "../src/config/schema.js";
|
|
8
|
+
|
|
9
|
+
describe("switchboardConfigSchema", () => {
|
|
10
|
+
it("fills every default from an empty layer", () => {
|
|
11
|
+
const config = switchboardConfigSchema.parse({});
|
|
12
|
+
expect(config.logLevel).toBe("info");
|
|
13
|
+
expect(config.server).toEqual({
|
|
14
|
+
port: 4001,
|
|
15
|
+
strictPort: false,
|
|
16
|
+
basePath: "/",
|
|
17
|
+
gatewayAdapter: "apollo",
|
|
18
|
+
dev: false,
|
|
19
|
+
});
|
|
20
|
+
expect(config.storage).toEqual({
|
|
21
|
+
reactor: {},
|
|
22
|
+
readModel: {},
|
|
23
|
+
inMemory: false,
|
|
24
|
+
pglite: { fsync: true, workers: true, vacuumFull: { mode: "off" } },
|
|
25
|
+
migratePglite: false,
|
|
26
|
+
});
|
|
27
|
+
expect(config.protocol).toEqual({
|
|
28
|
+
featureFlags: {
|
|
29
|
+
documentDecisions: false,
|
|
30
|
+
authEnforcement: false,
|
|
31
|
+
authGroups: false,
|
|
32
|
+
authConditions: false,
|
|
33
|
+
},
|
|
34
|
+
createSignaturePolicy: "v2-required",
|
|
35
|
+
unsupportedStoredDocuments: "refuse",
|
|
36
|
+
legacyProcessorIds: true,
|
|
37
|
+
catchUpPriority: "dynamic",
|
|
38
|
+
processorTiming: "basic",
|
|
39
|
+
processorTimingWindowMs: 60_000,
|
|
40
|
+
processorSlowBatchMs: 1_000,
|
|
41
|
+
processorTimingLogMs: 0,
|
|
42
|
+
});
|
|
43
|
+
expect(config.telemetry).toEqual({
|
|
44
|
+
memory: {
|
|
45
|
+
enabled: false,
|
|
46
|
+
intervalMs: 30_000,
|
|
47
|
+
outputs: ["memory", "file"],
|
|
48
|
+
file: { maxMb: 10, keep: 5 },
|
|
49
|
+
ringSize: 720,
|
|
50
|
+
consoleIntervalMs: 300_000,
|
|
51
|
+
workers: true,
|
|
52
|
+
windowMin: 30,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
expect(config.workers).toEqual({
|
|
56
|
+
executor: { count: 0, poolSize: 2, acquireTimeoutMs: 5000 },
|
|
57
|
+
hostPoolSize: 16,
|
|
58
|
+
projection: { enabled: false, poolSize: 8 },
|
|
59
|
+
});
|
|
60
|
+
expect(config.inspection).toEqual({ enabled: true, admin: false });
|
|
61
|
+
expect(config.features).toEqual({
|
|
62
|
+
documentModelSubgraphs: true,
|
|
63
|
+
pluginHost: false,
|
|
64
|
+
privacy: { enabled: false },
|
|
65
|
+
});
|
|
66
|
+
expect(config.attachments).toEqual({ storage: { kind: "filesystem" } });
|
|
67
|
+
expect(config.auth.documentPermissions).toEqual({ enabled: false });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("keeps the defaults beside a nested value a layer sets", () => {
|
|
71
|
+
const layer: SwitchboardConfigInput = {
|
|
72
|
+
workers: { executor: { count: "auto" } },
|
|
73
|
+
storage: { pglite: { vacuumFull: { mode: "quiet" } } },
|
|
74
|
+
};
|
|
75
|
+
const config = switchboardConfigSchema.parse(layer);
|
|
76
|
+
expect(config.workers.executor).toEqual({
|
|
77
|
+
count: "auto",
|
|
78
|
+
poolSize: 2,
|
|
79
|
+
acquireTimeoutMs: 5000,
|
|
80
|
+
});
|
|
81
|
+
expect(config.workers.hostPoolSize).toBe(16);
|
|
82
|
+
expect(config.storage.pglite).toEqual({
|
|
83
|
+
fsync: true,
|
|
84
|
+
workers: true,
|
|
85
|
+
vacuumFull: { mode: "quiet" },
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("leaves undoV3 to the reactor unless a layer sets it", () => {
|
|
90
|
+
expect(
|
|
91
|
+
switchboardConfigSchema.parse({}).protocol.featureFlags,
|
|
92
|
+
).not.toHaveProperty("undoV3");
|
|
93
|
+
expect(
|
|
94
|
+
switchboardConfigSchema.parse({
|
|
95
|
+
protocol: { featureFlags: { undoV3: false } },
|
|
96
|
+
}).protocol.featureFlags.undoV3,
|
|
97
|
+
).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it.each<[string, SwitchboardConfigInput]>([
|
|
101
|
+
["a port out of range", { server: { port: 70000 } }],
|
|
102
|
+
["a fractional worker count", { workers: { executor: { count: 1.5 } } }],
|
|
103
|
+
["a host pool of 0", { workers: { hostPoolSize: 0 } }],
|
|
104
|
+
["a catch-up level above 7", { protocol: { catchUpPriority: 8 } }],
|
|
105
|
+
[
|
|
106
|
+
"an unknown timing level",
|
|
107
|
+
{ protocol: { processorTiming: "full" as never } },
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
"a sampling interval under a second",
|
|
111
|
+
{ telemetry: { memory: { intervalMs: 10 } } },
|
|
112
|
+
],
|
|
113
|
+
[
|
|
114
|
+
"an unknown memory output",
|
|
115
|
+
{ telemetry: { memory: { outputs: ["otel" as never] } } },
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
"an unknown signature policy",
|
|
119
|
+
{ protocol: { createSignaturePolicy: "v3" as "legacy" } },
|
|
120
|
+
],
|
|
121
|
+
["a PG major it does not ship", { storage: { forcePgVersion: 15 as 16 } }],
|
|
122
|
+
])("refuses %s", (_name, layer) => {
|
|
123
|
+
expect(switchboardConfigSchema.safeParse(layer).success).toBe(false);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe("the config modules", () => {
|
|
128
|
+
it("load without the server", async () => {
|
|
129
|
+
vi.doMock("../src/server.mjs", () => {
|
|
130
|
+
throw new Error("the server was loaded");
|
|
131
|
+
});
|
|
132
|
+
await expect(import("../src/config/from-env.js")).resolves.toBeDefined();
|
|
133
|
+
vi.doUnmock("../src/server.mjs");
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe("switchboardConfigLayerSchema", () => {
|
|
138
|
+
const layer = switchboardConfigLayerSchema(["server.port", "drive"]);
|
|
139
|
+
|
|
140
|
+
it("keeps a layer as written, without defaults", () => {
|
|
141
|
+
expect(layer.parse({})).toEqual({});
|
|
142
|
+
expect(layer.parse({ auth: { enabled: true } })).toEqual({
|
|
143
|
+
auth: { enabled: true },
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("validates values and refuses unknown or omitted keys", () => {
|
|
148
|
+
expect(
|
|
149
|
+
layer.safeParse({ workers: { executor: { count: "auto" } } }),
|
|
150
|
+
).toMatchObject({ success: true });
|
|
151
|
+
expect(
|
|
152
|
+
layer.safeParse({ workers: { executor: { count: -1 } } }).success,
|
|
153
|
+
).toBe(false);
|
|
154
|
+
expect(layer.safeParse({ auth: { enabeld: true } }).success).toBe(false);
|
|
155
|
+
expect(layer.safeParse({ server: { port: 1 } }).success).toBe(false);
|
|
156
|
+
expect(layer.safeParse({ drive: {} }).success).toBe(false);
|
|
157
|
+
expect(layer.safeParse({ server: { basePath: "/x" } }).success).toBe(true);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("emits a JSON Schema once the map key is omitted", () => {
|
|
161
|
+
const schema = z.toJSONSchema(
|
|
162
|
+
switchboardConfigLayerSchema(["processorConfig"]),
|
|
163
|
+
{ io: "input" },
|
|
164
|
+
);
|
|
165
|
+
expect(schema).toMatchObject({ additionalProperties: false });
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ReactorBuilder, ReactorClientBuilder } from "@powerhousedao/reactor";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { applySwitchboardReactorDefaults } from "../src/builder-defaults.mjs";
|
|
4
|
+
import { resolveCreateSignaturePolicy } from "../src/create-signature-policy.mjs";
|
|
5
|
+
|
|
6
|
+
describe("resolveCreateSignaturePolicy", () => {
|
|
7
|
+
it("defaults to v2-required with a signer", () => {
|
|
8
|
+
expect(resolveCreateSignaturePolicy({}, { hasSigner: true })).toBe(
|
|
9
|
+
"v2-required",
|
|
10
|
+
);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("reads CREATE_SIGNATURE_POLICY", () => {
|
|
14
|
+
expect(
|
|
15
|
+
resolveCreateSignaturePolicy(
|
|
16
|
+
{ CREATE_SIGNATURE_POLICY: "legacy" },
|
|
17
|
+
{ hasSigner: true },
|
|
18
|
+
),
|
|
19
|
+
).toBe("legacy");
|
|
20
|
+
expect(
|
|
21
|
+
resolveCreateSignaturePolicy(
|
|
22
|
+
{ CREATE_SIGNATURE_POLICY: " v2-required " },
|
|
23
|
+
{ hasSigner: true },
|
|
24
|
+
),
|
|
25
|
+
).toBe("v2-required");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("refuses an unknown value", () => {
|
|
29
|
+
expect(() =>
|
|
30
|
+
resolveCreateSignaturePolicy(
|
|
31
|
+
{ CREATE_SIGNATURE_POLICY: "v2" },
|
|
32
|
+
{ hasSigner: true },
|
|
33
|
+
),
|
|
34
|
+
).toThrow(/CREATE_SIGNATURE_POLICY/);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("falls back to legacy with a warning when there is no signer", () => {
|
|
38
|
+
const warn = vi.fn();
|
|
39
|
+
|
|
40
|
+
expect(
|
|
41
|
+
resolveCreateSignaturePolicy({}, { hasSigner: false, logger: { warn } }),
|
|
42
|
+
).toBe("legacy");
|
|
43
|
+
expect(warn).toHaveBeenCalledOnce();
|
|
44
|
+
|
|
45
|
+
warn.mockClear();
|
|
46
|
+
expect(
|
|
47
|
+
resolveCreateSignaturePolicy(
|
|
48
|
+
{ CREATE_SIGNATURE_POLICY: "legacy" },
|
|
49
|
+
{ hasSigner: false, logger: { warn } },
|
|
50
|
+
),
|
|
51
|
+
).toBe("legacy");
|
|
52
|
+
expect(warn).not.toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("applySwitchboardReactorDefaults", () => {
|
|
57
|
+
it("hands the creation policy to the client builder", () => {
|
|
58
|
+
const clientBuilder = new ReactorClientBuilder();
|
|
59
|
+
const withPolicy = vi.spyOn(clientBuilder, "withCreateSignaturePolicy");
|
|
60
|
+
|
|
61
|
+
applySwitchboardReactorDefaults(new ReactorBuilder(), clientBuilder, {
|
|
62
|
+
includeBaseModels: false,
|
|
63
|
+
signalHandlers: false,
|
|
64
|
+
createSignaturePolicy: "legacy",
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(withPolicy).toHaveBeenCalledWith("legacy");
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { IReactorClient } from "@powerhousedao/reactor";
|
|
2
|
+
import { reactorDriveDocumentModelModule } from "@powerhousedao/reactor-drive";
|
|
3
|
+
import { driveDocumentModelModule } from "@powerhousedao/shared/document-drive";
|
|
4
|
+
import {
|
|
5
|
+
headNewDocument,
|
|
6
|
+
selectDocumentModelModule,
|
|
7
|
+
type DocumentModelModule,
|
|
8
|
+
type NewDocumentHeaderOptions,
|
|
9
|
+
type PHDocument,
|
|
10
|
+
} from "@powerhousedao/shared/document-model";
|
|
11
|
+
|
|
12
|
+
const modules = [
|
|
13
|
+
driveDocumentModelModule,
|
|
14
|
+
reactorDriveDocumentModelModule,
|
|
15
|
+
] as unknown as DocumentModelModule[];
|
|
16
|
+
import { describe, expect, it } from "vitest";
|
|
17
|
+
import { addDefaultDrive, addDefaultReactorDrive } from "../src/utils.mjs";
|
|
18
|
+
|
|
19
|
+
function client(): { client: IReactorClient; created: PHDocument[] } {
|
|
20
|
+
const created: PHDocument[] = [];
|
|
21
|
+
return {
|
|
22
|
+
created,
|
|
23
|
+
client: {
|
|
24
|
+
get: () => Promise.reject(new Error("not found")),
|
|
25
|
+
resolveIdOrSlug: () =>
|
|
26
|
+
Promise.reject(
|
|
27
|
+
Object.assign(new Error("not found"), {
|
|
28
|
+
name: "DocumentNotFoundError",
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
31
|
+
newDocument: (type: string, options?: NewDocumentHeaderOptions) =>
|
|
32
|
+
Promise.resolve(
|
|
33
|
+
headNewDocument(
|
|
34
|
+
selectDocumentModelModule(modules, type),
|
|
35
|
+
options,
|
|
36
|
+
"v2-required",
|
|
37
|
+
{ "base-reducer": 3 },
|
|
38
|
+
),
|
|
39
|
+
),
|
|
40
|
+
isDocumentIdTaken: () => Promise.resolve(false),
|
|
41
|
+
write: {
|
|
42
|
+
create: (document: PHDocument) => {
|
|
43
|
+
created.push(document);
|
|
44
|
+
return Promise.resolve({
|
|
45
|
+
readable: Promise.resolve({
|
|
46
|
+
documentId: document.header.id,
|
|
47
|
+
branch: "main",
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
} as unknown as IReactorClient,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe.each([
|
|
57
|
+
["addDefaultDrive", addDefaultDrive],
|
|
58
|
+
["addDefaultReactorDrive", addDefaultReactorDrive],
|
|
59
|
+
])("%s", (_name, add) => {
|
|
60
|
+
it("heads the drive with the client's newDocument", async () => {
|
|
61
|
+
const { client: reactor, created } = client();
|
|
62
|
+
|
|
63
|
+
await add(reactor, { slug: "main", global: { name: "Main" } } as never, 1);
|
|
64
|
+
|
|
65
|
+
expect(created[0].header.protocolVersions).toEqual({
|
|
66
|
+
"base-reducer": 3,
|
|
67
|
+
signature: 2,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("heads a drive with a configured id as legacy at the same versions", async () => {
|
|
72
|
+
const { client: reactor, created } = client();
|
|
73
|
+
|
|
74
|
+
await add(reactor, { id: "fixed", global: { name: "Main" } } as never, 1);
|
|
75
|
+
|
|
76
|
+
expect(created[0].header.id).toBe("fixed");
|
|
77
|
+
expect(created[0].header.protocolVersions).toEqual({ "base-reducer": 3 });
|
|
78
|
+
});
|
|
79
|
+
});
|