@bleedingdev/modern-js-ultramodern-create 3.9.3-ultramodern.1 → 3.9.3-ultramodern.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.
Files changed (30) hide show
  1. package/dist/cjs/ultramodern-workspace/add-vertical/shell-files.cjs +2 -7
  2. package/dist/cjs/ultramodern-workspace/api/client.cjs +2 -37
  3. package/dist/cjs/ultramodern-workspace/api.cjs +0 -3
  4. package/dist/cjs/ultramodern-workspace/native-app.cjs +0 -2
  5. package/dist/cjs/ultramodern-workspace/package-json.cjs +1 -3
  6. package/dist/cjs/ultramodern-workspace/validation/architecture.cjs +24 -11
  7. package/dist/cjs/ultramodern-workspace/validation/native-shell-runtime.cjs +134 -0
  8. package/dist/cjs/ultramodern-workspace/write-app.cjs +1 -3
  9. package/dist/esm/ultramodern-workspace/add-vertical/shell-files.js +3 -8
  10. package/dist/esm/ultramodern-workspace/api/client.js +4 -36
  11. package/dist/esm/ultramodern-workspace/api.js +1 -1
  12. package/dist/esm/ultramodern-workspace/native-app.js +0 -2
  13. package/dist/esm/ultramodern-workspace/package-json.js +1 -3
  14. package/dist/esm/ultramodern-workspace/validation/architecture.js +24 -11
  15. package/dist/esm/ultramodern-workspace/validation/native-shell-runtime.js +96 -0
  16. package/dist/esm/ultramodern-workspace/write-app.js +1 -3
  17. package/dist/esm-node/ultramodern-workspace/add-vertical/shell-files.js +3 -8
  18. package/dist/esm-node/ultramodern-workspace/api/client.js +4 -36
  19. package/dist/esm-node/ultramodern-workspace/api.js +1 -1
  20. package/dist/esm-node/ultramodern-workspace/native-app.js +0 -2
  21. package/dist/esm-node/ultramodern-workspace/package-json.js +1 -3
  22. package/dist/esm-node/ultramodern-workspace/validation/architecture.js +24 -11
  23. package/dist/esm-node/ultramodern-workspace/validation/native-shell-runtime.js +97 -0
  24. package/dist/esm-node/ultramodern-workspace/write-app.js +1 -3
  25. package/dist/types/ultramodern-workspace/api/client.d.ts +1 -2
  26. package/dist/types/ultramodern-workspace/api.d.ts +1 -1
  27. package/dist/types/ultramodern-workspace/validation/native-shell-runtime.d.ts +19 -0
  28. package/package.json +18 -18
  29. package/release-cohort.json +51 -51
  30. package/templates/workspace-scripts/proof-workerd-ssr.mjs +371 -38
@@ -7,6 +7,15 @@ import path from "node:path";
7
7
  import { parseEnv } from "node:util";
8
8
  import { convertV4MiniflareOptions, Log, LogLevel, Miniflare } from "miniflare";
9
9
 
10
+ // Runs every built Worker in workerd through Miniflare and writes the report
11
+ // below. Inputs:
12
+ // - ULTRAMODERN_WORKSPACE_ROOT: workspace with topology/ and the report
13
+ // (default: the current directory).
14
+ // - ULTRAMODERN_WORKERD_ARTIFACT_ROOT: root holding each app's built
15
+ // `<topology path>/.output` (default: the workspace root).
16
+ // - ULTRAMODERN_WORKERD_PROOF_FIXTURE: optional JSON runtime data; see
17
+ // validateWorkerdProofFixture for its format.
18
+ // - ULTRAMODERN_KEEP_WORKERD=1: keep the Workers serving on their local ports.
10
19
  const reportRelativePath = ".codex/reports/cloudflare-workerd-ssr/composition-proof.json";
11
20
  // Mirrors the public website quality gate default for server-rendered HTML.
12
21
  const defaultSsrHtmlMaxBytes = 250_000;
@@ -109,13 +118,15 @@ const createWorkerModules = (outputRoot, main) => {
109
118
  }));
110
119
  };
111
120
 
112
- const readExecutionEnvelope = async (appId, outputRoot, expectedUnitId) => {
121
+ const readExecutionEnvelope = async (appId, appRoot, outputRoot, expectedUnitId) => {
113
122
  const envelopePath = path.join(
114
123
  outputRoot,
115
124
  "release/microvertical-release-envelope.json",
116
125
  );
117
126
  assert(fs.existsSync(envelopePath), `${appId} executed .output release envelope is missing`);
118
- const appRequire = createRequire(path.join(outputRoot, "../package.json"));
127
+ // The verifier is the workspace app's own toolchain, wherever its built
128
+ // artifacts were placed.
129
+ const appRequire = createRequire(path.join(appRoot, "package.json"));
119
130
  const sdkRequire = createRequire(
120
131
  appRequire.resolve("@modern-js/ultramodern-app-tools"),
121
132
  );
@@ -271,14 +282,34 @@ const readDevVars = (outputRoot) => {
271
282
  return fs.existsSync(devVarsPath) ? parseEnv(fs.readFileSync(devVarsPath, "utf8")) : {};
272
283
  };
273
284
 
274
- const loadApps = async (workspaceRoot, topology, overlay) => {
285
+ // A topology path names one app directory below the selected root. Built
286
+ // artifacts may live in a separate root (ULTRAMODERN_WORKERD_ARTIFACT_ROOT),
287
+ // but a topology path must never select output outside it.
288
+ export const resolveAppOutputRoot = (artifactRoot, appId, appPath) => {
289
+ assert(typeof appPath === "string" && appPath.length > 0, `${appId} topology path is missing`);
290
+ const segments = normalizePath(appPath).split("/");
291
+ const outputRoot = path.resolve(artifactRoot, appPath, ".output");
292
+ const relativeOutput = path.relative(artifactRoot, outputRoot);
293
+ assert(
294
+ !path.isAbsolute(appPath) &&
295
+ !path.posix.isAbsolute(normalizePath(appPath)) &&
296
+ !segments.includes("..") &&
297
+ relativeOutput !== ".output" &&
298
+ relativeOutput !== `..` &&
299
+ !relativeOutput.startsWith(`..${path.sep}`) &&
300
+ !path.isAbsolute(relativeOutput),
301
+ `${appId} topology path ${appPath} escapes the selected artifact root`,
302
+ );
303
+ return outputRoot;
304
+ };
305
+
306
+ const loadApps = async (workspaceRoot, artifactRoot, topology, overlay) => {
275
307
  const { plans, rawApps } = planWorkerdSsrProof(topology);
276
308
  return Promise.all(rawApps.map(async (rawApp, index) => {
277
309
  const plan = plans[index];
278
310
  const hasApiSurface = plan.kind === "vertical" && rawApp.surfaceProfile !== "ui-only";
279
311
  const appPath = rawApp.path;
280
- assert(typeof appPath === "string" && appPath.length > 0, `${plan.id} topology path is missing`);
281
- const outputRoot = path.join(workspaceRoot, appPath, ".output");
312
+ const outputRoot = resolveAppOutputRoot(artifactRoot, plan.id, appPath);
282
313
  const wranglerPath = path.join(outputRoot, "wrangler.json");
283
314
  assert(
284
315
  fs.existsSync(wranglerPath),
@@ -303,6 +334,7 @@ const loadApps = async (workspaceRoot, topology, overlay) => {
303
334
  // and the envelope surfaces must match the declared application profile.
304
335
  const executedEnvelope = await readExecutionEnvelope(
305
336
  plan.id,
337
+ path.join(workspaceRoot, appPath),
306
338
  outputRoot,
307
339
  rawApp.deliveryUnit?.unitId,
308
340
  );
@@ -371,7 +403,176 @@ const createLocalHyperdrives = (app) => {
371
403
  );
372
404
  };
373
405
 
374
- const createWorkerOptions = (app, workspaceRoot, extra = {}) => {
406
+ const emptyWorkerdProofFixture = Object.freeze({
407
+ schemaVersion: 1,
408
+ kvSeeds: [],
409
+ ownerTargets: [],
410
+ shellApiTargets: [],
411
+ });
412
+ const httpHeaderName = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/u;
413
+
414
+ /**
415
+ * Validate the runtime data a workspace supplies through
416
+ * ULTRAMODERN_WORKERD_PROOF_FIXTURE (schemaVersion 1):
417
+ *
418
+ * - `kvSeeds[]`: `{ appId, binding, entries: [{ key, value }] }`. Each seed
419
+ * names a `kv_namespaces` binding of an executed Worker's wrangler.json; the
420
+ * string entries are written to that native namespace before any request.
421
+ * Workers sharing a namespace id share its entries, so seeds must agree.
422
+ * - `ownerTargets[]`: `{ appId, baseUrl }`. A MicroVertical's approved HTTPS
423
+ * origin (`https://host[:port]/`). A Worker's outbound fetch to that origin
424
+ * is served by the owner's Worker; every other origin stays disabled.
425
+ * - `shellApiTargets[]`: `{ shellId, appId, routePrefix, headers }`. The shell
426
+ * mounts the owner API under `routePrefix`; each API smoke check is sent to
427
+ * the shell at `routePrefix + route` with `headers`, and must reach the
428
+ * owner's `baseUrl + route` and return the owner's status, content type and
429
+ * body unchanged. Redirects are not followed. An API app without a Shell API
430
+ * target is proven through the shell's service binding.
431
+ *
432
+ * The proof only executes this data; it never derives it from topology.
433
+ */
434
+ export const validateWorkerdProofFixture = (fixture, apps) => {
435
+ assert(
436
+ fixture?.schemaVersion === 1 &&
437
+ Array.isArray(fixture.kvSeeds) &&
438
+ Array.isArray(fixture.ownerTargets) &&
439
+ Array.isArray(fixture.shellApiTargets),
440
+ "Invalid Workerd proof fixture",
441
+ );
442
+ const appsById = new Map(apps.map((app) => [app.id, app]));
443
+ const seededKeys = new Set();
444
+ const sharedValues = new Map();
445
+ for (const seed of fixture.kvSeeds) {
446
+ const app = appsById.get(seed?.appId);
447
+ const namespace = Array.isArray(app?.wrangler.kv_namespaces)
448
+ ? app.wrangler.kv_namespaces.find((candidate) => candidate?.binding === seed.binding)
449
+ : undefined;
450
+ assert(
451
+ typeof seed?.binding === "string" && namespace && Array.isArray(seed.entries),
452
+ "Workerd proof KV seed must name an executed Worker's declared kv_namespaces binding",
453
+ );
454
+ for (const entry of seed.entries) {
455
+ const seededKey = JSON.stringify([seed.appId, seed.binding, entry?.key]);
456
+ assert(
457
+ typeof entry?.key === "string" &&
458
+ entry.key.length > 0 &&
459
+ typeof entry.value === "string" &&
460
+ !seededKeys.has(seededKey),
461
+ "Workerd proof KV seeds must contain unique string keys with string values",
462
+ );
463
+ seededKeys.add(seededKey);
464
+ const sharedKey = JSON.stringify([namespace.id, entry.key]);
465
+ assert(
466
+ !sharedValues.has(sharedKey) || sharedValues.get(sharedKey) === entry.value,
467
+ "Workerd proof KV seeds must not conflict in a shared namespace",
468
+ );
469
+ sharedValues.set(sharedKey, entry.value);
470
+ }
471
+ }
472
+ const ownerOrigins = new Set();
473
+ const ownerIds = new Set();
474
+ for (const target of fixture.ownerTargets) {
475
+ const app = appsById.get(target?.appId);
476
+ const url = typeof target?.baseUrl === "string" ? URL.parse(target.baseUrl) : null;
477
+ assert(
478
+ app?.kind === "vertical" &&
479
+ url?.protocol === "https:" &&
480
+ target.baseUrl === `${url.origin}/` &&
481
+ !ownerOrigins.has(url.origin) &&
482
+ !ownerIds.has(app.id),
483
+ "Workerd proof owner targets must be unique executed MicroVerticals at canonical HTTPS origins",
484
+ );
485
+ ownerOrigins.add(url.origin);
486
+ ownerIds.add(app.id);
487
+ }
488
+ const mounts = new Set();
489
+ for (const target of fixture.shellApiTargets) {
490
+ const shell = appsById.get(target?.shellId);
491
+ const app = appsById.get(target?.appId);
492
+ const mount = JSON.stringify([target?.shellId, target?.appId]);
493
+ const { routePrefix, headers } = target ?? {};
494
+ assert(
495
+ shell?.kind === "shell" &&
496
+ app?.hasApiSurface === true &&
497
+ ownerIds.has(app.id) &&
498
+ typeof routePrefix === "string" &&
499
+ routePrefix.startsWith("/") &&
500
+ !routePrefix.endsWith("/") &&
501
+ !/[?#\\]|%(?:2f|5c)/iu.test(routePrefix) &&
502
+ !routePrefix.split("/").some((segment) => segment === "." || segment === "..") &&
503
+ headers !== null &&
504
+ typeof headers === "object" &&
505
+ !Array.isArray(headers) &&
506
+ Object.entries(headers).every(
507
+ ([name, value]) =>
508
+ httpHeaderName.test(name) && typeof value === "string" && !/[\r\n]/u.test(value),
509
+ ) &&
510
+ !mounts.has(mount),
511
+ "Workerd proof Shell API targets must name one approved owner, an explicit mount and string headers",
512
+ );
513
+ mounts.add(mount);
514
+ }
515
+ return fixture;
516
+ };
517
+
518
+ const readWorkerdProofFixture = (apps) => {
519
+ const location = process.env.ULTRAMODERN_WORKERD_PROOF_FIXTURE;
520
+ return location === undefined || location === ""
521
+ ? emptyWorkerdProofFixture
522
+ : validateWorkerdProofFixture(readJson(path.resolve(location)), apps);
523
+ };
524
+
525
+ // Wrangler's kv_namespaces binding -> namespace id, as `wrangler dev` binds
526
+ // local KV storage.
527
+ const createKvNamespaces = (app) => {
528
+ const namespaces = app.wrangler.kv_namespaces ?? [];
529
+ assert(Array.isArray(namespaces), `${app.id} wrangler kv_namespaces must be an array`);
530
+ return Object.fromEntries(
531
+ namespaces.map((namespace) => {
532
+ assert(
533
+ typeof namespace?.binding === "string" &&
534
+ namespace.binding.length > 0 &&
535
+ typeof namespace.id === "string" &&
536
+ namespace.id.length > 0,
537
+ `${app.id} has an invalid KV namespace binding`,
538
+ );
539
+ return [namespace.binding, namespace.id];
540
+ }),
541
+ );
542
+ };
543
+
544
+ // Write fixture KV entries into every namespace the runtime's Workers bind.
545
+ // Workers bound to one namespace id share storage, so each id is seeded once.
546
+ const seedWorkerdProofKv = async (miniflare, runtimeApps, apps, fixture) => {
547
+ const entriesByNamespace = new Map();
548
+ for (const seed of fixture.kvSeeds) {
549
+ const owner = apps.find((candidate) => candidate.id === seed.appId);
550
+ const { id } = owner.wrangler.kv_namespaces.find(
551
+ (namespace) => namespace.binding === seed.binding,
552
+ );
553
+ const entries = entriesByNamespace.get(id) ?? new Map();
554
+ for (const entry of seed.entries) entries.set(entry.key, entry.value);
555
+ entriesByNamespace.set(id, entries);
556
+ }
557
+ const seeded = new Set();
558
+ for (const app of runtimeApps) {
559
+ for (const { binding, id } of app.wrangler.kv_namespaces ?? []) {
560
+ const entries = entriesByNamespace.get(id);
561
+ if (entries === undefined || seeded.has(id)) continue;
562
+ const namespace = await miniflare.getKVNamespace(binding, workerName(app));
563
+ for (const [key, value] of entries) {
564
+ await namespace.put(key, value);
565
+ assert(
566
+ (await namespace.get(key)) === value,
567
+ `${app.id} KV namespace ${binding} did not keep seeded key ${key}`,
568
+ );
569
+ }
570
+ seeded.add(id);
571
+ }
572
+ }
573
+ };
574
+
575
+ const createWorkerOptions = (app, artifactRoot, extra = {}) => {
375
576
  const main = typeof app.wrangler.main === "string" ? app.wrangler.main : "server/index.mjs";
376
577
  const assets =
377
578
  app.wrangler.assets && typeof app.wrangler.assets === "object" ? app.wrangler.assets : {};
@@ -415,11 +616,11 @@ const createWorkerOptions = (app, workspaceRoot, extra = {}) => {
415
616
  appId: app.id,
416
617
  apiBackend,
417
618
  envelopeDigest: app.envelope.envelopeDigest,
418
- envelopePath: normalizePath(path.relative(workspaceRoot, app.envelopePath)),
619
+ envelopePath: normalizePath(path.relative(artifactRoot, app.envelopePath)),
419
620
  identity: app.envelope.identity,
420
621
  main: mainLogicalPath,
421
622
  modules: boundModules,
422
- modulesRoot: normalizePath(path.relative(workspaceRoot, app.outputRoot)),
623
+ modulesRoot: normalizePath(path.relative(artifactRoot, app.outputRoot)),
423
624
  worker: workerName(app),
424
625
  },
425
626
  name: workerName(app),
@@ -429,6 +630,7 @@ const createWorkerOptions = (app, workspaceRoot, extra = {}) => {
429
630
  compatibilityFlags: app.wrangler.compatibility_flags,
430
631
  bindings: { ...app.wrangler.vars, ...app.devVars },
431
632
  hyperdrives: createLocalHyperdrives(app),
633
+ kvNamespaces: createKvNamespaces(app),
432
634
  assets: {
433
635
  binding: typeof assets.binding === "string" ? assets.binding : "ASSETS",
434
636
  directory: path.resolve(app.outputRoot, directory),
@@ -467,15 +669,39 @@ const findReleaseMarkers = (value, markers = []) => {
467
669
  const jsonPathValue = (value, key) =>
468
670
  String(key).split(".").reduce((current, segment) => current?.[segment], value);
469
671
 
470
- const responseEvidence = async (app, response, check) => {
672
+ // A bounded summary of an RFC 9457-style problem body, or an Effect tagged error.
673
+ const problemSummary = (body) => {
674
+ const problem = {};
675
+ for (const key of ["type", "title", "code", "_tag"]) {
676
+ if (typeof body?.[key] === "string") problem[key] = body[key].slice(0, 200);
677
+ }
678
+ if (Number.isFinite(body?.status)) problem.status = body.status;
679
+ return problem;
680
+ };
681
+
682
+ const responseEvidence = async (app, response, check, phase) => {
471
683
  const bytes = Buffer.from(await response.arrayBuffer());
684
+ const contentType = response.headers.get("content-type");
472
685
  let body;
686
+ let parseError;
473
687
  try {
474
688
  body = JSON.parse(bytes.toString("utf8"));
475
689
  } catch (error) {
476
- throw new Error(`${app.id} API response is not JSON: ${error.message}`);
690
+ parseError = error;
691
+ }
692
+ assert(
693
+ response.ok,
694
+ `${app.id} ${phase} API response returned HTTP ${response.status}: ${JSON.stringify({
695
+ phase,
696
+ status: response.status,
697
+ contentType,
698
+ sha256: sha256(bytes),
699
+ problem: problemSummary(body),
700
+ })}`,
701
+ );
702
+ if (parseError !== undefined) {
703
+ throw new Error(`${app.id} ${phase} API response is not JSON: ${parseError.message}`);
477
704
  }
478
- assert(response.ok, `${app.id} API response returned HTTP ${response.status}`);
479
705
  let marker;
480
706
  if (app.apiProtocol === "rpc") {
481
707
  assert(
@@ -504,6 +730,7 @@ const responseEvidence = async (app, response, check) => {
504
730
  return {
505
731
  bodyBase64: bytes.toString("base64"),
506
732
  byteLength: bytes.byteLength,
733
+ contentType,
507
734
  ...(marker ? { releaseMarker: marker } : {}),
508
735
  sha256: sha256(bytes),
509
736
  status: response.status,
@@ -537,7 +764,13 @@ const resolveApiSmokeChecks = (app, shell) => {
537
764
  return [...uniqueChecks.values()];
538
765
  };
539
766
 
540
- const runApiProofs = async (apps, miniflare, shell, executionByAppId) => {
767
+ const responseSummary = ({ contentType, sha256: digest, status }) => ({
768
+ contentType,
769
+ sha256: digest,
770
+ status,
771
+ });
772
+
773
+ const runApiProofs = async (apps, miniflare, shell, executionByAppId, fixture, recorders) => {
541
774
  const results = [];
542
775
  for (const app of apps.filter((candidate) => candidate.hasApiSurface)) {
543
776
  const jsonSmokeChecks = resolveApiSmokeChecks(app, shell);
@@ -545,17 +778,26 @@ const runApiProofs = async (apps, miniflare, shell, executionByAppId) => {
545
778
  jsonSmokeChecks.length > 0,
546
779
  `${app.id} has no real Cloudflare API smoke check`,
547
780
  );
548
- const binding = (shell.wrangler.services ?? []).find(
549
- (candidate) => candidate.service === workerName(app),
781
+ // The shell reaches an owner API through the fixture's explicit HTTPS
782
+ // mount, or else through its declared service binding.
783
+ const shellTarget = fixture.shellApiTargets.find(
784
+ (candidate) => candidate.shellId === shell.id && candidate.appId === app.id,
550
785
  );
786
+ const ownerTarget = fixture.ownerTargets.find((candidate) => candidate.appId === app.id);
787
+ const binding = shellTarget
788
+ ? undefined
789
+ : (shell.wrangler.services ?? []).find(
790
+ (candidate) => candidate.service === workerName(app),
791
+ );
551
792
  assert(
552
- binding || (app.apiOnly && !shell.verticalRefs.includes(app.id)),
553
- `${shell.id} has no service binding for ${app.id}`,
793
+ shellTarget || binding || (app.apiOnly && !shell.verticalRefs.includes(app.id)),
794
+ `${shell.id} has no service binding or Shell API target for ${app.id}`,
554
795
  );
555
796
  for (const check of jsonSmokeChecks) {
556
797
  const method = String(check.method ?? "GET").toUpperCase();
557
798
  const headers = {};
558
- const init = { method, headers };
799
+ // A redirect is the response under proof, never a hop to follow.
800
+ const init = { method, headers, redirect: "manual" };
559
801
  if (check.body !== undefined) {
560
802
  headers["content-type"] = "application/json";
561
803
  init.body = JSON.stringify(check.body);
@@ -566,21 +808,45 @@ const runApiProofs = async (apps, miniflare, shell, executionByAppId) => {
566
808
  await miniflare.getWorker(workerName(app))
567
809
  ).fetch(`https://${workerName(app)}.invalid${check.route}`, init),
568
810
  check,
811
+ "direct",
569
812
  );
570
- const throughShell = binding
813
+ const outboundRequestStart = recorders.outboundRequests.length;
814
+ const shellRoute = shellTarget ? `${shellTarget.routePrefix}${check.route}` : check.route;
815
+ const throughShell = shellTarget || binding
571
816
  ? await responseEvidence(
572
817
  app,
573
- await miniflare.dispatchFetch(
574
- `https://${workerName(shell)}.invalid${check.route}`,
575
- init,
576
- ),
818
+ await miniflare.dispatchFetch(`https://${workerName(shell)}.invalid${shellRoute}`, {
819
+ ...init,
820
+ headers: { ...headers, ...shellTarget?.headers },
821
+ }),
577
822
  check,
823
+ "through-shell",
578
824
  )
579
825
  : undefined;
580
826
  if (throughShell) {
581
827
  assert(
582
- direct.sha256 === throughShell.sha256,
583
- `${app.id} direct and service-binding API responses differ`,
828
+ direct.status === throughShell.status &&
829
+ direct.sha256 === throughShell.sha256 &&
830
+ direct.contentType === throughShell.contentType,
831
+ `${app.id} direct and through-shell API responses differ: ${JSON.stringify({
832
+ direct: responseSummary(direct),
833
+ throughShell: responseSummary(throughShell),
834
+ })}`,
835
+ );
836
+ }
837
+ const outboundRequests = recorders.outboundRequests.slice(outboundRequestStart);
838
+ if (shellTarget) {
839
+ const ownerUrl = new URL(check.route, ownerTarget.baseUrl).href;
840
+ assert(
841
+ outboundRequests.some(
842
+ (request) =>
843
+ request.callerId === shell.id &&
844
+ request.targetAppId === app.id &&
845
+ request.url === ownerUrl &&
846
+ request.method === method &&
847
+ request.response?.status === throughShell.status,
848
+ ),
849
+ `${app.id} Shell API proof did not reach its approved HTTPS owner at ${ownerUrl}: ${JSON.stringify(outboundRequests)}`,
584
850
  );
585
851
  }
586
852
  const target = {
@@ -591,9 +857,16 @@ const runApiProofs = async (apps, miniflare, shell, executionByAppId) => {
591
857
  results.push({
592
858
  appId: app.id,
593
859
  shellId: shell.id,
594
- ...(binding
595
- ? { binding: binding.binding, bindingTarget: target, throughShell }
596
- : { directTarget: target }),
860
+ ...(shellTarget
861
+ ? {
862
+ httpsTarget: { ...target, baseUrl: ownerTarget.baseUrl },
863
+ outboundRequests,
864
+ shellRoute,
865
+ throughShell,
866
+ }
867
+ : binding
868
+ ? { binding: binding.binding, bindingTarget: target, throughShell }
869
+ : { directTarget: target }),
597
870
  direct,
598
871
  id: check.id,
599
872
  method,
@@ -631,6 +904,7 @@ const startWorkerdTargetServers = async (
631
904
  miniflare,
632
905
  failedServices,
633
906
  workerConfigurations,
907
+ fixture,
634
908
  ) => {
635
909
  const servers = [];
636
910
  const isolatedVerticalRuntimes = [];
@@ -643,7 +917,13 @@ const startWorkerdTargetServers = async (
643
917
  );
644
918
  const runtime =
645
919
  app.kind === "vertical"
646
- ? createIsolatedRuntime(workerConfigurations[index], new ProofLog())
920
+ ? await createIsolatedRuntime(
921
+ workerConfigurations[index],
922
+ new ProofLog(),
923
+ app,
924
+ apps,
925
+ fixture,
926
+ )
647
927
  : miniflare;
648
928
  if (runtime !== miniflare) {
649
929
  isolatedVerticalRuntimes.push(runtime);
@@ -795,14 +1075,23 @@ const decodeDistributedSsrFragmentRequest = (request) => {
795
1075
  // instance. Keep the shell composition runtime intact, but give every directly
796
1076
  // requested MicroVertical its own runtime so its static assets and MF manifest
797
1077
  // cannot resolve from a sibling Worker. Its service bindings still resolve
798
- // through the shared composition runtime.
799
- const createIsolatedRuntime = (workerOptions, log) =>
800
- new Miniflare(
1078
+ // through the shared composition runtime. Its KV namespaces are its own, so
1079
+ // they receive the fixture seeds again.
1080
+ const createIsolatedRuntime = async (workerOptions, log, app, apps, fixture) => {
1081
+ const runtime = new Miniflare(
801
1082
  convertV4MiniflareOptions({
802
1083
  log,
803
1084
  workers: [workerOptions],
804
1085
  }),
805
1086
  );
1087
+ try {
1088
+ await seedWorkerdProofKv(runtime, [app], apps, fixture);
1089
+ return runtime;
1090
+ } catch (error) {
1091
+ await runtime.dispose();
1092
+ throw error;
1093
+ }
1094
+ };
806
1095
 
807
1096
  const createServiceBindings = (
808
1097
  caller,
@@ -974,15 +1263,26 @@ const writeReport = (reportPath, report) => {
974
1263
 
975
1264
  const main = async () => {
976
1265
  const workspaceRoot = path.resolve(process.env.ULTRAMODERN_WORKSPACE_ROOT ?? process.cwd());
1266
+ // Built `.output` directories may live outside the workspace, for example
1267
+ // when a release job proves downloaded artifacts. Topology still comes from
1268
+ // the workspace.
1269
+ const artifactRoot = path.resolve(
1270
+ process.env.ULTRAMODERN_WORKERD_ARTIFACT_ROOT || workspaceRoot,
1271
+ );
977
1272
  const reportPath = path.join(workspaceRoot, reportRelativePath);
978
1273
  const keepWorkerd = process.env.ULTRAMODERN_KEEP_WORKERD === "1";
979
1274
  const apps = await loadApps(
980
1275
  workspaceRoot,
1276
+ artifactRoot,
981
1277
  readJson(path.join(workspaceRoot, "topology/reference-topology.json")),
982
1278
  readJson(path.join(workspaceRoot, "topology/local-overlays/development.json")),
983
1279
  );
984
1280
  const shells = apps.filter((app) => app.kind === "shell");
985
1281
  assert(!keepWorkerd || shells.length === 1, "Browser workerd proof requires exactly one shell");
1282
+ const fixture = readWorkerdProofFixture(apps);
1283
+ const ownerTargetsByOrigin = new Map(
1284
+ fixture.ownerTargets.map((target) => [new URL(target.baseUrl).origin, target]),
1285
+ );
986
1286
 
987
1287
  const recorders = {
988
1288
  apiBindingRequests: [],
@@ -992,14 +1292,39 @@ const main = async () => {
992
1292
  const failedServices = new Set();
993
1293
  const composition = {};
994
1294
  const workerConfigurations = apps.map((app) =>
995
- createWorkerOptions(app, workspaceRoot, {
1295
+ createWorkerOptions(app, artifactRoot, {
996
1296
  serviceBindings: createServiceBindings(app, { ...recorders, composition, failedServices }),
1297
+ // The network stays disabled except for the fixture's approved HTTPS
1298
+ // owner origins, which are served by the owner's own Worker.
997
1299
  async outboundService(request) {
998
1300
  const requestUrl = new URL(request.url);
999
- recorders.outboundRequests.push({ callerId: app.id, url: requestUrl.href });
1000
- return new Response("External network disabled by SSR proof", {
1001
- status: 502,
1002
- });
1301
+ const outboundRequest = {
1302
+ callerId: app.id,
1303
+ method: request.method,
1304
+ requestBody: {
1305
+ contentLength: request.headers.get("content-length"),
1306
+ contentType: request.headers.get("content-type"),
1307
+ present: request.body !== null,
1308
+ },
1309
+ url: requestUrl.href,
1310
+ };
1311
+ recorders.outboundRequests.push(outboundRequest);
1312
+ const target = ownerTargetsByOrigin.get(requestUrl.origin);
1313
+ const owner = apps.find((candidate) => candidate.id === target?.appId);
1314
+ if (owner === undefined || failedServices.has(workerName(owner))) {
1315
+ return new Response("External network disabled by SSR proof", {
1316
+ status: 502,
1317
+ });
1318
+ }
1319
+ outboundRequest.targetAppId = owner.id;
1320
+ const response = await (
1321
+ await composition.miniflare.getWorker(workerName(owner))
1322
+ ).fetch(request);
1323
+ outboundRequest.response = {
1324
+ contentType: response.headers.get("content-type"),
1325
+ status: response.status,
1326
+ };
1327
+ return response;
1003
1328
  },
1004
1329
  }),
1005
1330
  );
@@ -1019,6 +1344,7 @@ const main = async () => {
1019
1344
  const report = { executions, apiProofs: [], proofs: [], verticalProofs: [] };
1020
1345
 
1021
1346
  try {
1347
+ await seedWorkerdProofKv(miniflare, apps, apps, fixture);
1022
1348
  for (const shell of shells) {
1023
1349
  // Shell routes compose declared server-rendered boundaries through the
1024
1350
  // shell's entry Worker exactly as a browser request would.
@@ -1054,7 +1380,7 @@ const main = async () => {
1054
1380
  );
1055
1381
  }
1056
1382
  report.apiProofs.push(
1057
- ...(await runApiProofs(apps, miniflare, shell, executionByAppId)),
1383
+ ...(await runApiProofs(apps, miniflare, shell, executionByAppId, fixture, recorders)),
1058
1384
  );
1059
1385
  }
1060
1386
 
@@ -1065,7 +1391,13 @@ const main = async () => {
1065
1391
  continue;
1066
1392
  }
1067
1393
  const runtimeLog = new ProofLog();
1068
- const runtime = createIsolatedRuntime(workers[index], runtimeLog);
1394
+ const runtime = await createIsolatedRuntime(
1395
+ workers[index],
1396
+ runtimeLog,
1397
+ vertical,
1398
+ apps,
1399
+ fixture,
1400
+ );
1069
1401
  try {
1070
1402
  for (const route of vertical.ssrRoutes) {
1071
1403
  report.verticalProofs.push({
@@ -1092,6 +1424,7 @@ const main = async () => {
1092
1424
  miniflare,
1093
1425
  failedServices,
1094
1426
  workers,
1427
+ fixture,
1095
1428
  );
1096
1429
  console.log(`WORKERD_TARGET_URLS=${JSON.stringify(targetServers.targetUrls)}`);
1097
1430
  console.log(`WORKERD_URL=${targetServers.targetUrls[shells[0].id]}`);