@powerhousedao/switchboard 6.2.3 → 6.3.0-dev.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.tsbuild/test/ai-gateway.test.d.ts +2 -0
- package/.tsbuild/test/ai-gateway.test.d.ts.map +1 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts +2 -0
- package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts +2 -0
- package/.tsbuild/test/boot-auth-config.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-desktop-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-desktop-auth.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts +2 -0
- package/.tsbuild/test/boot-env-isolation.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-helpers.d.ts +5 -0
- package/.tsbuild/test/boot-helpers.d.ts.map +1 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-mcp-auth.test.d.ts +2 -0
- package/.tsbuild/test/boot-mcp-auth.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-port-zero.test.d.ts +2 -0
- package/.tsbuild/test/boot-port-zero.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts +2 -0
- package/.tsbuild/test/boot-preconditions.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-privacy.test.d.ts +2 -0
- package/.tsbuild/test/boot-privacy.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-ready-drives.test.d.ts +2 -0
- package/.tsbuild/test/boot-ready-drives.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-undo-v3-flag.test.d.ts +2 -0
- package/.tsbuild/test/boot-undo-v3-flag.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts.map +1 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts +2 -0
- package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts.map +1 -0
- package/.tsbuild/test/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-composition.test.d.ts +2 -0
- package/.tsbuild/test/default-composition.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-protocol-versions.test.d.ts.map +1 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
- package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
- package/.tsbuild/test/delegated-publish.test.d.ts +2 -0
- package/.tsbuild/test/delegated-publish.test.d.ts.map +1 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts +2 -0
- package/.tsbuild/test/durable-node-fs-pg16.test.d.ts.map +1 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.d.ts +13 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.d.ts.map +1 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/index.d.ts +3 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/index.d.ts.map +1 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/tally/index.d.ts +7 -0
- package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/tally/index.d.ts.map +1 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts +2 -0
- package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
- package/.tsbuild/test/keyframe-reclaim-store.test.d.ts +2 -0
- package/.tsbuild/test/keyframe-reclaim-store.test.d.ts.map +1 -0
- package/.tsbuild/test/observability-signals.test.d.ts +2 -0
- package/.tsbuild/test/observability-signals.test.d.ts.map +1 -0
- package/.tsbuild/test/permissions-backfill.test.d.ts +2 -0
- package/.tsbuild/test/permissions-backfill.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts +2 -0
- package/.tsbuild/test/pglite-preflight.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts +2 -0
- package/.tsbuild/test/pglite-storage-dirs.test.d.ts.map +1 -0
- package/.tsbuild/test/pglite-store.test.d.ts +2 -0
- package/.tsbuild/test/pglite-store.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
- package/.tsbuild/test/plugin-config-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
- package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
- package/.tsbuild/test/port-probe.test.d.ts +2 -0
- package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
- package/.tsbuild/test/processor-timing-log.test.d.ts +2 -0
- package/.tsbuild/test/processor-timing-log.test.d.ts.map +1 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
- package/.tsbuild/test/renown-storage-path.test.d.ts.map +1 -0
- package/.tsbuild/test/served-schemas-mixed-package.test.d.ts +2 -0
- package/.tsbuild/test/served-schemas-mixed-package.test.d.ts.map +1 -0
- package/.tsbuild/test/served-schemas.test.d.ts +2 -0
- package/.tsbuild/test/served-schemas.test.d.ts.map +1 -0
- package/.tsbuild/test/shutdown.test.d.ts +2 -0
- package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
- package/.tsbuild/test/snapshot-writer.d.ts +18 -0
- package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
- package/.tsbuild/test/store-lock.test.d.ts +2 -0
- package/.tsbuild/test/store-lock.test.d.ts.map +1 -0
- package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
- package/.tsbuild/test/two-switchboards.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/runtime-host.test.d.ts +2 -0
- package/.tsbuild/test/workflow/runtime-host.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-reactor-access.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
- package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
- package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/Auth.md +108 -2
- package/CHANGELOG.md +1122 -2
- package/README.md +69 -24
- package/dist/boot.d.mts +46 -0
- package/dist/boot.d.mts.map +1 -0
- package/dist/boot.mjs +67 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/config/from-env.d.mts +15 -0
- package/dist/config/from-env.d.mts.map +1 -0
- package/dist/config/from-env.mjs +4 -0
- package/dist/config/schema.d.mts +3 -0
- package/dist/config/schema.mjs +4 -0
- package/dist/from-env-DKK_wPrO.mjs +497 -0
- package/dist/from-env-DKK_wPrO.mjs.map +1 -0
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +40 -219
- package/dist/index.mjs.map +1 -1
- package/dist/mcp-VW52B8KD.mjs +32 -0
- package/dist/mcp-VW52B8KD.mjs.map +1 -0
- package/dist/migrate.mjs +5 -4
- package/dist/migrate.mjs.map +1 -1
- package/dist/observability-CldagyT_.mjs +224 -0
- package/dist/observability-CldagyT_.mjs.map +1 -0
- package/dist/observability.d.mts +30 -0
- package/dist/observability.d.mts.map +1 -0
- package/dist/observability.mjs +4 -0
- package/dist/plugin-host-tTjDTNz0.d.mts +46 -0
- package/dist/plugin-host-tTjDTNz0.d.mts.map +1 -0
- package/dist/plugins/ai.d.mts +37 -0
- package/dist/plugins/ai.d.mts.map +1 -0
- package/dist/plugins/ai.mjs +400 -0
- package/dist/plugins/ai.mjs.map +1 -0
- package/dist/plugins/attachments.d.mts +33 -0
- package/dist/plugins/attachments.d.mts.map +1 -0
- package/dist/plugins/attachments.mjs +4 -0
- package/dist/plugins/mcp.d.mts +31 -0
- package/dist/plugins/mcp.d.mts.map +1 -0
- package/dist/plugins/mcp.mjs +4 -0
- package/dist/plugins/privacy.d.mts +22 -0
- package/dist/plugins/privacy.d.mts.map +1 -0
- package/dist/plugins/privacy.mjs +4 -0
- package/dist/plugins/workflows.d.mts +80 -0
- package/dist/plugins/workflows.d.mts.map +1 -0
- package/dist/plugins/workflows.mjs +4 -0
- package/dist/postgres-url-DTDhBjXX.mjs +11 -0
- package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
- package/dist/privacy-HQnhqf2H.mjs +91 -0
- package/dist/privacy-HQnhqf2H.mjs.map +1 -0
- package/dist/privacy-UodgY0i_.mjs +44 -0
- package/dist/privacy-UodgY0i_.mjs.map +1 -0
- package/dist/renown-layers-DmbWLt46.mjs +42 -0
- package/dist/renown-layers-DmbWLt46.mjs.map +1 -0
- package/dist/schema-BJ-OFAox.mjs +359 -0
- package/dist/schema-BJ-OFAox.mjs.map +1 -0
- package/dist/schema-w1lShimw.d.mts +258 -0
- package/dist/schema-w1lShimw.d.mts.map +1 -0
- package/dist/server-BS-PFzoK.mjs +2752 -0
- package/dist/server-BS-PFzoK.mjs.map +1 -0
- package/dist/server.d.mts +94 -228
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +5 -4
- package/dist/types-Bk4T4D9F.d.mts +318 -0
- package/dist/types-Bk4T4D9F.d.mts.map +1 -0
- package/dist/utils-Cm0TE6dP.mjs +148 -0
- package/dist/utils-Cm0TE6dP.mjs.map +1 -0
- package/dist/utils.d.mts +29 -3
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +5 -4
- package/dist/worker-pool-gyxJnCxA.mjs +304 -0
- package/dist/worker-pool-gyxJnCxA.mjs.map +1 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts +33 -0
- package/dist/workflow-runtime-CF5pc8mt.d.mts.map +1 -0
- package/dist/workflows-mdYUh3Us.mjs +1947 -0
- package/dist/workflows-mdYUh3Us.mjs.map +1 -0
- package/package.json +86 -24
- package/scripts/install-packages.sh +0 -0
- package/test/ai-gateway.test.ts +612 -0
- package/test/attachment-reference-read-model.test.ts +28 -20
- package/test/attachments/byte-grants.test.ts +4 -1
- package/test/attachments/download-target.test.ts +36 -20
- package/test/attachments/index.test.ts +13 -1
- package/test/attachments/reserve-metadata-parity.test.ts +96 -0
- package/test/attachments/routes-integration.test.ts +1 -0
- package/test/attachments/routes.test.ts +132 -12
- package/test/attachments/service-config.test.ts +28 -16
- package/test/boot-auth-config.test.ts +146 -0
- package/test/boot-create-signature-policy.test.ts +15 -13
- package/test/boot-desktop-auth.test.ts +278 -0
- package/test/boot-env-isolation.test.ts +26 -0
- package/test/boot-helpers.ts +19 -0
- package/test/boot-inspection-enabled.test.ts +140 -0
- package/test/boot-mcp-auth.test.ts +449 -0
- package/test/boot-mcp-enabled.test.ts +27 -27
- package/test/boot-port-zero.test.ts +101 -0
- package/test/boot-preconditions.test.ts +213 -0
- package/test/boot-privacy.test.ts +232 -0
- package/test/boot-ready-drives.test.ts +141 -0
- package/test/boot-undo-v3-flag.test.ts +120 -0
- package/test/boot-unsupported-stored-documents.test.ts +23 -19
- 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 +109 -0
- package/test/boot-workflow-singleton-retry.test.ts +122 -0
- package/test/config-from-env.test.ts +968 -0
- package/test/config-merge.test.ts +351 -0
- package/test/config-schema.test.ts +183 -0
- package/test/default-composition.test.ts +290 -0
- package/test/default-drive-protocol-versions.test.ts +79 -0
- package/test/default-drive-slug.test.ts +265 -0
- package/test/delegated-publish.test.ts +435 -0
- package/test/durable-node-fs-pg16.test.ts +80 -0
- package/test/fatal-shutdown.test.ts +104 -1
- package/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.ts +16 -0
- package/test/fixtures/mixed-subgraphs/subgraphs/index.ts +3 -0
- package/test/fixtures/mixed-subgraphs/subgraphs/tally/index.ts +73 -0
- package/test/goldens/packages.graphql +797 -0
- package/test/goldens/privacy.graphql +853 -0
- package/test/goldens/reactor-drive-nodes.graphql +827 -0
- package/test/goldens/resolvers.json +327 -0
- package/test/goldens/supergraph.graphql +5918 -0
- package/test/goldens/workflow-runtime.graphql +1548 -0
- package/test/inspection-throttle.test.ts +23 -0
- package/test/keyframe-reclaim-store.test.ts +156 -0
- package/test/observability-signals.test.ts +131 -0
- package/test/permissions-backfill.test.ts +486 -0
- package/test/pglite-dialect.test.ts +237 -2
- package/test/pglite-preflight.test.ts +313 -0
- package/test/pglite-storage-dirs.test.ts +113 -0
- package/test/pglite-store.test.ts +441 -0
- package/test/pglite-version.test.ts +9 -1
- package/test/plugin-config-schemas.test.ts +83 -0
- package/test/plugin-presence.test.ts +262 -0
- package/test/port-probe.test.ts +45 -0
- package/test/processor-timing-log.test.ts +109 -0
- package/test/reactor-feature-flags.test.ts +20 -0
- package/test/redact-webhook-path.test.ts +9 -0
- package/test/renown-storage-path.test.ts +40 -0
- package/test/renown-trust-policy.test.ts +7 -9
- package/test/served-schemas-mixed-package.test.ts +251 -0
- package/test/served-schemas.test.ts +134 -0
- package/test/shutdown.test.ts +278 -0
- package/test/snapshot-writer.ts +94 -0
- package/test/store-lock.test.ts +65 -0
- package/test/two-switchboards.test.ts +146 -0
- package/test/worker-pool.test.ts +27 -1
- package/test/workflow/oauth-apps-config.test.ts +66 -0
- package/test/workflow/oauth.test.ts +82 -10
- package/test/workflow/resolvers.test.ts +230 -38
- package/test/workflow/runtime-host.test.ts +19 -0
- package/test/workflow/waitpoint-routes.test.ts +306 -0
- package/test/workflow/waitpoint-runtime.test.ts +204 -0
- package/test/workflow/webhook-trigger-test.test.ts +8 -0
- package/test/workflow-reactor-access.test.ts +384 -0
- package/test/workflow-reactor-enforcement.test.ts +808 -0
- package/test/workflow-read-gate.test.ts +128 -60
- package/test/workflow-runtime.test.ts +1005 -237
- package/test/workflows-plugin-config.test.ts +77 -0
- package/tsconfig.json +5 -2
- package/tsdown.config.ts +12 -0
- package/vitest.config.ts +66 -1
- package/.tsbuild/test/mcp-flag.test.d.ts +0 -2
- package/.tsbuild/test/mcp-flag.test.d.ts.map +0 -1
- package/dist/server-sQoWp21G.mjs +0 -2939
- package/dist/server-sQoWp21G.mjs.map +0 -1
- package/dist/utils-uaBlzyjS.mjs +0 -86
- package/dist/utils-uaBlzyjS.mjs.map +0 -1
- package/test/mcp-flag.test.ts +0 -56
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Test-only v1 snapshot.bin writer over a loose on-disk tree.
|
|
2
|
+
import { promises as fs } from "node:fs";
|
|
3
|
+
import type { FileHandle } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
const MAGIC = new Uint8Array([0x50, 0x47, 0x4c, 0x41]);
|
|
7
|
+
const FORMAT_VERSION = 1;
|
|
8
|
+
const HEADER_SIZE = 12;
|
|
9
|
+
const ENTRY_PREFIX_SIZE = 9;
|
|
10
|
+
const DEFAULT_SKIP = ["snapshot.bin", "snapshot.bin.tmp"];
|
|
11
|
+
|
|
12
|
+
export interface SnapshotEntry {
|
|
13
|
+
type: 0 | 1;
|
|
14
|
+
mode: number;
|
|
15
|
+
relPath: string;
|
|
16
|
+
data?: Buffer;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface WriteSnapshotOptions {
|
|
20
|
+
/** Root-level names to leave out. Defaults to the snapshot files. */
|
|
21
|
+
skip?: string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function collectDiskEntries(
|
|
25
|
+
dataDir: string,
|
|
26
|
+
options: WriteSnapshotOptions = {},
|
|
27
|
+
): Promise<SnapshotEntry[]> {
|
|
28
|
+
const skip = new Set(options.skip ?? DEFAULT_SKIP);
|
|
29
|
+
const entries: SnapshotEntry[] = [];
|
|
30
|
+
const walk = async (dir: string, rel: string) => {
|
|
31
|
+
const names = (await fs.readdir(dir)).sort();
|
|
32
|
+
for (const name of names) {
|
|
33
|
+
if (rel === "" && skip.has(name)) continue;
|
|
34
|
+
const full = path.join(dir, name);
|
|
35
|
+
const relPath = rel === "" ? name : `${rel}/${name}`;
|
|
36
|
+
const stat = await fs.lstat(full);
|
|
37
|
+
if (stat.isDirectory()) {
|
|
38
|
+
entries.push({ type: 0, mode: stat.mode & 0o7777, relPath });
|
|
39
|
+
await walk(full, relPath);
|
|
40
|
+
} else if (stat.isFile()) {
|
|
41
|
+
entries.push({
|
|
42
|
+
type: 1,
|
|
43
|
+
mode: stat.mode & 0o7777,
|
|
44
|
+
relPath,
|
|
45
|
+
data: await fs.readFile(full),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
await walk(dataDir, "");
|
|
51
|
+
return entries;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function encodeSnapshot(entries: SnapshotEntry[]): Buffer {
|
|
55
|
+
const encoder = new TextEncoder();
|
|
56
|
+
const parts: Buffer[] = [];
|
|
57
|
+
const header = Buffer.alloc(HEADER_SIZE);
|
|
58
|
+
header.set(MAGIC, 0);
|
|
59
|
+
header.writeUInt32LE(FORMAT_VERSION, 4);
|
|
60
|
+
header.writeUInt32LE(entries.length, 8);
|
|
61
|
+
parts.push(header);
|
|
62
|
+
for (const entry of entries) {
|
|
63
|
+
const pathBytes = encoder.encode(entry.relPath);
|
|
64
|
+
const dataLen = entry.data?.byteLength ?? 0;
|
|
65
|
+
const prefix = Buffer.alloc(ENTRY_PREFIX_SIZE + pathBytes.byteLength + 4);
|
|
66
|
+
prefix.writeUInt8(entry.type, 0);
|
|
67
|
+
prefix.writeUInt32LE(entry.mode, 1);
|
|
68
|
+
prefix.writeUInt32LE(pathBytes.byteLength, 5);
|
|
69
|
+
prefix.set(pathBytes, ENTRY_PREFIX_SIZE);
|
|
70
|
+
prefix.writeUInt32LE(dataLen, ENTRY_PREFIX_SIZE + pathBytes.byteLength);
|
|
71
|
+
parts.push(prefix);
|
|
72
|
+
if (entry.data && dataLen > 0) parts.push(entry.data);
|
|
73
|
+
}
|
|
74
|
+
return Buffer.concat(parts);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Serializes `dataDir` into `snapshotPath`. Returns the entry count and size. */
|
|
78
|
+
export async function writeSnapshotFromDir(
|
|
79
|
+
dataDir: string,
|
|
80
|
+
snapshotPath: string,
|
|
81
|
+
options: WriteSnapshotOptions = {},
|
|
82
|
+
): Promise<{ entries: number; bytes: number }> {
|
|
83
|
+
const entries = await collectDiskEntries(dataDir, options);
|
|
84
|
+
const bytes = encodeSnapshot(entries);
|
|
85
|
+
let fh: FileHandle | undefined;
|
|
86
|
+
try {
|
|
87
|
+
fh = await fs.open(snapshotPath, "w");
|
|
88
|
+
await fh.writeFile(bytes);
|
|
89
|
+
await fh.sync();
|
|
90
|
+
} finally {
|
|
91
|
+
await fh?.close();
|
|
92
|
+
}
|
|
93
|
+
return { entries: entries.length, bytes: bytes.byteLength };
|
|
94
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
import {
|
|
6
|
+
acquireStoreLocks,
|
|
7
|
+
releaseStoreLocks,
|
|
8
|
+
StoreInUseError,
|
|
9
|
+
} from "../src/store-lock.mjs";
|
|
10
|
+
|
|
11
|
+
const dirs: string[] = [];
|
|
12
|
+
function store(): string {
|
|
13
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "ph-store-lock-"));
|
|
14
|
+
dirs.push(root);
|
|
15
|
+
return path.join(root, "reactor-storage");
|
|
16
|
+
}
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
releaseStoreLocks();
|
|
19
|
+
for (const d of dirs.splice(0))
|
|
20
|
+
fs.rmSync(d, { recursive: true, force: true });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const lockOf = (dir: string) => `${path.resolve(dir)}.lock`;
|
|
24
|
+
const lockPid = (dir: string) =>
|
|
25
|
+
(JSON.parse(fs.readFileSync(lockOf(dir), "utf8")) as { pid: number }).pid;
|
|
26
|
+
const claim = (dir: string, pid: number) =>
|
|
27
|
+
fs.writeFileSync(
|
|
28
|
+
lockOf(dir),
|
|
29
|
+
JSON.stringify({ pid, startedAt: "earlier", command: "ph run vetra" }),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
describe("acquireStoreLocks", () => {
|
|
33
|
+
it("writes a sibling lock (never inside the data dir) and releases it", () => {
|
|
34
|
+
const dir = store();
|
|
35
|
+
acquireStoreLocks([dir]);
|
|
36
|
+
expect(lockPid(dir)).toBe(process.pid);
|
|
37
|
+
expect(fs.existsSync(dir)).toBe(false); // initdb still gets an empty dir
|
|
38
|
+
releaseStoreLocks();
|
|
39
|
+
expect(fs.existsSync(lockOf(dir))).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("refuses a store held by another live process, naming it", () => {
|
|
43
|
+
const dir = store();
|
|
44
|
+
claim(dir, 4242);
|
|
45
|
+
expect(() => acquireStoreLocks([dir], (pid) => pid === 4242)).toThrow(
|
|
46
|
+
StoreInUseError,
|
|
47
|
+
);
|
|
48
|
+
expect(() => acquireStoreLocks([dir], (pid) => pid === 4242)).toThrow(
|
|
49
|
+
/pid 4242.*ph run vetra/,
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("takes over a stale lock from a dead (hard-killed) process", () => {
|
|
54
|
+
const dir = store();
|
|
55
|
+
claim(dir, 4242);
|
|
56
|
+
acquireStoreLocks([dir], () => false);
|
|
57
|
+
expect(lockPid(dir)).toBe(process.pid);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("is re-entrant for the owning process (in-process restarts)", () => {
|
|
61
|
+
const dir = store();
|
|
62
|
+
acquireStoreLocks([dir]);
|
|
63
|
+
expect(() => acquireStoreLocks([dir])).not.toThrow();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { signaturePolicyOf } from "@powerhousedao/shared/document-model";
|
|
2
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import type { ILogger } from "document-model";
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import type { SwitchboardConfigInput } from "../src/config/schema.js";
|
|
8
|
+
import { startSwitchboard, type SwitchboardReactor } from "../src/server.mjs";
|
|
9
|
+
|
|
10
|
+
type Info = ReturnType<typeof vi.fn>;
|
|
11
|
+
|
|
12
|
+
function stubLogger(): ILogger & { info: Info } {
|
|
13
|
+
const logger = {
|
|
14
|
+
verbose: vi.fn(),
|
|
15
|
+
debug: vi.fn(),
|
|
16
|
+
info: vi.fn(),
|
|
17
|
+
warn: vi.fn(),
|
|
18
|
+
error: vi.fn(),
|
|
19
|
+
child: vi.fn(),
|
|
20
|
+
};
|
|
21
|
+
logger.child.mockReturnValue(logger);
|
|
22
|
+
return logger as unknown as ILogger & { info: Info };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function messages(logger: { info: Info }): string[] {
|
|
26
|
+
return logger.info.mock.calls.map(([message]) => String(message));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The `[policy enforcement, caller identity]` reactor-api logged, if any. */
|
|
30
|
+
function authSetup(logger: { info: Info }): unknown[] | undefined {
|
|
31
|
+
return logger.info.mock.calls
|
|
32
|
+
.find(([message]) =>
|
|
33
|
+
String(message).startsWith("Setting up Auth middleware"),
|
|
34
|
+
)
|
|
35
|
+
?.slice(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function throttled(port: number): Promise<boolean> {
|
|
39
|
+
const response = await fetch(`http://localhost:${port}/graphql/inspection`, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: { "content-type": "application/json" },
|
|
42
|
+
body: JSON.stringify({
|
|
43
|
+
query:
|
|
44
|
+
'{ inspection { validateDocument(documentId: "missing") { documentId } } }',
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
const body = (await response.json()) as {
|
|
48
|
+
errors?: { extensions?: { code?: string } }[];
|
|
49
|
+
};
|
|
50
|
+
return (body.errors ?? []).some(
|
|
51
|
+
(error) => error.extensions?.code === "TOO_MANY_REQUESTS",
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Env a direct caller does not map: nothing inside the server may read it.
|
|
56
|
+
const STRAY_ENV = { AUTH_ENABLED: "true", ADMINS: "0xenv" };
|
|
57
|
+
|
|
58
|
+
describe("two switchboards in one process", () => {
|
|
59
|
+
let root: string;
|
|
60
|
+
const started: SwitchboardReactor[] = [];
|
|
61
|
+
const previous = new Map<string, string | undefined>();
|
|
62
|
+
|
|
63
|
+
beforeEach(async () => {
|
|
64
|
+
root = await mkdtemp(join(tmpdir(), "switchboard-two-"));
|
|
65
|
+
for (const [name, value] of Object.entries(STRAY_ENV)) {
|
|
66
|
+
previous.set(name, process.env[name]);
|
|
67
|
+
process.env[name] = value;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
afterEach(async () => {
|
|
72
|
+
for (const handle of started.splice(0)) await handle.shutdown();
|
|
73
|
+
for (const [name, value] of previous) {
|
|
74
|
+
if (value === undefined) delete process.env[name];
|
|
75
|
+
else process.env[name] = value;
|
|
76
|
+
}
|
|
77
|
+
previous.clear();
|
|
78
|
+
await rm(root, { recursive: true, force: true });
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
async function boot(name: string, config: SwitchboardConfigInput) {
|
|
82
|
+
const logger = stubLogger();
|
|
83
|
+
const handle = await startSwitchboard(
|
|
84
|
+
{
|
|
85
|
+
server: { port: 0 },
|
|
86
|
+
storage: { inMemory: true, userDataDir: join(root, name) },
|
|
87
|
+
features: { workflows: false, mcp: false },
|
|
88
|
+
packages: { disableLocal: true },
|
|
89
|
+
identity: { keypairPath: join(root, name, "identity.json") },
|
|
90
|
+
...config,
|
|
91
|
+
},
|
|
92
|
+
{ logger, signalHandlers: false, fatalErrorShutdown: false },
|
|
93
|
+
);
|
|
94
|
+
started.push(handle);
|
|
95
|
+
return { handle, logger };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
it("runs each on its own config, not on the process env", async () => {
|
|
99
|
+
const a = await boot("a", {
|
|
100
|
+
protocol: {
|
|
101
|
+
featureFlags: { documentDecisions: true },
|
|
102
|
+
createSignaturePolicy: "legacy",
|
|
103
|
+
},
|
|
104
|
+
auth: { resolveIdentity: true },
|
|
105
|
+
inspection: { callsPerMinute: 1 },
|
|
106
|
+
});
|
|
107
|
+
const b = await boot("b", {
|
|
108
|
+
protocol: { featureFlags: { documentDecisions: false } },
|
|
109
|
+
inspection: { callsPerMinute: 3 },
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
expect(a.handle.port).toBeGreaterThan(0);
|
|
113
|
+
expect(b.handle.port).toBeGreaterThan(0);
|
|
114
|
+
expect(a.handle.port).not.toBe(b.handle.port);
|
|
115
|
+
|
|
116
|
+
const flagsOn = "Reactor feature flags enabled: documentDecisions";
|
|
117
|
+
expect(messages(a.logger)).toContain(flagsOn);
|
|
118
|
+
expect(messages(b.logger)).not.toContain(flagsOn);
|
|
119
|
+
|
|
120
|
+
// AUTH_ENABLED in process.env reaches neither.
|
|
121
|
+
expect(authSetup(a.logger)).toEqual([false, true]);
|
|
122
|
+
expect(authSetup(b.logger)).toBeUndefined();
|
|
123
|
+
|
|
124
|
+
const onA = await a.handle.reactor.createEmpty("powerhouse/document-model");
|
|
125
|
+
const onB = await b.handle.reactor.createEmpty("powerhouse/document-model");
|
|
126
|
+
expect(signaturePolicyOf(onA.header)).toBe("legacy");
|
|
127
|
+
expect(signaturePolicyOf(onB.header)).toBe("v2-required");
|
|
128
|
+
const exists = (handle: SwitchboardReactor, id: string) =>
|
|
129
|
+
handle.reactor.get(id).then(
|
|
130
|
+
() => true,
|
|
131
|
+
() => false,
|
|
132
|
+
);
|
|
133
|
+
expect(await exists(a.handle, onA.header.id)).toBe(true);
|
|
134
|
+
expect(await exists(b.handle, onA.header.id)).toBe(false);
|
|
135
|
+
expect(await exists(a.handle, onB.header.id)).toBe(false);
|
|
136
|
+
|
|
137
|
+
expect(a.handle.inspectionEnabled).toBe(true);
|
|
138
|
+
expect(b.handle.inspectionEnabled).toBe(true);
|
|
139
|
+
expect(await throttled(a.handle.port)).toBe(false);
|
|
140
|
+
expect(await throttled(a.handle.port)).toBe(true);
|
|
141
|
+
for (let call = 0; call < 3; call++) {
|
|
142
|
+
expect(await throttled(b.handle.port)).toBe(false);
|
|
143
|
+
}
|
|
144
|
+
expect(await throttled(b.handle.port)).toBe(true);
|
|
145
|
+
}, 120_000);
|
|
146
|
+
});
|
package/test/worker-pool.test.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { ILogger } from "document-model";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
2
|
+
import { existsSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
3
5
|
import { describe, expect, it, vi } from "vitest";
|
|
4
6
|
import {
|
|
5
7
|
autoWorkerCount,
|
|
6
8
|
buildWorkerDbConfig,
|
|
9
|
+
keepImportableSources,
|
|
7
10
|
resolveHostPoolSize,
|
|
8
11
|
resolveWorkerModelSources,
|
|
9
12
|
resolveWorkerPoolOptions,
|
|
@@ -264,3 +267,26 @@ describe("resolveWorkerModelSources", () => {
|
|
|
264
267
|
expect(logger.warn).toHaveBeenCalledTimes(1);
|
|
265
268
|
});
|
|
266
269
|
});
|
|
270
|
+
|
|
271
|
+
describe("keepImportableSources", () => {
|
|
272
|
+
it("keeps sources that export a model and drops one that throws or has none", async () => {
|
|
273
|
+
const dir = mkdtempSync(path.join(tmpdir(), "ph-model-sources-"));
|
|
274
|
+
const good = path.join(dir, "good.mjs");
|
|
275
|
+
const broken = path.join(dir, "broken.mjs");
|
|
276
|
+
const empty = path.join(dir, "empty.mjs");
|
|
277
|
+
writeFileSync(
|
|
278
|
+
good,
|
|
279
|
+
'export const Model = { reducer: () => ({}), documentModel: { global: { id: "test/model" } } };',
|
|
280
|
+
);
|
|
281
|
+
writeFileSync(broken, 'throw new Error("stale dist");');
|
|
282
|
+
// What `ph init` builds for a project with no models yet.
|
|
283
|
+
writeFileSync(empty, "export {};");
|
|
284
|
+
|
|
285
|
+
const kept = await keepImportableSources(
|
|
286
|
+
[{ filePath: broken }, { filePath: good }, { filePath: empty }],
|
|
287
|
+
stubLogger(),
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
expect(kept).toEqual([{ filePath: good }]);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { parseOAuthApps } from "../../src/workflow/oauth-apps-config.js";
|
|
4
|
+
|
|
5
|
+
const DIR = path.resolve("/project");
|
|
6
|
+
const RELAY = {
|
|
7
|
+
clientId: "relay-cid",
|
|
8
|
+
redirectUri: "https://sektar.io/api/oauth/callback",
|
|
9
|
+
tokenUrl: "https://sektar.io/api/oauth/token",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
describe("workflows.oauthApps", () => {
|
|
13
|
+
it("resolves client files from the config file's folder and keeps a relay", () => {
|
|
14
|
+
expect(
|
|
15
|
+
parseOAuthApps(
|
|
16
|
+
[
|
|
17
|
+
{
|
|
18
|
+
id: "sektar-google",
|
|
19
|
+
clients: { desktop: "secrets/desktop.json" },
|
|
20
|
+
relay: RELAY,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
DIR,
|
|
24
|
+
),
|
|
25
|
+
).toEqual([
|
|
26
|
+
{
|
|
27
|
+
id: "sektar-google",
|
|
28
|
+
clients: { desktop: path.join(DIR, "secrets/desktop.json") },
|
|
29
|
+
relay: RELAY,
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("drops a relay that is not an object, keeping the app", () => {
|
|
35
|
+
const dropped: [string, unknown][] = [];
|
|
36
|
+
const apps = parseOAuthApps(
|
|
37
|
+
[
|
|
38
|
+
{ id: "string", clients: { web: "w.json" }, relay: RELAY.redirectUri },
|
|
39
|
+
{ id: "list", clients: { web: "w.json" }, relay: [RELAY] },
|
|
40
|
+
{ id: "null", clients: { web: "w.json" }, relay: null },
|
|
41
|
+
{ id: "none", clients: { web: "w.json" } },
|
|
42
|
+
],
|
|
43
|
+
DIR,
|
|
44
|
+
(id, relay) => dropped.push([id, relay]),
|
|
45
|
+
);
|
|
46
|
+
expect(apps.map((app) => app.id)).toEqual([
|
|
47
|
+
"string",
|
|
48
|
+
"list",
|
|
49
|
+
"null",
|
|
50
|
+
"none",
|
|
51
|
+
]);
|
|
52
|
+
for (const app of apps) expect(app).not.toHaveProperty("relay");
|
|
53
|
+
expect(dropped).toEqual([
|
|
54
|
+
["string", RELAY.redirectUri],
|
|
55
|
+
["list", [RELAY]],
|
|
56
|
+
["null", null],
|
|
57
|
+
]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("leaves out entries without an id and reads a non-list as none", () => {
|
|
61
|
+
expect(parseOAuthApps([{ clients: {} }, null, { id: "" }], DIR)).toEqual(
|
|
62
|
+
[],
|
|
63
|
+
);
|
|
64
|
+
expect(parseOAuthApps({ id: "x" }, DIR)).toEqual([]);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
createHttpAdapter,
|
|
5
5
|
HttpRouteService,
|
|
6
6
|
type Context,
|
|
7
|
-
type IAuthorizationService,
|
|
8
7
|
} from "@powerhousedao/reactor-api";
|
|
9
8
|
import type { WorkflowRuntimeService } from "@powerhousedao/reactor-workflow";
|
|
10
9
|
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
|
@@ -115,13 +114,12 @@ describe("startOAuth", () => {
|
|
|
115
114
|
user: { address: "0xadmin" },
|
|
116
115
|
}) as unknown as Context;
|
|
117
116
|
|
|
118
|
-
function build(callbackUrl: string | undefined
|
|
117
|
+
function build(callbackUrl: string | undefined) {
|
|
119
118
|
const runtime = {
|
|
120
119
|
startOAuth: vi.fn(() => Promise.resolve({})),
|
|
121
120
|
};
|
|
122
121
|
const resolvers = getResolvers(
|
|
123
122
|
runtime as unknown as WorkflowRuntimeService,
|
|
124
|
-
{ isSupremeAdmin: () => isAdmin } as unknown as IAuthorizationService,
|
|
125
123
|
callbackUrl ? { callbackUrl } : undefined,
|
|
126
124
|
) as Record<string, Record<string, Resolver>>;
|
|
127
125
|
return {
|
|
@@ -133,13 +131,6 @@ describe("startOAuth", () => {
|
|
|
133
131
|
|
|
134
132
|
const PATH = "/api/@powerhousedao/workflow/oauth/callback";
|
|
135
133
|
|
|
136
|
-
it("is an administrator's, like minting a secret", () => {
|
|
137
|
-
const { start } = build(`https://sb.example${PATH}`, false);
|
|
138
|
-
expect(() => start({}, { connectionId: "c1" }, ctx())).toThrow(
|
|
139
|
-
"Admin access required",
|
|
140
|
-
);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
134
|
it("uses the host's own redirect when it knows its origin", async () => {
|
|
144
135
|
const { runtime, start } = build(`https://sb.example${PATH}`);
|
|
145
136
|
await start(
|
|
@@ -212,3 +203,84 @@ describe("startOAuth", () => {
|
|
|
212
203
|
);
|
|
213
204
|
});
|
|
214
205
|
});
|
|
206
|
+
|
|
207
|
+
describe("oauthSignIn", () => {
|
|
208
|
+
const PATH = "/api/@powerhousedao/workflow/oauth/callback";
|
|
209
|
+
const CTX = { headers: {}, db: {}, user: { address: "0xabc" } } as never;
|
|
210
|
+
|
|
211
|
+
function build(
|
|
212
|
+
callbackUrl: string | undefined,
|
|
213
|
+
mode: "desktop" | "web" | "relay" | "none",
|
|
214
|
+
) {
|
|
215
|
+
const runtime = {
|
|
216
|
+
oauthSignInMode: vi.fn(() => Promise.resolve(mode)),
|
|
217
|
+
};
|
|
218
|
+
const resolvers = getResolvers(
|
|
219
|
+
runtime as unknown as WorkflowRuntimeService,
|
|
220
|
+
callbackUrl ? { callbackUrl } : undefined,
|
|
221
|
+
) as Record<string, Record<string, Resolver>>;
|
|
222
|
+
return { runtime, signIn: resolvers.WorkflowRuntimeQueries.oauthSignIn };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
it.each([
|
|
226
|
+
["desktop", "DESKTOP"],
|
|
227
|
+
["web", "WEB"],
|
|
228
|
+
["relay", "RELAY"],
|
|
229
|
+
["none", "NONE"],
|
|
230
|
+
] as const)(
|
|
231
|
+
"answers the runtime's %s decision for the host's own callback as %s",
|
|
232
|
+
async (mode, answer) => {
|
|
233
|
+
const own = `https://env.vetra.io${PATH}`;
|
|
234
|
+
const { runtime, signIn } = build(own, mode);
|
|
235
|
+
await expect(
|
|
236
|
+
signIn(
|
|
237
|
+
{},
|
|
238
|
+
{
|
|
239
|
+
appId: "sektar-google",
|
|
240
|
+
redirectUri: `https://evil.example${PATH}`,
|
|
241
|
+
},
|
|
242
|
+
CTX,
|
|
243
|
+
),
|
|
244
|
+
).resolves.toBe(answer);
|
|
245
|
+
expect(runtime.oauthSignInMode).toHaveBeenCalledWith(
|
|
246
|
+
"sektar-google",
|
|
247
|
+
own,
|
|
248
|
+
);
|
|
249
|
+
},
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
it("takes the caller's redirect when the host knows only its path", async () => {
|
|
253
|
+
const { runtime, signIn } = build(PATH, "desktop");
|
|
254
|
+
await expect(
|
|
255
|
+
signIn(
|
|
256
|
+
{},
|
|
257
|
+
{ appId: "sektar-google", redirectUri: `http://localhost:4001${PATH}` },
|
|
258
|
+
CTX,
|
|
259
|
+
),
|
|
260
|
+
).resolves.toBe("DESKTOP");
|
|
261
|
+
expect(runtime.oauthSignInMode).toHaveBeenCalledWith(
|
|
262
|
+
"sektar-google",
|
|
263
|
+
`http://localhost:4001${PATH}`,
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it("answers NONE when the host cannot name the callback a sign-in would use", async () => {
|
|
268
|
+
const noRoutes = build(undefined, "web");
|
|
269
|
+
await expect(
|
|
270
|
+
noRoutes.signIn({}, { appId: "sektar-google" }, CTX),
|
|
271
|
+
).resolves.toBe("NONE");
|
|
272
|
+
const pathOnly = build(PATH, "web");
|
|
273
|
+
await expect(
|
|
274
|
+
pathOnly.signIn({}, { appId: "sektar-google" }, CTX),
|
|
275
|
+
).resolves.toBe("NONE");
|
|
276
|
+
await expect(
|
|
277
|
+
pathOnly.signIn(
|
|
278
|
+
{},
|
|
279
|
+
{ appId: "sektar-google", redirectUri: "https://x.example/elsewhere" },
|
|
280
|
+
CTX,
|
|
281
|
+
),
|
|
282
|
+
).resolves.toBe("NONE");
|
|
283
|
+
expect(noRoutes.runtime.oauthSignInMode).not.toHaveBeenCalled();
|
|
284
|
+
expect(pathOnly.runtime.oauthSignInMode).not.toHaveBeenCalled();
|
|
285
|
+
});
|
|
286
|
+
});
|