@powerhousedao/switchboard 6.4.0-next.0 → 6.4.0-next.2
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/plugin-inspector.test.d.ts +2 -0
- package/.tsbuild/test/plugin-inspector.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +22 -0
- package/README.md +1 -1
- package/dist/index.mjs +1 -1
- package/dist/plugins/attachments.mjs +3 -3
- package/dist/plugins/inspector.d.mts +68 -0
- package/dist/plugins/inspector.d.mts.map +1 -0
- package/dist/plugins/inspector.mjs +107 -0
- package/dist/plugins/inspector.mjs.map +1 -0
- package/dist/{server-BMRdMNvC.mjs → server-CbKdygtT.mjs} +4 -4
- package/dist/server-CbKdygtT.mjs.map +1 -0
- package/dist/server.d.mts +3 -3
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +3 -3
- package/dist/{types-D-QK3xhO.d.mts → types-D8s6VzUO.d.mts} +7 -2
- package/dist/{types-D-QK3xhO.d.mts.map → types-D8s6VzUO.d.mts.map} +1 -1
- package/dist/utils.d.mts +1 -1
- package/package.json +23 -17
- package/test/plugin-inspector.test.ts +300 -0
- package/tsdown.config.ts +1 -0
- package/dist/server-BMRdMNvC.mjs.map +0 -1
package/dist/server.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { a as SwitchboardConfigInput, i as SwitchboardConfig } from "./schema-CZsLzAZg.mjs";
|
|
2
2
|
import { n as WorkflowTriggersCapability } from "./workflow-runtime-CF5pc8mt.mjs";
|
|
3
|
-
import { a as SwitchboardDriveDocumentType, i as SwitchboardDeps, n as StartServerOptions, o as SwitchboardDriveInput, r as StorageOptions, s as SwitchboardReactor, t as IdentityOptions } from "./types-
|
|
3
|
+
import { a as SwitchboardDriveDocumentType, i as SwitchboardDeps, n as StartServerOptions, o as SwitchboardDriveInput, r as StorageOptions, s as SwitchboardReactor, t as IdentityOptions } from "./types-D8s6VzUO.mjs";
|
|
4
4
|
import { ILogger } from "document-model";
|
|
5
5
|
import { ChannelScheme, Database, IDocumentModelLoader, IStoreMaintenance, JwtHandler, KeyframeSettings, PoolInstrumentation, ReactorBuilder, ReactorClientBuilder, ReactorFeatureFlags, ReactorStorageFacts, SignerConfig, StoredProtocolRefusal, UnsupportedStoredDocuments, UnsupportedStoredProtocolError } from "@powerhousedao/reactor";
|
|
6
6
|
import { PGliteLike, PgliteMaintenanceSettings, resolvePgliteMaintenance } from "@powerhousedao/reactor-api/pglite-node";
|
|
7
|
-
import { DocumentModelModule, SignaturePolicy, UpgradeManifest } from "@powerhousedao/shared/document-model";
|
|
7
|
+
import { DocumentModelModule as DocumentModelModule$1, SignaturePolicy, UpgradeManifest } from "@powerhousedao/shared/document-model";
|
|
8
8
|
import { IRenown } from "@renown/sdk/node";
|
|
9
9
|
import { Kysely } from "kysely";
|
|
10
10
|
import "@electric-sql/pglite";
|
|
@@ -22,7 +22,7 @@ interface PgliteStoreSettings {
|
|
|
22
22
|
//#endregion
|
|
23
23
|
//#region src/builder-defaults.d.mts
|
|
24
24
|
type SwitchboardReactorDefaultsOptions = {
|
|
25
|
-
documentModels?: DocumentModelModule[];
|
|
25
|
+
documentModels?: DocumentModelModule$1[];
|
|
26
26
|
/** Upgrade manifests for versioned models, one per document type. */
|
|
27
27
|
upgradeManifests?: UpgradeManifest<readonly number[]>[];
|
|
28
28
|
/** Default true. */
|
package/dist/server.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/pglite-store.mts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;cAYa;KACD,2BAA2B;;;;UCuHtB;EACf;EACA,cAAc;EACd;;;;KClHU;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;;;;wBCrEK,kCACd,OAAO,wCACP,KAAK,OAAO,aACX;;qBAaU,oCAAoC;WACtC,mBAAmB;WACnB;EAET,YAAY,OAAO;SAYH,QACd,iBACC,SAAS;;;;;wBCyJE,uBACd,UAAS,KAAK;;;;;;wBAgCM,gBAAgB,eAAe;;wBA2ErC,iBACd,YAAY,2CACZ,mBACA,qBACC;;;;;;KAmCE;EACH,QAAQ,OAAO;EACf,qBAAqB;EACrB,cAAc;;EAEd,mBAAmB;;wBAGC,oBAAoB;EACxC;EACA;EACA,oBAAoB;EACpB;;EAEA;;EAEA;EACA,iBAAiB;;EAEjB,eAAe;EACf,QAAQ;IACN,QAAQ;iBAkEK;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;wBAcc,yBAAyB;EACvC;EACA;;EAEA;;EAEA;EACA;IACE;;wBAmCY,8BACd,SAAS,KAAK,uDACd,oBACA,QAAQ;EACL;EAAmB,YAAY;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/pglite-version.ts","../src/pglite-store.mts","../src/builder-defaults.mts","../src/unsupported-stored-documents.mts","../src/server.mts"],"mappings":";;;;;;;;;;;cAYa;KACD,2BAA2B;;;;UCuHtB;EACf;EACA,cAAc;EACd;;;;KClHU;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;;;;wBCrEK,kCACd,OAAO,wCACP,KAAK,OAAO,aACX;;qBAaU,oCAAoC;WACtC,mBAAmB;WACnB;EAET,YAAY,OAAO;SAYH,QACd,iBACC,SAAS;;;;;wBCyJE,uBACd,UAAS,KAAK;;;;;;wBAgCM,gBAAgB,eAAe;;wBA2ErC,iBACd,YAAY,2CACZ,mBACA,qBACC;;;;;;KAmCE;EACH,QAAQ,OAAO;EACf,qBAAqB;EACrB,cAAc;;EAEd,mBAAmB;;wBAGC,oBAAoB;EACxC;EACA;EACA,oBAAoB;EACpB;;EAEA;;EAEA;EACA,iBAAiB;;EAEjB,eAAe;EACf,QAAQ;IACN,QAAQ;iBAkEK;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;wBAcc,yBAAyB;EACvC;EACA;;EAEA;;EAEA;EACA;IACE;;wBAmCY,8BACd,SAAS,KAAK,uDACd,oBACA,QAAQ;EACL;EAAmB,YAAY;;;;;;;;;;;;;;;;;;;;qBA8vCvB,mBAAgB,QACpB,wBAAsB,OACvB,oBACL,QAAQ"}
|
package/dist/server.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { n as StoredDocumentsRefusedError, r as resolveUnsupportedStoredDocuments } from "./from-env-CLImR6qa.mjs";
|
|
3
|
-
import { a as resolveKeyframes, i as isPortAvailable, n as deriveAttachmentServiceConfig, o as resolvePgliteStorageDirs, r as initSwitchboardProcess, s as startSwitchboard, t as createReactorKysely, u as applySwitchboardReactorDefaults } from "./server-
|
|
3
|
+
import { a as resolveKeyframes, i as isPortAvailable, n as deriveAttachmentServiceConfig, o as resolvePgliteStorageDirs, r as initSwitchboardProcess, s as startSwitchboard, t as createReactorKysely, u as applySwitchboardReactorDefaults } from "./server-CbKdygtT.mjs";
|
|
4
4
|
export { StoredDocumentsRefusedError, applySwitchboardReactorDefaults, createReactorKysely, deriveAttachmentServiceConfig, initSwitchboardProcess, isPortAvailable, resolveKeyframes, resolvePgliteStorageDirs, resolveUnsupportedStoredDocuments, startSwitchboard };
|
|
5
|
-
!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]="
|
|
6
|
-
//# debugId=
|
|
5
|
+
!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]="293c6b56-d507-575e-a939-cd9642f043b8")}catch(e){}}();
|
|
6
|
+
//# debugId=293c6b56-d507-575e-a939-cd9642f043b8
|
|
@@ -122,7 +122,7 @@ type StartServerOptions = {
|
|
|
122
122
|
/**
|
|
123
123
|
* If true, fail immediately when the requested port is in use instead of
|
|
124
124
|
* falling back to the next free port. Matches the semantics of Vite's
|
|
125
|
-
* `--strictPort` flag that flows through the `ph
|
|
125
|
+
* `--strictPort` flag that flows through the `ph dev` command.
|
|
126
126
|
*/
|
|
127
127
|
strictPort?: boolean;
|
|
128
128
|
dev?: boolean;
|
|
@@ -187,6 +187,11 @@ type StartServerOptions = {
|
|
|
187
187
|
privacy?: PrivacyOptions;
|
|
188
188
|
processorConfig?: Map<string, unknown>;
|
|
189
189
|
disableLocalPackages?: boolean;
|
|
190
|
+
/**
|
|
191
|
+
* False keeps the Vetra codegen processor out of a `dev` switchboard, so
|
|
192
|
+
* no drive there rewrites the project's code. Set by the inspector plugin.
|
|
193
|
+
*/
|
|
194
|
+
codegenProcessor?: boolean;
|
|
190
195
|
enableDocumentModelSubgraphs?: boolean;
|
|
191
196
|
/**
|
|
192
197
|
* When true, enables dynamic loading of document models from the registry
|
|
@@ -320,4 +325,4 @@ type SwitchboardReactor = {
|
|
|
320
325
|
//#endregion
|
|
321
326
|
export { SwitchboardDriveDocumentType as a, SwitchboardDeps as i, StartServerOptions as n, SwitchboardDriveInput as o, StorageOptions as r, SwitchboardReactor as s, IdentityOptions as t };
|
|
322
327
|
export {};
|
|
323
|
-
//# sourceMappingURL=types-
|
|
328
|
+
//# sourceMappingURL=types-D8s6VzUO.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-D8s6VzUO.d.mts","names":[],"sources":["../src/privacy.mts","../src/types.ts"],"mappings":";;;;;;;;;;;KAyBY;;EAEV;;EAEA;;EAEA,SAAS;;EAET;EACA;EACA;EACA;;;;;;;;;;KCRU;;KAKA,wBAAwB;EAClC,eAAe;;KAGL;EACV;EACA;EACA;;KAGU;;EAEV;;;;;;EAMA;;;;;EAKA;;EAGA;;;;;;;KAQU;;;;;;;;;;;;;;;;;;;;;EAqBV,UAAU;;;;;;;;EAQV;;;;;;;EAOA;;;;;EAKA,aAAa;;;;;;;EAOb;EACA;;;;;;;EAOA;;;;;;EAMA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;IAEM;IACA;;;;;;;EASN,WAAW;;EAEX;;;EAGA;;;;;;;;EAQA,oBAAoB;;;EAGpB;;;;EAIA;;;EAGA;IACE;;;;;;;IAOA;MACE;MACA;QAAW;QAAkB;;MAC7B;QAAU;QAAkB;QAAqB;;;;;EAIrD,UAAU;EACV,kBAAkB;EAClB;;;;;EAKA;EACA;;;;;;EAMA;;;;;;EAMA,iBAAiB;EACjB,SAAS;;;;;;;;;;EAUT;;;;;;;;;;EAUA;;;;;;;;;EASA;IACE;IACA;IACA;;;;;;;;;;;EAWF;IACE;IACA;;;;;;;;;EASF,6BAA6B;;;KAInB;EACV,SAAS;;EAET,UAAU;;EAEV,oBAAoB;;EAEpB,eAAe;;EAEf;;EAEA;;EAEA,aAAa;;EAEb,gBAAgB;;KAGN;EACV;EACA,SAAS;;;;;EAKT,mBAAmB;;EAEnB,+BAA+B;;;EAG/B,mBAAmB;;EAEnB;;EAEA,iBAAiB;;EAEjB;IAAY,SAAS;;;EAErB;;EAEA;;EAEA,WAAW;;EAEX,QAAQ;;;;;EAKR;;;;;;;;EAQA,gBAAgB"}
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as SwitchboardDriveInput } from "./types-
|
|
1
|
+
import { o as SwitchboardDriveInput } from "./types-D8s6VzUO.mjs";
|
|
2
2
|
import { IReactorClient } from "@powerhousedao/reactor";
|
|
3
3
|
//#region src/postgres-url.d.mts
|
|
4
4
|
export declare function isPostgresUrl(url: string): boolean;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/switchboard",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.4.0-next.
|
|
4
|
+
"version": "6.4.0-next.2",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -68,6 +68,12 @@
|
|
|
68
68
|
"types": "./dist/plugins/ai.d.mts",
|
|
69
69
|
"import": "./dist/plugins/ai.mjs",
|
|
70
70
|
"default": "./dist/plugins/ai.mjs"
|
|
71
|
+
},
|
|
72
|
+
"./plugins/inspector": {
|
|
73
|
+
"source": "./src/plugins/inspector.mts",
|
|
74
|
+
"types": "./dist/plugins/inspector.d.mts",
|
|
75
|
+
"import": "./dist/plugins/inspector.mjs",
|
|
76
|
+
"default": "./dist/plugins/inspector.mjs"
|
|
71
77
|
}
|
|
72
78
|
},
|
|
73
79
|
"engines": {
|
|
@@ -99,23 +105,23 @@
|
|
|
99
105
|
"@opentelemetry/sdk-node": "^0.218.0",
|
|
100
106
|
"@opentelemetry/sdk-trace-base": "^2.7.1",
|
|
101
107
|
"@opentelemetry/semantic-conventions": "^1.41.1",
|
|
102
|
-
"@powerhousedao/config": "6.4.0-next.
|
|
103
|
-
"@powerhousedao/host-core": "6.4.0-next.
|
|
104
|
-
"@powerhousedao/opentelemetry-instrumentation-reactor": "6.4.0-next.
|
|
105
|
-
"@powerhousedao/reactor": "6.4.0-next.
|
|
106
|
-
"@powerhousedao/reactor-api": "6.4.0-next.
|
|
107
|
-
"@powerhousedao/reactor-attachments": "6.4.0-next.
|
|
108
|
-
"@powerhousedao/reactor-drive": "6.4.0-next.
|
|
109
|
-
"@powerhousedao/reactor-group": "6.4.0-next.
|
|
110
|
-
"@powerhousedao/reactor-privacy": "6.4.0-next.
|
|
111
|
-
"@powerhousedao/reactor-workflow": "6.4.0-next.
|
|
112
|
-
"@powerhousedao/shared": "6.4.0-next.
|
|
113
|
-
"@powerhousedao/workflow": "6.4.0-next.
|
|
108
|
+
"@powerhousedao/config": "6.4.0-next.2",
|
|
109
|
+
"@powerhousedao/host-core": "6.4.0-next.2",
|
|
110
|
+
"@powerhousedao/opentelemetry-instrumentation-reactor": "6.4.0-next.2",
|
|
111
|
+
"@powerhousedao/reactor": "6.4.0-next.2",
|
|
112
|
+
"@powerhousedao/reactor-api": "6.4.0-next.2",
|
|
113
|
+
"@powerhousedao/reactor-attachments": "6.4.0-next.2",
|
|
114
|
+
"@powerhousedao/reactor-drive": "6.4.0-next.2",
|
|
115
|
+
"@powerhousedao/reactor-group": "6.4.0-next.2",
|
|
116
|
+
"@powerhousedao/reactor-privacy": "6.4.0-next.2",
|
|
117
|
+
"@powerhousedao/reactor-workflow": "6.4.0-next.2",
|
|
118
|
+
"@powerhousedao/shared": "6.4.0-next.2",
|
|
119
|
+
"@powerhousedao/workflow": "6.4.0-next.2",
|
|
114
120
|
"@pyroscope/nodejs": "^0.4.5",
|
|
115
|
-
"@renown/sdk": "6.4.0-next.
|
|
121
|
+
"@renown/sdk": "6.4.0-next.2",
|
|
116
122
|
"@sentry/node": "^10.53.1",
|
|
117
123
|
"@sentry/opentelemetry": "^10.53.1",
|
|
118
|
-
"document-model": "6.4.0-next.
|
|
124
|
+
"document-model": "6.4.0-next.2",
|
|
119
125
|
"dotenv": "^16.4.7",
|
|
120
126
|
"express": "^4.22.1",
|
|
121
127
|
"graphql": "^16",
|
|
@@ -131,7 +137,7 @@
|
|
|
131
137
|
"@openfeature/core": "1.9.1",
|
|
132
138
|
"@openfeature/env-var-provider": "0.3.1",
|
|
133
139
|
"@openfeature/server-sdk": "1.19.0",
|
|
134
|
-
"@powerhousedao/vetra": "6.4.0-next.
|
|
140
|
+
"@powerhousedao/vetra": "6.4.0-next.2",
|
|
135
141
|
"@types/express": "^4.17.25",
|
|
136
142
|
"@types/node": "25.2.3",
|
|
137
143
|
"@types/pg": "8.16.0",
|
|
@@ -143,7 +149,7 @@
|
|
|
143
149
|
"vitest": "5.0.3"
|
|
144
150
|
},
|
|
145
151
|
"peerDependencies": {
|
|
146
|
-
"@powerhousedao/vetra": "6.4.0-next.
|
|
152
|
+
"@powerhousedao/vetra": "6.4.0-next.2",
|
|
147
153
|
"react": ">=19.0.0",
|
|
148
154
|
"vite": "^8.0.0"
|
|
149
155
|
},
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The inspector plugin: what it reports (every loaded document model module,
|
|
3
|
+
* all specification versions), when (ready, each package reload), where (a
|
|
4
|
+
* file, gone at shutdown), and that it keeps the Vetra codegen processor out
|
|
5
|
+
* of a dev switchboard.
|
|
6
|
+
*/
|
|
7
|
+
import type { HostPlugin, ResolvedPlugin } from "@powerhousedao/host-core";
|
|
8
|
+
import {
|
|
9
|
+
documentModelDocumentModelModule,
|
|
10
|
+
type DocumentModelModule,
|
|
11
|
+
type ILogger,
|
|
12
|
+
} from "document-model";
|
|
13
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
14
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
15
|
+
import { tmpdir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
18
|
+
import type { SwitchboardHostContext } from "../src/plugin-host.mjs";
|
|
19
|
+
import {
|
|
20
|
+
createInspectorPlugin,
|
|
21
|
+
inspectorPluginConfigSchema,
|
|
22
|
+
inspectorReportOf,
|
|
23
|
+
type InspectorReport,
|
|
24
|
+
} from "../src/plugins/inspector.mjs";
|
|
25
|
+
import type { startSwitchboard } from "../src/server.mjs";
|
|
26
|
+
import { bootSwitchboard } from "./boot-helpers.js";
|
|
27
|
+
|
|
28
|
+
function stubLogger(): ILogger {
|
|
29
|
+
const logger = {
|
|
30
|
+
verbose: vi.fn(),
|
|
31
|
+
debug: vi.fn(),
|
|
32
|
+
info: vi.fn(),
|
|
33
|
+
warn: vi.fn(),
|
|
34
|
+
error: vi.fn(),
|
|
35
|
+
child: vi.fn(),
|
|
36
|
+
};
|
|
37
|
+
logger.child.mockReturnValue(logger);
|
|
38
|
+
return logger as unknown as ILogger;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A module of another type or version, shaped like the base one. */
|
|
42
|
+
function moduleOf(
|
|
43
|
+
id: string,
|
|
44
|
+
name: string,
|
|
45
|
+
version?: number,
|
|
46
|
+
): DocumentModelModule {
|
|
47
|
+
const base =
|
|
48
|
+
documentModelDocumentModelModule as unknown as DocumentModelModule;
|
|
49
|
+
return {
|
|
50
|
+
...base,
|
|
51
|
+
...(version === undefined ? {} : { version }),
|
|
52
|
+
documentModel: {
|
|
53
|
+
...base.documentModel,
|
|
54
|
+
global: { ...base.documentModel.global, id, name },
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const readReport = (file: string) =>
|
|
60
|
+
JSON.parse(readFileSync(file, "utf8")) as InspectorReport;
|
|
61
|
+
|
|
62
|
+
let tempRoot: string;
|
|
63
|
+
let reportFile: string;
|
|
64
|
+
|
|
65
|
+
beforeEach(async () => {
|
|
66
|
+
tempRoot = await mkdtemp(join(tmpdir(), "switchboard-inspector-"));
|
|
67
|
+
reportFile = join(tempRoot, "preview", "inspector.json");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
afterEach(async () => {
|
|
71
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("inspector config", () => {
|
|
75
|
+
it("needs a report file and rejects a typo'd key", () => {
|
|
76
|
+
expect(inspectorPluginConfigSchema.safeParse({}).success).toBe(false);
|
|
77
|
+
expect(
|
|
78
|
+
inspectorPluginConfigSchema.safeParse({ reportFile: "a.json" }).success,
|
|
79
|
+
).toBe(true);
|
|
80
|
+
expect(
|
|
81
|
+
inspectorPluginConfigSchema.safeParse({ reportFile: "a.json", file: "b" })
|
|
82
|
+
.success,
|
|
83
|
+
).toBe(false);
|
|
84
|
+
expect(() => createInspectorPlugin({})).toThrow();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe("inspectorReportOf", () => {
|
|
89
|
+
it("lists every module with its specifications, the project marked local", () => {
|
|
90
|
+
const report = inspectorReportOf(
|
|
91
|
+
[
|
|
92
|
+
[
|
|
93
|
+
tempRoot,
|
|
94
|
+
[
|
|
95
|
+
moduleOf("acme/invoice", "Invoice", 2),
|
|
96
|
+
moduleOf("acme/contact", "Contact"),
|
|
97
|
+
moduleOf("acme/invoice", "Invoice", 1),
|
|
98
|
+
],
|
|
99
|
+
],
|
|
100
|
+
["@acme/other", [moduleOf("other/thing", "Thing")]],
|
|
101
|
+
],
|
|
102
|
+
{
|
|
103
|
+
sequence: 3,
|
|
104
|
+
localPackage: tempRoot,
|
|
105
|
+
now: new Date("2026-01-02T03:04:05.000Z"),
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
expect(report).toMatchObject({
|
|
110
|
+
version: 1,
|
|
111
|
+
sequence: 3,
|
|
112
|
+
writtenAt: "2026-01-02T03:04:05.000Z",
|
|
113
|
+
pid: process.pid,
|
|
114
|
+
});
|
|
115
|
+
expect(report.packages.map((p) => [p.name, p.local])).toEqual(
|
|
116
|
+
[
|
|
117
|
+
["@acme/other", false],
|
|
118
|
+
[tempRoot, true],
|
|
119
|
+
].sort(([a], [b]) => String(a).localeCompare(String(b))),
|
|
120
|
+
);
|
|
121
|
+
const local = report.packages.find((p) => p.local)!;
|
|
122
|
+
expect(
|
|
123
|
+
local.models.map((m) => [m.documentType, m.name, m.version]),
|
|
124
|
+
).toEqual([
|
|
125
|
+
["acme/contact", "Contact", undefined],
|
|
126
|
+
["acme/invoice", "Invoice", 1],
|
|
127
|
+
["acme/invoice", "Invoice", 2],
|
|
128
|
+
]);
|
|
129
|
+
expect(local.models[0]).not.toHaveProperty("version");
|
|
130
|
+
expect(
|
|
131
|
+
local.models[1]!.documentModel.specifications.length,
|
|
132
|
+
).toBeGreaterThan(0);
|
|
133
|
+
expect(local.models[1]!.documentModel.id).toBe("acme/invoice");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("marks nothing local when the project is not loaded", () => {
|
|
137
|
+
const report = inspectorReportOf([[tempRoot, []]], { sequence: 1 });
|
|
138
|
+
expect(report.packages).toEqual([
|
|
139
|
+
{ name: tempRoot, local: false, models: [] },
|
|
140
|
+
]);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe("inspector hooks", () => {
|
|
145
|
+
function stubContext(
|
|
146
|
+
initial: Map<string, DocumentModelModule[]>,
|
|
147
|
+
options: Record<string, unknown> = {},
|
|
148
|
+
) {
|
|
149
|
+
const handlers: ((
|
|
150
|
+
models: Record<string, DocumentModelModule[]>,
|
|
151
|
+
) => unknown)[] = [];
|
|
152
|
+
const logger = stubLogger();
|
|
153
|
+
const ctx = {
|
|
154
|
+
logger,
|
|
155
|
+
options,
|
|
156
|
+
renown: null,
|
|
157
|
+
contributions: {},
|
|
158
|
+
api: {
|
|
159
|
+
packageManager: {
|
|
160
|
+
getDocumentModels: () => new Map(initial),
|
|
161
|
+
onDocumentModelsChange: (
|
|
162
|
+
handler: (models: Record<string, DocumentModelModule[]>) => unknown,
|
|
163
|
+
) => {
|
|
164
|
+
handlers.push(handler);
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
} as unknown as SwitchboardHostContext;
|
|
169
|
+
return {
|
|
170
|
+
ctx,
|
|
171
|
+
logger,
|
|
172
|
+
reload: (models: Record<string, DocumentModelModule[]>) =>
|
|
173
|
+
handlers.forEach((handler) => handler(models)),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
it("reports at ready and on every reload, and removes the file at shutdown", () => {
|
|
178
|
+
const plugin = createInspectorPlugin({ reportFile });
|
|
179
|
+
const cwd = process.cwd();
|
|
180
|
+
const { ctx, reload } = stubContext(
|
|
181
|
+
new Map([[cwd, [moduleOf("acme/contact", "Contact")]]]),
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
plugin.hooks!.onReactorReady!(ctx);
|
|
185
|
+
const first = readReport(reportFile);
|
|
186
|
+
expect(first.sequence).toBe(1);
|
|
187
|
+
expect(first.packages).toHaveLength(1);
|
|
188
|
+
expect(first.packages[0]).toMatchObject({ name: cwd, local: true });
|
|
189
|
+
expect(first.packages[0]!.models.map((m) => m.documentType)).toEqual([
|
|
190
|
+
"acme/contact",
|
|
191
|
+
]);
|
|
192
|
+
|
|
193
|
+
reload({
|
|
194
|
+
[cwd]: [
|
|
195
|
+
moduleOf("acme/contact", "Contact"),
|
|
196
|
+
moduleOf("acme/invoice", "Invoice", 1),
|
|
197
|
+
],
|
|
198
|
+
});
|
|
199
|
+
const second = readReport(reportFile);
|
|
200
|
+
expect(second.sequence).toBe(2);
|
|
201
|
+
expect(second.packages[0]!.models.map((m) => m.documentType)).toEqual([
|
|
202
|
+
"acme/contact",
|
|
203
|
+
"acme/invoice",
|
|
204
|
+
]);
|
|
205
|
+
// Only the report: the temp file it was written through is gone.
|
|
206
|
+
expect(readdirSync(join(tempRoot, "preview"))).toEqual(["inspector.json"]);
|
|
207
|
+
|
|
208
|
+
plugin.hooks!.onShutdown!(ctx);
|
|
209
|
+
expect(existsSync(reportFile)).toBe(false);
|
|
210
|
+
// A reload that lands after the stop writes nothing.
|
|
211
|
+
reload({ [cwd]: [] });
|
|
212
|
+
expect(existsSync(reportFile)).toBe(false);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("marks no package local on a switchboard that does not load the project", () => {
|
|
216
|
+
const plugin = createInspectorPlugin({ reportFile });
|
|
217
|
+
const { ctx } = stubContext(new Map([[process.cwd(), []]]), {
|
|
218
|
+
disableLocalPackages: true,
|
|
219
|
+
});
|
|
220
|
+
plugin.hooks!.onReactorReady!(ctx);
|
|
221
|
+
expect(readReport(reportFile).packages[0]!.local).toBe(false);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("warns and carries on when the report cannot be written", () => {
|
|
225
|
+
// A folder in the file's place: the rename fails.
|
|
226
|
+
const plugin = createInspectorPlugin({ reportFile: tempRoot });
|
|
227
|
+
const { ctx, logger } = stubContext(new Map());
|
|
228
|
+
expect(() => plugin.hooks!.onReactorReady!(ctx)).not.toThrow();
|
|
229
|
+
expect(logger.warn).toHaveBeenCalledTimes(1);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("switches the codegen processor off unless asked to keep it", () => {
|
|
233
|
+
const { ctx } = stubContext(new Map());
|
|
234
|
+
expect(
|
|
235
|
+
createInspectorPlugin({ reportFile }).hooks!.transformServerOptions!(
|
|
236
|
+
{ dev: true },
|
|
237
|
+
ctx,
|
|
238
|
+
),
|
|
239
|
+
).toEqual({ dev: true, codegenProcessor: false });
|
|
240
|
+
expect(
|
|
241
|
+
createInspectorPlugin({
|
|
242
|
+
reportFile,
|
|
243
|
+
codegen: true,
|
|
244
|
+
}).hooks!.transformServerOptions!({ dev: true }, ctx),
|
|
245
|
+
).toEqual({ dev: true });
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
describe("a switchboard with the inspector in its composition", () => {
|
|
250
|
+
it("writes the report once ready and removes it at shutdown", async () => {
|
|
251
|
+
const names = ["PH_REACTOR_DATABASE_URL", "MCP_ENABLED"];
|
|
252
|
+
const previous = names.map((name) => [name, process.env[name]] as const);
|
|
253
|
+
process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
|
|
254
|
+
delete process.env.MCP_ENABLED;
|
|
255
|
+
const composition: ResolvedPlugin[] = [
|
|
256
|
+
{
|
|
257
|
+
plugin: createInspectorPlugin({ reportFile }) as HostPlugin,
|
|
258
|
+
provenance: "built-in",
|
|
259
|
+
entry: {
|
|
260
|
+
enabled: true,
|
|
261
|
+
verbs: "*",
|
|
262
|
+
config: { reportFile },
|
|
263
|
+
module: "@powerhousedao/switchboard/plugins/inspector",
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
];
|
|
267
|
+
let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
|
|
268
|
+
try {
|
|
269
|
+
switchboard = await bootSwitchboard(
|
|
270
|
+
{
|
|
271
|
+
server: { port: 0 },
|
|
272
|
+
storage: { readModel: { url: join(tempRoot, "read-model") } },
|
|
273
|
+
features: { workflows: false },
|
|
274
|
+
packages: { disableLocal: true },
|
|
275
|
+
identity: { keypairPath: join(tempRoot, "identity.json") },
|
|
276
|
+
drive: { slug: "default-drive", global: { name: "Default Drive" } },
|
|
277
|
+
},
|
|
278
|
+
{ logger: stubLogger(), pluginComposition: composition },
|
|
279
|
+
);
|
|
280
|
+
const report = readReport(reportFile);
|
|
281
|
+
expect(report).toMatchObject({
|
|
282
|
+
version: 1,
|
|
283
|
+
sequence: 1,
|
|
284
|
+
pid: process.pid,
|
|
285
|
+
});
|
|
286
|
+
expect(Array.isArray(report.packages)).toBe(true);
|
|
287
|
+
expect(report.packages.every((p) => !p.local)).toBe(true);
|
|
288
|
+
|
|
289
|
+
await switchboard.shutdown();
|
|
290
|
+
switchboard = undefined;
|
|
291
|
+
expect(existsSync(reportFile)).toBe(false);
|
|
292
|
+
} finally {
|
|
293
|
+
await switchboard?.shutdown();
|
|
294
|
+
for (const [name, value] of previous) {
|
|
295
|
+
if (value === undefined) delete process.env[name];
|
|
296
|
+
else process.env[name] = value;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}, 60_000);
|
|
300
|
+
});
|