@ultimat3/cli 31.27.0 → 31.29.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 (134) hide show
  1. package/CLAUDE.md +4 -1
  2. package/README.md +14 -4
  3. package/package.json +29 -29
  4. package/src/app-manifest.ts +6 -1
  5. package/src/app-migrations-verdict.ts +84 -0
  6. package/src/cmd-doctor.ts +11 -3
  7. package/src/cmd-drill.ts +23 -9
  8. package/src/cmd-repro-spec.ts +13 -1
  9. package/src/cmd-repro.ts +37 -5
  10. package/src/cmd-upgrade-codemods.ts +71 -0
  11. package/src/cmd-upgrade-spec.ts +19 -5
  12. package/src/cmd-upgrade.ts +91 -34
  13. package/src/codemods/agents-dev-mcp.ts +50 -0
  14. package/src/codemods/authenticator-session-refusal.ts +214 -0
  15. package/src/codemods/biome-no-default-export.ts +58 -0
  16. package/src/codemods/bunfig-island-coverage.ts +33 -0
  17. package/src/codemods/chart-dashboard.ts +73 -0
  18. package/src/codemods/ci-e2e-browser-stock.ts +75 -0
  19. package/src/codemods/ci-e2e-browser.ts +63 -0
  20. package/src/codemods/codemod.ts +58 -0
  21. package/src/codemods/define-error-leaf.ts +73 -0
  22. package/src/codemods/docs-ci-parts.ts +65 -0
  23. package/src/codemods/docs-gate-prose.ts +53 -0
  24. package/src/codemods/docs-island-rows.ts +31 -0
  25. package/src/codemods/docs-shipped-guards.ts +100 -0
  26. package/src/codemods/docs-test-services.ts +62 -0
  27. package/src/codemods/engine-diff.ts +104 -0
  28. package/src/codemods/engine-edits.ts +111 -0
  29. package/src/codemods/engine-fs.ts +95 -0
  30. package/src/codemods/engine.ts +191 -0
  31. package/src/codemods/format-edited-hook-3122.ts +28 -0
  32. package/src/codemods/format-edited-hook.ts +152 -0
  33. package/src/codemods/helm-alerts-deploy.ts +85 -0
  34. package/src/codemods/helm-alerts-objective.ts +105 -0
  35. package/src/codemods/helm-alerts-stock.ts +108 -0
  36. package/src/codemods/index.ts +60 -0
  37. package/src/codemods/metrics-probe-healthz.ts +47 -0
  38. package/src/codemods/migrate-job-ordered.ts +81 -0
  39. package/src/codemods/migrate-job-stock.ts +41 -0
  40. package/src/codemods/pending.ts +36 -0
  41. package/src/codemods/repro-gitignore.ts +40 -0
  42. package/src/codemods/runtime-pin-lines.ts +109 -0
  43. package/src/codemods/runtime-pin.ts +116 -0
  44. package/src/codemods/solid-floor.ts +63 -0
  45. package/src/codemods/test-ports.ts +86 -0
  46. package/src/codemods/test-suites.ts +37 -0
  47. package/src/codemods/theme-toggle-mount-over.ts +70 -0
  48. package/src/codemods/vendored-guards.ts +186 -0
  49. package/src/codemods/verify-floor-skips.ts +88 -0
  50. package/src/codemods/verify-floor-steps.ts +90 -0
  51. package/src/doctor-advisory-floors.ts +113 -0
  52. package/src/doctor-guards.ts +39 -86
  53. package/src/doctor-superseded.ts +67 -0
  54. package/src/drill-schema-behind.ts +26 -0
  55. package/src/error-codes-doctor.ts +12 -4
  56. package/src/error-codes.ts +9 -0
  57. package/src/exercise-database.ts +7 -2
  58. package/src/framework-schema-apply.ts +7 -19
  59. package/src/framework-schema-stamp.ts +38 -3
  60. package/src/framework-schema-verify.ts +120 -0
  61. package/src/framework-schema-wait.ts +125 -0
  62. package/src/generate-files.ts +6 -5
  63. package/src/guards-built-in-codes.ts +36 -0
  64. package/src/guards-built-in-refusal.ts +25 -0
  65. package/src/guards-built-in.ts +134 -0
  66. package/src/guards-materialize.ts +42 -0
  67. package/src/guards-paths.ts +37 -0
  68. package/src/guards-shipped-names.ts +38 -0
  69. package/src/guards-vendored.ts +73 -0
  70. package/src/guards.ts +90 -34
  71. package/src/index.ts +10 -0
  72. package/src/lint-findings.ts +3 -3
  73. package/src/mcp-errors.ts +12 -1
  74. package/src/measure-scope.ts +23 -3
  75. package/src/messages-repro.ts +16 -2
  76. package/src/messages-upgrade.ts +15 -0
  77. package/src/messages.ts +1 -1
  78. package/src/repro-archive-collect.ts +161 -0
  79. package/src/repro-archive-write.ts +96 -0
  80. package/src/repro-archive.ts +161 -0
  81. package/src/repro-bundle.ts +8 -16
  82. package/src/repro-errors.ts +14 -2
  83. package/src/repro-framework.ts +53 -0
  84. package/src/repro-parse.ts +87 -0
  85. package/src/repro-redact.ts +218 -0
  86. package/src/repro-scrub.ts +257 -0
  87. package/src/role-pg-stats.ts +21 -0
  88. package/src/role-start.ts +4 -0
  89. package/src/runtime-queue.ts +27 -6
  90. package/src/serve-boot-probe.ts +97 -0
  91. package/src/serve-boot.ts +26 -1
  92. package/src/serve-retire.ts +16 -3
  93. package/src/superseded-match.ts +87 -0
  94. package/src/superseded.ts +84 -0
  95. package/src/templates/bun-image.ts +48 -0
  96. package/src/templates/chart-dashboard-panels.ts +178 -0
  97. package/src/templates/chart-dashboard.ts +9 -135
  98. package/src/templates/github/ci.yml.ts +1 -1
  99. package/src/templates/guard-released-forms.ts +112 -0
  100. package/src/templates/guard-runtime-pin-test.ts +54 -0
  101. package/src/templates/guard-runtime-pin.ts +189 -0
  102. package/src/templates/scaffold-claude-agents.ts +6 -6
  103. package/src/templates/scaffold-claude-commands.ts +1 -1
  104. package/src/templates/scaffold-claude-hook.ts +18 -8
  105. package/src/templates/scaffold-claude.ts +2 -2
  106. package/src/templates/scaffold-container.ts +2 -2
  107. package/src/templates/scaffold-docs.ts +26 -24
  108. package/src/templates/scaffold-guards.ts +73 -39
  109. package/src/templates/scaffold-helm-alert-deploy.ts +105 -0
  110. package/src/templates/scaffold-helm-alert-rules.ts +7 -1
  111. package/src/templates/scaffold-helm-alerts.ts +3 -0
  112. package/src/templates/scaffold-helm-migrate.ts +85 -0
  113. package/src/templates/scaffold-helm-templates.ts +2 -36
  114. package/src/templates/scaffold-helm.ts +1 -0
  115. package/src/templates/scaffold-repo.ts +2 -1
  116. package/src/unthrown-codes.ts +2 -0
  117. package/src/upgrade-bun-floor.ts +4 -0
  118. package/src/upgrade-clean-tree.ts +54 -0
  119. package/src/upgrade-gate-codemods-install.ts +40 -0
  120. package/src/upgrade-gate-codemods.ts +151 -0
  121. package/src/upgrade-gate.ts +38 -6
  122. package/src/upgrade-lock.ts +118 -0
  123. package/src/upgrade-plan.ts +2 -1
  124. package/src/upgrade-report-codemods.ts +54 -0
  125. package/src/upgrade-report.ts +52 -27
  126. package/src/upgrade-signals.ts +91 -0
  127. package/src/upgrade-unfinished.ts +61 -0
  128. package/wiki/CLI-Reference.md +70 -5
  129. package/wiki/Deployment.md +2 -1
  130. package/wiki/Interface-Rules.md +17 -8
  131. package/wiki/Known-Gaps.md +1 -1
  132. package/wiki/Observability.md +1 -0
  133. package/wiki/Project-Layout.md +4 -4
  134. package/wiki/Upgrading.md +6 -0
@@ -0,0 +1,88 @@
1
+ // 31.27.0: a scaffold's x.verify.json names every gate step — required in `steps`, or excused in
2
+ // `skip` with its why — and sets `strict`. An older app gains the `skip` rows that hold for it
3
+ // (roadmap; job with no job suite; e2e with no page). `strict` is 31.28.0's (`verify-floor-steps`).
4
+
5
+ import { floorSteps } from '../templates/scaffold-verify-floor';
6
+ import { VERIFY_FLOOR_FILE } from '../verify-floor';
7
+ import type { Codemod, CodemodApp } from './codemod';
8
+
9
+ export type Floor = Record<string, unknown>;
10
+
11
+ export const isObject = (value: unknown): value is Floor =>
12
+ typeof value === 'object' && value !== null && !Array.isArray(value);
13
+
14
+ const any = async (app: CodemodApp, pattern: string): Promise<boolean> =>
15
+ (await app.glob(pattern)).length > 0;
16
+
17
+ /** What the app ships suites for, as `floorSteps` asks it: a job suite, a page to load. */
18
+ export async function floorSuites(
19
+ app: CodemodApp,
20
+ ): Promise<{ readonly jobs: boolean; readonly pages: boolean }> {
21
+ return {
22
+ jobs: await any(app, '{apps,packages}/**/*.job.test.ts'),
23
+ pages: await any(app, 'apps/*/{site,app}/**/page.tsx'),
24
+ };
25
+ }
26
+
27
+ /** The steps that cannot run in this app, each with the scaffold's own why. */
28
+ async function excused(app: CodemodApp): Promise<Readonly<Record<string, string>>> {
29
+ const { jobs, pages } = await floorSuites(app);
30
+ const why = floorSteps({ jobs: false, pages: false }).skip;
31
+ const out: Record<string, string> = {};
32
+ if (!jobs && why.job !== undefined) out['job'] = why.job;
33
+ if (!pages && why.e2e !== undefined) out['e2e'] = why.e2e;
34
+ if (!(await app.exists('docs/idea/14-roadmap.md')) && why.roadmap !== undefined) {
35
+ out['roadmap'] = why.roadmap;
36
+ }
37
+ return out;
38
+ }
39
+
40
+ /** `floor` with `skip` merged in, placed right after `steps` as the scaffold writes it. */
41
+ function withSkip(floor: Floor, skip: Readonly<Record<string, string>>): Floor {
42
+ const merged = { ...(isObject(floor['skip']) ? floor['skip'] : {}), ...skip };
43
+ const out: Floor = {};
44
+ for (const [key, value] of Object.entries(floor)) {
45
+ if (key === 'skip') continue;
46
+ out[key] = value;
47
+ if (key === 'steps') out['skip'] = merged;
48
+ }
49
+ if (!('skip' in out)) out['skip'] = merged;
50
+ return out;
51
+ }
52
+
53
+ export const renderFloor = (floor: Floor): string => `${JSON.stringify(floor, null, 2)}\n`;
54
+
55
+ export const codemod: Codemod = {
56
+ id: 'verify-floor-skips',
57
+ since: '31.27.0',
58
+ summary: `${VERIFY_FLOOR_FILE} excuses the gate steps this app cannot run (roadmap; job, e2e where it has none), each with its why`,
59
+ async run(app) {
60
+ const source = await app.read(VERIFY_FLOOR_FILE);
61
+ if (source === undefined) return { changed: [], skipped: [] };
62
+ let floor: unknown;
63
+ try {
64
+ floor = JSON.parse(source);
65
+ } catch {
66
+ floor = undefined;
67
+ }
68
+ if (!isObject(floor)) {
69
+ return {
70
+ changed: [],
71
+ skipped: [
72
+ { path: VERIFY_FLOOR_FILE, reason: 'it is not a JSON object, so no row was added to it' },
73
+ ],
74
+ };
75
+ }
76
+ const steps = Array.isArray(floor['steps']) ? floor['steps'] : [];
77
+ const held = isObject(floor['skip']) ? floor['skip'] : {};
78
+ const add = Object.fromEntries(
79
+ Object.entries(await excused(app)).filter(
80
+ ([step]) => !steps.includes(step) && !(step in held),
81
+ ),
82
+ );
83
+ const next = Object.keys(add).length === 0 ? floor : withSkip(floor, add);
84
+ if (Object.keys(add).length === 0) return { changed: [], skipped: [] };
85
+ await app.write(VERIFY_FLOOR_FILE, renderFloor(next));
86
+ return { changed: [VERIFY_FLOOR_FILE], skipped: [] };
87
+ },
88
+ };
@@ -0,0 +1,90 @@
1
+ // 31.28.0: x.verify.json floors every step the scaffold floors for an app like this one (the list
2
+ // is `floorSteps`, never restated here), so none is `X_VERIFY_STEP_UNFLOORED`; and once the floor
3
+ // names every gate step — required or excused — `strict` goes on. Short of that, `strict: false`
4
+ // is written once with a note: a decision recorded, not a question asked on every upgrade.
5
+
6
+ import { floorSteps } from '../templates/scaffold-verify-floor';
7
+ import { VERIFY_FLOOR_FILE } from '../verify-floor';
8
+ import { VERIFY_STEP_NAMES } from '../verify-step';
9
+ import type { Codemod, CodemodResult } from './codemod';
10
+ import { unifiedDiff } from './engine-diff';
11
+ import type { Floor } from './verify-floor-skips';
12
+ import { floorSuites, isObject, renderFloor } from './verify-floor-skips';
13
+
14
+ const NOTHING: CodemodResult = { changed: [], skipped: [] };
15
+
16
+ /** The scaffold's order for every step it floors, then the app's own steps in theirs. */
17
+ const ordered = (
18
+ held: readonly unknown[],
19
+ wanted: readonly string[],
20
+ added: readonly string[],
21
+ ): readonly unknown[] => [
22
+ ...wanted.filter((step) => held.includes(step) || added.includes(step)),
23
+ ...held.filter((step) => typeof step !== 'string' || !wanted.includes(step)),
24
+ ];
25
+
26
+ /** `floor` with `strict` set, placed after `skip` (or `steps`) as the scaffold writes it. */
27
+ function withStrict(floor: Floor, strict: boolean): Floor {
28
+ const anchor = 'skip' in floor ? 'skip' : 'steps';
29
+ const out: Floor = {};
30
+ for (const [key, value] of Object.entries(floor)) {
31
+ if (key === 'strict') continue;
32
+ out[key] = value;
33
+ if (key === anchor) out['strict'] = strict;
34
+ }
35
+ if (!('strict' in out)) out['strict'] = strict;
36
+ return out;
37
+ }
38
+
39
+ export const codemod: Codemod = {
40
+ id: 'verify-floor-steps',
41
+ since: '31.28.0',
42
+ summary: `${VERIFY_FLOOR_FILE} floors every step the scaffold floors, and is strict once it names the whole gate`,
43
+ async run(app) {
44
+ const source = await app.read(VERIFY_FLOOR_FILE);
45
+ if (source === undefined) return NOTHING;
46
+ let floor: unknown;
47
+ try {
48
+ floor = JSON.parse(source);
49
+ } catch {
50
+ return NOTHING;
51
+ }
52
+ // `verify-floor-skips` already reports a floor that is not a JSON object.
53
+ if (!isObject(floor) || !Array.isArray(floor['steps'])) return NOTHING;
54
+ const held: unknown[] = floor['steps'];
55
+ const skip = isObject(floor['skip']) ? floor['skip'] : {};
56
+ const wanted = floorSteps(await floorSuites(app)).steps;
57
+ const added = wanted.filter((step) => !held.includes(step) && !(step in skip));
58
+ // `steps` replaced where it stands: the app's key order kept.
59
+ let next: Floor =
60
+ added.length === 0
61
+ ? floor
62
+ : Object.fromEntries(
63
+ Object.entries(floor).map(([key, value]) => [
64
+ key,
65
+ key === 'steps' ? ordered(held, wanted, added) : value,
66
+ ]),
67
+ );
68
+ const skipped: CodemodResult['skipped'][number][] = [];
69
+ if (next['strict'] === undefined) {
70
+ const named = new Set([...(next['steps'] as unknown[]), ...Object.keys(skip)]);
71
+ const unnamed = VERIFY_STEP_NAMES.filter((step) => !named.has(step));
72
+ next = withStrict(next, unnamed.length === 0);
73
+ if (unnamed.length > 0) {
74
+ skipped.push({
75
+ path: VERIFY_FLOOR_FILE,
76
+ reason: `"strict": false recorded, once: ${unnamed.join(', ')} is in neither "steps" nor "skip", so strict would be red where those run nothing. Run x verify --json, give each its place, then set "strict": true`,
77
+ diff: unifiedDiff(
78
+ VERIFY_FLOOR_FILE,
79
+ renderFloor(next),
80
+ renderFloor(withStrict(next, true)),
81
+ ),
82
+ });
83
+ }
84
+ }
85
+ const text = renderFloor(next);
86
+ if (text === source) return { changed: [], skipped };
87
+ await app.write(VERIFY_FLOOR_FILE, text);
88
+ return { changed: [VERIFY_FLOOR_FILE], skipped };
89
+ },
90
+ };
@@ -0,0 +1,113 @@
1
+ // `x doctor`'s advisory floors: a version the app's `bun.lock` resolves below the first release an
2
+ // npm advisory left behind, for the dependencies the framework brings and cannot floor itself.
3
+ // A warning and never the verdict (`X_BREAKING_ON_MAIN`); `scripts/advisory-floors.ts` is the
4
+ // framework-side half that raises the ranges it can.
5
+
6
+ // why: Bun exposes no path-join primitive; Bun.file takes one already joined.
7
+ import { join } from 'node:path';
8
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
9
+ import type { Finding } from './output';
10
+ import { quoteArg } from './shell-quote';
11
+
12
+ export const ADVISORY_FLOOR_UNMET = 'X_ADVISORY_FLOOR_UNMET';
13
+
14
+ export interface AdvisoryFloor {
15
+ readonly name: string;
16
+ /** The lowest version every listed advisory left behind. */
17
+ readonly floor: string;
18
+ readonly advisories: readonly string[];
19
+ /** How it reaches an app: a range the app declares itself, or one a framework dependency does. */
20
+ readonly via: 'app' | 'transitive';
21
+ }
22
+
23
+ /**
24
+ * As of 2026-11-15. `solid-js` is the app's own pin (`@ultimat3/ui` peers `^1.9.18`: the first
25
+ * release asking for seroval `~1.6.11`); the other two arrive through `sass`, whose ranges admit
26
+ * the patched versions, so a lockfile refresh is the whole fix and no `overrides` is needed.
27
+ */
28
+ export const ADVISORY_FLOORS: readonly AdvisoryFloor[] = [
29
+ {
30
+ name: 'solid-js',
31
+ floor: '1.9.18',
32
+ advisories: ['GHSA-3qxh-p7jc-5xh6', 'GHSA-f86p-h4j2-7qgj', 'GHSA-9wx9-5pv9-3349'],
33
+ via: 'app',
34
+ },
35
+ {
36
+ name: 'source-map-js',
37
+ floor: '1.2.2',
38
+ advisories: ['GHSA-68fv-2mgg-jv7q'],
39
+ via: 'transitive',
40
+ },
41
+ {
42
+ name: 'immutable',
43
+ floor: '5.1.8',
44
+ advisories: ['GHSA-xvcm-6775-5m9r', 'GHSA-v56q-mh7h-f735'],
45
+ via: 'transitive',
46
+ },
47
+ ];
48
+
49
+ /** The floor the codemod raises an app's `solid-js` to. */
50
+ export const SOLID_FLOOR = ADVISORY_FLOORS[0]?.floor ?? '1.9.18';
51
+
52
+ /** A registry release: what `Bun.semver.order` can compare. */
53
+ const RELEASE = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]*)?$/;
54
+
55
+ /** Every version `bun.lock` resolves for `name`, nested `parent/name` entries included. */
56
+ function resolvedVersions(packages: Readonly<Record<string, unknown>>, name: string): string[] {
57
+ return Object.entries(packages).flatMap(([key, entry]) => {
58
+ if (key !== name && !key.endsWith(`/${name}`)) return [];
59
+ const head = Array.isArray(entry) ? entry[0] : undefined;
60
+ return typeof head === 'string' && head.startsWith(`${name}@`)
61
+ ? [head.slice(name.length + 1)]
62
+ : [];
63
+ });
64
+ }
65
+
66
+ async function lockPackages(root: string): Promise<Readonly<Record<string, unknown>> | undefined> {
67
+ const file = Bun.file(join(root, 'bun.lock'));
68
+ if (!(await file.exists())) return undefined;
69
+ try {
70
+ const parsed: unknown = Bun.JSONC.parse(await file.text());
71
+ const packages =
72
+ typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, 'packages') : undefined;
73
+ return typeof packages === 'object' && packages !== null
74
+ ? (packages as Record<string, unknown>)
75
+ : undefined;
76
+ } catch {
77
+ // Not swallowed: an unparsable lockfile is `bun install`'s to refuse, loudly, on the next run.
78
+ return undefined;
79
+ }
80
+ }
81
+
82
+ /** One warning per floor the lockfile resolves under, lowest resolved version named. */
83
+ export async function advisoryFloorFindings(
84
+ root: string,
85
+ floors: readonly AdvisoryFloor[] = ADVISORY_FLOORS,
86
+ ): Promise<readonly Finding[]> {
87
+ const packages = await lockPackages(root);
88
+ if (packages === undefined) return [];
89
+ const transitive = floors.filter((f) => f.via === 'transitive').map((f) => quoteArg(f.name));
90
+ return floors.flatMap((row) => {
91
+ // A git, tarball or `file:` head is no release on npm's line, so no advisory range reads it:
92
+ // skipped rather than ordered, because `Bun.semver.order` throws on it and would take every
93
+ // other `x doctor` check down with this warning.
94
+ const below = resolvedVersions(packages, row.name)
95
+ .filter((version) => RELEASE.test(version))
96
+ .filter((version) => Bun.semver.order(version, row.floor) < 0)
97
+ .sort((a, b) => Bun.semver.order(a, b));
98
+ const lowest = below[0];
99
+ if (lowest === undefined) return [];
100
+ return [
101
+ {
102
+ code: ADVISORY_FLOOR_UNMET,
103
+ cause: `bun.lock resolves ${row.name} ${lowest}, below ${row.floor}, the first release past ${row.advisories.join(', ')}`,
104
+ fix:
105
+ row.via === 'app'
106
+ ? ['bun', 'add', '--exact', `${quoteArg(row.name)}@${row.floor}`].join(' ')
107
+ : ['bun', 'update', ...transitive].join(' '),
108
+ docs: ERROR_DOCS_URL,
109
+ at: 'bun.lock',
110
+ },
111
+ ];
112
+ });
113
+ }
@@ -1,58 +1,16 @@
1
- // `x doctor`'s guard listing: the shipped guards this app's `guards/` does not hold, and the ones
2
- // it holds in a form that is not the current template — each with the command that writes it.
3
- // Never in the VERDICT: every shipped guard is the app's copy ("delete this file to drop the
4
- // rule"), so a missing one is a warning beside it (`data.warnings`) and an edited one a listing.
1
+ // `x doctor`'s guard listing: the copies of shipped guards this app's `guards/` still holds. Every
2
+ // shipped guard runs from the installed framework (`guards-built-in.ts`), so none is ever missing;
3
+ // a copy runs in its place and never receives a fix, so each is listed with its diff and the edit
4
+ // that resolves it (`guards-vendored.ts`). Never in the VERDICT: a warning beside it.
5
5
 
6
6
  // why: Bun exposes no path-join primitive; Bun.file takes one already joined.
7
7
  import { join } from 'node:path';
8
- import { ERROR_DOCS_URL } from '@ultimat3/core';
9
- import { GUARD_DIR, guardPaths } from './guards';
8
+ import { guardPaths } from './guards';
9
+ import { vendoredPath } from './guards-built-in';
10
+ import { resolvingEdit, type VendoredCopy, vendoredCopy, vendoredFinding } from './guards-vendored';
10
11
  import { msg } from './messages';
11
12
  import type { CommandResult, Finding, JsonValue } from './output';
12
- import { SHIPPED_GUARD_NAMES, shippedGuardSources } from './templates/scaffold-guards';
13
-
14
- export interface MissingGuard {
15
- readonly name: string;
16
- /** The command that writes it, with its test. Then `x verify` says what it finds. */
17
- readonly add: string;
18
- }
19
-
20
- /** The rule, pure: which shipped names have no file among the guards an app holds. */
21
- export function missingShippedGuards(present: readonly string[]): readonly MissingGuard[] {
22
- const held = new Set(present.map((path) => path.replace(/\.tsx?$/, '')));
23
- return SHIPPED_GUARD_NAMES.filter((name) => !held.has(`${GUARD_DIR}/${name}`)).map((name) => ({
24
- name,
25
- add: `x g guard ${name}`,
26
- }));
27
- }
28
-
29
- export const MISSING_GUARD = 'X_SHIPPED_GUARD_MISSING';
30
-
31
- /**
32
- * A missing shipped guard as a WARNING, one per guard: the gate does not hold this app to that
33
- * rule, and "no findings — environment is shippable" alone said nothing of it. A warning and not a
34
- * finding, so on `main` an adopter's doctor keeps its exit status (`doctor-warnings.ts`).
35
- */
36
- export function missingGuardWarnings(entries: readonly GuardListingEntry[]): readonly Finding[] {
37
- return entries
38
- .filter((entry): entry is MissingGuard => 'add' in entry)
39
- .map(({ name, add }) => ({
40
- code: MISSING_GUARD,
41
- cause: `${GUARD_DIR}/${name}.ts is not in this app, so x verify does not hold it to the shipped ${name} rule`,
42
- fix: `${add} && x verify --only boundaries --json`,
43
- docs: ERROR_DOCS_URL,
44
- at: `${GUARD_DIR}/${name}.ts`,
45
- }));
46
- }
47
-
48
- export interface DifferingGuard {
49
- readonly name: string;
50
- /** Rewrites the guard and its test from the current template. Review the diff, then keep it. */
51
- readonly refresh: string;
52
- }
53
-
54
- /** One line of the listing: a shipped guard the app lacks, or holds in another form. */
55
- export type GuardListingEntry = MissingGuard | DifferingGuard;
13
+ import { SHIPPED_GUARD_NAMES } from './templates/scaffold-guards';
56
14
 
57
15
  /** A guard file as the app holds it, path relative to the app root. */
58
16
  export interface HeldGuard {
@@ -60,63 +18,58 @@ export interface HeldGuard {
60
18
  readonly source: string;
61
19
  }
62
20
 
63
- /** A checkout on Windows may write CRLF; the rule is the same text either way. */
64
- const sameText = (a: string, b: string): boolean =>
65
- a.replaceAll('\r\n', '\n') === b.replaceAll('\r\n', '\n');
66
-
67
21
  /**
68
- * The rule, pure: which held guards carry a shipped name and are not that guard's current
69
- * template. A guard with a name the framework never shipped is the app's own, and has no template.
22
+ * The rule, pure: which held guards carry a shipped name, each judged against the shipped guard. A
23
+ * guard with a name the framework never shipped is the app's own — `app-<name>` after the migration.
70
24
  */
71
- export function differingShippedGuards(held: readonly HeldGuard[]): readonly DifferingGuard[] {
72
- const differing: DifferingGuard[] = [];
73
- for (const { path, source } of held) {
74
- const name = path.slice(`${GUARD_DIR}/`.length).replace(/\.tsx?$/, '');
75
- // An earlier form a shipped guard still accepts (`shippedGuardSources`) is current too.
76
- const templates = shippedGuardSources(name);
77
- if (templates.length === 0 || templates.some((template) => sameText(source, template)))
78
- continue;
79
- differing.push({ name, refresh: `x g guard ${name} --force` });
25
+ export function vendoredShippedGuards(held: readonly HeldGuard[]): readonly VendoredCopy[] {
26
+ const paths = held.map(({ path }) => path);
27
+ const copies: VendoredCopy[] = [];
28
+ for (const name of SHIPPED_GUARD_NAMES) {
29
+ const path = vendoredPath(paths, name);
30
+ const source = held.find((guard) => guard.path === path)?.source;
31
+ if (path !== undefined && source !== undefined) copies.push(vendoredCopy(name, path, source));
80
32
  }
81
- return differing;
33
+ return copies;
82
34
  }
83
35
 
84
36
  /** The I/O half: the same enumeration the `boundaries` step runs, so the two cannot disagree. */
85
- export async function shippedGuardsProbe(root: string): Promise<readonly GuardListingEntry[]> {
37
+ export async function shippedGuardsProbe(root: string): Promise<readonly VendoredCopy[]> {
86
38
  const paths = await guardPaths(root);
87
39
  const held = await Promise.all(
88
40
  paths.map(async (path) => ({ path, source: await Bun.file(join(root, path)).text() })),
89
41
  );
90
- const entries: GuardListingEntry[] = [
91
- ...missingShippedGuards(paths),
92
- ...differingShippedGuards(held),
93
- ];
94
- return entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
42
+ return vendoredShippedGuards(held);
95
43
  }
96
44
 
45
+ /** One warning per copy — the code the `boundaries` step lists too — so the exit status stays. */
46
+ export const vendoredGuardWarnings = (copies: readonly VendoredCopy[]): readonly Finding[] =>
47
+ copies.map(vendoredFinding);
48
+
97
49
  /**
98
- * The listing, on a result `x doctor` already decided: `data.guards` for a machine; for a person,
99
- * a line per differing guard — a missing one's command is its warning's line, never printed twice.
100
- * `ok`, the summary and the findings are returned as they came.
50
+ * The listing, on a result `x doctor` already decided: `data.guards` for a machine — `missing`
51
+ * always empty now, `differs` each edited copy with the edit that resolves it and its diff,
52
+ * `vendored` every copy — and for a person, one line and an edit per copy. `ok`, the summary and
53
+ * the findings are returned as they came.
101
54
  */
102
55
  export function withGuardListing(
103
56
  result: CommandResult,
104
- entries: readonly GuardListingEntry[],
57
+ copies: readonly VendoredCopy[],
105
58
  ): CommandResult {
106
59
  const data = typeof result.data === 'object' && result.data !== null ? result.data : {};
107
- const missing = entries.filter((entry): entry is MissingGuard => 'add' in entry);
108
- const differs = entries.filter((entry): entry is DifferingGuard => 'refresh' in entry);
109
- const lines = [
110
- ...(differs.length === 0
60
+ const lines =
61
+ copies.length === 0
111
62
  ? []
112
63
  : [
113
- msg('cli.doctor.guardsDiffer', { count: differs.length }),
114
- ...differs.map(({ refresh }) => ` ${refresh}`),
115
- ]),
116
- ];
64
+ msg('cli.doctor.guardsDiffer', { count: copies.length }),
65
+ ...copies.map((copy) => ` ${resolvingEdit(copy)}`),
66
+ ];
117
67
  const guards: JsonValue = {
118
- missing: missing.map(({ name, add }) => ({ name, add })),
119
- differs: differs.map(({ name, refresh }) => ({ name, refresh })),
68
+ missing: [],
69
+ differs: copies
70
+ .filter(({ identical }) => !identical)
71
+ .map((copy) => ({ name: copy.name, refresh: resolvingEdit(copy), diff: copy.diff ?? '' })),
72
+ vendored: copies.map(({ name }) => name),
120
73
  };
121
74
  return {
122
75
  ...result,
@@ -0,0 +1,67 @@
1
+ // `x doctor`'s and `x upgrade`'s superseded workarounds: every note in an app's source or docs
2
+ // that names a workaround the framework has since retired (`superseded.ts`), as a warning with the
3
+ // edit that retires it. A warning and never the verdict: an app that upgrades with no change keeps
4
+ // a green doctor on `main` (`X_BREAKING_ON_MAIN`).
5
+
6
+ // why: Bun exposes no path-join primitive; Bun.file takes one already joined.
7
+ import { join } from 'node:path';
8
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
9
+ import type { Finding } from './output';
10
+ import { eachSourceFile, isVendored, sortedPosix } from './source-files';
11
+ import type { SupersededWorkaround } from './superseded';
12
+ import { SUPERSEDED_WORKAROUNDS } from './superseded';
13
+ import type { SupersededHit } from './superseded-match';
14
+ import { matchSuperseded } from './superseded-match';
15
+
16
+ export const SUPERSEDED_WORKAROUND = 'X_SUPERSEDED_WORKAROUND';
17
+
18
+ /**
19
+ * Beyond the gate's source set: an app's gaps list is markdown, and a hand-written terminator or
20
+ * relay lives in `bin/`, which no gate step reads.
21
+ */
22
+ const EXTRA_GLOBS = ['bin/**/*.{ts,tsx}', '*.md', 'docs/**/*.md'] as const;
23
+
24
+ /** Every file the scan reads: the gate's own source set, then `EXTRA_GLOBS`. */
25
+ export async function supersededPaths(root: string): Promise<readonly string[]> {
26
+ const paths: string[] = [];
27
+ for await (const path of eachSourceFile(root)) paths.push(path);
28
+ for (const pattern of EXTRA_GLOBS) {
29
+ const found: string[] = [];
30
+ for await (const path of new Bun.Glob(pattern).scan({ cwd: root, absolute: false })) {
31
+ if (!isVendored(path)) found.push(path);
32
+ }
33
+ paths.push(...sortedPosix(found));
34
+ }
35
+ return paths;
36
+ }
37
+
38
+ /** One hit as a warning: the cause names the replacement and the version that shipped it. */
39
+ export function supersededFinding(hit: SupersededHit, row: SupersededWorkaround): Finding {
40
+ return {
41
+ code: SUPERSEDED_WORKAROUND,
42
+ cause: `${hit.at} keeps the '${row.id}' workaround; ${row.replacement} shipped in ${row.shippedIn}`,
43
+ fix: row.fix,
44
+ docs: ERROR_DOCS_URL,
45
+ at: hit.at.replace(/:\d+$/, ''),
46
+ };
47
+ }
48
+
49
+ /**
50
+ * The seam `x upgrade` calls too: every superseded workaround under `root`, as warnings, in file
51
+ * order. `rows` defaults to the table; a test passes its own.
52
+ */
53
+ export async function supersededFindings(
54
+ root: string,
55
+ rows: readonly SupersededWorkaround[] = SUPERSEDED_WORKAROUNDS,
56
+ ): Promise<readonly Finding[]> {
57
+ const byId = new Map(rows.map((row) => [row.id, row]));
58
+ const findings: Finding[] = [];
59
+ for (const path of await supersededPaths(root)) {
60
+ const text = await Bun.file(join(root, path)).text();
61
+ for (const hit of matchSuperseded(path, text, rows)) {
62
+ const row = byId.get(hit.id);
63
+ if (row !== undefined) findings.push(supersededFinding(hit, row));
64
+ }
65
+ }
66
+ return findings;
67
+ }
@@ -0,0 +1,26 @@
1
+ // The statement `x drill roll-before-migrate` hands its fleet: the framework schema stamp rewound
2
+ // to name one older build only, so every serving role this build starts meets a schema behind it.
3
+ // Here and not in `@ultimat3/testing`: the stamp is this package's (`framework-schema-stamp.ts`).
4
+
5
+ import { literal } from '@ultimat3/db';
6
+ import { nextStamp, STAMP_RELATION } from './framework-schema-stamp';
7
+
8
+ /** No build's DDL hashes to this, so the stamp names a build this one is not. */
9
+ const OLDER_SCHEMA = '0000000000000000';
10
+
11
+ /** A version before `version`: the previous minor, else the previous patch, else the last major. */
12
+ export function olderVersion(version: string): string {
13
+ const [major = 0, minor = 0, patch = 0] = version
14
+ .split(/[.+-]/)
15
+ .slice(0, 3)
16
+ .map((part) => Number.parseInt(part, 10) || 0);
17
+ if (minor > 0) return `${String(major)}.${String(minor - 1)}.0`;
18
+ if (patch > 0) return `${String(major)}.0.${String(patch - 1)}`;
19
+ return `${String(Math.max(major - 1, 0))}.0.0`;
20
+ }
21
+
22
+ /** The statement that leaves the stamp naming only a build older than `version`. */
23
+ export const behindStampSql = (version: string): string =>
24
+ `comment on table ${STAMP_RELATION} is ${
25
+ literal(nextStamp(null, { version: olderVersion(version), schema: OLDER_SCHEMA })).text
26
+ }`;
@@ -1,7 +1,7 @@
1
- // The X_* codes of how an app is HELD — `x doctor`'s floor, pin, env-name, row-security and
2
- // shipped-guard checks, the `exercise` floor and the `drift` step's undeclared index — split out of
3
- // `error-codes.ts` at its 500-line ceiling. `error-codes.ts` folds these into the CLI's one owned
4
- // union and registers them in its one call; nothing else imports this file.
1
+ // The X_* codes of how an app is HELD — `x doctor`'s floor, pin, env, row-security, guard,
2
+ // superseded-workaround, advisory-floor and owed-codemod checks, the `exercise` floor and `drift`'s
3
+ // undeclared index. Split from `error-codes.ts` at its ceiling; it folds these into the CLI's one
4
+ // owned union and registers them in its one call; nothing else imports this file.
5
5
 
6
6
  /** Codes `x doctor`, the `exercise` floor and the `drift` step's index advice declare and own. */
7
7
  export const CLI_DOCTOR_ERROR_CODES = [
@@ -12,6 +12,10 @@ export const CLI_DOCTOR_ERROR_CODES = [
12
12
  'X_DB_ROW_SECURITY_OFF',
13
13
  'X_DB_INDEX_UNDECLARED',
14
14
  'X_SHIPPED_GUARD_MISSING',
15
+ 'X_SUPERSEDED_WORKAROUND',
16
+ 'X_GUARD_VENDORED',
17
+ 'X_ADVISORY_FLOOR_UNMET',
18
+ 'X_UPGRADE_CODEMODS_PENDING',
15
19
  ] as const;
16
20
 
17
21
  export type CliDoctorErrorCode = (typeof CLI_DOCTOR_ERROR_CODES)[number];
@@ -25,4 +29,8 @@ export const CLI_DOCTOR_ERROR_TITLES: Readonly<Record<CliDoctorErrorCode, string
25
29
  X_DB_ROW_SECURITY_OFF: 'Raw sql reaches tenant tables while database.rowSecurity is off',
26
30
  X_DB_INDEX_UNDECLARED: 'Schema dump holds an index nothing declares',
27
31
  X_SHIPPED_GUARD_MISSING: "A guard x new ships is not in this app's guards/",
32
+ X_SUPERSEDED_WORKAROUND: 'a workaround the framework has since retired is still in the app',
33
+ X_GUARD_VENDORED: 'a guards/ copy of a shipped guard',
34
+ X_ADVISORY_FLOOR_UNMET: 'a resolved dependency is below its advisory floor',
35
+ X_UPGRADE_CODEMODS_PENDING: 'files an older x upgrade left for codemods',
28
36
  };
@@ -237,6 +237,10 @@ export const CLI_OWNED_ERROR_CODES = [
237
237
  'X_DEV_PEER_REFUSED',
238
238
  'X_PROFILE_ROUTE_FAILED',
239
239
  'X_ROWS_SLICE_ENTITY',
240
+ 'X_GUARD_BUILT_IN',
241
+ 'X_REPRO_BUNDLE_INVALID',
242
+ 'X_UPGRADE_LOCKED',
243
+ 'X_APP_MIGRATIONS_UNAPPLIED',
240
244
  ] as const;
241
245
 
242
246
  /**
@@ -462,6 +466,11 @@ export const CLI_ERROR_TITLES: Readonly<Record<CliListedErrorCode, string>> = {
462
466
  X_DEV_PEER_REFUSED: 'a /_x request came from a non-loopback peer',
463
467
  X_PROFILE_ROUTE_FAILED: 'the profiled route answered an error',
464
468
  X_ROWS_SLICE_ENTITY: "the slice's entity is not the scaffolded table",
469
+ X_GUARD_BUILT_IN: 'x g guard named a shipped guard',
470
+ X_REPRO_BUNDLE_INVALID: 'the file is not a repro bundle this version can open',
471
+ X_UPGRADE_LOCKED: 'another x upgrade holds this app',
472
+ X_APP_MIGRATIONS_UNAPPLIED:
473
+ 'a serving role booted over a database missing migrations this build ships',
465
474
  };
466
475
 
467
476
  // One unconditional call, so a second package claiming one of the CLI's codes throws
@@ -4,7 +4,7 @@
4
4
  // gate needs nothing listening, exactly as the `drift` step does not.
5
5
 
6
6
  import type { Environment } from '@ultimat3/core';
7
- import { ENVIRONMENT_KEY, resolveEnvironment, UltimateError } from '@ultimat3/core';
7
+ import { ENVIRONMENT_KEY, resolveEnvironment, UltimateError, withStoreMode } from '@ultimat3/core';
8
8
  import type { DbClient, Migration } from '@ultimat3/db';
9
9
  import { dbExecutor, migrate, raw, setDbClient } from '@ultimat3/db';
10
10
  import {
@@ -59,6 +59,8 @@ const PINNED = [ENVIRONMENT_KEY, 'NODE_ENV'] as const;
59
59
  * no `ULTIMATE_SECRETS_KEY`, and every row sealed here dies with the scratch database). Every
60
60
  * variable is put back as found: a command that exits must not leave the next one a test process.
61
61
  *
62
+ * Core's `storeMode` is declared `database` for the length of `work` (`withStoreMode`).
63
+ *
62
64
  * The frozen clock too, and FIRST — as `bun test`'s preload freezes it before any module loads. The
63
65
  * scratch database is PGlite, whose Postgres arms its timers off `Date.now()`: booted on the real
64
66
  * clock and frozen under later (the pass's room), its 10 s idle-stats timer was re-armed at
@@ -80,7 +82,10 @@ export async function withExerciseProcess<T>(
80
82
  if (!clock.installed) installDeterminism();
81
83
  Object.assign(process.env, added);
82
84
  try {
83
- return await work();
85
+ // A test process ON a database: the scratch one `withExerciseDatabase` installs. A store an
86
+ // app picks at load by core's `storeMode` (an api key, a device token) is that database's, or
87
+ // every reach writing it sends no statement and proves nothing. `bun test` stays `memory`.
88
+ return await withStoreMode('database', work);
84
89
  } finally {
85
90
  restoreCapturedDeterminism(clock);
86
91
  for (const [key, value] of previous) {