@ultimat3/cli 31.49.0 → 31.50.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 (53) hide show
  1. package/package.json +30 -30
  2. package/src/api-registration.ts +18 -1
  3. package/src/api-routes.ts +1 -0
  4. package/src/app-load.ts +1 -2
  5. package/src/app-openapi.ts +7 -1
  6. package/src/budgets.ts +2 -1
  7. package/src/cmd-i18n.ts +33 -1
  8. package/src/codemods/engine-fs.ts +9 -2
  9. package/src/codemods/merge-drivers.ts +85 -4
  10. package/src/exercise-services.ts +13 -3
  11. package/src/framework-schema.ts +15 -5
  12. package/src/guard-sources.ts +1 -2
  13. package/src/messages-upgrade.ts +4 -0
  14. package/src/page-navigation.ts +5 -2
  15. package/src/pwa-artifacts.ts +1 -1
  16. package/src/retained-assets-boot.ts +1 -1
  17. package/src/runtime-assets-site.ts +2 -2
  18. package/src/runtime-assets.ts +1 -1
  19. package/src/runtime-render-document.ts +1 -2
  20. package/src/site-asset-routes.ts +2 -2
  21. package/src/site-assets.ts +5 -158
  22. package/src/sw-precache-plan.ts +1 -1
  23. package/src/templates/guard-raw-motion.ts +96 -0
  24. package/src/templates/guard-released-forms.ts +4 -1
  25. package/src/templates/scaffold-repo.ts +1 -1
  26. package/src/test-only-shipped.ts +29 -2
  27. package/src/test-shards.ts +20 -8
  28. package/src/upgrade-coverage-ratchet.ts +95 -0
  29. package/src/upgrade-gate.ts +31 -11
  30. package/src/upgrade-report.ts +14 -0
  31. package/src/verify-e2e.ts +21 -3
  32. package/src/workspace-checks.ts +4 -1
  33. package/wiki/Actions.md +64 -2
  34. package/wiki/Auth.md +6 -2
  35. package/wiki/CLI-Reference.md +8 -2
  36. package/wiki/Client-Navigation.md +34 -4
  37. package/wiki/Configuration.md +2 -1
  38. package/wiki/Entities-And-Migrations.md +12 -2
  39. package/wiki/Home.md +2 -2
  40. package/wiki/I18n.md +1 -1
  41. package/wiki/Interface-Rules.md +3 -1
  42. package/wiki/Known-Gaps.md +1 -1
  43. package/wiki/MCP-And-AI.md +41 -9
  44. package/wiki/Notify.md +4 -2
  45. package/wiki/Outbound-HTTP.md +53 -2
  46. package/wiki/Policies-And-Authz.md +1 -1
  47. package/wiki/Realtime.md +14 -6
  48. package/wiki/Routes-And-Render-Modes.md +1 -1
  49. package/wiki/Static-Assets.md +5 -3
  50. package/wiki/Testing.md +57 -3
  51. package/wiki/Theming.md +6 -3
  52. package/wiki/UI-Components.md +1 -0
  53. package/wiki/Upgrading.md +1 -0
@@ -1,163 +1,10 @@
1
- // The site asset table: every file under `apps/web/site/assets/`, named by a content-hashed URL.
2
- // One table per app root answers all three questions — the URL `asset()` returns while a page
3
- // renders, the file `/assets/*` serves, and the copy `x build --target static` writes — so the
4
- // page, the container and the CDN can never name one file three ways.
1
+ // The static export's half of the site asset table: every asset copied under its hashed URL. The
2
+ // table itself is `@ultimat3/render/server`'s, shared with the test preload.
5
3
 
6
- // why: `asset()` is called from a synchronous render, so the table answers synchronously — and Bun
7
- // ships no sync stat or sync read; `join`/`relative` because Bun ships no path API either.
8
- import { copyFileSync, mkdirSync, readFileSync, statSync } from 'node:fs';
4
+ // why: Bun ships no sync copy or mkdir, and the export walks the table synchronously.
5
+ import { copyFileSync, mkdirSync } from 'node:fs';
9
6
  import { dirname, join } from 'node:path'; // why: Bun ships no path API.
10
- import type { AssetExtension, AssetPath } from '@ultimat3/render';
11
- import { ASSET_DIR, AssetMissingError, assetPathProblem } from '@ultimat3/render';
12
- import { contentHash } from '@ultimat3/render/server';
13
-
14
- /** App-root-relative, beside `favicon.ico`: `apps/web/site/` is where an app's public files live. */
15
- export const SITE_ASSETS_SOURCE = `apps/web/site/${ASSET_DIR}`;
16
-
17
- /** The URL prefix every hashed asset is served under, and the export directory it is copied to. */
18
- export const SITE_ASSET_BASE_PATH = `/${ASSET_DIR}`;
19
-
20
- /** What each served extension IS. `vtt` carries a charset: captions are text a player decodes. */
21
- export const ASSET_CONTENT_TYPES: Readonly<Record<AssetExtension, string>> = {
22
- avif: 'image/avif',
23
- webp: 'image/webp',
24
- png: 'image/png',
25
- jpg: 'image/jpeg',
26
- jpeg: 'image/jpeg',
27
- gif: 'image/gif',
28
- svg: 'image/svg+xml',
29
- ico: 'image/x-icon',
30
- woff2: 'font/woff2',
31
- mp4: 'video/mp4',
32
- webm: 'video/webm',
33
- vtt: 'text/vtt; charset=utf-8',
34
- };
35
-
36
- export interface SiteAsset {
37
- /** As `asset()` names it: `assets/brand/logo.svg`. */
38
- readonly path: AssetPath;
39
- /** Absolute path on disk. */
40
- readonly file: string;
41
- /** `@ultimat3/render`'s `contentHash` of the bytes, 8 hex characters — the one CSS and HTML get. */
42
- readonly hash: string;
43
- /** `/assets/brand/logo.<hash>.svg`. */
44
- readonly url: string;
45
- readonly contentType: string;
46
- readonly bytes: number;
47
- }
48
-
49
- const splitExtension = (path: string): { readonly stem: string; readonly extension: string } => {
50
- const dot = path.lastIndexOf('.');
51
- return { stem: path.slice(0, dot), extension: path.slice(dot + 1) };
52
- };
53
-
54
- /** The hash goes before the extension, so a static host still infers the type from the name. */
55
- export function hashedAssetUrl(path: AssetPath, hash: string): string {
56
- const { stem, extension } = splitExtension(path);
57
- return `/${stem}.${hash}.${extension}`;
58
- }
59
-
60
- const HASHED = /^\/(assets\/.+)\.([0-9a-f]{8})\.([a-z0-9]+)$/i;
61
-
62
- /** The inverse of `hashedAssetUrl`: which asset a request names, and at which content. */
63
- export function parseHashedAssetUrl(
64
- pathname: string,
65
- ): { readonly path: AssetPath; readonly hash: string } | undefined {
66
- const match = HASHED.exec(pathname);
67
- if (match === null) return undefined;
68
- const path = `${match[1] ?? ''}.${match[3] ?? ''}`;
69
- if (assetPathProblem(path) !== undefined) return undefined;
70
- return { path: path as AssetPath, hash: match[2] ?? '' };
71
- }
72
-
73
- export interface SiteAssetTable {
74
- /** The asset `asset()` named, hashed as the bytes are NOW. Throws `X_ASSET_MISSING`. */
75
- resolve(path: AssetPath): SiteAsset;
76
- /** Every servable file under the source directory, sorted by path. */
77
- all(): readonly SiteAsset[];
78
- }
79
-
80
- const missing = (path: string, cause: string): AssetMissingError =>
81
- new AssetMissingError(
82
- `asset(${JSON.stringify(path)}): ${cause}`,
83
- `add the file at ${SITE_ASSETS_SOURCE}/${path.slice(ASSET_DIR.length + 1)}, or correct the path passed to asset(), then x build --target static --json`,
84
- );
85
-
86
- /**
87
- * A stat per call, a read only when the file changed: `x dev` sees an edited image under a new URL
88
- * on the next render with no watcher, and the container — whose files never change — pays one
89
- * `stat` per `asset()` call and nothing else. One behaviour in both, never a dev-only rescan.
90
- */
91
- export function createSiteAssetTable(root: string): SiteAssetTable {
92
- const source = join(root, SITE_ASSETS_SOURCE);
93
- const cache = new Map<string, { readonly stamp: string; readonly asset: SiteAsset }>();
94
-
95
- const resolve = (path: AssetPath): SiteAsset => {
96
- const problem = assetPathProblem(path);
97
- if (problem !== undefined) throw missing(path, problem);
98
- const file = join(source, path.slice(ASSET_DIR.length + 1));
99
- let stamp: string;
100
- try {
101
- const stat = statSync(file);
102
- if (!stat.isFile()) throw missing(path, `${file} is not a file`);
103
- stamp = `${String(stat.mtimeMs)}:${String(stat.size)}`;
104
- } catch (error) {
105
- if (error instanceof AssetMissingError) throw error;
106
- throw missing(path, `no file at ${SITE_ASSETS_SOURCE}/${path.slice(ASSET_DIR.length + 1)}`);
107
- }
108
- const cached = cache.get(path);
109
- if (cached !== undefined && cached.stamp === stamp) return cached.asset;
110
- const bytes = readFileSync(file);
111
- const hash = contentHash(bytes);
112
- // `assetPathProblem` already refused an unknown extension; the guard keeps `constructor` from
113
- // ever answering an `Object` member if that check is loosened.
114
- const extension = splitExtension(path).extension.toLowerCase();
115
- const asset: SiteAsset = {
116
- path,
117
- file,
118
- hash,
119
- url: hashedAssetUrl(path, hash),
120
- contentType: Object.hasOwn(ASSET_CONTENT_TYPES, extension)
121
- ? ASSET_CONTENT_TYPES[extension as AssetExtension]
122
- : 'application/octet-stream',
123
- bytes: bytes.byteLength,
124
- };
125
- cache.set(path, { stamp, asset });
126
- return asset;
127
- };
128
-
129
- const all = (): readonly SiteAsset[] => {
130
- const found: SiteAsset[] = [];
131
- let files: string[];
132
- try {
133
- files = [...new Bun.Glob('**/*').scanSync({ cwd: source, onlyFiles: true })];
134
- } catch {
135
- // No `assets/` directory is an app with no assets, not an error.
136
- return [];
137
- }
138
- for (const relativePath of files.sort()) {
139
- const path = `${ASSET_DIR}/${relativePath.split('\\').join('/')}`;
140
- // A source file beside its renditions (a `.psd`, a `README.md`) is not a served asset.
141
- if (assetPathProblem(path) !== undefined) continue;
142
- found.push(resolve(path as AssetPath));
143
- }
144
- return found;
145
- };
146
-
147
- return { resolve, all };
148
- }
149
-
150
- /** One table per root, so the renderer and the route read the same cache. */
151
- const tables = new Map<string, SiteAssetTable>();
152
-
153
- export function siteAssetTable(root: string): SiteAssetTable {
154
- let table = tables.get(root);
155
- if (table === undefined) {
156
- table = createSiteAssetTable(root);
157
- tables.set(root, table);
158
- }
159
- return table;
160
- }
7
+ import { siteAssetTable } from '@ultimat3/render/server';
161
8
 
162
9
  /**
163
10
  * Every asset, copied into the static export under its hashed URL — a static host serves with no
@@ -6,8 +6,8 @@ import { localeSegment, localizePath } from '@ultimat3/core';
6
6
  import type { PrecacheAsset, PwaRoute } from '@ultimat3/pwa';
7
7
  import { strategyFor } from '@ultimat3/pwa';
8
8
  import type { RouteDescriptor } from '@ultimat3/render';
9
+ import { parseHashedAssetUrl } from '@ultimat3/render/server';
9
10
  import type { IslandBundle } from './island-bundle';
10
- import { parseHashedAssetUrl } from './site-assets';
11
11
  import type { StyleBundle } from './style-bundle';
12
12
 
13
13
  /**
@@ -66,6 +66,47 @@ const MOTION_PROPERTY = /^(?:transition|animation)(?:-|$)|^--/;
66
66
  const TOKEN_CALL = /(?<![\\w-])(?:var|(?:[\\w-]+\\.)[\\w-]+|duration|easing)\\([^()]*\\)/g;
67
67
  const TIME = /(?<![\\w.#-])(\\d*\\.?\\d+)(ms|s)\\b/g;
68
68
  const CURVE = /cubic-bezier\\(([^)]*)\\)/g;
69
+ /** A property the scale itself declares: \`--duration-base\`, \`--easing-in-out\`. */
70
+ const SCALE_PROPERTY = /^--(duration|easing)-([\\w-]+)$/;
71
+
72
+ /**
73
+ * The scale rung a custom property re-declares, or \`undefined\`. Rewriting its value to a token
74
+ * would make the property read itself; the app's tempo is the theme's \`motion\` slot instead.
75
+ */
76
+ const scaleRung = (property: string): { scale: string; name: string } | undefined => {
77
+ const [, scale = '', name = ''] = SCALE_PROPERTY.exec(property) ?? [];
78
+ const names = scale === 'duration' ? DURATIONS.map(([rung]) => rung) : Object.values(EASINGS);
79
+ return names.includes(name) ? { scale, name } : undefined;
80
+ };
81
+
82
+ /** \`defineTheme\`'s own grammar for a duration; it refuses any other spelling at boot. */
83
+ const THEME_TIME = /^(0|\\d+(\\.\\d+)?(ms|s))$/;
84
+ const CSS_NUMBER = /^-?\\d*\\.?\\d+$/;
85
+ /** \`.5\` and \`+0.5\` are valid CSS; the theme spells both \`0.5\`. */
86
+ const themeNumber = (text: string): string =>
87
+ text.replace(/^\\+/, '').replace(/^(-?)\\./, (_match, sign: string) => \`\${sign}0.\`);
88
+
89
+ /** The value as \`defineTheme\` takes it, or \`undefined\` when no spelling of it is one. */
90
+ const themeValue = (scale: string, value: string): string | undefined => {
91
+ if (scale === 'duration') {
92
+ const time = themeNumber(value);
93
+ return THEME_TIME.test(time) ? time : undefined;
94
+ }
95
+ const points = /^cubic-bezier\\(([^()]*)\\)$/
96
+ .exec(value)?.[1]
97
+ ?.split(',')
98
+ .map((n) => themeNumber(n.trim()));
99
+ if (points?.length !== 4 || !points.every((n) => CSS_NUMBER.test(n))) return undefined;
100
+ // x1 and x2 are points in time: the theme refuses a curve with either outside [0, 1].
101
+ const inTime = [points[0], points[2]].every((x) => Number(x) >= 0 && Number(x) <= 1);
102
+ return inTime ? \`cubic-bezier(\${points.join(', ')})\` : undefined;
103
+ };
104
+
105
+ /** The value the scale ships for a rung — a call that always boots. */
106
+ const shippedValue = (scale: string, name: string): string =>
107
+ scale === 'duration'
108
+ ? \`\${DURATIONS.find(([rung]) => rung === name)?.[1] ?? 0}ms\`
109
+ : \`cubic-bezier(\${(Object.entries(EASINGS).find(([, rung]) => rung === name)?.[0] ?? '').split(',').join(', ')})\`;
69
110
 
70
111
  /** The step a duration means: exact where it is one, the nearest where it is not. */
71
112
  const durationFor = (ms: number): string => {
@@ -124,6 +165,38 @@ export function rawMotion(files: readonly StyleFile[]): readonly Finding[] {
124
165
  if (literals.length === 0) continue;
125
166
  written += value.slice(cursor);
126
167
  const line = lineOf(scss, match.index);
168
+ const rung = scaleRung(property);
169
+ if (rung !== undefined) {
170
+ const key = /^\\w+$/.test(rung.name) ? rung.name : \`'\${rung.name}'\`;
171
+ // \`!important\` is the declaration's priority, not its value: the theme takes the time.
172
+ const important = /\\s*!important$/i.exec(value);
173
+ const accepted = themeValue(rung.scale, value.slice(0, important?.index));
174
+ const priority = important
175
+ ? ' (the theme sets it without !important, so a later declaration of the property wins)'
176
+ : '';
177
+ const call = (themed: string): string =>
178
+ \`defineTheme({ motion: { \${rung.scale}: { \${key}: '\${themed}' } } }) in apps/web/shared/theme.ts\`;
179
+ if (accepted === undefined) {
180
+ const grammar =
181
+ rung.scale === 'duration'
182
+ ? "a time such as '180ms' or '0.3s'"
183
+ : "cubic-bezier() of four numbers, x1 and x2 between 0 and 1, such as 'cubic-bezier(0.2, 0, 0, 1)'";
184
+ findings.push({
185
+ code: CODE,
186
+ cause: \`\${file.path}:\${line} re-declares \\\`\${property}: \${value}\\\`, which a theme cannot hold — a \${rung.scale} rung takes \${grammar}\`,
187
+ fix: \`\${call(shippedValue(rung.scale, rung.name))} — the shipped value; change it to \${grammar}, delete the line at \${file.path}:\${line}, then: x verify --only boundaries\`,
188
+ at: \`\${file.path}:\${line}\`,
189
+ });
190
+ continue;
191
+ }
192
+ findings.push({
193
+ code: CODE,
194
+ cause: \`\${file.path}:\${line} re-declares \\\`\${property}: \${value}\\\` — the motion scale's own property, set from a stylesheet\`,
195
+ fix: \`\${call(accepted)} — every \${ns}.\${rung.scale}(\${rung.name}) then moves at it\${priority}; delete the line at \${file.path}:\${line}, then: x verify --only boundaries\`,
196
+ at: \`\${file.path}:\${line}\`,
197
+ });
198
+ continue;
199
+ }
127
200
  findings.push({
128
201
  code: CODE,
129
202
  cause: \`\${file.path}:\${line} writes \\\`\${property}: \${value}\\\` — \${literals.join(' and ')} off the motion scale, a tempo of this file's own\`,
@@ -200,6 +273,29 @@ unitTest('a custom property holding a raw curve or time is refused, the fix inte
200
273
  expect(fixes(':root { --wait: 0.4s; --gap: 12px; --ok: var(--duration-fast); }')).toHaveLength(1);
201
274
  });
202
275
 
276
+ unitTest('re-declaring a property of the scale itself is sent to the theme slot', () => {
277
+ expect(fixes(':root { --duration-base: 180ms; }')[0]).toStartWith(
278
+ "defineTheme({ motion: { duration: { base: '180ms' } } }) in apps/web/shared/theme.ts",
279
+ );
280
+ expect(fixes(':root { --easing-in-out: cubic-bezier(0.4, 0, 0.2, 1); }')[0]).toStartWith(
281
+ "defineTheme({ motion: { easing: { 'in-out': 'cubic-bezier(0.4, 0, 0.2, 1)' } } })",
282
+ );
283
+ });
284
+
285
+ unitTest('a rung the theme spells differently is normalized; one it cannot hold says so', () => {
286
+ expect(fixes(':root { --duration-base: .5s; }')[0]).toStartWith(
287
+ "defineTheme({ motion: { duration: { base: '0.5s' } } })",
288
+ );
289
+ expect(fixes(':root { --easing-out: cubic-bezier(0,0,1,1); }')[0]).toStartWith(
290
+ "defineTheme({ motion: { easing: { out: 'cubic-bezier(0, 0, 1, 1)' } } })",
291
+ );
292
+ const refused = rawMotion(sheet(':root { --easing-out: cubic-bezier(1.5, 0, 0, 1); }'));
293
+ expect(refused[0]?.cause).toContain('which a theme cannot hold');
294
+ expect(refused[0]?.fix).toStartWith(
295
+ "defineTheme({ motion: { easing: { out: 'cubic-bezier(0.16, 1, 0.3, 1)' } } })",
296
+ );
297
+ });
298
+
203
299
  unitTest('the fix speaks the namespace the sheet uses the tokens under', () => {
204
300
  const scss = "@use '../shared/tokens' as t;\\n.a { transition-duration: 120ms; }";
205
301
  expect(fixes(scss)[0]).toStartWith('transition-duration: t.duration(fast) — ');
@@ -79,6 +79,9 @@ export const RELEASED_GUARD_FORMS: Readonly<
79
79
  ],
80
80
  'raw-motion': [
81
81
  ['14c1bs20ysc1u', 'error'],
82
+ ['23t5nj717gkf0', 'error'],
83
+ ['3azasze78buvt', 'error'],
84
+ ['3tk0sdgns06ck', 'error'],
82
85
  ['u6julhh0et2k', 'error'],
83
86
  ['w8aw0q20tfsz', 'error'],
84
87
  ],
@@ -176,7 +179,7 @@ export const RELEASED_GUARD_TEST_FORMS: Readonly<Record<string, readonly string[
176
179
  'raw-fetch': ['2lips924uo00f'],
177
180
  'raw-interval': ['1z55givy4sst0'],
178
181
  'raw-length': ['1hpgz9jowk5qu'],
179
- 'raw-motion': ['6420344uhv97', 'g6cs0de9jmr7'],
182
+ 'raw-motion': ['2kg7ezhf8u7a9', '6420344uhv97', 'g6cs0de9jmr7', 'xes72msaf3a3'],
180
183
  'raw-shadow': ['3kg8ft6y3ia0y'],
181
184
  'raw-z-index': ['3fb40f6bwp8kq'],
182
185
  'repo-await-in-loop': ['2axgbb82wldt4'],
@@ -29,7 +29,7 @@ import { verifyFloor } from './scaffold-verify-floor';
29
29
  * config as out of date on every `bun run lint`. A formatter is a build input: a floating range
30
30
  * is a `lint` step whose verdict depends on the day the app was installed.
31
31
  */
32
- const BIOME_VERSION = '2.6.4';
32
+ const BIOME_VERSION = '2.6.6';
33
33
 
34
34
  /**
35
35
  * The checker a scaffolded app typechecks with, and it must not lag the one the FRAMEWORK is built
@@ -15,6 +15,11 @@ export interface ShippedPackage {
15
15
  readonly dir: string;
16
16
  /** Package-relative (`src/index.ts`), and may be a glob (`src/icons/glyphs/*.ts`). */
17
17
  readonly entries: readonly string[];
18
+ /**
19
+ * The `files` negations, without their `!` (`src/link-login.ts`): a module one matches is not in
20
+ * the tarball, so it ships nothing whoever imports it.
21
+ */
22
+ readonly excluded?: readonly string[];
18
23
  }
19
24
 
20
25
  export interface TestOnlyModule {
@@ -29,7 +34,12 @@ export interface TestOnlyModule {
29
34
  * field: a module the manifest names is shipped on purpose, whichever field names it.
30
35
  */
31
36
  export function entryPatternsOf(manifest: unknown): readonly string[] {
32
- const text = JSON.stringify(manifest ?? null);
37
+ // A `files` negation names what the tarball leaves out, never an entry it ships.
38
+ const text = JSON.stringify(manifest ?? null, (key, value: unknown) =>
39
+ key === 'files' && Array.isArray(value)
40
+ ? value.filter((entry) => typeof entry !== 'string' || !entry.startsWith('!'))
41
+ : value,
42
+ );
33
43
  const found = [...text.matchAll(/(?:\.\/)?(src\/[\w./*-]+?\.tsx?)(?![\w.])/g)];
34
44
  return [...new Set(found.map((match) => match[1] ?? ''))].sort();
35
45
  }
@@ -135,18 +145,35 @@ export function testOnlyModules(
135
145
  pkg.entries.map((entry) => new Bun.Glob(`packages/${pkg.dir}/${entry}`)),
136
146
  ]),
137
147
  );
148
+ // A negation names a file or a directory (`!src/held/`): match the pattern and what is under it.
149
+ const excludedGlobs = new Map(
150
+ packages.map((pkg) => [
151
+ pkg.dir,
152
+ (pkg.excluded ?? []).flatMap((pattern) => {
153
+ const base = `packages/${pkg.dir}/${pattern.replace(/\/+$/, '')}`;
154
+ return [new Bun.Glob(base), new Bun.Glob(`${base}/**`)];
155
+ }),
156
+ ]),
157
+ );
158
+ const isExcluded = (path: string): boolean => {
159
+ const dir = /^packages\/([^/]+)\/src\//.exec(path)?.[1];
160
+ return (excludedGlobs.get(dir ?? '') ?? []).some((glob) => glob.match(path));
161
+ };
138
162
  const referrers = new Map<string, ReadonlySet<string>>();
139
163
  for (const path of sources.keys()) {
140
164
  const dir = /^packages\/([^/]+)\/src\//.exec(path)?.[1];
141
165
  const globs = dir === undefined ? undefined : entryGlobs.get(dir);
142
166
  if (globs === undefined || !path.endsWith('.ts') || isGenerated(path)) continue;
167
+ if (isExcluded(path)) continue;
143
168
  if (isTest(path) || isFixture(path) || globs.some((glob) => glob.match(path))) continue;
144
169
  const from = new Set([...(imports.get(path) ?? []), ...(named.get(baseName(path)) ?? [])]);
145
170
  from.delete(path);
146
171
  if (from.size > 0) referrers.set(path, from);
147
172
  }
148
173
  const testOnly = new Set(referrers.keys());
149
- const live = (path: string): boolean => !isTest(path) && !isFixture(path) && !testOnly.has(path);
174
+ // An excluded file is not in the tarball, so what only it imports ships for no one's sake.
175
+ const live = (path: string): boolean =>
176
+ !isTest(path) && !isFixture(path) && !isExcluded(path) && !testOnly.has(path);
150
177
  for (let changed = true; changed; ) {
151
178
  changed = false;
152
179
  for (const path of testOnly) {
@@ -64,6 +64,7 @@ import type { TestFile } from './test-select';
64
64
  import { loadTimings, SLOWEST_KEPT, slowestOf } from './test-timings';
65
65
  import { allSkippedFinding, failingFiles } from './test-verdict';
66
66
  import { BATCH_FILES_PER_WORKER, SHARED_BATCH_FILES_PER_WORKER } from './test-workers';
67
+ import { appE2eRun, drivesBrowser, type E2eRun, isAppRoot } from './verify-e2e';
67
68
  import type { TestType } from './verify-tests';
68
69
 
69
70
  /**
@@ -340,6 +341,15 @@ export async function runShards(options: RunShardsOptions): Promise<CommandResul
340
341
  isolatedRun(options) ? BATCH_FILES_PER_WORKER : SHARED_BATCH_FILES_PER_WORKER,
341
342
  )
342
343
  : [files];
344
+ // The e2e pass runs as the gate's `e2e` step does: in an app with a browser, under the e2e
345
+ // preload that spawns the app (`verify-e2e.ts`). Elsewhere its browser cases skip, as there.
346
+ const launch =
347
+ pass.type === 'e2e' && (await drivesBrowser(isAppRoot(options.root), options.env ?? Bun.env));
348
+ const passRun = (command: readonly string[]): E2eRun =>
349
+ launch
350
+ ? appE2eRun({ root: options.root, command, env: envOverrides })
351
+ : { command, env: envOverrides };
352
+ const passEnv = passRun([]).env;
343
353
  const result = await runBatches({
344
354
  runner: options.runner,
345
355
  batches,
@@ -347,16 +357,18 @@ export async function runShards(options: RunShardsOptions): Promise<CommandResul
347
357
  workers: pass.workers,
348
358
  ...(options.lease === undefined ? {} : { lease: options.lease }),
349
359
  argsFor: (batch, width) =>
350
- testArgs({
351
- files: batch,
352
- workers: width,
353
- ...(options.passthrough === undefined ? {} : { passthrough: options.passthrough }),
354
- ...(options.isolate === undefined ? {} : { isolate: options.isolate }),
355
- timings: join(options.root, TEST_TIMINGS_FILE),
356
- }),
360
+ passRun(
361
+ testArgs({
362
+ files: batch,
363
+ workers: width,
364
+ ...(options.passthrough === undefined ? {} : { passthrough: options.passthrough }),
365
+ ...(options.isolate === undefined ? {} : { isolate: options.isolate }),
366
+ timings: join(options.root, TEST_TIMINGS_FILE),
367
+ }),
368
+ ).command,
357
369
  options: {
358
370
  cwd: options.root,
359
- ...(Object.keys(envOverrides).length === 0 ? {} : { env: envOverrides }),
371
+ ...(Object.keys(passEnv).length === 0 ? {} : { env: passEnv }),
360
372
  },
361
373
  });
362
374
  batchCount += batches.length;
@@ -0,0 +1,95 @@
1
+ // A hop's coverage ratchet: a gate whose `unit` step says `X_COVERAGE_FLOOR_STALE` — the tree
2
+ // covers more than `x.verify.json` states, a codemod's test among the causes — gets the floor
3
+ // raised to what that run measured, never lowered, and `unit` judged again. Written into the
4
+ // hop's diff and reported, never silently.
5
+
6
+ // why: Bun exposes no path-join primitive; `x.verify.json` sits at the app root.
7
+ import { join } from 'node:path';
8
+ import { t } from '@ultimat3/schema';
9
+ import { COVERAGE_BAR, COVERAGE_FIELD, floorFor } from './coverage-floor';
10
+ import { msg } from './messages';
11
+ import { statedCoverage } from './upgrade-coverage';
12
+ import { documentIn } from './upgrade-document';
13
+ import type { HopGate } from './upgrade-gate';
14
+ import { VERIFY_FLOOR_FILE } from './verify-floor';
15
+
16
+ const STALE = 'X_COVERAGE_FLOOR_STALE';
17
+ const UNIT = 'unit';
18
+
19
+ interface Numbers {
20
+ readonly lines: number;
21
+ readonly funcs: number;
22
+ }
23
+
24
+ /** What the report carries: the floor before, the one written, and the run that measured it. */
25
+ export interface HopCoverageRatchet {
26
+ readonly file: string;
27
+ readonly measured: Numbers;
28
+ readonly from: Numbers;
29
+ readonly to: Numbers;
30
+ }
31
+
32
+ type Verify = HopGate['verify'];
33
+
34
+ const MEASURED = t.object({
35
+ data: t.object({ coverage: t.object({ unit: t.object({ lines: t.number, funcs: t.number }) }) }),
36
+ });
37
+
38
+ /** Whether the gate's `unit` step said its floor is stale. */
39
+ export const staleUnitFloor = (verify: Verify): boolean =>
40
+ verify.findings.some((finding) => finding.step === UNIT && finding.code === STALE);
41
+
42
+ /** The `unit` step's measurement off a verify document; undefined when it carries none. */
43
+ export function measuredUnit(stdout: string): Numbers | undefined {
44
+ const parsed = MEASURED.safeParse(documentIn(stdout));
45
+ if (parsed.issues !== undefined) return undefined;
46
+ const { lines, funcs } = (parsed.value as { data: { coverage: { unit: Numbers } } }).data.coverage
47
+ .unit;
48
+ return { lines, funcs };
49
+ }
50
+
51
+ /**
52
+ * Each number to the larger of the stated floor and the measured whole percent — the stale
53
+ * finding's own fix — so no floor ever falls. A floor that reaches the bar drops its `why`, as
54
+ * that fix says. Null when nothing rises, or the app states no floor to raise.
55
+ */
56
+ export async function raiseCoverageFloor(
57
+ root: string,
58
+ measured: Numbers,
59
+ ): Promise<HopCoverageRatchet | null> {
60
+ const stated = await statedCoverage(root);
61
+ if (stated === undefined) return null;
62
+ const from = { lines: stated.floor.lines, funcs: stated.floor.funcs };
63
+ const to = {
64
+ lines: Math.max(from.lines, floorFor(measured.lines)),
65
+ funcs: Math.max(from.funcs, floorFor(measured.funcs)),
66
+ };
67
+ if (to.lines === from.lines && to.funcs === from.funcs) return null;
68
+ const { why, ...raw } = stated.payload[COVERAGE_FIELD] as Record<string, unknown>;
69
+ const cleared = to.lines >= COVERAGE_BAR && to.funcs >= COVERAGE_BAR;
70
+ const coverage = cleared ? { ...raw, ...to } : { ...raw, ...to, why };
71
+ const next = { ...stated.payload, [COVERAGE_FIELD]: coverage };
72
+ await Bun.write(join(root, VERIFY_FLOOR_FILE), `${JSON.stringify(next, null, 2)}\n`);
73
+ return { file: VERIFY_FLOOR_FILE, measured: { ...measured }, from, to };
74
+ }
75
+
76
+ /**
77
+ * The gate's verdict with `unit` replaced by its re-run. Green only when `unit` was the one red
78
+ * step, its re-run passed, and no finding sits outside every step.
79
+ */
80
+ export function rejudgedVerify(verify: Verify, unit: Verify): Verify {
81
+ const others = verify.findings.filter((finding) => finding.step !== UNIT);
82
+ const failedOthers = verify.failed.filter((name) => name !== UNIT);
83
+ const ok =
84
+ unit.ok &&
85
+ failedOthers.length === 0 &&
86
+ verify.failed.includes(UNIT) &&
87
+ others.every((finding) => finding.step !== undefined);
88
+ return {
89
+ ...verify,
90
+ ok,
91
+ summary: msg('cli.upgrade.coverageRejudged', { summary: verify.summary, unit: unit.summary }),
92
+ failed: unit.ok ? failedOthers : verify.failed,
93
+ findings: [...others, ...unit.findings],
94
+ };
95
+ }
@@ -1,7 +1,7 @@
1
1
  // A hop's gate, run by the CLI the hop just installed: codemods, manifest, doctor, missing guards,
2
- // a Bun-floor hop's coverage, exercise, verify (`upgrade-gate-codemods.ts`, `upgrade-guards.ts`).
3
- // Never in this process: the installed CLI may be majors older, so each answer is read as a
4
- // foreign document (`local-cli.ts`), and one that will not parse is never green.
2
+ // a Bun-floor hop's coverage, exercise, verify, a stale coverage floor raised (`upgrade-gate-*`,
3
+ // `upgrade-guards.ts`, `upgrade-coverage-ratchet.ts`). Never in this process: the installed CLI may
4
+ // be majors older, so each answer is a foreign document (`local-cli.ts`); unparsed is never green.
5
5
 
6
6
  // why: Bun exposes no path-join primitive; the installed bin is assembled from the app root.
7
7
  import { join } from 'node:path';
@@ -13,6 +13,13 @@ import { exerciseReportStamp } from './exercise-floor-report';
13
13
  import { LOCAL_CLI_BIN } from './local-cli';
14
14
  import type { CoverageRebaseline, HopCoverage } from './upgrade-coverage';
15
15
  import { rebaselineCoverage, statedCoverage } from './upgrade-coverage';
16
+ import type { HopCoverageRatchet } from './upgrade-coverage-ratchet';
17
+ import {
18
+ measuredUnit,
19
+ raiseCoverageFloor,
20
+ rejudgedVerify,
21
+ staleUnitFloor,
22
+ } from './upgrade-coverage-ratchet';
16
23
  import { documentIn } from './upgrade-document';
17
24
  import type { HopExerciseFloor } from './upgrade-exercise-floor';
18
25
  import { ratchetExerciseFloor } from './upgrade-exercise-floor';
@@ -140,6 +147,11 @@ export interface HopGate {
140
147
  readonly exercise: HopExercise;
141
148
  /** The exercise figures the hop wrote into `x.verify.json` as its ratchet; null when none. */
142
149
  readonly exerciseFloor: HopExerciseFloor | null;
150
+ /**
151
+ * The coverage floor raised to what the gate's `unit` run measured, on its `X_COVERAGE_FLOOR_STALE`
152
+ * — `verify` is then the verdict with `unit` re-run. Absent when nothing was raised.
153
+ */
154
+ readonly coverageRaised?: HopCoverageRatchet;
143
155
  readonly verify: {
144
156
  readonly ok: boolean;
145
157
  readonly summary: string;
@@ -305,14 +317,21 @@ export async function runHopGate(input: {
305
317
  // The installed gate's own list first: the steps owed to CI are steps that CLI has. None owed
306
318
  // (every one of its steps named) is that CLI's full gate, run and reported as one.
307
319
  const notRun = only === undefined ? undefined : await installedNotRun(installed, only);
308
- const verify =
309
- only === undefined || notRun === undefined || notRun.length === 0
310
- ? readVerify(await installed(['verify', '--json']))
311
- : {
312
- ...readVerify(await installed(['verify', '--only', only.steps.join(','), '--json'])),
313
- only: only.steps,
314
- notRun,
315
- };
320
+ const full = only === undefined || notRun === undefined || notRun.length === 0;
321
+ const ran = await installed(
322
+ full ? ['verify', '--json'] : ['verify', '--only', only.steps.join(','), '--json'],
323
+ );
324
+ let verify: HopGate['verify'] = full
325
+ ? readVerify(ran)
326
+ : { ...readVerify(ran), only: only.steps, notRun };
327
+ let coverageRaised: HopCoverageRatchet | null = null;
328
+ const measured = staleUnitFloor(verify) ? measuredUnit(ran.stdout) : undefined;
329
+ if (measured !== undefined) coverageRaised = await raiseCoverageFloor(root, measured);
330
+ if (coverageRaised !== null) {
331
+ onStage('coverage');
332
+ const unit = readVerify(await installed(['verify', '--only', 'unit', '--json']));
333
+ verify = rejudgedVerify(verify, unit);
334
+ }
316
335
  return {
317
336
  codemods,
318
337
  superseded,
@@ -322,6 +341,7 @@ export async function runHopGate(input: {
322
341
  coverage,
323
342
  exercise,
324
343
  exerciseFloor,
344
+ ...(coverageRaised === null ? {} : { coverageRaised }),
325
345
  verify,
326
346
  };
327
347
  }
@@ -145,6 +145,19 @@ export const humanLines = (
145
145
  funcs: Math.floor(gate.coverage.measured.funcs * 10) / 10,
146
146
  }),
147
147
  ]),
148
+ ...(gate?.coverageRaised === undefined
149
+ ? []
150
+ : [
151
+ msg('cli.upgrade.coverageRaised', {
152
+ file: gate.coverageRaised.file,
153
+ fromLines: gate.coverageRaised.from.lines,
154
+ fromFuncs: gate.coverageRaised.from.funcs,
155
+ toLines: gate.coverageRaised.to.lines,
156
+ toFuncs: gate.coverageRaised.to.funcs,
157
+ lines: Math.floor(gate.coverageRaised.measured.lines * 10) / 10,
158
+ funcs: Math.floor(gate.coverageRaised.measured.funcs * 10) / 10,
159
+ }),
160
+ ]),
148
161
  ...(gate === undefined || gate.exerciseFloor === null
149
162
  ? []
150
163
  : [
@@ -220,6 +233,7 @@ export const report = (
220
233
  doctorWarnings: gate?.doctorWarnings ?? [],
221
234
  exercise: gate?.exercise ?? null,
222
235
  exerciseFloor: gate?.exerciseFloor ?? null,
236
+ coverageRaised: gate?.coverageRaised ?? null,
223
237
  verify: gate?.verify ?? null,
224
238
  scripts,
225
239
  then,