@xlinklight/testkit 0.0.0-stage → 7.0.0
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/LICENSE +21 -0
- package/README.md +168 -2
- package/content/platform-baseline.sql +273 -0
- package/package.json +274 -3
- package/src/acceptance-oracle.d.mts +24 -0
- package/src/acceptance-oracle.mjs +79 -0
- package/src/architecture-database.d.mts +36 -0
- package/src/architecture-database.mjs +64 -0
- package/src/artifact-build.d.mts +3 -0
- package/src/artifact-build.mjs +35 -0
- package/src/artifact-declarations.mjs +24 -0
- package/src/artifact-graphs.mjs +61 -0
- package/src/artifact-lock.mjs +32 -0
- package/src/artifact-observation.mjs +50 -0
- package/src/artifact-publisher.d.mts +30 -0
- package/src/artifact-publisher.mjs +84 -0
- package/src/browser-lifecycle.mjs +45 -0
- package/src/browser-operation-owner.mjs +28 -0
- package/src/cloudflare-browser.d.mts +14 -0
- package/src/cloudflare-browser.mjs +41 -0
- package/src/cloudflare-build.d.mts +19 -0
- package/src/cloudflare-build.mjs +61 -0
- package/src/cloudflare-http.d.mts +5 -0
- package/src/cloudflare-http.mjs +65 -0
- package/src/cloudflare-pages.d.mts +34 -0
- package/src/cloudflare-pages.mjs +170 -0
- package/src/cloudflare-provider-http.d.mts +8 -0
- package/src/cloudflare-provider-http.mjs +32 -0
- package/src/cloudflare-worker-package.d.mts +6 -0
- package/src/cloudflare-worker-package.mjs +24 -0
- package/src/cloudflare-worker-qualification.d.mts +4 -0
- package/src/cloudflare-worker-qualification.mjs +63 -0
- package/src/cloudflare-workers.d.mts +37 -0
- package/src/cloudflare-workers.mjs +90 -0
- package/src/cluster-directory.d.mts +16 -0
- package/src/cluster-directory.mjs +90 -0
- package/src/core-publishing.d.mts +75 -0
- package/src/core-publishing.mjs +214 -0
- package/src/dev-command-runner.mjs +97 -0
- package/src/fixture-path.mjs +19 -0
- package/src/function-admission.d.mts +1 -0
- package/src/function-admission.mjs +58 -0
- package/src/host-artifact.mjs +32 -0
- package/src/host-stop.mjs +15 -0
- package/src/independent-artifact-qualification.mjs +67 -0
- package/src/independent-runtime-qualification.mjs +647 -0
- package/src/isolated-browser-child.mjs +29 -0
- package/src/isolated-browser.mjs +69 -0
- package/src/lifecycle-trace.mjs +32 -0
- package/src/managed-native-fixture.d.mts +84 -0
- package/src/managed-native-fixture.mjs +209 -0
- package/src/native-fixture.mjs +125 -0
- package/src/native-platform.mjs +56 -0
- package/src/operator-accounts.mjs +103 -0
- package/src/operator-vault.d.mts +2 -0
- package/src/operator-vault.mjs +9 -0
- package/src/owned-process.mjs +75 -0
- package/src/owner-build-cli.d.mts +1 -0
- package/src/owner-build-cli.mjs +31 -0
- package/src/owner-database.mjs +215 -0
- package/src/owner-operator-build.d.mts +1 -0
- package/src/owner-operator-build.mjs +33 -0
- package/src/owner-package-build.d.mts +2 -0
- package/src/owner-package-build.mjs +29 -0
- package/src/owner-production-browser.mjs +215 -0
- package/src/owner-production-instances.mjs +41 -0
- package/src/owner-production.d.mts +104 -0
- package/src/owner-production.mjs +338 -0
- package/src/owner-release.mjs +41 -0
- package/src/owner-worker-build.d.mts +3 -0
- package/src/owner-worker-build.mjs +83 -0
- package/src/prebuilt-build.d.mts +8 -0
- package/src/prebuilt-build.mjs +69 -0
- package/src/prebuilt-output.d.mts +2 -0
- package/src/prebuilt-output.mjs +104 -0
- package/src/production-hosts.mjs +38 -0
- package/src/publisher-acceptance-host-cli.mjs +23 -0
- package/src/publisher-acceptance-owner.mjs +116 -0
- package/src/publisher-acceptance-runner.mjs +250 -0
- package/src/publisher-acceptance-service.mjs +49 -0
- package/src/publisher-acceptance.d.mts +61 -0
- package/src/publisher-acceptance.mjs +3 -0
- package/src/publishing-source.d.mts +11 -0
- package/src/publishing-source.mjs +32 -0
- package/src/qualification-function-host.mjs +26 -0
- package/src/qualification-route-owner.mjs +64 -0
- package/src/qualification-transport.mjs +18 -0
- package/src/registry-core-selection.mjs +41 -0
- package/src/release-artifact.d.mts +17 -0
- package/src/release-artifact.mjs +113 -0
- package/src/release-build.d.mts +12 -0
- package/src/release-build.mjs +71 -0
- package/src/release-cli.d.mts +27 -0
- package/src/release-cli.mjs +79 -0
- package/src/release-control.mjs +45 -0
- package/src/release-coordinator.d.mts +9 -0
- package/src/release-coordinator.mjs +222 -0
- package/src/release-credentials.d.mts +8 -0
- package/src/release-credentials.mjs +97 -0
- package/src/release-environment.mjs +60 -0
- package/src/release-mutex.d.mts +10 -0
- package/src/release-mutex.mjs +38 -0
- package/src/release-operator.d.mts +6 -0
- package/src/release-operator.mjs +59 -0
- package/src/release-supabase.d.mts +7 -0
- package/src/release-supabase.mjs +37 -0
- package/src/release-vercel.d.mts +22 -0
- package/src/release-vercel.mjs +51 -0
- package/src/release-writer.d.mts +6 -0
- package/src/release-writer.mjs +172 -0
- package/src/retained-postgres-shutdown.d.mts +51 -0
- package/src/retained-postgres-shutdown.mjs +262 -0
- package/src/schema-snapshot.mjs +51 -0
- package/src/static-ui-artifact.mjs +54 -0
- package/src/static-ui-routes.mjs +3 -0
- package/src/temporary-acquisition.mjs +62 -0
- package/src/temporary-scope.d.mts +47 -0
- package/src/temporary-scope.mjs +268 -0
- package/src/unscoped-read.mjs +14 -0
- package/src/worker-artifact.mjs +214 -0
package/package.json
CHANGED
|
@@ -1,6 +1,277 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xlinklight/testkit",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "7.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/zopenge/link-light.git",
|
|
8
|
+
"directory": "packages/testkit"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public",
|
|
12
|
+
"registry": "https://registry.npmjs.org",
|
|
13
|
+
"provenance": false
|
|
14
|
+
},
|
|
15
|
+
"private": false,
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": [
|
|
18
|
+
"./src/host-stop.mjs"
|
|
19
|
+
],
|
|
20
|
+
"files": [
|
|
21
|
+
"src",
|
|
22
|
+
"content",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"bin": {
|
|
26
|
+
"link-light-build": "./src/owner-build-cli.mjs",
|
|
27
|
+
"link-light-acceptance-runner": "./src/publisher-acceptance-host-cli.mjs"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
"./cloudflare-build": {
|
|
31
|
+
"types": "./src/cloudflare-build.d.mts",
|
|
32
|
+
"browser": null,
|
|
33
|
+
"import": "./src/cloudflare-build.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./cloudflare-http": {
|
|
36
|
+
"types": "./src/cloudflare-http.d.mts",
|
|
37
|
+
"import": "./src/cloudflare-http.mjs"
|
|
38
|
+
},
|
|
39
|
+
"./cloudflare-browser": {
|
|
40
|
+
"types": "./src/cloudflare-browser.d.mts",
|
|
41
|
+
"import": "./src/cloudflare-browser.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./cloudflare-workers": {
|
|
44
|
+
"types": "./src/cloudflare-workers.d.mts",
|
|
45
|
+
"import": "./src/cloudflare-workers.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./publishing-source": {
|
|
48
|
+
"types": "./src/publishing-source.d.mts",
|
|
49
|
+
"browser": null,
|
|
50
|
+
"import": "./src/publishing-source.mjs"
|
|
51
|
+
},
|
|
52
|
+
"./owner-build-cli": {
|
|
53
|
+
"types": "./src/owner-build-cli.d.mts",
|
|
54
|
+
"browser": null,
|
|
55
|
+
"import": "./src/owner-build-cli.mjs"
|
|
56
|
+
},
|
|
57
|
+
"./artifact-observation": "./src/artifact-observation.mjs",
|
|
58
|
+
"./artifact-build": {
|
|
59
|
+
"types": "./src/artifact-build.d.mts",
|
|
60
|
+
"browser": null,
|
|
61
|
+
"import": "./src/artifact-build.mjs"
|
|
62
|
+
},
|
|
63
|
+
"./artifact-publisher": {
|
|
64
|
+
"types": "./src/artifact-publisher.d.mts",
|
|
65
|
+
"workerd": "./src/artifact-publisher.mjs",
|
|
66
|
+
"browser": null,
|
|
67
|
+
"import": "./src/artifact-publisher.mjs"
|
|
68
|
+
},
|
|
69
|
+
"./cloudflare-pages": {
|
|
70
|
+
"types": "./src/cloudflare-pages.d.mts",
|
|
71
|
+
"workerd": "./src/cloudflare-pages.mjs",
|
|
72
|
+
"browser": null,
|
|
73
|
+
"import": "./src/cloudflare-pages.mjs"
|
|
74
|
+
},
|
|
75
|
+
"./core-publishing": {
|
|
76
|
+
"types": "./src/core-publishing.d.mts",
|
|
77
|
+
"workerd": "./src/core-publishing.mjs",
|
|
78
|
+
"browser": null,
|
|
79
|
+
"import": "./src/core-publishing.mjs"
|
|
80
|
+
},
|
|
81
|
+
"./publisher-acceptance": {
|
|
82
|
+
"types": "./src/publisher-acceptance.d.mts",
|
|
83
|
+
"browser": null,
|
|
84
|
+
"import": "./src/publisher-acceptance.mjs"
|
|
85
|
+
},
|
|
86
|
+
"./static-ui-artifact": "./src/static-ui-artifact.mjs",
|
|
87
|
+
"./prebuilt-output": {
|
|
88
|
+
"types": "./src/prebuilt-output.d.mts",
|
|
89
|
+
"browser": null,
|
|
90
|
+
"import": "./src/prebuilt-output.mjs"
|
|
91
|
+
},
|
|
92
|
+
"./prebuilt-build": {
|
|
93
|
+
"types": "./src/prebuilt-build.d.mts",
|
|
94
|
+
"browser": null,
|
|
95
|
+
"import": "./src/prebuilt-build.mjs"
|
|
96
|
+
},
|
|
97
|
+
"./worker-artifact": "./src/worker-artifact.mjs",
|
|
98
|
+
"./artifact-lock": "./src/artifact-lock.mjs",
|
|
99
|
+
"./artifact-declarations": "./src/artifact-declarations.mjs",
|
|
100
|
+
"./artifact-graphs": "./src/artifact-graphs.mjs",
|
|
101
|
+
"./independent-runtime-qualification": "./src/independent-runtime-qualification.mjs",
|
|
102
|
+
"./native-fixture": "./src/native-fixture.mjs",
|
|
103
|
+
"./architecture-database": {
|
|
104
|
+
"types": "./src/architecture-database.d.mts",
|
|
105
|
+
"import": "./src/architecture-database.mjs"
|
|
106
|
+
},
|
|
107
|
+
"./host-artifact": "./src/host-artifact.mjs",
|
|
108
|
+
"./temporary-scope": "./src/temporary-scope.mjs",
|
|
109
|
+
"./owned-process": "./src/owned-process.mjs",
|
|
110
|
+
"./native-platform": "./src/native-platform.mjs",
|
|
111
|
+
"./cluster-directory": {
|
|
112
|
+
"types": "./src/cluster-directory.d.mts",
|
|
113
|
+
"import": "./src/cluster-directory.mjs"
|
|
114
|
+
},
|
|
115
|
+
"./managed-native-fixture": {
|
|
116
|
+
"types": "./src/managed-native-fixture.d.mts",
|
|
117
|
+
"import": "./src/managed-native-fixture.mjs"
|
|
118
|
+
},
|
|
119
|
+
"./retained-postgres-shutdown": {
|
|
120
|
+
"types": "./src/retained-postgres-shutdown.d.mts",
|
|
121
|
+
"import": "./src/retained-postgres-shutdown.mjs"
|
|
122
|
+
},
|
|
123
|
+
"./host-stop": "./src/host-stop.mjs",
|
|
124
|
+
"./production-hosts": "./src/production-hosts.mjs",
|
|
125
|
+
"./browser-lifecycle": "./src/browser-lifecycle.mjs",
|
|
126
|
+
"./platform-baseline": "./content/platform-baseline.sql",
|
|
127
|
+
"./dev-command-runner": "./src/dev-command-runner.mjs",
|
|
128
|
+
"./lifecycle-trace": "./src/lifecycle-trace.mjs",
|
|
129
|
+
"./release-cli": {
|
|
130
|
+
"types": "./src/release-cli.d.mts",
|
|
131
|
+
"browser": null,
|
|
132
|
+
"import": "./src/release-cli.mjs"
|
|
133
|
+
},
|
|
134
|
+
"./release-credentials": {
|
|
135
|
+
"types": "./src/release-credentials.d.mts",
|
|
136
|
+
"browser": null,
|
|
137
|
+
"import": "./src/release-credentials.mjs"
|
|
138
|
+
},
|
|
139
|
+
"./release-writer": {
|
|
140
|
+
"types": "./src/release-writer.d.mts",
|
|
141
|
+
"browser": null,
|
|
142
|
+
"import": "./src/release-writer.mjs"
|
|
143
|
+
},
|
|
144
|
+
"./release-coordinator": {
|
|
145
|
+
"types": "./src/release-coordinator.d.mts",
|
|
146
|
+
"browser": null,
|
|
147
|
+
"import": "./src/release-coordinator.mjs"
|
|
148
|
+
},
|
|
149
|
+
"./release-mutex": {
|
|
150
|
+
"types": "./src/release-mutex.d.mts",
|
|
151
|
+
"browser": null,
|
|
152
|
+
"import": "./src/release-mutex.mjs"
|
|
153
|
+
},
|
|
154
|
+
"./function-admission": {
|
|
155
|
+
"types": "./src/function-admission.d.mts",
|
|
156
|
+
"browser": null,
|
|
157
|
+
"import": "./src/function-admission.mjs"
|
|
158
|
+
},
|
|
159
|
+
"./release-artifact": {
|
|
160
|
+
"types": "./src/release-artifact.d.mts",
|
|
161
|
+
"browser": null,
|
|
162
|
+
"import": "./src/release-artifact.mjs"
|
|
163
|
+
},
|
|
164
|
+
"./release-build": {
|
|
165
|
+
"types": "./src/release-build.d.mts",
|
|
166
|
+
"browser": null,
|
|
167
|
+
"import": "./src/release-build.mjs"
|
|
168
|
+
},
|
|
169
|
+
"./owner-release": {
|
|
170
|
+
"browser": null,
|
|
171
|
+
"import": "./src/owner-release.mjs"
|
|
172
|
+
},
|
|
173
|
+
"./acceptance-oracle": {
|
|
174
|
+
"types": "./src/acceptance-oracle.d.mts",
|
|
175
|
+
"workerd": "./src/acceptance-oracle.mjs",
|
|
176
|
+
"browser": null,
|
|
177
|
+
"import": "./src/acceptance-oracle.mjs"
|
|
178
|
+
},
|
|
179
|
+
"./owner-production": {
|
|
180
|
+
"types": "./src/owner-production.d.mts",
|
|
181
|
+
"workerd": "./src/owner-production.mjs",
|
|
182
|
+
"browser": null,
|
|
183
|
+
"import": "./src/owner-production.mjs"
|
|
184
|
+
},
|
|
185
|
+
"./operator-accounts": {
|
|
186
|
+
"browser": null,
|
|
187
|
+
"import": "./src/operator-accounts.mjs"
|
|
188
|
+
},
|
|
189
|
+
"./schema-snapshot": {
|
|
190
|
+
"browser": null,
|
|
191
|
+
"import": "./src/schema-snapshot.mjs"
|
|
192
|
+
},
|
|
193
|
+
"./owner-database": {
|
|
194
|
+
"browser": null,
|
|
195
|
+
"import": "./src/owner-database.mjs"
|
|
196
|
+
},
|
|
197
|
+
"./release-environment": {
|
|
198
|
+
"browser": null,
|
|
199
|
+
"import": "./src/release-environment.mjs"
|
|
200
|
+
},
|
|
201
|
+
"./release-control": {
|
|
202
|
+
"workerd": "./src/release-control.mjs",
|
|
203
|
+
"browser": null,
|
|
204
|
+
"import": "./src/release-control.mjs"
|
|
205
|
+
},
|
|
206
|
+
"./release-vercel": {
|
|
207
|
+
"types": "./src/release-vercel.d.mts",
|
|
208
|
+
"browser": null,
|
|
209
|
+
"import": "./src/release-vercel.mjs"
|
|
210
|
+
},
|
|
211
|
+
"./release-supabase": {
|
|
212
|
+
"types": "./src/release-supabase.d.mts",
|
|
213
|
+
"browser": null,
|
|
214
|
+
"import": "./src/release-supabase.mjs"
|
|
215
|
+
},
|
|
216
|
+
"./operator-vault": {
|
|
217
|
+
"types": "./src/operator-vault.d.mts",
|
|
218
|
+
"browser": null,
|
|
219
|
+
"import": "./src/operator-vault.mjs"
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
"dependencies": {
|
|
223
|
+
"@openge/forge-artifact-publish": "0.4.1",
|
|
224
|
+
"@openge/forge-command-runner": "0.1.0-rc.1",
|
|
225
|
+
"@openge/forge-generated-artifacts": "0.2.0",
|
|
226
|
+
"@openge/forge-process-control": "0.1.0",
|
|
227
|
+
"@openge/forge-process-control-node": "0.1.0",
|
|
228
|
+
"@supabase/supabase-js": "2.108.2",
|
|
229
|
+
"canonicalize": "2.1.0",
|
|
230
|
+
"dependency-cruiser": "18.4.0",
|
|
231
|
+
"js-yaml": "4.2.0",
|
|
232
|
+
"pg": "8.23.0",
|
|
233
|
+
"pg-boss": "12.35.0",
|
|
234
|
+
"vite": "8.0.16",
|
|
235
|
+
"@xlinklight/publishing": "3.0.0"
|
|
236
|
+
},
|
|
237
|
+
"peerDependencies": {
|
|
238
|
+
"wrangler": "4.158.0",
|
|
239
|
+
"@cloudflare/playwright": "1.4.0",
|
|
240
|
+
"@openge/forge-http-transport": "0.1.0",
|
|
241
|
+
"cloudflare": "7.3.0",
|
|
242
|
+
"@noble/hashes": "2.4.0",
|
|
243
|
+
"@xlinklight/solution-sdk": "3.1.0",
|
|
244
|
+
"@xlinklight/platform": "5.0.0"
|
|
245
|
+
},
|
|
246
|
+
"peerDependenciesMeta": {
|
|
247
|
+
"wrangler": {
|
|
248
|
+
"optional": true
|
|
249
|
+
},
|
|
250
|
+
"@cloudflare/playwright": {
|
|
251
|
+
"optional": true
|
|
252
|
+
},
|
|
253
|
+
"@xlinklight/solution-sdk": {
|
|
254
|
+
"optional": true
|
|
255
|
+
},
|
|
256
|
+
"@xlinklight/platform": {
|
|
257
|
+
"optional": true
|
|
258
|
+
},
|
|
259
|
+
"@openge/forge-http-transport": {
|
|
260
|
+
"optional": true
|
|
261
|
+
},
|
|
262
|
+
"cloudflare": {
|
|
263
|
+
"optional": true
|
|
264
|
+
},
|
|
265
|
+
"@noble/hashes": {
|
|
266
|
+
"optional": true
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
"engines": {
|
|
270
|
+
"node": ">=22.15.0"
|
|
271
|
+
},
|
|
272
|
+
"scripts": {
|
|
273
|
+
"build": "node scripts/build.mjs",
|
|
274
|
+
"test": "node --test tests/*.test.mjs",
|
|
275
|
+
"test:architecture-native": "node --test tests/architecture-database.native.mjs"
|
|
276
|
+
}
|
|
6
277
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface AcceptanceOracleReference {readonly parameter:number;readonly path?:readonly string[]}
|
|
2
|
+
export interface AcceptanceOracleStatement {
|
|
3
|
+
readonly name:string;readonly text:string;
|
|
4
|
+
readonly parameters:readonly {readonly type:'text'|'jsonb';readonly maximumBytes:number}[];
|
|
5
|
+
readonly returns:{readonly kind:'rows';readonly maximumRows:number;readonly columns:readonly {readonly name:string;readonly type:'text'|'int4'|'boolean';readonly maximumBytes?:number}[]}|{readonly kind:'command';readonly minimumAffectedRows:number;readonly maximumAffectedRows:number};
|
|
6
|
+
readonly scope:{readonly kind:'instance'|'run';readonly allowProviders:boolean;readonly instance?:AcceptanceOracleReference;readonly tenant?:AcceptanceOracleReference;readonly principal?:AcceptanceOracleReference;readonly revision?:AcceptanceOracleReference;readonly run?:AcceptanceOracleReference};
|
|
7
|
+
}
|
|
8
|
+
export interface AcceptanceOracleResult {rows:Record<string,unknown>[];rowCount:number}
|
|
9
|
+
export interface AcceptanceOracleCommand {statement:AcceptanceOracleStatement;values:readonly unknown[];statementDigest:`sha256:${string}`;signal?:AbortSignal}
|
|
10
|
+
export interface AcceptanceOracleClient {
|
|
11
|
+
resolve(statement:AcceptanceOracleStatement):{statement:AcceptanceOracleStatement;statementDigest:`sha256:${string}`};
|
|
12
|
+
query(statement:AcceptanceOracleStatement,values:readonly unknown[],options?:{signal?:AbortSignal}):Promise<AcceptanceOracleResult>;
|
|
13
|
+
}
|
|
14
|
+
/** The returned declaration is deeply frozen and registered by object identity. */
|
|
15
|
+
export function defineAcceptanceOracleStatement(input:AcceptanceOracleStatement):AcceptanceOracleStatement;
|
|
16
|
+
/** JCS (canonicalize2.1.0) SHA256 over the finite owned declaration, identical
|
|
17
|
+
* to Core metadata digest semantics without requiring the optional platform. */
|
|
18
|
+
export function acceptanceOracleStatementDigest(statement:AcceptanceOracleStatement):`sha256:${string}`;
|
|
19
|
+
/** Pure factory. Local execute uses {name,text,values}; a privileged service
|
|
20
|
+
* instead calls its exact fixed function with the digest/current release context. */
|
|
21
|
+
export function createAcceptanceOracleClient(options:{statements:readonly AcceptanceOracleStatement[];execute(command:AcceptanceOracleCommand):Promise<{rows:Record<string,unknown>[];rowCount?:number}>}):AcceptanceOracleClient;
|
|
22
|
+
export const acceptanceBudgetStatement:AcceptanceOracleStatement;
|
|
23
|
+
export const acceptanceCommittedStatement:AcceptanceOracleStatement;
|
|
24
|
+
export const coreAcceptanceOracleStatements:readonly AcceptanceOracleStatement[];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {createHash} from 'node:crypto';
|
|
2
|
+
import canonicalize from 'canonicalize';
|
|
3
|
+
|
|
4
|
+
const statements=new WeakSet();
|
|
5
|
+
const fail=code=>Error('ACCEPTANCE_ORACLE_'+code);
|
|
6
|
+
const record=(value,keys)=>value!==null&&typeof value==='object'&&!Array.isArray(value)&&Object.keys(value).sort().join(',')===[...keys].sort().join(',');
|
|
7
|
+
const integer=(value,maximum)=>Number.isSafeInteger(value)&&value>=0&&value<=maximum;
|
|
8
|
+
const identifier=value=>typeof value==='string'&&/^[a-z][a-z0-9_]{0,62}$/.test(value);
|
|
9
|
+
const encoder=new TextEncoder(),bytes=value=>encoder.encode(value).byteLength;
|
|
10
|
+
function freeze(value){if(value&&typeof value==='object'){for(const item of Object.values(value))freeze(item);Object.freeze(value);}return value;}
|
|
11
|
+
// Read data descriptors once. No accessor or user serialization hook is ever
|
|
12
|
+
// invoked, and every subsequent check/serialization uses this private copy.
|
|
13
|
+
function snapshot(value,invalid){
|
|
14
|
+
let nodes=0,minimumBytes=0;const ancestors=new Set();
|
|
15
|
+
const copy=(item,depth=0)=>{
|
|
16
|
+
if(++nodes>65536||depth>64||++minimumBytes>65536)invalid();
|
|
17
|
+
if(item===null||typeof item==='boolean')return item;
|
|
18
|
+
if(typeof item==='string'){minimumBytes+=bytes(item);if(minimumBytes>65536||item.includes('\0'))invalid();return item;}
|
|
19
|
+
if(typeof item==='number'&&Number.isSafeInteger(item))return item;
|
|
20
|
+
if(!item||typeof item!=='object'||ancestors.has(item)||!Array.isArray(item)&&![Object.prototype,null].includes(Object.getPrototypeOf(item)))invalid();
|
|
21
|
+
const properties=Object.getOwnPropertyDescriptors(item),keys=Reflect.ownKeys(properties),array=Array.isArray(item);if(keys.some(key=>typeof key!=='string')||keys.length>65536)invalid();
|
|
22
|
+
const length=array?properties.length?.value:undefined;if(array&&(!integer(length,65536)||keys.length!==length+1))invalid();
|
|
23
|
+
const output=array?[]:{};ancestors.add(item);
|
|
24
|
+
for(const key of keys){if(array&&key==='length')continue;const property=properties[key];if(!Object.hasOwn(property,'value')||!property.enumerable||array&&(!/^(0|[1-9][0-9]*)$/.test(key)||Number(key)>=length))invalid();if(!array)minimumBytes+=bytes(key);if(minimumBytes>65536)invalid();Object.defineProperty(output,key,{value:copy(property.value,depth+1),enumerable:true,writable:true,configurable:true});}
|
|
25
|
+
ancestors.delete(item);return output;
|
|
26
|
+
};
|
|
27
|
+
try{const output=copy(value);if(bytes(JSON.stringify(output))>65536)invalid();return output;}catch{invalid();}
|
|
28
|
+
}
|
|
29
|
+
function validate(input){
|
|
30
|
+
const invalid=()=>{throw fail('STATEMENT_INVALID');};
|
|
31
|
+
if(!record(input,['name','text','parameters','returns','scope'])||!identifier(input.name)||typeof input.text!=='string'||!input.text.trim()||bytes(input.text)>32768||input.text.includes('\0')||/\p{Surrogate}/u.test(input.text)||!Array.isArray(input.parameters)||!input.parameters.length||input.parameters.length>8)invalid();
|
|
32
|
+
for(const parameter of input.parameters)if(!record(parameter,['type','maximumBytes'])||!['text','jsonb'].includes(parameter.type)||!integer(parameter.maximumBytes,parameter.type==='text'?1024:65536)||!parameter.maximumBytes)invalid();
|
|
33
|
+
const returns=input.returns;
|
|
34
|
+
if(returns?.kind==='rows'){
|
|
35
|
+
if(!record(returns,['kind','maximumRows','columns'])||!integer(returns.maximumRows,2)||!returns.maximumRows||!Array.isArray(returns.columns)||!returns.columns.length||returns.columns.length>8)invalid();
|
|
36
|
+
const names=new Set();for(const column of returns.columns){if(!record(column,column.type==='text'?['name','type','maximumBytes']:['name','type'])||!identifier(column.name)||names.has(column.name)||!['text','int4','boolean'].includes(column.type)||column.type==='text'&&(!integer(column.maximumBytes,65536)||!column.maximumBytes))invalid();names.add(column.name);}
|
|
37
|
+
}else if(returns?.kind==='command'){
|
|
38
|
+
if(!record(returns,['kind','minimumAffectedRows','maximumAffectedRows'])||!integer(returns.minimumAffectedRows,1)||!integer(returns.maximumAffectedRows,1)||returns.minimumAffectedRows>returns.maximumAffectedRows)invalid();
|
|
39
|
+
}else invalid();
|
|
40
|
+
const scope=input.scope,fields=['instance','tenant','principal','revision','run'];
|
|
41
|
+
if(!scope||typeof scope!=='object'||Array.isArray(scope)||!['instance','run'].includes(scope.kind)||typeof scope.allowProviders!=='boolean'||Object.keys(scope).some(key=>!['kind','allowProviders',...fields].includes(key))||scope.kind==='instance'&&!scope.instance||scope.kind==='run'&&!scope.run)invalid();
|
|
42
|
+
for(const field of fields)if(scope[field]!==undefined){const ref=scope[field];if(!record(ref,ref.path===undefined?['parameter']:['parameter','path'])||!integer(ref.parameter,input.parameters.length-1))invalid();if(ref.path!==undefined&&(!Array.isArray(ref.path)||!ref.path.length||ref.path.length>4||ref.path.some(part=>typeof part!=='string'||!/^[_A-Za-z][_A-Za-z0-9]{0,63}$/.test(part)||['__proto__','prototype','constructor'].includes(part))||input.parameters[ref.parameter].type!=='jsonb'))invalid();}
|
|
43
|
+
return input;
|
|
44
|
+
}
|
|
45
|
+
/** Trusted source declaration only. SQL is data for local PG/installation;
|
|
46
|
+
* deployed callers have no SQL-string execution port. */
|
|
47
|
+
export function defineAcceptanceOracleStatement(input){const result=freeze(validate(snapshot(input,()=>{throw fail('STATEMENT_INVALID');})));statements.add(result);return result;}
|
|
48
|
+
// Same mature JCS implementation/version as Core, without making the optional
|
|
49
|
+
// platform peer a prerequisite for independent testkit tools.
|
|
50
|
+
export function acceptanceOracleStatementDigest(statement){return 'sha256:'+createHash('sha256').update(canonicalize(validate(snapshot(statement,()=>{throw fail('STATEMENT_INVALID');}))),'utf8').digest('hex');}
|
|
51
|
+
|
|
52
|
+
function parameters(statement,values){
|
|
53
|
+
const invalid=()=>{throw fail('PARAMETERS_INVALID');},selected=snapshot(values,invalid);
|
|
54
|
+
if(!Array.isArray(selected)||selected.length!==statement.parameters.length)invalid();
|
|
55
|
+
for(const [index,value]of selected.entries()){const definition=statement.parameters[index];if(definition.type==='text'){if(typeof value!=='string'||bytes(value)>definition.maximumBytes)invalid();}else if(bytes(JSON.stringify(value))>definition.maximumBytes)invalid();}
|
|
56
|
+
for(const field of ['instance','tenant','principal','revision','run'])if(statement.scope[field]){const ref=statement.scope[field];let value=selected[ref.parameter];for(const part of ref.path??[]){if(!value||typeof value!=='object'||!Object.hasOwn(value,part))throw fail('SCOPE_INVALID');value=value[part];}if(field==='revision'){if(!(typeof value==='number'&&Number.isSafeInteger(value)&&value>0)&&!(typeof value==='string'&&/^[1-9][0-9]{0,63}$/.test(value)))throw fail('SCOPE_INVALID');}else if(typeof value!=='string'||!value||bytes(value)>1024||/[\0-\x1f\x7f]/.test(value))throw fail('SCOPE_INVALID');}
|
|
57
|
+
return freeze(selected);
|
|
58
|
+
}
|
|
59
|
+
function result(statement,value){
|
|
60
|
+
const invalid=()=>{throw fail('RESULT_INVALID');};let rows,rowCount;
|
|
61
|
+
try{if(!value||typeof value!=='object')invalid();const rowProperty=Object.getOwnPropertyDescriptor(value,'rows'),countProperty=Object.getOwnPropertyDescriptor(value,'rowCount');if(!rowProperty||!Object.hasOwn(rowProperty,'value')||countProperty&&!Object.hasOwn(countProperty,'value'))invalid();rows=snapshot(rowProperty.value,invalid);rowCount=countProperty?.value;}catch{invalid();}if(!Array.isArray(rows))invalid();
|
|
62
|
+
if(statement.returns.kind==='command'){if(rows.length||!integer(rowCount,statement.returns.maximumAffectedRows)||rowCount<statement.returns.minimumAffectedRows)invalid();return {rows:[],rowCount};}
|
|
63
|
+
const definition=statement.returns;if(rows.length>definition.maximumRows||rowCount!==undefined&&rowCount!==rows.length)invalid();
|
|
64
|
+
for(const row of rows){if(!record(row,definition.columns.map(column=>column.name)))invalid();for(const column of definition.columns){const selected=row[column.name];if(column.type==='text'?(typeof selected!=='string'||bytes(selected)>column.maximumBytes):column.type==='boolean'?typeof selected!=='boolean':!Number.isInteger(selected)||selected< -2147483648||selected>2147483647)invalid();}}
|
|
65
|
+
return {rows,rowCount:rows.length};
|
|
66
|
+
}
|
|
67
|
+
/** One finite descriptor registry and result contract shared by local PG and
|
|
68
|
+
* private fixed-function adapters. This factory owns no connections/resources. */
|
|
69
|
+
export function createAcceptanceOracleClient({statements:registered,execute}={}){
|
|
70
|
+
if(!Array.isArray(registered)||!registered.length||registered.length>64||typeof execute!=='function')throw fail('REGISTRY_INVALID');
|
|
71
|
+
const registry=new Map(),names=new Set();for(const statement of registered){if(!statements.has(statement)||names.has(statement.name))throw fail('REGISTRY_INVALID');registry.set(statement,acceptanceOracleStatementDigest(statement));names.add(statement.name);}
|
|
72
|
+
const resolve=statement=>{const statementDigest=registry.get(statement);if(!statementDigest)throw fail('STATEMENT_UNKNOWN');return {statement,statementDigest};};
|
|
73
|
+
return Object.freeze({resolve,async query(statement,values,options={}){if(!record(options,options?.signal===undefined?[]:['signal'])||options.signal!==undefined&&!(options.signal instanceof AbortSignal))throw fail('OPTIONS_INVALID');const selected=resolve(statement),snapshot=parameters(statement,values);if(options.signal?.aborted)throw fail('CANCELLED');let observed;try{observed=await execute({...selected,values:snapshot,signal:options.signal});}catch{throw fail(options.signal?.aborted?'CANCELLED':'QUERY_FAILED');}if(options.signal?.aborted)throw fail('CANCELLED');return result(statement,observed);}});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const text=()=>({type:'text',maximumBytes:256});
|
|
77
|
+
export const acceptanceBudgetStatement=defineAcceptanceOracleStatement({name:'ll_acceptance_budget',text:'SELECT budget_limit=0 AS zero_limit,reservation=0 AS zero_reservation FROM platform_private.execution_budgets WHERE tenant_id=$1 AND instance_id=$2 AND principal_id=$3',parameters:[text(),text(),text()],returns:{kind:'rows',maximumRows:1,columns:[{name:'zero_limit',type:'boolean'},{name:'zero_reservation',type:'boolean'}]},scope:{kind:'instance',tenant:{parameter:0},instance:{parameter:1},principal:{parameter:2},allowProviders:true}});
|
|
78
|
+
export const acceptanceCommittedStatement=defineAcceptanceOracleStatement({name:'ll_acceptance_committed',text:"SELECT (SELECT count(*)::int FROM platform_private.execution_results WHERE run_id=$1) results,(SELECT count(*)::int FROM platform_private.execution_events WHERE run_id=$1 AND payload->>'status'='succeeded') terminal,(SELECT count(*)::int FROM platform_private.execution_delivery WHERE run_id=$1) outbox",parameters:[text()],returns:{kind:'rows',maximumRows:1,columns:[{name:'results',type:'int4'},{name:'terminal',type:'int4'},{name:'outbox',type:'int4'}]},scope:{kind:'run',run:{parameter:0},allowProviders:false}});
|
|
79
|
+
export const coreAcceptanceOracleStatements=Object.freeze([acceptanceBudgetStatement,acceptanceCommittedStatement]);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type ArchitectureRow=Record<string,unknown>;
|
|
2
|
+
export interface ArchitectureQueryResult<Row extends ArchitectureRow=ArchitectureRow>{rows:Row[];rowCount:number|null;command:string}
|
|
3
|
+
export interface ArchitectureSqlClient {
|
|
4
|
+
query<Row extends ArchitectureRow=ArchitectureRow>(sql:string,values?:readonly unknown[]):Promise<ArchitectureQueryResult<Row>>;
|
|
5
|
+
close():Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
export interface ArchitectureMigration {name:string;sql:string}
|
|
8
|
+
export interface ArchitectureDatabaseOptions {
|
|
9
|
+
root:string;
|
|
10
|
+
runtimeRoot:string;
|
|
11
|
+
migrations:readonly ArchitectureMigration[];
|
|
12
|
+
label?:string;
|
|
13
|
+
prerequisiteSql?:string;
|
|
14
|
+
beforeMigration?:(input:{client:ArchitectureSqlClient;migrationName:string})=>Promise<unknown>;
|
|
15
|
+
signal?:AbortSignal;
|
|
16
|
+
retainEvidence?:boolean;
|
|
17
|
+
evidenceBase?:string;
|
|
18
|
+
}
|
|
19
|
+
export const ARCHITECTURE_DATABASE_CAPABILITIES:Readonly<{tier:'postgres-16-owned-native';postgres:true;realTransactions:true;databaseRpc:true;supabaseAuth:false;postgrest:false;browser:false}>;
|
|
20
|
+
export interface ArchitectureDatabase {
|
|
21
|
+
capabilities:typeof ARCHITECTURE_DATABASE_CAPABILITIES;
|
|
22
|
+
ownsEnvironment:true;
|
|
23
|
+
retainsDataDirectory:boolean;
|
|
24
|
+
target:{connection:{host:string;port:number;user:string;password:string;database:string}};
|
|
25
|
+
connectionString:string;
|
|
26
|
+
postgresVersion:string;
|
|
27
|
+
appliedMigrations:readonly {name:string;sha256:string}[];
|
|
28
|
+
paths:Readonly<{dataDirectory:string;temporary:string;evidence:string}>;
|
|
29
|
+
evidence:string;
|
|
30
|
+
resultFile?:string;
|
|
31
|
+
connect():Promise<ArchitectureSqlClient>;
|
|
32
|
+
query<Row extends ArchitectureRow=ArchitectureRow>(sql:string,values?:readonly unknown[]):Promise<ArchitectureQueryResult<Row>>;
|
|
33
|
+
transaction<Result>(operation:(client:ArchitectureSqlClient)=>Promise<Result>):Promise<Result>;
|
|
34
|
+
close(result?:{status:string;error?:string}):Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export function createArchitectureDatabase(options:ArchitectureDatabaseOptions):Promise<ArchitectureDatabase>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import {createHash} from 'node:crypto';
|
|
3
|
+
import pg from 'pg';
|
|
4
|
+
import {startNativeFixture} from './native-fixture.mjs';
|
|
5
|
+
|
|
6
|
+
export const ARCHITECTURE_DATABASE_CAPABILITIES=Object.freeze({tier:'postgres-16-owned-native',postgres:true,realTransactions:true,databaseRpc:true,supabaseAuth:false,postgrest:false,browser:false});
|
|
7
|
+
|
|
8
|
+
/** A real owned PostgreSQL database with caller-selected SQL and no business defaults. */
|
|
9
|
+
export async function createArchitectureDatabase(options={}){
|
|
10
|
+
if(typeof options.root!=='string'||!path.isAbsolute(options.root))throw Error('ARCHITECTURE_ROOT_REQUIRED');
|
|
11
|
+
if(typeof options.runtimeRoot!=='string'||!path.isAbsolute(options.runtimeRoot))throw Error('ARCHITECTURE_RUNTIME_ROOT_REQUIRED');
|
|
12
|
+
if(!Array.isArray(options.migrations))throw Error('ARCHITECTURE_MIGRATIONS_REQUIRED');
|
|
13
|
+
const migrations=options.migrations.map(migration=>{
|
|
14
|
+
if(!migration||typeof migration.name!=='string'||!/^[A-Za-z0-9][A-Za-z0-9_.-]{0,191}$/.test(migration.name)||typeof migration.sql!=='string'||!migration.sql.trim())throw Error('ARCHITECTURE_MIGRATION_INVALID');
|
|
15
|
+
return {name:migration.name,sql:migration.sql};
|
|
16
|
+
});
|
|
17
|
+
if(new Set(migrations.map(migration=>migration.name)).size!==migrations.length)throw Error('ARCHITECTURE_MIGRATION_DUPLICATE');
|
|
18
|
+
if(options.prerequisiteSql!==undefined&&typeof options.prerequisiteSql!=='string')throw Error('ARCHITECTURE_PREREQUISITE_INVALID');
|
|
19
|
+
const fixture=await startNativeFixture({...options,label:options.label??'architecture',domains:[]});
|
|
20
|
+
let closed=false,closing;
|
|
21
|
+
const pending=new Set(),clients=new Set(),closeFailures=[];
|
|
22
|
+
const track=promise=>{pending.add(promise);void promise.then(()=>pending.delete(promise),()=>pending.delete(promise));return promise;};
|
|
23
|
+
const assertOpen=()=>{if(closed)throw Error('architecture_database_closed');};
|
|
24
|
+
const connectClient=(transactionAdmission=false)=>track((async()=>{
|
|
25
|
+
assertOpen();
|
|
26
|
+
const raw=new pg.Client({...fixture.ownerConfig,statement_timeout:10000});
|
|
27
|
+
raw.on('error',error=>closeFailures.push(error));
|
|
28
|
+
try{await raw.connect();}catch(error){try{await raw.end();}catch(closeError){closeFailures.push(closeError);throw new AggregateError([error,closeError],'architecture_database_connect_cleanup_failed');}throw error;}
|
|
29
|
+
let closingClient,clientClosed=false;
|
|
30
|
+
const managed={query:async(sql,values=[])=>{if(!transactionAdmission)assertOpen();if(clientClosed)throw Error('architecture_database_client_closed');return track(raw.query(sql,[...values]));},close:()=>closingClient??=(async()=>{clientClosed=true;try{await raw.end();clients.delete(managed);}catch(error){closeFailures.push(error);throw error;}})()};
|
|
31
|
+
clients.add(managed);
|
|
32
|
+
if(closed&&!transactionAdmission){await managed.close();throw Error('architecture_database_closed');}
|
|
33
|
+
return managed;
|
|
34
|
+
})());
|
|
35
|
+
const connect=()=>connectClient();
|
|
36
|
+
const close=(result={status:'PASS'})=>closing??=(async()=>{
|
|
37
|
+
closed=true;
|
|
38
|
+
await Promise.allSettled([...pending]);
|
|
39
|
+
const outcomes=await Promise.allSettled([...clients].map(client=>client.close()));
|
|
40
|
+
const failures=[...new Set([...closeFailures,...outcomes.filter(outcome=>outcome.status==='rejected').map(outcome=>outcome.reason)])];
|
|
41
|
+
try{await fixture.dispose(failures.length?{status:'FAIL',error:'architecture_database_client_cleanup_failed'}:result);}catch(error){failures.push(error);}
|
|
42
|
+
if(failures.length)throw new AggregateError(failures,'architecture_database_cleanup_failed');
|
|
43
|
+
})();
|
|
44
|
+
const query=async(sql,values=[])=>{assertOpen();return track(fixture.owner.query(sql,[...values]));};
|
|
45
|
+
const transaction=operation=>track((async()=>{
|
|
46
|
+
assertOpen();const client=await connectClient(true);
|
|
47
|
+
try{await client.query('begin');try{const result=await operation(client);await client.query('commit');return result;}catch(error){try{await client.query('rollback');}catch(rollbackError){throw new AggregateError([error,rollbackError],'architecture_transaction_rollback_failed');}throw error;}}
|
|
48
|
+
finally{await client.close();}
|
|
49
|
+
})());
|
|
50
|
+
try{
|
|
51
|
+
const version=String((await query('show server_version')).rows[0]?.server_version??'');
|
|
52
|
+
if(!version.startsWith('16.'))throw Error('architecture_database_version_rejected:'+version);
|
|
53
|
+
if(options.prerequisiteSql?.trim())await transaction(client=>client.query(options.prerequisiteSql));
|
|
54
|
+
await query('create schema architecture_test; create table architecture_test.applied_migrations(name text primary key,sha256 text not null check(sha256 ~ \'^[a-f0-9]{64}$\'));');
|
|
55
|
+
const appliedMigrations=[];
|
|
56
|
+
for(const migration of migrations){
|
|
57
|
+
const sha256=createHash('sha256').update(migration.sql,'utf8').digest('hex');
|
|
58
|
+
await transaction(async client=>{await options.beforeMigration?.({client,migrationName:migration.name});await client.query(migration.sql);await client.query('insert into architecture_test.applied_migrations values($1,$2)',[migration.name,sha256]);});
|
|
59
|
+
appliedMigrations.push({name:migration.name,sha256});
|
|
60
|
+
}
|
|
61
|
+
const url=new URL('postgresql://localhost');url.hostname=fixture.ownerConfig.host;url.port=String(fixture.ownerConfig.port);url.username=fixture.ownerConfig.user;url.password=fixture.ownerConfig.password;url.pathname='/'+fixture.ownerConfig.database;
|
|
62
|
+
return {capabilities:ARCHITECTURE_DATABASE_CAPABILITIES,ownsEnvironment:true,retainsDataDirectory:options.retainEvidence===true||options.evidenceBase!==undefined,target:{connection:{...fixture.ownerConfig}},connectionString:url.toString(),postgresVersion:version,appliedMigrations,paths:fixture.paths,evidence:fixture.evidence,resultFile:fixture.resultFile,connect,query,transaction,close};
|
|
63
|
+
}catch(error){try{await close({status:'FAIL',error:fixture.redact(error.message)});}catch(cleanupError){throw new AggregateError([error,cleanupError],'architecture_database_initialization_cleanup_failed');}throw error;}
|
|
64
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {prepareStaticUiArtifact} from './static-ui-artifact.mjs';
|
|
4
|
+
import {writeReleaseArtifact} from './release-artifact.mjs';
|
|
5
|
+
|
|
6
|
+
const fail=()=>Error('ARTIFACT_BUILD_INPUT_INVALID');
|
|
7
|
+
async function bytes(root,relative,maximum){
|
|
8
|
+
const file=path.join(root,relative),info=await fs.lstat(file);
|
|
9
|
+
if(!info.isFile()||info.isSymbolicLink()||info.nlink!==1||info.size>maximum||await fs.realpath(file)!==file)throw fail();
|
|
10
|
+
const body=await fs.readFile(file);if(body.length>maximum)throw fail();return body;
|
|
11
|
+
}
|
|
12
|
+
async function read(root,relative,maximum=2097152){const body=await bytes(root,relative,maximum);return {body,value:JSON.parse(body)};}
|
|
13
|
+
async function generated(root){
|
|
14
|
+
for(const relative of ['deployment','deployment/generated']){
|
|
15
|
+
const target=path.join(root,relative);try{await fs.mkdir(target);}catch(error){if(error.code!=='EEXIST')throw error;}
|
|
16
|
+
const info=await fs.lstat(target);if(!info.isDirectory()||info.isSymbolicLink()||await fs.realpath(target)!==target)throw fail();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function replace(root,relative,value,owned){
|
|
20
|
+
try{const previous=await read(root,relative);if(!owned(previous.value))throw fail();}catch(error){if(error.code!=='ENOENT')throw error;}
|
|
21
|
+
const body=JSON.stringify(value)+'\n';if(Buffer.byteLength(body)>2097152)throw fail();
|
|
22
|
+
await fs.writeFile(path.join(root,relative),body);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Build-time static receipt; no standalone host, nonce server or provider API. */
|
|
26
|
+
export async function prepareStaticUiBuild({root,directory,hostOrigin}){
|
|
27
|
+
root=await fs.realpath(root);await generated(root);
|
|
28
|
+
const metadata=(await read(root,'package.json',65536)).value,marker=(await read(root,directory+'/build-info.json',4096)).value;
|
|
29
|
+
if(Object.keys(marker).sort().join(',')!=='name,schemaVersion,version'||marker.schemaVersion!==2||marker.name!==metadata.name||marker.version!==metadata.version)throw fail();
|
|
30
|
+
const headers=await prepareStaticUiArtifact({root,directory,hostOrigin,maximumFiles:8192,maximumBytes:134217728});
|
|
31
|
+
const ui=await writeReleaseArtifact({root,entries:[directory],exclude:[directory+'/release-ui.json'],output:'deployment/generated/ui.json',kind:'ui',replace:true,maximumBytes:132120576,maximumFiles:8191});
|
|
32
|
+
const receipt=(await read(root,'deployment/generated/ui.json')).value;
|
|
33
|
+
await replace(root,directory+'/release-ui.json',receipt,old=>old?.schemaVersion===1&&old.kind==='ui'&&Array.isArray(old.files));
|
|
34
|
+
return {status:'STATIC_UI_BUILT',...headers,uiDigest:ui.digest,receiptBytes:ui.bytes};
|
|
35
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
export function assertArtifactDeclarationPaths(consumer,files){
|
|
6
|
+
const root=fs.realpathSync(consumer);
|
|
7
|
+
assert(Array.isArray(files)&&files.length>0&&files.length<=8192,'DECLARATION_SOURCE_LIMIT');
|
|
8
|
+
for(const file of files){const selected=fs.realpathSync(file),relative=path.relative(root,selected);assert(relative&&relative!=='..'&&!relative.startsWith('..'+path.sep)&&!path.isAbsolute(relative),'DECLARATION_SOURCE_OUTSIDE_CONSUMER: '+file);}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Execute this probe through the consumer's module fence and installed compiler. */
|
|
12
|
+
export function writeArtifactDeclarationProbe({consumer,configFile}){
|
|
13
|
+
const root=fs.realpathSync(consumer);
|
|
14
|
+
assert(typeof configFile==='string'&&/^[a-z][a-z0-9.-]{0,79}\.json$/.test(configFile),'DECLARATION_CONFIGURATION');
|
|
15
|
+
const source=`import assert from 'node:assert/strict';import fs from 'node:fs';import path from 'node:path';import ts from 'typescript';
|
|
16
|
+
const assertArtifactDeclarationPaths=${assertArtifactDeclarationPaths.toString()};
|
|
17
|
+
const root=import.meta.dirname,file=path.join(root,${JSON.stringify(configFile)}),loaded=ts.readConfigFile(file,ts.sys.readFile);if(loaded.error)throw Error('DECLARATION_CONFIGURATION');
|
|
18
|
+
const parsed=ts.parseJsonConfigFileContent(loaded.config,ts.sys,root),program=ts.createProgram(parsed.fileNames,parsed.options),diagnostics=[...parsed.errors,...ts.getPreEmitDiagnostics(program)];
|
|
19
|
+
assertArtifactDeclarationPaths(root,program.getSourceFiles().map(source=>source.fileName));
|
|
20
|
+
if(diagnostics.length)throw Error(ts.formatDiagnosticsWithColorAndContext(diagnostics,{getCanonicalFileName:name=>name,getCurrentDirectory:()=>root,getNewLine:()=>'\\n'}));
|
|
21
|
+
console.log(JSON.stringify({status:'PASS',sourceFiles:program.getSourceFiles().length,sourceAccess:false}));
|
|
22
|
+
`;
|
|
23
|
+
const probe=path.join(root,'compile-declarations.mjs');fs.writeFileSync(probe,source,{flag:'wx'});return probe;
|
|
24
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {builtinModules} from 'node:module';
|
|
5
|
+
import {build} from 'vite';
|
|
6
|
+
import {cruise} from 'dependency-cruiser';
|
|
7
|
+
|
|
8
|
+
const escape=value=>value.replace(/[.*+?^${}()|[\]\\]/g,'\\$&');
|
|
9
|
+
function inputs(options){
|
|
10
|
+
assert(options&&typeof options==='object'&&!Array.isArray(options),'EXPLICIT_GRAPH_INPUT_REQUIRED');
|
|
11
|
+
const root=fs.realpathSync(options.root);
|
|
12
|
+
assert.equal(root,path.resolve(options.root),'CONSUMER_GRAPH_ESCAPE');
|
|
13
|
+
const inside=file=>{const relative=path.relative(root,file);assert(relative&&!relative.startsWith('..'+path.sep)&&relative!=='..'&&!path.isAbsolute(relative),'CONSUMER_GRAPH_ESCAPE');return file;};
|
|
14
|
+
const entry=inside(fs.realpathSync(options.entry));assert(fs.statSync(entry).isFile()&&/\.(?:mjs|cjs|js)$/.test(entry),'PUBLISHED_JAVASCRIPT_ENTRY_REQUIRED');
|
|
15
|
+
return{root,entry,inside};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Compile the actual installed UI closure with environment/config discovery disabled. */
|
|
19
|
+
export async function qualifyBrowserBundle(options){
|
|
20
|
+
const {root,entry,inside}=inputs(options),cache=inside(path.resolve(options.cacheDirectory));
|
|
21
|
+
if(fs.existsSync(cache))inside(fs.realpathSync(cache));
|
|
22
|
+
const modules=new Set();
|
|
23
|
+
const output=await build({root,configFile:false,envDir:false,envPrefix:[],publicDir:false,cacheDir:cache,logLevel:'silent',plugins:[{
|
|
24
|
+
name:'published-ui-boundary',enforce:'pre',
|
|
25
|
+
resolveId(source){
|
|
26
|
+
if(source.startsWith('node:')||builtinModules.includes(source)||/^(?:pg(?:-boss)?(?:$|\/)|server-only(?:$|\/)|@supabase\/)/.test(source)||/(?:^|\/)server(?:\.|\/|$)/.test(source))throw Error('FORBIDDEN_DEPENDENCY: '+source);
|
|
27
|
+
},
|
|
28
|
+
load(id){
|
|
29
|
+
if(id.startsWith('\0'))return;
|
|
30
|
+
const file=id.split('?')[0];
|
|
31
|
+
if(path.isAbsolute(file)){inside(file);if(fs.existsSync(file))inside(fs.realpathSync(file));}
|
|
32
|
+
if(/(?:^|\/)server(?:\.|\/|$)/.test(file.replaceAll('\\','/')))throw Error('FORBIDDEN_DEPENDENCY: server module');
|
|
33
|
+
modules.add(id);assert(modules.size<=4096,'BROWSER_MODULE_LIMIT');
|
|
34
|
+
},
|
|
35
|
+
}],build:{write:false,minify:false,sourcemap:false,emptyOutDir:false,lib:{entry,formats:['es'],fileName:'ui'}}});
|
|
36
|
+
const outputs=(Array.isArray(output)?output:[output]).flatMap(value=>value.output??[]);
|
|
37
|
+
let outputBytes=0;const code=[];
|
|
38
|
+
for(const item of outputs){const bytes=item.type==='chunk'?Buffer.from(item.code):typeof item.source==='string'?Buffer.from(item.source):Buffer.from(item.source);outputBytes+=bytes.length;assert(outputBytes<=16*1024**2,'BROWSER_OUTPUT_LIMIT');if(item.type==='chunk')code.push(item.code);}
|
|
39
|
+
assert(outputBytes>0,'BROWSER_OUTPUT_MISSING');
|
|
40
|
+
return{modules:[...modules].sort(),outputBytes,code:code.join('\n')};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Follow owned JavaScript edges; external package boundaries remain visible. */
|
|
44
|
+
export async function qualifyServerGraph(options){
|
|
45
|
+
const {root,entry,inside}=inputs(options),uiEntry=inside(fs.realpathSync(options.uiEntry));
|
|
46
|
+
const uiPath=path.relative(root,uiEntry).replaceAll('\\','/');
|
|
47
|
+
const rules={forbidden:[
|
|
48
|
+
{name:'worker-no-ui',severity:'error',from:{},to:{path:'(?:^|/)(?:react(?:-dom)?|next)(?:/|$)|(?:^|/)ui(?:/|\\.)|^'+escape(uiPath)+'$'}},
|
|
49
|
+
{name:'worker-no-cycle',severity:'error',from:{},to:{circular:true}},
|
|
50
|
+
{name:'worker-no-unresolved',severity:'error',from:{},to:{couldNotResolve:true}},
|
|
51
|
+
{name:'worker-no-consumer-escape',severity:'error',from:{},to:{path:'^\\.\\.(?:/|$)'}},
|
|
52
|
+
],options:{doNotFollow:{dependencyTypes:['npm','npm-dev','npm-peer','npm-optional','npm-bundled']}}};
|
|
53
|
+
const graph=await cruise([path.relative(root,entry)],{...rules.options,baseDir:root,validate:true,ruleSet:rules,outputType:'json',preserveSymlinks:false,enhancedResolveOptions:{exportsFields:['exports'],conditionNames:['import','node','default'],extensions:['.js','.mjs','.cjs','.json']}},{bustTheCache:true});
|
|
54
|
+
assert(graph.output,'SERVER_GRAPH_OUTPUT_REQUIRED');
|
|
55
|
+
if(typeof graph.output==='string')assert(Buffer.byteLength(graph.output)<=16*1024**2,'SERVER_GRAPH_OUTPUT_LIMIT');
|
|
56
|
+
const output=typeof graph.output==='string'?JSON.parse(graph.output):graph.output;
|
|
57
|
+
assert(output.modules.length>0&&output.modules.length<=8192,'SERVER_MODULE_LIMIT');
|
|
58
|
+
const violations=output.summary.violations;
|
|
59
|
+
assert.equal(violations.length,0,'FORBIDDEN_DEPENDENCY: '+JSON.stringify(violations));
|
|
60
|
+
return{modules:output.modules,violations};
|
|
61
|
+
}
|