@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,109 @@
|
|
|
1
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import type { ILogger } from "document-model";
|
|
5
|
+
import { describe, expect, it, vi } from "vitest";
|
|
6
|
+
import type { SwitchboardConfigInput } from "../src/config/schema.js";
|
|
7
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
8
|
+
|
|
9
|
+
type Info = ReturnType<typeof vi.fn>;
|
|
10
|
+
|
|
11
|
+
function stubLogger(): ILogger & { info: Info } {
|
|
12
|
+
const logger = {
|
|
13
|
+
verbose: vi.fn(),
|
|
14
|
+
debug: vi.fn(),
|
|
15
|
+
info: vi.fn(),
|
|
16
|
+
warn: vi.fn(),
|
|
17
|
+
error: vi.fn(),
|
|
18
|
+
child: vi.fn(),
|
|
19
|
+
};
|
|
20
|
+
logger.child.mockReturnValue(logger);
|
|
21
|
+
return logger as unknown as ILogger & { info: Info };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const AUTH_VARS = ["AUTH_ENABLED", "ADMINS", "RESOLVE_CALLER_IDENTITY"];
|
|
25
|
+
|
|
26
|
+
/** Whether the switchboard enforces auth, from reactor-api's setup log. */
|
|
27
|
+
async function bootsWithAuth(options: {
|
|
28
|
+
file: Record<string, unknown>;
|
|
29
|
+
config?: SwitchboardConfigInput["auth"];
|
|
30
|
+
env?: Record<string, string>;
|
|
31
|
+
}): Promise<boolean> {
|
|
32
|
+
const tempRoot = await mkdtemp(join(tmpdir(), "switchboard-auth-config-"));
|
|
33
|
+
const names = ["PH_REACTOR_DATABASE_URL", ...AUTH_VARS];
|
|
34
|
+
const previous = names.map((name) => [name, process.env[name]] as const);
|
|
35
|
+
for (const name of AUTH_VARS) delete process.env[name];
|
|
36
|
+
process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
|
|
37
|
+
Object.assign(process.env, options.env);
|
|
38
|
+
const configFile = join(tempRoot, "powerhouse.config.json");
|
|
39
|
+
await writeFile(configFile, JSON.stringify(options.file));
|
|
40
|
+
const logger = stubLogger();
|
|
41
|
+
const switchboard = await bootSwitchboard(
|
|
42
|
+
{
|
|
43
|
+
configFile,
|
|
44
|
+
auth: options.config,
|
|
45
|
+
server: { port: 0 },
|
|
46
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
47
|
+
features: { workflows: false, mcp: false },
|
|
48
|
+
packages: { disableLocal: true },
|
|
49
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
50
|
+
},
|
|
51
|
+
{ logger },
|
|
52
|
+
).finally(() => {
|
|
53
|
+
for (const [name, value] of previous) {
|
|
54
|
+
if (value === undefined) delete process.env[name];
|
|
55
|
+
else process.env[name] = value;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
try {
|
|
59
|
+
const setup = logger.info.mock.calls.find(
|
|
60
|
+
([message]) =>
|
|
61
|
+
typeof message === "string" &&
|
|
62
|
+
message.startsWith("Setting up Auth middleware"),
|
|
63
|
+
);
|
|
64
|
+
return setup?.[1] === true;
|
|
65
|
+
} finally {
|
|
66
|
+
await switchboard.shutdown();
|
|
67
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const ADMIN = "0x1111111111111111111111111111111111111111";
|
|
72
|
+
|
|
73
|
+
describe("booting Switchboard with auth", () => {
|
|
74
|
+
it("enforces auth the config turns on", async () => {
|
|
75
|
+
expect(
|
|
76
|
+
await bootsWithAuth({
|
|
77
|
+
file: {},
|
|
78
|
+
config: { enabled: true, admins: [ADMIN] },
|
|
79
|
+
}),
|
|
80
|
+
).toBe(true);
|
|
81
|
+
}, 60_000);
|
|
82
|
+
|
|
83
|
+
it("still takes auth from the config file when the config leaves it unset", async () => {
|
|
84
|
+
expect(
|
|
85
|
+
await bootsWithAuth({
|
|
86
|
+
file: { auth: { enabled: true, admins: [ADMIN] } },
|
|
87
|
+
}),
|
|
88
|
+
).toBe(true);
|
|
89
|
+
}, 60_000);
|
|
90
|
+
|
|
91
|
+
it("lets AUTH_ENABLED override the config file, as before", async () => {
|
|
92
|
+
expect(
|
|
93
|
+
await bootsWithAuth({
|
|
94
|
+
file: { auth: { enabled: true, admins: [ADMIN] } },
|
|
95
|
+
env: { AUTH_ENABLED: "false" },
|
|
96
|
+
}),
|
|
97
|
+
).toBe(false);
|
|
98
|
+
}, 60_000);
|
|
99
|
+
|
|
100
|
+
it("lets AUTH_ENABLED override the caller's config, as it overrode options", async () => {
|
|
101
|
+
expect(
|
|
102
|
+
await bootsWithAuth({
|
|
103
|
+
file: {},
|
|
104
|
+
config: { enabled: false },
|
|
105
|
+
env: { AUTH_ENABLED: "true", ADMINS: ADMIN },
|
|
106
|
+
}),
|
|
107
|
+
).toBe(true);
|
|
108
|
+
}, 60_000);
|
|
109
|
+
});
|
|
@@ -8,7 +8,8 @@ import { tmpdir } from "node:os";
|
|
|
8
8
|
import { join } from "node:path";
|
|
9
9
|
import type { ILogger } from "document-model";
|
|
10
10
|
import { describe, expect, it, vi } from "vitest";
|
|
11
|
-
import { startSwitchboard } from "../src/server.mjs";
|
|
11
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
12
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
12
13
|
|
|
13
14
|
function stubLogger(): ILogger {
|
|
14
15
|
const logger = {
|
|
@@ -37,19 +38,20 @@ async function withSwitchboard(
|
|
|
37
38
|
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
38
39
|
|
|
39
40
|
try {
|
|
40
|
-
switchboard = await
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
switchboard = await bootSwitchboard(
|
|
42
|
+
{
|
|
43
|
+
server: { port: 0 },
|
|
44
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
45
|
+
features: { workflows: false, mcp: false },
|
|
46
|
+
packages: { disableLocal: true },
|
|
47
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
48
|
+
drive: {
|
|
49
|
+
slug: "default-drive",
|
|
50
|
+
global: { name: "Default Drive" },
|
|
51
|
+
},
|
|
50
52
|
},
|
|
51
|
-
logger: stubLogger(),
|
|
52
|
-
|
|
53
|
+
{ logger: stubLogger() },
|
|
54
|
+
);
|
|
53
55
|
await run(switchboard);
|
|
54
56
|
await switchboard.shutdown();
|
|
55
57
|
switchboard = undefined;
|
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { afterEach, describe, expect, it } from "vitest";
|
|
5
5
|
import { switchboardBootFactsFromEnv } from "../src/boot.mjs";
|
|
6
6
|
|
|
7
|
-
// Its own file:
|
|
7
|
+
// Its own file: a .env loaded by an earlier import in this worker would mask a leak.
|
|
8
8
|
describe("switchboardBootFactsFromEnv", () => {
|
|
9
9
|
const cwd = process.cwd();
|
|
10
10
|
let dir: string | undefined;
|
|
@@ -14,7 +14,7 @@ describe("switchboardBootFactsFromEnv", () => {
|
|
|
14
14
|
delete process.env.PH_BOOT_ENV_SENTINEL;
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
it("leaves process.env as it found it,
|
|
17
|
+
it("leaves process.env as it found it, with a .env in the cwd", async () => {
|
|
18
18
|
dir = mkdtempSync(path.join(tmpdir(), "sb-boot-env-"));
|
|
19
19
|
writeFileSync(path.join(dir, ".env"), "PH_BOOT_ENV_SENTINEL=leaked\n");
|
|
20
20
|
process.chdir(dir);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { switchboardConfigFromEnv } from "../src/config/from-env.js";
|
|
2
|
+
import { callerOverEnv } from "../src/config/merge.js";
|
|
3
|
+
import type { SwitchboardConfigInput } from "../src/config/schema.js";
|
|
4
|
+
import { startSwitchboard, type SwitchboardDeps } from "../src/server.mjs";
|
|
5
|
+
|
|
6
|
+
/** Boots the way an edge does: the caller's layer over process.env's. */
|
|
7
|
+
export function bootSwitchboard(
|
|
8
|
+
config: SwitchboardConfigInput,
|
|
9
|
+
deps: SwitchboardDeps = {},
|
|
10
|
+
): ReturnType<typeof startSwitchboard> {
|
|
11
|
+
return startSwitchboard(
|
|
12
|
+
callerOverEnv(
|
|
13
|
+
switchboardConfigFromEnv(process.env, { logger: deps.logger }),
|
|
14
|
+
config,
|
|
15
|
+
),
|
|
16
|
+
deps,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -3,7 +3,8 @@ import { tmpdir } from "node:os";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import type { ILogger } from "document-model";
|
|
5
5
|
import { describe, expect, it, vi } from "vitest";
|
|
6
|
-
import { startSwitchboard } from "../src/server.mjs";
|
|
6
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
7
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
7
8
|
|
|
8
9
|
function stubLogger(): ILogger {
|
|
9
10
|
const logger = {
|
|
@@ -40,19 +41,21 @@ async function withSwitchboard(
|
|
|
40
41
|
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
41
42
|
|
|
42
43
|
try {
|
|
43
|
-
switchboard = await
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
switchboard = await bootSwitchboard(
|
|
45
|
+
{
|
|
46
|
+
server: { port: 0 },
|
|
47
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
48
|
+
features: { workflows: false },
|
|
49
|
+
inspection: { enabled: inspection },
|
|
50
|
+
packages: { disableLocal: true },
|
|
51
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
52
|
+
drive: {
|
|
53
|
+
slug: "default-drive",
|
|
54
|
+
global: { name: "Default Drive" },
|
|
55
|
+
},
|
|
53
56
|
},
|
|
54
|
-
logger: stubLogger(),
|
|
55
|
-
|
|
57
|
+
{ logger: stubLogger() },
|
|
58
|
+
);
|
|
56
59
|
await run(switchboard);
|
|
57
60
|
await switchboard.shutdown();
|
|
58
61
|
switchboard = undefined;
|
|
@@ -3,7 +3,8 @@ import { tmpdir } from "node:os";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import type { ILogger } from "document-model";
|
|
5
5
|
import { describe, expect, it, vi } from "vitest";
|
|
6
|
-
import { startSwitchboard } from "../src/server.mjs";
|
|
6
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
7
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
7
8
|
|
|
8
9
|
function stubLogger(): ILogger {
|
|
9
10
|
const logger = {
|
|
@@ -43,19 +44,20 @@ async function withSwitchboard(
|
|
|
43
44
|
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
44
45
|
|
|
45
46
|
try {
|
|
46
|
-
switchboard = await
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
switchboard = await bootSwitchboard(
|
|
48
|
+
{
|
|
49
|
+
server: { port: 0 },
|
|
50
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
51
|
+
features: { workflows: false, mcp: mcp },
|
|
52
|
+
packages: { disableLocal: true },
|
|
53
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
54
|
+
drive: {
|
|
55
|
+
slug: "default-drive",
|
|
56
|
+
global: { name: "Default Drive" },
|
|
57
|
+
},
|
|
56
58
|
},
|
|
57
|
-
logger: stubLogger(),
|
|
58
|
-
|
|
59
|
+
{ logger: stubLogger() },
|
|
60
|
+
);
|
|
59
61
|
await run(switchboard);
|
|
60
62
|
await switchboard.shutdown();
|
|
61
63
|
switchboard = undefined;
|
|
@@ -3,7 +3,8 @@ import { tmpdir } from "node:os";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import type { ILogger } from "document-model";
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
-
import { startSwitchboard } from "../src/server.mjs";
|
|
6
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
7
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
7
8
|
|
|
8
9
|
type Switchboard = Awaited<ReturnType<typeof startSwitchboard>>;
|
|
9
10
|
|
|
@@ -48,19 +49,20 @@ async function boot(): Promise<Switchboard> {
|
|
|
48
49
|
const tempRoot = await mkdtemp(join(tmpdir(), "switchboard-port-zero-"));
|
|
49
50
|
tempRoots.push(tempRoot);
|
|
50
51
|
process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
|
|
51
|
-
const switchboard = await
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
const switchboard = await bootSwitchboard(
|
|
53
|
+
{
|
|
54
|
+
server: { port: 0 },
|
|
55
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
56
|
+
features: { workflows: false, mcp: false },
|
|
57
|
+
packages: { disableLocal: true },
|
|
58
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
59
|
+
drive: {
|
|
60
|
+
slug: "default-drive",
|
|
61
|
+
global: { name: "Default Drive" },
|
|
62
|
+
},
|
|
61
63
|
},
|
|
62
|
-
logger: stubLogger(),
|
|
63
|
-
|
|
64
|
+
{ logger: stubLogger() },
|
|
65
|
+
);
|
|
64
66
|
running.push(switchboard);
|
|
65
67
|
return switchboard;
|
|
66
68
|
}
|
|
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
|
|
|
2
2
|
import {
|
|
3
3
|
reactorDbUrlOf,
|
|
4
4
|
switchboardBootFactsFromEnv,
|
|
5
|
+
switchboardBootFactsOf,
|
|
5
6
|
switchboardBootIssues,
|
|
6
7
|
type SwitchboardBootFacts,
|
|
7
8
|
} from "../src/boot.mjs";
|
|
@@ -66,6 +67,56 @@ describe("switchboardBootIssues", () => {
|
|
|
66
67
|
});
|
|
67
68
|
});
|
|
68
69
|
|
|
70
|
+
describe("switchboardBootFactsOf", () => {
|
|
71
|
+
it("reads the facts from a config", async () => {
|
|
72
|
+
expect(
|
|
73
|
+
await switchboardBootFactsOf(
|
|
74
|
+
{
|
|
75
|
+
storage: {
|
|
76
|
+
reactor: { url: POSTGRES },
|
|
77
|
+
readModel: { url: "./read" },
|
|
78
|
+
},
|
|
79
|
+
workers: { executor: { count: 3 }, projection: { enabled: true } },
|
|
80
|
+
protocol: { featureFlags: { authEnforcement: true } },
|
|
81
|
+
auth: { renown: { source: "self" } },
|
|
82
|
+
},
|
|
83
|
+
{ dev: false },
|
|
84
|
+
),
|
|
85
|
+
).toEqual({
|
|
86
|
+
dev: false,
|
|
87
|
+
workers: 3,
|
|
88
|
+
projectionWorker: true,
|
|
89
|
+
reactorDbUrl: POSTGRES,
|
|
90
|
+
authEnforcement: true,
|
|
91
|
+
renownSource: "self",
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("never takes the reactor database from the read model", async () => {
|
|
96
|
+
const facts = await switchboardBootFactsOf(
|
|
97
|
+
{ storage: { readModel: { url: POSTGRES } } },
|
|
98
|
+
{ dev: false },
|
|
99
|
+
);
|
|
100
|
+
expect(facts.reactorDbUrl).toBeUndefined();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("lets the config's renown source win over the configured one", async () => {
|
|
104
|
+
const configuredRenown = { source: "self" as const };
|
|
105
|
+
expect(
|
|
106
|
+
(await switchboardBootFactsOf({}, { dev: false, configuredRenown }))
|
|
107
|
+
.renownSource,
|
|
108
|
+
).toBe("self");
|
|
109
|
+
expect(
|
|
110
|
+
(
|
|
111
|
+
await switchboardBootFactsOf(
|
|
112
|
+
{ auth: { renown: { source: "remote" } } },
|
|
113
|
+
{ dev: false, configuredRenown },
|
|
114
|
+
)
|
|
115
|
+
).renownSource,
|
|
116
|
+
).toBe("remote");
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
69
120
|
describe("switchboardBootFactsFromEnv", () => {
|
|
70
121
|
it("reads the facts with the server's parsers", async () => {
|
|
71
122
|
const { facts, issues } = await switchboardBootFactsFromEnv(
|
|
@@ -4,7 +4,8 @@ import { join } from "node:path";
|
|
|
4
4
|
import type { ILogger } from "document-model";
|
|
5
5
|
import pg from "pg";
|
|
6
6
|
import { describe, expect, it, vi } from "vitest";
|
|
7
|
-
import { startSwitchboard } from "../src/server.mjs";
|
|
7
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
8
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
8
9
|
|
|
9
10
|
const ADMIN = "0xadad00000000000000000000000000000000adad";
|
|
10
11
|
const SECRET = "switchboard-privacy-test-deployment-secret-0123";
|
|
@@ -59,15 +60,16 @@ async function boot(
|
|
|
59
60
|
tempRoot: string,
|
|
60
61
|
logger: ILogger = stubLogger(),
|
|
61
62
|
): Promise<Switchboard> {
|
|
62
|
-
return
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
return bootSwitchboard(
|
|
64
|
+
{
|
|
65
|
+
server: { port: 0 },
|
|
66
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
67
|
+
features: { workflows: false, mcp: false },
|
|
68
|
+
packages: { disableLocal: true },
|
|
69
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
70
|
+
},
|
|
71
|
+
{ logger },
|
|
72
|
+
);
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
async function queryErasure(switchboard: Switchboard) {
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
vi,
|
|
27
27
|
} from "vitest";
|
|
28
28
|
import { ClosablePGliteDialect } from "../src/pglite-dialect.js";
|
|
29
|
-
import {
|
|
29
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
30
30
|
import { StoredDocumentsRefusedError } from "../src/unsupported-stored-documents.mjs";
|
|
31
31
|
|
|
32
32
|
const ENV_KEYS = [
|
|
@@ -143,14 +143,15 @@ describe("booting over documents this build does not run", () => {
|
|
|
143
143
|
}, BOOT_TIMEOUT);
|
|
144
144
|
|
|
145
145
|
function boot(logger: ILogger) {
|
|
146
|
-
return
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
146
|
+
return bootSwitchboard(
|
|
147
|
+
{
|
|
148
|
+
server: { port: 0 },
|
|
149
|
+
features: { workflows: false, mcp: false },
|
|
150
|
+
packages: { disableLocal: true },
|
|
151
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
152
|
+
},
|
|
153
|
+
{ logger },
|
|
154
|
+
);
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
it(
|
|
@@ -8,7 +8,8 @@ import { join } from "node:path";
|
|
|
8
8
|
import type { ILogger } from "document-model";
|
|
9
9
|
import { describe, expect, it, vi } from "vitest";
|
|
10
10
|
import type * as RenownModule from "../src/renown.js";
|
|
11
|
-
import { startSwitchboard } from "../src/server.mjs";
|
|
11
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
12
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
12
13
|
|
|
13
14
|
vi.mock("../src/renown.js", async (importOriginal) => ({
|
|
14
15
|
...(await importOriginal<typeof RenownModule>()),
|
|
@@ -37,14 +38,15 @@ describe("booting Switchboard without Renown", () => {
|
|
|
37
38
|
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
38
39
|
|
|
39
40
|
try {
|
|
40
|
-
switchboard = await
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
switchboard = await bootSwitchboard(
|
|
42
|
+
{
|
|
43
|
+
server: { port: 0 },
|
|
44
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
45
|
+
features: { workflows: false, mcp: false },
|
|
46
|
+
packages: { disableLocal: true },
|
|
47
|
+
},
|
|
48
|
+
{ logger },
|
|
49
|
+
);
|
|
48
50
|
|
|
49
51
|
expect(
|
|
50
52
|
logger.warn.mock.calls.some(
|
|
@@ -3,7 +3,8 @@ import { tmpdir } from "node:os";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import type { ILogger } from "document-model";
|
|
5
5
|
import { describe, expect, it, vi } from "vitest";
|
|
6
|
-
import { startSwitchboard } from "../src/server.mjs";
|
|
6
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
7
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
7
8
|
|
|
8
9
|
function stubLogger(): ILogger & { info: ReturnType<typeof vi.fn> } {
|
|
9
10
|
const logger = {
|
|
@@ -31,15 +32,16 @@ describe("booting Switchboard", () => {
|
|
|
31
32
|
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
32
33
|
|
|
33
34
|
try {
|
|
34
|
-
switchboard = await
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
switchboard = await bootSwitchboard(
|
|
36
|
+
{
|
|
37
|
+
server: { port: 0 },
|
|
38
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
39
|
+
features: { workflows: false, mcp: false },
|
|
40
|
+
packages: { disableLocal: true },
|
|
41
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
42
|
+
},
|
|
43
|
+
{ logger },
|
|
44
|
+
);
|
|
43
45
|
|
|
44
46
|
const flagLog = logger.info.mock.calls.find(
|
|
45
47
|
([message]) => message === "Feature flags: @flags",
|
|
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
6
|
import type * as RenownModule from "../src/renown.js";
|
|
7
|
-
import {
|
|
7
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
8
8
|
|
|
9
9
|
vi.mock("../src/renown.js", async (importOriginal) => ({
|
|
10
10
|
...(await importOriginal<typeof RenownModule>()),
|
|
@@ -57,15 +57,16 @@ describe("booting with pooled workers under authEnforcement", () => {
|
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
function boot(numWorkers: number) {
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
return bootSwitchboard(
|
|
61
|
+
{
|
|
62
|
+
server: { port: 0 },
|
|
63
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
64
|
+
features: { workflows: false, mcp: false },
|
|
65
|
+
packages: { disableLocal: true },
|
|
66
|
+
workers: { executor: { count: numWorkers } },
|
|
67
|
+
},
|
|
68
|
+
{ logger: stubLogger() },
|
|
69
|
+
);
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
it("fails with a self Renown source", async () => {
|
|
@@ -39,6 +39,7 @@ vi.mock("@powerhousedao/reactor-workflow", async (importOriginal) => {
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
const { startSwitchboard } = await import("../src/server.mjs");
|
|
42
|
+
const { bootSwitchboard } = await import("./boot-helpers.js");
|
|
42
43
|
|
|
43
44
|
function stubLogger(): ILogger & { warn: ReturnType<typeof vi.fn> } {
|
|
44
45
|
const logger = {
|
|
@@ -63,15 +64,16 @@ describe("booting Switchboard when another process holds the singleton", () => {
|
|
|
63
64
|
|
|
64
65
|
try {
|
|
65
66
|
// The boot RESOLVES. That is the whole finding.
|
|
66
|
-
switchboard = await
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
switchboard = await bootSwitchboard(
|
|
68
|
+
{
|
|
69
|
+
server: { port: 0 },
|
|
70
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
71
|
+
features: { workflows: true, mcp: false },
|
|
72
|
+
packages: { disableLocal: true },
|
|
73
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
74
|
+
},
|
|
75
|
+
{ logger },
|
|
76
|
+
);
|
|
75
77
|
|
|
76
78
|
// The API is up and serving: the reactor answers, the document models
|
|
77
79
|
// are registered, everything but workflows works.
|
|
@@ -16,7 +16,8 @@ import type { ILogger } from "document-model";
|
|
|
16
16
|
import { Kysely, PostgresDialect } from "kysely";
|
|
17
17
|
import pg from "pg";
|
|
18
18
|
import { describe, expect, it, vi } from "vitest";
|
|
19
|
-
import { startSwitchboard } from "../src/server.mjs";
|
|
19
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
20
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
20
21
|
|
|
21
22
|
const PG_URL = process.env.REACTOR_TEST_PG_URL;
|
|
22
23
|
const DATABASE = "switchboard_workflow_retry";
|
|
@@ -74,15 +75,16 @@ describe.skipIf(!PG_URL)(
|
|
|
74
75
|
owner: "the-other-host",
|
|
75
76
|
});
|
|
76
77
|
|
|
77
|
-
switchboard = await
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
switchboard = await bootSwitchboard(
|
|
79
|
+
{
|
|
80
|
+
server: { port: 0 },
|
|
81
|
+
storage: { readModel: { url: readModelUrl } },
|
|
82
|
+
features: { workflows: true, mcp: false },
|
|
83
|
+
packages: { disableLocal: true },
|
|
84
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
85
|
+
},
|
|
86
|
+
{ logger: stubLogger() },
|
|
87
|
+
);
|
|
86
88
|
expect(switchboard.workflowTriggers).toBeUndefined();
|
|
87
89
|
expect(await queryHealth(switchboard.port)).toBeUndefined();
|
|
88
90
|
|