@ultimat3/cli 31.26.0 → 31.27.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.
Files changed (117) hide show
  1. package/CLAUDE.md +44 -36
  2. package/README.md +5 -4
  3. package/package.json +29 -29
  4. package/src/app-mcp.ts +17 -3
  5. package/src/cmd-cache-spec.ts +5 -2
  6. package/src/cmd-db-spec.ts +2 -3
  7. package/src/cmd-db.ts +0 -2
  8. package/src/cmd-deploy-verify-sample.ts +93 -0
  9. package/src/cmd-deploy-verify.ts +2 -41
  10. package/src/cmd-dev-spec.ts +15 -1
  11. package/src/cmd-dev.ts +31 -4
  12. package/src/cmd-doctor.ts +4 -1
  13. package/src/cmd-exercise-spec.ts +7 -1
  14. package/src/cmd-exercise.ts +22 -10
  15. package/src/cmd-generate.ts +2 -0
  16. package/src/cmd-jobs-spec.ts +3 -6
  17. package/src/cmd-jobs.ts +1 -7
  18. package/src/cmd-logs-spec.ts +2 -1
  19. package/src/cmd-logs.ts +9 -28
  20. package/src/cmd-planned.ts +11 -45
  21. package/src/cmd-profile-frames.ts +99 -0
  22. package/src/cmd-profile-spec.ts +24 -0
  23. package/src/cmd-profile.ts +164 -0
  24. package/src/cmd-status-sample.ts +57 -0
  25. package/src/cmd-status-spec.ts +30 -0
  26. package/src/cmd-status.ts +108 -0
  27. package/src/cmd-token-spec.ts +5 -2
  28. package/src/cmd-token.ts +7 -3
  29. package/src/coverage-island.ts +121 -0
  30. package/src/coverage-lcov.ts +49 -5
  31. package/src/coverage-remap.ts +146 -0
  32. package/src/db-replay-engine-prepared.ts +66 -0
  33. package/src/db-replay-engine-template.ts +156 -0
  34. package/src/db-replay-engine.ts +4 -0
  35. package/src/db-replay-scratch-reap.ts +54 -0
  36. package/src/deploy-verify-flags.ts +9 -2
  37. package/src/deploy-verify-grade.ts +10 -3
  38. package/src/dev-boot.ts +14 -1
  39. package/src/dev-dashboard-guard.ts +57 -10
  40. package/src/dev-host.ts +46 -0
  41. package/src/dev-tls-cache.ts +103 -0
  42. package/src/dev-tls-der.ts +69 -0
  43. package/src/dev-tls.ts +120 -0
  44. package/src/doctor-browser.ts +60 -0
  45. package/src/error-codes-verify.ts +47 -0
  46. package/src/error-codes.ts +14 -23
  47. package/src/exercise-database.ts +40 -7
  48. package/src/exercise-push-device.ts +51 -0
  49. package/src/exercise-route-api.ts +74 -0
  50. package/src/exercise-routes.ts +14 -5
  51. package/src/exercise-services.ts +3 -1
  52. package/src/exercise-shard-flag.ts +47 -0
  53. package/src/fix-command.ts +2 -2
  54. package/src/generate-factories.ts +5 -11
  55. package/src/generate-feature-required.ts +9 -4
  56. package/src/generate-files.ts +20 -2
  57. package/src/generate-kinds.ts +5 -1
  58. package/src/guards.ts +21 -6
  59. package/src/island-bundle-options.ts +48 -0
  60. package/src/island-bundle.ts +18 -46
  61. package/src/island-link.ts +5 -0
  62. package/src/island-outputs.ts +5 -0
  63. package/src/mcp-errors-verify.ts +35 -0
  64. package/src/mcp-errors.ts +10 -19
  65. package/src/mcp-host-logs.ts +121 -0
  66. package/src/mcp-host.ts +12 -73
  67. package/src/messages-floor.ts +19 -0
  68. package/src/messages-status.ts +10 -0
  69. package/src/messages.ts +21 -0
  70. package/src/registry.ts +4 -0
  71. package/src/role-start-types.ts +7 -0
  72. package/src/role-start.ts +4 -0
  73. package/src/serve-boot.ts +7 -1
  74. package/src/serve-env-tls.ts +57 -0
  75. package/src/solid-loader.ts +27 -10
  76. package/src/templates/generate-export-rows.ts +136 -0
  77. package/src/templates/generate-import-rows.ts +186 -0
  78. package/src/templates/generate-rows-slice.ts +95 -0
  79. package/src/templates/github/ci.yml.ts +4 -0
  80. package/src/templates/scaffold-db-package.ts +3 -0
  81. package/src/templates/scaffold-docs.ts +8 -6
  82. package/src/templates/scaffold-repo.ts +2 -7
  83. package/src/templates/scaffold-site.ts +4 -1
  84. package/src/templates/scaffold-suites.ts +72 -0
  85. package/src/templates/scaffold-test-services.ts +35 -10
  86. package/src/templates/scaffold-verify-floor.ts +53 -31
  87. package/src/templates/shapes/api.ts +4 -0
  88. package/src/templates/slice-foundation.ts +3 -3
  89. package/src/unthrown-codes.ts +1 -1
  90. package/src/upgrade-gate.ts +6 -1
  91. package/src/upgrade-guards-baseline.ts +43 -0
  92. package/src/upgrade-guards.ts +37 -2
  93. package/src/upgrade-report.ts +3 -0
  94. package/src/verify-coverage-run.ts +42 -11
  95. package/src/verify-e2e.ts +115 -4
  96. package/src/verify-floor.ts +27 -0
  97. package/src/verify-guard-baseline.ts +109 -0
  98. package/src/verify-live.ts +72 -0
  99. package/src/verify-merge-skips.ts +51 -0
  100. package/src/verify-merge.ts +36 -2
  101. package/src/verify-run.ts +48 -7
  102. package/src/verify-services.ts +287 -0
  103. package/src/verify-skip-reason.ts +53 -0
  104. package/src/verify-strict.ts +108 -0
  105. package/src/verify-test-command.ts +129 -0
  106. package/src/verify-tests.ts +39 -126
  107. package/types/babel-modules.d.ts +2 -0
  108. package/wiki/CLI-Reference.md +142 -23
  109. package/wiki/Caching-And-Invalidation.md +1 -1
  110. package/wiki/Entities-And-Migrations.md +1 -1
  111. package/wiki/Jobs-And-Workflows.md +3 -3
  112. package/wiki/Known-Gaps.md +5 -1
  113. package/wiki/MCP-And-AI.md +1 -1
  114. package/wiki/PWA-And-Offline.md +1 -1
  115. package/wiki/Troubleshooting.md +3 -3
  116. package/wiki/Tutorial-05-Deploy-Free.md +2 -2
  117. package/wiki/Upgrading.md +3 -0
@@ -6,6 +6,7 @@
6
6
 
7
7
  import { sortedImports } from './imports';
8
8
  import type { GeneratedFile, NameSet } from './naming';
9
+ import { e2eSuiteFiles } from './scaffold-suites';
9
10
 
10
11
  // Plain strings for the framework lines, never template literals: the workspace-dependency scanner
11
12
  // blanks a string's contents but not a nested template's, so a template here would bill the CLI
@@ -305,9 +306,11 @@ unitTest('it ships zero JS and declares the metadata a search result renders', a
305
306
  });
306
307
  `;
307
308
 
308
- /** The landing page, its stylesheet and its test. */
309
+ /** The landing page, its stylesheet, its test and its e2e suite. */
309
310
  export const siteFiles = (app: NameSet): readonly GeneratedFile[] => [
310
311
  { path: 'apps/web/site/page.tsx', contents: sitePage(app) },
311
312
  { path: 'apps/web/site/page.module.scss', contents: siteStyle() },
312
313
  { path: 'apps/web/site/page.test.ts', contents: sitePageTest(app) },
314
+ // The same page in a real browser: the `e2e` step every scaffold with a page runs.
315
+ ...e2eSuiteFiles(),
313
316
  ];
@@ -0,0 +1,72 @@
1
+ // The two suites every scaffold ships for what a unit test cannot answer: the production driver
2
+ // against a real Postgres (`live`), and the landing page in a real browser (`e2e`). With both, a
3
+ // fresh app's gate runs its `live` and `e2e` steps from the first commit, example slice or not.
4
+
5
+ import type { GeneratedFile } from './naming';
6
+
7
+ /** Where the live suite lands: beside the handle it vouches for. */
8
+ export const LIVE_SUITE_PATH = 'packages/db/src/client.live.test.ts';
9
+
10
+ /** Where the e2e suite lands: beside the page it drives (a shape that drops the page drops it). */
11
+ export const E2E_SUITE_PATH = 'apps/web/site/page.e2e.test.ts';
12
+
13
+ const liveSuite =
14
+ (): string => `// The production driver against a real Postgres — the half the embedded database cannot vouch for.
15
+ // A \`uuid[]\`, a \`timestamptz\`, a \`jsonb\` and a \`bigint\` decoded over the wire, so a decode that
16
+ // differs from PGlite's is red here and not on the first deploy. \`needs\` skips it, naming the
17
+ // command that starts the database, when TEST_DATABASE_URL is unset.
18
+ import { postgresClient, sql } from '@ultimat3/db';
19
+ import { expect, liveTest } from '@ultimat3/testing';
20
+
21
+ const ids = ['00000000-0000-4000-8000-000000000001', '00000000-0000-4000-8000-000000000002'];
22
+
23
+ interface Decoded {
24
+ readonly ids: readonly string[];
25
+ readonly at: Date;
26
+ readonly doc: { readonly n: number };
27
+ readonly big: string;
28
+ }
29
+
30
+ liveTest(
31
+ 'the production driver decodes what the app stores',
32
+ async () => {
33
+ const { TEST_DATABASE_URL: url } = Bun.env;
34
+ const client = postgresClient({ url });
35
+ try {
36
+ const [row] = await client.query<Decoded>(
37
+ sql\`select \${ids}::uuid[] as ids, '2026-01-01T00:00:00Z'::timestamptz as at, '{"n":1}'::jsonb as doc, 9007199254740993::bigint as big\`,
38
+ );
39
+ expect(row?.ids).toEqual(ids);
40
+ expect(row?.at.toISOString()).toBe('2026-01-01T00:00:00.000Z');
41
+ expect(row?.doc).toEqual({ n: 1 });
42
+ // Past 2^53: a bigint that came back as a number would have lost its last digit.
43
+ expect(row?.big).toBe('9007199254740993');
44
+ } finally {
45
+ await client.close();
46
+ }
47
+ },
48
+ { needs: ['postgres'] },
49
+ );
50
+ `;
51
+
52
+ const e2eSuite =
53
+ (): string => `// The landing page in a real browser, against the BUILT output — what \`renderRoute\` in
54
+ // page.test.ts cannot see: the document a browser parses and the title its tab shows. Its own file
55
+ // because the gate types a test by its FILENAME — an e2eTest in page.test.ts is a unit test.
56
+ import { e2eTest, expect } from '@ultimat3/testing';
57
+
58
+ e2eTest('/ loads in a browser and names itself', async ({ page }) => {
59
+ await page.goto('/');
60
+ expect(await page.title()).not.toBe('');
61
+ });
62
+ `;
63
+
64
+ /** The live suite, in the db package every scaffold writes. */
65
+ export const liveSuiteFiles = (): readonly GeneratedFile[] => [
66
+ { path: LIVE_SUITE_PATH, contents: liveSuite() },
67
+ ];
68
+
69
+ /** The e2e suite, beside the landing page. */
70
+ export const e2eSuiteFiles = (): readonly GeneratedFile[] => [
71
+ { path: E2E_SUITE_PATH, contents: e2eSuite() },
72
+ ];
@@ -3,17 +3,40 @@
3
3
  // `docker/docker-compose.test.yml`, cut to what an app has. Ports sit apart from the dev stack's
4
4
  // so both can run at once; `ci.yml` starts this file before `bun run verify`.
5
5
 
6
+ import { fnv1a } from '@ultimat3/core';
6
7
  import type { GeneratedFile, NameSet } from './naming';
7
8
  import { S3_GATEWAY_IMAGE } from './pinned-images';
8
9
 
9
10
  export const TEST_COMPOSE_PATH = 'docker/docker-compose.test.yml';
10
11
  export const TEST_ENV_PATH = 'docker/test-services.env';
11
12
 
12
- /** Host ports, one place: the compose file publishes them and the env file names them. */
13
+ /** Each service's band start: the dev stack's port plus 50000, so both stacks run at once. */
13
14
  export const TEST_PORTS = { postgres: 55432, redis: 56379, nats: 54222, s3: 59000 } as const;
14
15
 
16
+ /** How wide each band is: the bands stay disjoint, and two apps collide 1 time in 500. */
17
+ export const TEST_PORT_SPREAD = 500;
18
+
19
+ type TestPorts = { readonly [K in keyof typeof TEST_PORTS]: number };
20
+
21
+ /**
22
+ * This app's host ports, one place: the compose file publishes them and the env file names them.
23
+ * One fixed set made two scaffolds on one machine share 55432, so the second app's live suites
24
+ * dialled the first app's container; the app's name now picks its offset into each band.
25
+ */
26
+ export const testPorts = (app: NameSet): TestPorts => {
27
+ // FNV-1a over the app's name: stable across machines and runs.
28
+ const offset = fnv1a(app.kebab) % TEST_PORT_SPREAD;
29
+ return {
30
+ postgres: TEST_PORTS.postgres + offset,
31
+ redis: TEST_PORTS.redis + offset,
32
+ nats: TEST_PORTS.nats + offset,
33
+ s3: TEST_PORTS.s3 + offset,
34
+ };
35
+ };
36
+
15
37
  const composeTest = (
16
38
  app: NameSet,
39
+ ports: TestPorts = testPorts(app),
17
40
  ): string => `# The services the test suites run against — in RAM, and silent.
18
41
  #
19
42
  # docker compose -f ${TEST_COMPOSE_PATH} up -d --wait
@@ -22,7 +45,8 @@ const composeTest = (
22
45
  #
23
46
  # \`--wait\` returns once every healthcheck passes. CI runs the same lines (.github/workflows/ci.yml).
24
47
  # None of it is required: with no TEST_* variable set the unit suite runs on the in-memory driver,
25
- # and a suite that needs a real server skips. Ports are the dev stack's plus 50000, so both run.
48
+ # and a suite that needs a real server skips. Ports are this app's own (its name picks
49
+ # them), above the dev stack's, so both stacks — and two apps — run at once.
26
50
  #
27
51
  # Three rules, on every service:
28
52
  #
@@ -71,7 +95,7 @@ services:
71
95
  -c min_wal_size=32MB
72
96
  -c max_wal_size=256MB
73
97
  tmpfs: [/var/lib/postgresql]
74
- ports: ['127.0.0.1:${TEST_PORTS.postgres}:5432']
98
+ ports: ['127.0.0.1:${ports.postgres}:5432']
75
99
  healthcheck:
76
100
  # TCP, never the socket: the entrypoint's temporary init server listens on the socket only.
77
101
  test: ['CMD-SHELL', 'pg_isready -U ${app.kebab} -h 127.0.0.1 -p 5432']
@@ -84,7 +108,7 @@ services:
84
108
  image: redis:8-alpine
85
109
  command: ['redis-server', '--save', '', '--appendonly', 'no', '--loglevel', 'nothing']
86
110
  tmpfs: [/data]
87
- ports: ['127.0.0.1:${TEST_PORTS.redis}:6379']
111
+ ports: ['127.0.0.1:${ports.redis}:6379']
88
112
  healthcheck:
89
113
  test: ['CMD', 'redis-cli', 'ping']
90
114
  interval: 1s
@@ -97,7 +121,7 @@ services:
97
121
  image: nats:2-alpine
98
122
  command: ['-js', '-sd', '/data', '-m', '8222', '-l', '/dev/null']
99
123
  tmpfs: [/data]
100
- ports: ['127.0.0.1:${TEST_PORTS.nats}:4222']
124
+ ports: ['127.0.0.1:${ports.nats}:4222']
101
125
  healthcheck:
102
126
  test: ['CMD', 'wget', '-q', '--spider', 'http://127.0.0.1:8222/healthz']
103
127
  interval: 1s
@@ -117,7 +141,7 @@ services:
117
141
  ROOT_ACCESS_KEY: ${app.kebab}
118
142
  ROOT_SECRET_KEY: ${app.kebab}-test
119
143
  tmpfs: [/data/${app.kebab}-test]
120
- ports: ['127.0.0.1:${TEST_PORTS.s3}:9000']
144
+ ports: ['127.0.0.1:${ports.s3}:9000']
121
145
  healthcheck:
122
146
  test: ['CMD', 'nc', '-z', '127.0.0.1', '9000']
123
147
  interval: 1s
@@ -127,13 +151,14 @@ services:
127
151
 
128
152
  const testEnv = (
129
153
  app: NameSet,
154
+ ports: TestPorts = testPorts(app),
130
155
  ): string => `# Where the suites find the services ${TEST_COMPOSE_PATH} starts — the one place these URLs are
131
156
  # written. A laptop sources it (\`set -a; . ${TEST_ENV_PATH}; set +a\`); CI appends it to $GITHUB_ENV.
132
157
  # TEST_DATABASE_URL is what @ultimat3/testing clones one database per test worker from.
133
- TEST_DATABASE_URL=postgres://${app.kebab}:${app.kebab}-test@127.0.0.1:${TEST_PORTS.postgres}/postgres
134
- TEST_REDIS_URL=redis://127.0.0.1:${TEST_PORTS.redis}
135
- TEST_NATS_URL=nats://127.0.0.1:${TEST_PORTS.nats}
136
- TEST_S3_URL=http://${app.kebab}:${app.kebab}-test@127.0.0.1:${TEST_PORTS.s3}/${app.kebab}-test
158
+ TEST_DATABASE_URL=postgres://${app.kebab}:${app.kebab}-test@127.0.0.1:${ports.postgres}/postgres
159
+ TEST_REDIS_URL=redis://127.0.0.1:${ports.redis}
160
+ TEST_NATS_URL=nats://127.0.0.1:${ports.nats}
161
+ TEST_S3_URL=http://${app.kebab}:${app.kebab}-test@127.0.0.1:${ports.s3}/${app.kebab}-test
137
162
  `;
138
163
 
139
164
  /** The test stack and its env file. */
@@ -7,30 +7,21 @@ import { COVERAGE_BAR } from '../coverage-floor';
7
7
  import type { VerifyStepName } from '../verify-step';
8
8
 
9
9
  /**
10
- * The suite ratchet, committed on day one. Without it `readVerifyFloor` answers "no file is no
11
- * floor" and a deleted suite turns its step from green into skipped-and-green — so
12
- * `X_VERIFY_SUITE_VANISHED` was unreachable in every generated app, in the one repo shape that
13
- * grows suites fastest.
10
+ * The suite ratchet, committed on day one, naming ALL of the gate: every step is either required in
11
+ * `steps` or excused in `skip` with a written why (`verify-strict.ts`), and
12
+ * `scaffold-verify-floor.test.ts` refuses a scaffold that leaves one in neither. Without a floor
13
+ * `readVerifyFloor` answers "no file is no floor" and a deleted suite turns its step from green into
14
+ * skipped-and-green. Typed as `VerifyStepName`, so a name the gate does not run is a compile error.
14
15
  *
15
- * Every name here is a step this scaffold has proved it can run: the SIX that declare no `applies`
16
- * at all — typecheck, lint, boundaries, filesize, errors, manifest — plus `package-shape` (five
17
- * workspace packages), `unit` (every generator emits a `<file>.test.ts`; like every suite step it
18
- * applies on its own file list, `verify-tests.ts`), and `eval`, `drift` and `budgets`, which apply
19
- * to any root with an `app.config.ts`. Typed as `VerifyStepName`, so a name the gate does not run
20
- * is a compile error rather than a floor that covers nothing.
16
+ * `live` and `e2e` are required of every scaffold with the files that make them run
17
+ * (`scaffold-suites.ts`): the production driver against the test Postgres `x verify` starts, the
18
+ * landing page in a real browser. No browser is red with the command that locates one, never a
19
+ * green step that checked nothing. `contract-diff` applies once `bun run setup` has written
20
+ * `x.manifest.json`, which is the first command the README gives.
21
21
  *
22
- * Plus `contract`, which every variant now ships a file for — `apps/web/api/health.contract.test.ts`
23
- * — and, with the example slice, `live` and `job`: its query is a `liveTest` and its job a
24
- * `jobTest`, and both were written into plain `<name>.test.ts` files that the `unit` step ran while
25
- * `x test live` and `x test job` answered X_TEST_NO_FILES. This is the commit that makes the app's
26
- * own gate run them, which is what the paragraph below always said the condition was.
27
- *
28
- * Two remain absent. `e2e` has a scaffolded file and it is an `e2eTest` — `test.skip` until the app
29
- * registers a browser driver, so the step would run zero tests and fail the ratchet on the
30
- * scaffold's own placeholder. Its absence is visible rather than silent: a suite that executed
31
- * nothing reports as a SKIPPED step, not the green check it printed until #434, so the app's own
32
- * gate line says `- e2e` and names it in the summary until a driver makes it run. `contract-diff` needs a committed `x.manifest.json`, which
33
- * `x manifest` writes later. Each joins the list in the commit that makes the app's gate run it.
22
+ * And `strict: true`: a step that ran nothing is red unless `skip` carries its why
23
+ * (`X_VERIFY_STRICT_UNRUN`). Measured on a fresh `x new` / `--no-example`: `roadmap` everywhere,
24
+ * `job` without the example slice, `e2e` in the `api` shape — exactly the `WHY` rows below.
34
25
  */
35
26
  const SCAFFOLD_FLOOR: readonly VerifyStepName[] = [
36
27
  'typecheck',
@@ -41,11 +32,18 @@ const SCAFFOLD_FLOOR: readonly VerifyStepName[] = [
41
32
  'errors',
42
33
  'unit',
43
34
  'contract',
35
+ // `packages/db/src/client.live.test.ts`, in every scaffold — and the example's live query.
36
+ 'live',
44
37
  // Every app has an `app.config.ts` and primitives to run: `x new` writes `apps/web/exercise.ts`.
45
38
  'exercise',
39
+ // `apps/web/site/page.e2e.test.ts` — dropped, with this name, by a shape that serves no page.
40
+ 'e2e',
46
41
  'eval',
47
42
  'drift',
43
+ 'contract-diff',
48
44
  'budgets',
45
+ 'seo',
46
+ 'i18n',
49
47
  // Always applicable to a scaffolded app — it has an `app.config.ts`, roles and two guarded
50
48
  // routes — so a run that reports it skipped is a gate that lost the step, not an app with
51
49
  // nothing to check. It is the step that would have caught the 500 `x new` used to ship.
@@ -53,19 +51,42 @@ const SCAFFOLD_FLOOR: readonly VerifyStepName[] = [
53
51
  'manifest',
54
52
  ];
55
53
 
56
- /** The two suites only the example slice writes a file for — a floor step with no file is red. */
57
- const EXAMPLE_FLOOR: readonly VerifyStepName[] = ['live', 'job'];
54
+ /** Each step a scaffold may not run, with the why its `skip` carries. */
55
+ const WHY = {
56
+ roadmap:
57
+ 'a framework-repository step: it checks docs/idea/14-roadmap.md, which only the Ultimate monorepo ships',
58
+ job: 'this app declares no job yet: x g job <name> writes one with its .job.test.ts, and then job moves from "skip" to "steps"',
59
+ e2e: 'this app serves no page for a browser to load: x g route <name> --surface site writes one, and then e2e moves from "skip" to "steps"',
60
+ } as const satisfies Partial<Record<VerifyStepName, string>>;
61
+
62
+ /** What a scaffold ships suites for: a job (the example slice) and a page (every shape but `api`). */
63
+ export interface FloorSuites {
64
+ readonly jobs: boolean;
65
+ readonly pages: boolean;
66
+ }
67
+
68
+ /** The floor's `steps` and `skip` for one scaffold, derived from the suites it ships. */
69
+ export function floorSteps(suites: FloorSuites): {
70
+ readonly steps: readonly VerifyStepName[];
71
+ readonly skip: Readonly<Partial<Record<VerifyStepName, string>>>;
72
+ } {
73
+ const steps = SCAFFOLD_FLOOR.filter((step) => step !== 'e2e' || suites.pages);
74
+ return {
75
+ steps: suites.jobs ? [...steps, 'job'] : steps,
76
+ skip: {
77
+ ...(suites.jobs ? {} : { job: WHY.job }),
78
+ ...(suites.pages ? {} : { e2e: WHY.e2e }),
79
+ roadmap: WHY.roadmap,
80
+ },
81
+ };
82
+ }
58
83
 
59
84
  /**
60
85
  * What a unit test cannot execute in a scaffolded app, each with its reason — `x doctor` prints
61
- * them. Two kinds and no more: a file here is a file the floor does not see, so the list is not
86
+ * them. Entry points only: a file here is a file the floor does not see, so the list is not
62
87
  * a place to put code that merely has no test yet.
63
88
  */
64
89
  export const SCAFFOLD_COVERAGE_EXCLUDE: readonly CoverageExclude[] = [
65
- {
66
- glob: 'apps/**/*.island.tsx',
67
- why: 'an island runs in a browser: its test mounts a BUILT chunk (mountIsland), and Bun cannot map that chunk back to this source — its states are held by guards/island-without-states.ts and photographed by x shot --island',
68
- },
69
90
  {
70
91
  glob: 'apps/*/server.ts',
71
92
  why: 'the container entry point: it boots the roles and lives as long as the process — bun run dev and the image exercise it',
@@ -81,10 +102,11 @@ export const SCAFFOLD_COVERAGE_EXCLUDE: readonly CoverageExclude[] = [
81
102
  * to (`COVERAGE_BAR`), not a softer one for apps. `scaffold-smoke` runs the app's own `x verify`,
82
103
  * so the scaffold is green at it on what it generates or the job is red.
83
104
  */
84
- export const verifyFloor = (example: boolean): string =>
105
+ export const verifyFloor = (suites: FloorSuites): string =>
85
106
  `${JSON.stringify(
86
107
  {
87
- steps: example ? [...SCAFFOLD_FLOOR, ...EXAMPLE_FLOOR] : SCAFFOLD_FLOOR,
108
+ ...floorSteps(suites),
109
+ strict: true,
88
110
  coverage: {
89
111
  lines: COVERAGE_BAR,
90
112
  funcs: COVERAGE_BAR,
@@ -3,7 +3,9 @@
3
3
  // documents and the offline fallback, no island, no app UI. `/admin` stays: it is the operator's
4
4
  // console. The PWA block stays too: a page `x g` writes into this app is tested offline.
5
5
 
6
+ import { VERIFY_FLOOR_FILE } from '../../verify-floor';
6
7
  import type { GeneratedFile, NameSet } from '../naming';
8
+ import { verifyFloor } from '../scaffold-verify-floor';
7
9
  import { apiKeyFiles } from './api-keys';
8
10
  import type { ShapeEdit, ShapeOverlay } from './overlay';
9
11
  import { claudeRows, shapeLines } from './shared-edits';
@@ -97,5 +99,7 @@ export const apiShape: ShapeOverlay = {
97
99
  ...apiKeyFiles(),
98
100
  { path: 'apps/web/api/index.ts', contents: apiIndex(app) },
99
101
  { path: 'apps/web/api/index.test.ts', contents: apiIndexTest() },
102
+ // No page, so no browser suite: `e2e` is excused with its why rather than required of nothing.
103
+ { path: VERIFY_FLOOR_FILE, contents: verifyFloor({ jobs: true, pages: false }) },
100
104
  ],
101
105
  };
@@ -29,9 +29,9 @@ const notFoundCode = (feature: NameSet): string =>
29
29
  * The emitted `fix:` cites `x queries list`, and which command it cites is the whole point: a
30
30
  * scaffolded app runs the same `errors` step this repo does, so a fix naming a command the build
31
31
  * does not ship writes a fresh X_ERROR_FIX_INVALID into the app on every `x g action`. It cited
32
- * `x db studio`, which is in `PLANNED_SUBCOMMANDS` and exits X_NOT_IMPLEMENTED — the generator was
33
- * breaking the one rule it exists to demonstrate. `x queries list` ships, and a read is where a
34
- * caller gets an id that exists.
32
+ * `x db studio`, then planned and exiting X_NOT_IMPLEMENTED (it left the registry 2026-11-15) —
33
+ * the generator was breaking the one rule it exists to demonstrate. `x queries list` ships, and a
34
+ * read is where a caller gets an id that exists.
35
35
  */
36
36
  const errorsSource = (feature: NameSet): string => {
37
37
  const errorCode = notFoundCode(feature);
@@ -12,7 +12,7 @@ export const UNTHROWN_CODES_FILE = 'packages/cli/src/unthrown-codes.ts';
12
12
  * `X_ERROR_CODE_UNTHROWN_STALE`.
13
13
  */
14
14
  export const UNTHROWN_CODES: ReadonlySet<string> = new Set([
15
- // `x db studio` is planned and unreleased; it exits X_NOT_IMPLEMENTED.
15
+ // `studio` left `x db` (2026-11-15, wiki/Known-Gaps.md): nothing runs that could fail.
16
16
  'X_DB_STUDIO_FAILED',
17
17
  // 21.0.0: there is no LiveClient to register (X_REALTIME_UNINSTALLED replaced it).
18
18
  'X_LIVE_CLIENT_MISSING',
@@ -15,7 +15,7 @@ import { rebaselineCoverage, statedCoverage } from './upgrade-coverage';
15
15
  import { documentIn } from './upgrade-document';
16
16
  import type { HopExerciseFloor } from './upgrade-exercise-floor';
17
17
  import { ratchetExerciseFloor } from './upgrade-exercise-floor';
18
- import type { WithheldGuard } from './upgrade-guards';
18
+ import type { BaselinedGuard, WithheldGuard } from './upgrade-guards';
19
19
  import { installMissingGuards } from './upgrade-guards';
20
20
  import { parseJson } from './upgrade-registry';
21
21
 
@@ -101,6 +101,11 @@ export interface HopGuards {
101
101
  readonly installed: readonly string[];
102
102
  /** Not written, with how many findings each would have added (`upgrade-guards.ts`). */
103
103
  readonly withheld: readonly WithheldGuard[];
104
+ /**
105
+ * Also in `installed`: kept at its measured count, `guardBaseline` in `x.verify.json`. Absent
106
+ * when none, so `--json` of a hop that baselined nothing is unchanged.
107
+ */
108
+ readonly baselined?: readonly BaselinedGuard[];
104
109
  }
105
110
 
106
111
  /**
@@ -0,0 +1,43 @@
1
+ // A withheld guard's measured count, merged into `x.verify.json` as `guardBaseline` so the hop can
2
+ // keep it on disk at that count (`verify-guard-baseline.ts` judges it). The app's own keys are never
3
+ // touched: a baseline it already wrote for that guard, or a file that is not a JSON object, refuses.
4
+
5
+ // why: Bun exposes no path-join primitive; `x.verify.json` sits at the app root.
6
+ import { join } from 'node:path';
7
+ import { parseJson } from './upgrade-registry';
8
+ import { VERIFY_FLOOR_FILE } from './verify-floor';
9
+ import { GUARD_BASELINE_FIELD } from './verify-guard-baseline';
10
+
11
+ /** The floor's bytes before the write, or null when there was no file: what a rollback restores. */
12
+ export type FloorPrior = string | null;
13
+
14
+ const isRecord = (value: unknown): value is Record<string, unknown> =>
15
+ typeof value === 'object' && value !== null && !Array.isArray(value);
16
+
17
+ /**
18
+ * Writes `guardBaseline[name] = findings`; the prior bytes, or undefined when it refused. No file
19
+ * is a floor requiring no step, so the one written changes nothing but the baseline.
20
+ */
21
+ export async function writeGuardBaseline(
22
+ root: string,
23
+ name: string,
24
+ findings: number,
25
+ ): Promise<{ readonly prior: FloorPrior } | undefined> {
26
+ const file = Bun.file(join(root, VERIFY_FLOOR_FILE));
27
+ const prior = (await file.exists()) ? await file.text() : null;
28
+ const payload = prior === null ? { steps: [] } : parseJson(prior);
29
+ if (!isRecord(payload)) return undefined;
30
+ const current = payload[GUARD_BASELINE_FIELD];
31
+ if (current !== undefined && !isRecord(current)) return undefined;
32
+ if (current !== undefined && Object.hasOwn(current, name)) return undefined;
33
+ const next = { ...payload, [GUARD_BASELINE_FIELD]: { ...(current ?? {}), [name]: findings } };
34
+ await Bun.write(file, `${JSON.stringify(next, null, 2)}\n`);
35
+ return { prior };
36
+ }
37
+
38
+ /** Puts the floor back as it was: rewritten, or deleted when the write created it. */
39
+ export async function restoreFloor(root: string, prior: FloorPrior): Promise<void> {
40
+ const file = Bun.file(join(root, VERIFY_FLOOR_FILE));
41
+ if (prior !== null) await Bun.write(file, prior);
42
+ else if (await file.exists()) await file.delete();
43
+ }
@@ -9,6 +9,7 @@ import { MANIFEST_FILENAME } from '@ultimat3/manifest';
9
9
  import { t } from '@ultimat3/schema';
10
10
  import type { ExecResult } from './exec';
11
11
  import { documentIn } from './upgrade-document';
12
+ import { restoreFloor, writeGuardBaseline } from './upgrade-guards-baseline';
12
13
 
13
14
  const GENERATED = t.object({
14
15
  data: t.optional(t.object({ files: t.optional(t.array(t.string)) })),
@@ -28,9 +29,20 @@ export interface WithheldGuard {
28
29
  readonly findings: number | null;
29
30
  }
30
31
 
32
+ /** A guard the tree breaks, installed anyway at its measured count (`guardBaseline`). */
33
+ export interface BaselinedGuard {
34
+ readonly name: string;
35
+ readonly findings: number;
36
+ }
37
+
31
38
  export interface GuardInstall {
32
39
  readonly installed: readonly string[];
33
40
  readonly withheld: readonly WithheldGuard[];
41
+ /**
42
+ * Also in `installed`: kept because `x.verify.json` now holds it at this many findings. Absent
43
+ * when none, so a hop that baselined nothing reports exactly what it always did.
44
+ */
45
+ readonly baselined?: readonly BaselinedGuard[];
34
46
  }
35
47
 
36
48
  /** Runs the installed CLI with these arguments in the app root. */
@@ -122,7 +134,9 @@ export async function installMissingGuards(input: {
122
134
  findings: null,
123
135
  });
124
136
  const base = await boundariesCount(cli);
125
- if (base === undefined) return { installed: [], withheld: missing.map(unmeasured) };
137
+ if (base === undefined) {
138
+ return { installed: [], withheld: missing.map(unmeasured) };
139
+ }
126
140
 
127
141
  const written = new Map<string, Generated>();
128
142
  const withheld: WithheldGuard[] = [];
@@ -140,6 +154,7 @@ export async function installMissingGuards(input: {
140
154
  // Newest first, so each artifact ends at the bytes it held before the first run.
141
155
  for (const run of [...written.values()].reverse()) await rollback(root, run);
142
156
  const installed: string[] = [];
157
+ const baselined: BaselinedGuard[] = [];
143
158
  let held = base;
144
159
  for (const guard of missing.filter(({ name }) => written.has(name))) {
145
160
  const run = await generate(cli, root, guard.name);
@@ -149,10 +164,30 @@ export async function installMissingGuards(input: {
149
164
  held = count;
150
165
  continue;
151
166
  }
167
+ // Measured and over: held at its own count, kept only if this CLI's `boundaries` then finds
168
+ // no more than before — a release that ignores `guardBaseline` leaves it withheld, as it was.
169
+ if (run !== undefined && count !== undefined) {
170
+ const findings = count - held;
171
+ const floor = await writeGuardBaseline(root, guard.name, findings);
172
+ if (floor !== undefined) {
173
+ const recount = await boundariesCount(cli);
174
+ if (recount !== undefined && recount <= held) {
175
+ installed.push(guard.name);
176
+ baselined.push({ name: guard.name, findings });
177
+ held = recount;
178
+ continue;
179
+ }
180
+ await restoreFloor(root, floor.prior);
181
+ }
182
+ }
152
183
  await rollback(root, run);
153
184
  withheld.push({ ...guard, findings: count === undefined ? null : count - held });
154
185
  }
155
- return { installed, withheld: sortByName(withheld) };
186
+ return {
187
+ installed,
188
+ withheld: sortByName(withheld),
189
+ ...(baselined.length === 0 ? {} : { baselined }),
190
+ };
156
191
  }
157
192
 
158
193
  const sortByName = (list: readonly WithheldGuard[]): readonly WithheldGuard[] =>
@@ -89,6 +89,9 @@ export const humanLines = (input: {
89
89
  ? [msg(agentsMd === 'link' ? 'cli.upgrade.agentsMd.link' : 'cli.upgrade.agentsMd.differs')]
90
90
  : []),
91
91
  ...(gate?.guards.installed ?? []).map((name) => msg('cli.upgrade.guardInstalled', { name })),
92
+ ...(gate?.guards.baselined ?? []).map((guard) =>
93
+ msg('cli.upgrade.guardBaselined', { name: guard.name, count: guard.findings }),
94
+ ),
92
95
  ...(gate?.guards.withheld ?? []).map((guard) =>
93
96
  guard.findings === null
94
97
  ? msg('cli.upgrade.guardUnmeasured', { fix: guard.add })
@@ -19,9 +19,11 @@
19
19
 
20
20
  // why: Bun ships no recursive delete and no path-join primitive; the lcov parts live under `.x/`.
21
21
  import { rm } from 'node:fs/promises';
22
- // why: Bun ships no path-join primitive.
23
- import { dirname, join } from 'node:path';
24
- import { ISOLATED_ENV } from '@ultimat3/testing';
22
+ // why: Bun ships no path API; `posix.basename` names the module an island chunk was imported by.
23
+ import { dirname, join, posix } from 'node:path';
24
+ import { ISLAND_COVERAGE_ENV, ISOLATED_ENV } from '@ultimat3/testing';
25
+ import type { ChunkPart } from './coverage-island';
26
+ import { ISLAND_MAPS_DIR, readChunkMaps, withIslandChunks } from './coverage-island';
25
27
  import type { CoverageMap } from './coverage-lcov';
26
28
  import { fileCoverageOf, mergeCoverage, parseLcov } from './coverage-lcov';
27
29
  import type { ExecResult, Runner } from './exec';
@@ -170,15 +172,30 @@ export async function runCovered(options: CoveredRunOptions): Promise<CoveredRun
170
172
  options.pace,
171
173
  options.timings !== undefined,
172
174
  ),
173
- { cwd: options.root, env: { ...overrides, ULTIMATE_TEST_WORKER: String(slot) } },
175
+ {
176
+ cwd: options.root,
177
+ env: {
178
+ ...overrides,
179
+ ULTIMATE_TEST_WORKER: String(slot),
180
+ // Where `mountIsland` records each chunk's source map, so the chunk's lines can be
181
+ // credited to the island source rather than to a temp file the cut below drops.
182
+ [ISLAND_COVERAGE_ENV]: join(base, String(index), ISLAND_MAPS_DIR),
183
+ },
184
+ },
174
185
  );
175
186
  }
176
187
  };
177
- let maps: CoverageMap[];
188
+ let parts: SlicePart[];
189
+ let coverage: CoverageMap;
178
190
  let measured: Record<string, number> = {};
179
191
  try {
180
192
  await Promise.all(Array.from({ length: width }, (_, slot) => worker(slot)));
181
- maps = await Promise.all(slices.map((_, index) => readPart(join(base, String(index)))));
193
+ parts = await Promise.all(slices.map((_, index) => readPart(join(base, String(index)))));
194
+ coverage = await withIslandChunks(
195
+ options.root,
196
+ mergeCoverage(parts.map((part) => part.own)),
197
+ parts,
198
+ );
182
199
  if (options.timings !== undefined) {
183
200
  const reports = await Promise.all(
184
201
  slices.map((_, index) => readReport(join(base, String(index)))),
@@ -224,7 +241,7 @@ export async function runCovered(options: CoveredRunOptions): Promise<CoveredRun
224
241
  tests: countsOf(results),
225
242
  ...(first === undefined ? {} : { output }),
226
243
  ...(Object.keys(measured).length === 0 ? {} : { slowest: slowestOf(measured, options.files) }),
227
- coverage: mergeCoverage(maps),
244
+ coverage,
228
245
  };
229
246
  }
230
247
 
@@ -234,17 +251,31 @@ const readReport = (dir: string): Promise<string> =>
234
251
  .text()
235
252
  .catch(() => '');
236
253
 
254
+ /** One slice's lcov: its own tree's records, and what the island chunks need to be credited. */
255
+ interface SlicePart extends ChunkPart {
256
+ readonly own: CoverageMap;
257
+ }
258
+
237
259
  /**
238
260
  * One slice's lcov as a map, kept to the app's own tree: a slice loads a thousand framework files
239
261
  * for every hundred of the app's, and none of those is what the floor measures. No file is no
240
262
  * coverage — the slice died before writing it, and its exit code already says so.
263
+ *
264
+ * The chunk records ride beside it: `mountIsland` imports an island chunk from a temp file, so
265
+ * its record names no app path, and its lines are credited back to the sources its recorded map
266
+ * names once every slice is folded (`coverage-island.ts`).
241
267
  */
242
- async function readPart(dir: string): Promise<CoverageMap> {
268
+ async function readPart(dir: string): Promise<SlicePart> {
243
269
  const file = Bun.file(join(dir, 'lcov.info'));
244
- if (!(await file.exists())) return {};
245
- return Object.fromEntries(
246
- parseLcov(await file.text())
270
+ if (!(await file.exists())) return { own: {}, records: [], maps: new Map() };
271
+ const records = parseLcov(await file.text());
272
+ const own = Object.fromEntries(
273
+ records
247
274
  .filter((record) => /^(?:apps|packages)\//.test(record.file))
248
275
  .map((record) => [record.file, fileCoverageOf(record)]),
249
276
  );
277
+ const maps = await readChunkMaps(dir);
278
+ // Only the chunks are kept past this slice: every slice's whole record list is the corpus again.
279
+ const chunks = records.filter((record) => maps.has(posix.basename(record.file)));
280
+ return { own, records: chunks, maps };
250
281
  }