@ultimat3/cli 31.26.0 → 31.28.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.
- package/CLAUDE.md +47 -37
- package/README.md +19 -8
- package/package.json +29 -29
- package/src/app-manifest.ts +6 -1
- package/src/app-mcp.ts +17 -3
- package/src/cmd-cache-spec.ts +5 -2
- package/src/cmd-db-spec.ts +2 -3
- package/src/cmd-db.ts +0 -2
- package/src/cmd-deploy-verify-sample.ts +93 -0
- package/src/cmd-deploy-verify.ts +2 -41
- package/src/cmd-dev-spec.ts +15 -1
- package/src/cmd-dev.ts +31 -4
- package/src/cmd-doctor.ts +15 -4
- package/src/cmd-exercise-spec.ts +7 -1
- package/src/cmd-exercise.ts +22 -10
- package/src/cmd-generate.ts +2 -0
- package/src/cmd-jobs-spec.ts +3 -6
- package/src/cmd-jobs.ts +1 -7
- package/src/cmd-logs-spec.ts +2 -1
- package/src/cmd-logs.ts +9 -28
- package/src/cmd-planned.ts +11 -45
- package/src/cmd-profile-frames.ts +99 -0
- package/src/cmd-profile-spec.ts +24 -0
- package/src/cmd-profile.ts +164 -0
- package/src/cmd-repro-spec.ts +13 -1
- package/src/cmd-repro.ts +37 -5
- package/src/cmd-status-sample.ts +57 -0
- package/src/cmd-status-spec.ts +30 -0
- package/src/cmd-status.ts +108 -0
- package/src/cmd-token-spec.ts +5 -2
- package/src/cmd-token.ts +7 -3
- package/src/cmd-upgrade-codemods.ts +71 -0
- package/src/cmd-upgrade-spec.ts +19 -5
- package/src/cmd-upgrade.ts +91 -34
- package/src/codemods/agents-dev-mcp.ts +50 -0
- package/src/codemods/authenticator-session-refusal.ts +214 -0
- package/src/codemods/biome-no-default-export.ts +58 -0
- package/src/codemods/bunfig-island-coverage.ts +33 -0
- package/src/codemods/chart-dashboard.ts +73 -0
- package/src/codemods/ci-e2e-browser-stock.ts +75 -0
- package/src/codemods/ci-e2e-browser.ts +63 -0
- package/src/codemods/codemod.ts +58 -0
- package/src/codemods/define-error-leaf.ts +73 -0
- package/src/codemods/docs-ci-parts.ts +65 -0
- package/src/codemods/docs-gate-prose.ts +53 -0
- package/src/codemods/docs-island-rows.ts +31 -0
- package/src/codemods/docs-shipped-guards.ts +100 -0
- package/src/codemods/docs-test-services.ts +62 -0
- package/src/codemods/engine-diff.ts +104 -0
- package/src/codemods/engine-edits.ts +111 -0
- package/src/codemods/engine-fs.ts +95 -0
- package/src/codemods/engine.ts +191 -0
- package/src/codemods/format-edited-hook-3122.ts +28 -0
- package/src/codemods/format-edited-hook.ts +152 -0
- package/src/codemods/helm-alerts-objective.ts +105 -0
- package/src/codemods/helm-alerts-stock.ts +108 -0
- package/src/codemods/index.ts +56 -0
- package/src/codemods/metrics-probe-healthz.ts +47 -0
- package/src/codemods/pending.ts +36 -0
- package/src/codemods/repro-gitignore.ts +40 -0
- package/src/codemods/runtime-pin-lines.ts +109 -0
- package/src/codemods/runtime-pin.ts +116 -0
- package/src/codemods/solid-floor.ts +63 -0
- package/src/codemods/test-ports.ts +86 -0
- package/src/codemods/test-suites.ts +37 -0
- package/src/codemods/theme-toggle-mount-over.ts +70 -0
- package/src/codemods/vendored-guards.ts +186 -0
- package/src/codemods/verify-floor-skips.ts +88 -0
- package/src/codemods/verify-floor-steps.ts +90 -0
- package/src/coverage-island.ts +121 -0
- package/src/coverage-lcov.ts +49 -5
- package/src/coverage-remap.ts +146 -0
- package/src/db-replay-engine-prepared.ts +66 -0
- package/src/db-replay-engine-template.ts +156 -0
- package/src/db-replay-engine.ts +4 -0
- package/src/db-replay-scratch-reap.ts +54 -0
- package/src/deploy-verify-flags.ts +9 -2
- package/src/deploy-verify-grade.ts +10 -3
- package/src/dev-boot.ts +14 -1
- package/src/dev-dashboard-guard.ts +57 -10
- package/src/dev-host.ts +46 -0
- package/src/dev-tls-cache.ts +103 -0
- package/src/dev-tls-der.ts +69 -0
- package/src/dev-tls.ts +120 -0
- package/src/doctor-advisory-floors.ts +113 -0
- package/src/doctor-browser.ts +60 -0
- package/src/doctor-guards.ts +39 -86
- package/src/doctor-superseded.ts +67 -0
- package/src/error-codes-doctor.ts +12 -4
- package/src/error-codes-verify.ts +47 -0
- package/src/error-codes.ts +20 -23
- package/src/exercise-database.ts +47 -9
- package/src/exercise-push-device.ts +51 -0
- package/src/exercise-route-api.ts +74 -0
- package/src/exercise-routes.ts +14 -5
- package/src/exercise-services.ts +3 -1
- package/src/exercise-shard-flag.ts +47 -0
- package/src/fix-command.ts +2 -2
- package/src/generate-factories.ts +5 -11
- package/src/generate-feature-required.ts +9 -4
- package/src/generate-files.ts +26 -7
- package/src/generate-kinds.ts +5 -1
- package/src/guards-built-in-codes.ts +36 -0
- package/src/guards-built-in-refusal.ts +25 -0
- package/src/guards-built-in.ts +134 -0
- package/src/guards-materialize.ts +42 -0
- package/src/guards-paths.ts +37 -0
- package/src/guards-shipped-names.ts +38 -0
- package/src/guards-vendored.ts +73 -0
- package/src/guards.ts +105 -34
- package/src/index.ts +10 -0
- package/src/island-bundle-options.ts +48 -0
- package/src/island-bundle.ts +18 -46
- package/src/island-link.ts +5 -0
- package/src/island-outputs.ts +5 -0
- package/src/lint-findings.ts +3 -3
- package/src/mcp-errors-verify.ts +35 -0
- package/src/mcp-errors.ts +21 -20
- package/src/mcp-host-logs.ts +121 -0
- package/src/mcp-host.ts +12 -73
- package/src/measure-scope.ts +23 -3
- package/src/messages-floor.ts +19 -0
- package/src/messages-repro.ts +16 -2
- package/src/messages-status.ts +10 -0
- package/src/messages-upgrade.ts +15 -0
- package/src/messages.ts +22 -1
- package/src/registry.ts +4 -0
- package/src/repro-archive-collect.ts +161 -0
- package/src/repro-archive-write.ts +96 -0
- package/src/repro-archive.ts +161 -0
- package/src/repro-bundle.ts +8 -16
- package/src/repro-errors.ts +14 -2
- package/src/repro-framework.ts +53 -0
- package/src/repro-parse.ts +87 -0
- package/src/repro-redact.ts +218 -0
- package/src/repro-scrub.ts +257 -0
- package/src/role-start-types.ts +7 -0
- package/src/role-start.ts +4 -0
- package/src/serve-boot.ts +7 -1
- package/src/serve-env-tls.ts +57 -0
- package/src/solid-loader.ts +27 -10
- package/src/superseded-match.ts +87 -0
- package/src/superseded.ts +84 -0
- package/src/templates/bun-image.ts +48 -0
- package/src/templates/generate-export-rows.ts +136 -0
- package/src/templates/generate-import-rows.ts +186 -0
- package/src/templates/generate-rows-slice.ts +95 -0
- package/src/templates/github/ci.yml.ts +5 -1
- package/src/templates/guard-released-forms.ts +112 -0
- package/src/templates/guard-runtime-pin-test.ts +54 -0
- package/src/templates/guard-runtime-pin.ts +189 -0
- package/src/templates/scaffold-claude-agents.ts +6 -6
- package/src/templates/scaffold-claude-commands.ts +1 -1
- package/src/templates/scaffold-claude-hook.ts +18 -8
- package/src/templates/scaffold-claude.ts +2 -2
- package/src/templates/scaffold-db-package.ts +3 -0
- package/src/templates/scaffold-docs.ts +34 -30
- package/src/templates/scaffold-guards.ts +73 -39
- package/src/templates/scaffold-repo.ts +4 -8
- package/src/templates/scaffold-site.ts +4 -1
- package/src/templates/scaffold-suites.ts +72 -0
- package/src/templates/scaffold-test-services.ts +35 -10
- package/src/templates/scaffold-verify-floor.ts +53 -31
- package/src/templates/shapes/api.ts +4 -0
- package/src/templates/slice-foundation.ts +3 -3
- package/src/unthrown-codes.ts +3 -1
- package/src/upgrade-bun-floor.ts +4 -0
- package/src/upgrade-clean-tree.ts +54 -0
- package/src/upgrade-gate-codemods-install.ts +40 -0
- package/src/upgrade-gate-codemods.ts +151 -0
- package/src/upgrade-gate.ts +44 -7
- package/src/upgrade-guards-baseline.ts +43 -0
- package/src/upgrade-guards.ts +37 -2
- package/src/upgrade-lock.ts +118 -0
- package/src/upgrade-plan.ts +2 -1
- package/src/upgrade-report-codemods.ts +54 -0
- package/src/upgrade-report.ts +55 -27
- package/src/upgrade-signals.ts +91 -0
- package/src/upgrade-unfinished.ts +61 -0
- package/src/verify-coverage-run.ts +42 -11
- package/src/verify-e2e.ts +115 -4
- package/src/verify-floor.ts +27 -0
- package/src/verify-guard-baseline.ts +109 -0
- package/src/verify-live.ts +72 -0
- package/src/verify-merge-skips.ts +51 -0
- package/src/verify-merge.ts +36 -2
- package/src/verify-run.ts +48 -7
- package/src/verify-services.ts +287 -0
- package/src/verify-skip-reason.ts +53 -0
- package/src/verify-strict.ts +108 -0
- package/src/verify-test-command.ts +129 -0
- package/src/verify-tests.ts +39 -126
- package/types/babel-modules.d.ts +2 -0
- package/wiki/CLI-Reference.md +200 -27
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Entities-And-Migrations.md +1 -1
- package/wiki/Interface-Rules.md +17 -8
- package/wiki/Jobs-And-Workflows.md +3 -3
- package/wiki/Known-Gaps.md +5 -1
- package/wiki/MCP-And-AI.md +1 -1
- package/wiki/Observability.md +1 -0
- package/wiki/PWA-And-Offline.md +1 -1
- package/wiki/Project-Layout.md +4 -4
- package/wiki/Troubleshooting.md +3 -3
- package/wiki/Tutorial-05-Deploy-Free.md +2 -2
- package/wiki/Upgrading.md +8 -0
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { sortedImports } from './imports';
|
|
8
8
|
import type { GeneratedFile, NameSet } from './naming';
|
|
9
|
+
import { e2eSuiteFiles } from './scaffold-suites';
|
|
9
10
|
|
|
10
11
|
// Plain strings for the framework lines, never template literals: the workspace-dependency scanner
|
|
11
12
|
// blanks a string's contents but not a nested template's, so a template here would bill the CLI
|
|
@@ -305,9 +306,11 @@ unitTest('it ships zero JS and declares the metadata a search result renders', a
|
|
|
305
306
|
});
|
|
306
307
|
`;
|
|
307
308
|
|
|
308
|
-
/** The landing page, its stylesheet and its
|
|
309
|
+
/** The landing page, its stylesheet, its test and its e2e suite. */
|
|
309
310
|
export const siteFiles = (app: NameSet): readonly GeneratedFile[] => [
|
|
310
311
|
{ path: 'apps/web/site/page.tsx', contents: sitePage(app) },
|
|
311
312
|
{ path: 'apps/web/site/page.module.scss', contents: siteStyle() },
|
|
312
313
|
{ path: 'apps/web/site/page.test.ts', contents: sitePageTest(app) },
|
|
314
|
+
// The same page in a real browser: the `e2e` step every scaffold with a page runs.
|
|
315
|
+
...e2eSuiteFiles(),
|
|
313
316
|
];
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// The two suites every scaffold ships for what a unit test cannot answer: the production driver
|
|
2
|
+
// against a real Postgres (`live`), and the landing page in a real browser (`e2e`). With both, a
|
|
3
|
+
// fresh app's gate runs its `live` and `e2e` steps from the first commit, example slice or not.
|
|
4
|
+
|
|
5
|
+
import type { GeneratedFile } from './naming';
|
|
6
|
+
|
|
7
|
+
/** Where the live suite lands: beside the handle it vouches for. */
|
|
8
|
+
export const LIVE_SUITE_PATH = 'packages/db/src/client.live.test.ts';
|
|
9
|
+
|
|
10
|
+
/** Where the e2e suite lands: beside the page it drives (a shape that drops the page drops it). */
|
|
11
|
+
export const E2E_SUITE_PATH = 'apps/web/site/page.e2e.test.ts';
|
|
12
|
+
|
|
13
|
+
const liveSuite =
|
|
14
|
+
(): string => `// The production driver against a real Postgres — the half the embedded database cannot vouch for.
|
|
15
|
+
// A \`uuid[]\`, a \`timestamptz\`, a \`jsonb\` and a \`bigint\` decoded over the wire, so a decode that
|
|
16
|
+
// differs from PGlite's is red here and not on the first deploy. \`needs\` skips it, naming the
|
|
17
|
+
// command that starts the database, when TEST_DATABASE_URL is unset.
|
|
18
|
+
import { postgresClient, sql } from '@ultimat3/db';
|
|
19
|
+
import { expect, liveTest } from '@ultimat3/testing';
|
|
20
|
+
|
|
21
|
+
const ids = ['00000000-0000-4000-8000-000000000001', '00000000-0000-4000-8000-000000000002'];
|
|
22
|
+
|
|
23
|
+
interface Decoded {
|
|
24
|
+
readonly ids: readonly string[];
|
|
25
|
+
readonly at: Date;
|
|
26
|
+
readonly doc: { readonly n: number };
|
|
27
|
+
readonly big: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
liveTest(
|
|
31
|
+
'the production driver decodes what the app stores',
|
|
32
|
+
async () => {
|
|
33
|
+
const { TEST_DATABASE_URL: url } = Bun.env;
|
|
34
|
+
const client = postgresClient({ url });
|
|
35
|
+
try {
|
|
36
|
+
const [row] = await client.query<Decoded>(
|
|
37
|
+
sql\`select \${ids}::uuid[] as ids, '2026-01-01T00:00:00Z'::timestamptz as at, '{"n":1}'::jsonb as doc, 9007199254740993::bigint as big\`,
|
|
38
|
+
);
|
|
39
|
+
expect(row?.ids).toEqual(ids);
|
|
40
|
+
expect(row?.at.toISOString()).toBe('2026-01-01T00:00:00.000Z');
|
|
41
|
+
expect(row?.doc).toEqual({ n: 1 });
|
|
42
|
+
// Past 2^53: a bigint that came back as a number would have lost its last digit.
|
|
43
|
+
expect(row?.big).toBe('9007199254740993');
|
|
44
|
+
} finally {
|
|
45
|
+
await client.close();
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{ needs: ['postgres'] },
|
|
49
|
+
);
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
const e2eSuite =
|
|
53
|
+
(): string => `// The landing page in a real browser, against the BUILT output — what \`renderRoute\` in
|
|
54
|
+
// page.test.ts cannot see: the document a browser parses and the title its tab shows. Its own file
|
|
55
|
+
// because the gate types a test by its FILENAME — an e2eTest in page.test.ts is a unit test.
|
|
56
|
+
import { e2eTest, expect } from '@ultimat3/testing';
|
|
57
|
+
|
|
58
|
+
e2eTest('/ loads in a browser and names itself', async ({ page }) => {
|
|
59
|
+
await page.goto('/');
|
|
60
|
+
expect(await page.title()).not.toBe('');
|
|
61
|
+
});
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
/** The live suite, in the db package every scaffold writes. */
|
|
65
|
+
export const liveSuiteFiles = (): readonly GeneratedFile[] => [
|
|
66
|
+
{ path: LIVE_SUITE_PATH, contents: liveSuite() },
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
/** The e2e suite, beside the landing page. */
|
|
70
|
+
export const e2eSuiteFiles = (): readonly GeneratedFile[] => [
|
|
71
|
+
{ path: E2E_SUITE_PATH, contents: e2eSuite() },
|
|
72
|
+
];
|
|
@@ -3,17 +3,40 @@
|
|
|
3
3
|
// `docker/docker-compose.test.yml`, cut to what an app has. Ports sit apart from the dev stack's
|
|
4
4
|
// so both can run at once; `ci.yml` starts this file before `bun run verify`.
|
|
5
5
|
|
|
6
|
+
import { fnv1a } from '@ultimat3/core';
|
|
6
7
|
import type { GeneratedFile, NameSet } from './naming';
|
|
7
8
|
import { S3_GATEWAY_IMAGE } from './pinned-images';
|
|
8
9
|
|
|
9
10
|
export const TEST_COMPOSE_PATH = 'docker/docker-compose.test.yml';
|
|
10
11
|
export const TEST_ENV_PATH = 'docker/test-services.env';
|
|
11
12
|
|
|
12
|
-
/**
|
|
13
|
+
/** Each service's band start: the dev stack's port plus 50000, so both stacks run at once. */
|
|
13
14
|
export const TEST_PORTS = { postgres: 55432, redis: 56379, nats: 54222, s3: 59000 } as const;
|
|
14
15
|
|
|
16
|
+
/** How wide each band is: the bands stay disjoint, and two apps collide 1 time in 500. */
|
|
17
|
+
export const TEST_PORT_SPREAD = 500;
|
|
18
|
+
|
|
19
|
+
type TestPorts = { readonly [K in keyof typeof TEST_PORTS]: number };
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* This app's host ports, one place: the compose file publishes them and the env file names them.
|
|
23
|
+
* One fixed set made two scaffolds on one machine share 55432, so the second app's live suites
|
|
24
|
+
* dialled the first app's container; the app's name now picks its offset into each band.
|
|
25
|
+
*/
|
|
26
|
+
export const testPorts = (app: NameSet): TestPorts => {
|
|
27
|
+
// FNV-1a over the app's name: stable across machines and runs.
|
|
28
|
+
const offset = fnv1a(app.kebab) % TEST_PORT_SPREAD;
|
|
29
|
+
return {
|
|
30
|
+
postgres: TEST_PORTS.postgres + offset,
|
|
31
|
+
redis: TEST_PORTS.redis + offset,
|
|
32
|
+
nats: TEST_PORTS.nats + offset,
|
|
33
|
+
s3: TEST_PORTS.s3 + offset,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
15
37
|
const composeTest = (
|
|
16
38
|
app: NameSet,
|
|
39
|
+
ports: TestPorts = testPorts(app),
|
|
17
40
|
): string => `# The services the test suites run against — in RAM, and silent.
|
|
18
41
|
#
|
|
19
42
|
# docker compose -f ${TEST_COMPOSE_PATH} up -d --wait
|
|
@@ -22,7 +45,8 @@ const composeTest = (
|
|
|
22
45
|
#
|
|
23
46
|
# \`--wait\` returns once every healthcheck passes. CI runs the same lines (.github/workflows/ci.yml).
|
|
24
47
|
# None of it is required: with no TEST_* variable set the unit suite runs on the in-memory driver,
|
|
25
|
-
# and a suite that needs a real server skips. Ports are
|
|
48
|
+
# and a suite that needs a real server skips. Ports are this app's own (its name picks
|
|
49
|
+
# them), above the dev stack's, so both stacks — and two apps — run at once.
|
|
26
50
|
#
|
|
27
51
|
# Three rules, on every service:
|
|
28
52
|
#
|
|
@@ -71,7 +95,7 @@ services:
|
|
|
71
95
|
-c min_wal_size=32MB
|
|
72
96
|
-c max_wal_size=256MB
|
|
73
97
|
tmpfs: [/var/lib/postgresql]
|
|
74
|
-
ports: ['127.0.0.1:${
|
|
98
|
+
ports: ['127.0.0.1:${ports.postgres}:5432']
|
|
75
99
|
healthcheck:
|
|
76
100
|
# TCP, never the socket: the entrypoint's temporary init server listens on the socket only.
|
|
77
101
|
test: ['CMD-SHELL', 'pg_isready -U ${app.kebab} -h 127.0.0.1 -p 5432']
|
|
@@ -84,7 +108,7 @@ services:
|
|
|
84
108
|
image: redis:8-alpine
|
|
85
109
|
command: ['redis-server', '--save', '', '--appendonly', 'no', '--loglevel', 'nothing']
|
|
86
110
|
tmpfs: [/data]
|
|
87
|
-
ports: ['127.0.0.1:${
|
|
111
|
+
ports: ['127.0.0.1:${ports.redis}:6379']
|
|
88
112
|
healthcheck:
|
|
89
113
|
test: ['CMD', 'redis-cli', 'ping']
|
|
90
114
|
interval: 1s
|
|
@@ -97,7 +121,7 @@ services:
|
|
|
97
121
|
image: nats:2-alpine
|
|
98
122
|
command: ['-js', '-sd', '/data', '-m', '8222', '-l', '/dev/null']
|
|
99
123
|
tmpfs: [/data]
|
|
100
|
-
ports: ['127.0.0.1:${
|
|
124
|
+
ports: ['127.0.0.1:${ports.nats}:4222']
|
|
101
125
|
healthcheck:
|
|
102
126
|
test: ['CMD', 'wget', '-q', '--spider', 'http://127.0.0.1:8222/healthz']
|
|
103
127
|
interval: 1s
|
|
@@ -117,7 +141,7 @@ services:
|
|
|
117
141
|
ROOT_ACCESS_KEY: ${app.kebab}
|
|
118
142
|
ROOT_SECRET_KEY: ${app.kebab}-test
|
|
119
143
|
tmpfs: [/data/${app.kebab}-test]
|
|
120
|
-
ports: ['127.0.0.1:${
|
|
144
|
+
ports: ['127.0.0.1:${ports.s3}:9000']
|
|
121
145
|
healthcheck:
|
|
122
146
|
test: ['CMD', 'nc', '-z', '127.0.0.1', '9000']
|
|
123
147
|
interval: 1s
|
|
@@ -127,13 +151,14 @@ services:
|
|
|
127
151
|
|
|
128
152
|
const testEnv = (
|
|
129
153
|
app: NameSet,
|
|
154
|
+
ports: TestPorts = testPorts(app),
|
|
130
155
|
): string => `# Where the suites find the services ${TEST_COMPOSE_PATH} starts — the one place these URLs are
|
|
131
156
|
# written. A laptop sources it (\`set -a; . ${TEST_ENV_PATH}; set +a\`); CI appends it to $GITHUB_ENV.
|
|
132
157
|
# TEST_DATABASE_URL is what @ultimat3/testing clones one database per test worker from.
|
|
133
|
-
TEST_DATABASE_URL=postgres://${app.kebab}:${app.kebab}-test@127.0.0.1:${
|
|
134
|
-
TEST_REDIS_URL=redis://127.0.0.1:${
|
|
135
|
-
TEST_NATS_URL=nats://127.0.0.1:${
|
|
136
|
-
TEST_S3_URL=http://${app.kebab}:${app.kebab}-test@127.0.0.1:${
|
|
158
|
+
TEST_DATABASE_URL=postgres://${app.kebab}:${app.kebab}-test@127.0.0.1:${ports.postgres}/postgres
|
|
159
|
+
TEST_REDIS_URL=redis://127.0.0.1:${ports.redis}
|
|
160
|
+
TEST_NATS_URL=nats://127.0.0.1:${ports.nats}
|
|
161
|
+
TEST_S3_URL=http://${app.kebab}:${app.kebab}-test@127.0.0.1:${ports.s3}/${app.kebab}-test
|
|
137
162
|
`;
|
|
138
163
|
|
|
139
164
|
/** The test stack and its env file. */
|
|
@@ -7,30 +7,21 @@ import { COVERAGE_BAR } from '../coverage-floor';
|
|
|
7
7
|
import type { VerifyStepName } from '../verify-step';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* The suite ratchet, committed on day one
|
|
11
|
-
*
|
|
12
|
-
* `
|
|
13
|
-
*
|
|
10
|
+
* The suite ratchet, committed on day one, naming ALL of the gate: every step is either required in
|
|
11
|
+
* `steps` or excused in `skip` with a written why (`verify-strict.ts`), and
|
|
12
|
+
* `scaffold-verify-floor.test.ts` refuses a scaffold that leaves one in neither. Without a floor
|
|
13
|
+
* `readVerifyFloor` answers "no file is no floor" and a deleted suite turns its step from green into
|
|
14
|
+
* skipped-and-green. Typed as `VerifyStepName`, so a name the gate does not run is a compile error.
|
|
14
15
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* is a compile error rather than a floor that covers nothing.
|
|
16
|
+
* `live` and `e2e` are required of every scaffold with the files that make them run
|
|
17
|
+
* (`scaffold-suites.ts`): the production driver against the test Postgres `x verify` starts, the
|
|
18
|
+
* landing page in a real browser. No browser is red with the command that locates one, never a
|
|
19
|
+
* green step that checked nothing. `contract-diff` applies once `bun run setup` has written
|
|
20
|
+
* `x.manifest.json`, which is the first command the README gives.
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* `
|
|
25
|
-
* `x test live` and `x test job` answered X_TEST_NO_FILES. This is the commit that makes the app's
|
|
26
|
-
* own gate run them, which is what the paragraph below always said the condition was.
|
|
27
|
-
*
|
|
28
|
-
* Two remain absent. `e2e` has a scaffolded file and it is an `e2eTest` — `test.skip` until the app
|
|
29
|
-
* registers a browser driver, so the step would run zero tests and fail the ratchet on the
|
|
30
|
-
* scaffold's own placeholder. Its absence is visible rather than silent: a suite that executed
|
|
31
|
-
* nothing reports as a SKIPPED step, not the green check it printed until #434, so the app's own
|
|
32
|
-
* gate line says `- e2e` and names it in the summary until a driver makes it run. `contract-diff` needs a committed `x.manifest.json`, which
|
|
33
|
-
* `x manifest` writes later. Each joins the list in the commit that makes the app's gate run it.
|
|
22
|
+
* And `strict: true`: a step that ran nothing is red unless `skip` carries its why
|
|
23
|
+
* (`X_VERIFY_STRICT_UNRUN`). Measured on a fresh `x new` / `--no-example`: `roadmap` everywhere,
|
|
24
|
+
* `job` without the example slice, `e2e` in the `api` shape — exactly the `WHY` rows below.
|
|
34
25
|
*/
|
|
35
26
|
const SCAFFOLD_FLOOR: readonly VerifyStepName[] = [
|
|
36
27
|
'typecheck',
|
|
@@ -41,11 +32,18 @@ const SCAFFOLD_FLOOR: readonly VerifyStepName[] = [
|
|
|
41
32
|
'errors',
|
|
42
33
|
'unit',
|
|
43
34
|
'contract',
|
|
35
|
+
// `packages/db/src/client.live.test.ts`, in every scaffold — and the example's live query.
|
|
36
|
+
'live',
|
|
44
37
|
// Every app has an `app.config.ts` and primitives to run: `x new` writes `apps/web/exercise.ts`.
|
|
45
38
|
'exercise',
|
|
39
|
+
// `apps/web/site/page.e2e.test.ts` — dropped, with this name, by a shape that serves no page.
|
|
40
|
+
'e2e',
|
|
46
41
|
'eval',
|
|
47
42
|
'drift',
|
|
43
|
+
'contract-diff',
|
|
48
44
|
'budgets',
|
|
45
|
+
'seo',
|
|
46
|
+
'i18n',
|
|
49
47
|
// Always applicable to a scaffolded app — it has an `app.config.ts`, roles and two guarded
|
|
50
48
|
// routes — so a run that reports it skipped is a gate that lost the step, not an app with
|
|
51
49
|
// nothing to check. It is the step that would have caught the 500 `x new` used to ship.
|
|
@@ -53,19 +51,42 @@ const SCAFFOLD_FLOOR: readonly VerifyStepName[] = [
|
|
|
53
51
|
'manifest',
|
|
54
52
|
];
|
|
55
53
|
|
|
56
|
-
/**
|
|
57
|
-
const
|
|
54
|
+
/** Each step a scaffold may not run, with the why its `skip` carries. */
|
|
55
|
+
const WHY = {
|
|
56
|
+
roadmap:
|
|
57
|
+
'a framework-repository step: it checks docs/idea/14-roadmap.md, which only the Ultimate monorepo ships',
|
|
58
|
+
job: 'this app declares no job yet: x g job <name> writes one with its .job.test.ts, and then job moves from "skip" to "steps"',
|
|
59
|
+
e2e: 'this app serves no page for a browser to load: x g route <name> --surface site writes one, and then e2e moves from "skip" to "steps"',
|
|
60
|
+
} as const satisfies Partial<Record<VerifyStepName, string>>;
|
|
61
|
+
|
|
62
|
+
/** What a scaffold ships suites for: a job (the example slice) and a page (every shape but `api`). */
|
|
63
|
+
export interface FloorSuites {
|
|
64
|
+
readonly jobs: boolean;
|
|
65
|
+
readonly pages: boolean;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The floor's `steps` and `skip` for one scaffold, derived from the suites it ships. */
|
|
69
|
+
export function floorSteps(suites: FloorSuites): {
|
|
70
|
+
readonly steps: readonly VerifyStepName[];
|
|
71
|
+
readonly skip: Readonly<Partial<Record<VerifyStepName, string>>>;
|
|
72
|
+
} {
|
|
73
|
+
const steps = SCAFFOLD_FLOOR.filter((step) => step !== 'e2e' || suites.pages);
|
|
74
|
+
return {
|
|
75
|
+
steps: suites.jobs ? [...steps, 'job'] : steps,
|
|
76
|
+
skip: {
|
|
77
|
+
...(suites.jobs ? {} : { job: WHY.job }),
|
|
78
|
+
...(suites.pages ? {} : { e2e: WHY.e2e }),
|
|
79
|
+
roadmap: WHY.roadmap,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
58
83
|
|
|
59
84
|
/**
|
|
60
85
|
* What a unit test cannot execute in a scaffolded app, each with its reason — `x doctor` prints
|
|
61
|
-
* them.
|
|
86
|
+
* them. Entry points only: a file here is a file the floor does not see, so the list is not
|
|
62
87
|
* a place to put code that merely has no test yet.
|
|
63
88
|
*/
|
|
64
89
|
export const SCAFFOLD_COVERAGE_EXCLUDE: readonly CoverageExclude[] = [
|
|
65
|
-
{
|
|
66
|
-
glob: 'apps/**/*.island.tsx',
|
|
67
|
-
why: 'an island runs in a browser: its test mounts a BUILT chunk (mountIsland), and Bun cannot map that chunk back to this source — its states are held by guards/island-without-states.ts and photographed by x shot --island',
|
|
68
|
-
},
|
|
69
90
|
{
|
|
70
91
|
glob: 'apps/*/server.ts',
|
|
71
92
|
why: 'the container entry point: it boots the roles and lives as long as the process — bun run dev and the image exercise it',
|
|
@@ -81,10 +102,11 @@ export const SCAFFOLD_COVERAGE_EXCLUDE: readonly CoverageExclude[] = [
|
|
|
81
102
|
* to (`COVERAGE_BAR`), not a softer one for apps. `scaffold-smoke` runs the app's own `x verify`,
|
|
82
103
|
* so the scaffold is green at it on what it generates or the job is red.
|
|
83
104
|
*/
|
|
84
|
-
export const verifyFloor = (
|
|
105
|
+
export const verifyFloor = (suites: FloorSuites): string =>
|
|
85
106
|
`${JSON.stringify(
|
|
86
107
|
{
|
|
87
|
-
|
|
108
|
+
...floorSteps(suites),
|
|
109
|
+
strict: true,
|
|
88
110
|
coverage: {
|
|
89
111
|
lines: COVERAGE_BAR,
|
|
90
112
|
funcs: COVERAGE_BAR,
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
// documents and the offline fallback, no island, no app UI. `/admin` stays: it is the operator's
|
|
4
4
|
// console. The PWA block stays too: a page `x g` writes into this app is tested offline.
|
|
5
5
|
|
|
6
|
+
import { VERIFY_FLOOR_FILE } from '../../verify-floor';
|
|
6
7
|
import type { GeneratedFile, NameSet } from '../naming';
|
|
8
|
+
import { verifyFloor } from '../scaffold-verify-floor';
|
|
7
9
|
import { apiKeyFiles } from './api-keys';
|
|
8
10
|
import type { ShapeEdit, ShapeOverlay } from './overlay';
|
|
9
11
|
import { claudeRows, shapeLines } from './shared-edits';
|
|
@@ -97,5 +99,7 @@ export const apiShape: ShapeOverlay = {
|
|
|
97
99
|
...apiKeyFiles(),
|
|
98
100
|
{ path: 'apps/web/api/index.ts', contents: apiIndex(app) },
|
|
99
101
|
{ path: 'apps/web/api/index.test.ts', contents: apiIndexTest() },
|
|
102
|
+
// No page, so no browser suite: `e2e` is excused with its why rather than required of nothing.
|
|
103
|
+
{ path: VERIFY_FLOOR_FILE, contents: verifyFloor({ jobs: true, pages: false }) },
|
|
100
104
|
],
|
|
101
105
|
};
|
|
@@ -29,9 +29,9 @@ const notFoundCode = (feature: NameSet): string =>
|
|
|
29
29
|
* The emitted `fix:` cites `x queries list`, and which command it cites is the whole point: a
|
|
30
30
|
* scaffolded app runs the same `errors` step this repo does, so a fix naming a command the build
|
|
31
31
|
* does not ship writes a fresh X_ERROR_FIX_INVALID into the app on every `x g action`. It cited
|
|
32
|
-
* `x db studio`,
|
|
33
|
-
* breaking the one rule it exists to demonstrate. `x queries list` ships, and a
|
|
34
|
-
* caller gets an id that exists.
|
|
32
|
+
* `x db studio`, then planned and exiting X_NOT_IMPLEMENTED (it left the registry 2026-11-15) —
|
|
33
|
+
* the generator was breaking the one rule it exists to demonstrate. `x queries list` ships, and a
|
|
34
|
+
* read is where a caller gets an id that exists.
|
|
35
35
|
*/
|
|
36
36
|
const errorsSource = (feature: NameSet): string => {
|
|
37
37
|
const errorCode = notFoundCode(feature);
|
package/src/unthrown-codes.ts
CHANGED
|
@@ -12,7 +12,7 @@ export const UNTHROWN_CODES_FILE = 'packages/cli/src/unthrown-codes.ts';
|
|
|
12
12
|
* `X_ERROR_CODE_UNTHROWN_STALE`.
|
|
13
13
|
*/
|
|
14
14
|
export const UNTHROWN_CODES: ReadonlySet<string> = new Set([
|
|
15
|
-
// `x db
|
|
15
|
+
// `studio` left `x db` (2026-11-15, wiki/Known-Gaps.md): nothing runs that could fail.
|
|
16
16
|
'X_DB_STUDIO_FAILED',
|
|
17
17
|
// 21.0.0: there is no LiveClient to register (X_REALTIME_UNINSTALLED replaced it).
|
|
18
18
|
'X_LIVE_CLIENT_MISSING',
|
|
@@ -23,4 +23,6 @@ export const UNTHROWN_CODES: ReadonlySet<string> = new Set([
|
|
|
23
23
|
'X_PWA_SYNC_INCOMPLETE',
|
|
24
24
|
// 24.0.0: `x test --worker` was deleted; `x verify --only unit --shard i/n` is the one split.
|
|
25
25
|
'X_TEST_SHARD_FAILED',
|
|
26
|
+
// 31.28.0: shipped guards run built in, so none is ever missing (X_GUARD_VENDORED names copies).
|
|
27
|
+
'X_SHIPPED_GUARD_MISSING',
|
|
26
28
|
]);
|
package/src/upgrade-bun-floor.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
// why: Bun exposes no basename primitive.
|
|
6
6
|
import { basename } from 'node:path';
|
|
7
|
+
import { scaffoldDigestPatch } from './templates/bun-image';
|
|
7
8
|
|
|
8
9
|
export interface BunEdit {
|
|
9
10
|
readonly path: string;
|
|
@@ -181,6 +182,9 @@ function editLine(input: {
|
|
|
181
182
|
const parts = TAG.exec(tag);
|
|
182
183
|
const version = parts?.[1];
|
|
183
184
|
if (digest !== undefined) {
|
|
185
|
+
// A digest `x new` wrote holds a patch the framework knows, so the line says enough after all.
|
|
186
|
+
const known = scaffoldDigestPatch(digest.slice(1));
|
|
187
|
+
if (known !== undefined && !isBelow(known, floor)) return line;
|
|
184
188
|
const inspect = `by hand (docker buildx imagetools inspect oven/bun:${floor}-alpine)`;
|
|
185
189
|
if (version === undefined || isBelow(version, floor)) {
|
|
186
190
|
return listed(
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// `x upgrade`'s first refusal: a hop is one reviewable commit, so the tree must be clean — its own
|
|
2
|
+
// lock and record aside. When a stopped hop's record is there, the dirty tree IS that hop, and the
|
|
3
|
+
// fix is to stash it: committing half a hop is how a broken tree gets reviewed as a finished one.
|
|
4
|
+
|
|
5
|
+
// why: Bun exposes no path-join primitive; the state files are joined onto the app root.
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { UltimateError } from '@ultimat3/core';
|
|
8
|
+
import type { Runner } from './exec';
|
|
9
|
+
import { posixRelative } from './posix-path';
|
|
10
|
+
import { UPGRADE_LOCK_FILE } from './upgrade-lock';
|
|
11
|
+
import type { UnfinishedHop } from './upgrade-unfinished';
|
|
12
|
+
import { UNFINISHED_FILE } from './upgrade-unfinished';
|
|
13
|
+
|
|
14
|
+
/** The repository's root, or the refusal: git is the only record of where the walk stands. */
|
|
15
|
+
export async function requireCleanTree(
|
|
16
|
+
runner: Runner,
|
|
17
|
+
root: string,
|
|
18
|
+
unfinished: UnfinishedHop | undefined,
|
|
19
|
+
): Promise<string> {
|
|
20
|
+
const top = await runner(['git', 'rev-parse', '--show-toplevel'], { cwd: root });
|
|
21
|
+
if (!top.ok) {
|
|
22
|
+
throw new UltimateError({
|
|
23
|
+
code: 'X_UPGRADE_DIRTY_TREE',
|
|
24
|
+
cause: `${root} is not a git repository, and a hop has to be one commit you can review or undo`,
|
|
25
|
+
fix: 'git init && git add -A && git commit -m "before x upgrade" # then: x upgrade --json',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const repo = top.stdout.trim();
|
|
29
|
+
// Every untracked file by name, so this run's own lock and record — in an `.x/` a repository
|
|
30
|
+
// with no app may not ignore — are told apart from an author's change.
|
|
31
|
+
const own = new Set(
|
|
32
|
+
[UPGRADE_LOCK_FILE, UNFINISHED_FILE].map((file) => posixRelative(repo, join(root, file))),
|
|
33
|
+
);
|
|
34
|
+
const status = await runner(['git', 'status', '--porcelain', '--untracked-files=all'], {
|
|
35
|
+
cwd: root,
|
|
36
|
+
});
|
|
37
|
+
const changes = status.stdout
|
|
38
|
+
.split('\n')
|
|
39
|
+
.filter((line) => line.trim().length > 0 && !own.has(line.slice(3)));
|
|
40
|
+
if (status.ok && changes.length === 0) return repo;
|
|
41
|
+
const listed = changes.slice(0, 5).join('; ');
|
|
42
|
+
if (unfinished !== undefined) {
|
|
43
|
+
throw new UltimateError({
|
|
44
|
+
code: 'X_UPGRADE_DIRTY_TREE',
|
|
45
|
+
cause: `an x upgrade from ${unfinished.from} to ${unfinished.to} stopped after writing its pins (${UNFINISHED_FILE}, started ${unfinished.startedAt || 'at an unknown time'}), and its ${String(changes.length)} uncommitted change(s) are that half-finished hop: ${listed}`,
|
|
46
|
+
fix: 'git stash push --include-untracked # sets the half hop aside; then: x upgrade --json',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
throw new UltimateError({
|
|
50
|
+
code: 'X_UPGRADE_DIRTY_TREE',
|
|
51
|
+
cause: `${String(changes.length)} uncommitted change(s), and a hop has to be one reviewable commit: ${listed}`,
|
|
52
|
+
fix: 'git status --short # then commit or stash, and re-run: x upgrade --json',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// After codemods, the install they may owe: every `package.json` of the app read before and after,
|
|
2
|
+
// byte for byte — never a codemod's own report, which an installed CLI may under-state — and one
|
|
3
|
+
// `bun install` when any moved, so bun.lock and node_modules follow before anything reads them.
|
|
4
|
+
|
|
5
|
+
import { UltimateError } from '@ultimat3/core';
|
|
6
|
+
import type { Runner } from './exec';
|
|
7
|
+
import { execOutput } from './exec';
|
|
8
|
+
|
|
9
|
+
const MANIFESTS = new Bun.Glob('**/package.json');
|
|
10
|
+
|
|
11
|
+
/** Every `package.json` under the app root (none under `node_modules`), path to bytes. */
|
|
12
|
+
export async function manifestSnapshot(root: string): Promise<ReadonlyMap<string, string>> {
|
|
13
|
+
const out = new Map<string, string>();
|
|
14
|
+
for await (const path of MANIFESTS.scan({ cwd: root, dot: false })) {
|
|
15
|
+
const posix = path.replaceAll('\\', '/');
|
|
16
|
+
if (posix.split('/').includes('node_modules')) continue;
|
|
17
|
+
out.set(posix, await Bun.file(`${root}/${posix}`).text());
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const moved = (before: ReadonlyMap<string, string>, after: ReadonlyMap<string, string>): boolean =>
|
|
23
|
+
before.size !== after.size || [...after].some(([path, text]) => before.get(path) !== text);
|
|
24
|
+
|
|
25
|
+
/** `bun install` when a manifest moved since `before`; true when it ran. */
|
|
26
|
+
export async function reinstallIfMoved(input: {
|
|
27
|
+
readonly runner: Runner;
|
|
28
|
+
readonly root: string;
|
|
29
|
+
readonly to: string;
|
|
30
|
+
readonly before: ReadonlyMap<string, string>;
|
|
31
|
+
}): Promise<boolean> {
|
|
32
|
+
if (!moved(input.before, await manifestSnapshot(input.root))) return false;
|
|
33
|
+
const result = await input.runner([process.execPath, 'install'], { cwd: input.root });
|
|
34
|
+
if (result.ok) return true;
|
|
35
|
+
throw new UltimateError({
|
|
36
|
+
code: 'X_UPGRADE_INSTALL_FAILED',
|
|
37
|
+
cause: `bun install exited ${String(result.code)} after the ${input.to} codemods moved a package.json: ${execOutput(result).slice(-800) || 'no output'}`,
|
|
38
|
+
fix: 'git diff -- "*package.json" # the codemods\' edits; fix what the cause names, then: bun install && x upgrade --json',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// A hop's codemods, applied by the CLI the hop just installed (`x upgrade codemods`): that CLI holds
|
|
2
|
+
// the target release's list, which this one may predate. An installed CLI with no such subcommand
|
|
3
|
+
// (one older than the engine) answers no document; this CLI applies its own list instead.
|
|
4
|
+
|
|
5
|
+
// why: Bun exposes no path-join primitive; the installed bin is assembled from the app root.
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { t } from '@ultimat3/schema';
|
|
8
|
+
import { CODEMODS } from './codemods';
|
|
9
|
+
import type { CodemodsReport } from './codemods/engine';
|
|
10
|
+
import { runCodemods } from './codemods/engine';
|
|
11
|
+
import { fsCodemodApp } from './codemods/engine-fs';
|
|
12
|
+
import { supersededFindings } from './doctor-superseded';
|
|
13
|
+
import type { ExecResult, Runner } from './exec';
|
|
14
|
+
import { LOCAL_CLI_BIN } from './local-cli';
|
|
15
|
+
import type { Finding } from './output';
|
|
16
|
+
import { documentIn } from './upgrade-document';
|
|
17
|
+
import { manifestSnapshot, reinstallIfMoved } from './upgrade-gate-codemods-install';
|
|
18
|
+
import type { HopCodemods } from './upgrade-report-codemods';
|
|
19
|
+
|
|
20
|
+
const SKIP = t.object({ path: t.string, reason: t.string, diff: t.optional(t.string) });
|
|
21
|
+
const OUTCOME = t.object({
|
|
22
|
+
id: t.string,
|
|
23
|
+
since: t.string,
|
|
24
|
+
summary: t.string,
|
|
25
|
+
changed: t.array(t.string),
|
|
26
|
+
skipped: t.array(SKIP),
|
|
27
|
+
});
|
|
28
|
+
const DOCUMENT = t.object({
|
|
29
|
+
data: t.object({
|
|
30
|
+
codemods: t.object({
|
|
31
|
+
from: t.string,
|
|
32
|
+
to: t.string,
|
|
33
|
+
dryRun: t.boolean,
|
|
34
|
+
applied: t.array(OUTCOME),
|
|
35
|
+
}),
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/** The installed CLI's report, or undefined when it answered none this one can read. */
|
|
40
|
+
export function readCodemods(result: ExecResult): CodemodsReport | undefined {
|
|
41
|
+
const parsed = DOCUMENT.safeParse(documentIn(result.stdout));
|
|
42
|
+
if (!result.ok || parsed.issues !== undefined) return undefined;
|
|
43
|
+
return (parsed.value as { readonly data: { readonly codemods: CodemodsReport } }).data.codemods;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The codes an installed CLI with no `x upgrade codemods` answers: an unknown flag or subcommand,
|
|
48
|
+
* an unknown command. Only those leave the span to this CLI; any other failure is the hop's.
|
|
49
|
+
*/
|
|
50
|
+
const NO_SUBCOMMAND = new Set(['X_CLI_BAD_FLAG', 'X_CLI_UNKNOWN_COMMAND', 'X_NOT_IMPLEMENTED']);
|
|
51
|
+
|
|
52
|
+
const FAILURE = t.object({
|
|
53
|
+
findings: t.array(t.object({ code: t.string, cause: t.string, fix: t.string })),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/** The installed CLI's own failure, when it is one: undefined when it simply lacks the subcommand. */
|
|
57
|
+
function failureOf(result: ExecResult): HopCodemods['failure'] {
|
|
58
|
+
const parsed = FAILURE.safeParse(documentIn(result.stdout));
|
|
59
|
+
if (parsed.issues !== undefined) return undefined;
|
|
60
|
+
const [first] = (parsed.value as { readonly findings: NonNullable<HopCodemods['failure']>[] })
|
|
61
|
+
.findings;
|
|
62
|
+
return first === undefined || NO_SUBCOMMAND.has(first.code) ? undefined : first;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The span's codemods, by the installed CLI (or this one, only when that one lacks the
|
|
67
|
+
* subcommand), then a second `bun install` when any `package.json` moved — `reinstalled: true`.
|
|
68
|
+
*/
|
|
69
|
+
export async function applyHopCodemods(input: {
|
|
70
|
+
readonly runner: Runner;
|
|
71
|
+
readonly root: string;
|
|
72
|
+
readonly from: string;
|
|
73
|
+
readonly to: string;
|
|
74
|
+
}): Promise<HopCodemods> {
|
|
75
|
+
const { runner, root, from, to } = input;
|
|
76
|
+
const before = await manifestSnapshot(root);
|
|
77
|
+
const result = await runner(
|
|
78
|
+
[
|
|
79
|
+
process.execPath,
|
|
80
|
+
join(root, LOCAL_CLI_BIN),
|
|
81
|
+
'upgrade',
|
|
82
|
+
'codemods',
|
|
83
|
+
'--from',
|
|
84
|
+
from,
|
|
85
|
+
'--to',
|
|
86
|
+
to,
|
|
87
|
+
'--json',
|
|
88
|
+
],
|
|
89
|
+
{ cwd: root },
|
|
90
|
+
);
|
|
91
|
+
const answered = readCodemods(result);
|
|
92
|
+
const failure = answered === undefined ? failureOf(result) : undefined;
|
|
93
|
+
if (failure !== undefined) {
|
|
94
|
+
return { from, to, dryRun: false, applied: [], source: 'installed', failure };
|
|
95
|
+
}
|
|
96
|
+
const report: HopCodemods =
|
|
97
|
+
answered !== undefined
|
|
98
|
+
? { ...answered, source: 'installed' }
|
|
99
|
+
: {
|
|
100
|
+
...(await runCodemods({
|
|
101
|
+
app: fsCodemodApp(root),
|
|
102
|
+
codemods: CODEMODS,
|
|
103
|
+
from,
|
|
104
|
+
to,
|
|
105
|
+
dryRun: false,
|
|
106
|
+
})),
|
|
107
|
+
source: 'driver',
|
|
108
|
+
};
|
|
109
|
+
return (await reinstallIfMoved({ runner, root, to, before }))
|
|
110
|
+
? { ...report, reinstalled: true }
|
|
111
|
+
: report;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* `x upgrade --dry-run`'s view: this CLI's codemods over the span, written nowhere, and the
|
|
116
|
+
* superseded workarounds the tree holds now. The hop itself applies the installed release's list.
|
|
117
|
+
*/
|
|
118
|
+
export async function previewCodemods(
|
|
119
|
+
root: string,
|
|
120
|
+
from: string,
|
|
121
|
+
to: string,
|
|
122
|
+
): Promise<{ readonly codemods: HopCodemods; readonly superseded: readonly Finding[] }> {
|
|
123
|
+
const own = await runCodemods({
|
|
124
|
+
app: fsCodemodApp(root),
|
|
125
|
+
codemods: CODEMODS,
|
|
126
|
+
from,
|
|
127
|
+
to,
|
|
128
|
+
dryRun: true,
|
|
129
|
+
});
|
|
130
|
+
return { codemods: { ...own, source: 'driver' }, superseded: await supersededFindings(root) };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Below every release: an app already at its target reruns every codemod, which are idempotent. */
|
|
134
|
+
export const EVERY_RELEASE = '0.0.0';
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* No version moves, and still no copy of an old template stays: every codemod up to the release
|
|
138
|
+
* the app is on, through the installed CLI as a hop would (a dry run previews this CLI's list).
|
|
139
|
+
* Each is idempotent, so one already applied is a run that changes nothing.
|
|
140
|
+
*/
|
|
141
|
+
export async function atTargetCodemods(input: {
|
|
142
|
+
readonly runner: Runner;
|
|
143
|
+
readonly root: string;
|
|
144
|
+
readonly to: string;
|
|
145
|
+
readonly dryRun: boolean;
|
|
146
|
+
}): Promise<{ readonly codemods: HopCodemods; readonly superseded: readonly Finding[] }> {
|
|
147
|
+
const { runner, root, to } = input;
|
|
148
|
+
if (input.dryRun) return previewCodemods(root, EVERY_RELEASE, to);
|
|
149
|
+
const codemods = await applyHopCodemods({ runner, root, from: EVERY_RELEASE, to });
|
|
150
|
+
return { codemods, superseded: await supersededFindings(root) };
|
|
151
|
+
}
|