@ultimat3/cli 30.9.0 → 31.1.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 (215) hide show
  1. package/CLAUDE.md +80 -64
  2. package/README.md +4 -1
  3. package/package.json +30 -29
  4. package/src/admin-registration.ts +1 -1
  5. package/src/affected-base.ts +51 -0
  6. package/src/affected.ts +34 -11
  7. package/src/app-boundaries.ts +88 -9
  8. package/src/app-load-async.ts +133 -0
  9. package/src/app-load-batch.ts +203 -0
  10. package/src/app-load-prebuilt.ts +147 -0
  11. package/src/app-load-register.ts +175 -0
  12. package/src/app-load.ts +143 -175
  13. package/src/app-loader-imports.ts +31 -0
  14. package/src/app-root.ts +13 -0
  15. package/src/app-runtime.ts +5 -1
  16. package/src/boundary-findings.ts +12 -0
  17. package/src/browser-launcher-port.ts +3 -7
  18. package/src/browser-launcher.ts +1 -1
  19. package/src/budgets-scan.ts +8 -0
  20. package/src/budgets.ts +10 -1
  21. package/src/build-registry-background.ts +59 -0
  22. package/src/build-registry.ts +207 -0
  23. package/src/cdp-shot-clock.ts +3 -11
  24. package/src/cdp-shot-driver.ts +3 -2
  25. package/src/cdp-shot-element.ts +3 -2
  26. package/src/cdp-shot-page.ts +2 -2
  27. package/src/cdp-shot-watch.ts +4 -3
  28. package/src/ci-log.ts +76 -13
  29. package/src/cmd-affected-spec.ts +7 -3
  30. package/src/cmd-affected.ts +91 -77
  31. package/src/cmd-auth.ts +3 -3
  32. package/src/cmd-ci.ts +6 -3
  33. package/src/cmd-db-recount.ts +15 -0
  34. package/src/cmd-drill.ts +10 -6
  35. package/src/cmd-exercise.ts +2 -1
  36. package/src/cmd-generate-spec.ts +6 -0
  37. package/src/cmd-generate.ts +22 -4
  38. package/src/cmd-mail.ts +1 -1
  39. package/src/cmd-pr-spec.ts +1 -1
  40. package/src/cmd-pr.ts +72 -1
  41. package/src/cmd-routes.ts +2 -2
  42. package/src/cmd-secrets-spec.ts +4 -1
  43. package/src/cmd-shot.ts +14 -262
  44. package/src/cmd-test-spec.ts +2 -2
  45. package/src/cmd-verify-spec.ts +21 -1
  46. package/src/cmd-verify.ts +16 -4
  47. package/src/coverage-source.ts +4 -1
  48. package/src/db-diagnostics.ts +8 -1
  49. package/src/dev-boot.ts +29 -15
  50. package/src/dev-dashboard-invalidations.ts +43 -0
  51. package/src/dev-dashboard.ts +13 -16
  52. package/src/dev-n-plus-one.ts +7 -3
  53. package/src/dev-rebuild.ts +2 -1
  54. package/src/dev-route-table.ts +1 -1
  55. package/src/dev-traces.ts +16 -15
  56. package/src/document-options.ts +12 -1
  57. package/src/drift-store.ts +55 -0
  58. package/src/error-catalog.ts +8 -3
  59. package/src/error-codes-boundary.ts +32 -0
  60. package/src/error-codes-package.ts +38 -0
  61. package/src/error-codes.ts +28 -40
  62. package/src/errors.ts +17 -7
  63. package/src/exercise-database.ts +13 -1
  64. package/src/exercise-findings.ts +36 -18
  65. package/src/exercise-services.ts +84 -0
  66. package/src/exercise-subject.ts +38 -13
  67. package/src/failure-capture-boot.ts +9 -5
  68. package/src/framework-schema.ts +5 -5
  69. package/src/generate-exercise.ts +1 -1
  70. package/src/generate-files.ts +27 -7
  71. package/src/generate-kinds.ts +5 -0
  72. package/src/generate-refresh.ts +53 -0
  73. package/src/generate-workspace.ts +169 -0
  74. package/src/generate-write.ts +8 -2
  75. package/src/hold.ts +19 -8
  76. package/src/image-prepare.ts +6 -2
  77. package/src/index.ts +5 -20
  78. package/src/island-bundle.ts +7 -3
  79. package/src/island-capture.ts +2 -2
  80. package/src/island-harness.ts +1 -1
  81. package/src/job-registration.ts +43 -6
  82. package/src/jobs-driver.ts +4 -5
  83. package/src/mcp-errors.ts +20 -4
  84. package/src/mcp-host.ts +5 -1
  85. package/src/mcp-ui-interact.ts +3 -0
  86. package/src/messages-gate.ts +10 -0
  87. package/src/new-shapes-generate.ts +1 -1
  88. package/src/otlp-export.ts +94 -29
  89. package/src/output.ts +24 -10
  90. package/src/page-sync.ts +3 -1
  91. package/src/pr-activity.ts +150 -0
  92. package/src/pr-bots.ts +109 -0
  93. package/src/pr-threads.ts +7 -2
  94. package/src/role-load.ts +17 -11
  95. package/src/role-start.ts +5 -4
  96. package/src/role-sync.ts +7 -8
  97. package/src/route-islands-preload.ts +46 -0
  98. package/src/route-islands.ts +6 -2
  99. package/src/runtime-admin.ts +5 -1
  100. package/src/runtime-bindings.ts +25 -19
  101. package/src/runtime-boot-ports.ts +66 -0
  102. package/src/runtime-bus.ts +29 -5
  103. package/src/runtime-cache-bus.ts +53 -0
  104. package/src/runtime-cache.ts +43 -13
  105. package/src/runtime-isr-outcome.ts +5 -4
  106. package/src/runtime-jobs.ts +2 -2
  107. package/src/runtime-keys.ts +37 -0
  108. package/src/runtime-overrides.ts +148 -42
  109. package/src/runtime-port-bindings-queue.ts +36 -0
  110. package/src/runtime-port-bindings.ts +117 -0
  111. package/src/runtime-ports.ts +164 -0
  112. package/src/runtime-purge.ts +41 -28
  113. package/src/runtime-push.ts +7 -3
  114. package/src/runtime-queue.ts +70 -55
  115. package/src/runtime-realtime.ts +5 -5
  116. package/src/runtime-render-document.ts +4 -1
  117. package/src/runtime-services.ts +110 -158
  118. package/src/runtime-storage-boot.ts +111 -0
  119. package/src/runtime-storage-upload.ts +9 -7
  120. package/src/runtime-storage.ts +7 -1
  121. package/src/serve-boot.ts +8 -4
  122. package/src/serve-entry.ts +3 -0
  123. package/src/serve-env.ts +47 -14
  124. package/src/serve-prebuilt-paths.ts +3 -0
  125. package/src/serve-prebuilt.ts +15 -4
  126. package/src/serve.ts +2 -2
  127. package/src/shot-gpu.ts +61 -0
  128. package/src/shot-route.ts +95 -0
  129. package/src/shot-run.ts +189 -0
  130. package/src/shot-verdict.ts +5 -0
  131. package/src/static-cards.ts +3 -2
  132. package/src/static-report.ts +2 -2
  133. package/src/style-bundle.ts +1 -1
  134. package/src/sync-authenticator.ts +17 -18
  135. package/src/templates/action-tests.ts +4 -4
  136. package/src/templates/backfill.ts +5 -8
  137. package/src/templates/entity.ts +3 -0
  138. package/src/templates/github/ci.yml.ts +3 -1
  139. package/src/templates/github/dependabot.yml.ts +73 -0
  140. package/src/templates/job.ts +13 -22
  141. package/src/templates/naming.ts +20 -1
  142. package/src/templates/pinned/docker-compose.yml +1 -1
  143. package/src/templates/query.ts +7 -8
  144. package/src/templates/route.ts +5 -3
  145. package/src/templates/scaffold-api.ts +1 -1
  146. package/src/templates/scaffold-auth.ts +5 -3
  147. package/src/templates/scaffold-claude-commands.ts +6 -3
  148. package/src/templates/scaffold-claude.ts +4 -4
  149. package/src/templates/scaffold-container-compose.ts +2 -4
  150. package/src/templates/scaffold-domain-package.ts +1 -1
  151. package/src/templates/scaffold-entries.ts +6 -1
  152. package/src/templates/scaffold-helm-fences.ts +3 -2
  153. package/src/templates/scaffold-helm.ts +35 -6
  154. package/src/templates/scaffold-repo.ts +47 -135
  155. package/src/templates/scaffold-runtime-ports.ts +62 -0
  156. package/src/templates/scaffold-verify-floor.ts +97 -0
  157. package/src/templates/shapes/overlay.ts +1 -1
  158. package/src/templates/sign-in-oidc.ts +5 -3
  159. package/src/templates/sign-in-shared.ts +28 -10
  160. package/src/templates/workspace.ts +75 -0
  161. package/src/test-ignores.ts +5 -2
  162. package/src/test-select.ts +4 -1
  163. package/src/tsconfig-aliases.ts +85 -0
  164. package/src/upgrade-gate.ts +30 -5
  165. package/src/upgrade-report.ts +7 -1
  166. package/src/verify-changed-facts.ts +53 -0
  167. package/src/verify-changed-scope.ts +162 -0
  168. package/src/verify-changed.ts +174 -0
  169. package/src/verify-checks.ts +33 -19
  170. package/src/verify-drift-owner.ts +30 -0
  171. package/src/verify-e2e.ts +2 -1
  172. package/src/verify-factories.ts +86 -0
  173. package/src/verify-run.ts +13 -11
  174. package/src/verify-step.ts +13 -0
  175. package/src/verify-tests.ts +58 -6
  176. package/src/workspace-external-deps.ts +164 -0
  177. package/src/write-line.ts +21 -6
  178. package/wiki/Actions.md +2 -2
  179. package/wiki/Adapters.md +400 -0
  180. package/wiki/Admin-Dashboard.md +1 -1
  181. package/wiki/Agents.md +9 -9
  182. package/wiki/Auth.md +78 -2
  183. package/wiki/Building-Your-Own-Base.md +1 -1
  184. package/wiki/CLI-Reference.md +45 -14
  185. package/wiki/Caching-And-Invalidation.md +17 -5
  186. package/wiki/Compared.md +8 -2
  187. package/wiki/Configuration.md +14 -14
  188. package/wiki/Deployment.md +28 -1
  189. package/wiki/Entities-And-Migrations.md +47 -1
  190. package/wiki/FAQ.md +8 -2
  191. package/wiki/Feature-Flags.md +1 -1
  192. package/wiki/Home.md +3 -2
  193. package/wiki/Jobs-And-Workflows.md +107 -6
  194. package/wiki/Known-Gaps.md +4 -3
  195. package/wiki/MCP-And-AI.md +18 -4
  196. package/wiki/Mail.md +14 -5
  197. package/wiki/Migrations-And-Backfills.md +29 -4
  198. package/wiki/Money.md +2 -0
  199. package/wiki/N-Plus-One-Detection.md +24 -22
  200. package/wiki/Notify.md +28 -4
  201. package/wiki/Observability.md +121 -15
  202. package/wiki/Queries-And-Live-Queries.md +2 -2
  203. package/wiki/Realtime.md +9 -4
  204. package/wiki/Routes-And-Render-Modes.md +5 -0
  205. package/wiki/Scraping.md +57 -11
  206. package/wiki/Shapes.md +2 -2
  207. package/wiki/Stability.md +7 -5
  208. package/wiki/Storage-And-Uploads.md +56 -4
  209. package/wiki/Testing.md +65 -52
  210. package/wiki/Troubleshooting.md +1 -1
  211. package/wiki/Tutorial-01-First-App.md +1 -1
  212. package/wiki/Tutorial-04-Jobs-And-Realtime.md +1 -1
  213. package/wiki/Tutorial-05-Deploy-Free.md +1 -1
  214. package/wiki/Tutorial-06-Growing-Up.md +8 -8
  215. package/wiki/Upgrading.md +136 -5
package/src/cmd-shot.ts CHANGED
@@ -5,15 +5,13 @@
5
5
  // Never a step of `x verify`: it needs a real browser, and a gate that goes red because a machine
6
6
  // has no Chrome is a gate that fails for reasons unrelated to the change.
7
7
 
8
- import { mkdirSync } from 'node:fs';
9
8
  import { join, resolve } from 'node:path';
10
9
  import { renderFixShellArg } from '@ultimat3/core';
11
10
  import { appLocaleSet } from '@ultimat3/i18n/app-catalogs';
12
11
  import { IDLE_HYDRATE_TIMEOUT_MS } from '@ultimat3/render';
13
12
  import { requireAppRoot } from './app-root';
14
13
  import { appBrowser } from './browser-launcher';
15
- import type { ShotColorScheme, ShotDriver, ShotPage, ShotSession } from './browser-launcher-port';
16
- import { DEFAULT_PAGE_TIMEOUT_MS, systemShotClock } from './cdp-shot-clock';
14
+ import { DEFAULT_PAGE_TIMEOUT_MS } from './cdp-shot-clock';
17
15
  import {
18
16
  islandShot,
19
17
  islandShotResult,
@@ -33,130 +31,34 @@ import {
33
31
  } from './cmd-shot-matrix';
34
32
  import { shotSpec } from './cmd-shot-spec';
35
33
  import type { CliCommand, CommandContext } from './command';
36
- import { BadFlagError, MissingPositionalError } from './errors';
34
+ import { BadFlagError } from './errors';
37
35
  import { intFlagOr, PORT_RANGE } from './flag-number';
38
36
  import type { CommandResult } from './output';
39
37
  import type { ParsedArgs } from './parse';
40
38
  import { flagBool, flagString } from './parse';
41
39
  import { shotBrowserChoice } from './shot-browser';
42
- import { readCookieFlag, type ShotCookiePair, shotCookies } from './shot-cookie';
43
- import { acceptLanguageHeaders, localizedShotPath, readLocaleFlag } from './shot-locale';
40
+ import { readCookieFlag } from './shot-cookie';
41
+ import { localizedShotPath, readLocaleFlag } from './shot-locale';
42
+ import { readRoute, shotSlug } from './shot-route';
43
+ import { runShot } from './shot-run';
44
44
  import type { BootDevServer, ShotServer } from './shot-server';
45
45
  import { allowHostsFrom, devServerFor, SHOT_DIR } from './shot-server';
46
- import { SETTLE_POLL_MS, settleIslands } from './shot-settle';
47
- import { readThemeFlag, themeChoiceExpression } from './shot-theme';
48
- import type { IslandCount, ShotArtifacts } from './shot-verdict';
49
- import {
50
- buildVerdict,
51
- documentStatus,
52
- ISLAND_PROBE,
53
- parseIslandProbe,
54
- shotLines,
55
- shotSummary,
56
- verdictJson,
57
- } from './shot-verdict';
46
+ import { readThemeFlag } from './shot-theme';
47
+ import type { ShotArtifacts } from './shot-verdict';
48
+ import { shotLines, shotSummary, verdictJson } from './shot-verdict';
58
49
  import { parseViewports, refuseViewportWithComponent, runShotViewports } from './shot-viewport';
59
50
 
60
51
  /** Kernel-picked by default: :3000 is usually another project's dev server, not a free port. */
61
52
  const DEFAULT_PORT = 0;
62
53
 
63
- // Re-exported, not re-declared: a second declaration of a path or a host rule is a second answer.
54
+ // Re-exported, not re-declared: a second declaration of a path, a host rule, the route rule or the
55
+ // capture is a second answer. The route rule is `shot-route.ts`'s, the capture `shot-run.ts`'s.
56
+ export { readRoute, shotSlug } from './shot-route';
57
+ export type { ShotRun } from './shot-run';
58
+ export { runShot, SHOT_IMAGE, SHOT_VERDICT } from './shot-run';
64
59
  export type { BootDevServer, ShotServer };
65
60
  export { allowHostsFrom, devServerFor, SHOT_DIR };
66
61
 
67
- export const SHOT_IMAGE = 'shot.png';
68
- export const SHOT_VERDICT = 'verdict.json';
69
-
70
- /** A directory name a route can never escape: everything that is not a letter or digit is a dash. */
71
- export function shotSlug(route: string): string {
72
- const slug = route.replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-+|-+$/g, '');
73
- return slug === '' ? 'root' : slug.toLowerCase();
74
- }
75
-
76
- const pathOf = (url: string): string => {
77
- try {
78
- return new URL(url).pathname;
79
- } catch {
80
- return '/';
81
- }
82
- };
83
-
84
- /**
85
- * A reserved name (RFC 2606) that resolves nowhere, so the origin check below can never be
86
- * satisfied by an accident of what the app's own host happens to be.
87
- */
88
- const ROUTE_BASE = 'http://route.invalid';
89
-
90
- /**
91
- * Where a browser would actually go. The refusal above reads `scheme:` and nothing else, and this
92
- * is the question it was standing in for: a path is a path only if resolving it lands back on the
93
- * origin it was resolved against.
94
- */
95
- const resolvedOrigin = (path: string): string => {
96
- try {
97
- return new URL(path, ROUTE_BASE).origin;
98
- } catch {
99
- // A path `new URL` will not parse is one no browser will fetch either, and reporting it as the
100
- // origin it is not is the honest answer here.
101
- return '';
102
- }
103
- };
104
-
105
- const refuseRoute = (reason: string): never => {
106
- throw new BadFlagError({
107
- flag: 'route',
108
- command: 'shot',
109
- reason,
110
- // A placeholder, because there is nothing safe to substitute: unlike an absolute URL, an
111
- // origin-escaping route carries no path the caller can be assumed to have meant.
112
- fix: 'x shot /<path> --json',
113
- });
114
- };
115
-
116
- /**
117
- * A path on the app, never a URL. `x shot https://example.com` would photograph somebody else's
118
- * site through a headless browser inside your network, which is the SSRF shape `allowHosts` exists
119
- * to refuse — so it is refused here, at the argument, where the reader can still see why.
120
- *
121
- * `scheme:` was the ONLY spelling refused until 2026-08-22, and it is one of four: `//evil/x` is a
122
- * protocol-relative URL, `\evil\x` is the same thing to every URL parser (a backslash IS a slash
123
- * for a special scheme), and a TAB inside the path is deleted by the parser before the host is
124
- * read, so `/⇥/evil/x` becomes `//evil/x`. Each one reached `new URL(route, server.url)` and came
125
- * back pointed at another host. `allowHostsFrom` one layer down could not catch any of them: it
126
- * allows a HOSTNAME, and the hostname it is given is the one the page has already left — which is
127
- * how `x shot //localhost:9200/_cat/indices` photographed whatever else was on the dev box.
128
- */
129
- export function readRoute(raw: string | undefined): string {
130
- if (raw === undefined || raw.trim() === '') {
131
- throw new MissingPositionalError({ command: 'shot', positional: 'route', example: 'x shot /' });
132
- }
133
- const route = raw.trim();
134
- if (/^[a-z][a-z0-9+.-]*:/i.test(route)) {
135
- throw new BadFlagError({
136
- flag: 'route',
137
- command: 'shot',
138
- reason: `"${route}" is an absolute URL; x shot photographs a route of the app under test`,
139
- // The path out of the URL when it parses — the refusal's own fix line has to be runnable,
140
- // and `new URL('http://')` throws, so the fallback is the route every app has.
141
- fix: `x shot ${pathOf(route)} --json`,
142
- });
143
- }
144
- const path = route.startsWith('/') ? route : `/${route}`;
145
- // Its own refusal rather than folded into the origin check: `/a\b` stays on this origin and is
146
- // still not the route that was typed — the verdict would record `/a\b` beside a picture of
147
- // `/a/b`, which is the artifact lying about its own subject.
148
- if (path.includes('\\')) {
149
- return refuseRoute(`"${route}" contains a backslash, which a URL parser reads as "/"`);
150
- }
151
- const origin = resolvedOrigin(path);
152
- if (origin !== ROUTE_BASE) {
153
- return refuseRoute(
154
- `"${route}" is not a path on the app: a browser resolves it to ${origin === '' ? 'no URL at all' : origin}`,
155
- );
156
- }
157
- return path;
158
- }
159
-
160
62
  /**
161
63
  * The three integer flags, each read with its NAME as an argument. `intFlagOr` takes the name in a
162
64
  * `name:` field, which `flag-reads.ts` counts as a declaration rather than a read — so a command
@@ -182,156 +84,6 @@ const intFlag = (
182
84
  fallback,
183
85
  );
184
86
 
185
- export interface ShotRun {
186
- readonly route: string;
187
- readonly outDir: string;
188
- readonly driver: ShotDriver;
189
- readonly boot: () => Promise<ShotServer>;
190
- readonly settleMs: number;
191
- readonly timeoutMs: number;
192
- readonly fullPage: boolean;
193
- /**
194
- * `--allow-hosts`, verbatim. The app's own host is added once the server is up and never here:
195
- * with `--port 0` the port — and therefore the origin — does not exist until after the boot.
196
- */
197
- readonly extraHosts?: string | undefined;
198
- /**
199
- * The theme the picture is of. Two things happen BEFORE navigation, because the boot script runs
200
- * inline and nothing after `goto` can reach it: `prefers-color-scheme` is emulated so the boot's
201
- * "system" branch answers the same on every box, AND the scheme is stored as the visitor's
202
- * choice under `THEME_STORAGE_KEY` (`shot-theme.ts`), because an app with `theme.defaultMode`
203
- * set answers that before the OS and only a stored choice beats it (issue #489). Absent means
204
- * neither: the box's own preference and the app's own default — what `x shot` has always done,
205
- * and the point of `defaultMode` — and `ui.shot` names one explicitly for exactly that reason.
206
- */
207
- readonly colorScheme?: ShotColorScheme | undefined;
208
- /** CSS pixels the page is laid out in; absent is the driver's default. */
209
- readonly viewport?: { readonly width: number; readonly height: number } | undefined;
210
- /**
211
- * Sent as `Accept-Language` on every request. The command always sets it — `--locale`, or the
212
- * app's default locale — so a picture never depends on the language of the machine's Chrome.
213
- */
214
- readonly acceptLanguage?: string | undefined;
215
- /**
216
- * `--cookie`: set before the first navigation, each for the server's own URL once it is up —
217
- * so a consent banner (or any cookie-held choice) is decided in the picture.
218
- */
219
- readonly cookies?: readonly ShotCookiePair[] | undefined;
220
- readonly now?: (() => Date) | undefined;
221
- /**
222
- * `--expect-status`: the document status this shot is ok with — `404` to photograph the not-found
223
- * page on purpose. Absent means any 2xx, and anything else fails the verdict with the status.
224
- */
225
- readonly expectStatus?: number | undefined;
226
- /**
227
- * Something to do with the page AFTER the islands settled and BEFORE the picture — `ui.inspect`
228
- * reads the DOM here, on the one navigation the picture already paid for. `settle` re-runs the
229
- * island poll (an action that mounts something changes the count the verdict reports); the
230
- * caller who never calls it gets the count from the first settle.
231
- */
232
- readonly act?:
233
- | ((page: ShotPage, settle: () => Promise<IslandCount | null>) => Promise<void>)
234
- | undefined;
235
- }
236
-
237
- /** Nothing here may replace the failure that caused it, so a teardown throw is swallowed. */
238
- const quietly = async (stop: () => Promise<void>): Promise<void> => {
239
- await stop().catch(() => undefined);
240
- };
241
-
242
- /**
243
- * Boot (or find) the server, photograph one route, write both artifacts. The driver and the boot
244
- * are ARGUMENTS: `bun test` drives this with `fakeBrowser()` and a stub server, so the whole
245
- * command is proved on a machine with no Chrome — which this command is explicitly excluded from
246
- * the gate for needing.
247
- */
248
- export async function runShot(options: ShotRun): Promise<ShotArtifacts> {
249
- const server = await options.boot();
250
- let session: ShotSession | undefined;
251
- try {
252
- const requestedUrl = new URL(options.route, server.url).toString();
253
- session = await options.driver.open({
254
- name: 'x shot',
255
- // The host the picture is of, plus whatever the caller named. Never `*`: a headless browser
256
- // inside your network is the widest SSRF surface an app can own, and a screenshot command is
257
- // not the place to open it by default. Every refusal lands in the verdict's `refused` count.
258
- rules: { allowHosts: allowHostsFrom(server.url, options.extraHosts) },
259
- clock: systemShotClock,
260
- timeoutMs: options.timeoutMs,
261
- ...(options.viewport === undefined ? {} : { viewport: options.viewport }),
262
- ...(options.acceptLanguage === undefined
263
- ? {}
264
- : { headers: acceptLanguageHeaders(options.acceptLanguage) }),
265
- ...(options.cookies === undefined || options.cookies.length === 0
266
- ? {}
267
- : { cookies: shotCookies(options.cookies, new URL(server.url).toString()) }),
268
- });
269
- const page = session.page;
270
- if (options.colorScheme !== undefined) {
271
- await page.colorScheme(options.colorScheme);
272
- const choice = themeChoiceExpression(options.colorScheme);
273
- if (choice !== undefined) await page.prepare(choice);
274
- }
275
- await page.goto(requestedUrl, { timeout: options.timeoutMs });
276
- // Read NOW as well as at capture: the network ring is bounded, and a page that fires a few
277
- // hundred requests while it settles evicts the document entry the verdict needs.
278
- const landedStatus = documentStatus(page.network(), page.url());
279
- if (options.settleMs > 0) await Bun.sleep(options.settleMs);
280
- // The probe may legitimately answer nothing — a page that refuses evaluation, a driver with no
281
- // JS engine. `null` says so; a `0` would read as "the route renders no islands", which is a
282
- // different and much more alarming claim.
283
- const probe = (): Promise<IslandCount | null> =>
284
- page
285
- .evaluate(ISLAND_PROBE)
286
- .then(parseIslandProbe)
287
- .catch(() => null);
288
- // The same budget again, and deliberately no new flag: `settleMs` is the deadline at which the
289
- // runtime CALLS `import()`, so a mount gets exactly as long to settle as the runtime got to
290
- // start it — and `--settle 0`, which asks for no wait, still gets none.
291
- const settle = (): Promise<IslandCount | null> =>
292
- settleIslands(probe, { windowMs: options.settleMs, pollMs: SETTLE_POLL_MS });
293
- let islands = await settle();
294
- if (options.act !== undefined) {
295
- await options.act(page, async () => {
296
- islands = await settle();
297
- return islands;
298
- });
299
- }
300
- const bytes = await page.screenshot({ fullPage: options.fullPage });
301
- // Read AFTER the capture, so an error logged while the page settled is in the verdict that
302
- // ships with the picture it explains.
303
- const verdict = buildVerdict({
304
- route: options.route,
305
- requestedUrl,
306
- finalUrl: page.url(),
307
- server: server.origin,
308
- capturedAt: (options.now ?? (() => new Date()))().toISOString(),
309
- screenshot: SHOT_IMAGE,
310
- bytes,
311
- console: page.console(),
312
- pageErrors: page.pageErrors(),
313
- pageErrorsDropped: page.pageErrorsDropped(),
314
- network: page.network(),
315
- networkDropped: page.networkDropped(),
316
- islands,
317
- landedStatus,
318
- ...(options.expectStatus === undefined ? {} : { expectStatus: options.expectStatus }),
319
- });
320
- mkdirSync(options.outDir, { recursive: true });
321
- const image = join(options.outDir, SHOT_IMAGE);
322
- const verdictFile = join(options.outDir, SHOT_VERDICT);
323
- await Bun.write(image, bytes);
324
- await Bun.write(verdictFile, `${JSON.stringify(verdictJson(verdict), null, 2)}\n`);
325
- return { verdict, image, verdictFile };
326
- } finally {
327
- // Bound to a const: narrowing a `let` does not survive into the closure below, and the session
328
- // has to be closed from inside one so a teardown throw cannot replace the real failure.
329
- const open = session;
330
- if (open !== undefined) await quietly(() => open.close());
331
- await quietly(() => server.stop());
332
- }
333
- }
334
-
335
87
  /**
336
88
  * Where the artifacts land. A relative `--out` is a path the caller typed from where they stand,
337
89
  * so it resolves against the cwd — `x build --out`'s rule. Against the app root it landed
@@ -2,7 +2,7 @@
2
2
  // read it without loading `cmd-test.ts`, which `registry.ts` imports only when the command runs.
3
3
 
4
4
  import { TEST_TYPES } from '@ultimat3/testing/test-types';
5
- import { DEFAULT_BASE } from './affected';
5
+ import { DEFAULT_BASE_HELP } from './affected-base';
6
6
  import type { CommandSpec } from './parse';
7
7
  import {
8
8
  BUDGET_RULE,
@@ -60,7 +60,7 @@ export const testSpec: CommandSpec = {
60
60
  {
61
61
  name: 'base',
62
62
  type: 'string',
63
- summary: `--affected: git ref to diff against, merge-base style (default: ${DEFAULT_BASE})`,
63
+ summary: `--affected: git ref to diff against, merge-base style (default: ${DEFAULT_BASE_HELP})`,
64
64
  },
65
65
  {
66
66
  name: 'seed',
@@ -1,6 +1,7 @@
1
1
  // `x verify`'s declaration, apart from its body: the parser, `x help` and the `errors` step
2
2
  // read it without loading `cmd-verify.ts`, which `registry.ts` imports only when the command runs.
3
3
 
4
+ import { DEFAULT_BASE_HELP } from './affected-base';
4
5
  import type { CommandSpec } from './parse';
5
6
  import { BUDGET_RULE, WORKER_BYTES, WORKER_CEILING, WORKER_FLOOR } from './test-workers';
6
7
 
@@ -11,7 +12,7 @@ export const verifySpec: CommandSpec = {
11
12
  name: 'verify',
12
13
  summary: 'the gate: typecheck, lint, boundaries, all tests, drift, contract, budgets',
13
14
  usage:
14
- 'x verify [--only <step>[,<step>…] [--shard i/n [--timings file]]] [--workers N] [--isolate] [--json] · x verify merge <part.json…> [--json]',
15
+ 'x verify [--only <step>[,<step>…] [--shard i/n [--timings file]] | --changed [--base <ref>] [--dirty]] [--workers N] [--isolate] [--json] · x verify merge <part.json…> [--json]',
15
16
  requiresApp: true,
16
17
  subcommands: VERIFY_SUBCOMMANDS,
17
18
  defaultSubcommand: 'run',
@@ -33,6 +34,25 @@ export const verifySpec: CommandSpec = {
33
34
  summary:
34
35
  'run the named step(s), comma-separated, in one process — an iteration loop or one CI job, NOT A GATE RUN; the gate is this command with no flag, or `x verify merge` over every job',
35
36
  },
37
+ {
38
+ name: 'changed',
39
+ type: 'boolean',
40
+ subcommands: ['run'],
41
+ summary:
42
+ 'run only the steps whose inputs the diff touches, each named with the files that chose it (data.changed) — NOT A GATE RUN; never with --only',
43
+ },
44
+ {
45
+ name: 'base',
46
+ type: 'string',
47
+ subcommands: ['run'],
48
+ summary: `with --changed: git ref to diff against, merge-base style, as x affected reads it (default: ${DEFAULT_BASE_HELP})`,
49
+ },
50
+ {
51
+ name: 'dirty',
52
+ type: 'boolean',
53
+ subcommands: ['run'],
54
+ summary: 'with --changed: also count uncommitted and untracked work',
55
+ },
36
56
  {
37
57
  name: 'shard',
38
58
  type: 'string',
package/src/cmd-verify.ts CHANGED
@@ -2,7 +2,8 @@
2
2
  // same list in the terminal and in --json, and a non-zero exit if any step fails. Green means
3
3
  // shippable (axiom 5): one step list, no second checklist, no CI-only step.
4
4
  //
5
- // `--only <step>[,<step>…]` is the ONE narrowing, decided as D6, and it does not weaken that: the
5
+ // `--only <step>[,<step>…]` is the ONE narrowing, decided as D6 — `--changed` is the same narrowing
6
+ // with the list derived from the diff (`verify-changed.ts`) — and it does not weaken that: the
6
7
  // GATE is the no-flag run, and a narrowed run says `NOT A GATE RUN` in the summary and in `--json` so no
7
8
  // reader of either can take it for one. `--skip` stays refused — it would let a caller drop the
8
9
  // step that was going to fail and still read the output as a whole-tree verdict.
@@ -19,6 +20,7 @@ import type { CommandResult, JsonValue } from './output';
19
20
  import type { ParsedArgs } from './parse';
20
21
  import { flagBool, flagString } from './parse';
21
22
  import { WORKER_CEILING, WORKER_FLOOR } from './test-workers';
23
+ import { changedScope, readChangedRun, withChangedData } from './verify-changed-scope';
22
24
  import { VERIFY_STEPS } from './verify-checks';
23
25
  import { readVerifyFloor } from './verify-floor';
24
26
  import type { VerifyPart } from './verify-merge';
@@ -46,8 +48,14 @@ export const verifyCommand: CliCommand = {
46
48
  // Every reader before the run: an unrunnable flag must be refused in milliseconds, not after
47
49
  // `tsc -b` has spent fourteen seconds on a run the caller cannot use.
48
50
  const workers = readWorkers(ctx.args);
49
- const only = readOnlySteps(ctx.args);
50
- const shard = await readShard(ctx.args, only);
51
+ const onlyFlag = readOnlySteps(ctx.args);
52
+ // `--changed` is `--only` with the list derived from the diff — the same banner, the same
53
+ // `notAGateRun`, and the plan in `data.changed` so a reader sees why each step was chosen.
54
+ const changed = readChangedRun(ctx.args, onlyFlag)
55
+ ? await changedScope({ runner: ctx.runner, root, args: ctx.args })
56
+ : undefined;
57
+ const only = changed === undefined ? onlyFlag : changed.plan.steps.map((step) => step.name);
58
+ const shard = await readShard(ctx.args, onlyFlag);
51
59
  const isolate = flagBool(ctx.args, 'isolate') ? true : undefined;
52
60
  // Either render prints its verdict only when the run ends; the progress on stderr — a line per
53
61
  // finished step, a heartbeat while one runs — is what a cancelled job's log ends on (#589) and
@@ -62,10 +70,14 @@ export const verifyCommand: CliCommand = {
62
70
  ...(only === undefined ? {} : { only }),
63
71
  ...(shard === undefined ? {} : { shard }),
64
72
  ...(isolate === undefined ? {} : { isolate }),
73
+ ...(changed?.tests === undefined
74
+ ? {}
75
+ : { tests: { scope: changed.tests.scope, whole: changed.tests.whole } }),
65
76
  ...progress,
66
77
  }),
67
78
  );
68
- return shard === undefined ? result : withShardData(result, shard);
79
+ const sharded = shard === undefined ? result : withShardData(result, shard);
80
+ return changed === undefined ? sharded : withChangedData(sharded, changed);
69
81
  },
70
82
  };
71
83
 
@@ -36,7 +36,10 @@ function endOfTypeAlias(text: string, from: number): number {
36
36
  for (let i = from; i < text.length; i += 1) {
37
37
  const ch = text[i];
38
38
  if (ch === '{' || ch === '[' || ch === '(' || ch === '<') depth += 1;
39
- else if (ch === '}' || ch === ']' || ch === ')' || ch === '>') depth -= 1;
39
+ // The `>` of `=>` closes nothing: counted, an arrow type drove depth below zero and the alias
40
+ // "ended" at a `;` inside its own braces, leaving the rest to read as code.
41
+ else if (ch === '}' || ch === ']' || ch === ')' || (ch === '>' && text[i - 1] !== '='))
42
+ depth -= 1;
40
43
  else if (ch === ';' && depth <= 0) return i + 1;
41
44
  }
42
45
  return text.length;
@@ -59,6 +59,9 @@ export function renderDiagnostics(report: DbDiagnostics): readonly string[] {
59
59
  });
60
60
  }
61
61
 
62
+ /** The whole `x db diagnostics` budget on an embedded database, its cold boot included. */
63
+ export const EMBEDDED_DIAGNOSTICS_DEADLINE_MS = 30_000;
64
+
62
65
  /**
63
66
  * `startDb`, not `startQueue`: the queue's boot applies the framework tables, and a diagnostic
64
67
  * must write nothing. An embedded database `x dev` holds is refused rather than opened twice:
@@ -87,7 +90,11 @@ export async function runDiagnostics(ctx: CommandContext, root: string): Promise
87
90
  }
88
91
  const started = startDb(services, ctx.env);
89
92
  try {
90
- const report = await dbDiagnostics({ client: started.client, limit });
93
+ // Embedded, the probe IS the boot — a WASM compile and an initdb, 12.6 s cold under coverage —
94
+ // so the 3 s probe wait answered a healthy database X_DB_UNAVAILABLE. A server keeps the default.
95
+ const deadlineMs =
96
+ services.db.mode === 'embedded' ? EMBEDDED_DIAGNOSTICS_DEADLINE_MS : undefined;
97
+ const report = await dbDiagnostics({ client: started.client, limit, deadlineMs });
91
98
  const sections = Object.values(report);
92
99
  return {
93
100
  ok: true,
package/src/dev-boot.ts CHANGED
@@ -5,8 +5,7 @@
5
5
 
6
6
  import { devShellStyle } from '@ultimat3/admin/dev';
7
7
  import type { Role } from '@ultimat3/core';
8
- import { configureTelemetry, noopExporter } from '@ultimat3/core';
9
- import { setStatementObserver } from '@ultimat3/db';
8
+ import { subscribe, subscribeSemconvMetrics } from '@ultimat3/core';
10
9
  import type { OverlayNotice, RequestContext } from '@ultimat3/http';
11
10
  import { asCtx } from '@ultimat3/http';
12
11
  import { loadSignInPath } from './app-auth';
@@ -17,6 +16,7 @@ import { enableReloadTracking } from './app-reload-graph';
17
16
  import { loadAppRuntime } from './app-runtime';
18
17
  import type { DevDashboardInput, DevStatus } from './dev-dashboard';
19
18
  import { devPanels } from './dev-dashboard';
19
+ import { createInvalidationLog } from './dev-dashboard-invalidations';
20
20
  import { declareDevEnvironment, needsDevEnvironmentDeclaration } from './dev-environment';
21
21
  import { createStatementLedger } from './dev-n-plus-one';
22
22
  import type { DevState } from './dev-rebuild';
@@ -128,7 +128,7 @@ export async function startDev(options: StartDevOptions): Promise<DevServer> {
128
128
  true,
129
129
  );
130
130
  // The events binding the boot line reports is the bus the runtime chose, read off it.
131
- const services = withRealtimeEvents(resolved, env, runtime.realtime);
131
+ const services = withRealtimeEvents(resolved, env, appRuntime?.transport !== undefined);
132
132
  // `serve.ts`'s `releaseBoot` shape: everything acquired from here on is released, newest first,
133
133
  // if the boot throws — a failed `x dev` left PGlite holding `.x/pgdata` for the retry to meet.
134
134
  const acquired: (() => void | Promise<void>)[] = [() => runtime.stop()];
@@ -148,23 +148,36 @@ async function bootDev(
148
148
  appRuntime: RuntimeOverrides | undefined,
149
149
  ): Promise<DevServer> {
150
150
  // Installed before the app loads, so a span opened during registration is already recorded.
151
- // Tracing is always on in the framework and free until an exporter is configured; `x dev` is
152
- // what configures one, which is the whole reason `/_x/timeline` has anything to draw.
151
+ // Tracing is always on in the framework and free until something subscribes to `span.end`;
152
+ // `x dev`'s recorder is that subscriber, which is the whole reason `/_x/timeline` has anything.
153
153
  const traces = createTraceRecorder();
154
- configureTelemetry({ exporter: traces.exporter });
154
+ const unsubscribeTraces = subscribe('span.end', (event) => traces.exporter.export(event.payload));
155
155
  acquired.push(() => {
156
- configureTelemetry({ exporter: noopExporter });
156
+ unsubscribeTraces();
157
157
  traces.reset();
158
158
  });
159
- // Installed at the same moment and for the same reason: an observer is the single switch that
160
- // turns statement instrumentation on at all (`@ultimat3/db`'s `observe.ts`), so the timeline's
161
- // SQL rows and the repeat counts arrive together rather than through two toggles. `serve.ts`
162
- // installs neither — a production process pays the one `undefined` branch the seam costs
163
- // uninstalled, and nothing more (axiom 6).
159
+ // Subscribed at the same moment and for the same reason: the timeline's SQL rows and the repeat
160
+ // counts arrive together. A subscriber, never a slot — the app's own `db.statement` listeners
161
+ // hear the same events beside it. The production boot subscribes ONE: the semconv histograms
162
+ // (`subscribeSemconvMetrics`), so every statement there pays a dispatch, an event object and a
163
+ // histogram record — never this ledger, which keeps every statement's text.
164
164
  const statements = createStatementLedger();
165
- setStatementObserver(statements.observer);
165
+ const unsubscribeStatements = subscribe('db.statement', (event) =>
166
+ statements.observer.onStatement(event.payload),
167
+ );
168
+ // The semconv histograms (`db_client_operation_duration_seconds`, …) on `x dev`'s `/metrics` too,
169
+ // so a dashboard built against dev reads the series production exports.
170
+ const unsubscribeMetrics = subscribeSemconvMetrics();
171
+ // The `/_x` cache panel's history: the cache keeps no log of its own, the panel subscribes one.
172
+ const invalidations = createInvalidationLog();
173
+ const unsubscribeInvalidations = subscribe('cache.invalidate', (event) =>
174
+ invalidations.record(event.payload),
175
+ );
166
176
  acquired.push(() => {
167
- setStatementObserver(undefined);
177
+ unsubscribeInvalidations();
178
+ invalidations.reset();
179
+ unsubscribeMetrics();
180
+ unsubscribeStatements();
168
181
  statements.reset();
169
182
  });
170
183
  // ONE load at boot, the same call the rebuild below makes: the manifest and the findings are
@@ -188,7 +201,7 @@ async function bootDev(
188
201
  }),
189
202
  );
190
203
  // ON in `x dev` whatever `app.config.ts` says: a 5xx here is one `x repro <requestId>` away.
191
- acquired.push(armFailureCapture(appConfig, { force: true }));
204
+ acquired.push(armFailureCapture(appConfig, { force: true, store: runtime.failureStore }));
192
205
  // The manifest's build id is a content hash of every fact below it, so a dev document's
193
206
  // `x-ultimate-build` header names the exact shape the client was served against. Pinned at
194
207
  // boot on purpose: the header is handed to the HTTP config and the render modes once, and a
@@ -216,6 +229,7 @@ async function bootDev(
216
229
  }),
217
230
  traces,
218
231
  statements,
232
+ invalidations,
219
233
  ...envOf(options.env),
220
234
  };
221
235
  const panels = devPanels(dashboard).map((panel) => panel.key);
@@ -0,0 +1,43 @@
1
+ // The `/_x` cache panel's log: every `cache.invalidate` event this process emitted, newest first,
2
+ // bounded. A bus subscriber `x dev` installs at boot — the cache package keeps no ring buffer of
3
+ // its own (`X_INSTRUMENT_SLOT_FORBIDDEN`), so the one panel that reads the history holds it.
4
+
5
+ import type { InvalidationFact } from '@ultimat3/admin/dev';
6
+ import type { CacheInvalidateEvent, Clock } from '@ultimat3/core';
7
+ import { finiteCount, systemClock } from '@ultimat3/core';
8
+
9
+ /** The panel shows recent busts; it does not page through history. The cache's old log's figure. */
10
+ const DEFAULT_LIMIT = 100;
11
+
12
+ export interface InvalidationLog {
13
+ /** Feed it every bust: `subscribe('cache.invalidate', (e) => log.record(e.payload))`. */
14
+ record(event: CacheInvalidateEvent): void;
15
+ /** Newest first, a copy. */
16
+ facts(): readonly InvalidationFact[];
17
+ reset(): void;
18
+ }
19
+
20
+ export function createInvalidationLog(
21
+ options: { readonly limit?: number; readonly clock?: Clock } = {},
22
+ ): InvalidationLog {
23
+ const limit = finiteCount('createInvalidationLog', 'limit', options.limit ?? DEFAULT_LIMIT, 1);
24
+ const clock = options.clock ?? systemClock;
25
+ let log: InvalidationFact[] = [];
26
+ return {
27
+ record(event) {
28
+ log.unshift({
29
+ at: clock.now().toISOString(),
30
+ tags: event.tags,
31
+ busted: event.busted,
32
+ // The span active when the bust was ASKED for, stamped by the cache at the call — the
33
+ // subscriber runs inside the cache's own span, whose name would be every row's source.
34
+ source: event.source ?? 'cache',
35
+ });
36
+ if (log.length > limit) log.length = limit;
37
+ },
38
+ facts: () => [...log],
39
+ reset() {
40
+ log = [];
41
+ },
42
+ };
43
+ }