@powerhousedao/switchboard 6.2.3-dev.8 → 6.2.3-dev.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. package/.tsbuild/test/attachments/byte-grants.test.d.ts +2 -0
  2. package/.tsbuild/test/attachments/byte-grants.test.d.ts.map +1 -0
  3. package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts +2 -0
  4. package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts.map +1 -0
  5. package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts +2 -0
  6. package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts.map +1 -0
  7. package/.tsbuild/test/attachments/url-signer.test.d.ts +2 -0
  8. package/.tsbuild/test/attachments/url-signer.test.d.ts.map +1 -0
  9. package/.tsbuild/test/boot-auth-config.test.d.ts +2 -0
  10. package/.tsbuild/test/boot-auth-config.test.d.ts.map +1 -0
  11. package/.tsbuild/test/boot-create-signature-policy.test.d.ts +2 -0
  12. package/.tsbuild/test/boot-create-signature-policy.test.d.ts.map +1 -0
  13. package/.tsbuild/test/boot-env-isolation.test.d.ts +2 -0
  14. package/.tsbuild/test/boot-env-isolation.test.d.ts.map +1 -0
  15. package/.tsbuild/test/boot-helpers.d.ts +5 -0
  16. package/.tsbuild/test/boot-helpers.d.ts.map +1 -0
  17. package/.tsbuild/test/boot-inspection-enabled.test.d.ts +2 -0
  18. package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
  19. package/.tsbuild/test/boot-mcp-auth.test.d.ts +2 -0
  20. package/.tsbuild/test/boot-mcp-auth.test.d.ts.map +1 -0
  21. package/.tsbuild/test/boot-mcp-enabled.test.d.ts +2 -0
  22. package/.tsbuild/test/boot-mcp-enabled.test.d.ts.map +1 -0
  23. package/.tsbuild/test/boot-port-zero.test.d.ts +2 -0
  24. package/.tsbuild/test/boot-port-zero.test.d.ts.map +1 -0
  25. package/.tsbuild/test/boot-preconditions.test.d.ts +2 -0
  26. package/.tsbuild/test/boot-preconditions.test.d.ts.map +1 -0
  27. package/.tsbuild/test/boot-privacy.test.d.ts +2 -0
  28. package/.tsbuild/test/boot-privacy.test.d.ts.map +1 -0
  29. package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts +2 -0
  30. package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts.map +1 -0
  31. package/.tsbuild/test/boot-without-renown.test.d.ts +2 -0
  32. package/.tsbuild/test/boot-without-renown.test.d.ts.map +1 -0
  33. package/.tsbuild/test/boot-without-require-signatures.test.d.ts +2 -0
  34. package/.tsbuild/test/boot-without-require-signatures.test.d.ts.map +1 -0
  35. package/.tsbuild/test/boot-worker-trust-policy.test.d.ts +2 -0
  36. package/.tsbuild/test/boot-worker-trust-policy.test.d.ts.map +1 -0
  37. package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts +2 -0
  38. package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts.map +1 -0
  39. package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts +2 -0
  40. package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts.map +1 -0
  41. package/.tsbuild/test/builder-defaults.test.d.ts +2 -0
  42. package/.tsbuild/test/builder-defaults.test.d.ts.map +1 -0
  43. package/.tsbuild/test/config-from-env.test.d.ts +2 -0
  44. package/.tsbuild/test/config-from-env.test.d.ts.map +1 -0
  45. package/.tsbuild/test/config-merge.test.d.ts +2 -0
  46. package/.tsbuild/test/config-merge.test.d.ts.map +1 -0
  47. package/.tsbuild/test/config-schema.test.d.ts +2 -0
  48. package/.tsbuild/test/config-schema.test.d.ts.map +1 -0
  49. package/.tsbuild/test/create-signature-policy.test.d.ts +2 -0
  50. package/.tsbuild/test/create-signature-policy.test.d.ts.map +1 -0
  51. package/.tsbuild/test/default-drive-protocol-versions.test.d.ts +2 -0
  52. package/.tsbuild/test/default-drive-protocol-versions.test.d.ts.map +1 -0
  53. package/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
  54. package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
  55. package/.tsbuild/test/durable-node-fs-pg16.test.d.ts +2 -0
  56. package/.tsbuild/test/durable-node-fs-pg16.test.d.ts.map +1 -0
  57. package/.tsbuild/test/fatal-shutdown.test.d.ts +2 -0
  58. package/.tsbuild/test/fatal-shutdown.test.d.ts.map +1 -0
  59. package/.tsbuild/test/inspection-throttle.test.d.ts +2 -0
  60. package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
  61. package/.tsbuild/test/observability-signals.test.d.ts +2 -0
  62. package/.tsbuild/test/observability-signals.test.d.ts.map +1 -0
  63. package/.tsbuild/test/permissions-backfill.test.d.ts +2 -0
  64. package/.tsbuild/test/permissions-backfill.test.d.ts.map +1 -0
  65. package/.tsbuild/test/pglite-preflight.test.d.ts +2 -0
  66. package/.tsbuild/test/pglite-preflight.test.d.ts.map +1 -0
  67. package/.tsbuild/test/pglite-storage-dirs.test.d.ts +2 -0
  68. package/.tsbuild/test/pglite-storage-dirs.test.d.ts.map +1 -0
  69. package/.tsbuild/test/pglite-store.test.d.ts +2 -0
  70. package/.tsbuild/test/pglite-store.test.d.ts.map +1 -0
  71. package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
  72. package/.tsbuild/test/plugin-config-schemas.test.d.ts.map +1 -0
  73. package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
  74. package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
  75. package/.tsbuild/test/port-probe.test.d.ts +2 -0
  76. package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
  77. package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
  78. package/.tsbuild/test/renown-storage-path.test.d.ts.map +1 -0
  79. package/.tsbuild/test/renown-trust-policy.test.d.ts +2 -0
  80. package/.tsbuild/test/renown-trust-policy.test.d.ts.map +1 -0
  81. package/.tsbuild/test/served-schemas.test.d.ts +2 -0
  82. package/.tsbuild/test/served-schemas.test.d.ts.map +1 -0
  83. package/.tsbuild/test/shutdown.test.d.ts +2 -0
  84. package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
  85. package/.tsbuild/test/snapshot-writer.d.ts +18 -0
  86. package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
  87. package/.tsbuild/test/store-lock.test.d.ts +2 -0
  88. package/.tsbuild/test/store-lock.test.d.ts.map +1 -0
  89. package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
  90. package/.tsbuild/test/two-switchboards.test.d.ts.map +1 -0
  91. package/.tsbuild/test/unsupported-stored-documents.test.d.ts +2 -0
  92. package/.tsbuild/test/unsupported-stored-documents.test.d.ts.map +1 -0
  93. package/.tsbuild/test/workflow/harness.d.ts +56 -0
  94. package/.tsbuild/test/workflow/harness.d.ts.map +1 -0
  95. package/.tsbuild/test/workflow/oauth.test.d.ts +2 -0
  96. package/.tsbuild/test/workflow/oauth.test.d.ts.map +1 -0
  97. package/.tsbuild/test/workflow/resolvers.test.d.ts +2 -0
  98. package/.tsbuild/test/workflow/resolvers.test.d.ts.map +1 -0
  99. package/.tsbuild/test/workflow/runtime-host.test.d.ts +2 -0
  100. package/.tsbuild/test/workflow/runtime-host.test.d.ts.map +1 -0
  101. package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts +2 -0
  102. package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts.map +1 -0
  103. package/.tsbuild/test/workflow/webhook-signed.test.d.ts +2 -0
  104. package/.tsbuild/test/workflow/webhook-signed.test.d.ts.map +1 -0
  105. package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts +2 -0
  106. package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts.map +1 -0
  107. package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts +2 -0
  108. package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts.map +1 -0
  109. package/.tsbuild/test/workflow-reactor-access.test.d.ts +2 -0
  110. package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
  111. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
  112. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
  113. package/.tsbuild/test/workflow-read-gate.test.d.ts +2 -0
  114. package/.tsbuild/test/workflow-read-gate.test.d.ts.map +1 -0
  115. package/.tsbuild/test/workflow-runtime.test.d.ts +2 -0
  116. package/.tsbuild/test/workflow-runtime.test.d.ts.map +1 -0
  117. package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
  118. package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
  119. package/.tsbuild/tsconfig.tsbuildinfo +1 -1
  120. package/.tsbuild/tsdown.config.d.ts.map +1 -1
  121. package/.tsbuild/vitest.config.d.ts.map +1 -1
  122. package/Auth.md +144 -2
  123. package/CHANGELOG.md +1074 -0
  124. package/README.md +55 -14
  125. package/dist/boot.d.mts +46 -0
  126. package/dist/boot.d.mts.map +1 -0
  127. package/dist/boot.mjs +67 -0
  128. package/dist/boot.mjs.map +1 -0
  129. package/dist/config/from-env.d.mts +15 -0
  130. package/dist/config/from-env.d.mts.map +1 -0
  131. package/dist/config/from-env.mjs +4 -0
  132. package/dist/config/schema.d.mts +3 -0
  133. package/dist/config/schema.mjs +4 -0
  134. package/dist/from-env-BO0n9R02.mjs +401 -0
  135. package/dist/from-env-BO0n9R02.mjs.map +1 -0
  136. package/dist/index.d.mts +2 -1
  137. package/dist/index.mjs +76 -79
  138. package/dist/index.mjs.map +1 -1
  139. package/dist/install-packages.d.mts +2 -1
  140. package/dist/install-packages.mjs +2 -2
  141. package/dist/install-packages.mjs.map +1 -1
  142. package/dist/mcp-SsBK14Jm.mjs +32 -0
  143. package/dist/mcp-SsBK14Jm.mjs.map +1 -0
  144. package/dist/migrate.d.mts +2 -1
  145. package/dist/migrate.mjs +7 -5
  146. package/dist/migrate.mjs.map +1 -1
  147. package/dist/plugin-host-C1sYEm8g.d.mts +46 -0
  148. package/dist/plugin-host-C1sYEm8g.d.mts.map +1 -0
  149. package/dist/plugins/attachments.d.mts +33 -0
  150. package/dist/plugins/attachments.d.mts.map +1 -0
  151. package/dist/plugins/attachments.mjs +4 -0
  152. package/dist/plugins/mcp.d.mts +31 -0
  153. package/dist/plugins/mcp.d.mts.map +1 -0
  154. package/dist/plugins/mcp.mjs +4 -0
  155. package/dist/plugins/privacy.d.mts +22 -0
  156. package/dist/plugins/privacy.d.mts.map +1 -0
  157. package/dist/plugins/privacy.mjs +4 -0
  158. package/dist/plugins/workflows.d.mts +79 -0
  159. package/dist/plugins/workflows.d.mts.map +1 -0
  160. package/dist/plugins/workflows.mjs +4 -0
  161. package/dist/postgres-url-DTDhBjXX.mjs +11 -0
  162. package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
  163. package/dist/privacy-BO8Q25xI.mjs +44 -0
  164. package/dist/privacy-BO8Q25xI.mjs.map +1 -0
  165. package/dist/privacy-DxIJGH4P.mjs +91 -0
  166. package/dist/privacy-DxIJGH4P.mjs.map +1 -0
  167. package/dist/renown-layers-COZsrGQT.mjs +40 -0
  168. package/dist/renown-layers-COZsrGQT.mjs.map +1 -0
  169. package/dist/schema-0g_QdOWn.mjs +267 -0
  170. package/dist/schema-0g_QdOWn.mjs.map +1 -0
  171. package/dist/schema-ivUWPQOn.d.mts +202 -0
  172. package/dist/schema-ivUWPQOn.d.mts.map +1 -0
  173. package/dist/server-cE1BWLQu.mjs +2518 -0
  174. package/dist/server-cE1BWLQu.mjs.map +1 -0
  175. package/dist/server.d.mts +270 -48
  176. package/dist/server.d.mts.map +1 -1
  177. package/dist/server.mjs +5 -5
  178. package/dist/utils-C6AIF38Z.mjs +133 -0
  179. package/dist/utils-C6AIF38Z.mjs.map +1 -0
  180. package/dist/utils.d.mts +12 -5
  181. package/dist/utils.d.mts.map +1 -1
  182. package/dist/utils.mjs +4 -3
  183. package/dist/worker-pool-BWHBLBJd.mjs +304 -0
  184. package/dist/worker-pool-BWHBLBJd.mjs.map +1 -0
  185. package/dist/workflow-runtime-7GaJ13c9.d.mts +30 -0
  186. package/dist/workflow-runtime-7GaJ13c9.d.mts.map +1 -0
  187. package/dist/workflows-COM3MKfD.mjs +1437 -0
  188. package/dist/workflows-COM3MKfD.mjs.map +1 -0
  189. package/package.json +68 -23
  190. package/scripts/install-packages.sh +0 -0
  191. package/test/attachment-reference-read-model.test.ts +28 -20
  192. package/test/attachments/auth.test.ts +85 -0
  193. package/test/attachments/byte-grants.test.ts +290 -0
  194. package/test/attachments/byte-routes-read-gate.integration.test.ts +314 -0
  195. package/test/attachments/download-target.test.ts +211 -32
  196. package/test/attachments/index.test.ts +47 -4
  197. package/test/attachments/reserve-metadata-parity.test.ts +96 -0
  198. package/test/attachments/routes-integration.test.ts +60 -4
  199. package/test/attachments/routes.test.ts +297 -35
  200. package/test/attachments/service-config.test.ts +41 -19
  201. package/test/attachments/url-signer.test.ts +105 -0
  202. package/test/boot-auth-config.test.ts +109 -0
  203. package/test/boot-create-signature-policy.test.ts +110 -0
  204. package/test/boot-env-isolation.test.ts +26 -0
  205. package/test/boot-helpers.ts +19 -0
  206. package/test/boot-inspection-enabled.test.ts +140 -0
  207. package/test/boot-mcp-auth.test.ts +449 -0
  208. package/test/boot-mcp-enabled.test.ts +119 -0
  209. package/test/boot-port-zero.test.ts +101 -0
  210. package/test/boot-preconditions.test.ts +200 -0
  211. package/test/boot-privacy.test.ts +232 -0
  212. package/test/boot-unsupported-stored-documents.test.ts +214 -0
  213. package/test/boot-without-renown.test.ts +83 -0
  214. package/test/boot-without-require-signatures.test.ts +76 -0
  215. package/test/boot-worker-trust-policy.test.ts +91 -0
  216. package/test/boot-workflow-singleton-conflict.test.ts +109 -0
  217. package/test/boot-workflow-singleton-retry.test.ts +122 -0
  218. package/test/builder-defaults.test.ts +80 -0
  219. package/test/config-from-env.test.ts +758 -0
  220. package/test/config-merge.test.ts +215 -0
  221. package/test/config-schema.test.ts +128 -0
  222. package/test/create-signature-policy.test.ts +69 -0
  223. package/test/default-drive-protocol-versions.test.ts +102 -0
  224. package/test/default-drive-slug.test.ts +97 -0
  225. package/test/durable-node-fs-pg16.test.ts +80 -0
  226. package/test/fatal-shutdown.test.ts +165 -0
  227. package/test/goldens/packages.graphql +797 -0
  228. package/test/goldens/privacy.graphql +853 -0
  229. package/test/goldens/reactor-drive-nodes.graphql +827 -0
  230. package/test/goldens/resolvers.json +322 -0
  231. package/test/goldens/supergraph.graphql +5652 -0
  232. package/test/goldens/workflow-runtime.graphql +1419 -0
  233. package/test/inspection-throttle.test.ts +23 -0
  234. package/test/observability-signals.test.ts +131 -0
  235. package/test/permissions-backfill.test.ts +486 -0
  236. package/test/pglite-dialect.test.ts +237 -2
  237. package/test/pglite-preflight.test.ts +313 -0
  238. package/test/pglite-storage-dirs.test.ts +113 -0
  239. package/test/pglite-store.test.ts +264 -0
  240. package/test/pglite-version.test.ts +9 -1
  241. package/test/plugin-config-schemas.test.ts +83 -0
  242. package/test/plugin-presence.test.ts +262 -0
  243. package/test/port-probe.test.ts +45 -0
  244. package/test/renown-storage-path.test.ts +40 -0
  245. package/test/renown-trust-policy.test.ts +313 -0
  246. package/test/served-schemas.test.ts +134 -0
  247. package/test/shutdown.test.ts +278 -0
  248. package/test/snapshot-writer.ts +94 -0
  249. package/test/store-lock.test.ts +65 -0
  250. package/test/two-switchboards.test.ts +146 -0
  251. package/test/unsupported-stored-documents.test.ts +72 -0
  252. package/test/worker-pool.test.ts +27 -1
  253. package/test/workflow/harness.ts +289 -0
  254. package/test/workflow/oauth.test.ts +205 -0
  255. package/test/workflow/resolvers.test.ts +369 -0
  256. package/test/workflow/runtime-host.test.ts +19 -0
  257. package/test/workflow/webhook-dedupe.test.ts +295 -0
  258. package/test/workflow/webhook-signed.test.ts +509 -0
  259. package/test/workflow/webhook-trigger-test.test.ts +82 -0
  260. package/test/workflow/webhook-unsigned.test.ts +345 -0
  261. package/test/workflow-reactor-access.test.ts +384 -0
  262. package/test/workflow-reactor-enforcement.test.ts +808 -0
  263. package/test/workflow-read-gate.test.ts +213 -0
  264. package/test/workflow-runtime.test.ts +1135 -0
  265. package/test/workflows-plugin-config.test.ts +77 -0
  266. package/tsconfig.json +11 -2
  267. package/tsdown.config.ts +12 -1
  268. package/vitest.config.ts +65 -0
  269. package/dist/server-CiKkVE6g.mjs +0 -1555
  270. package/dist/server-CiKkVE6g.mjs.map +0 -1
  271. package/dist/utils-Baw7rThP.mjs +0 -80
  272. package/dist/utils-Baw7rThP.mjs.map +0 -1
@@ -0,0 +1,215 @@
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("ignores MCP_ENABLED and PH_WORKFLOWS_ENABLED under the plugin host", () => {
187
+ const env = {
188
+ FEATURE_PLUGIN_HOST_ENABLED: "1",
189
+ MCP_ENABLED: "false",
190
+ PH_WORKFLOWS_ENABLED: "true",
191
+ };
192
+ const host = resolved(env, {});
193
+ expect(host.features.pluginHost).toBe(true);
194
+ expect(host.features.mcp).toBeUndefined();
195
+ expect(host.features.workflows).toBeUndefined();
196
+ const withCaller = resolved(env, {
197
+ features: { mcp: false, workflows: true },
198
+ });
199
+ expect(withCaller.features.mcp).toBe(false);
200
+ expect(withCaller.features.workflows).toBe(true);
201
+ // Not carved: classic on both paths.
202
+ expect(
203
+ resolved({ ...env, INSPECTION_ENABLED: "false" }, {}).inspection.enabled,
204
+ ).toBe(false);
205
+ });
206
+ });
207
+
208
+ describe("startSwitchboard", () => {
209
+ it("refuses the old options shape instead of booting on defaults", async () => {
210
+ const { startSwitchboard } = await import("../src/server.mjs");
211
+ await expect(
212
+ startSwitchboard({ port: 0, dbPath: "x" } as SwitchboardConfigInput),
213
+ ).rejects.toThrow("unknown config keys: port, dbPath");
214
+ });
215
+ });
@@ -0,0 +1,128 @@
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
+ });
39
+ expect(config.workers).toEqual({
40
+ executor: { count: 0, poolSize: 2, acquireTimeoutMs: 5000 },
41
+ hostPoolSize: 16,
42
+ projection: { enabled: false, poolSize: 8 },
43
+ });
44
+ expect(config.inspection).toEqual({ enabled: true, admin: false });
45
+ expect(config.features).toEqual({
46
+ documentModelSubgraphs: true,
47
+ pluginHost: false,
48
+ privacy: { enabled: false },
49
+ });
50
+ expect(config.attachments).toEqual({ storage: { kind: "filesystem" } });
51
+ expect(config.auth.documentPermissions).toEqual({ enabled: false });
52
+ });
53
+
54
+ it("keeps the defaults beside a nested value a layer sets", () => {
55
+ const layer: SwitchboardConfigInput = {
56
+ workers: { executor: { count: "auto" } },
57
+ storage: { pglite: { vacuumFull: { mode: "quiet" } } },
58
+ };
59
+ const config = switchboardConfigSchema.parse(layer);
60
+ expect(config.workers.executor).toEqual({
61
+ count: "auto",
62
+ poolSize: 2,
63
+ acquireTimeoutMs: 5000,
64
+ });
65
+ expect(config.workers.hostPoolSize).toBe(16);
66
+ expect(config.storage.pglite).toEqual({
67
+ fsync: true,
68
+ workers: true,
69
+ vacuumFull: { mode: "quiet" },
70
+ });
71
+ });
72
+
73
+ it.each<[string, SwitchboardConfigInput]>([
74
+ ["a port out of range", { server: { port: 70000 } }],
75
+ ["a fractional worker count", { workers: { executor: { count: 1.5 } } }],
76
+ ["a host pool of 0", { workers: { hostPoolSize: 0 } }],
77
+ ["a catch-up level above 7", { protocol: { catchUpPriority: 8 } }],
78
+ [
79
+ "an unknown signature policy",
80
+ { protocol: { createSignaturePolicy: "v3" as "legacy" } },
81
+ ],
82
+ ["a PG major it does not ship", { storage: { forcePgVersion: 15 as 16 } }],
83
+ ])("refuses %s", (_name, layer) => {
84
+ expect(switchboardConfigSchema.safeParse(layer).success).toBe(false);
85
+ });
86
+ });
87
+
88
+ describe("the config modules", () => {
89
+ it("load without the server", async () => {
90
+ vi.doMock("../src/server.mjs", () => {
91
+ throw new Error("the server was loaded");
92
+ });
93
+ await expect(import("../src/config/from-env.js")).resolves.toBeDefined();
94
+ vi.doUnmock("../src/server.mjs");
95
+ });
96
+ });
97
+
98
+ describe("switchboardConfigLayerSchema", () => {
99
+ const layer = switchboardConfigLayerSchema(["server.port", "drive"]);
100
+
101
+ it("keeps a layer as written, without defaults", () => {
102
+ expect(layer.parse({})).toEqual({});
103
+ expect(layer.parse({ auth: { enabled: true } })).toEqual({
104
+ auth: { enabled: true },
105
+ });
106
+ });
107
+
108
+ it("validates values and refuses unknown or omitted keys", () => {
109
+ expect(
110
+ layer.safeParse({ workers: { executor: { count: "auto" } } }),
111
+ ).toMatchObject({ success: true });
112
+ expect(
113
+ layer.safeParse({ workers: { executor: { count: -1 } } }).success,
114
+ ).toBe(false);
115
+ expect(layer.safeParse({ auth: { enabeld: true } }).success).toBe(false);
116
+ expect(layer.safeParse({ server: { port: 1 } }).success).toBe(false);
117
+ expect(layer.safeParse({ drive: {} }).success).toBe(false);
118
+ expect(layer.safeParse({ server: { basePath: "/x" } }).success).toBe(true);
119
+ });
120
+
121
+ it("emits a JSON Schema once the map key is omitted", () => {
122
+ const schema = z.toJSONSchema(
123
+ switchboardConfigLayerSchema(["processorConfig"]),
124
+ { io: "input" },
125
+ );
126
+ expect(schema).toMatchObject({ additionalProperties: false });
127
+ });
128
+ });
@@ -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,102 @@
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
+ write: {
41
+ create: (document: PHDocument) => {
42
+ created.push(document);
43
+ return Promise.resolve({
44
+ readable: Promise.resolve({
45
+ documentId: document.header.id,
46
+ branch: "main",
47
+ }),
48
+ });
49
+ },
50
+ },
51
+ } as unknown as IReactorClient,
52
+ };
53
+ }
54
+
55
+ describe.each([
56
+ ["addDefaultDrive", addDefaultDrive],
57
+ ["addDefaultReactorDrive", addDefaultReactorDrive],
58
+ ])("%s", (_name, add) => {
59
+ it("heads the drive with the client's newDocument", async () => {
60
+ const { client: reactor, created } = client();
61
+
62
+ await add(reactor, { slug: "main", global: { name: "Main" } } as never, 1);
63
+
64
+ expect(created[0].header.protocolVersions).toEqual({
65
+ "base-reducer": 3,
66
+ signature: 2,
67
+ });
68
+ });
69
+
70
+ it("heads a drive with a configured id as legacy at the same versions", async () => {
71
+ const { client: reactor, created } = client();
72
+
73
+ await add(reactor, { id: "fixed", global: { name: "Main" } } as never, 1);
74
+
75
+ expect(created[0].header.id).toBe("fixed");
76
+ expect(created[0].header.protocolVersions).toEqual({ "base-reducer": 3 });
77
+ });
78
+
79
+ it("makes a drive anew under its slug when its pinned id is one only a v2 create derives", async () => {
80
+ const { client: reactor, created } = client();
81
+ const errors: string[] = [];
82
+ // The id of a drive created as v2-required in another store
83
+ const pinned = "HRsIHuMMTdmjgCdy9QGWyx96zOFByPo787oBQcEt9f4";
84
+
85
+ const url = await add(
86
+ reactor,
87
+ { id: pinned, slug: "mail", global: { name: "Mail" } } as never,
88
+ 1,
89
+ { error: (message: string) => errors.push(message) },
90
+ );
91
+
92
+ // Created v2-required under a derived id, not as a legacy one claiming it
93
+ expect(created[0].header.id).not.toBe(pinned);
94
+ expect(created[0].header.protocolVersions).toEqual({
95
+ "base-reducer": 3,
96
+ signature: 2,
97
+ });
98
+ expect(created[0].header.slug).toBe("mail");
99
+ expect(url).toBe("http://localhost:1/d/mail");
100
+ expect(errors[0]).toContain(`pins ${pinned}`);
101
+ });
102
+ });
@@ -0,0 +1,97 @@
1
+ import {
2
+ ReactorBuilder,
3
+ ReactorClientBuilder,
4
+ type InProcessReactorClientModule,
5
+ } from "@powerhousedao/reactor";
6
+ import { driveDocumentModelModule } from "@powerhousedao/shared/document-drive";
7
+ import type { DriveInput } from "@powerhousedao/shared/document-drive";
8
+ import {
9
+ withSignaturePolicy,
10
+ type DocumentModelModule,
11
+ } from "@powerhousedao/shared/document-model";
12
+ import { documentModelDocumentModelModule } from "document-model";
13
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
14
+ import { addDefaultDrive } from "../src/utils.mjs";
15
+
16
+ const PORT = 4001;
17
+
18
+ const workflows = (id: string): DriveInput =>
19
+ ({
20
+ id,
21
+ slug: "workflows",
22
+ global: { name: "Workflows" },
23
+ local: {
24
+ availableOffline: true,
25
+ listeners: [],
26
+ sharingType: "public",
27
+ triggers: [],
28
+ },
29
+ }) as DriveInput;
30
+
31
+ describe("addDefaultDrive with a slug another document holds", () => {
32
+ let module: InProcessReactorClientModule;
33
+ const logger = { error: vi.fn() };
34
+
35
+ beforeEach(async () => {
36
+ logger.error.mockClear();
37
+ module = await new ReactorClientBuilder()
38
+ .withReactorBuilder(
39
+ new ReactorBuilder().withDocumentModelSources([
40
+ driveDocumentModelModule as unknown as DocumentModelModule,
41
+ documentModelDocumentModelModule as unknown as DocumentModelModule,
42
+ ]),
43
+ )
44
+ .buildModule();
45
+ });
46
+
47
+ afterEach(() => {
48
+ module.reactor.kill();
49
+ });
50
+
51
+ const isCreated = (id: string) =>
52
+ module.client.get(id).then(
53
+ () => true,
54
+ () => false,
55
+ );
56
+
57
+ it("creates the drive when the slug is free", async () => {
58
+ await expect(
59
+ addDefaultDrive(module.client, workflows("workflows-a"), PORT, logger),
60
+ ).resolves.toBe(`http://localhost:${PORT}/d/workflows-a`);
61
+ await expect(module.client.resolveIdOrSlug("workflows")).resolves.toBe(
62
+ "workflows-a",
63
+ );
64
+ });
65
+
66
+ // A project moved to another folder hashes its drive ids anew.
67
+ it("serves the drive that holds the slug instead of creating a twin", async () => {
68
+ await addDefaultDrive(
69
+ module.client,
70
+ workflows("workflows-a"),
71
+ PORT,
72
+ logger,
73
+ );
74
+ await expect(
75
+ addDefaultDrive(module.client, workflows("workflows-b"), PORT, logger),
76
+ ).resolves.toBe(`http://localhost:${PORT}/d/workflows-a`);
77
+ expect(await isCreated("workflows-b")).toBe(false);
78
+ expect(logger.error).not.toHaveBeenCalled();
79
+ });
80
+
81
+ it("logs an error and creates nothing when another kind of document holds it", async () => {
82
+ const other = withSignaturePolicy(
83
+ documentModelDocumentModelModule.utils.createDocument(),
84
+ "legacy",
85
+ );
86
+ other.header.slug = "workflows";
87
+ await module.client.create(other);
88
+
89
+ await expect(
90
+ addDefaultDrive(module.client, workflows("workflows-c"), PORT, logger),
91
+ ).resolves.toBeUndefined();
92
+ expect(await isCreated("workflows-c")).toBe(false);
93
+ expect(logger.error).toHaveBeenCalledWith(
94
+ `The default drive "workflows" was not created: the slug belongs to powerhouse/document-model document ${other.header.id}.`,
95
+ );
96
+ });
97
+ });
@@ -0,0 +1,80 @@
1
+ import { createDurableNodeFs } from "@powerhousedao/reactor-api/pglite-node";
2
+ import nodeFs, { promises as fs } from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { afterEach, describe, expect, it } from "vitest";
6
+ import { loadNodeFsClass, loadPGliteModule } from "../src/pglite-version.js";
7
+
8
+ // A fresh initdb takes ~10 s under suite load; the Windows runner is slower.
9
+ const BOOT = 180_000;
10
+ const COMMITS = 10;
11
+ const RM = { recursive: true, force: true, maxRetries: 10 } as const;
12
+
13
+ describe("durable NodeFS over pglite-legacy-02 (PG16)", () => {
14
+ const tempDirs: string[] = [];
15
+
16
+ afterEach(async () => {
17
+ for (const dir of tempDirs.splice(0)) {
18
+ await fs.rm(dir, RM);
19
+ }
20
+ });
21
+
22
+ it(
23
+ "opens a PG16 dir over pglite-legacy-02 with the durable fs",
24
+ async () => {
25
+ const dir = await fs.mkdtemp(path.join(os.tmpdir(), "durable-pg16-"));
26
+ tempDirs.push(dir);
27
+ const counts = { fsync: 0, fdatasync: 0 };
28
+ const hostFs = {
29
+ fsyncSync: (fd: number) => {
30
+ counts.fsync++;
31
+ nodeFs.fsyncSync(fd);
32
+ },
33
+ fdatasyncSync: (fd: number) => {
34
+ counts.fdatasync++;
35
+ nodeFs.fdatasyncSync(fd);
36
+ },
37
+ };
38
+ const [{ PGlite }, NodeFS] = await Promise.all([
39
+ loadPGliteModule(16),
40
+ loadNodeFsClass(16),
41
+ ]);
42
+ const pg = new PGlite({
43
+ fs: createDurableNodeFs(NodeFS, dir, {
44
+ hostFs,
45
+ maintenanceIntervalMs: 0,
46
+ }),
47
+ });
48
+ try {
49
+ await pg.waitReady;
50
+ const version = await pg.query<{ v: string }>(
51
+ "SELECT current_setting('server_version_num') AS v",
52
+ );
53
+ expect(version.rows[0].v.startsWith("16")).toBe(true);
54
+ await pg.exec("CREATE TABLE t (v int)");
55
+ const before = counts.fdatasync;
56
+ for (let i = 0; i < COMMITS; i++) {
57
+ await pg.exec(`INSERT INTO t VALUES (${i})`);
58
+ }
59
+ const perCommit = counts.fdatasync - before;
60
+ const fsyncBefore = counts.fsync;
61
+ await pg.exec("CHECKPOINT");
62
+ const checkpointSyncs = counts.fsync - fsyncBefore;
63
+ console.info(
64
+ `pglite-legacy-02: ${perCommit} host fdatasync over ${COMMITS} commits, ${checkpointSyncs} host fsync on CHECKPOINT, ${fsyncBefore} host fsync since open`,
65
+ );
66
+ // Pins decision 5's outcome on 0.2.17: WAL goes through
67
+ // open_datasync, which never reaches the fdatasync hook, so commits
68
+ // are not synced; the stream-op patch does take (CHECKPOINT syncs).
69
+ expect(perCommit).toBe(0);
70
+ expect(checkpointSyncs).toBeGreaterThan(0);
71
+ } finally {
72
+ await pg.close();
73
+ }
74
+ expect(
75
+ (await fs.readFile(path.join(dir, "PG_VERSION"), "utf8")).trim(),
76
+ ).toBe("16");
77
+ },
78
+ BOOT,
79
+ );
80
+ });