@ultimat3/cli 30.9.0 → 31.0.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 +75 -64
- package/README.md +4 -1
- package/package.json +30 -29
- package/src/admin-registration.ts +1 -1
- package/src/affected.ts +5 -1
- package/src/app-boundaries.ts +88 -9
- package/src/app-load-async.ts +133 -0
- package/src/app-load-batch.ts +203 -0
- package/src/app-load-prebuilt.ts +147 -0
- package/src/app-load-register.ts +175 -0
- package/src/app-load.ts +143 -175
- package/src/app-loader-imports.ts +31 -0
- package/src/app-root.ts +13 -0
- package/src/app-runtime.ts +5 -1
- package/src/boundary-findings.ts +12 -0
- package/src/browser-launcher-port.ts +3 -7
- package/src/browser-launcher.ts +1 -1
- package/src/budgets-scan.ts +8 -0
- package/src/budgets.ts +10 -1
- package/src/build-registry-background.ts +59 -0
- package/src/build-registry.ts +207 -0
- package/src/cdp-shot-clock.ts +3 -11
- package/src/cdp-shot-driver.ts +3 -2
- package/src/cdp-shot-element.ts +3 -2
- package/src/cdp-shot-page.ts +2 -2
- package/src/cdp-shot-watch.ts +4 -3
- package/src/cmd-auth.ts +3 -3
- package/src/cmd-db-recount.ts +15 -0
- package/src/cmd-drill.ts +10 -6
- package/src/cmd-exercise.ts +2 -1
- package/src/cmd-generate-spec.ts +6 -0
- package/src/cmd-generate.ts +22 -4
- package/src/cmd-mail.ts +1 -1
- package/src/cmd-routes.ts +2 -2
- package/src/cmd-secrets-spec.ts +4 -1
- package/src/cmd-shot.ts +14 -4
- package/src/cmd-verify-spec.ts +21 -1
- package/src/cmd-verify.ts +16 -4
- package/src/coverage-source.ts +4 -1
- package/src/db-diagnostics.ts +8 -1
- package/src/dev-boot.ts +29 -15
- package/src/dev-dashboard-invalidations.ts +43 -0
- package/src/dev-dashboard.ts +13 -16
- package/src/dev-n-plus-one.ts +7 -3
- package/src/dev-rebuild.ts +2 -1
- package/src/dev-route-table.ts +1 -1
- package/src/dev-traces.ts +16 -15
- package/src/document-options.ts +12 -1
- package/src/drift-store.ts +55 -0
- package/src/error-catalog.ts +8 -3
- package/src/error-codes-boundary.ts +32 -0
- package/src/error-codes.ts +23 -19
- package/src/errors.ts +17 -7
- package/src/exercise-database.ts +13 -1
- package/src/exercise-findings.ts +36 -18
- package/src/exercise-services.ts +84 -0
- package/src/exercise-subject.ts +38 -13
- package/src/failure-capture-boot.ts +9 -5
- package/src/framework-schema.ts +5 -5
- package/src/generate-exercise.ts +1 -1
- package/src/generate-files.ts +27 -7
- package/src/generate-kinds.ts +5 -0
- package/src/generate-refresh.ts +53 -0
- package/src/generate-workspace.ts +169 -0
- package/src/generate-write.ts +8 -2
- package/src/hold.ts +19 -8
- package/src/image-prepare.ts +6 -2
- package/src/index.ts +5 -20
- package/src/island-bundle.ts +7 -3
- package/src/island-capture.ts +2 -2
- package/src/island-harness.ts +1 -1
- package/src/job-registration.ts +43 -6
- package/src/jobs-driver.ts +4 -5
- package/src/mcp-errors.ts +18 -4
- package/src/mcp-host.ts +5 -1
- package/src/mcp-ui-interact.ts +3 -0
- package/src/messages-gate.ts +4 -0
- package/src/new-shapes-generate.ts +1 -1
- package/src/otlp-export.ts +94 -29
- package/src/output.ts +3 -7
- package/src/page-sync.ts +3 -1
- package/src/role-load.ts +17 -11
- package/src/role-start.ts +5 -4
- package/src/role-sync.ts +7 -8
- package/src/route-islands-preload.ts +46 -0
- package/src/route-islands.ts +6 -2
- package/src/runtime-admin.ts +5 -1
- package/src/runtime-bindings.ts +25 -19
- package/src/runtime-boot-ports.ts +66 -0
- package/src/runtime-bus.ts +29 -5
- package/src/runtime-cache-bus.ts +53 -0
- package/src/runtime-cache.ts +43 -13
- package/src/runtime-isr-outcome.ts +5 -4
- package/src/runtime-jobs.ts +2 -2
- package/src/runtime-keys.ts +37 -0
- package/src/runtime-overrides.ts +148 -42
- package/src/runtime-port-bindings-queue.ts +36 -0
- package/src/runtime-port-bindings.ts +117 -0
- package/src/runtime-ports.ts +164 -0
- package/src/runtime-purge.ts +41 -28
- package/src/runtime-push.ts +7 -3
- package/src/runtime-queue.ts +70 -55
- package/src/runtime-realtime.ts +5 -5
- package/src/runtime-render-document.ts +4 -1
- package/src/runtime-services.ts +110 -158
- package/src/runtime-storage-boot.ts +111 -0
- package/src/runtime-storage-upload.ts +9 -7
- package/src/runtime-storage.ts +7 -1
- package/src/serve-boot.ts +8 -4
- package/src/serve-entry.ts +3 -0
- package/src/serve-env.ts +47 -14
- package/src/serve-prebuilt-paths.ts +3 -0
- package/src/serve-prebuilt.ts +15 -4
- package/src/serve.ts +2 -2
- package/src/static-cards.ts +3 -2
- package/src/static-report.ts +2 -2
- package/src/style-bundle.ts +1 -1
- package/src/sync-authenticator.ts +17 -18
- package/src/templates/action-tests.ts +4 -4
- package/src/templates/backfill.ts +5 -8
- package/src/templates/entity.ts +3 -0
- package/src/templates/github/ci.yml.ts +3 -1
- package/src/templates/github/dependabot.yml.ts +73 -0
- package/src/templates/job.ts +13 -22
- package/src/templates/naming.ts +20 -1
- package/src/templates/pinned/docker-compose.yml +1 -1
- package/src/templates/query.ts +7 -8
- package/src/templates/route.ts +5 -3
- package/src/templates/scaffold-api.ts +1 -1
- package/src/templates/scaffold-auth.ts +5 -3
- package/src/templates/scaffold-claude-commands.ts +6 -3
- package/src/templates/scaffold-claude.ts +4 -4
- package/src/templates/scaffold-container-compose.ts +2 -4
- package/src/templates/scaffold-domain-package.ts +1 -1
- package/src/templates/scaffold-entries.ts +6 -1
- package/src/templates/scaffold-helm-fences.ts +3 -2
- package/src/templates/scaffold-helm.ts +35 -6
- package/src/templates/scaffold-repo.ts +47 -135
- package/src/templates/scaffold-runtime-ports.ts +62 -0
- package/src/templates/scaffold-verify-floor.ts +97 -0
- package/src/templates/shapes/overlay.ts +1 -1
- package/src/templates/sign-in-oidc.ts +5 -3
- package/src/templates/sign-in-shared.ts +28 -10
- package/src/templates/workspace.ts +75 -0
- package/src/test-ignores.ts +5 -2
- package/src/test-select.ts +4 -1
- package/src/upgrade-gate.ts +30 -5
- package/src/upgrade-report.ts +7 -1
- package/src/verify-changed-facts.ts +53 -0
- package/src/verify-changed-scope.ts +161 -0
- package/src/verify-changed.ts +174 -0
- package/src/verify-checks.ts +31 -19
- package/src/verify-drift-owner.ts +30 -0
- package/src/verify-e2e.ts +2 -1
- package/src/verify-factories.ts +86 -0
- package/src/verify-run.ts +13 -11
- package/src/verify-step.ts +13 -0
- package/src/verify-tests.ts +58 -6
- package/src/write-line.ts +21 -6
- package/wiki/Actions.md +2 -2
- package/wiki/Adapters.md +400 -0
- package/wiki/Admin-Dashboard.md +1 -1
- package/wiki/Agents.md +9 -9
- package/wiki/Auth.md +78 -2
- package/wiki/Building-Your-Own-Base.md +1 -1
- package/wiki/CLI-Reference.md +34 -7
- package/wiki/Caching-And-Invalidation.md +17 -5
- package/wiki/Compared.md +8 -2
- package/wiki/Configuration.md +14 -14
- package/wiki/Deployment.md +28 -1
- package/wiki/Entities-And-Migrations.md +47 -1
- package/wiki/FAQ.md +8 -2
- package/wiki/Feature-Flags.md +1 -1
- package/wiki/Home.md +3 -2
- package/wiki/Jobs-And-Workflows.md +107 -6
- package/wiki/Known-Gaps.md +4 -3
- package/wiki/MCP-And-AI.md +18 -4
- package/wiki/Mail.md +14 -5
- package/wiki/Migrations-And-Backfills.md +29 -4
- package/wiki/Money.md +2 -0
- package/wiki/N-Plus-One-Detection.md +24 -22
- package/wiki/Notify.md +28 -4
- package/wiki/Observability.md +121 -15
- package/wiki/Queries-And-Live-Queries.md +2 -2
- package/wiki/Realtime.md +9 -4
- package/wiki/Routes-And-Render-Modes.md +5 -0
- package/wiki/Scraping.md +57 -11
- package/wiki/Shapes.md +2 -2
- package/wiki/Stability.md +7 -5
- package/wiki/Storage-And-Uploads.md +56 -4
- package/wiki/Testing.md +65 -52
- package/wiki/Troubleshooting.md +1 -1
- package/wiki/Tutorial-01-First-App.md +1 -1
- package/wiki/Tutorial-04-Jobs-And-Realtime.md +1 -1
- package/wiki/Tutorial-05-Deploy-Free.md +1 -1
- package/wiki/Tutorial-06-Growing-Up.md +8 -8
- package/wiki/Upgrading.md +129 -4
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// the page that links to the first one. PKCE, the sealed handshake, the state check and the account
|
|
4
4
|
// link are the framework's; which IdP group means which role stays the app's (`resolveGrants`).
|
|
5
5
|
|
|
6
|
+
// The literal the generated tests pin comes from auth itself, so the scaffold cannot drift from it.
|
|
7
|
+
import { oauthStartPath } from '@ultimat3/auth';
|
|
6
8
|
import { catalogJson } from './catalog-json';
|
|
7
9
|
import { catalogPath } from './locales';
|
|
8
10
|
import type { GeneratedFile } from './naming';
|
|
@@ -54,7 +56,7 @@ import { AFTER_SIGN_IN } from './sign-in-flow';
|
|
|
54
56
|
|
|
55
57
|
export const OIDC_PROVIDER = '${provider}';
|
|
56
58
|
export const OIDC_ISSUER_ENV = '${oidcEnvPrefix(provider)}_ISSUER';
|
|
57
|
-
/** Where the sign-in page sends a browser: the start leg,
|
|
59
|
+
/** Where the sign-in page sends a browser: the start leg, \`${oauthStartPath(provider)}\`. */
|
|
58
60
|
export const OIDC_START_PATH = oauthStartPath(OIDC_PROVIDER);
|
|
59
61
|
|
|
60
62
|
type Env = Readonly<Record<string, string | undefined>>;
|
|
@@ -94,7 +96,7 @@ import { OIDC_ISSUER_ENV, OIDC_PROVIDER, OIDC_START_PATH, oidcLegs } from './oid
|
|
|
94
96
|
unitTest('the provider, its issuer key and its start path are spelled once', () => {
|
|
95
97
|
expect(OIDC_PROVIDER).toBe('${provider}');
|
|
96
98
|
expect(OIDC_ISSUER_ENV).toBe('${oidcEnvPrefix(provider)}_ISSUER');
|
|
97
|
-
expect(OIDC_START_PATH).toBe('
|
|
99
|
+
expect(OIDC_START_PATH).toBe('${oauthStartPath(provider)}');
|
|
98
100
|
// Importing this module registered nothing: the first sign-in does.
|
|
99
101
|
expect(hasOAuthProvider(OIDC_PROVIDER)).toBe(false);
|
|
100
102
|
});
|
|
@@ -175,7 +177,7 @@ export function oidcSignInFiles(
|
|
|
175
177
|
{ path: `${AUTH_DIR}/sign-in/page.tsx`, contents: signInPageSource(module, OIDC_FORM) },
|
|
176
178
|
{
|
|
177
179
|
path: `${AUTH_DIR}/sign-in/page.test.ts`,
|
|
178
|
-
contents: signInPageTest(module, 'app.auth.signIn', `'href="
|
|
180
|
+
contents: signInPageTest(module, 'app.auth.signIn', `'href="${oauthStartPath(provider)}"'`),
|
|
179
181
|
},
|
|
180
182
|
...options.locales.map((locale) => ({
|
|
181
183
|
path: catalogPath(locale),
|
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
import type { GeneratedFile } from './naming';
|
|
7
7
|
import { authModule } from './scaffold-auth';
|
|
8
|
+
import {
|
|
9
|
+
baseRuntimeSource,
|
|
10
|
+
baseRuntimeTest,
|
|
11
|
+
RUNTIME_HEADER,
|
|
12
|
+
RUNTIME_MODULE,
|
|
13
|
+
RUNTIME_TEST,
|
|
14
|
+
runtimePortLines,
|
|
15
|
+
} from './scaffold-runtime-ports';
|
|
8
16
|
import { destroySessionTest } from './sign-in-action-tests';
|
|
9
17
|
|
|
10
18
|
/** Every generated file lives under the scaffold's own auth slice, beside `auth.ts`. */
|
|
@@ -215,8 +223,6 @@ const styleSource =
|
|
|
215
223
|
`;
|
|
216
224
|
|
|
217
225
|
/** The files both shapes write, with the guard over this shape's settings. */
|
|
218
|
-
/** Where the generated runtime lives: `apps/<app>/runtime.ts` is what both boots read first. */
|
|
219
|
-
export const RUNTIME_MODULE = 'apps/web/runtime.ts';
|
|
220
226
|
|
|
221
227
|
/** The plain routes a shape mounts: an import line, and the expression `routes:` takes. */
|
|
222
228
|
export interface RuntimeRoutes {
|
|
@@ -224,16 +230,17 @@ export interface RuntimeRoutes {
|
|
|
224
230
|
readonly expression: string;
|
|
225
231
|
}
|
|
226
232
|
|
|
227
|
-
const runtimeSource = (
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// role, where the same throw in a module the app scan imports is logged and the boot goes on.
|
|
233
|
+
const runtimeSource = (routes: RuntimeRoutes | undefined): string => `${RUNTIME_HEADER}
|
|
234
|
+
// The sign-in guard runs HERE: a throw in this module stops the role, where the same throw in a
|
|
235
|
+
// module the app scan imports is logged and the boot goes on.
|
|
236
|
+
import type { RuntimeOverrides } from '@ultimat3/cli/serve';
|
|
232
237
|
import { assertSignInConfigured } from './app/auth/sign-in-guard';${routes === undefined ? '' : `\n${routes.importLine}`}
|
|
233
238
|
|
|
234
239
|
assertSignInConfigured(process.env);
|
|
235
240
|
|
|
236
|
-
export const runtime = {
|
|
241
|
+
export const runtime = {
|
|
242
|
+
${routes === undefined ? '' : ` routes: ${routes.expression},\n`}${runtimePortLines()}
|
|
243
|
+
} satisfies RuntimeOverrides;
|
|
237
244
|
`;
|
|
238
245
|
|
|
239
246
|
const runtimeTest = (
|
|
@@ -253,8 +260,19 @@ export function sharedSignInFiles(
|
|
|
253
260
|
routes?: RuntimeRoutes,
|
|
254
261
|
): readonly GeneratedFile[] {
|
|
255
262
|
return [
|
|
256
|
-
|
|
257
|
-
{
|
|
263
|
+
// Over `x new`'s own pair while it is untouched; an author's edited copy is a conflict.
|
|
264
|
+
{
|
|
265
|
+
path: RUNTIME_MODULE,
|
|
266
|
+
contents: runtimeSource(routes),
|
|
267
|
+
merge: 'replaces-pristine',
|
|
268
|
+
pristine: baseRuntimeSource(),
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
path: RUNTIME_TEST,
|
|
272
|
+
contents: runtimeTest(routes),
|
|
273
|
+
merge: 'replaces-pristine',
|
|
274
|
+
pristine: baseRuntimeTest(),
|
|
275
|
+
},
|
|
258
276
|
{ path: `${AUTH_DIR}/sign-in-flow.ts`, contents: flowSource() },
|
|
259
277
|
{ path: `${AUTH_DIR}/sign-in-flow.test.ts`, contents: flowTest() },
|
|
260
278
|
{ path: `${AUTH_DIR}/sign-in-guard.ts`, contents: guardSource(keys, why) },
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// `x g app <name>` and `x g package <name>`: one more workspace in a scaffolded monorepo. Nothing
|
|
2
|
+
// outside the new directory changes: the root `workspaces` globs (`apps/*`, `packages/*`) admit it
|
|
3
|
+
// and the root tsconfig's one alias (`@<app>/*` → `packages/*/src`, then `apps/*`) reaches it.
|
|
4
|
+
|
|
5
|
+
import type { GeneratedFile, NameSet } from './naming';
|
|
6
|
+
import { packageShapeFiles, workspacePackageJson } from './scaffold-package-shape';
|
|
7
|
+
|
|
8
|
+
const appTsconfig = `{
|
|
9
|
+
"extends": "../../tsconfig.json",
|
|
10
|
+
"include": ["**/*.ts", "**/*.tsx", "../../types/scss.d.ts"]
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* No `dependencies`: an app declares a package as it first imports one (`package-shape`'s
|
|
16
|
+
* `X_WORKSPACE_DEP_UNDECLARED`), and a fresh app imports nothing. `exports` is apps/admin's, so a
|
|
17
|
+
* sibling's `import type` of a module here resolves the same way.
|
|
18
|
+
*/
|
|
19
|
+
const appPackageJson = (app: NameSet, name: string): string => `{
|
|
20
|
+
"name": "@${app.kebab}/${name}",
|
|
21
|
+
"version": "0.0.0",
|
|
22
|
+
"private": true,
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
"./*": "./*.ts",
|
|
26
|
+
"./*.tsx": "./*.tsx"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"typecheck": "tsc --noEmit -p ../../tsconfig.json"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
/** `apps/<name>/`: scanned by the one boot like `apps/web`, served by the same image. */
|
|
35
|
+
export const workspaceAppFiles = (app: NameSet, name: string): readonly GeneratedFile[] => [
|
|
36
|
+
{ path: `apps/${name}/package.json`, contents: appPackageJson(app, name) },
|
|
37
|
+
{ path: `apps/${name}/tsconfig.json`, contents: appTsconfig },
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const packageIndex = (
|
|
41
|
+
app: NameSet,
|
|
42
|
+
name: string,
|
|
43
|
+
): string => `// @${app.kebab}/${name}: code every app of this repo may share. Named exports only; it imports
|
|
44
|
+
// \`@ultimat3/*\` and sibling packages, never an app (the \`boundaries\` step,
|
|
45
|
+
// X_BOUNDARY_PACKAGE_TO_APP).
|
|
46
|
+
|
|
47
|
+
/** This package's import specifier, for a caller that has to name it in a message. */
|
|
48
|
+
export const PACKAGE_NAME = '@${app.kebab}/${name}';
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
const packageTest = (
|
|
52
|
+
app: NameSet,
|
|
53
|
+
): string => `// Pins the package's place in the repo: it is installed under the app's own scope, so a
|
|
54
|
+
// sibling imports it as \`@${app.kebab}/<name>\` and never by a relative path.
|
|
55
|
+
|
|
56
|
+
import { expect } from 'bun:test';
|
|
57
|
+
import { unitTest } from '@ultimat3/testing';
|
|
58
|
+
import { PACKAGE_NAME } from './index';
|
|
59
|
+
|
|
60
|
+
unitTest('the package is named into the app scope', () => {
|
|
61
|
+
expect(PACKAGE_NAME.startsWith('@${app.kebab}/')).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
/** `packages/<name>/`: the root alias `@<app>/*` → `./packages/*\/src` already reaches it. */
|
|
66
|
+
export const workspacePackageFiles = (
|
|
67
|
+
app: NameSet,
|
|
68
|
+
name: string,
|
|
69
|
+
description = 'Code shared by every app in this repository',
|
|
70
|
+
): readonly GeneratedFile[] => [
|
|
71
|
+
{ path: `packages/${name}/package.json`, contents: workspacePackageJson(app, name, description) },
|
|
72
|
+
...packageShapeFiles(app, name, description),
|
|
73
|
+
{ path: `packages/${name}/src/index.ts`, contents: packageIndex(app, name) },
|
|
74
|
+
{ path: `packages/${name}/src/index.test.ts`, contents: packageTest(app) },
|
|
75
|
+
];
|
package/src/test-ignores.ts
CHANGED
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
// predicate `discoverTests` filters by and the `--path-ignore-patterns` the serial steps pass to
|
|
3
3
|
// `bun test`. A leaf, so `test-select.ts` and `verify-tests.ts` (which import each other) share it.
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Build output, installed packages, git's own tree and an app's `.x/` state: never a test, at ANY
|
|
7
|
+
* depth. The last two because discovery scans dot-directories (`.claude/hooks/*.test.ts` is a test).
|
|
8
|
+
*/
|
|
9
|
+
const IGNORED_ANYWHERE = ['dist', 'node_modules', '.git', '.x'] as const;
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* Nested projects with their own gate (`examples/`, `dummy/`, run by
|
package/src/test-select.ts
CHANGED
|
@@ -48,7 +48,10 @@ export async function discoverTests(
|
|
|
48
48
|
): Promise<readonly TestFile[]> {
|
|
49
49
|
const filters = filter === undefined ? undefined : typeof filter === 'string' ? [filter] : filter;
|
|
50
50
|
const files: TestFile[] = [];
|
|
51
|
-
|
|
51
|
+
// `dot: true`: a hook's test under `.claude/hooks/` is a test; `.git` and `.x` are refused by the
|
|
52
|
+
// one ignore policy below (`test-ignores.ts`), never by the glob.
|
|
53
|
+
const glob = new Bun.Glob(TEST_GLOB);
|
|
54
|
+
for await (const found of glob.scan({ cwd: root, absolute: false, dot: true })) {
|
|
52
55
|
const path = found.split('\\').join('/');
|
|
53
56
|
if (isIgnoredTestPath(path)) continue;
|
|
54
57
|
if (filters !== undefined && !filters.some((part) => path.includes(part))) continue;
|
package/src/upgrade-gate.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// A hop's gate, run by the CLI the hop just installed: `x manifest`, `x doctor --json`, `x
|
|
2
|
-
// --json`. Never in this process, because the installed CLI is the one that knows the installed
|
|
1
|
+
// A hop's gate, run by the CLI the hop just installed: `x manifest`, `x doctor --json`, `x exercise
|
|
2
|
+
// --json`, `x verify --json`. Never in this process, because the installed CLI is the one that knows the installed
|
|
3
3
|
// framework (`local-cli.ts`), and it may be many majors older than this one: each answer is read as
|
|
4
4
|
// a foreign document, and one that will not parse is a finding, never a green.
|
|
5
5
|
|
|
@@ -84,9 +84,21 @@ export interface HopGuards {
|
|
|
84
84
|
readonly differs: readonly { readonly name: string; readonly refresh: string }[];
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/**
|
|
88
|
+
* `x exercise`'s findings, listed before the gate: an upgrade spent its commits feeding the
|
|
89
|
+
* exercise one red gate at a time, and each of these fixes pastes as written.
|
|
90
|
+
*/
|
|
91
|
+
export interface HopExercise {
|
|
92
|
+
/** False when the hop's CLI answered no exercise document (none, or one predating it): unknown. */
|
|
93
|
+
readonly reported: boolean;
|
|
94
|
+
readonly ok: boolean;
|
|
95
|
+
readonly findings: readonly GateFinding[];
|
|
96
|
+
}
|
|
97
|
+
|
|
87
98
|
export interface HopGate {
|
|
88
99
|
readonly manifest: { readonly ok: boolean; readonly findings: readonly GateFinding[] };
|
|
89
100
|
readonly guards: HopGuards;
|
|
101
|
+
readonly exercise: HopExercise;
|
|
90
102
|
readonly verify: {
|
|
91
103
|
readonly ok: boolean;
|
|
92
104
|
readonly summary: string;
|
|
@@ -164,6 +176,17 @@ const readManifest = (result: ExecResult): HopGate['manifest'] => {
|
|
|
164
176
|
return { ok: result.ok, findings: flatten(document) };
|
|
165
177
|
};
|
|
166
178
|
|
|
179
|
+
/** Read like the manifest, except that no document is `reported: false`, never a finding. */
|
|
180
|
+
const readExercise = (result: ExecResult): HopExercise => {
|
|
181
|
+
const parsed = MANIFEST.safeParse(documentIn(result.stdout));
|
|
182
|
+
if (parsed.issues !== undefined) return { reported: false, ok: false, findings: [] };
|
|
183
|
+
const document = parsed.value as {
|
|
184
|
+
readonly ok: boolean;
|
|
185
|
+
readonly findings?: readonly RawFinding[];
|
|
186
|
+
};
|
|
187
|
+
return { reported: true, ok: result.ok && document.ok, findings: flatten(document) };
|
|
188
|
+
};
|
|
189
|
+
|
|
167
190
|
/** A doctor that exits red is normal (a port, an env key); only its listing is read here. */
|
|
168
191
|
const readGuards = (result: ExecResult): HopGuards => {
|
|
169
192
|
const parsed = DOCTOR.safeParse(documentIn(result.stdout));
|
|
@@ -173,11 +196,11 @@ const readGuards = (result: ExecResult): HopGuards => {
|
|
|
173
196
|
return { reported: true, missing: guards.missing ?? [], differs: guards.differs ?? [] };
|
|
174
197
|
};
|
|
175
198
|
|
|
176
|
-
/** The
|
|
199
|
+
/** The four, in order, each told apart by `onStage` so a long gate is not a long silence. */
|
|
177
200
|
export async function runHopGate(input: {
|
|
178
201
|
readonly runner: Runner;
|
|
179
202
|
readonly root: string;
|
|
180
|
-
readonly onStage: (stage: 'manifest' | 'doctor' | 'verify') => void;
|
|
203
|
+
readonly onStage: (stage: 'manifest' | 'doctor' | 'exercise' | 'verify') => void;
|
|
181
204
|
}): Promise<HopGate> {
|
|
182
205
|
const { runner, root, onStage } = input;
|
|
183
206
|
const installed = (args: readonly string[]): Promise<ExecResult> =>
|
|
@@ -186,9 +209,11 @@ export async function runHopGate(input: {
|
|
|
186
209
|
const manifest = readManifest(await installed(['manifest', '--json']));
|
|
187
210
|
onStage('doctor');
|
|
188
211
|
const guards = readGuards(await installed(['doctor', '--json']));
|
|
212
|
+
onStage('exercise');
|
|
213
|
+
const exercise = readExercise(await installed(['exercise', '--json']));
|
|
189
214
|
onStage('verify');
|
|
190
215
|
const verify = readVerify(await installed(['verify', '--json']));
|
|
191
|
-
return { manifest, guards, verify };
|
|
216
|
+
return { manifest, guards, exercise, verify };
|
|
192
217
|
}
|
|
193
218
|
|
|
194
219
|
/** What a repository with no app can still be asked, in the order an author would run them. */
|
package/src/upgrade-report.ts
CHANGED
|
@@ -88,7 +88,12 @@ export const humanLines = (input: {
|
|
|
88
88
|
...(gate?.guards.differs ?? []).map((guard) =>
|
|
89
89
|
msg('cli.upgrade.guard', { fix: guard.refresh }),
|
|
90
90
|
),
|
|
91
|
-
|
|
91
|
+
// The exercise's own list first: every fix it has, before the gate's verdict on the same tree.
|
|
92
|
+
...findingLines([
|
|
93
|
+
...(gate?.exercise.findings ?? []),
|
|
94
|
+
...(gate?.manifest.findings ?? []),
|
|
95
|
+
...(gate?.verify.findings ?? []),
|
|
96
|
+
]),
|
|
92
97
|
...scripts
|
|
93
98
|
.filter((script) => script.ok === false)
|
|
94
99
|
.map((script) => msg('cli.upgrade.scriptRed', { name: script.name })),
|
|
@@ -133,6 +138,7 @@ export const report = (input: {
|
|
|
133
138
|
agentsMd: input.agentsMd ?? null,
|
|
134
139
|
guards: gate?.guards ?? null,
|
|
135
140
|
manifest: gate?.manifest ?? null,
|
|
141
|
+
exercise: gate?.exercise ?? null,
|
|
136
142
|
verify: gate?.verify ?? null,
|
|
137
143
|
scripts,
|
|
138
144
|
then,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// `x verify --changed`, the disk half: which app files the `drift` step's inputs reach by import,
|
|
2
|
+
// and which TypeScript files exist now. Read once, handed to the pure planner (`verify-changed.ts`).
|
|
3
|
+
// Seeds are read off the import itself — a file importing `@ultimat3/entity` declares a table
|
|
4
|
+
// however it is named — never off a filename convention a hand-written entity can miss.
|
|
5
|
+
|
|
6
|
+
// why: Bun ships no path API; files are read from the app root with the host's separator.
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { appSourceFiles, fileImports } from './app-module-graph';
|
|
9
|
+
import { isTest } from './source-files';
|
|
10
|
+
import type { ChangedFacts } from './verify-changed';
|
|
11
|
+
|
|
12
|
+
/** A runtime OR type import of the entity package, in any of its subpaths. */
|
|
13
|
+
const ENTITY_IMPORT = /['"]@ultimat3\/entity(?:\/[^'"]*)?['"]/;
|
|
14
|
+
|
|
15
|
+
interface Scanned {
|
|
16
|
+
readonly path: string;
|
|
17
|
+
readonly imports: readonly string[];
|
|
18
|
+
readonly opaque: boolean;
|
|
19
|
+
readonly seed: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Pure: the closure over already-scanned files, so the rule is testable without a tree. */
|
|
23
|
+
export function driftReachOf(files: readonly Scanned[]): ReadonlySet<string> | 'everything' {
|
|
24
|
+
const byPath = new Map(files.map((file) => [file.path, file]));
|
|
25
|
+
const reached = new Set<string>();
|
|
26
|
+
const queue = files.filter((file) => file.seed).map((file) => file.path);
|
|
27
|
+
for (let at = queue.shift(); at !== undefined; at = queue.shift()) {
|
|
28
|
+
if (reached.has(at)) continue;
|
|
29
|
+
reached.add(at);
|
|
30
|
+
const file = byPath.get(at);
|
|
31
|
+
// A seed that computes an import can reach any file: nothing is provably outside drift.
|
|
32
|
+
if (file?.opaque === true) return 'everything';
|
|
33
|
+
for (const target of file?.imports ?? []) if (!reached.has(target)) queue.push(target);
|
|
34
|
+
}
|
|
35
|
+
return reached;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function readChangedFacts(root: string): Promise<ChangedFacts> {
|
|
39
|
+
const paths = await appSourceFiles(root);
|
|
40
|
+
const scanned: Scanned[] = [];
|
|
41
|
+
for (const path of paths) {
|
|
42
|
+
if (isTest(path)) continue;
|
|
43
|
+
const source = await Bun.file(join(root, path)).text();
|
|
44
|
+
const found = fileImports(root, path, source);
|
|
45
|
+
scanned.push({
|
|
46
|
+
path,
|
|
47
|
+
imports: found.imports,
|
|
48
|
+
opaque: found.opaque,
|
|
49
|
+
seed: path.startsWith('packages/db/') || ENTITY_IMPORT.test(source),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return { driftReach: driftReachOf(scanned), known: new Set(paths) };
|
|
53
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// `x verify --changed`, resolved: the diff (`affected.ts`'s one reader of `--base`/`--dirty`, so
|
|
2
|
+
// `x affected` and this flag can never measure a change against two different bases), re-rooted
|
|
3
|
+
// onto the app, then planned. What `cmd-verify.ts` narrows the run with, and what `--json` reports.
|
|
4
|
+
|
|
5
|
+
// why: Bun ships no path API; git prints paths from the checkout root, the planner reads app-relative.
|
|
6
|
+
import { join, relative, resolve } from 'node:path';
|
|
7
|
+
import { renderFixShellArg } from '@ultimat3/core';
|
|
8
|
+
import type { AffectedSelection } from './affected';
|
|
9
|
+
import { changedFiles, gitRoot, readAffectedSelection } from './affected';
|
|
10
|
+
import type { AppTestScope } from './affected-tests';
|
|
11
|
+
import { appTestScope, narrowToApp } from './affected-tests';
|
|
12
|
+
import { BadFlagError } from './errors';
|
|
13
|
+
import type { Runner } from './exec';
|
|
14
|
+
import type { CommandResult, JsonValue } from './output';
|
|
15
|
+
import type { ParsedArgs } from './parse';
|
|
16
|
+
import { flagBool, flagString } from './parse';
|
|
17
|
+
import { discoverTests } from './test-select';
|
|
18
|
+
import type { ChangedFacts, ChangedStepPlan } from './verify-changed';
|
|
19
|
+
import { narrowSuites, planChangedSteps } from './verify-changed';
|
|
20
|
+
import { readChangedFacts } from './verify-changed-facts';
|
|
21
|
+
import type { ChangedTestSelection, VerifyStepName } from './verify-step';
|
|
22
|
+
|
|
23
|
+
/** Every test file a suite would discover, app-root-relative. */
|
|
24
|
+
const discoverAll = async (root: string): Promise<readonly string[]> =>
|
|
25
|
+
(await discoverTests(root)).map((file) => file.path);
|
|
26
|
+
|
|
27
|
+
export interface ChangedScope {
|
|
28
|
+
readonly selection: AffectedSelection;
|
|
29
|
+
/** Suites already narrowed to `tests.kept`. */
|
|
30
|
+
readonly plan: ChangedStepPlan;
|
|
31
|
+
/**
|
|
32
|
+
* What each suite runs — `undefined` when a changed file forced every test (or no app). `kept`
|
|
33
|
+
* is `x test --affected`'s answer: the closure's tests and every test the graph never read.
|
|
34
|
+
*/
|
|
35
|
+
readonly tests: ChangedTestRun | undefined;
|
|
36
|
+
/** The changed files that forced every test, when one did. */
|
|
37
|
+
readonly forcing: readonly string[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** `VerifyContext.tests`, plus the files it keeps, for `--json`. */
|
|
41
|
+
export interface ChangedTestRun extends ChangedTestSelection {
|
|
42
|
+
readonly kept: readonly string[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const toPosix = (path: string): string => path.split('\\').join('/');
|
|
46
|
+
|
|
47
|
+
/** Checkout-relative paths onto the app root: a file outside the app comes back `../…`. */
|
|
48
|
+
export const reRoot = (checkout: string, app: string, paths: readonly string[]): string[] =>
|
|
49
|
+
paths.map((path) => toPosix(relative(resolve(app), join(resolve(checkout), path))));
|
|
50
|
+
|
|
51
|
+
export async function changedScope(options: {
|
|
52
|
+
readonly runner: Runner;
|
|
53
|
+
readonly root: string;
|
|
54
|
+
readonly args: ParsedArgs;
|
|
55
|
+
/** Injected by tests; the real read walks the app once. */
|
|
56
|
+
readonly facts?: (root: string) => Promise<ChangedFacts>;
|
|
57
|
+
/** Injected by tests; the real one is `x test --affected`'s selection. */
|
|
58
|
+
readonly tests?: (
|
|
59
|
+
root: string,
|
|
60
|
+
checkout: string,
|
|
61
|
+
changed: readonly string[],
|
|
62
|
+
) => Promise<AppTestScope | undefined>;
|
|
63
|
+
/** Injected by tests; the real one is the suites' own discovery, every type. */
|
|
64
|
+
readonly discover?: (root: string) => Promise<readonly string[]>;
|
|
65
|
+
}): Promise<ChangedScope> {
|
|
66
|
+
const selection = readAffectedSelection(options.args, 'verify');
|
|
67
|
+
const checkout = await gitRoot(options.runner, options.root, 'verify');
|
|
68
|
+
const files = await changedFiles(options.runner, {
|
|
69
|
+
cwd: checkout,
|
|
70
|
+
command: 'verify',
|
|
71
|
+
selection,
|
|
72
|
+
});
|
|
73
|
+
const facts = await (options.facts ?? readChangedFacts)(options.root);
|
|
74
|
+
const selected = await (options.tests ?? appTestScope)(options.root, checkout, files);
|
|
75
|
+
const plan = planChangedSteps(reRoot(checkout, options.root, files), facts);
|
|
76
|
+
if (selected === undefined || selected.all) {
|
|
77
|
+
return { selection, plan, tests: undefined, forcing: selected?.forcing ?? [] };
|
|
78
|
+
}
|
|
79
|
+
const discovered = await (options.discover ?? discoverAll)(options.root);
|
|
80
|
+
const kept = narrowToApp(
|
|
81
|
+
discovered.map((path) => ({ path })),
|
|
82
|
+
options.root,
|
|
83
|
+
selected,
|
|
84
|
+
).kept.map((file) => file.path);
|
|
85
|
+
const narrowed = narrowSuites(plan, kept);
|
|
86
|
+
return {
|
|
87
|
+
selection,
|
|
88
|
+
plan: narrowed.plan,
|
|
89
|
+
tests: { scope: selected, whole: narrowed.whole, kept },
|
|
90
|
+
forcing: [],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** `data.changed`: the base, every file with its rule, and every step with the files that chose it. */
|
|
95
|
+
export const changedScopeJson = (scope: ChangedScope): JsonValue => ({
|
|
96
|
+
base: scope.selection.base,
|
|
97
|
+
dirty: scope.selection.dirty,
|
|
98
|
+
files: scope.plan.files.map((file) => ({ path: file.path, rule: file.rule })),
|
|
99
|
+
steps: scope.plan.steps.map((step) => ({ name: step.name, files: [...step.files] })),
|
|
100
|
+
tests:
|
|
101
|
+
scope.tests === undefined
|
|
102
|
+
? { all: true, forcing: [...scope.forcing] }
|
|
103
|
+
: { all: false, files: [...scope.tests.kept], whole: [...scope.tests.whole] },
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
/** How many files a human line names before it says `(+N)`. */
|
|
107
|
+
const SHOWN = 3;
|
|
108
|
+
|
|
109
|
+
/** One human line per selected step: `drift ← packages/db/migrations/1.sql (+2)`. */
|
|
110
|
+
export const changedScopeLines = (scope: ChangedScope): readonly string[] =>
|
|
111
|
+
scope.plan.steps.map((step) => {
|
|
112
|
+
const shown = step.files.slice(0, SHOWN).join(', ');
|
|
113
|
+
const more = step.files.length > SHOWN ? ` (+${step.files.length - SHOWN})` : '';
|
|
114
|
+
return ` ${step.name.padEnd(14)}← ${shown}${more}`;
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Whether this run is `--changed`. Refused beside `--only` — two narrowings, and whichever won
|
|
119
|
+
* the other would be silently ignored — and `--base`/`--dirty` without it, which narrow nothing.
|
|
120
|
+
*/
|
|
121
|
+
export function readChangedRun(
|
|
122
|
+
args: ParsedArgs,
|
|
123
|
+
only: readonly VerifyStepName[] | undefined,
|
|
124
|
+
): boolean {
|
|
125
|
+
const changed = flagBool(args, 'changed');
|
|
126
|
+
if (changed && only !== undefined) {
|
|
127
|
+
throw new BadFlagError({
|
|
128
|
+
flag: 'changed',
|
|
129
|
+
command: 'verify',
|
|
130
|
+
reason: '--changed derives the step list from the diff and --only names one: pick one',
|
|
131
|
+
fix: 'x verify --changed --json',
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (!changed) {
|
|
135
|
+
const stray =
|
|
136
|
+
flagString(args, 'base') !== undefined
|
|
137
|
+
? 'base'
|
|
138
|
+
: flagBool(args, 'dirty')
|
|
139
|
+
? 'dirty'
|
|
140
|
+
: undefined;
|
|
141
|
+
if (stray !== undefined) {
|
|
142
|
+
throw new BadFlagError({
|
|
143
|
+
flag: stray,
|
|
144
|
+
command: 'verify',
|
|
145
|
+
reason: `--${stray} scopes the diff --changed reads, and does nothing without it`,
|
|
146
|
+
fix:
|
|
147
|
+
stray === 'base'
|
|
148
|
+
? `x verify --changed --base ${renderFixShellArg(flagString(args, 'base'), '<ref>')} --json`
|
|
149
|
+
: 'x verify --changed --dirty --json',
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return changed;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** `data.changed` and one line per chosen step, after whatever the run already reported. */
|
|
157
|
+
export const withChangedData = (result: CommandResult, scope: ChangedScope): CommandResult => ({
|
|
158
|
+
...result,
|
|
159
|
+
lines: [...changedScopeLines(scope), ...(result.lines ?? [])],
|
|
160
|
+
data: { ...((result.data ?? {}) as Record<string, JsonValue>), changed: changedScopeJson(scope) },
|
|
161
|
+
});
|