@ultimat3/cli 19.1.3 → 19.3.1

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 (65) hide show
  1. package/CLAUDE.md +125 -8
  2. package/package.json +29 -29
  3. package/src/app-boundaries.ts +11 -2
  4. package/src/app-load.ts +5 -1
  5. package/src/app-openapi.ts +13 -5
  6. package/src/app-permissions.ts +0 -0
  7. package/src/browser-launcher.ts +53 -4
  8. package/src/budgets.ts +60 -7
  9. package/src/cmd-dev.ts +49 -39
  10. package/src/cmd-doctor.ts +61 -23
  11. package/src/cmd-generate.ts +5 -2
  12. package/src/cmd-i18n.ts +10 -3
  13. package/src/cmd-jobs.ts +56 -10
  14. package/src/cmd-shot.ts +3 -1
  15. package/src/cmd-test.ts +15 -10
  16. package/src/db-seed.ts +2 -1
  17. package/src/dev-queue.ts +16 -2
  18. package/src/dev-reload.ts +46 -0
  19. package/src/dev-render.ts +28 -7
  20. package/src/dev-roles.ts +9 -8
  21. package/src/dev-runtime.ts +4 -1
  22. package/src/dev-sync.ts +17 -3
  23. package/src/dev-watch-tree.ts +226 -0
  24. package/src/dev-watch.ts +75 -0
  25. package/src/doctor-offline.ts +122 -0
  26. package/src/duplicate-packages.ts +278 -0
  27. package/src/error-catalog.ts +4 -5
  28. package/src/error-codes.ts +6 -0
  29. package/src/fix-command.ts +40 -1
  30. package/src/fix-path.ts +10 -11
  31. package/src/flag-number.ts +15 -0
  32. package/src/generate-kinds.ts +54 -4
  33. package/src/generate-write.ts +25 -2
  34. package/src/gitignore.ts +145 -0
  35. package/src/hold.ts +50 -17
  36. package/src/i18n-registration.ts +34 -5
  37. package/src/index.ts +3 -1
  38. package/src/island-bundle.ts +123 -10
  39. package/src/island-harness.ts +11 -4
  40. package/src/island-states-load.ts +2 -1
  41. package/src/jobs-driver.ts +4 -1
  42. package/src/mcp-errors.ts +2 -0
  43. package/src/mcp-host.ts +21 -9
  44. package/src/parse.ts +17 -0
  45. package/src/path-segments.ts +14 -0
  46. package/src/prerender.ts +68 -16
  47. package/src/retry-memo.ts +37 -0
  48. package/src/serve.ts +17 -2
  49. package/src/shot-browser.ts +23 -4
  50. package/src/source-files.ts +3 -1
  51. package/src/static-report.ts +21 -1
  52. package/src/style-bundle.ts +124 -0
  53. package/src/style-csp.ts +14 -12
  54. package/src/style-routes.ts +56 -0
  55. package/src/sw-artifacts.ts +84 -12
  56. package/src/templates/admin-page.ts +49 -1
  57. package/src/templates/resource-form-island.ts +13 -3
  58. package/src/templates/scaffold-container.ts +12 -0
  59. package/src/templates/scaffold-repo.ts +13 -2
  60. package/src/test-passes.ts +79 -0
  61. package/src/test-shards.ts +110 -36
  62. package/src/verify-checks.ts +13 -7
  63. package/src/verify-step.ts +4 -4
  64. package/src/verify-tests.ts +33 -8
  65. package/src/web-binding.ts +22 -0
@@ -0,0 +1,56 @@
1
+ // Serving the surface stylesheets. `x dev` and the container mount the same route over the same
2
+ // table, for `island-routes.ts`' reason: the URL is minted by one resolver and baked into the
3
+ // document, so a dev-only path would be a page that paints in `x dev` and renders naked in the
4
+ // image.
5
+
6
+ import type { Route, UltimateRequest } from '@ultimat3/http';
7
+ import { applyCacheHeaders, json } from '@ultimat3/http';
8
+ import type { StyleBundle } from './style-bundle';
9
+ import { STYLE_BASE_PATH } from './style-bundle';
10
+
11
+ /**
12
+ * A getter, not the bundle: `x dev` re-registers island CSS on every watcher tick, and a table
13
+ * captured when the route was mounted would serve the stylesheet as it was at boot for the rest of
14
+ * the session.
15
+ */
16
+ export type StyleSource = () => StyleBundle;
17
+
18
+ /**
19
+ * The URL is content-addressed, so the bytes behind it never change and the answer is
20
+ * `public, max-age=31536000, immutable` — the same headers an island chunk earns, and the whole
21
+ * reason this is a file rather than 157 kB of `<style>` inside a `no-store` document.
22
+ *
23
+ * A miss can only be a document older than this process's registry, which is a fact worth stating
24
+ * rather than a bare 404 whose meaning an agent has to guess.
25
+ */
26
+ export function styleRoutes(source: StyleSource): readonly Route[] {
27
+ return [
28
+ {
29
+ method: 'GET',
30
+ path: `${STYLE_BASE_PATH}/*file`,
31
+ meta: { name: 'assets.style', auth: 'public', tags: ['assets'] },
32
+ handler: (request: UltimateRequest): Response => {
33
+ const chunk = source().chunkAt(request.pathname);
34
+ if (chunk === undefined) {
35
+ return json(
36
+ {
37
+ ok: false,
38
+ error: {
39
+ code: 'X_ROUTE_NOT_FOUND',
40
+ cause: `no surface stylesheet is registered at ${request.pathname} — the document that asked for it was rendered against an older build`,
41
+ // No `x` citation, for `island-routes.ts`' reason: this route is mounted in
42
+ // exactly two places (`cmd-dev.ts`, `serve.ts`) and neither reads `.x/static`.
43
+ fix: 'reload the page — this process serves only the stylesheet its own modules registered, and the document holding this URL came from an earlier build',
44
+ },
45
+ },
46
+ { status: 404 },
47
+ );
48
+ }
49
+ return applyCacheHeaders(
50
+ new Response(chunk.css, { headers: { 'content-type': 'text/css; charset=utf-8' } }),
51
+ { mode: 'immutable' },
52
+ );
53
+ },
54
+ },
55
+ ];
56
+ }
@@ -9,6 +9,7 @@ import type { RouteDescriptor } from '@ultimat3/render';
9
9
  import type { IslandBundle } from './island-bundle';
10
10
  import { msg } from './messages';
11
11
  import type { PwaArtifacts } from './pwa-artifacts';
12
+ import type { StyleBundle } from './style-bundle';
12
13
 
13
14
  /** Root scope, so `/sw.js` and nothing under a directory — `assertScope` refuses the rest. */
14
15
  export const SERVICE_WORKER_PATH = '/sw.js';
@@ -43,15 +44,47 @@ export interface ServiceWorkerInput {
43
44
  readonly buildId: string;
44
45
  readonly routes: readonly RouteDescriptor[];
45
46
  readonly islands: IslandBundle;
47
+ /**
48
+ * The surface stylesheets every document links. Precached beside the island chunks and for the
49
+ * same reason: they are content-addressed and served `immutable`, and a document that reaches
50
+ * the offline fallback with no CSS is a page the visitor cannot read.
51
+ */
52
+ readonly styles: StyleBundle;
53
+ /**
54
+ * What the build RENDERED, keyed by the route path it was rendered for. Optional because only a
55
+ * static export has documents to hash: `x dev` and the container emit the worker at boot, where
56
+ * no page has been built yet, and `buildPrecacheManifest` falls back to the build id for a route
57
+ * this map does not name.
58
+ */
59
+ readonly documents?: ReadonlyMap<string, RenderedDocument>;
60
+ }
61
+
62
+ /**
63
+ * One rendered document, as the precache manifest needs it.
64
+ *
65
+ * `revision` is `contentHash(html)` — `@ultimat3/render`'s own, the function that already stamps
66
+ * an ETag — and never the build id. `precache.ts`' header states the rule and nothing kept it:
67
+ * `pwaRoutes` projected four of `PwaRoute`'s eight fields, so every route entry read
68
+ * `{"url":"/","revision":"build-aaa","bytes":0}` and two deploys of a byte-identical site
69
+ * re-fetched every precached document. The zero was the second half — `DEFAULT_PRECACHE_WARN_BYTES`
70
+ * is a 5 MB budget over a total that could not count one byte of HTML.
71
+ */
72
+ export interface RenderedDocument {
73
+ readonly revision: string;
74
+ readonly bytes: number;
46
75
  }
47
76
 
48
77
  /**
49
78
  * The route table, as the service worker sees it. `api/` is dropped: an API response is a JSON
50
79
  * document whose freshness is the app's business, and precaching one serves a stale answer to a
51
- * client that had a network. Only the four fields `PwaRoute` reads cross — a descriptor carries
52
- * budgets and policy flags that a browser has no use for.
80
+ * client that had a network. Only the fields a browser can act on cross — a descriptor carries
81
+ * budgets and policy flags it has no use for — plus, for a route this build rendered, the content
82
+ * hash and the byte count of the document it produced.
53
83
  */
54
- const pwaRoutes = (routes: readonly RouteDescriptor[]): readonly PwaRoute[] =>
84
+ const pwaRoutes = (
85
+ routes: readonly RouteDescriptor[],
86
+ documents: ReadonlyMap<string, RenderedDocument>,
87
+ ): readonly PwaRoute[] =>
55
88
  // `flatMap` rather than `filter().map()`: the filter's predicate does not narrow `surface` for
56
89
  // the map that follows it, and `PwaRoute` declares the two navigable surfaces only. A cast would
57
90
  // hide the day a fifth surface arrives.
@@ -59,6 +92,8 @@ const pwaRoutes = (routes: readonly RouteDescriptor[]): readonly PwaRoute[] =>
59
92
  // `shared/` is dropped with `api/`, and for a stronger reason: it is not a URL at all — the
60
93
  // surface exists so two routes can import one module, and a browser can never navigate to it.
61
94
  if (route.surface !== 'site' && route.surface !== 'app') return [];
95
+ // A `Map`, so a route path that happens to spell a prototype member cannot answer with one.
96
+ const document = documents.get(route.path);
62
97
  return [
63
98
  {
64
99
  path: route.path,
@@ -66,19 +101,24 @@ const pwaRoutes = (routes: readonly RouteDescriptor[]): readonly PwaRoute[] =>
66
101
  mode: route.mode,
67
102
  offline: route.offline,
68
103
  dynamic: route.dynamic,
104
+ // Absent rather than invented for a route no build rendered — an `ssr` page, or one this
105
+ // pass could not produce. `buildPrecacheManifest` then falls back to the build id, which
106
+ // is the honest answer when there are no bytes to hash.
107
+ ...(document === undefined ? {} : { revision: document.revision, bytes: document.bytes }),
69
108
  },
70
109
  ];
71
110
  });
72
111
 
73
112
  /**
74
- * Every island chunk, precached. They are content-addressed and served `immutable`, so the
75
- * revision IS the URL's hash and a byte-identical chunk across deploys is never re-downloaded.
113
+ * Every island chunk and every surface stylesheet, precached. They are content-addressed and
114
+ * served `immutable`, so the revision IS the URL's hash and a byte-identical asset across deploys
115
+ * is never re-downloaded.
76
116
  *
77
117
  * Sorted by url, because `buildPrecacheManifest` sorts its own entries but the ASSET list is what
78
118
  * decides which of two equal urls wins, and `sw.js` must be byte-identical for identical input.
79
119
  */
80
- const islandAssets = (islands: IslandBundle): readonly PrecacheAsset[] =>
81
- [...islands.chunks]
120
+ const staticAssets = (islands: IslandBundle, styles: StyleBundle): readonly PrecacheAsset[] =>
121
+ [...islands.chunks, ...styles.chunks]
82
122
  .map((chunk) => ({ url: chunk.url, revision: chunk.url, bytes: chunk.bytes }))
83
123
  .sort((a, b) => (a.url < b.url ? -1 : a.url > b.url ? 1 : 0));
84
124
 
@@ -120,27 +160,47 @@ export function serviceWorkerArtifacts(
120
160
  input: ServiceWorkerInput,
121
161
  ): ServiceWorkerArtifacts | undefined {
122
162
  const pwa = input.pwa;
123
- if (pwa.offline.fallback === null) return undefined;
163
+ const head = serviceWorkerHead(pwa);
164
+ const fallback = pwa.offline.fallback;
165
+ // One predicate DECIDES — `serviceWorkerHead`, so a document can never name a script this
166
+ // function then declines to emit — and the `null` check is what NARROWS `fallback` below:
167
+ // TypeScript cannot learn a `string` from the other's answer, and a cast would hide the day the
168
+ // two stop agreeing.
169
+ if (head === undefined || fallback === null) return undefined;
170
+ const documents = input.documents ?? new Map<string, RenderedDocument>();
171
+ // The offline document is the one entry `buildPrecacheManifest` adds ITSELF, as
172
+ // `reason: 'fallback'`, ahead of every route — and `add()` keeps the first entry per url, so its
173
+ // revision is the one that decides. Without this pair it was the build id whatever the build
174
+ // knew, which re-downloaded the single page an offline navigation depends on on every deploy.
175
+ // Absent when this pass did not render the fallback (no route serves it — `x doctor` reports
176
+ // that as `X_PWA_NO_OFFLINE_FALLBACK`), and then `@ultimat3/pwa` falls back to the build id.
177
+ const fallbackDocument = documents.get(fallback);
124
178
  const output = generateServiceWorker(
125
- pwaRoutes(input.routes),
179
+ pwaRoutes(input.routes, documents),
126
180
  {
127
181
  scope: SW_SCOPE,
128
182
  swPath: SERVICE_WORKER_PATH,
183
+ ...(fallbackDocument === undefined
184
+ ? {}
185
+ : {
186
+ offlineFallbackRevision: fallbackDocument.revision,
187
+ offlineFallbackBytes: fallbackDocument.bytes,
188
+ }),
129
189
  offline: {
130
- fallback: pwa.offline.fallback,
190
+ fallback,
131
191
  ...(pwa.offline.image === null ? {} : { image: pwa.offline.image }),
132
192
  ...(pwa.offline.font === null ? {} : { font: pwa.offline.font }),
133
193
  neverCache: pwa.offline.neverCache,
134
194
  },
135
195
  capabilities: { backgroundSync: pwa.backgroundSync, push: pwa.push },
136
- assets: islandAssets(input.islands),
196
+ assets: staticAssets(input.islands, input.styles),
137
197
  },
138
198
  input.buildId,
139
199
  );
140
200
  return {
141
201
  source: output.source,
142
202
  register: registerSource(),
143
- head: `<script src="${SW_REGISTER_PATH}" defer></script>`,
203
+ head,
144
204
  precache: output.precache,
145
205
  // `output.warnings` IS `output.precache.warnings` — the generator returns the manifest's list
146
206
  // verbatim — so it is read once, not twice. The push line is this module's own, and it is the
@@ -152,6 +212,18 @@ export function serviceWorkerArtifacts(
152
212
  };
153
213
  }
154
214
 
215
+ /**
216
+ * The one `<script src>` a document needs, or `undefined` for an app that gets no worker.
217
+ *
218
+ * Separate from `serviceWorkerArtifacts` because the two are wanted at different moments: a static
219
+ * export has to put this tag in every document it renders, and the WORKER cannot be emitted until
220
+ * those documents exist — its precache manifest is built from their content hashes. One predicate
221
+ * for both (`offline.fallback === null` is `generateServiceWorker`'s refusal, spent early), so a
222
+ * document can never name a script the export does not carry.
223
+ */
224
+ export const serviceWorkerHead = (pwa: PwaArtifacts): string | undefined =>
225
+ pwa.offline.fallback === null ? undefined : `<script src="${SW_REGISTER_PATH}" defer></script>`;
226
+
155
227
  /**
156
228
  * `pwa.push: true` with nothing to sign a subscription with. There is no `pwa.vapid` config key
157
229
  * yet, so today this fires for EVERY app that sets the flag — deliberately: a switch that silently
@@ -9,6 +9,7 @@ import { sortedImports } from './imports';
9
9
  import { catalogPath, resolveLocales } from './locales';
10
10
  import type { GeneratedFile } from './naming';
11
11
  import { camel, kebab, pascal } from './naming';
12
+ import { LINE_WIDTH } from './wrap';
12
13
 
13
14
  /** Where an admin lives when the caller does not say. `x new` scaffolds this layout. */
14
15
  export const DEFAULT_ADMIN_PAGE_DIR = 'apps/admin/src/pages';
@@ -58,9 +59,45 @@ const catalogImport = (module: string | undefined): string =>
58
59
  const pageImports = (module: string | undefined): string =>
59
60
  sortedImports([
60
61
  `import type { AdminCustomPage, AdminPageProps } from '@ultimat3/admin';`,
62
+ `import { definePermissions } from '@ultimat3/policy';`,
61
63
  catalogImport(module),
62
64
  ]);
63
65
 
66
+ /**
67
+ * The page DECLARES the permission it requires, in both registries that decide about it.
68
+ *
69
+ * `x g admin:page ops` emitted `permissions: ['ops:read']` and nothing anywhere declared
70
+ * `ops:read`, so `assertPermission` threw X_PERMISSION_UNKNOWN on the first request that reached
71
+ * the page: a screen the generator built and no actor can open. Nothing catches it either — the
72
+ * gate's `policy` step reads `roleDefinitions()` and `routeEntries()`, and an admin page is
73
+ * neither a role nor a route, so `x verify` is green over it.
74
+ *
75
+ * Here rather than in a `policy.ts` beside it, because registration is a side effect of IMPORT and
76
+ * `pages:` already imports this module: a declaration in a file the admin does not import is a
77
+ * declaration that never runs. `declare module` is the type half — `can()`'s key type reads the
78
+ * registry, not the `definePermissions` call — and merging an identical member is what lets an app
79
+ * that already declares this permission keep its own declaration.
80
+ */
81
+ const declarePermissions = (name: string, permission: string): string => {
82
+ const line = `export const ${camel(name)}PagePermissions = definePermissions(['${permission}']);`;
83
+ // Emitted PRE-formatted, because a template cannot run one: past 100 columns biome rewrites this
84
+ // call across four lines, and `x new zebra`-class names reach it (`emitted-contract.test.ts`
85
+ // varies both the length and the first letter for exactly this reason).
86
+ return line.length <= LINE_WIDTH
87
+ ? line
88
+ : `export const ${camel(name)}PagePermissions = definePermissions([\n '${permission}',\n]);`;
89
+ };
90
+
91
+ const permissionDeclaration = (name: string, permission: string): string => `
92
+ declare module '@ultimat3/policy' {
93
+ interface PermissionRegistry {
94
+ '${permission}': true;
95
+ }
96
+ }
97
+
98
+ ${declarePermissions(name, permission)}
99
+ `;
100
+
64
101
  /** `useT()` is per render, so the component binds it in its own body. */
65
102
  const translatorBinding = (module: string | undefined): string =>
66
103
  module === undefined ? '' : '\n const t = useT();\n';
@@ -81,9 +118,12 @@ const pageSource = (
81
118
  // so the specifier is relative to wherever \`defineAdmin\` lives:
82
119
  // import { ${declaration}Page } from './${name}';
83
120
  // defineAdmin({ …, pages: […, ${declaration}Page] })
121
+ //
122
+ // The permission below is declared here AND has to be decided: an authz map built from a fixed
123
+ // list must name '${permission}' too, or a declared permission is still denied for everyone.
84
124
 
85
125
  ${pageImports(module)}
86
-
126
+ ${permissionDeclaration(name, permission)}
87
127
  export function ${Name}Page(props: AdminPageProps) {${translatorBinding(module)}
88
128
  return (
89
129
  <section>
@@ -108,6 +148,7 @@ const pageTest = (name: string, permission: string): string => {
108
148
  const declaration = camel(name);
109
149
  return `// The ${name} admin page is guarded and owns no route of its own — the two facts that separate an
110
150
  // admin screen from a page, and the two an edit here is most likely to break.
151
+ import { knownPermissions } from '@ultimat3/policy';
111
152
  import { expect, unitTest } from '@ultimat3/testing';
112
153
  import { ${declaration}Page } from './${name}';
113
154
 
@@ -119,6 +160,13 @@ unitTest('the ${name} admin page is rooted and guarded', () => {
119
160
  expect(${declaration}Page.permissions).toContain('${permission}');
120
161
  });
121
162
 
163
+ // A \`permissions:\` entry no \`definePermissions()\` declares is X_PERMISSION_UNKNOWN on the first
164
+ // request that reaches the page — a screen this generator built and nobody can open. Importing the
165
+ // page above is what registers it, which is why the declaration lives in that file and not beside it.
166
+ unitTest('the ${name} admin page declares its permission', () => {
167
+ expect(knownPermissions()).toContain('${permission}');
168
+ });
169
+
122
170
  unitTest('the ${name} admin page declares no route of its own', () => {
123
171
  // \`pages:\` is the only way in. A \`config\` export here would be a route the frame never guards.
124
172
  expect('config' in ${declaration}Page).toBe(false);
@@ -39,8 +39,14 @@ const formIslandSource = (
39
39
 
40
40
  import { Button, Form, Input, setSolidRuntime, UiProvider } from '@ultimat3/ui';
41
41
  import type { JSX } from 'solid-js';
42
- import * as solidRuntime from 'solid-js';
43
- import { createSignal } from 'solid-js';
42
+ import {
43
+ createContext,
44
+ createEffect,
45
+ createMemo,
46
+ createSignal,
47
+ onCleanup,
48
+ useContext,
49
+ } from 'solid-js';
44
50
  import { render } from 'solid-js/web';
45
51
  import styles from './ui.module.scss';
46
52
 
@@ -123,11 +129,15 @@ function ${feature.pascal}FormBody(props: ${feature.pascal}FormProps): JSX.Eleme
123
129
  * registers. Delete the line and the first \`<UiProvider>\` render throws X_UI_RUNTIME_MISSING —
124
130
  * loud on purpose, because a DOM render that lost its runtime is a theme toggle that does nothing.
125
131
  *
132
+ * Six NAMED imports, never \`import * as solidRuntime\`: a namespace object handed to a function
133
+ * keeps every export of solid-js alive, and the bundler cannot shake what it cannot see unused —
134
+ * measured at 14.8 kB minified per island chunk (5.6 kB gzipped) for the namespace form.
135
+ *
126
136
  * The shell is cleared first: Solid's \`render\` APPENDS when the container already has children,
127
137
  * so without it the server's markup stays on screen above a second, live copy of the same thing.
128
138
  */
129
139
  export function mount(el: HTMLElement, props: ${feature.pascal}FormProps): void {
130
- setSolidRuntime(solidRuntime);
140
+ setSolidRuntime({ createContext, useContext, createSignal, createMemo, createEffect, onCleanup });
131
141
  el.textContent = '';
132
142
  render(
133
143
  () => (
@@ -6,6 +6,7 @@
6
6
  // run-to-completion migrate step are conventions every container platform shares — a Heroku
7
7
  // buildpack, a Render blueprint or a fly.toml would be the primitive that never ships.
8
8
 
9
+ import { SECRETS_KEY_FILE } from '@ultimat3/core';
9
10
  import type { GeneratedFile, NameSet } from './naming';
10
11
  import { helmFiles } from './scaffold-helm';
11
12
 
@@ -81,6 +82,12 @@ ENTRYPOINT ["bun", "apps/web/server.ts"]
81
82
  * tells the operator to create, in its own `env_file:` — nor `.env.development`, and both landed in
82
83
  * an image layer that `cache-to=mode=max` then pushes to a shared cache. Same four lines the
83
84
  * framework's own `docker/Dockerfile.dockerignore` carries, and for the same reason.
85
+ *
86
+ * The key file is interpolated from `SECRETS_KEY_FILE` rather than written out, because the
87
+ * constant is what `findMasterKey` reads: a rename would otherwise leave every app this generator
88
+ * has ever produced ignoring a filename nothing writes, which reads as a rule still in force.
89
+ * `scripts/image-contract.ts` holds every ignore file IN THIS TREE to the same line; a generated
90
+ * app's copy is this template's, and `scaffold-container.test.ts` is where it is judged.
84
91
  */
85
92
  const dockerignore = (): string => `**/.env
86
93
  **/.env.*
@@ -88,6 +95,11 @@ const dockerignore = (): string => `**/.env
88
95
  # Same shape, different file: an .npmrc carries a registry auth token, so any that exists in a
89
96
  # build context is somebody's local credential and has no business in a layer.
90
97
  **/.npmrc
98
+ # Same shape, and this one is the key itself: ${SECRETS_KEY_FILE} decrypts the committed
99
+ # secrets.enc.json beside it, and findMasterKey falls back to the file whenever
100
+ # ULTIMATE_SECRETS_KEY is unset — so a baked copy boots the image on it and the platform's key is
101
+ # never exercised.
102
+ **/${SECRETS_KEY_FILE}
91
103
 
92
104
  node_modules
93
105
  **/node_modules
@@ -307,6 +307,12 @@ const bunfig = (): string => `[test]
307
307
  root = "."
308
308
  # Frozen clock, seeded RNG, sealed network — nondeterminism in a test is a bug.
309
309
  preload = ["@ultimat3/testing/preload"]
310
+ # An island is mounted from a BUILT chunk that \`mountIsland\` writes to a temp .mjs, so
311
+ # \`bun test --coverage\` reports that file: two minified lines, under a name no source has. Bun
312
+ # does not remap a pre-built module through its sourcemap (measured on 1.4.0, and the build does
313
+ # emit one), so the row can only ever be noise — the island's own .island.tsx is not what it
314
+ # describes. Ignoring it removes the phantom; it hides no line any test was covering.
315
+ coveragePathIgnorePatterns = ["**/*.mjs"]
310
316
  `;
311
317
 
312
318
  const scssTypes =
@@ -327,13 +333,18 @@ declare module '*.scss' {
327
333
  }
328
334
  `;
329
335
 
336
+ // Build output is ROOT-ANCHORED, and that is not cosmetic: an unanchored `dist/` or `coverage/`
337
+ // matches a directory of that name at ANY depth, so `apps/web/site/dist/page.tsx` — an app's own
338
+ // `/dist` route, the directory IS the URL — was a file git refused to commit and `x dev` refused to
339
+ // reload. `packages/*/dist/` keeps a workspace's build output ignored without reaching a surface.
330
340
  const gitignore = (): string => `node_modules/
331
341
  .x/
332
- dist/
342
+ /dist/
343
+ packages/*/dist/
333
344
  *.tsbuildinfo
334
345
  .env
335
346
  .env.*.local
336
- coverage/
347
+ /coverage/
337
348
  playwright-report/
338
349
  test-results/
339
350
  `;
@@ -0,0 +1,79 @@
1
+ // Which of a selection's files may share a worker pool, and which may not. `--parallel=N` is the
2
+ // width of the WHOLE run, so a selection holding a `live` or an `e2e` file is more than one run —
3
+ // this file decides how many, and `test-shards.ts` spends them.
4
+
5
+ import type { TestFile } from './test-select';
6
+ import type { TestType } from './verify-tests';
7
+ import { ownerOf, SERIAL_TYPES } from './verify-tests';
8
+
9
+ /** One `bun test` invocation: which files, how wide, and the type its reproduce line names. */
10
+ export interface TestPass {
11
+ readonly files: readonly TestFile[];
12
+ readonly workers: number;
13
+ /**
14
+ * The type this pass is exactly the selection of, when it is one — so a failure's `fix:` names
15
+ * `x test live --workers 1` and reruns THESE files, not the whole corpus at this width.
16
+ */
17
+ readonly type?: TestType;
18
+ }
19
+
20
+ export interface PassInput {
21
+ readonly files: readonly TestFile[];
22
+ /** What the caller asked for, already bounded by `--workers`' own reader. */
23
+ readonly workers: number;
24
+ /** The positional, when there was one. A pass over one type keeps it; the split never adds one. */
25
+ readonly type?: TestType;
26
+ /** Set for a `--worker I` rerun, which is one process by construction. */
27
+ readonly shard?: number;
28
+ }
29
+
30
+ const widthFor = (files: readonly TestFile[], workers: number): number =>
31
+ Math.max(1, Math.min(Math.trunc(workers), files.length || 1));
32
+
33
+ /**
34
+ * The passes one invocation becomes. One, for every selection that holds no serial file — which
35
+ * is every `x test unit`, every `--filter` over a feature's contract tests, and the whole corpus
36
+ * of an app that has neither.
37
+ *
38
+ * `live` and `e2e` are the exception, and `verify-tests.ts` owns both the list and the reasons: a
39
+ * logical replication slot is named at the Postgres CLUSTER level so a per-worker database does
40
+ * not isolate it, and `e2e` shares one `dist/` and one browser profile. `x verify` has routed them
41
+ * through `runSerial` since 2026-08 while `x test` clamped on the POSITIONAL alone — so a bare
42
+ * `x test --workers 8` ran the very files the gate runs one at a time, eight at a time, and only
43
+ * a real `TEST_DATABASE_URL` makes that visible.
44
+ *
45
+ * Each serial type is its own pass rather than one pass over both, because the pass's `type` is
46
+ * what its failure reproduces with: `x test live --workers 1` selects exactly the files that ran.
47
+ *
48
+ * A `--worker I` rerun is left whole: it is a single `bun test --isolate --shard=i/N` process, so
49
+ * nothing inside it runs beside anything else, and splitting it would make shard i of the rerun a
50
+ * different set of files from shard i of the run it reproduces.
51
+ */
52
+ export function testPasses(input: PassInput): readonly TestPass[] {
53
+ const serialTypes = new Set<TestType>(SERIAL_TYPES);
54
+ if (input.shard !== undefined) {
55
+ return [
56
+ {
57
+ files: input.files,
58
+ workers: widthFor(input.files, input.workers),
59
+ ...(input.type === undefined ? {} : { type: input.type }),
60
+ },
61
+ ];
62
+ }
63
+ const shared = input.files.filter((file) => !serialTypes.has(ownerOf(file.path)));
64
+ const passes: TestPass[] = [];
65
+ // Cheapest first, and the widest first: the pool run is most of the corpus and most of the
66
+ // signal, and a serial suite that needs a database is the one a laptop is least likely to have.
67
+ if (shared.length > 0) {
68
+ passes.push({
69
+ files: shared,
70
+ workers: widthFor(shared, input.workers),
71
+ ...(input.type === undefined ? {} : { type: input.type }),
72
+ });
73
+ }
74
+ for (const type of SERIAL_TYPES) {
75
+ const files = input.files.filter((file) => ownerOf(file.path) === type);
76
+ if (files.length > 0) passes.push({ files, workers: 1, type });
77
+ }
78
+ return passes;
79
+ }