@ultimat3/cli 31.5.0 → 31.6.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 +14 -7
- package/package.json +29 -29
- package/src/admin-catalog-keys.ts +17 -1
- package/src/app-transport.ts +7 -3
- package/src/browser-barrel-cut.ts +109 -0
- package/src/browser-import-chain.ts +119 -0
- package/src/browser-transport.ts +85 -13
- package/src/cmd-dev.ts +15 -2
- package/src/cmd-fix.ts +14 -4
- package/src/cmd-i18n.ts +52 -10
- package/src/dev-boot.ts +6 -4
- package/src/dev-log.ts +95 -0
- package/src/dev-rebuild-remount.ts +152 -0
- package/src/dev-rebuild-schema.ts +30 -0
- package/src/dev-rebuild.ts +51 -14
- package/src/dev-supervisor.ts +5 -4
- package/src/error-codes.ts +2 -0
- package/src/error-contract.ts +29 -2
- package/src/fix-sequence.ts +97 -0
- package/src/generate-grant-findings.ts +2 -2
- package/src/generate-grants.ts +50 -1
- package/src/generate-write.ts +16 -0
- package/src/i18n-registration.ts +8 -5
- package/src/load-findings.ts +29 -22
- package/src/mcp-errors.ts +11 -3
- package/src/mcp-host-shell.ts +128 -0
- package/src/mcp-host.ts +19 -54
- package/src/mcp-test-output.ts +5 -2
- package/src/messages-gate.ts +12 -0
- package/src/messages.ts +16 -0
- package/src/policy-append.ts +88 -0
- package/src/templates/entity.ts +18 -3
- package/src/templates/policy.ts +5 -1
- package/src/templates/query.ts +4 -2
- package/src/templates/resource-service.ts +5 -2
- package/src/templates/scaffold-repo.ts +8 -2
- package/src/ts-scan.ts +86 -1
- package/src/verify-checks.ts +23 -51
- package/src/verify-contract-diff.ts +143 -0
- package/src/verify-seeds.ts +132 -0
- package/src/verify-tests.ts +12 -6
- package/wiki/CLI-Reference.md +2 -2
- package/wiki/Upgrading.md +3 -0
package/src/verify-checks.ts
CHANGED
|
@@ -5,15 +5,14 @@
|
|
|
5
5
|
import { existsSync } from 'node:fs';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
import { APP_CONFIG_FILE, ERROR_DOCS_URL } from '@ultimat3/core';
|
|
8
|
-
import
|
|
9
|
-
import { AGENTS_MD_FILENAME, MANIFEST_FILENAME, verifyContract } from '@ultimat3/manifest';
|
|
8
|
+
import { AGENTS_MD_FILENAME } from '@ultimat3/manifest';
|
|
10
9
|
import type { MetaIssue } from '@ultimat3/seo';
|
|
11
10
|
import { llmsDescriptionIssues, validateMeta } from '@ultimat3/seo';
|
|
12
11
|
import { checkAgentsMd } from './app-agents-md';
|
|
13
12
|
import { readAppSources } from './app-boundaries';
|
|
14
13
|
import { envExampleFindings } from './app-env';
|
|
15
14
|
import { loadApp } from './app-load';
|
|
16
|
-
import { appManifest
|
|
15
|
+
import { appManifest } from './app-manifest';
|
|
17
16
|
import { policyFindings } from './app-permissions';
|
|
18
17
|
import { asyncPageFindings } from './async-pages';
|
|
19
18
|
import { appBoundaryFindings } from './boundary-findings';
|
|
@@ -32,7 +31,7 @@ import { readJobBudgetFindings } from './job-budget';
|
|
|
32
31
|
import { unregisteredJobFindings } from './job-registration';
|
|
33
32
|
import { LINT_ARGV, lintOutcome } from './lint-findings';
|
|
34
33
|
import { liveRouteFindings } from './live-routes';
|
|
35
|
-
import {
|
|
34
|
+
import { blockedByLoad, withLoadFindings } from './load-findings';
|
|
36
35
|
import {
|
|
37
36
|
hasCommittedContract,
|
|
38
37
|
manifestMissingFindings,
|
|
@@ -41,7 +40,6 @@ import {
|
|
|
41
40
|
import { mcpLockFindings } from './mcp-lock-findings';
|
|
42
41
|
import { msg } from './messages';
|
|
43
42
|
import type { Finding } from './output';
|
|
44
|
-
import { findingFrom } from './output';
|
|
45
43
|
import { retainUnsweptFindings } from './retain-sweep';
|
|
46
44
|
import { checkMigrationDrift } from './schema-drift';
|
|
47
45
|
import { checkSchemaDump } from './schema-dump-drift';
|
|
@@ -52,6 +50,7 @@ import { loadSiteSettings } from './site-config';
|
|
|
52
50
|
import { readStaticReport } from './static-report';
|
|
53
51
|
import { unknownToolGateFindings } from './tool-gate-names';
|
|
54
52
|
import { measureIfStale } from './verify-budgets-build';
|
|
53
|
+
import { contractDiffStep } from './verify-contract-diff';
|
|
55
54
|
import { nestedAppRootFindings } from './verify-drift-owner';
|
|
56
55
|
import { exerciseStep } from './verify-exercise';
|
|
57
56
|
import { floorProblemFindings, readVerifyFloor } from './verify-floor';
|
|
@@ -192,9 +191,11 @@ export const VERIFY_STEPS: readonly VerifyStep[] = [
|
|
|
192
191
|
},
|
|
193
192
|
},
|
|
194
193
|
...TEST_STEPS.slice(0, AFTER_JOB),
|
|
195
|
-
|
|
194
|
+
// Every step that loads the app stands down while the load is red: the cause is `manifest`'s,
|
|
195
|
+
// and what a half-filled registry looks like is not a finding (`load-findings.ts`).
|
|
196
|
+
blockedByLoad(exerciseStep),
|
|
196
197
|
...TEST_STEPS.slice(AFTER_JOB),
|
|
197
|
-
{
|
|
198
|
+
blockedByLoad({
|
|
198
199
|
name: 'drift',
|
|
199
200
|
summary:
|
|
200
201
|
'entity declarations vs migrations, every destructive statement declared, every statement no declaration carries, and the committed schema dump',
|
|
@@ -235,26 +236,9 @@ export const VERIFY_STEPS: readonly VerifyStep[] = [
|
|
|
235
236
|
client: () => checkClientDrift(ctx.root),
|
|
236
237
|
});
|
|
237
238
|
},
|
|
238
|
-
},
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
summary: 'the published contract vs the committed manifest',
|
|
242
|
-
// A BREAKING change against the committed manifest, and nothing else. Whether the committed
|
|
243
|
-
// files are stale — `openapi.json` included — is the `manifest` step's, through the one check
|
|
244
|
-
// `x manifest --check` runs (`manifest-staleness.ts`): reported here as well it was two
|
|
245
|
-
// steps and one command answering one question, and the step named `manifest` saying green.
|
|
246
|
-
applies: async (ctx) => existsSync(join(ctx.root, MANIFEST_FILENAME)),
|
|
247
|
-
async run(ctx) {
|
|
248
|
-
const committed = await readAppManifest(ctx.root);
|
|
249
|
-
const { manifest, findings } = await appManifest(ctx.root);
|
|
250
|
-
// A module that will not import is `manifest`'s to report (`load-findings.ts`).
|
|
251
|
-
return withoutLoadFindings(ctx.root, [
|
|
252
|
-
...findings,
|
|
253
|
-
...(committed === undefined ? [] : contractFindings(committed, manifest)),
|
|
254
|
-
]);
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
{
|
|
239
|
+
}),
|
|
240
|
+
blockedByLoad(contractDiffStep),
|
|
241
|
+
blockedByLoad({
|
|
258
242
|
name: 'budgets',
|
|
259
243
|
summary:
|
|
260
244
|
'per-route JS bytes, the global style layer every document carries, and the routes that boot nothing to receive their live rows',
|
|
@@ -288,12 +272,10 @@ export const VERIFY_STEPS: readonly VerifyStep[] = [
|
|
|
288
272
|
// reported under `X_ISLAND_PROPS_INVALID` — the build's own sentence, naming the prop and
|
|
289
273
|
// its bytes — and not as an `X_BUDGET_UNMEASURED` whose fix is to go and read this file.
|
|
290
274
|
const report = await readStaticReport(ctx.root);
|
|
291
|
-
//
|
|
292
|
-
//
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
const outcome = await withoutLoadFindings(ctx.root, [
|
|
296
|
-
...findings,
|
|
275
|
+
// Reached only over a clean load (`blockedByLoad`): a route a broken module never registered
|
|
276
|
+
// is the load's finding on `manifest`, never one `X_BUDGET_UNMEASURED` per route here.
|
|
277
|
+
const { manifest } = await appManifest(ctx.root);
|
|
278
|
+
const outcome = fromFindings([
|
|
297
279
|
...checkDocumentStyles(documentSurfaces()),
|
|
298
280
|
// The third rider, and the same question this step already asks one level down: what
|
|
299
281
|
// JavaScript does this route's document boot? A live read with no island is a route
|
|
@@ -314,8 +296,8 @@ export const VERIFY_STEPS: readonly VerifyStep[] = [
|
|
|
314
296
|
.join('\n');
|
|
315
297
|
return output === '' ? outcome : { ...outcome, output };
|
|
316
298
|
},
|
|
317
|
-
},
|
|
318
|
-
{
|
|
299
|
+
}),
|
|
300
|
+
blockedByLoad({
|
|
319
301
|
name: 'seo',
|
|
320
302
|
summary: 'every indexable site/ route has a title and a description a search result can render',
|
|
321
303
|
// The SEO checkers shipped in `@ultimat3/seo` with no caller anywhere — `validateMeta` and its
|
|
@@ -349,8 +331,8 @@ export const VERIFY_STEPS: readonly VerifyStep[] = [
|
|
|
349
331
|
...(warnings.length === 0 ? {} : { warnings }),
|
|
350
332
|
};
|
|
351
333
|
},
|
|
352
|
-
},
|
|
353
|
-
{
|
|
334
|
+
}),
|
|
335
|
+
blockedByLoad({
|
|
354
336
|
name: 'i18n',
|
|
355
337
|
summary: 'every string this app renders resolves — in the catalogs AND in the registry',
|
|
356
338
|
// Its own step rather than a rider on `boundaries`, by that step's own test: a rider must ask
|
|
@@ -370,16 +352,16 @@ export const VERIFY_STEPS: readonly VerifyStep[] = [
|
|
|
370
352
|
// is the vacuous green this check exists to refuse.
|
|
371
353
|
applies: async (ctx) => existsSync(join(ctx.root, APP_CONFIG_FILE)),
|
|
372
354
|
run: async (ctx) => fromFindings(await catalogFindings(ctx.root)),
|
|
373
|
-
},
|
|
374
|
-
{
|
|
355
|
+
}),
|
|
356
|
+
blockedByLoad({
|
|
375
357
|
name: 'policy',
|
|
376
358
|
summary: 'every permission this app grants or requires is one it declares',
|
|
377
359
|
// A repo with no `app.config.ts` is the framework monorepo, which declares no roles and
|
|
378
360
|
// registers no routes — SKIPPED there, never passed, for the reason `i18n` gives: a step that
|
|
379
361
|
// answers `ok` about nothing is the vacuous green these checks exist to refuse.
|
|
380
362
|
applies: async (ctx) => existsSync(join(ctx.root, APP_CONFIG_FILE)),
|
|
381
|
-
run: async (ctx) =>
|
|
382
|
-
},
|
|
363
|
+
run: async (ctx) => fromFindings(await policyFindings(ctx.root)),
|
|
364
|
+
}),
|
|
383
365
|
{
|
|
384
366
|
name: 'manifest',
|
|
385
367
|
summary: 'the files an agent reads: generated facts, hand-written conventions, the env example',
|
|
@@ -466,16 +448,6 @@ async function driftFindings(root: string): Promise<readonly Finding[]> {
|
|
|
466
448
|
return [...findings, ...(await manifestStaleness(root, manifest))];
|
|
467
449
|
}
|
|
468
450
|
|
|
469
|
-
/** A breaking change is allowed — with a major bump. `verifyContract` is the one that decides. */
|
|
470
|
-
function contractFindings(before: Manifest, after: Manifest): readonly Finding[] {
|
|
471
|
-
try {
|
|
472
|
-
verifyContract({ before, after });
|
|
473
|
-
return [];
|
|
474
|
-
} catch (error) {
|
|
475
|
-
return [{ ...findingFrom(error), at: MANIFEST_FILENAME }];
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
451
|
/**
|
|
480
452
|
* One `MetaIssue` as the gate reports it. `at` is the route FILE and never the URL: every seo error
|
|
481
453
|
* already names the file in its cause, and `at` is what an agent opens.
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// The `contract-diff` gate step: the contract the code builds now against the one last committed.
|
|
2
|
+
// Split from `verify-checks.ts` (at its ceiling) so the baseline — which file counts as "published"
|
|
3
|
+
// — is decided in one place beside the step that reads it.
|
|
4
|
+
|
|
5
|
+
// why: Bun has no synchronous existence check for `applies`.
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
// why: Bun ships no path joiner.
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import type { Manifest } from '@ultimat3/manifest';
|
|
10
|
+
import { isManifest, MANIFEST_FILENAME, verifyContract } from '@ultimat3/manifest';
|
|
11
|
+
import { DEFAULT_REMOTE, fetchFixFor } from './affected-base';
|
|
12
|
+
import { appManifest, readAppManifest } from './app-manifest';
|
|
13
|
+
import type { Runner } from './exec';
|
|
14
|
+
import { msg } from './messages';
|
|
15
|
+
import type { Finding } from './output';
|
|
16
|
+
import { findingFrom } from './output';
|
|
17
|
+
import type { StepOutcome, VerifyStep } from './verify-step';
|
|
18
|
+
|
|
19
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
20
|
+
|
|
21
|
+
/** The published contract, and — whenever it is not HEAD's file — the line saying what it is. */
|
|
22
|
+
export interface CommittedManifest {
|
|
23
|
+
readonly manifest?: Manifest;
|
|
24
|
+
readonly notice?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const file = MANIFEST_FILENAME;
|
|
28
|
+
|
|
29
|
+
/** A git call that answers `undefined` for every way of not answering — no binary included. */
|
|
30
|
+
async function gitOut(root: string, runner: Runner, args: readonly string[]) {
|
|
31
|
+
const result = await runner(['git', ...args], { cwd: root }).catch(() => undefined);
|
|
32
|
+
return result?.ok === true ? result.stdout : undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const parsedManifest = (text: string): Manifest | undefined => {
|
|
36
|
+
try {
|
|
37
|
+
const parsed: unknown = JSON.parse(text);
|
|
38
|
+
return isManifest(parsed) ? parsed : undefined;
|
|
39
|
+
} catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The commit whose manifest is published. A pull request in CI (`GITHUB_BASE_REF`) has the
|
|
46
|
+
* rebaselined manifest committed at HEAD, so its baseline is the merge base with the target
|
|
47
|
+
* branch. A shallow checkout (CI's: depth 1, the base fetched at depth 1) reaches no merge base, and
|
|
48
|
+
* the fetched base ref itself is then the baseline — on a PR merge commit, its first parent. Only a
|
|
49
|
+
* base that is not fetched at all falls back to HEAD and names the fetch. Everywhere else, HEAD.
|
|
50
|
+
*/
|
|
51
|
+
async function baselineRev(root: string, runner: Runner, env: Env) {
|
|
52
|
+
const base = env['GITHUB_BASE_REF'];
|
|
53
|
+
if (base === undefined || base === '') return { rev: 'HEAD' };
|
|
54
|
+
const ref = `${DEFAULT_REMOTE}/${base}`;
|
|
55
|
+
const notice = msg('cli.verify.contract.mergeBase', { file, ref });
|
|
56
|
+
const sha = (await gitOut(root, runner, ['merge-base', 'HEAD', ref]))?.trim();
|
|
57
|
+
if (sha !== undefined && sha !== '') return { rev: sha, notice };
|
|
58
|
+
const tip = await gitOut(root, runner, ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]);
|
|
59
|
+
if (tip !== undefined)
|
|
60
|
+
return { rev: ref, notice: msg('cli.verify.contract.baseTip', { file, ref }) };
|
|
61
|
+
return {
|
|
62
|
+
rev: 'HEAD',
|
|
63
|
+
notice: msg('cli.verify.contract.baseUnfetched', { ref, file, fix: fetchFixFor(ref) }),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The contract as last COMMITTED, never the working-tree file: `x manifest` and every `x g`
|
|
69
|
+
* rewrite that one, so a breaking change diffed against it was green with no decision made (plan
|
|
70
|
+
* 101 19a FX4). Inside a checkout with no file at the baseline (never committed, or no commit yet)
|
|
71
|
+
* nothing is published, so there is no baseline. Outside a checkout (an unpacked tarball, a
|
|
72
|
+
* container with no `.git`) the file on disk is the only contract there is.
|
|
73
|
+
*/
|
|
74
|
+
export async function committedAppManifest(
|
|
75
|
+
root: string,
|
|
76
|
+
runner: Runner,
|
|
77
|
+
env: Env = {},
|
|
78
|
+
): Promise<CommittedManifest> {
|
|
79
|
+
if ((await gitOut(root, runner, ['rev-parse', '--is-inside-work-tree'])) === undefined) {
|
|
80
|
+
const notice = msg('cli.verify.contract.noCheckout', { file });
|
|
81
|
+
const manifest = await readAppManifest(root);
|
|
82
|
+
return manifest === undefined ? { notice } : { manifest, notice };
|
|
83
|
+
}
|
|
84
|
+
const { rev, notice: base } = await baselineRev(root, runner, env);
|
|
85
|
+
const withBase = (notice: string): string => (base === undefined ? notice : `${base}\n${notice}`);
|
|
86
|
+
const text = await gitOut(root, runner, ['show', `${rev}:./${file}`]);
|
|
87
|
+
if (text !== undefined) {
|
|
88
|
+
const manifest = parsedManifest(text);
|
|
89
|
+
if (manifest === undefined)
|
|
90
|
+
return { notice: withBase(msg('cli.verify.contract.notManifest', { file, rev })) };
|
|
91
|
+
return base === undefined ? { manifest } : { manifest, notice: base };
|
|
92
|
+
}
|
|
93
|
+
const head = await gitOut(root, runner, ['rev-parse', '--verify', '--quiet', 'HEAD']);
|
|
94
|
+
return {
|
|
95
|
+
notice: withBase(
|
|
96
|
+
head === undefined
|
|
97
|
+
? msg('cli.verify.contract.noCommit', { file })
|
|
98
|
+
: msg('cli.verify.contract.uncommitted', { file, rev }),
|
|
99
|
+
),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** A breaking change is allowed — with a major bump. `verifyContract` is the one that decides. */
|
|
104
|
+
function contractFindings(before: Manifest, after: Manifest): readonly Finding[] {
|
|
105
|
+
try {
|
|
106
|
+
verifyContract({ before, after });
|
|
107
|
+
return [];
|
|
108
|
+
} catch (error) {
|
|
109
|
+
return [{ ...findingFrom(error), at: MANIFEST_FILENAME }];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* `built` — the manifest the code describes now — against the committed contract
|
|
115
|
+
* (`committedAppManifest`). Whenever the baseline is not HEAD's file, `output` says which.
|
|
116
|
+
*/
|
|
117
|
+
export async function contractDiffOutcome(
|
|
118
|
+
root: string,
|
|
119
|
+
runner: Runner,
|
|
120
|
+
built: Manifest,
|
|
121
|
+
env: Env = {},
|
|
122
|
+
): Promise<StepOutcome> {
|
|
123
|
+
const { manifest, notice } = await committedAppManifest(root, runner, env);
|
|
124
|
+
const findings = manifest === undefined ? [] : contractFindings(manifest, built);
|
|
125
|
+
return {
|
|
126
|
+
ok: findings.length === 0,
|
|
127
|
+
findings,
|
|
128
|
+
...(notice === undefined ? {} : { output: notice }),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export const contractDiffStep: VerifyStep = {
|
|
133
|
+
name: 'contract-diff',
|
|
134
|
+
summary: 'the published contract vs the manifest committed at HEAD (in CI: at the merge base)',
|
|
135
|
+
// A BREAKING change against the committed manifest, and nothing else. Whether the committed
|
|
136
|
+
// files are stale — `openapi.json` included — is the `manifest` step's, through the one check
|
|
137
|
+
// `x manifest --check` runs (`manifest-staleness.ts`).
|
|
138
|
+
applies: async (ctx) => existsSync(join(ctx.root, MANIFEST_FILENAME)),
|
|
139
|
+
async run(ctx) {
|
|
140
|
+
const { manifest } = await appManifest(ctx.root);
|
|
141
|
+
return contractDiffOutcome(ctx.root, ctx.runner, manifest, ctx.env ?? Bun.env);
|
|
142
|
+
},
|
|
143
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// The seed run on the `unit` step: every seed the app declares (`SEED_GLOBS`) runs once, in file
|
|
2
|
+
// order, on one in-memory driver. A row its entity refuses — `{ minor: 19.99 }` typechecks — is
|
|
3
|
+
// reported with the entity's OWN code and fix, here, instead of 13 s later inside the e2e step's
|
|
4
|
+
// X_E2E_APP_FAILED. No seed file is no seeds: nothing is spawned.
|
|
5
|
+
|
|
6
|
+
import { ERROR_DOCS_URL, UltimateError } from '@ultimat3/core';
|
|
7
|
+
import type { Infer } from '@ultimat3/schema';
|
|
8
|
+
import { parse, t } from '@ultimat3/schema';
|
|
9
|
+
import { SEED_GLOBS } from './db-seed';
|
|
10
|
+
import type { Runner } from './exec';
|
|
11
|
+
import type { Finding } from './output';
|
|
12
|
+
import { findingFrom } from './output';
|
|
13
|
+
import { hasPathSegment } from './path-segments';
|
|
14
|
+
import { posixRelative } from './posix-path';
|
|
15
|
+
import { quoteArg } from './shell-quote';
|
|
16
|
+
import { isTest, sortedPosix } from './source-files';
|
|
17
|
+
|
|
18
|
+
const reportSchema = t.array(
|
|
19
|
+
t.object({
|
|
20
|
+
file: t.string,
|
|
21
|
+
/** The export that declared the seed; `*` when the module would not import. */
|
|
22
|
+
export: t.string,
|
|
23
|
+
seed: t.string,
|
|
24
|
+
code: t.nullable(t.string),
|
|
25
|
+
cause: t.nullable(t.string),
|
|
26
|
+
fix: t.nullable(t.string),
|
|
27
|
+
message: t.string,
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
type SeedFailure = Infer<typeof reportSchema>[number];
|
|
31
|
+
|
|
32
|
+
/** The seed files `x db seed` would import, app-root-relative and sorted: the run's order. */
|
|
33
|
+
async function seedFiles(root: string): Promise<readonly string[]> {
|
|
34
|
+
const files = new Set<string>();
|
|
35
|
+
for (const pattern of SEED_GLOBS) {
|
|
36
|
+
for await (const absolute of new Bun.Glob(pattern).scan({ cwd: root, absolute: true })) {
|
|
37
|
+
const file = posixRelative(root, absolute);
|
|
38
|
+
if (hasPathSegment(absolute, 'node_modules') || isTest(file)) continue;
|
|
39
|
+
files.add(file);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return sortedPosix([...files]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Run in a CHILD, from the app's root, for `verify-factories.ts`'s reason: the seeds, `isSeed` and
|
|
47
|
+
* `memoryDriver` must be the app's own `@ultimat3/entity`, and the app's entities must not register
|
|
48
|
+
* into this process. One driver for the whole run, so a later seed reads what an earlier one wrote,
|
|
49
|
+
* as `x db seed` does. The last stdout line is the report: the failures only.
|
|
50
|
+
*/
|
|
51
|
+
const script = (files: readonly string[]): string => `const files = ${JSON.stringify(files)};
|
|
52
|
+
const { isSeed, memoryDriver } = await import('@ultimat3/entity');
|
|
53
|
+
const driver = memoryDriver();
|
|
54
|
+
const str = (value, key) => { try { const v = value?.[key]; return typeof v === 'string' ? v : null; } catch { return null; } };
|
|
55
|
+
const failure = (file, name, seed, error) => ({ file, export: name, seed,
|
|
56
|
+
code: str(error, 'code'), cause: str(error, 'cause'), fix: str(error, 'fix'),
|
|
57
|
+
message: str(error, 'message') ?? (() => { try { return String(error); } catch { return 'a value that will not render'; } })() });
|
|
58
|
+
const failures = [];
|
|
59
|
+
for (const file of files) {
|
|
60
|
+
let mod;
|
|
61
|
+
try { mod = await import(\`\${process.cwd()}/\${file}\`); }
|
|
62
|
+
catch (error) { failures.push(failure(file, '*', '*', error)); continue; }
|
|
63
|
+
for (const [name, value] of Object.entries(mod)) {
|
|
64
|
+
if (!isSeed(value)) continue;
|
|
65
|
+
try { await value.run({ driver }); } catch (error) { failures.push(failure(file, name, value.name, error)); }
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
console.log(JSON.stringify(failures));`;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A seed threw something with no code of its own (a `TypeError` in its body, a module that would
|
|
72
|
+
* not import). The fix is the one line that reproduces it with a full stack, on the same in-memory
|
|
73
|
+
* driver the unit step used — the seed's own file, its own export.
|
|
74
|
+
*/
|
|
75
|
+
export class SeedFailedError extends UltimateError {
|
|
76
|
+
constructor(input: { failure: SeedFailure; where: string }) {
|
|
77
|
+
const { failure } = input;
|
|
78
|
+
const call =
|
|
79
|
+
failure.export === '*'
|
|
80
|
+
? `await import('./${failure.file}')`
|
|
81
|
+
: `await (await import('./${failure.file}'))[${JSON.stringify(failure.export)}].run()`;
|
|
82
|
+
super({
|
|
83
|
+
code: 'X_SEED_FAILED',
|
|
84
|
+
cause: `${input.where} threw an uncoded value on the in-memory driver: ${failure.message}`,
|
|
85
|
+
fix: `bun --eval ${quoteArg(call)}`,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The inner error, at the top level: a coded refusal keeps its code and its fix verbatim — the
|
|
92
|
+
* entity's fix is the one that names the edit — and only the cause gains which seed and file.
|
|
93
|
+
* An uncoded throw has no fix of its own, so the fix is the line that reproduces it with a stack.
|
|
94
|
+
*/
|
|
95
|
+
export const seedFinding = (failure: SeedFailure): Finding => {
|
|
96
|
+
const where =
|
|
97
|
+
failure.export === '*'
|
|
98
|
+
? `${failure.file} did not import`
|
|
99
|
+
: `seed "${failure.seed}" (${failure.file})`;
|
|
100
|
+
if (failure.code?.startsWith('X_') === true && failure.cause !== null && failure.fix !== null) {
|
|
101
|
+
return {
|
|
102
|
+
code: failure.code,
|
|
103
|
+
cause: `${where} on the in-memory driver: ${failure.cause}`,
|
|
104
|
+
fix: failure.fix,
|
|
105
|
+
docs: ERROR_DOCS_URL,
|
|
106
|
+
at: failure.file,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return { ...findingFrom(new SeedFailedError({ failure, where })), at: failure.file };
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** The child's last stdout line, parsed — or one finding saying the run printed no report. */
|
|
113
|
+
function readReport(stdout: string, stderr: string, first: string): readonly SeedFailure[] {
|
|
114
|
+
const last = stdout.trim().split('\n').at(-1) ?? '';
|
|
115
|
+
try {
|
|
116
|
+
return parse(reportSchema, JSON.parse(last));
|
|
117
|
+
} catch {
|
|
118
|
+
const reason = stderr.trim().split('\n').slice(-3).join(' ') || 'no report was printed';
|
|
119
|
+
return [
|
|
120
|
+
{ file: first, export: '*', seed: '*', code: null, cause: null, fix: null, message: reason },
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The seed run's findings for the app at `root`; none when it declares no seed file. */
|
|
126
|
+
export async function seedFindings(root: string, runner: Runner): Promise<readonly Finding[]> {
|
|
127
|
+
const files = await seedFiles(root);
|
|
128
|
+
const first = files[0];
|
|
129
|
+
if (first === undefined) return [];
|
|
130
|
+
const result = await runner(['bun', '--eval', script(files)], { cwd: root });
|
|
131
|
+
return readReport(result.stdout, result.stderr, first).map(seedFinding);
|
|
132
|
+
}
|
package/src/verify-tests.ts
CHANGED
|
@@ -32,6 +32,7 @@ import { factoryFindings } from './verify-factories';
|
|
|
32
32
|
import { readVerifyFloor } from './verify-floor';
|
|
33
33
|
import type { MachinePace } from './verify-pace';
|
|
34
34
|
import { DECLARED_PACE, defaultTimeoutArgs, pacedMs, paceEnv } from './verify-pace';
|
|
35
|
+
import { seedFindings } from './verify-seeds';
|
|
35
36
|
import { shardFiles } from './verify-shard';
|
|
36
37
|
import type { ChangedTestSelection, StepOutcome, VerifyContext, VerifyStep } from './verify-step';
|
|
37
38
|
import { fromExec, fromFindings } from './verify-step';
|
|
@@ -449,16 +450,21 @@ const summaryOf = (type: TypedTest): string =>
|
|
|
449
450
|
Object.hasOwn(SUMMARIES, type) ? SUMMARIES[type] : `${type} tests`;
|
|
450
451
|
|
|
451
452
|
/**
|
|
452
|
-
* The unit suite, and an app's factory lint
|
|
453
|
-
*
|
|
454
|
-
*
|
|
453
|
+
* The unit suite, and beside it an app's factory lint (`verify-factories.ts`) and seed run
|
|
454
|
+
* (`verify-seeds.ts`): a factory or a seed row its entity refuses is found here, with the entity's
|
|
455
|
+
* own code, not by every test that uses it or inside e2e's X_E2E_APP_FAILED. The two are separate
|
|
456
|
+
* children run at once, so the step pays the slower one. Under `--shard` only slice 1 runs them,
|
|
457
|
+
* so `x verify merge` reports each finding once.
|
|
455
458
|
*/
|
|
456
459
|
const unitStep = async (ctx: VerifyContext): Promise<StepOutcome> => {
|
|
457
460
|
const suite = await runType(ctx, 'unit');
|
|
458
461
|
if (!isApp(ctx.root) || (ctx.shard !== undefined && ctx.shard.index !== 1)) return suite;
|
|
459
|
-
const factories = await
|
|
460
|
-
|
|
461
|
-
|
|
462
|
+
const [factories, seeds] = await Promise.all([
|
|
463
|
+
factoryFindings(ctx.root, ctx.runner),
|
|
464
|
+
seedFindings(ctx.root, ctx.runner),
|
|
465
|
+
]);
|
|
466
|
+
if (factories.length === 0 && seeds.length === 0) return suite;
|
|
467
|
+
return { ...suite, ok: false, findings: [...factories, ...seeds, ...suite.findings] };
|
|
462
468
|
};
|
|
463
469
|
|
|
464
470
|
const stepFor = (type: TestType): VerifyStep => {
|
package/wiki/CLI-Reference.md
CHANGED
|
@@ -1167,8 +1167,8 @@ whatever its bearer token was issued.
|
|
|
1167
1167
|
| `errors.explain` | `X_*` → cause, fix, docs | `dev:read` |
|
|
1168
1168
|
| `db.query` | ONE read-only SQL statement; `limit` defaults to 100 rows, maximum 1000 | `db:read` |
|
|
1169
1169
|
| `db.migrate` | apply pending migrations to a **branch** database | `db:migrate` |
|
|
1170
|
-
| `tests.run` |
|
|
1171
|
-
| `verify.run` |
|
|
1170
|
+
| `tests.run` | `x test [--filter]` itself — the shell's files, batches and environment, so it agrees with `x test`; structured results — an error outside any test (`1 error` beside `0 fail`) or a non-zero exit is a failure, never `failed: 0` | `dev:test` |
|
|
1171
|
+
| `verify.run` | `x verify` itself, so it agrees with the shell; `only: [steps]` is `--only` (not a gate run); structured per-step result | `dev:test` |
|
|
1172
1172
|
| `logs.tail` | last N log lines, optionally for one role | `dev:logs` |
|
|
1173
1173
|
| `graph.query` | `{ node }`: what a change to a file or primitive reaches (`x impact`); `{ from, to }`: the edges linking two nodes (`x graph --from --to`) | `dev:read` |
|
|
1174
1174
|
| `ui.shot` | photograph one route at a named viewport, light or dark; PNG path plus verdict. Launches a browser | `dev:test` |
|
package/wiki/Upgrading.md
CHANGED
|
@@ -208,6 +208,9 @@ A setter still on a package's `.` barrel is `X_ADAPTER_PORT_INCOMPLETE` on the `
|
|
|
208
208
|
| built, content-hashed asset routes spend the new `assets` rate-limit bucket (**31.5.0**: 2,000 burst, 200/s), not `default`. An app that lowered `rateLimit.buckets.default` to throttle its static files no longer throttles them that way | to tighten static routes, set `rateLimit: { buckets: { assets: { capacity, refillPerSecond } } }` in `app.config.ts`. Nothing to do otherwise |
|
|
209
209
|
| `rateLimit.buckets` in `app.config.ts` merges over the shipped buckets key by key (**31.5.0**). Before, any `buckets` you declared replaced the whole table, so `auth`, `mutation` and `assets` were gone and routes naming them used `default` | nothing. A bucket you declared still wins under its own name; delete any copy of a shipped bucket you kept only so it would not disappear |
|
|
210
210
|
| a `from(entity, fn)` provider's function receives a `RowWindow` (**31.5.0**), `{ after, limit, order, filters }`, the page the read is after | nothing: a function that ignores the argument behaves as before. Optional: a repository that reads its own top N reads `after` and `limit` instead, so later pages are not empty or short |
|
|
211
|
+
| `x verify`'s `contract-diff` step is red, `X_MANIFEST_BREAKING`, on a breaking change that `x manifest` or `x g` had already written into `x.manifest.json`: from **31.6.0** the baseline is the manifest as committed (at `HEAD`, or at the merge base with `origin/$GITHUB_BASE_REF` in a GitHub pull request), never the working-tree file | bump the major version, or restore the removed surface. Regenerating the manifest no longer clears it |
|
|
212
|
+
| `x verify`'s `unit` step runs the app's seeds on the memory driver (**31.6.0**): a seed row the entity refuses — float money, a value its schema rejects — turns `unit` red under the entity's own code, and a seed that throws with no code is `X_SEED_FAILED` | fix the seed row the finding names, as its `fix:` says. Then `x verify --only unit` |
|
|
213
|
+
| `x verify`'s `errors` step reports `X_ERROR_FIX_INVALID` on an app's own error whose `fix:` defers the edit (a whitespace-delimited `# after <verb>ing …` or `# once <…>ed`), only says re-run, or runs `x g … --force` (**31.6.0**) | rewrite that `fix:` as the edit itself (`edit <path>.<ext>:<line> — <instruction>`) or a command that works on its own, with no `--force` |
|
|
211
214
|
|
|
212
215
|
## 29.x → 30.0.0, entry by entry
|
|
213
216
|
|