@powerhousedao/switchboard 6.2.3-dev.55 → 6.2.3-dev.57
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-inspection-enabled.test.d.ts +2 -0
- package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
- package/.tsbuild/test/inspection-flag.test.d.ts +2 -0
- package/.tsbuild/test/inspection-flag.test.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/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +88 -0
- package/README.md +13 -11
- package/dist/index.mjs +1 -1
- package/dist/{server-kc2kg0hU.mjs → server-Cw2WnaCA.mjs} +122 -66
- package/dist/server-Cw2WnaCA.mjs.map +1 -0
- package/dist/server.d.mts +5 -0
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +3 -3
- package/package.json +15 -15
- package/test/attachments/routes.test.ts +105 -1
- package/test/boot-inspection-enabled.test.ts +150 -0
- package/test/inspection-flag.test.ts +62 -0
- package/test/inspection-throttle.test.ts +23 -0
- package/test/workflow-runtime.test.ts +21 -3
- package/dist/server-kc2kg0hU.mjs.map +0 -1
package/dist/server.d.mts
CHANGED
|
@@ -129,6 +129,9 @@ export type StartServerOptions = {
|
|
|
129
129
|
/** Mount the MCP server at `/mcp`. On by default; `false` wins over
|
|
130
130
|
* MCP_ENABLED, which can turn it off but never on. */
|
|
131
131
|
mcp?: boolean;
|
|
132
|
+
/** Mount the read-only inspection subgraph at `/graphql/inspection`. On by
|
|
133
|
+
* default; `false` wins over INSPECTION_ENABLED, which can turn it off. */
|
|
134
|
+
inspection?: boolean;
|
|
132
135
|
/** Powerhouse workflows: the runtime, its subgraph, its webhooks and its
|
|
133
136
|
* document models. Wins over PH_WORKFLOWS_ENABLED and the config file. */
|
|
134
137
|
workflows?: {
|
|
@@ -221,6 +224,8 @@ export type SwitchboardReactor = {
|
|
|
221
224
|
};
|
|
222
225
|
/** Whether `/mcp` is mounted, after the option and MCP_ENABLED. */
|
|
223
226
|
mcpEnabled: boolean;
|
|
227
|
+
/** Whether `/graphql/inspection` is mounted, after the option and INSPECTION_ENABLED. */
|
|
228
|
+
inspectionEnabled: boolean;
|
|
224
229
|
/** The Renown instance if identity was initialized */
|
|
225
230
|
renown: IRenown$1 | null;
|
|
226
231
|
/**
|
package/dist/server.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/privacy.mts","../src/workflow-runtime.mts","../src/types.ts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;;;;;cASa;KACD,2BAA2B;;;KCe3B;;EAEV;;EAEA;;EAEA,SAAS;;;;;;KCkCC;EACN;;EAEA;EACA;;;;;;;;;;YC/CM;;YAKA,wBAAwB;EAClC,eAAe;;YAGL;EACV;EACA;EACA;;YAGU;;EAEV;;;;;EAKA;;EAGA;;YAGU;;;;;;;;;;;;;;;;;;;;;EAqBV,UAAU;;;;;;;;EAQV;;;;;;;EAOA;EACA;EACA;;;;;;EAMA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;IAEM;IACA;;;;;;;EASN,WAAW;;EAEX;;;EAGA;;;EAGA;IACE;;;EAGF,UAAU;EACV,kBAAkB;EAClB;EACA;;;;;;EAMA;EACA,SAAS;;;;;;;;;;EAUT;;;;;;;;;;EAUA;;;;;;;;;EASA;IACE;IACA;IACA;;;;;;;;;;;EAWF;IACE;IACA;;;;;;;;;EASF,6BAA6B;;YAGnB;EACV;EACA,SAAS;;EAET,mBAAmB;;EAEnB,+BAA+B;;;EAG/B,mBAAmB;;EAEnB;;EAEA,iBAAiB;;EAEjB;IAAY,SAAS;;;EAErB;;EAEA,QAAQ;;;;;EAKR;;;;;;;;;;;;;EAaA,gBAAgB;;;;
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/privacy.mts","../src/workflow-runtime.mts","../src/types.ts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;;;;;cASa;KACD,2BAA2B;;;KCe3B;;EAEV;;EAEA;;EAEA,SAAS;;;;;;KCkCC;EACN;;EAEA;EACA;;;;;;;;;;YC/CM;;YAKA,wBAAwB;EAClC,eAAe;;YAGL;EACV;EACA;EACA;;YAGU;;EAEV;;;;;EAKA;;EAGA;;YAGU;;;;;;;;;;;;;;;;;;;;;EAqBV,UAAU;;;;;;;;EAQV;;;;;;;EAOA;EACA;EACA;;;;;;EAMA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;IAEM;IACA;;;;;;;EASN,WAAW;;EAEX;;;EAGA;;;EAGA;;;EAGA;IACE;;;EAGF,UAAU;EACV,kBAAkB;EAClB;EACA;;;;;;EAMA;EACA,SAAS;;;;;;;;;;EAUT;;;;;;;;;;EAUA;;;;;;;;;EASA;IACE;IACA;IACA;;;;;;;;;;;EAWF;IACE;IACA;;;;;;;;;EASF,6BAA6B;;YAGnB;EACV;EACA,SAAS;;EAET,mBAAmB;;EAEnB,+BAA+B;;;EAG/B,mBAAmB;;EAEnB;;EAEA,iBAAiB;;EAEjB;IAAY,SAAS;;;EAErB;;EAEA;;EAEA,QAAQ;;;;;EAKR;;;;;;;;;;;;;EAaA,gBAAgB;;;;KCpNN;EAIV,iBAAiB;;EAEjB,mBAAmB;;EAEnB;;;;;;;EAOA,gBAAgB;;EAEhB;;EAEA;IACE;IACA,eAAe,QAAQ;;;EAGzB,sBAAsB;EACtB,SAAS;;;;;;EAMT,SAAS;;;;;EAKT,cAAc,KAAK;;EAEnB,wBAAwB;;wBAiBV,gCACd,gBAAgB,gBAChB,eAAe,sBACf,UAAS;;;;wBCvEK,kCACd,OAAO,wCACP,KAAK,OAAO,aACX;;qBAaU,oCAAoC;WACtC;IAAqB;IAAkB;;WACvC;EAET,YAAY,OAAO;SAcZ,QAAQ,iBAAiB,SAAS;;;;;;;;;wBCuL3B,gBAAgB,eAAe;;;;;;KA6D1C;EACH,QAAQ,OAAO;EACf,qBAAqB;EACrB,cAAc;;wBAGM,oBAAoB;EACxC;EACA;EACA,oBAAoB;EACpB;;;;;;;EAOA;EACA,QAAQ;IACN,QAAQ;;wBA4DI,8BACd,SAAS,KAAK,uDACd,oBACA,QAAQ;EACL;EAAmB,YAAY;;;;;;;;;;;;;;;;;;;qBA0hCvB,mBAAgB,UAClB,uBACR,QAAQ"}
|
package/dist/server.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as StoredDocumentsRefusedError, i as startSwitchboard, n as deriveAttachmentServiceConfig, o as resolveUnsupportedStoredDocuments, r as isPortAvailable, s as applySwitchboardReactorDefaults, t as createReactorKysely } from "./server-
|
|
2
|
+
import { a as StoredDocumentsRefusedError, i as startSwitchboard, n as deriveAttachmentServiceConfig, o as resolveUnsupportedStoredDocuments, r as isPortAvailable, s as applySwitchboardReactorDefaults, t as createReactorKysely } from "./server-Cw2WnaCA.mjs";
|
|
3
3
|
export { StoredDocumentsRefusedError, applySwitchboardReactorDefaults, createReactorKysely, deriveAttachmentServiceConfig, isPortAvailable, resolveUnsupportedStoredDocuments, startSwitchboard };
|
|
4
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
5
|
-
//# debugId=
|
|
4
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a0774745-54c0-5116-aa98-7bec55598af8")}catch(e){}}();
|
|
5
|
+
//# debugId=a0774745-54c0-5116-aa98-7bec55598af8
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/switchboard",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.2.3-dev.
|
|
4
|
+
"version": "6.2.3-dev.57",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@openfeature/core": "1.9.1",
|
|
42
42
|
"@openfeature/env-var-provider": "0.3.1",
|
|
43
43
|
"@openfeature/server-sdk": "1.19.0",
|
|
44
|
-
"@powerhousedao/config": "6.2.3-dev.
|
|
44
|
+
"@powerhousedao/config": "6.2.3-dev.57",
|
|
45
45
|
"@opentelemetry/api": "^1.9.0",
|
|
46
46
|
"@opentelemetry/exporter-metrics-otlp-http": "^0.218.0",
|
|
47
47
|
"@opentelemetry/exporter-trace-otlp-http": "^0.218.0",
|
|
@@ -55,22 +55,22 @@
|
|
|
55
55
|
"@opentelemetry/sdk-node": "^0.218.0",
|
|
56
56
|
"@opentelemetry/sdk-trace-base": "^2.7.1",
|
|
57
57
|
"@opentelemetry/semantic-conventions": "^1.41.1",
|
|
58
|
-
"@powerhousedao/opentelemetry-instrumentation-reactor": "6.2.3-dev.
|
|
59
|
-
"@powerhousedao/reactor": "6.2.3-dev.
|
|
60
|
-
"@powerhousedao/shared": "6.2.3-dev.
|
|
61
|
-
"@powerhousedao/vetra": "6.2.3-dev.
|
|
62
|
-
"@powerhousedao/reactor-api": "6.2.3-dev.
|
|
63
|
-
"@powerhousedao/reactor-attachments": "6.2.3-dev.
|
|
64
|
-
"@powerhousedao/reactor-drive": "6.2.3-dev.
|
|
65
|
-
"@powerhousedao/reactor-group": "6.2.3-dev.
|
|
66
|
-
"@powerhousedao/reactor-privacy": "6.2.3-dev.
|
|
67
|
-
"@powerhousedao/reactor-workflow": "6.2.3-dev.
|
|
68
|
-
"@powerhousedao/workflow": "6.2.3-dev.
|
|
58
|
+
"@powerhousedao/opentelemetry-instrumentation-reactor": "6.2.3-dev.57",
|
|
59
|
+
"@powerhousedao/reactor": "6.2.3-dev.57",
|
|
60
|
+
"@powerhousedao/shared": "6.2.3-dev.57",
|
|
61
|
+
"@powerhousedao/vetra": "6.2.3-dev.57",
|
|
62
|
+
"@powerhousedao/reactor-api": "6.2.3-dev.57",
|
|
63
|
+
"@powerhousedao/reactor-attachments": "6.2.3-dev.57",
|
|
64
|
+
"@powerhousedao/reactor-drive": "6.2.3-dev.57",
|
|
65
|
+
"@powerhousedao/reactor-group": "6.2.3-dev.57",
|
|
66
|
+
"@powerhousedao/reactor-privacy": "6.2.3-dev.57",
|
|
67
|
+
"@powerhousedao/reactor-workflow": "6.2.3-dev.57",
|
|
68
|
+
"@powerhousedao/workflow": "6.2.3-dev.57",
|
|
69
69
|
"@pyroscope/nodejs": "^0.4.5",
|
|
70
|
-
"@renown/sdk": "6.2.3-dev.
|
|
70
|
+
"@renown/sdk": "6.2.3-dev.57",
|
|
71
71
|
"@sentry/node": "^10.53.1",
|
|
72
72
|
"@sentry/opentelemetry": "^10.53.1",
|
|
73
|
-
"document-model": "6.2.3-dev.
|
|
73
|
+
"document-model": "6.2.3-dev.57",
|
|
74
74
|
"dotenv": "^16.4.7",
|
|
75
75
|
"express": "^4.22.1",
|
|
76
76
|
"graphql": "^16",
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "@powerhousedao/reactor-attachments";
|
|
6
6
|
import { Kysely } from "kysely";
|
|
7
7
|
import { PGliteDialect } from "kysely-pglite-dialect";
|
|
8
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
8
|
+
import { mkdtemp, readdir, rm } from "node:fs/promises";
|
|
9
9
|
import {
|
|
10
10
|
validateHeaderValue,
|
|
11
11
|
type IncomingMessage,
|
|
@@ -101,8 +101,17 @@ function makeRes(): CapturedRes {
|
|
|
101
101
|
getHeader(name: string) {
|
|
102
102
|
return headers[name.toLowerCase()];
|
|
103
103
|
},
|
|
104
|
+
removeHeader(name: string) {
|
|
105
|
+
delete headers[name.toLowerCase()];
|
|
106
|
+
},
|
|
104
107
|
_done: done,
|
|
105
108
|
});
|
|
109
|
+
// Like ServerResponse: headers count as sent once the first byte is written.
|
|
110
|
+
Object.defineProperty(writable, "headersSent", {
|
|
111
|
+
get(): boolean {
|
|
112
|
+
return chunks.length > 0;
|
|
113
|
+
},
|
|
114
|
+
});
|
|
106
115
|
Object.defineProperty(writable, "_body", {
|
|
107
116
|
get(): Buffer {
|
|
108
117
|
return Buffer.concat(chunks);
|
|
@@ -696,6 +705,101 @@ describe("attachment routes", () => {
|
|
|
696
705
|
}
|
|
697
706
|
});
|
|
698
707
|
|
|
708
|
+
async function uploadText(payload: string): Promise<string> {
|
|
709
|
+
const reserveRes = makeRes();
|
|
710
|
+
await makeReserveHandler(attachments)(
|
|
711
|
+
makeReq({
|
|
712
|
+
method: "POST",
|
|
713
|
+
body: JSON.stringify({ mimeType: "text/plain", fileName: "a.txt" }),
|
|
714
|
+
}),
|
|
715
|
+
reserveRes,
|
|
716
|
+
);
|
|
717
|
+
await waitFor(reserveRes);
|
|
718
|
+
const { reservationId } = JSON.parse(reserveRes._body.toString("utf8")) as {
|
|
719
|
+
reservationId: string;
|
|
720
|
+
};
|
|
721
|
+
const uploadRes = makeRes();
|
|
722
|
+
await makeUploadHandler(attachments)(
|
|
723
|
+
makeReq({ method: "PUT", params: { reservationId }, body: payload }),
|
|
724
|
+
uploadRes,
|
|
725
|
+
);
|
|
726
|
+
await waitFor(uploadRes);
|
|
727
|
+
return (JSON.parse(uploadRes._body.toString("utf8")) as { hash: string })
|
|
728
|
+
.hash;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// The blob store is a directory; its metadata lives in the database. When
|
|
732
|
+
// the directory is lost (a pod-local tmpdir after a restart) the metadata
|
|
733
|
+
// still says "available". Reading such a blob used to raise an unhandled
|
|
734
|
+
// stream error that took the whole process down.
|
|
735
|
+
it("GET download returns 404 when the blob file is missing from disk", async () => {
|
|
736
|
+
const hash = await uploadText("gone");
|
|
737
|
+
const files = await readdir(storagePath, {
|
|
738
|
+
recursive: true,
|
|
739
|
+
withFileTypes: true,
|
|
740
|
+
});
|
|
741
|
+
const blobs = files.filter((f) => f.isFile() && f.name.startsWith(hash));
|
|
742
|
+
expect(blobs.length).toBeGreaterThan(0);
|
|
743
|
+
for (const f of blobs) await rm(join(f.parentPath, f.name));
|
|
744
|
+
|
|
745
|
+
const res = makeRes();
|
|
746
|
+
await grantedDownload(attachments)(
|
|
747
|
+
makeReq({ method: "GET", params: { hash } }),
|
|
748
|
+
res,
|
|
749
|
+
);
|
|
750
|
+
await waitFor(res);
|
|
751
|
+
|
|
752
|
+
expect(res.statusCode).toBe(404);
|
|
753
|
+
expect(JSON.parse(res._body.toString("utf8"))).toEqual({
|
|
754
|
+
error: "Attachment not found",
|
|
755
|
+
});
|
|
756
|
+
// The download headers were set before the read failed; none may leak
|
|
757
|
+
// onto the JSON error.
|
|
758
|
+
expect(res.getHeader("content-length")).toBeUndefined();
|
|
759
|
+
expect(res.getHeader("content-disposition")).toBeUndefined();
|
|
760
|
+
expect(res.getHeader("attachment-metadata")).toBeUndefined();
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
it("GET download aborts the response when the blob fails mid-stream", async () => {
|
|
764
|
+
const hash = await uploadText("partial");
|
|
765
|
+
const originalGet = attachments.store.get.bind(attachments.store);
|
|
766
|
+
const real = await originalGet(hash as never);
|
|
767
|
+
let sentFirst = false;
|
|
768
|
+
attachments.store.get = () =>
|
|
769
|
+
Promise.resolve({
|
|
770
|
+
header: real.header,
|
|
771
|
+
// First chunk flows to the response; the read fails only after it
|
|
772
|
+
// has been written, the way a disk error partway through a file would.
|
|
773
|
+
body: new ReadableStream<Uint8Array>({
|
|
774
|
+
async pull(controller) {
|
|
775
|
+
if (!sentFirst) {
|
|
776
|
+
sentFirst = true;
|
|
777
|
+
controller.enqueue(new TextEncoder().encode("part"));
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
781
|
+
controller.error(new Error("EIO: read failed"));
|
|
782
|
+
},
|
|
783
|
+
}) as never,
|
|
784
|
+
});
|
|
785
|
+
try {
|
|
786
|
+
const res = makeRes();
|
|
787
|
+
const closed = new Promise<void>((resolve) => res.once("close", resolve));
|
|
788
|
+
await grantedDownload(attachments)(
|
|
789
|
+
makeReq({ method: "GET", params: { hash } }),
|
|
790
|
+
res,
|
|
791
|
+
);
|
|
792
|
+
await closed;
|
|
793
|
+
// Bytes were already on the wire: the only honest signal left is to
|
|
794
|
+
// cut the connection, never to finish it as if it were complete.
|
|
795
|
+
expect(res._body.toString("utf8")).toBe("part");
|
|
796
|
+
expect(res.destroyed).toBe(true);
|
|
797
|
+
expect(res.writableFinished).toBe(false);
|
|
798
|
+
} finally {
|
|
799
|
+
attachments.store.get = originalGet;
|
|
800
|
+
}
|
|
801
|
+
});
|
|
802
|
+
|
|
699
803
|
it("identical uploads dedupe to the same hash", async () => {
|
|
700
804
|
const reserveHandler = makeReserveHandler(attachments);
|
|
701
805
|
const uploadHandler = makeUploadHandler(attachments);
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
+
import { createServer } from "node:net";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import type { ILogger } from "document-model";
|
|
6
|
+
import { describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { startSwitchboard } from "../src/server.mjs";
|
|
8
|
+
|
|
9
|
+
// `port: 0` would bind a random port the switchboard does not report back, so
|
|
10
|
+
// the test picks a free one and pins it.
|
|
11
|
+
async function freePort(): Promise<number> {
|
|
12
|
+
const server = createServer();
|
|
13
|
+
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
14
|
+
const address = server.address();
|
|
15
|
+
await new Promise<void>((resolve) => server.close(() => resolve()));
|
|
16
|
+
if (!address || typeof address === "string") throw new Error("no port");
|
|
17
|
+
return address.port;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function stubLogger(): ILogger {
|
|
21
|
+
const logger = {
|
|
22
|
+
verbose: vi.fn(),
|
|
23
|
+
debug: vi.fn(),
|
|
24
|
+
info: vi.fn(),
|
|
25
|
+
warn: vi.fn(),
|
|
26
|
+
error: vi.fn(),
|
|
27
|
+
child: vi.fn(),
|
|
28
|
+
};
|
|
29
|
+
logger.child.mockReturnValue(logger);
|
|
30
|
+
return logger as unknown as ILogger;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function withSwitchboard(
|
|
34
|
+
env: Record<string, string>,
|
|
35
|
+
inspection: boolean | undefined,
|
|
36
|
+
run: (
|
|
37
|
+
switchboard: Awaited<ReturnType<typeof startSwitchboard>>,
|
|
38
|
+
) => Promise<void>,
|
|
39
|
+
): Promise<void> {
|
|
40
|
+
const tempRoot = await mkdtemp(
|
|
41
|
+
join(tmpdir(), "switchboard-inspection-enabled-"),
|
|
42
|
+
);
|
|
43
|
+
const names = [
|
|
44
|
+
"PH_REACTOR_DATABASE_URL",
|
|
45
|
+
"INSPECTION_ENABLED",
|
|
46
|
+
...Object.keys(env),
|
|
47
|
+
];
|
|
48
|
+
const previous = names.map((name) => [name, process.env[name]] as const);
|
|
49
|
+
process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
|
|
50
|
+
delete process.env.INSPECTION_ENABLED;
|
|
51
|
+
Object.assign(process.env, env);
|
|
52
|
+
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
switchboard = await startSwitchboard({
|
|
56
|
+
workflows: { enabled: false },
|
|
57
|
+
dbPath: join(tempRoot, "read-model"),
|
|
58
|
+
port: await freePort(),
|
|
59
|
+
strictPort: true,
|
|
60
|
+
inspection,
|
|
61
|
+
disableLocalPackages: true,
|
|
62
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
63
|
+
drive: {
|
|
64
|
+
slug: "default-drive",
|
|
65
|
+
global: { name: "Default Drive" },
|
|
66
|
+
},
|
|
67
|
+
logger: stubLogger(),
|
|
68
|
+
});
|
|
69
|
+
await run(switchboard);
|
|
70
|
+
await switchboard.shutdown();
|
|
71
|
+
switchboard = undefined;
|
|
72
|
+
} finally {
|
|
73
|
+
await switchboard?.shutdown();
|
|
74
|
+
for (const [name, value] of previous) {
|
|
75
|
+
if (value === undefined) {
|
|
76
|
+
delete process.env[name];
|
|
77
|
+
} else {
|
|
78
|
+
process.env[name] = value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const query = `{ inspection { info { workflows } } }`;
|
|
86
|
+
|
|
87
|
+
async function postQuery(
|
|
88
|
+
port: number,
|
|
89
|
+
path: string,
|
|
90
|
+
): Promise<{ status: number; body: unknown }> {
|
|
91
|
+
const response = await fetch(`http://127.0.0.1:${port}${path}`, {
|
|
92
|
+
method: "POST",
|
|
93
|
+
headers: { "content-type": "application/json" },
|
|
94
|
+
body: JSON.stringify({ query }),
|
|
95
|
+
});
|
|
96
|
+
const text = await response.text();
|
|
97
|
+
let body: unknown = text;
|
|
98
|
+
try {
|
|
99
|
+
body = JSON.parse(text);
|
|
100
|
+
} catch {
|
|
101
|
+
// Not JSON; keep the raw text.
|
|
102
|
+
}
|
|
103
|
+
return { status: response.status, body };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
describe("booting Switchboard", () => {
|
|
107
|
+
it("mounts /graphql/inspection by default", async () => {
|
|
108
|
+
await withSwitchboard(
|
|
109
|
+
{},
|
|
110
|
+
undefined,
|
|
111
|
+
async ({ inspectionEnabled, port }) => {
|
|
112
|
+
expect(inspectionEnabled).toBe(true);
|
|
113
|
+
const { status, body } = await postQuery(port, "/graphql/inspection");
|
|
114
|
+
expect(status).toBe(200);
|
|
115
|
+
expect(body).toMatchObject({
|
|
116
|
+
data: { inspection: { info: { workflows: false } } },
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
}, 60_000);
|
|
121
|
+
|
|
122
|
+
it('leaves /graphql/inspection unmounted under INSPECTION_ENABLED="false"', async () => {
|
|
123
|
+
await withSwitchboard(
|
|
124
|
+
{ INSPECTION_ENABLED: "false" },
|
|
125
|
+
undefined,
|
|
126
|
+
async ({ inspectionEnabled, port }) => {
|
|
127
|
+
expect(inspectionEnabled).toBe(false);
|
|
128
|
+
expect((await postQuery(port, "/graphql/inspection")).status).toBe(404);
|
|
129
|
+
const supergraph = await postQuery(port, "/graphql");
|
|
130
|
+
const { errors } = supergraph.body as {
|
|
131
|
+
errors?: { message: string }[];
|
|
132
|
+
};
|
|
133
|
+
expect(errors?.[0]?.message).toContain(
|
|
134
|
+
'Cannot query field "inspection"',
|
|
135
|
+
);
|
|
136
|
+
},
|
|
137
|
+
);
|
|
138
|
+
}, 60_000);
|
|
139
|
+
|
|
140
|
+
it("keeps a host's inspection: false over INSPECTION_ENABLED=true", async () => {
|
|
141
|
+
await withSwitchboard(
|
|
142
|
+
{ INSPECTION_ENABLED: "true" },
|
|
143
|
+
false,
|
|
144
|
+
async ({ inspectionEnabled, port }) => {
|
|
145
|
+
expect(inspectionEnabled).toBe(false);
|
|
146
|
+
expect((await postQuery(port, "/graphql/inspection")).status).toBe(404);
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
}, 60_000);
|
|
150
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
2
|
+
import { initFeatureFlags } from "../src/feature-flags.js";
|
|
3
|
+
import {
|
|
4
|
+
INSPECTION_ENABLED,
|
|
5
|
+
resolveInspectionEnabled,
|
|
6
|
+
} from "../src/inspection-flag.mjs";
|
|
7
|
+
import type { BooleanFlagSource } from "../src/workflow-runtime.mjs";
|
|
8
|
+
|
|
9
|
+
describe("resolveInspectionEnabled", () => {
|
|
10
|
+
let featureFlags: BooleanFlagSource;
|
|
11
|
+
|
|
12
|
+
beforeAll(async () => {
|
|
13
|
+
featureFlags = await initFeatureFlags();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
delete process.env[INSPECTION_ENABLED];
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("defaults to on", async () => {
|
|
21
|
+
await expect(resolveInspectionEnabled({ featureFlags })).resolves.toBe(
|
|
22
|
+
true,
|
|
23
|
+
);
|
|
24
|
+
await expect(
|
|
25
|
+
resolveInspectionEnabled({ featureFlags, option: true }),
|
|
26
|
+
).resolves.toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('is turned off by INSPECTION_ENABLED="false"', async () => {
|
|
30
|
+
process.env[INSPECTION_ENABLED] = "false";
|
|
31
|
+
|
|
32
|
+
await expect(resolveInspectionEnabled({ featureFlags })).resolves.toBe(
|
|
33
|
+
false,
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("turns off a host that asked for inspection", async () => {
|
|
38
|
+
process.env[INSPECTION_ENABLED] = "false";
|
|
39
|
+
|
|
40
|
+
await expect(
|
|
41
|
+
resolveInspectionEnabled({ featureFlags, option: true }),
|
|
42
|
+
).resolves.toBe(false);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("never turns on a host that switched inspection off", async () => {
|
|
46
|
+
process.env[INSPECTION_ENABLED] = "true";
|
|
47
|
+
|
|
48
|
+
await expect(
|
|
49
|
+
resolveInspectionEnabled({ featureFlags, option: false }),
|
|
50
|
+
).resolves.toBe(false);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("leaves inspection on for any value but the string false", async () => {
|
|
54
|
+
for (const raw of ["true", "0", "no", ""]) {
|
|
55
|
+
process.env[INSPECTION_ENABLED] = raw;
|
|
56
|
+
await expect(
|
|
57
|
+
resolveInspectionEnabled({ featureFlags }),
|
|
58
|
+
`INSPECTION_ENABLED=${JSON.stringify(raw)}`,
|
|
59
|
+
).resolves.toBe(true);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { inspectionThrottleFromEnv } from "../src/inspection-throttle.mjs";
|
|
3
|
+
|
|
4
|
+
describe("inspectionThrottleFromEnv", () => {
|
|
5
|
+
it("keeps the default when unset or blank", () => {
|
|
6
|
+
expect(inspectionThrottleFromEnv({})).toEqual({});
|
|
7
|
+
expect(
|
|
8
|
+
inspectionThrottleFromEnv({ PH_INSPECTION_CALLS_PER_MINUTE: " " }),
|
|
9
|
+
).toEqual({});
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("reads PH_INSPECTION_CALLS_PER_MINUTE", () => {
|
|
13
|
+
expect(
|
|
14
|
+
inspectionThrottleFromEnv({ PH_INSPECTION_CALLS_PER_MINUTE: " 30 " }),
|
|
15
|
+
).toEqual({ callsPerMinute: 30 });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it.each(["abc", "-1", "1.5", "0", "1O"])("throws on %s", (raw) => {
|
|
19
|
+
expect(() =>
|
|
20
|
+
inspectionThrottleFromEnv({ PH_INSPECTION_CALLS_PER_MINUTE: raw }),
|
|
21
|
+
).toThrow(/PH_INSPECTION_CALLS_PER_MINUTE/);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -161,21 +161,38 @@ function memoryWebhooks() {
|
|
|
161
161
|
|
|
162
162
|
describe("composeWorkflowRuntime", () => {
|
|
163
163
|
let databases: Kysely<unknown>[] = [];
|
|
164
|
+
let stores: PGlite[] = [];
|
|
164
165
|
let module: InProcessReactorClientModule | undefined;
|
|
165
166
|
let composed: ComposedWorkflowRuntime | undefined;
|
|
167
|
+
// initdb is most of a store's cost (seconds on Windows): once, then copies.
|
|
168
|
+
let template: Blob | undefined;
|
|
169
|
+
|
|
170
|
+
beforeAll(async () => {
|
|
171
|
+
const pg = new PGlite();
|
|
172
|
+
try {
|
|
173
|
+
template = await pg.dumpDataDir("none");
|
|
174
|
+
} finally {
|
|
175
|
+
await pg.close();
|
|
176
|
+
}
|
|
177
|
+
}, 30_000);
|
|
166
178
|
|
|
167
179
|
afterEach(async () => {
|
|
168
180
|
await composed?.stop();
|
|
169
181
|
await module?.reactor.kill().completed;
|
|
170
182
|
for (const database of databases) await database.destroy();
|
|
183
|
+
// Kysely's destroy leaves the PGlite open.
|
|
184
|
+
for (const store of stores) if (!store.closed) await store.close();
|
|
171
185
|
composed = undefined;
|
|
172
186
|
module = undefined;
|
|
173
187
|
databases = [];
|
|
188
|
+
stores = [];
|
|
174
189
|
});
|
|
175
190
|
|
|
176
191
|
function pglite(): Kysely<unknown> {
|
|
192
|
+
const store = new PGlite({ loadDataDir: template });
|
|
193
|
+
stores.push(store);
|
|
177
194
|
const database = new Kysely<unknown>({
|
|
178
|
-
dialect: new PGliteDialect(
|
|
195
|
+
dialect: new PGliteDialect(store),
|
|
179
196
|
});
|
|
180
197
|
databases.push(database);
|
|
181
198
|
return database;
|
|
@@ -361,7 +378,8 @@ describe("composeWorkflowRuntime", () => {
|
|
|
361
378
|
const webhooks = memoryWebhooks();
|
|
362
379
|
const clientModule = await buildReactorModule();
|
|
363
380
|
// Intervals only, from here on: the singleton lease's heartbeat and the
|
|
364
|
-
// run-retention sweep from compose, then the supervisor's tick
|
|
381
|
+
// run-retention sweep from compose, then the supervisor's tick and the
|
|
382
|
+
// PENDING-run sweep.
|
|
365
383
|
vi.useFakeTimers({ toFake: ["setInterval", "clearInterval"] });
|
|
366
384
|
try {
|
|
367
385
|
const workflows = await compose(clientModule, {
|
|
@@ -376,7 +394,7 @@ describe("composeWorkflowRuntime", () => {
|
|
|
376
394
|
await expect(
|
|
377
395
|
webhooks.families[0]!.policyFor?.("wf-unknown"),
|
|
378
396
|
).resolves.toBeUndefined();
|
|
379
|
-
expect(vi.getTimerCount()).toBe(
|
|
397
|
+
expect(vi.getTimerCount()).toBe(4);
|
|
380
398
|
|
|
381
399
|
await workflows.stop();
|
|
382
400
|
await workflows.stop();
|