@powerhousedao/switchboard 6.2.3-dev.78 → 6.2.3-dev.79
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/boot-auth-config.test.d.ts +2 -0
- package/.tsbuild/test/boot-auth-config.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/config-from-env.test.d.ts +2 -0
- package/.tsbuild/test/config-from-env.test.d.ts.map +1 -0
- package/.tsbuild/test/config-merge.test.d.ts +2 -0
- package/.tsbuild/test/config-merge.test.d.ts.map +1 -0
- package/.tsbuild/test/config-schema.test.d.ts +2 -0
- package/.tsbuild/test/config-schema.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-protocol-versions.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/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +35 -0
- package/README.md +9 -5
- package/dist/boot.d.mts +8 -0
- package/dist/boot.d.mts.map +1 -1
- package/dist/boot.mjs +22 -16
- package/dist/boot.mjs.map +1 -1
- package/dist/config/from-env.d.mts +15 -0
- package/dist/config/from-env.d.mts.map +1 -0
- package/dist/config/from-env.mjs +4 -0
- package/dist/config/schema.d.mts +3 -0
- package/dist/config/schema.mjs +4 -0
- package/dist/from-env-BO0n9R02.mjs +401 -0
- package/dist/from-env-BO0n9R02.mjs.map +1 -0
- package/dist/index.mjs +34 -38
- package/dist/index.mjs.map +1 -1
- package/dist/migrate.mjs +2 -2
- package/dist/{plugin-host-BBqojyyY.d.mts → plugin-host-C1sYEm8g.d.mts} +4 -1
- package/dist/plugin-host-C1sYEm8g.d.mts.map +1 -0
- package/dist/plugins/attachments.d.mts +3 -3
- package/dist/plugins/attachments.mjs +3 -3
- package/dist/plugins/mcp.d.mts +1 -1
- package/dist/plugins/privacy.d.mts +1 -1
- package/dist/plugins/privacy.mjs +3 -3
- package/dist/plugins/workflows.d.mts +1 -1
- package/dist/plugins/workflows.mjs +3 -3
- package/dist/privacy-BO8Q25xI.mjs +44 -0
- package/dist/privacy-BO8Q25xI.mjs.map +1 -0
- package/dist/{privacy-BsFl7GzK.mjs → privacy-DxIJGH4P.mjs} +14 -41
- package/dist/privacy-DxIJGH4P.mjs.map +1 -0
- package/dist/renown-layers-COZsrGQT.mjs +40 -0
- package/dist/renown-layers-COZsrGQT.mjs.map +1 -0
- package/dist/schema-0g_QdOWn.mjs +267 -0
- package/dist/schema-0g_QdOWn.mjs.map +1 -0
- package/dist/schema-ivUWPQOn.d.mts +202 -0
- package/dist/schema-ivUWPQOn.d.mts.map +1 -0
- package/dist/{server-Bdq8xquD.mjs → server-CtGBZlTg.mjs} +230 -382
- package/dist/server-CtGBZlTg.mjs.map +1 -0
- package/dist/server.d.mts +46 -11
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +5 -4
- package/dist/{utils-CTtD7Oti.mjs → utils-BbV_nodR.mjs} +23 -20
- package/dist/utils-BbV_nodR.mjs.map +1 -0
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +3 -3
- package/dist/{reactor-feature-flags-BtWVQDt6.mjs → worker-pool-BWHBLBJd.mjs} +12 -32
- package/dist/worker-pool-BWHBLBJd.mjs.map +1 -0
- package/dist/workflow-runtime-7GaJ13c9.d.mts.map +1 -1
- package/dist/{workflows-fsBcElEi.mjs → workflows-QY9Y2eoD.mjs} +5 -16
- package/dist/workflows-QY9Y2eoD.mjs.map +1 -0
- package/package.json +29 -19
- package/test/attachment-reference-read-model.test.ts +22 -19
- package/test/attachments/download-target.test.ts +29 -19
- package/test/attachments/service-config.test.ts +28 -16
- package/test/boot-auth-config.test.ts +109 -0
- package/test/boot-create-signature-policy.test.ts +15 -13
- package/test/boot-env-isolation.test.ts +2 -2
- package/test/boot-helpers.ts +18 -0
- package/test/boot-inspection-enabled.test.ts +16 -13
- package/test/boot-mcp-enabled.test.ts +15 -13
- package/test/boot-port-zero.test.ts +15 -13
- package/test/boot-preconditions.test.ts +51 -0
- package/test/boot-privacy.test.ts +12 -10
- package/test/boot-unsupported-stored-documents.test.ts +10 -9
- package/test/boot-without-renown.test.ts +11 -9
- package/test/boot-without-require-signatures.test.ts +12 -10
- package/test/boot-worker-trust-policy.test.ts +11 -10
- package/test/boot-workflow-singleton-conflict.test.ts +11 -9
- package/test/boot-workflow-singleton-retry.test.ts +12 -10
- package/test/config-from-env.test.ts +758 -0
- package/test/config-merge.test.ts +215 -0
- package/test/config-schema.test.ts +128 -0
- package/test/default-drive-protocol-versions.test.ts +78 -0
- package/test/pglite-storage-dirs.test.ts +24 -14
- package/test/pglite-store.test.ts +1 -62
- package/test/plugin-presence.test.ts +27 -21
- package/test/renown-storage-path.test.ts +9 -8
- package/test/shutdown.test.ts +22 -21
- package/test/two-switchboards.test.ts +146 -0
- package/test/workflow-runtime.test.ts +12 -69
- package/tsdown.config.ts +2 -0
- package/vitest.config.ts +2 -0
- package/.tsbuild/test/inspection-flag.test.d.ts +0 -2
- package/.tsbuild/test/inspection-flag.test.d.ts.map +0 -1
- package/.tsbuild/test/mcp-flag.test.d.ts +0 -2
- package/.tsbuild/test/mcp-flag.test.d.ts.map +0 -1
- package/dist/plugin-host-BBqojyyY.d.mts.map +0 -1
- package/dist/privacy-BsFl7GzK.mjs.map +0 -1
- package/dist/reactor-feature-flags-BtWVQDt6.mjs.map +0 -1
- package/dist/server-Bdq8xquD.mjs.map +0 -1
- package/dist/utils-CTtD7Oti.mjs.map +0 -1
- package/dist/workflows-fsBcElEi.mjs.map +0 -1
- package/test/inspection-flag.test.ts +0 -62
- package/test/mcp-flag.test.ts +0 -56
|
@@ -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,78 @@
|
|
|
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
|
+
});
|
|
@@ -7,20 +7,30 @@ describe("resolvePgliteStorageDirs", () => {
|
|
|
7
7
|
const phDir = path.join("/proj", ".ph");
|
|
8
8
|
|
|
9
9
|
it("keeps the classic literals verbatim without a user-data root", () => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
const dirs = resolvePgliteStorageDirs({
|
|
11
|
+
dbPath: undefined,
|
|
12
|
+
reactorDbUrl: undefined,
|
|
13
|
+
callerReactor: false,
|
|
14
|
+
});
|
|
15
|
+
expect(dirs.reactorPgliteDir).toBe("./.ph/reactor-storage");
|
|
16
|
+
expect(dirs.readModelPgliteDir).toBe(".ph/read-storage");
|
|
17
|
+
expect(dirs.sharedPgliteDir).toBeNull();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("moves the defaults under the user-data root", () => {
|
|
21
|
+
const userData = path.join("/home", "user");
|
|
22
|
+
const dirs = resolvePgliteStorageDirs({
|
|
23
|
+
dbPath: undefined,
|
|
24
|
+
reactorDbUrl: undefined,
|
|
25
|
+
callerReactor: false,
|
|
26
|
+
userDataDir: userData,
|
|
27
|
+
});
|
|
28
|
+
expect(dirs.reactorPgliteDir).toBe(
|
|
29
|
+
path.join(userData, ".ph", "reactor-storage"),
|
|
30
|
+
);
|
|
31
|
+
expect(dirs.readModelPgliteDir).toBe(
|
|
32
|
+
path.join(userData, ".ph", "read-storage"),
|
|
33
|
+
);
|
|
24
34
|
});
|
|
25
35
|
|
|
26
36
|
it("defaults to the classic split under the .ph tree", () => {
|
|
@@ -9,28 +9,15 @@ import { EventEmitter } from "node:events";
|
|
|
9
9
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
10
10
|
import { tmpdir } from "node:os";
|
|
11
11
|
import { join } from "node:path";
|
|
12
|
-
import {
|
|
13
|
-
afterEach,
|
|
14
|
-
beforeAll,
|
|
15
|
-
beforeEach,
|
|
16
|
-
describe,
|
|
17
|
-
expect,
|
|
18
|
-
it,
|
|
19
|
-
vi,
|
|
20
|
-
} from "vitest";
|
|
21
|
-
import { initFeatureFlags } from "../src/feature-flags.js";
|
|
12
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
22
13
|
import { installFatalErrorShutdown } from "../src/fatal-shutdown.mjs";
|
|
23
14
|
import {
|
|
24
15
|
createPgliteStoreFactory,
|
|
25
|
-
PGLITE_WORKERS_DEFAULT,
|
|
26
|
-
PH_PGLITE_WORKERS,
|
|
27
|
-
resolvePgliteWorkersEnabled,
|
|
28
16
|
routePgliteWorkerFailures,
|
|
29
17
|
terminateOnPoisoned,
|
|
30
18
|
type PgliteStoreOptions,
|
|
31
19
|
vacuumFullTimingFromEnv,
|
|
32
20
|
} from "../src/pglite-store.mjs";
|
|
33
|
-
import type { BooleanFlagSource } from "../src/workflow-runtime.mjs";
|
|
34
21
|
|
|
35
22
|
const BOOT = 90_000;
|
|
36
23
|
|
|
@@ -72,54 +59,6 @@ class FakeWorkerEvents {
|
|
|
72
59
|
}
|
|
73
60
|
}
|
|
74
61
|
|
|
75
|
-
describe("resolvePgliteWorkersEnabled", () => {
|
|
76
|
-
let featureFlags: BooleanFlagSource;
|
|
77
|
-
|
|
78
|
-
const previous = process.env[PH_PGLITE_WORKERS];
|
|
79
|
-
|
|
80
|
-
beforeAll(async () => {
|
|
81
|
-
featureFlags = await initFeatureFlags();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
beforeEach(() => {
|
|
85
|
-
delete process.env[PH_PGLITE_WORKERS];
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
afterEach(() => {
|
|
89
|
-
if (previous === undefined) delete process.env[PH_PGLITE_WORKERS];
|
|
90
|
-
else process.env[PH_PGLITE_WORKERS] = previous;
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("falls back to the default constant", async () => {
|
|
94
|
-
expect(PGLITE_WORKERS_DEFAULT).toBe(true);
|
|
95
|
-
await expect(resolvePgliteWorkersEnabled({ featureFlags })).resolves.toBe(
|
|
96
|
-
PGLITE_WORKERS_DEFAULT,
|
|
97
|
-
);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('is turned on by PH_PGLITE_WORKERS="true"', async () => {
|
|
101
|
-
process.env[PH_PGLITE_WORKERS] = "true";
|
|
102
|
-
await expect(resolvePgliteWorkersEnabled({ featureFlags })).resolves.toBe(
|
|
103
|
-
true,
|
|
104
|
-
);
|
|
105
|
-
process.env[PH_PGLITE_WORKERS] = "false";
|
|
106
|
-
await expect(resolvePgliteWorkersEnabled({ featureFlags })).resolves.toBe(
|
|
107
|
-
false,
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("lets the host option win either way", async () => {
|
|
112
|
-
process.env[PH_PGLITE_WORKERS] = "true";
|
|
113
|
-
await expect(
|
|
114
|
-
resolvePgliteWorkersEnabled({ featureFlags, option: false }),
|
|
115
|
-
).resolves.toBe(false);
|
|
116
|
-
process.env[PH_PGLITE_WORKERS] = "false";
|
|
117
|
-
await expect(
|
|
118
|
-
resolvePgliteWorkersEnabled({ featureFlags, option: true }),
|
|
119
|
-
).resolves.toBe(true);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
62
|
describe("routePgliteWorkerFailures", () => {
|
|
124
63
|
it("sends an abort to the fatal shutdown", () => {
|
|
125
64
|
const proc = fatalProcess();
|
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
builtinSwitchboardPlugins,
|
|
9
9
|
createSwitchboardPluginHost,
|
|
10
10
|
} from "../src/plugin-host.mjs";
|
|
11
|
-
import {
|
|
11
|
+
import type { SwitchboardConfigInput } from "../src/config/schema.js";
|
|
12
|
+
import type { startSwitchboard, SwitchboardDeps } from "../src/server.mjs";
|
|
13
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
12
14
|
|
|
13
15
|
function stubLogger(): ILogger {
|
|
14
16
|
const logger = {
|
|
@@ -31,7 +33,7 @@ function stubLogger(): ILogger {
|
|
|
31
33
|
* — case 5 below covers workflow presence on its own, lighter path.
|
|
32
34
|
*/
|
|
33
35
|
async function withPluginHostSwitchboard(
|
|
34
|
-
|
|
36
|
+
override: { config?: SwitchboardConfigInput; deps?: SwitchboardDeps },
|
|
35
37
|
run: (
|
|
36
38
|
switchboard: Awaited<ReturnType<typeof startSwitchboard>>,
|
|
37
39
|
) => Promise<void>,
|
|
@@ -51,19 +53,20 @@ async function withPluginHostSwitchboard(
|
|
|
51
53
|
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
52
54
|
|
|
53
55
|
try {
|
|
54
|
-
switchboard = await
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
switchboard = await bootSwitchboard(
|
|
57
|
+
{
|
|
58
|
+
server: { port: 0 },
|
|
59
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
60
|
+
features: { workflows: false, ...override.config?.features },
|
|
61
|
+
packages: { disableLocal: true },
|
|
62
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
63
|
+
drive: {
|
|
64
|
+
slug: "default-drive",
|
|
65
|
+
global: { name: "Default Drive" },
|
|
66
|
+
},
|
|
63
67
|
},
|
|
64
|
-
logger: stubLogger(),
|
|
65
|
-
|
|
66
|
-
});
|
|
68
|
+
{ logger: stubLogger(), ...override.deps },
|
|
69
|
+
);
|
|
67
70
|
await run(switchboard);
|
|
68
71
|
await switchboard.shutdown();
|
|
69
72
|
switchboard = undefined;
|
|
@@ -112,7 +115,7 @@ describe("plugin-host composition presence (FEATURE_PLUGIN_HOST_ENABLED)", () =>
|
|
|
112
115
|
|
|
113
116
|
it("EMPTY composition ([]): attachments absent", async () => {
|
|
114
117
|
await withPluginHostSwitchboard(
|
|
115
|
-
{ pluginComposition: [] },
|
|
118
|
+
{ deps: { pluginComposition: [] } },
|
|
116
119
|
async (switchboard) => {
|
|
117
120
|
expect(switchboard.attachmentService).toBeUndefined();
|
|
118
121
|
expect(await getReservation(switchboard.port)).toBe(404);
|
|
@@ -126,7 +129,7 @@ describe("plugin-host composition presence (FEATURE_PLUGIN_HOST_ENABLED)", () =>
|
|
|
126
129
|
// its subsystem.
|
|
127
130
|
it("EMPTY composition ([]): /mcp does not mount — presence is activation", async () => {
|
|
128
131
|
await withPluginHostSwitchboard(
|
|
129
|
-
{ pluginComposition: [] },
|
|
132
|
+
{ deps: { pluginComposition: [] } },
|
|
130
133
|
async (switchboard) => {
|
|
131
134
|
expect(switchboard.mcpEnabled).toBe(false);
|
|
132
135
|
expect(await postMcp(switchboard.port)).toBe(404);
|
|
@@ -140,7 +143,7 @@ describe("plugin-host composition presence (FEATURE_PLUGIN_HOST_ENABLED)", () =>
|
|
|
140
143
|
);
|
|
141
144
|
expect(mcpOnly).toHaveLength(1);
|
|
142
145
|
await withPluginHostSwitchboard(
|
|
143
|
-
{ pluginComposition: mcpOnly },
|
|
146
|
+
{ deps: { pluginComposition: mcpOnly } },
|
|
144
147
|
async (switchboard) => {
|
|
145
148
|
expect(switchboard.mcpEnabled).toBe(true);
|
|
146
149
|
expect(await postMcp(switchboard.port)).not.toBe(404);
|
|
@@ -151,10 +154,13 @@ describe("plugin-host composition presence (FEATURE_PLUGIN_HOST_ENABLED)", () =>
|
|
|
151
154
|
}, 60_000);
|
|
152
155
|
|
|
153
156
|
it("an explicit mcp: false option still wins over the default composition", async () => {
|
|
154
|
-
await withPluginHostSwitchboard(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
157
|
+
await withPluginHostSwitchboard(
|
|
158
|
+
{ config: { features: { mcp: false } } },
|
|
159
|
+
async (switchboard) => {
|
|
160
|
+
expect(switchboard.mcpEnabled).toBe(false);
|
|
161
|
+
expect(await postMcp(switchboard.port)).toBe(404);
|
|
162
|
+
},
|
|
163
|
+
);
|
|
158
164
|
}, 60_000);
|
|
159
165
|
});
|
|
160
166
|
|
|
@@ -6,19 +6,18 @@ import { afterEach, describe, expect, it } from "vitest";
|
|
|
6
6
|
import { initRenown } from "../src/renown.js";
|
|
7
7
|
|
|
8
8
|
describe("initRenown storage", () => {
|
|
9
|
-
const saved = process.env.PH_USER_DATA_DIR;
|
|
10
9
|
let userData: string | undefined;
|
|
11
10
|
|
|
12
11
|
afterEach(async () => {
|
|
13
|
-
if (saved === undefined) delete process.env.PH_USER_DATA_DIR;
|
|
14
|
-
else process.env.PH_USER_DATA_DIR = saved;
|
|
15
12
|
if (userData) await rm(userData, { recursive: true, force: true });
|
|
16
13
|
});
|
|
17
14
|
|
|
18
|
-
it("keeps renown's user storage under
|
|
15
|
+
it("keeps renown's user storage under the user-data dir", async () => {
|
|
19
16
|
userData = await mkdtemp(join(tmpdir(), "switchboard-renown-"));
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
await initRenown({
|
|
18
|
+
keypairPath: join(userData, ".ph", ".keypair.json"),
|
|
19
|
+
userDataDir: userData,
|
|
20
|
+
});
|
|
22
21
|
expect(existsSync(join(userData, ".ph", ".renown.json"))).toBe(true);
|
|
23
22
|
});
|
|
24
23
|
|
|
@@ -26,11 +25,13 @@ describe("initRenown storage", () => {
|
|
|
26
25
|
userData = await mkdtemp(join(tmpdir(), "switchboard-renown-"));
|
|
27
26
|
const cwd = join(userData, "project");
|
|
28
27
|
await mkdir(cwd);
|
|
29
|
-
process.env.PH_USER_DATA_DIR = userData;
|
|
30
28
|
const before = process.cwd();
|
|
31
29
|
process.chdir(cwd);
|
|
32
30
|
try {
|
|
33
|
-
await initRenown({
|
|
31
|
+
await initRenown({
|
|
32
|
+
keypairPath: join(userData, ".ph", ".keypair.json"),
|
|
33
|
+
userDataDir: userData,
|
|
34
|
+
});
|
|
34
35
|
} finally {
|
|
35
36
|
process.chdir(before);
|
|
36
37
|
}
|