@ultimat3/cli 31.16.0 → 31.17.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/README.md +7 -1
- package/package.json +29 -29
- package/src/cache-graph.ts +67 -0
- package/src/cmd-cache-spec.ts +25 -0
- package/src/cmd-cache.ts +187 -0
- package/src/cmd-config-spec.ts +23 -0
- package/src/cmd-config.ts +61 -0
- package/src/cmd-exercise.ts +34 -10
- package/src/cmd-explain-spec.ts +24 -0
- package/src/cmd-explain.ts +201 -0
- package/src/cmd-logs-spec.ts +34 -0
- package/src/cmd-logs.ts +80 -0
- package/src/cmd-planned.ts +15 -29
- package/src/cmd-token-spec.ts +54 -0
- package/src/cmd-token.ts +173 -0
- package/src/cmd-verify-spec.ts +13 -3
- package/src/cmd-verify.ts +2 -0
- package/src/config-redact.ts +39 -0
- package/src/dev-boot-data-dir.ts +69 -0
- package/src/dev-boot.ts +26 -13
- package/src/error-codes-tooling.ts +6 -4
- package/src/error-codes.ts +2 -0
- package/src/errors.ts +8 -2
- package/src/exercise-entry-edit.ts +5 -1
- package/src/exercise-routes.ts +59 -0
- package/src/explain-capture.ts +38 -0
- package/src/generate-exercise.ts +2 -2
- package/src/generate-factories.ts +133 -0
- package/src/generate-files.ts +11 -0
- package/src/generate-kinds.ts +13 -0
- package/src/mcp-db-target.ts +4 -3
- package/src/mcp-errors.ts +4 -0
- package/src/messages-gate.ts +2 -0
- package/src/messages-ops.ts +32 -0
- package/src/messages-upgrade.ts +1 -0
- package/src/messages.ts +2 -0
- package/src/otlp-export.ts +16 -2
- package/src/registry.ts +10 -0
- package/src/role-start.ts +11 -5
- package/src/runtime-services.ts +35 -19
- package/src/serve-boot-phases.ts +30 -0
- package/src/serve-boot-warnings.ts +62 -0
- package/src/serve-boot.ts +30 -11
- package/src/templates/generate-cron-job.ts +90 -0
- package/src/templates/generate-purge.ts +93 -0
- package/src/templates/generate-webhook-receiver.ts +274 -0
- package/src/templates/github/ci.yml.ts +101 -36
- package/src/templates/guard-repo-raw-sql-test.ts +174 -0
- package/src/templates/guard-repo-raw-sql.ts +115 -145
- package/src/templates/guard-unbounded-fanout.ts +170 -0
- package/src/templates/scaffold-claude-commands.ts +3 -2
- package/src/templates/scaffold-docs.ts +3 -2
- package/src/templates/scaffold-guards.ts +3 -0
- package/src/upgrade-gate.ts +18 -6
- package/src/upgrade-report.ts +4 -0
- package/src/verify-plan.ts +127 -0
- package/wiki/CI-Parallel-Gate.md +38 -1
- package/wiki/CLI-Reference.md +90 -12
- package/wiki/Caching-And-Invalidation.md +10 -10
- package/wiki/Configuration.md +4 -2
- package/wiki/Known-Gaps.md +1 -1
- package/wiki/MCP-And-AI.md +1 -1
- package/wiki/Testing.md +32 -0
- package/wiki/Troubleshooting.md +3 -2
- package/wiki/Upgrading.md +6 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// The `unbounded-fanout` guard `x new` ships: a database call per element of a list runs through
|
|
2
|
+
// `mapBounded` with a stated width, never `Promise.all` over the whole list at once. Three adopters
|
|
3
|
+
// hand-rolled the pool this replaces; the list a table grows to is what makes the shape a defect.
|
|
4
|
+
|
|
5
|
+
import { guardCode } from './guard';
|
|
6
|
+
import type { GeneratedFile } from './naming';
|
|
7
|
+
|
|
8
|
+
/** Derived from the guard's name, never a literal: an `X_*` literal here is a FRAMEWORK code. */
|
|
9
|
+
const NAME = 'unbounded-fanout';
|
|
10
|
+
const CODE = guardCode(NAME);
|
|
11
|
+
|
|
12
|
+
const source =
|
|
13
|
+
(): string => `// unbounded-fanout: a database call per row runs a bounded number at a time, never all at once.
|
|
14
|
+
// \`x verify\` discovers every file in \`guards/\` and runs its \`guard\` inside the \`boundaries\`
|
|
15
|
+
// step — nothing registers this file, so nothing can forget to. Delete it to drop the rule.
|
|
16
|
+
//
|
|
17
|
+
// Why: \`Promise.all(rows.map(async (row) => db…))\` opens one statement per row AT ONCE. Ten rows
|
|
18
|
+
// is fine; the ten thousand a table grows to is ten thousand statements queued on a pool of ten,
|
|
19
|
+
// every other request waiting behind them. \`mapBounded\` from \`@ultimat3/core\` is the same map with
|
|
20
|
+
// a stated width, results in input order, and the first failure stops the rest.
|
|
21
|
+
// Read: a \`Promise.all(\` or \`Promise.allSettled(\` over \`<list>.map(…)\`, async or not, whose
|
|
22
|
+
// callback names \`db\`, \`tx\` or a \`…repo\`/\`…Repo\`, anywhere under apps/ and packages/ but a test.
|
|
23
|
+
// Not read: an array literal, which is bounded where it is written. Admitted: a \`// why:\` on the
|
|
24
|
+
// line or the line above it.
|
|
25
|
+
|
|
26
|
+
import type { Finding, Guard } from '@ultimat3/cli';
|
|
27
|
+
|
|
28
|
+
/** The app owns the codes its own conventions raise — this one is named for the guard. */
|
|
29
|
+
const CODE = '${CODE}';
|
|
30
|
+
|
|
31
|
+
export interface SourceFile {
|
|
32
|
+
/** App-root-relative POSIX path, so the finding names the file an author opens. */
|
|
33
|
+
readonly path: string;
|
|
34
|
+
readonly source: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const ALL = /\\bPromise\\s*\\.\\s*all(?:Settled)?\\s*\\(/g;
|
|
38
|
+
/** \`async\` or not: \`rows.map((row) => db.posts.find(row.id))\` is the same statement per row. */
|
|
39
|
+
const MAPPED = /\\.\\s*map\\s*\\(/;
|
|
40
|
+
/** \`db\`, \`tx\`, and a repository by any name that ends in one: \`repo\`, \`usersRepo\`, \`PostRepo\`. */
|
|
41
|
+
const DATABASE = /\\b(?:db|tx|\\w*[Rr]epo)\\b\\s*[.(]/;
|
|
42
|
+
const WHY = /\\/\\/\\s*why:/;
|
|
43
|
+
|
|
44
|
+
/** Comments and string bodies blanked IN PLACE, so a line number still points at the source. */
|
|
45
|
+
const blank = (text: string): string =>
|
|
46
|
+
text
|
|
47
|
+
.replaceAll(/\\/\\*[\\s\\S]*?\\*\\//g, (match) => match.replaceAll(/[^\\n]/g, ' '))
|
|
48
|
+
.replaceAll(/(?<![:\\w])\\/\\/[^\\n]*/g, (match) => ' '.repeat(match.length))
|
|
49
|
+
.replaceAll(/'(?:[^'\\\\\\n]|\\\\.)*'|"(?:[^"\\\\\\n]|\\\\.)*"|\`(?:[^\`\\\\]|\\\\.)*\`/g, (match) =>
|
|
50
|
+
match.replaceAll(/[^\\n]/g, ' '),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
/** The text between the \`(\` at \`open\` and the \`)\` that closes it. */
|
|
54
|
+
const argumentAt = (text: string, open: number): string => {
|
|
55
|
+
let depth = 0;
|
|
56
|
+
for (let index = open; index < text.length; index += 1) {
|
|
57
|
+
const char = text[index];
|
|
58
|
+
if (char === '(' || char === '[' || char === '{') depth += 1;
|
|
59
|
+
if (char === ')' || char === ']' || char === '}') depth -= 1;
|
|
60
|
+
if (depth === 0) return text.slice(open + 1, index);
|
|
61
|
+
}
|
|
62
|
+
return text.slice(open + 1);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** Pure — the caller does the I/O — so the rule is testable without a filesystem. */
|
|
66
|
+
export function unboundedFanouts(files: readonly SourceFile[]): readonly Finding[] {
|
|
67
|
+
const findings: Finding[] = [];
|
|
68
|
+
for (const file of files) {
|
|
69
|
+
const lines = file.source.split('\\n');
|
|
70
|
+
const text = blank(file.source);
|
|
71
|
+
for (const match of text.matchAll(ALL)) {
|
|
72
|
+
const argument = argumentAt(text, match.index + match[0].length - 1);
|
|
73
|
+
const mapped = argument.search(MAPPED);
|
|
74
|
+
const list = argument.slice(0, Math.max(mapped, 0)).trim().replaceAll(/\\s+/g, ' ');
|
|
75
|
+
// An array literal is as long as the line that writes it; a list read from anywhere is not.
|
|
76
|
+
if (mapped < 1 || list.startsWith('[') || !DATABASE.test(argument)) continue;
|
|
77
|
+
const line = text.slice(0, match.index).split('\\n').length;
|
|
78
|
+
if (WHY.test(lines[line - 1] ?? '') || WHY.test(lines[line - 2] ?? '')) continue;
|
|
79
|
+
const at = \`\${file.path}:\${line}\`;
|
|
80
|
+
findings.push({
|
|
81
|
+
code: CODE,
|
|
82
|
+
cause: \`\${at} starts a database call for every element of \${list} at once — as many statements in flight as the list is long, queued on a pool a fraction of that size\`,
|
|
83
|
+
fix: \`mapBounded(\${list}, <the same async callback>, { width: 8 }) — from @ultimat3/core, in place of the Promise.all at \${at}, the width what the pool can take — or a // why: comment on that line naming the list's bound — then: x verify\`,
|
|
84
|
+
at,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return findings;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Every source file but a test: a fixture's fan-out is over the rows it planted. */
|
|
92
|
+
export const readsFile = (path: string): boolean => !/\\.test\\.tsx?$/.test(path);
|
|
93
|
+
|
|
94
|
+
export const guard: Guard = {
|
|
95
|
+
summary: 'a database call per row runs through mapBounded, never Promise.all over the list',
|
|
96
|
+
async check(_root, sources) {
|
|
97
|
+
// The run's ONE read of the source: every guard asking for this glob shares the walk.
|
|
98
|
+
const code = await sources.files('{apps,packages}/**/*.{ts,tsx}');
|
|
99
|
+
return unboundedFanouts(
|
|
100
|
+
code
|
|
101
|
+
.filter((file) => readsFile(file.path))
|
|
102
|
+
.map((file) => ({ path: file.path, source: file.text })),
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
const test =
|
|
109
|
+
(): string => `// The rule, driven directly. Failure case first: a guard whose rule silently stopped matching is
|
|
110
|
+
// a green gate over the convention it was written to enforce.
|
|
111
|
+
|
|
112
|
+
import { expect, unitTest } from '@ultimat3/testing';
|
|
113
|
+
import { readsFile, unboundedFanouts } from './unbounded-fanout';
|
|
114
|
+
|
|
115
|
+
const file = (source: string) => [{ path: 'apps/web/app/posts/service.ts', source }];
|
|
116
|
+
|
|
117
|
+
unitTest('a database call per row, all at once, is refused at its line', () => {
|
|
118
|
+
const source =
|
|
119
|
+
'const a = 1;\\nawait Promise.all(rows.map(async (row) => db.posts.update(row.id, row)));';
|
|
120
|
+
const findings = unboundedFanouts(file(source));
|
|
121
|
+
expect(findings).toHaveLength(1);
|
|
122
|
+
expect(findings[0]?.code).toBe('${CODE}');
|
|
123
|
+
expect(findings[0]?.at).toBe('apps/web/app/posts/service.ts:2');
|
|
124
|
+
expect(findings[0]?.fix).toStartWith('mapBounded(rows, <the same async callback>, { width: 8 })');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
unitTest('allSettled, a tx, a repo and a chained list are the same rule', () => {
|
|
128
|
+
const settled = 'Promise.allSettled(ids.map(async (id) => tx.posts.delete(id)));';
|
|
129
|
+
expect(unboundedFanouts(file(settled))).toHaveLength(1);
|
|
130
|
+
const chained =
|
|
131
|
+
'Promise.all(\\n rows\\n .filter((row) => row.ok)\\n .map(async (row) => repo.byId(row.id)),\\n);';
|
|
132
|
+
expect(unboundedFanouts(file(chained))[0]?.cause).toContain('rows .filter((row) => row.ok)');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
unitTest('a callback without async, and a repository by any name, are the same rule', () => {
|
|
136
|
+
const plain = 'Promise.all(rows.map((r) => db.posts.find(r.id)));';
|
|
137
|
+
expect(unboundedFanouts(file(plain))).toHaveLength(1);
|
|
138
|
+
const named = 'Promise.all(ids.map((id) => usersRepo.byId(id)));';
|
|
139
|
+
expect(unboundedFanouts(file(named))).toHaveLength(1);
|
|
140
|
+
// Not a repository: \`report\` only starts like one.
|
|
141
|
+
expect(unboundedFanouts(file('Promise.all(ids.map((id) => report.sum(id)));'))).toEqual([]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
unitTest('an array literal, a map with no database call and a why: are not refused', () => {
|
|
145
|
+
const literal = 'Promise.all([a, b].map(async (one) => db.posts.byId(one)));';
|
|
146
|
+
expect(unboundedFanouts(file(literal))).toEqual([]);
|
|
147
|
+
expect(unboundedFanouts(file('Promise.all(urls.map(async (url) => hash(url)));'))).toEqual([]);
|
|
148
|
+
const why = '// why: at most three locales\\nPromise.all(locales.map(async (l) => db.t.byId(l)));';
|
|
149
|
+
expect(unboundedFanouts(file(why))).toEqual([]);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
unitTest('a comment and a string naming the shape are not code', () => {
|
|
153
|
+
expect(unboundedFanouts(file('// Promise.all(rows.map(async (r) => db.x(r)))'))).toEqual([]);
|
|
154
|
+
expect(
|
|
155
|
+
unboundedFanouts(file("const s = 'Promise.all(rows.map(async (r) => db.x(r)))';")),
|
|
156
|
+
).toEqual([]);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
unitTest('every source file is read but a test', () => {
|
|
160
|
+
expect(readsFile('apps/web/app/posts/service.ts')).toBe(true);
|
|
161
|
+
expect(readsFile('packages/domain/src/rules.ts')).toBe(true);
|
|
162
|
+
expect(readsFile('apps/web/app/posts/service.test.ts')).toBe(false);
|
|
163
|
+
});
|
|
164
|
+
`;
|
|
165
|
+
|
|
166
|
+
/** `guards/unbounded-fanout.ts` and its test. No index, no registry — the directory registers it. */
|
|
167
|
+
export const unboundedFanoutGuardFiles = (): readonly GeneratedFile[] => [
|
|
168
|
+
{ path: `guards/${NAME}.ts`, contents: source() },
|
|
169
|
+
{ path: `guards/${NAME}.test.ts`, contents: test() },
|
|
170
|
+
];
|
|
@@ -82,8 +82,9 @@ bun run verify --json # the same, machine-readable
|
|
|
82
82
|
\`\`\`
|
|
83
83
|
|
|
84
84
|
\`bun run verify\` is \`bunx x verify\`, the whole gate: its \`budgets\` step builds what it weighs when
|
|
85
|
-
\`.x/build-stats.json\` is missing or older than the source. CI runs this same script
|
|
86
|
-
\`.github/workflows/ci.yml\`
|
|
85
|
+
\`.x/build-stats.json\` is missing or older than the source. CI runs this same script, cut into
|
|
86
|
+
parts — \`.github/workflows/ci.yml\` asks \`bun run verify plan\` for them, runs \`bun run setup\` and
|
|
87
|
+
each part's \`bun run verify --only …\`, and \`bun run verify merge\` is the verdict.
|
|
87
88
|
|
|
88
89
|
Red is instructions, not a verdict: **every finding carries an executable \`fix:\` — run it verbatim
|
|
89
90
|
before improvising**, and \`bunx x errors explain <CODE>\` expands any code it names. Never narrow the gate
|
|
@@ -38,12 +38,13 @@ queries, jobs, MCP tools, published operations and tests it touches, each with p
|
|
|
38
38
|
|
|
39
39
|
| Rule | Detail | Refused by |
|
|
40
40
|
|---|---|---|
|
|
41
|
-
| One gate | \`bun run verify\` — \`bunx x verify\`, which builds what its \`budgets\` step weighs. Green means shippable; never merge red. CI runs the same
|
|
41
|
+
| One gate | \`bun run verify\` — \`bunx x verify\`, which builds what its \`budgets\` step weighs. Green means shippable; never merge red. CI runs the same gate, cut into parts: \`bun run verify plan --json\` names them, each runner runs \`bun run setup && bun run verify --only <steps>\`, and \`bun run verify merge\` is the verdict | the gate itself, and \`.github/workflows/ci.yml\` on every push and pull request; \`.github/workflows/image.yml\` publishes only a commit it passed |
|
|
42
42
|
| Coverage | the unit suite covers 95% of the lines and functions of this app's own source — every file under \`apps/\` and \`packages/\`, one no test loads counted at 0%. A floor, not the goal: a test added to raise it is proven by mutation — break the source, watch it go red, restore | \`X_COVERAGE_BELOW_FLOOR\` on the \`unit\` step; \`coverage\` in \`x.verify.json\` states the floor, and it only rises |
|
|
43
43
|
| One way | generators, not hand-rolled files: \`bunx x g resource\`, \`bunx x g action\`, \`bunx x g route\` | review |
|
|
44
44
|
| Surfaces | \`site/\` is 0kb JS and may not import \`app/\`; \`shared/\` is a leaf | \`X_BOUNDARY_SITE_TO_APP\` |
|
|
45
45
|
| Data | routes call actions and queries; only \`repo.ts\` touches the database | \`X_BOUNDARY_ROUTE_TO_DB\` |
|
|
46
46
|
| Repos | a \`repo.ts\` reads through the typed handle, never a \`sql\` literal the handle can express | \`guards/repo-raw-sql.ts\` |
|
|
47
|
+
| Fan-out | a database call per element of a list runs through \`mapBounded(rows, fn, { width })\` from \`@ultimat3/core\` — never \`Promise.all(rows.map(async …))\`, one statement per row at once; a \`// why:\` on the line admits a list bounded where it is built | \`guards/unbounded-fanout.ts\` |
|
|
47
48
|
| Vendors | a server \`fetch(\` carries a \`signal\` in its own options — better, it is \`outbound()\` from \`@ultimat3/core/outbound\`: a deadline, the caller's signal, safe-only retry | \`guards/raw-fetch.ts\` |
|
|
48
49
|
| Polling | an island re-reads a query on a timer with \`useQuery(ref, input, { poll: pollEvery(ms) })\` (\`@ultimat3/realtime\`), anything else with \`visibleInterval(run, ms)\` from \`@ultimat3/core/page\` — no call while the tab is hidden, none after a lost session — never a bare \`setInterval(\`; a \`// why:\` on the line admits a tick that is not a read | \`guards/raw-interval.ts\` |
|
|
49
50
|
| Confirmation | a destructive act asks through \`ConfirmDialog\` from \`@ultimat3/ui\` — Cancel focused, a native post, stays open on a refusal — never \`confirm(\`; a \`// why:\` on the line admits a call that is not that question | \`guards/native-confirm.ts\` |
|
|
@@ -181,7 +182,7 @@ with \`X_DB_DRIFT\`, and that is the fix it names.
|
|
|
181
182
|
| \`x.manifest.json\` | generated facts: routes, actions, jobs, policies |
|
|
182
183
|
| \`.mcp.json\` | MCP client config: the dev tools, \`bunx @ultimat3/cli mcp serve --transport stdio\` |
|
|
183
184
|
| \`apps/web/mcp.ts\` | the app's own \`POST /mcp\`: exposed actions, behind a bearer token |
|
|
184
|
-
| \`.github/workflows/ci.yml\` | \`bun run setup\` then \`bun run verify
|
|
185
|
+
| \`.github/workflows/ci.yml\` | on push and pull request: \`bun run verify plan\` cuts the gate into parts, each runner runs \`bun run setup\` then its \`bun run verify --only …\`, and \`bun run verify merge\` folds them into the one verdict |
|
|
185
186
|
| \`.github/workflows/image.yml\` | after a green \`ci\` on the default branch: \`docker/Dockerfile\` to \`ghcr.io\`, tagged \`sha-<7>\`, always on \`ubuntu-latest\` (bash and Docker). \`ci.yml\` runs on \`vars.CI_RUNNER\`, default \`ubuntu-latest\` |
|
|
186
187
|
`;
|
|
187
188
|
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
// is `bare-error`'s second half: an app code is declared once, with core's `defineError`. One is
|
|
25
25
|
// about the TAB: an island polls with `visibleInterval()`, which a hidden tab and a lost session stop.
|
|
26
26
|
// One is about the QUESTION: a destructive act asks through `ConfirmDialog`, never `confirm(`.
|
|
27
|
+
// One is about the POOL: a database call per row runs through `mapBounded`, never all at once.
|
|
27
28
|
|
|
28
29
|
import { animatedLayoutPropertyGuardFiles } from './guard-animated-layout-property';
|
|
29
30
|
import { bareErrorGuardFiles } from './guard-bare-error';
|
|
@@ -43,6 +44,7 @@ import { rawShadowGuardFiles } from './guard-raw-shadow';
|
|
|
43
44
|
import { rawZIndexGuardFiles } from './guard-raw-z-index';
|
|
44
45
|
import { repoRawSqlGuardFiles } from './guard-repo-raw-sql';
|
|
45
46
|
import { semanticInteractiveGuardFiles } from './guard-semantic-interactive';
|
|
47
|
+
import { unboundedFanoutGuardFiles } from './guard-unbounded-fanout';
|
|
46
48
|
import { undeclaredCustomPropertyGuardFiles } from './guard-undeclared-custom-property';
|
|
47
49
|
import { undefinedStyleClassGuardFiles } from './guard-undefined-style-class';
|
|
48
50
|
import { untranslatedStringGuardFiles } from './guard-untranslated-string';
|
|
@@ -74,6 +76,7 @@ const SHIPPED: readonly (readonly [string, () => readonly GeneratedFile[]])[] =
|
|
|
74
76
|
['raw-z-index', rawZIndexGuardFiles],
|
|
75
77
|
['repo-raw-sql', repoRawSqlGuardFiles],
|
|
76
78
|
['semantic-interactive', semanticInteractiveGuardFiles],
|
|
79
|
+
['unbounded-fanout', unboundedFanoutGuardFiles],
|
|
77
80
|
['undeclared-custom-property', undeclaredCustomPropertyGuardFiles],
|
|
78
81
|
['undefined-style-class', undefinedStyleClassGuardFiles],
|
|
79
82
|
['untranslated-string', untranslatedStringGuardFiles],
|
package/src/upgrade-gate.ts
CHANGED
|
@@ -42,6 +42,7 @@ const GUARD_DIFFERS = t.object({ name: t.string, refresh: t.string });
|
|
|
42
42
|
const DOCTOR = t.object({
|
|
43
43
|
data: t.optional(
|
|
44
44
|
t.object({
|
|
45
|
+
warnings: t.optional(t.array(FINDING)),
|
|
45
46
|
guards: t.optional(
|
|
46
47
|
t.object({
|
|
47
48
|
missing: t.optional(t.array(GUARD_MISSING)),
|
|
@@ -81,6 +82,7 @@ interface VerifyDocument {
|
|
|
81
82
|
|
|
82
83
|
interface DoctorDocument {
|
|
83
84
|
readonly data?: {
|
|
85
|
+
readonly warnings?: readonly RawFinding[];
|
|
84
86
|
readonly guards?: {
|
|
85
87
|
readonly missing?: readonly { readonly name: string; readonly add: string }[];
|
|
86
88
|
readonly differs?: readonly { readonly name: string; readonly refresh: string }[];
|
|
@@ -114,6 +116,11 @@ export interface HopExercise {
|
|
|
114
116
|
|
|
115
117
|
export interface HopGate {
|
|
116
118
|
readonly manifest: { readonly ok: boolean; readonly findings: readonly GateFinding[] };
|
|
119
|
+
/**
|
|
120
|
+
* The installed `x doctor`'s `data.warnings[]`: never red on this major, the next one's red —
|
|
121
|
+
* said by the hop that installed the doctor saying them (`X_VERIFY_STEP_UNFLOORED` among them).
|
|
122
|
+
*/
|
|
123
|
+
readonly doctorWarnings: readonly GateFinding[];
|
|
117
124
|
readonly guards: HopGuards;
|
|
118
125
|
/** The coverage floor a Bun-floor hop moved to what it measured; null when none moved. */
|
|
119
126
|
readonly coverage: HopCoverage | null;
|
|
@@ -193,11 +200,14 @@ const readExercise = (result: ExecResult): HopExercise => {
|
|
|
193
200
|
return { reported: true, ok: result.ok && document.ok, findings: flatten(document) };
|
|
194
201
|
};
|
|
195
202
|
|
|
196
|
-
/** A doctor that exits red is normal (a port, an env key);
|
|
197
|
-
const
|
|
203
|
+
/** A doctor that exits red is normal (a port, an env key); its listing and warnings are read. */
|
|
204
|
+
const readDoctor = (result: ExecResult): DoctorDocument['data'] => {
|
|
198
205
|
const parsed = DOCTOR.safeParse(documentIn(result.stdout));
|
|
199
|
-
|
|
200
|
-
|
|
206
|
+
return parsed.issues === undefined ? (parsed.value as DoctorDocument).data : undefined;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const readGuards = (doctor: DoctorDocument['data']): HopGuards => {
|
|
210
|
+
const guards = doctor?.guards;
|
|
201
211
|
if (guards === undefined) {
|
|
202
212
|
return { reported: false, missing: [], differs: [], installed: [], withheld: [] };
|
|
203
213
|
}
|
|
@@ -230,7 +240,9 @@ export async function runHopGate(input: {
|
|
|
230
240
|
onStage('manifest');
|
|
231
241
|
const manifest = readManifest(await installed(['manifest', '--json']));
|
|
232
242
|
onStage('doctor');
|
|
233
|
-
const
|
|
243
|
+
const doctor = readDoctor(await installed(['doctor', '--json']));
|
|
244
|
+
const doctorWarnings = (doctor?.warnings ?? []).map(pick);
|
|
245
|
+
const listed = readGuards(doctor);
|
|
234
246
|
let guards = listed;
|
|
235
247
|
if (listed.missing.length > 0) {
|
|
236
248
|
onStage('guards');
|
|
@@ -256,7 +268,7 @@ export async function runHopGate(input: {
|
|
|
256
268
|
const exerciseFloor = await ratchetExerciseFloor(root, stamp);
|
|
257
269
|
onStage('verify');
|
|
258
270
|
const verify = readVerify(await installed(['verify', '--json']));
|
|
259
|
-
return { manifest, guards, coverage, exercise, exerciseFloor, verify };
|
|
271
|
+
return { manifest, doctorWarnings, guards, coverage, exercise, exerciseFloor, verify };
|
|
260
272
|
}
|
|
261
273
|
|
|
262
274
|
/** What a repository with no app can still be asked, in the order an author would run them. */
|
package/src/upgrade-report.ts
CHANGED
|
@@ -118,6 +118,9 @@ export const humanLines = (input: {
|
|
|
118
118
|
figures: JSON.stringify(gate.exerciseFloor.written),
|
|
119
119
|
}),
|
|
120
120
|
]),
|
|
121
|
+
...(gate?.doctorWarnings ?? []).map((warning) =>
|
|
122
|
+
msg('cli.upgrade.doctorWarning', { code: warning.code, fix: warning.fix }),
|
|
123
|
+
),
|
|
121
124
|
// The exercise's own list first: every fix it has, before the gate's verdict on the same tree.
|
|
122
125
|
...findingLines([
|
|
123
126
|
...(gate?.exercise.findings ?? []),
|
|
@@ -172,6 +175,7 @@ export const report = (input: {
|
|
|
172
175
|
guards: gate?.guards ?? null,
|
|
173
176
|
coverage: gate?.coverage ?? null,
|
|
174
177
|
manifest: gate?.manifest ?? null,
|
|
178
|
+
doctorWarnings: gate?.doctorWarnings ?? [],
|
|
175
179
|
exercise: gate?.exercise ?? null,
|
|
176
180
|
exerciseFloor: gate?.exerciseFloor ?? null,
|
|
177
181
|
verify: gate?.verify ?? null,
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// `x verify plan --parts <n> --json`: the gate cut into CI parts, each `x verify --only <steps>
|
|
2
|
+
// [--shard i/n]` on a runner of its own, as one document a workflow's matrix reads by `fromJSON`.
|
|
3
|
+
// Derived from `VERIFY_STEP_NAMES` and `SHARDABLE_STEPS`, so a new step lands in a part without
|
|
4
|
+
// anyone editing a workflow — and `x verify merge` folds the parts back into the one verdict.
|
|
5
|
+
|
|
6
|
+
import { BadFlagError } from './errors';
|
|
7
|
+
import { readIntFlag } from './flag-number';
|
|
8
|
+
import { msg } from './messages';
|
|
9
|
+
import type { CommandResult, JsonValue } from './output';
|
|
10
|
+
import type { ParsedArgs } from './parse';
|
|
11
|
+
import type { VerifyStepName } from './verify-step';
|
|
12
|
+
import { VERIFY_STEP_NAMES } from './verify-step';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* What a part's runner starts before the gate: nothing, the test Postgres alone, or every test
|
|
16
|
+
* service. A level rather than service names — the compose file is the app's, and the workflow that
|
|
17
|
+
* starts it is the one place its names are spelled.
|
|
18
|
+
*/
|
|
19
|
+
export type PartNeeds = 'none' | 'database' | 'services';
|
|
20
|
+
|
|
21
|
+
export interface PlanPart {
|
|
22
|
+
/** The matrix row's name: the job's title and its artifact's, unique across the plan. */
|
|
23
|
+
readonly part: string;
|
|
24
|
+
/** In the gate's declared order, as `--only` runs them. */
|
|
25
|
+
readonly only: readonly VerifyStepName[];
|
|
26
|
+
/** `i/n` — absent on a part that runs its steps whole. */
|
|
27
|
+
readonly shard?: string;
|
|
28
|
+
readonly needs: PartNeeds;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The three groups that are not "everything else". The suites that read the test database split
|
|
33
|
+
* together; `live` alone, one process per runner (`SHARDABLE_STEPS`); `e2e` beside `typecheck`,
|
|
34
|
+
* the two slow unsharded steps, so the cheap static steps finish on a runner of their own.
|
|
35
|
+
*/
|
|
36
|
+
const UNIT_STEPS: readonly VerifyStepName[] = ['unit', 'contract', 'job'];
|
|
37
|
+
const LIVE_STEPS: readonly VerifyStepName[] = ['live'];
|
|
38
|
+
const BROWSER_STEPS: readonly VerifyStepName[] = ['typecheck', 'e2e'];
|
|
39
|
+
|
|
40
|
+
/** What `x new` writes into the workflow: one static, one browser, one unit and one live runner. */
|
|
41
|
+
export const DEFAULT_PLAN_PARTS = 4;
|
|
42
|
+
/** Two unsharded parts and at least one shard of each split group: fewer is not this layout. */
|
|
43
|
+
export const MIN_SPLIT_PARTS = 4;
|
|
44
|
+
/** A bound on a typo, not on cost: GitHub caps one matrix at 256 jobs. */
|
|
45
|
+
export const MAX_PLAN_PARTS = 64;
|
|
46
|
+
|
|
47
|
+
const ordered = (steps: readonly VerifyStepName[]): readonly VerifyStepName[] =>
|
|
48
|
+
VERIFY_STEP_NAMES.filter((name) => steps.includes(name));
|
|
49
|
+
|
|
50
|
+
const shards = (
|
|
51
|
+
prefix: string,
|
|
52
|
+
steps: readonly VerifyStepName[],
|
|
53
|
+
total: number,
|
|
54
|
+
needs: PartNeeds,
|
|
55
|
+
): readonly PlanPart[] =>
|
|
56
|
+
Array.from({ length: total }, (_, at) => ({
|
|
57
|
+
part: `${prefix}-${String(at + 1)}`,
|
|
58
|
+
only: ordered(steps),
|
|
59
|
+
shard: `${String(at + 1)}/${String(total)}`,
|
|
60
|
+
needs,
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* `parts` runners' worth of the gate. One is the whole gate on one runner. From four, the
|
|
65
|
+
* runners past the two unsharded parts split the unit group and `live`, the unit group taking the
|
|
66
|
+
* odd one: it holds the most files. Every step lands in exactly one part or in every shard of one
|
|
67
|
+
* split — the rule `x verify merge` refuses a run by.
|
|
68
|
+
*/
|
|
69
|
+
export function verifyPlan(parts: number): readonly PlanPart[] {
|
|
70
|
+
if (parts === 1) return [{ part: 'gate', only: VERIFY_STEP_NAMES, needs: 'services' }];
|
|
71
|
+
const split = parts - 2;
|
|
72
|
+
const grouped = new Set<VerifyStepName>([...UNIT_STEPS, ...LIVE_STEPS, ...BROWSER_STEPS]);
|
|
73
|
+
return [
|
|
74
|
+
...shards('unit', UNIT_STEPS, Math.ceil(split / 2), 'database'),
|
|
75
|
+
...shards('live', LIVE_STEPS, Math.floor(split / 2), 'services'),
|
|
76
|
+
{ part: 'static', only: VERIFY_STEP_NAMES.filter((name) => !grouped.has(name)), needs: 'none' },
|
|
77
|
+
{ part: 'e2e', only: ordered(BROWSER_STEPS), needs: 'database' },
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** `strategy.matrix` as GitHub reads it: `only` comma-joined, `shard` only where there is one. */
|
|
82
|
+
export const planMatrix = (plan: readonly PlanPart[]): { readonly include: JsonValue[] } => ({
|
|
83
|
+
include: plan.map((part) => ({
|
|
84
|
+
part: part.part,
|
|
85
|
+
only: part.only.join(','),
|
|
86
|
+
...(part.shard === undefined ? {} : { shard: part.shard }),
|
|
87
|
+
needs: part.needs,
|
|
88
|
+
})),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/** `--parts`, screened: an integer in range, and never the two counts this layout cannot make. */
|
|
92
|
+
export function readPlanParts(args: ParsedArgs): number {
|
|
93
|
+
const example = `x verify plan --parts ${String(DEFAULT_PLAN_PARTS)} --json`;
|
|
94
|
+
const parts =
|
|
95
|
+
readIntFlag(args, {
|
|
96
|
+
name: 'parts',
|
|
97
|
+
command: 'verify plan',
|
|
98
|
+
min: 1,
|
|
99
|
+
max: MAX_PLAN_PARTS,
|
|
100
|
+
example,
|
|
101
|
+
}) ?? DEFAULT_PLAN_PARTS;
|
|
102
|
+
if (parts > 1 && parts < MIN_SPLIT_PARTS) {
|
|
103
|
+
throw new BadFlagError({
|
|
104
|
+
flag: 'parts',
|
|
105
|
+
command: 'verify plan',
|
|
106
|
+
reason: `${String(parts)} runners cannot hold the static part, the browser part and a shard of each split group (1, or ${String(MIN_SPLIT_PARTS)} to ${String(MAX_PLAN_PARTS)})`,
|
|
107
|
+
fix: example,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return parts;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The subcommand's body: pure, so the workflow's matrix and this answer cannot disagree. */
|
|
114
|
+
export function verifyPlanCommand(args: ParsedArgs): CommandResult {
|
|
115
|
+
const parts = readPlanParts(args);
|
|
116
|
+
const plan = verifyPlan(parts);
|
|
117
|
+
return {
|
|
118
|
+
ok: true,
|
|
119
|
+
command: 'verify plan',
|
|
120
|
+
summary: msg('cli.verify.plan', { parts: plan.length, steps: VERIFY_STEP_NAMES.length }),
|
|
121
|
+
data: { parts: plan.length, matrix: planMatrix(plan) },
|
|
122
|
+
lines: plan.map(
|
|
123
|
+
(part) =>
|
|
124
|
+
`${part.part} x verify --only ${part.only.join(',')}${part.shard === undefined ? '' : ` --shard ${part.shard}`} (${part.needs})`,
|
|
125
|
+
),
|
|
126
|
+
};
|
|
127
|
+
}
|
package/wiki/CI-Parallel-Gate.md
CHANGED
|
@@ -80,7 +80,44 @@ slowest part's, which is the wall time CI waited. A part that is not an `x verif
|
|
|
80
80
|
document is `X_VERIFY_MERGE_INPUT` — and so is a step whose `durationMs` is not a number or whose
|
|
81
81
|
`findings` are not each a `code`, `cause` and `fix`.
|
|
82
82
|
|
|
83
|
-
##
|
|
83
|
+
## `x verify plan` — the parts, as data
|
|
84
|
+
|
|
85
|
+
`As of 31.17.0`. `x verify plan [--parts n] --json` answers the split instead of a workflow spelling
|
|
86
|
+
it: `data.matrix` is a GitHub `strategy.matrix`, one row per part —
|
|
87
|
+
`{ part, only, shard?, needs }` — derived from `VERIFY_STEP_NAMES`, so a step the gate gains lands in
|
|
88
|
+
a part with no workflow edit. Pure: no file read, nothing started.
|
|
89
|
+
|
|
90
|
+
```text
|
|
91
|
+
$ x verify plan --parts 4
|
|
92
|
+
unit-1 x verify --only unit,contract,job --shard 1/1 (database)
|
|
93
|
+
live-1 x verify --only live --shard 1/1 (services)
|
|
94
|
+
static x verify --only lint,boundaries,filesize,package-shape,errors,exercise,eval,drift,contract-diff,budgets,seo,i18n,policy,manifest,roadmap (none)
|
|
95
|
+
e2e x verify --only typecheck,e2e (database)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
| `--parts` | Layout |
|
|
99
|
+
|---|---|
|
|
100
|
+
| `1` | `gate`: every step on one runner, `needs: services` |
|
|
101
|
+
| `4`–`64` (default `4`) | `static` and `e2e` (`typecheck` + `e2e`, the two slow unsharded steps) whole; the rest of the runners split between shards of `unit,contract,job` and of `live`, the unit group taking the odd one |
|
|
102
|
+
| `2`, `3`, `0`, `65`+ | `X_CLI_BAD_FLAG` — two or three runners cannot hold this layout |
|
|
103
|
+
|
|
104
|
+
`needs` is a level, not service names: `none`, `database` (the test Postgres alone) or `services`
|
|
105
|
+
(every test service) — the compose file is the app's, and the workflow is the one place its names are
|
|
106
|
+
spelled. **`x new`'s `.github/workflows/ci.yml` reads it**: a `plan` job runs
|
|
107
|
+
`bun run verify plan --parts 4 --json` and hands `.data.matrix` to the `gate` job by `fromJSON`;
|
|
108
|
+
each part runs `bun run setup`, starts what its `needs` asks for, runs
|
|
109
|
+
`bun run verify --only "$ONLY" ${SHARD:+--shard "$SHARD"} --json` and uploads the document, red or
|
|
110
|
+
green; `verify` downloads every part and runs `bun run verify merge`. An app scaffolded before 31.17.0
|
|
111
|
+
keeps its one-job workflow, which still works; to adopt, copy a fresh scaffold's
|
|
112
|
+
`.github/workflows/ci.yml`.
|
|
113
|
+
|
|
114
|
+
This repository's own `ci.yml` stays hand-written — it carries services and URLs only the framework
|
|
115
|
+
has — and `verify-plan.test.ts` holds its `gate` matrix to `verifyPlan(7)`: a step added to the gate
|
|
116
|
+
or a part edited out of the matrix is red there before it is `X_VERIFY_MERGE_INCOMPLETE` after a push.
|
|
117
|
+
|
|
118
|
+
## A GitHub Actions workflow, by hand
|
|
119
|
+
|
|
120
|
+
The same shape with a matrix you write yourself — for a split the plan does not make:
|
|
84
121
|
|
|
85
122
|
```yaml
|
|
86
123
|
name: ci
|