@powerhousedao/switchboard 6.2.3 → 6.3.0-dev.2

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.
Files changed (271) hide show
  1. package/.tsbuild/test/ai-gateway.test.d.ts +2 -0
  2. package/.tsbuild/test/ai-gateway.test.d.ts.map +1 -0
  3. package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts +2 -0
  4. package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts.map +1 -0
  5. package/.tsbuild/test/boot-auth-config.test.d.ts +2 -0
  6. package/.tsbuild/test/boot-auth-config.test.d.ts.map +1 -0
  7. package/.tsbuild/test/boot-desktop-auth.test.d.ts +2 -0
  8. package/.tsbuild/test/boot-desktop-auth.test.d.ts.map +1 -0
  9. package/.tsbuild/test/boot-env-isolation.test.d.ts +2 -0
  10. package/.tsbuild/test/boot-env-isolation.test.d.ts.map +1 -0
  11. package/.tsbuild/test/boot-helpers.d.ts +5 -0
  12. package/.tsbuild/test/boot-helpers.d.ts.map +1 -0
  13. package/.tsbuild/test/boot-inspection-enabled.test.d.ts +2 -0
  14. package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
  15. package/.tsbuild/test/boot-mcp-auth.test.d.ts +2 -0
  16. package/.tsbuild/test/boot-mcp-auth.test.d.ts.map +1 -0
  17. package/.tsbuild/test/boot-port-zero.test.d.ts +2 -0
  18. package/.tsbuild/test/boot-port-zero.test.d.ts.map +1 -0
  19. package/.tsbuild/test/boot-preconditions.test.d.ts +2 -0
  20. package/.tsbuild/test/boot-preconditions.test.d.ts.map +1 -0
  21. package/.tsbuild/test/boot-privacy.test.d.ts +2 -0
  22. package/.tsbuild/test/boot-privacy.test.d.ts.map +1 -0
  23. package/.tsbuild/test/boot-ready-drives.test.d.ts +2 -0
  24. package/.tsbuild/test/boot-ready-drives.test.d.ts.map +1 -0
  25. package/.tsbuild/test/boot-undo-v3-flag.test.d.ts +2 -0
  26. package/.tsbuild/test/boot-undo-v3-flag.test.d.ts.map +1 -0
  27. package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts +2 -0
  28. package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts.map +1 -0
  29. package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts +2 -0
  30. package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts.map +1 -0
  31. package/.tsbuild/test/config-from-env.test.d.ts +2 -0
  32. package/.tsbuild/test/config-from-env.test.d.ts.map +1 -0
  33. package/.tsbuild/test/config-merge.test.d.ts +2 -0
  34. package/.tsbuild/test/config-merge.test.d.ts.map +1 -0
  35. package/.tsbuild/test/config-schema.test.d.ts +2 -0
  36. package/.tsbuild/test/config-schema.test.d.ts.map +1 -0
  37. package/.tsbuild/test/default-composition.test.d.ts +2 -0
  38. package/.tsbuild/test/default-composition.test.d.ts.map +1 -0
  39. package/.tsbuild/test/default-drive-protocol-versions.test.d.ts +2 -0
  40. package/.tsbuild/test/default-drive-protocol-versions.test.d.ts.map +1 -0
  41. package/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
  42. package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
  43. package/.tsbuild/test/delegated-publish.test.d.ts +2 -0
  44. package/.tsbuild/test/delegated-publish.test.d.ts.map +1 -0
  45. package/.tsbuild/test/durable-node-fs-pg16.test.d.ts +2 -0
  46. package/.tsbuild/test/durable-node-fs-pg16.test.d.ts.map +1 -0
  47. package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.d.ts +13 -0
  48. package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.d.ts.map +1 -0
  49. package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/index.d.ts +3 -0
  50. package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/index.d.ts.map +1 -0
  51. package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/tally/index.d.ts +7 -0
  52. package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/tally/index.d.ts.map +1 -0
  53. package/.tsbuild/test/inspection-throttle.test.d.ts +2 -0
  54. package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
  55. package/.tsbuild/test/keyframe-reclaim-store.test.d.ts +2 -0
  56. package/.tsbuild/test/keyframe-reclaim-store.test.d.ts.map +1 -0
  57. package/.tsbuild/test/observability-signals.test.d.ts +2 -0
  58. package/.tsbuild/test/observability-signals.test.d.ts.map +1 -0
  59. package/.tsbuild/test/permissions-backfill.test.d.ts +2 -0
  60. package/.tsbuild/test/permissions-backfill.test.d.ts.map +1 -0
  61. package/.tsbuild/test/pglite-preflight.test.d.ts +2 -0
  62. package/.tsbuild/test/pglite-preflight.test.d.ts.map +1 -0
  63. package/.tsbuild/test/pglite-storage-dirs.test.d.ts +2 -0
  64. package/.tsbuild/test/pglite-storage-dirs.test.d.ts.map +1 -0
  65. package/.tsbuild/test/pglite-store.test.d.ts +2 -0
  66. package/.tsbuild/test/pglite-store.test.d.ts.map +1 -0
  67. package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
  68. package/.tsbuild/test/plugin-config-schemas.test.d.ts.map +1 -0
  69. package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
  70. package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
  71. package/.tsbuild/test/port-probe.test.d.ts +2 -0
  72. package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
  73. package/.tsbuild/test/processor-timing-log.test.d.ts +2 -0
  74. package/.tsbuild/test/processor-timing-log.test.d.ts.map +1 -0
  75. package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
  76. package/.tsbuild/test/renown-storage-path.test.d.ts.map +1 -0
  77. package/.tsbuild/test/served-schemas-mixed-package.test.d.ts +2 -0
  78. package/.tsbuild/test/served-schemas-mixed-package.test.d.ts.map +1 -0
  79. package/.tsbuild/test/served-schemas.test.d.ts +2 -0
  80. package/.tsbuild/test/served-schemas.test.d.ts.map +1 -0
  81. package/.tsbuild/test/shutdown.test.d.ts +2 -0
  82. package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
  83. package/.tsbuild/test/snapshot-writer.d.ts +18 -0
  84. package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
  85. package/.tsbuild/test/store-lock.test.d.ts +2 -0
  86. package/.tsbuild/test/store-lock.test.d.ts.map +1 -0
  87. package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
  88. package/.tsbuild/test/two-switchboards.test.d.ts.map +1 -0
  89. package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts +2 -0
  90. package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts.map +1 -0
  91. package/.tsbuild/test/workflow/runtime-host.test.d.ts +2 -0
  92. package/.tsbuild/test/workflow/runtime-host.test.d.ts.map +1 -0
  93. package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts +2 -0
  94. package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts.map +1 -0
  95. package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts +2 -0
  96. package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts.map +1 -0
  97. package/.tsbuild/test/workflow-reactor-access.test.d.ts +2 -0
  98. package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
  99. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
  100. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
  101. package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
  102. package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
  103. package/.tsbuild/tsconfig.tsbuildinfo +1 -1
  104. package/Auth.md +108 -2
  105. package/CHANGELOG.md +1066 -2
  106. package/README.md +69 -24
  107. package/dist/boot.d.mts +46 -0
  108. package/dist/boot.d.mts.map +1 -0
  109. package/dist/boot.mjs +67 -0
  110. package/dist/boot.mjs.map +1 -0
  111. package/dist/config/from-env.d.mts +15 -0
  112. package/dist/config/from-env.d.mts.map +1 -0
  113. package/dist/config/from-env.mjs +4 -0
  114. package/dist/config/schema.d.mts +3 -0
  115. package/dist/config/schema.mjs +4 -0
  116. package/dist/from-env-DKK_wPrO.mjs +497 -0
  117. package/dist/from-env-DKK_wPrO.mjs.map +1 -0
  118. package/dist/index.d.mts +1 -2
  119. package/dist/index.mjs +40 -219
  120. package/dist/index.mjs.map +1 -1
  121. package/dist/mcp-VW52B8KD.mjs +32 -0
  122. package/dist/mcp-VW52B8KD.mjs.map +1 -0
  123. package/dist/migrate.mjs +5 -4
  124. package/dist/migrate.mjs.map +1 -1
  125. package/dist/observability-CldagyT_.mjs +224 -0
  126. package/dist/observability-CldagyT_.mjs.map +1 -0
  127. package/dist/observability.d.mts +30 -0
  128. package/dist/observability.d.mts.map +1 -0
  129. package/dist/observability.mjs +4 -0
  130. package/dist/plugin-host-tTjDTNz0.d.mts +46 -0
  131. package/dist/plugin-host-tTjDTNz0.d.mts.map +1 -0
  132. package/dist/plugins/ai.d.mts +37 -0
  133. package/dist/plugins/ai.d.mts.map +1 -0
  134. package/dist/plugins/ai.mjs +400 -0
  135. package/dist/plugins/ai.mjs.map +1 -0
  136. package/dist/plugins/attachments.d.mts +33 -0
  137. package/dist/plugins/attachments.d.mts.map +1 -0
  138. package/dist/plugins/attachments.mjs +4 -0
  139. package/dist/plugins/mcp.d.mts +31 -0
  140. package/dist/plugins/mcp.d.mts.map +1 -0
  141. package/dist/plugins/mcp.mjs +4 -0
  142. package/dist/plugins/privacy.d.mts +22 -0
  143. package/dist/plugins/privacy.d.mts.map +1 -0
  144. package/dist/plugins/privacy.mjs +4 -0
  145. package/dist/plugins/workflows.d.mts +80 -0
  146. package/dist/plugins/workflows.d.mts.map +1 -0
  147. package/dist/plugins/workflows.mjs +4 -0
  148. package/dist/postgres-url-DTDhBjXX.mjs +11 -0
  149. package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
  150. package/dist/privacy-HQnhqf2H.mjs +91 -0
  151. package/dist/privacy-HQnhqf2H.mjs.map +1 -0
  152. package/dist/privacy-UodgY0i_.mjs +44 -0
  153. package/dist/privacy-UodgY0i_.mjs.map +1 -0
  154. package/dist/renown-layers-DmbWLt46.mjs +42 -0
  155. package/dist/renown-layers-DmbWLt46.mjs.map +1 -0
  156. package/dist/schema-BJ-OFAox.mjs +359 -0
  157. package/dist/schema-BJ-OFAox.mjs.map +1 -0
  158. package/dist/schema-w1lShimw.d.mts +258 -0
  159. package/dist/schema-w1lShimw.d.mts.map +1 -0
  160. package/dist/server-BS-PFzoK.mjs +2752 -0
  161. package/dist/server-BS-PFzoK.mjs.map +1 -0
  162. package/dist/server.d.mts +94 -228
  163. package/dist/server.d.mts.map +1 -1
  164. package/dist/server.mjs +5 -4
  165. package/dist/types-Bk4T4D9F.d.mts +318 -0
  166. package/dist/types-Bk4T4D9F.d.mts.map +1 -0
  167. package/dist/utils-Cm0TE6dP.mjs +148 -0
  168. package/dist/utils-Cm0TE6dP.mjs.map +1 -0
  169. package/dist/utils.d.mts +29 -3
  170. package/dist/utils.d.mts.map +1 -1
  171. package/dist/utils.mjs +5 -4
  172. package/dist/worker-pool-gyxJnCxA.mjs +304 -0
  173. package/dist/worker-pool-gyxJnCxA.mjs.map +1 -0
  174. package/dist/workflow-runtime-CF5pc8mt.d.mts +33 -0
  175. package/dist/workflow-runtime-CF5pc8mt.d.mts.map +1 -0
  176. package/dist/workflows-mdYUh3Us.mjs +1947 -0
  177. package/dist/workflows-mdYUh3Us.mjs.map +1 -0
  178. package/package.json +86 -24
  179. package/scripts/install-packages.sh +0 -0
  180. package/test/ai-gateway.test.ts +612 -0
  181. package/test/attachment-reference-read-model.test.ts +28 -20
  182. package/test/attachments/byte-grants.test.ts +4 -1
  183. package/test/attachments/download-target.test.ts +36 -20
  184. package/test/attachments/index.test.ts +13 -1
  185. package/test/attachments/reserve-metadata-parity.test.ts +96 -0
  186. package/test/attachments/routes-integration.test.ts +1 -0
  187. package/test/attachments/routes.test.ts +132 -12
  188. package/test/attachments/service-config.test.ts +28 -16
  189. package/test/boot-auth-config.test.ts +146 -0
  190. package/test/boot-create-signature-policy.test.ts +15 -13
  191. package/test/boot-desktop-auth.test.ts +278 -0
  192. package/test/boot-env-isolation.test.ts +26 -0
  193. package/test/boot-helpers.ts +19 -0
  194. package/test/boot-inspection-enabled.test.ts +140 -0
  195. package/test/boot-mcp-auth.test.ts +449 -0
  196. package/test/boot-mcp-enabled.test.ts +27 -27
  197. package/test/boot-port-zero.test.ts +101 -0
  198. package/test/boot-preconditions.test.ts +213 -0
  199. package/test/boot-privacy.test.ts +232 -0
  200. package/test/boot-ready-drives.test.ts +141 -0
  201. package/test/boot-undo-v3-flag.test.ts +120 -0
  202. package/test/boot-unsupported-stored-documents.test.ts +23 -19
  203. package/test/boot-without-renown.test.ts +11 -9
  204. package/test/boot-without-require-signatures.test.ts +12 -10
  205. package/test/boot-worker-trust-policy.test.ts +11 -10
  206. package/test/boot-workflow-singleton-conflict.test.ts +109 -0
  207. package/test/boot-workflow-singleton-retry.test.ts +122 -0
  208. package/test/config-from-env.test.ts +968 -0
  209. package/test/config-merge.test.ts +351 -0
  210. package/test/config-schema.test.ts +183 -0
  211. package/test/default-composition.test.ts +290 -0
  212. package/test/default-drive-protocol-versions.test.ts +79 -0
  213. package/test/default-drive-slug.test.ts +265 -0
  214. package/test/delegated-publish.test.ts +435 -0
  215. package/test/durable-node-fs-pg16.test.ts +80 -0
  216. package/test/fatal-shutdown.test.ts +104 -1
  217. package/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.ts +16 -0
  218. package/test/fixtures/mixed-subgraphs/subgraphs/index.ts +3 -0
  219. package/test/fixtures/mixed-subgraphs/subgraphs/tally/index.ts +73 -0
  220. package/test/goldens/packages.graphql +797 -0
  221. package/test/goldens/privacy.graphql +853 -0
  222. package/test/goldens/reactor-drive-nodes.graphql +827 -0
  223. package/test/goldens/resolvers.json +327 -0
  224. package/test/goldens/supergraph.graphql +5918 -0
  225. package/test/goldens/workflow-runtime.graphql +1548 -0
  226. package/test/inspection-throttle.test.ts +23 -0
  227. package/test/keyframe-reclaim-store.test.ts +156 -0
  228. package/test/observability-signals.test.ts +131 -0
  229. package/test/permissions-backfill.test.ts +486 -0
  230. package/test/pglite-dialect.test.ts +237 -2
  231. package/test/pglite-preflight.test.ts +313 -0
  232. package/test/pglite-storage-dirs.test.ts +113 -0
  233. package/test/pglite-store.test.ts +441 -0
  234. package/test/pglite-version.test.ts +9 -1
  235. package/test/plugin-config-schemas.test.ts +83 -0
  236. package/test/plugin-presence.test.ts +262 -0
  237. package/test/port-probe.test.ts +45 -0
  238. package/test/processor-timing-log.test.ts +109 -0
  239. package/test/reactor-feature-flags.test.ts +20 -0
  240. package/test/redact-webhook-path.test.ts +9 -0
  241. package/test/renown-storage-path.test.ts +40 -0
  242. package/test/renown-trust-policy.test.ts +7 -9
  243. package/test/served-schemas-mixed-package.test.ts +251 -0
  244. package/test/served-schemas.test.ts +134 -0
  245. package/test/shutdown.test.ts +278 -0
  246. package/test/snapshot-writer.ts +94 -0
  247. package/test/store-lock.test.ts +65 -0
  248. package/test/two-switchboards.test.ts +146 -0
  249. package/test/worker-pool.test.ts +27 -1
  250. package/test/workflow/oauth-apps-config.test.ts +66 -0
  251. package/test/workflow/oauth.test.ts +82 -10
  252. package/test/workflow/resolvers.test.ts +230 -38
  253. package/test/workflow/runtime-host.test.ts +19 -0
  254. package/test/workflow/waitpoint-routes.test.ts +306 -0
  255. package/test/workflow/waitpoint-runtime.test.ts +204 -0
  256. package/test/workflow/webhook-trigger-test.test.ts +8 -0
  257. package/test/workflow-reactor-access.test.ts +384 -0
  258. package/test/workflow-reactor-enforcement.test.ts +808 -0
  259. package/test/workflow-read-gate.test.ts +128 -60
  260. package/test/workflow-runtime.test.ts +1005 -237
  261. package/test/workflows-plugin-config.test.ts +77 -0
  262. package/tsconfig.json +5 -2
  263. package/tsdown.config.ts +12 -0
  264. package/vitest.config.ts +66 -1
  265. package/.tsbuild/test/mcp-flag.test.d.ts +0 -2
  266. package/.tsbuild/test/mcp-flag.test.d.ts.map +0 -1
  267. package/dist/server-sQoWp21G.mjs +0 -2939
  268. package/dist/server-sQoWp21G.mjs.map +0 -1
  269. package/dist/utils-uaBlzyjS.mjs +0 -86
  270. package/dist/utils-uaBlzyjS.mjs.map +0 -1
  271. package/test/mcp-flag.test.ts +0 -56
@@ -0,0 +1,351 @@
1
+ import type { ILogger } from "document-model";
2
+ import { describe, expect, it } from "vitest";
3
+ import { binSwitchboardConfig } from "../src/config/bin.js";
4
+ import { switchboardConfigFromEnv } from "../src/config/from-env.js";
5
+ import {
6
+ callerOverEnv,
7
+ mergeSwitchboardConfig,
8
+ switchboardConfigSchema,
9
+ type SwitchboardConfig,
10
+ type SwitchboardConfigInput,
11
+ } from "../src/config/schema.js";
12
+
13
+ type Env = Record<string, string | undefined>;
14
+
15
+ const silent = { warn: () => undefined } as unknown as ILogger;
16
+
17
+ function resolved(env: Env, caller: SwitchboardConfigInput): SwitchboardConfig {
18
+ return switchboardConfigSchema.parse(
19
+ callerOverEnv(switchboardConfigFromEnv(env, { logger: silent }), caller),
20
+ );
21
+ }
22
+
23
+ describe("mergeSwitchboardConfig", () => {
24
+ it("lets a later layer win per key and keeps the rest", () => {
25
+ expect(
26
+ mergeSwitchboardConfig(
27
+ { server: { port: 1, basePath: "/a" }, logLevel: "debug" },
28
+ { server: { port: 2 } },
29
+ { server: { port: undefined } },
30
+ ),
31
+ ).toEqual({ server: { port: 2, basePath: "/a" }, logLevel: "debug" });
32
+ });
33
+
34
+ it("replaces arrays, maps and the attachment storage whole", () => {
35
+ const s3 = {
36
+ kind: "s3" as const,
37
+ s3: {
38
+ endpoint: "e",
39
+ region: "r",
40
+ bucket: "b",
41
+ accessKeyId: "a",
42
+ secretAccessKey: "s",
43
+ prefix: "p",
44
+ forcePathStyle: false,
45
+ uploadTtlSeconds: 1,
46
+ downloadTtlSeconds: 1,
47
+ },
48
+ };
49
+ const processorConfig = new Map([["b", 2]]);
50
+ expect(
51
+ mergeSwitchboardConfig(
52
+ {
53
+ auth: { admins: ["0xa", "0xb"] },
54
+ attachments: { storage: s3 },
55
+ processorConfig: new Map([["a", 1]]),
56
+ },
57
+ {
58
+ auth: { admins: ["0xc"] },
59
+ attachments: { storage: { kind: "filesystem" } },
60
+ processorConfig,
61
+ },
62
+ ),
63
+ ).toEqual({
64
+ auth: { admins: ["0xc"] },
65
+ attachments: { storage: { kind: "filesystem" } },
66
+ processorConfig,
67
+ });
68
+ });
69
+ });
70
+
71
+ describe("callerOverEnv keeps each key's precedence", () => {
72
+ it("lets the caller win an ordinary key", () => {
73
+ const config = resolved(
74
+ {
75
+ PH_REGISTRY_URL: "https://env",
76
+ PH_PGLITE_WORKERS: "true",
77
+ PH_WORKFLOWS_ENABLED: "1",
78
+ DATABASE_URL: "/env/read",
79
+ PH_REACTOR_DATABASE_URL: "/env/reactor",
80
+ },
81
+ {
82
+ packages: { registryUrl: "https://caller" },
83
+ storage: {
84
+ pglite: { workers: false },
85
+ readModel: { url: "/caller" },
86
+ reactor: { url: "/caller" },
87
+ },
88
+ features: { workflows: false },
89
+ },
90
+ );
91
+ expect(config.packages.registryUrl).toBe("https://caller");
92
+ expect(config.storage.pglite.workers).toBe(false);
93
+ expect(config.features.workflows).toBe(false);
94
+ expect(config.storage.readModel.url).toBe("/caller");
95
+ expect(config.storage.reactor.url).toBe("/caller");
96
+ });
97
+
98
+ it("falls back to the env where the caller says nothing", () => {
99
+ const config = resolved(
100
+ { PH_PGLITE_WORKERS: "false", PH_WORKFLOWS_ENABLED: "0" },
101
+ {},
102
+ );
103
+ expect(config.storage.pglite.workers).toBe(false);
104
+ expect(config.features.workflows).toBe(false);
105
+ });
106
+
107
+ it("lets DOCUMENT_MODEL_SUBGRAPHS_ENABLED win over the caller", () => {
108
+ expect(
109
+ resolved(
110
+ { DOCUMENT_MODEL_SUBGRAPHS_ENABLED: "false" },
111
+ { features: { documentModelSubgraphs: true } },
112
+ ).features.documentModelSubgraphs,
113
+ ).toBe(false);
114
+ expect(
115
+ resolved({}, { features: { documentModelSubgraphs: false } }).features
116
+ .documentModelSubgraphs,
117
+ ).toBe(false);
118
+ });
119
+
120
+ it("lets reactor-api's overriding auth env vars win over the caller", () => {
121
+ const { auth } = resolved(
122
+ {
123
+ AUTH_ENABLED: "false",
124
+ ADMINS: "0xEnv",
125
+ RESOLVE_CALLER_IDENTITY: "false",
126
+ REQUIRE_AUTHENTICATED_CALLER: "false",
127
+ REQUIRE_AUTHENTICATED_CALLER_EXEMPT_PATHS: "/env",
128
+ ATTACHMENT_READS_FOLLOW_DOCUMENT_POLICY: "false",
129
+ DEFAULT_PROTECTION: "false",
130
+ },
131
+ {
132
+ auth: {
133
+ enabled: true,
134
+ admins: ["0xcaller"],
135
+ resolveIdentity: true,
136
+ requireAuthenticatedCaller: true,
137
+ requireAuthenticatedCallerExemptPaths: ["/caller"],
138
+ attachmentReadsFollowDocumentPolicy: true,
139
+ defaultProtection: true,
140
+ },
141
+ },
142
+ );
143
+ expect(auth).toMatchObject({
144
+ enabled: false,
145
+ admins: ["0xenv"],
146
+ resolveIdentity: false,
147
+ requireAuthenticatedCaller: false,
148
+ requireAuthenticatedCallerExemptPaths: ["/env"],
149
+ attachmentReadsFollowDocumentPolicy: false,
150
+ // An ordinary key: the caller wins.
151
+ defaultProtection: true,
152
+ });
153
+ });
154
+
155
+ it("lets each ACCESS env var win over the caller's access, key by key", () => {
156
+ const { auth } = resolved(
157
+ {
158
+ ACCESS: "licensed",
159
+ VETRA_GATE_TOKEN: "vgt_env",
160
+ },
161
+ {
162
+ auth: {
163
+ access: {
164
+ mode: "open",
165
+ gateUrl: "https://vetra.example/gate",
166
+ gateToken: "vgt_caller",
167
+ },
168
+ },
169
+ },
170
+ );
171
+ expect(auth.access).toEqual({
172
+ mode: "licensed",
173
+ gateUrl: "https://vetra.example/gate",
174
+ gateToken: "vgt_env",
175
+ });
176
+ });
177
+
178
+ it("keeps the caller's access when no ACCESS env var is set", () => {
179
+ const { auth } = resolved(
180
+ {},
181
+ { auth: { access: { mode: "licensed", gateToken: "vgt_caller" } } },
182
+ );
183
+ expect(auth.access).toEqual({ mode: "licensed", gateToken: "vgt_caller" });
184
+ });
185
+
186
+ it.each([
187
+ [{}, undefined, true],
188
+ [{ MCP_ENABLED: "false" }, undefined, false],
189
+ [{ MCP_ENABLED: "false" }, true, false],
190
+ [{ MCP_ENABLED: "true" }, false, false],
191
+ [{ MCP_ENABLED: "yes" }, undefined, true],
192
+ [{}, false, false],
193
+ ] as const)(
194
+ "MCP: env %o with the caller's %s mounts it: %s",
195
+ (env, mcp, mounted) => {
196
+ expect(resolved(env, { features: { mcp } }).features.mcp ?? true).toBe(
197
+ mounted,
198
+ );
199
+ },
200
+ );
201
+
202
+ it.each([
203
+ [{}, undefined, true],
204
+ [{ INSPECTION_ENABLED: "false" }, undefined, false],
205
+ [{ INSPECTION_ENABLED: "false" }, true, false],
206
+ [{ INSPECTION_ENABLED: "true" }, false, false],
207
+ [{ INSPECTION_ENABLED: "0" }, undefined, true],
208
+ [{ INSPECTION_ENABLED: "true" }, undefined, true],
209
+ ] as const)(
210
+ "inspection: env %o with the caller's %s mounts it: %s",
211
+ (env, enabled, mounted) => {
212
+ expect(
213
+ resolved(env, { inspection: { enabled } }).inspection.enabled,
214
+ ).toBe(mounted);
215
+ },
216
+ );
217
+
218
+ it("lets PH_WORKFLOWS_ENABLED switch workflows off under the plugin host", () => {
219
+ const env = {
220
+ FEATURE_PLUGIN_HOST_ENABLED: "1",
221
+ PH_WORKFLOWS_ENABLED: "false",
222
+ };
223
+ expect(resolved(env, {}).features.workflows).toBe(false);
224
+ expect(
225
+ resolved(env, { features: { workflows: true } }).features.workflows,
226
+ ).toBe(false);
227
+ });
228
+
229
+ it("ignores an env true for MCP_ENABLED and PH_WORKFLOWS_ENABLED under the plugin host", () => {
230
+ const env = {
231
+ FEATURE_PLUGIN_HOST_ENABLED: "1",
232
+ MCP_ENABLED: "true",
233
+ PH_WORKFLOWS_ENABLED: "true",
234
+ };
235
+ const host = resolved(env, {});
236
+ expect(host.features.pluginHost).toBe(true);
237
+ expect(host.features.mcp).toBeUndefined();
238
+ expect(host.features.workflows).toBeUndefined();
239
+ const withCaller = resolved(env, {
240
+ features: { mcp: false, workflows: true },
241
+ });
242
+ expect(withCaller.features.mcp).toBe(false);
243
+ expect(withCaller.features.workflows).toBe(true);
244
+ // Not carved: classic on both paths.
245
+ expect(
246
+ resolved({ ...env, INSPECTION_ENABLED: "false" }, {}).inspection.enabled,
247
+ ).toBe(false);
248
+ });
249
+ });
250
+
251
+ describe("an env false always wins", () => {
252
+ const host = { FEATURE_PLUGIN_HOST_ENABLED: "1" };
253
+
254
+ it("MCP_ENABLED=false beats a caller's mcp, classic and plugin host", () => {
255
+ const caller = { features: { mcp: true } };
256
+ expect(resolved({ MCP_ENABLED: "false" }, caller).features.mcp).toBe(false);
257
+ expect(
258
+ resolved({ ...host, MCP_ENABLED: "false" }, caller).features.mcp,
259
+ ).toBe(false);
260
+ expect(resolved({ ...host, MCP_ENABLED: "false" }, {}).features.mcp).toBe(
261
+ false,
262
+ );
263
+ });
264
+
265
+ it("MCP_ENABLED=false beats the bin's own features.mcp under the plugin host", () => {
266
+ const config = switchboardConfigSchema.parse(
267
+ binSwitchboardConfig(
268
+ { ...host, MCP_ENABLED: "false" },
269
+ { migratePglite: false, logger: silent },
270
+ ),
271
+ );
272
+ expect(config.features.pluginHost).toBe(true);
273
+ expect(config.features.mcp).toBe(false);
274
+ });
275
+
276
+ it("DOCUMENT_MODEL_SUBGRAPHS_ENABLED=false beats a caller's, classic and plugin host", () => {
277
+ const caller = { features: { documentModelSubgraphs: true } };
278
+ const env = { DOCUMENT_MODEL_SUBGRAPHS_ENABLED: "false" };
279
+ expect(resolved(env, caller).features.documentModelSubgraphs).toBe(false);
280
+ expect(
281
+ resolved({ ...host, ...env }, caller).features.documentModelSubgraphs,
282
+ ).toBe(false);
283
+ });
284
+
285
+ it("PH_WORKFLOWS_ENABLED=false beats a caller's, classic and plugin host", () => {
286
+ const caller = { features: { workflows: true } };
287
+ expect(
288
+ resolved({ PH_WORKFLOWS_ENABLED: "false" }, caller).features.workflows,
289
+ ).toBe(false);
290
+ expect(
291
+ resolved({ ...host, PH_WORKFLOWS_ENABLED: "false" }, caller).features
292
+ .workflows,
293
+ ).toBe(false);
294
+ });
295
+
296
+ it("PH_PRIVACY_ENABLED=false beats a caller's, classic and plugin host", () => {
297
+ const caller = {
298
+ features: {
299
+ privacy: { enabled: true, deploymentSecret: "x".repeat(32) },
300
+ },
301
+ };
302
+ const env = { PH_PRIVACY_ENABLED: "false" };
303
+ expect(resolved(env, caller).features.privacy.enabled).toBe(false);
304
+ expect(resolved({ ...host, ...env }, caller).features.privacy.enabled).toBe(
305
+ false,
306
+ );
307
+ expect(
308
+ resolved({ PH_PRIVACY_ENABLED: "true" }, caller).features.privacy.enabled,
309
+ ).toBe(true);
310
+ });
311
+
312
+ it("INSPECTION_ENABLED=false beats a caller's, classic and plugin host", () => {
313
+ const caller = { inspection: { enabled: true } };
314
+ const env = { INSPECTION_ENABLED: "false" };
315
+ expect(resolved(env, caller).inspection.enabled).toBe(false);
316
+ expect(resolved({ ...host, ...env }, caller).inspection.enabled).toBe(
317
+ false,
318
+ );
319
+ });
320
+ });
321
+
322
+ describe("startSwitchboard", () => {
323
+ it("refuses the old options shape instead of booting on defaults", async () => {
324
+ const { startSwitchboard } = await import("../src/server.mjs");
325
+ await expect(
326
+ startSwitchboard({ port: 0, dbPath: "x" } as SwitchboardConfigInput),
327
+ ).rejects.toThrow("unknown config keys: port, dbPath");
328
+ });
329
+ });
330
+
331
+ describe("packages.hostValidation", () => {
332
+ it("defaults to log", () => {
333
+ expect(resolved({}, {}).packages.hostValidation).toBe("log");
334
+ });
335
+
336
+ it("reads PH_HOST_VALIDATION and a caller's config", () => {
337
+ expect(
338
+ resolved({ PH_HOST_VALIDATION: " refuse " }, {}).packages.hostValidation,
339
+ ).toBe("refuse");
340
+ expect(
341
+ resolved({}, { packages: { hostValidation: "refuse" } }).packages
342
+ .hostValidation,
343
+ ).toBe("refuse");
344
+ });
345
+
346
+ it("refuses an unknown PH_HOST_VALIDATION", () => {
347
+ expect(() => resolved({ PH_HOST_VALIDATION: "strict" }, {})).toThrow(
348
+ 'PH_HOST_VALIDATION must be "log" or "refuse", got "strict"',
349
+ );
350
+ });
351
+ });
@@ -0,0 +1,183 @@
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
+ privacy: { enabled: false },
64
+ });
65
+ // Unset is its own state: the plugin host with the default composition.
66
+ expect(config.features.pluginHost).toBeUndefined();
67
+ expect(config.attachments).toEqual({ storage: { kind: "filesystem" } });
68
+ expect(config.auth.documentPermissions).toEqual({ enabled: false });
69
+ expect(config.auth.access).toEqual({ mode: "open" });
70
+ });
71
+
72
+ it("refuses ACCESS=members, pointing at licensed", () => {
73
+ expect(() =>
74
+ switchboardConfigSchema.parse({ auth: { access: { mode: "members" } } }),
75
+ ).toThrow(
76
+ "ACCESS=members is not supported; use ACCESS=licensed with Vetra's gate",
77
+ );
78
+ });
79
+
80
+ it("refuses an unknown ACCESS by name", () => {
81
+ expect(() =>
82
+ switchboardConfigSchema.parse({ auth: { access: { mode: "everyone" } } }),
83
+ ).toThrow("ACCESS=everyone is not supported");
84
+ });
85
+
86
+ it("keeps the defaults beside a nested value a layer sets", () => {
87
+ const layer: SwitchboardConfigInput = {
88
+ workers: { executor: { count: "auto" } },
89
+ storage: { pglite: { vacuumFull: { mode: "quiet" } } },
90
+ };
91
+ const config = switchboardConfigSchema.parse(layer);
92
+ expect(config.workers.executor).toEqual({
93
+ count: "auto",
94
+ poolSize: 2,
95
+ acquireTimeoutMs: 5000,
96
+ });
97
+ expect(config.workers.hostPoolSize).toBe(16);
98
+ expect(config.storage.pglite).toEqual({
99
+ fsync: true,
100
+ workers: true,
101
+ vacuumFull: { mode: "quiet" },
102
+ });
103
+ });
104
+
105
+ it("leaves undoV3 to the reactor unless a layer sets it", () => {
106
+ expect(
107
+ switchboardConfigSchema.parse({}).protocol.featureFlags,
108
+ ).not.toHaveProperty("undoV3");
109
+ expect(
110
+ switchboardConfigSchema.parse({
111
+ protocol: { featureFlags: { undoV3: false } },
112
+ }).protocol.featureFlags.undoV3,
113
+ ).toBe(false);
114
+ });
115
+
116
+ it.each<[string, SwitchboardConfigInput]>([
117
+ ["a port out of range", { server: { port: 70000 } }],
118
+ ["a fractional worker count", { workers: { executor: { count: 1.5 } } }],
119
+ ["a host pool of 0", { workers: { hostPoolSize: 0 } }],
120
+ ["a catch-up level above 7", { protocol: { catchUpPriority: 8 } }],
121
+ [
122
+ "an unknown timing level",
123
+ { protocol: { processorTiming: "full" as never } },
124
+ ],
125
+ [
126
+ "a sampling interval under a second",
127
+ { telemetry: { memory: { intervalMs: 10 } } },
128
+ ],
129
+ [
130
+ "an unknown memory output",
131
+ { telemetry: { memory: { outputs: ["otel" as never] } } },
132
+ ],
133
+ [
134
+ "an unknown signature policy",
135
+ { protocol: { createSignaturePolicy: "v3" as "legacy" } },
136
+ ],
137
+ ["a PG major it does not ship", { storage: { forcePgVersion: 15 as 16 } }],
138
+ ])("refuses %s", (_name, layer) => {
139
+ expect(switchboardConfigSchema.safeParse(layer).success).toBe(false);
140
+ });
141
+ });
142
+
143
+ describe("the config modules", () => {
144
+ it("load without the server", async () => {
145
+ vi.doMock("../src/server.mjs", () => {
146
+ throw new Error("the server was loaded");
147
+ });
148
+ await expect(import("../src/config/from-env.js")).resolves.toBeDefined();
149
+ vi.doUnmock("../src/server.mjs");
150
+ });
151
+ });
152
+
153
+ describe("switchboardConfigLayerSchema", () => {
154
+ const layer = switchboardConfigLayerSchema(["server.port", "drive"]);
155
+
156
+ it("keeps a layer as written, without defaults", () => {
157
+ expect(layer.parse({})).toEqual({});
158
+ expect(layer.parse({ auth: { enabled: true } })).toEqual({
159
+ auth: { enabled: true },
160
+ });
161
+ });
162
+
163
+ it("validates values and refuses unknown or omitted keys", () => {
164
+ expect(
165
+ layer.safeParse({ workers: { executor: { count: "auto" } } }),
166
+ ).toMatchObject({ success: true });
167
+ expect(
168
+ layer.safeParse({ workers: { executor: { count: -1 } } }).success,
169
+ ).toBe(false);
170
+ expect(layer.safeParse({ auth: { enabeld: true } }).success).toBe(false);
171
+ expect(layer.safeParse({ server: { port: 1 } }).success).toBe(false);
172
+ expect(layer.safeParse({ drive: {} }).success).toBe(false);
173
+ expect(layer.safeParse({ server: { basePath: "/x" } }).success).toBe(true);
174
+ });
175
+
176
+ it("emits a JSON Schema once the map key is omitted", () => {
177
+ const schema = z.toJSONSchema(
178
+ switchboardConfigLayerSchema(["processorConfig"]),
179
+ { io: "input" },
180
+ );
181
+ expect(schema).toMatchObject({ additionalProperties: false });
182
+ });
183
+ });