@ultimat3/cli 31.27.0 → 31.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +3 -1
- package/README.md +14 -4
- package/package.json +29 -29
- package/src/app-manifest.ts +6 -1
- package/src/cmd-doctor.ts +11 -3
- package/src/cmd-repro-spec.ts +13 -1
- package/src/cmd-repro.ts +37 -5
- package/src/cmd-upgrade-codemods.ts +71 -0
- package/src/cmd-upgrade-spec.ts +19 -5
- package/src/cmd-upgrade.ts +91 -34
- package/src/codemods/agents-dev-mcp.ts +50 -0
- package/src/codemods/authenticator-session-refusal.ts +214 -0
- package/src/codemods/biome-no-default-export.ts +58 -0
- package/src/codemods/bunfig-island-coverage.ts +33 -0
- package/src/codemods/chart-dashboard.ts +73 -0
- package/src/codemods/ci-e2e-browser-stock.ts +75 -0
- package/src/codemods/ci-e2e-browser.ts +63 -0
- package/src/codemods/codemod.ts +58 -0
- package/src/codemods/define-error-leaf.ts +73 -0
- package/src/codemods/docs-ci-parts.ts +65 -0
- package/src/codemods/docs-gate-prose.ts +53 -0
- package/src/codemods/docs-island-rows.ts +31 -0
- package/src/codemods/docs-shipped-guards.ts +100 -0
- package/src/codemods/docs-test-services.ts +62 -0
- package/src/codemods/engine-diff.ts +104 -0
- package/src/codemods/engine-edits.ts +111 -0
- package/src/codemods/engine-fs.ts +95 -0
- package/src/codemods/engine.ts +191 -0
- package/src/codemods/format-edited-hook-3122.ts +28 -0
- package/src/codemods/format-edited-hook.ts +152 -0
- package/src/codemods/helm-alerts-objective.ts +105 -0
- package/src/codemods/helm-alerts-stock.ts +108 -0
- package/src/codemods/index.ts +56 -0
- package/src/codemods/metrics-probe-healthz.ts +47 -0
- package/src/codemods/pending.ts +36 -0
- package/src/codemods/repro-gitignore.ts +40 -0
- package/src/codemods/runtime-pin-lines.ts +109 -0
- package/src/codemods/runtime-pin.ts +116 -0
- package/src/codemods/solid-floor.ts +63 -0
- package/src/codemods/test-ports.ts +86 -0
- package/src/codemods/test-suites.ts +37 -0
- package/src/codemods/theme-toggle-mount-over.ts +70 -0
- package/src/codemods/vendored-guards.ts +186 -0
- package/src/codemods/verify-floor-skips.ts +88 -0
- package/src/codemods/verify-floor-steps.ts +90 -0
- package/src/doctor-advisory-floors.ts +113 -0
- package/src/doctor-guards.ts +39 -86
- package/src/doctor-superseded.ts +67 -0
- package/src/error-codes-doctor.ts +12 -4
- package/src/error-codes.ts +6 -0
- package/src/exercise-database.ts +7 -2
- package/src/generate-files.ts +6 -5
- package/src/guards-built-in-codes.ts +36 -0
- package/src/guards-built-in-refusal.ts +25 -0
- package/src/guards-built-in.ts +134 -0
- package/src/guards-materialize.ts +42 -0
- package/src/guards-paths.ts +37 -0
- package/src/guards-shipped-names.ts +38 -0
- package/src/guards-vendored.ts +73 -0
- package/src/guards.ts +90 -34
- package/src/index.ts +10 -0
- package/src/lint-findings.ts +3 -3
- package/src/mcp-errors.ts +11 -1
- package/src/measure-scope.ts +23 -3
- package/src/messages-repro.ts +16 -2
- package/src/messages-upgrade.ts +15 -0
- package/src/messages.ts +1 -1
- package/src/repro-archive-collect.ts +161 -0
- package/src/repro-archive-write.ts +96 -0
- package/src/repro-archive.ts +161 -0
- package/src/repro-bundle.ts +8 -16
- package/src/repro-errors.ts +14 -2
- package/src/repro-framework.ts +53 -0
- package/src/repro-parse.ts +87 -0
- package/src/repro-redact.ts +218 -0
- package/src/repro-scrub.ts +257 -0
- package/src/superseded-match.ts +87 -0
- package/src/superseded.ts +84 -0
- package/src/templates/bun-image.ts +48 -0
- package/src/templates/github/ci.yml.ts +1 -1
- package/src/templates/guard-released-forms.ts +112 -0
- package/src/templates/guard-runtime-pin-test.ts +54 -0
- package/src/templates/guard-runtime-pin.ts +189 -0
- package/src/templates/scaffold-claude-agents.ts +6 -6
- package/src/templates/scaffold-claude-commands.ts +1 -1
- package/src/templates/scaffold-claude-hook.ts +18 -8
- package/src/templates/scaffold-claude.ts +2 -2
- package/src/templates/scaffold-docs.ts +26 -24
- package/src/templates/scaffold-guards.ts +73 -39
- package/src/templates/scaffold-repo.ts +2 -1
- package/src/unthrown-codes.ts +2 -0
- package/src/upgrade-bun-floor.ts +4 -0
- package/src/upgrade-clean-tree.ts +54 -0
- package/src/upgrade-gate-codemods-install.ts +40 -0
- package/src/upgrade-gate-codemods.ts +151 -0
- package/src/upgrade-gate.ts +38 -6
- package/src/upgrade-lock.ts +118 -0
- package/src/upgrade-plan.ts +2 -1
- package/src/upgrade-report-codemods.ts +54 -0
- package/src/upgrade-report.ts +52 -27
- package/src/upgrade-signals.ts +91 -0
- package/src/upgrade-unfinished.ts +61 -0
- package/wiki/CLI-Reference.md +58 -4
- package/wiki/Interface-Rules.md +17 -8
- package/wiki/Observability.md +1 -0
- package/wiki/Project-Layout.md +4 -4
- package/wiki/Upgrading.md +5 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// `x doctor`'s advisory floors: a version the app's `bun.lock` resolves below the first release an
|
|
2
|
+
// npm advisory left behind, for the dependencies the framework brings and cannot floor itself.
|
|
3
|
+
// A warning and never the verdict (`X_BREAKING_ON_MAIN`); `scripts/advisory-floors.ts` is the
|
|
4
|
+
// framework-side half that raises the ranges it can.
|
|
5
|
+
|
|
6
|
+
// why: Bun exposes no path-join primitive; Bun.file takes one already joined.
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { ERROR_DOCS_URL } from '@ultimat3/core';
|
|
9
|
+
import type { Finding } from './output';
|
|
10
|
+
import { quoteArg } from './shell-quote';
|
|
11
|
+
|
|
12
|
+
export const ADVISORY_FLOOR_UNMET = 'X_ADVISORY_FLOOR_UNMET';
|
|
13
|
+
|
|
14
|
+
export interface AdvisoryFloor {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
/** The lowest version every listed advisory left behind. */
|
|
17
|
+
readonly floor: string;
|
|
18
|
+
readonly advisories: readonly string[];
|
|
19
|
+
/** How it reaches an app: a range the app declares itself, or one a framework dependency does. */
|
|
20
|
+
readonly via: 'app' | 'transitive';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* As of 2026-11-15. `solid-js` is the app's own pin (`@ultimat3/ui` peers `^1.9.18`: the first
|
|
25
|
+
* release asking for seroval `~1.6.11`); the other two arrive through `sass`, whose ranges admit
|
|
26
|
+
* the patched versions, so a lockfile refresh is the whole fix and no `overrides` is needed.
|
|
27
|
+
*/
|
|
28
|
+
export const ADVISORY_FLOORS: readonly AdvisoryFloor[] = [
|
|
29
|
+
{
|
|
30
|
+
name: 'solid-js',
|
|
31
|
+
floor: '1.9.18',
|
|
32
|
+
advisories: ['GHSA-3qxh-p7jc-5xh6', 'GHSA-f86p-h4j2-7qgj', 'GHSA-9wx9-5pv9-3349'],
|
|
33
|
+
via: 'app',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'source-map-js',
|
|
37
|
+
floor: '1.2.2',
|
|
38
|
+
advisories: ['GHSA-68fv-2mgg-jv7q'],
|
|
39
|
+
via: 'transitive',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'immutable',
|
|
43
|
+
floor: '5.1.8',
|
|
44
|
+
advisories: ['GHSA-xvcm-6775-5m9r', 'GHSA-v56q-mh7h-f735'],
|
|
45
|
+
via: 'transitive',
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
/** The floor the codemod raises an app's `solid-js` to. */
|
|
50
|
+
export const SOLID_FLOOR = ADVISORY_FLOORS[0]?.floor ?? '1.9.18';
|
|
51
|
+
|
|
52
|
+
/** A registry release: what `Bun.semver.order` can compare. */
|
|
53
|
+
const RELEASE = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]*)?$/;
|
|
54
|
+
|
|
55
|
+
/** Every version `bun.lock` resolves for `name`, nested `parent/name` entries included. */
|
|
56
|
+
function resolvedVersions(packages: Readonly<Record<string, unknown>>, name: string): string[] {
|
|
57
|
+
return Object.entries(packages).flatMap(([key, entry]) => {
|
|
58
|
+
if (key !== name && !key.endsWith(`/${name}`)) return [];
|
|
59
|
+
const head = Array.isArray(entry) ? entry[0] : undefined;
|
|
60
|
+
return typeof head === 'string' && head.startsWith(`${name}@`)
|
|
61
|
+
? [head.slice(name.length + 1)]
|
|
62
|
+
: [];
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function lockPackages(root: string): Promise<Readonly<Record<string, unknown>> | undefined> {
|
|
67
|
+
const file = Bun.file(join(root, 'bun.lock'));
|
|
68
|
+
if (!(await file.exists())) return undefined;
|
|
69
|
+
try {
|
|
70
|
+
const parsed: unknown = Bun.JSONC.parse(await file.text());
|
|
71
|
+
const packages =
|
|
72
|
+
typeof parsed === 'object' && parsed !== null ? Reflect.get(parsed, 'packages') : undefined;
|
|
73
|
+
return typeof packages === 'object' && packages !== null
|
|
74
|
+
? (packages as Record<string, unknown>)
|
|
75
|
+
: undefined;
|
|
76
|
+
} catch {
|
|
77
|
+
// Not swallowed: an unparsable lockfile is `bun install`'s to refuse, loudly, on the next run.
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** One warning per floor the lockfile resolves under, lowest resolved version named. */
|
|
83
|
+
export async function advisoryFloorFindings(
|
|
84
|
+
root: string,
|
|
85
|
+
floors: readonly AdvisoryFloor[] = ADVISORY_FLOORS,
|
|
86
|
+
): Promise<readonly Finding[]> {
|
|
87
|
+
const packages = await lockPackages(root);
|
|
88
|
+
if (packages === undefined) return [];
|
|
89
|
+
const transitive = floors.filter((f) => f.via === 'transitive').map((f) => quoteArg(f.name));
|
|
90
|
+
return floors.flatMap((row) => {
|
|
91
|
+
// A git, tarball or `file:` head is no release on npm's line, so no advisory range reads it:
|
|
92
|
+
// skipped rather than ordered, because `Bun.semver.order` throws on it and would take every
|
|
93
|
+
// other `x doctor` check down with this warning.
|
|
94
|
+
const below = resolvedVersions(packages, row.name)
|
|
95
|
+
.filter((version) => RELEASE.test(version))
|
|
96
|
+
.filter((version) => Bun.semver.order(version, row.floor) < 0)
|
|
97
|
+
.sort((a, b) => Bun.semver.order(a, b));
|
|
98
|
+
const lowest = below[0];
|
|
99
|
+
if (lowest === undefined) return [];
|
|
100
|
+
return [
|
|
101
|
+
{
|
|
102
|
+
code: ADVISORY_FLOOR_UNMET,
|
|
103
|
+
cause: `bun.lock resolves ${row.name} ${lowest}, below ${row.floor}, the first release past ${row.advisories.join(', ')}`,
|
|
104
|
+
fix:
|
|
105
|
+
row.via === 'app'
|
|
106
|
+
? ['bun', 'add', '--exact', `${quoteArg(row.name)}@${row.floor}`].join(' ')
|
|
107
|
+
: ['bun', 'update', ...transitive].join(' '),
|
|
108
|
+
docs: ERROR_DOCS_URL,
|
|
109
|
+
at: 'bun.lock',
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
});
|
|
113
|
+
}
|
package/src/doctor-guards.ts
CHANGED
|
@@ -1,58 +1,16 @@
|
|
|
1
|
-
// `x doctor`'s guard listing: the shipped guards this app's `guards/`
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// `x doctor`'s guard listing: the copies of shipped guards this app's `guards/` still holds. Every
|
|
2
|
+
// shipped guard runs from the installed framework (`guards-built-in.ts`), so none is ever missing;
|
|
3
|
+
// a copy runs in its place and never receives a fix, so each is listed with its diff and the edit
|
|
4
|
+
// that resolves it (`guards-vendored.ts`). Never in the VERDICT: a warning beside it.
|
|
5
5
|
|
|
6
6
|
// why: Bun exposes no path-join primitive; Bun.file takes one already joined.
|
|
7
7
|
import { join } from 'node:path';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { guardPaths } from './guards';
|
|
9
|
+
import { vendoredPath } from './guards-built-in';
|
|
10
|
+
import { resolvingEdit, type VendoredCopy, vendoredCopy, vendoredFinding } from './guards-vendored';
|
|
10
11
|
import { msg } from './messages';
|
|
11
12
|
import type { CommandResult, Finding, JsonValue } from './output';
|
|
12
|
-
import { SHIPPED_GUARD_NAMES
|
|
13
|
-
|
|
14
|
-
export interface MissingGuard {
|
|
15
|
-
readonly name: string;
|
|
16
|
-
/** The command that writes it, with its test. Then `x verify` says what it finds. */
|
|
17
|
-
readonly add: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** The rule, pure: which shipped names have no file among the guards an app holds. */
|
|
21
|
-
export function missingShippedGuards(present: readonly string[]): readonly MissingGuard[] {
|
|
22
|
-
const held = new Set(present.map((path) => path.replace(/\.tsx?$/, '')));
|
|
23
|
-
return SHIPPED_GUARD_NAMES.filter((name) => !held.has(`${GUARD_DIR}/${name}`)).map((name) => ({
|
|
24
|
-
name,
|
|
25
|
-
add: `x g guard ${name}`,
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const MISSING_GUARD = 'X_SHIPPED_GUARD_MISSING';
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* A missing shipped guard as a WARNING, one per guard: the gate does not hold this app to that
|
|
33
|
-
* rule, and "no findings — environment is shippable" alone said nothing of it. A warning and not a
|
|
34
|
-
* finding, so on `main` an adopter's doctor keeps its exit status (`doctor-warnings.ts`).
|
|
35
|
-
*/
|
|
36
|
-
export function missingGuardWarnings(entries: readonly GuardListingEntry[]): readonly Finding[] {
|
|
37
|
-
return entries
|
|
38
|
-
.filter((entry): entry is MissingGuard => 'add' in entry)
|
|
39
|
-
.map(({ name, add }) => ({
|
|
40
|
-
code: MISSING_GUARD,
|
|
41
|
-
cause: `${GUARD_DIR}/${name}.ts is not in this app, so x verify does not hold it to the shipped ${name} rule`,
|
|
42
|
-
fix: `${add} && x verify --only boundaries --json`,
|
|
43
|
-
docs: ERROR_DOCS_URL,
|
|
44
|
-
at: `${GUARD_DIR}/${name}.ts`,
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface DifferingGuard {
|
|
49
|
-
readonly name: string;
|
|
50
|
-
/** Rewrites the guard and its test from the current template. Review the diff, then keep it. */
|
|
51
|
-
readonly refresh: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** One line of the listing: a shipped guard the app lacks, or holds in another form. */
|
|
55
|
-
export type GuardListingEntry = MissingGuard | DifferingGuard;
|
|
13
|
+
import { SHIPPED_GUARD_NAMES } from './templates/scaffold-guards';
|
|
56
14
|
|
|
57
15
|
/** A guard file as the app holds it, path relative to the app root. */
|
|
58
16
|
export interface HeldGuard {
|
|
@@ -60,63 +18,58 @@ export interface HeldGuard {
|
|
|
60
18
|
readonly source: string;
|
|
61
19
|
}
|
|
62
20
|
|
|
63
|
-
/** A checkout on Windows may write CRLF; the rule is the same text either way. */
|
|
64
|
-
const sameText = (a: string, b: string): boolean =>
|
|
65
|
-
a.replaceAll('\r\n', '\n') === b.replaceAll('\r\n', '\n');
|
|
66
|
-
|
|
67
21
|
/**
|
|
68
|
-
* The rule, pure: which held guards carry a shipped name
|
|
69
|
-
*
|
|
22
|
+
* The rule, pure: which held guards carry a shipped name, each judged against the shipped guard. A
|
|
23
|
+
* guard with a name the framework never shipped is the app's own — `app-<name>` after the migration.
|
|
70
24
|
*/
|
|
71
|
-
export function
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
continue;
|
|
79
|
-
differing.push({ name, refresh: `x g guard ${name} --force` });
|
|
25
|
+
export function vendoredShippedGuards(held: readonly HeldGuard[]): readonly VendoredCopy[] {
|
|
26
|
+
const paths = held.map(({ path }) => path);
|
|
27
|
+
const copies: VendoredCopy[] = [];
|
|
28
|
+
for (const name of SHIPPED_GUARD_NAMES) {
|
|
29
|
+
const path = vendoredPath(paths, name);
|
|
30
|
+
const source = held.find((guard) => guard.path === path)?.source;
|
|
31
|
+
if (path !== undefined && source !== undefined) copies.push(vendoredCopy(name, path, source));
|
|
80
32
|
}
|
|
81
|
-
return
|
|
33
|
+
return copies;
|
|
82
34
|
}
|
|
83
35
|
|
|
84
36
|
/** The I/O half: the same enumeration the `boundaries` step runs, so the two cannot disagree. */
|
|
85
|
-
export async function shippedGuardsProbe(root: string): Promise<readonly
|
|
37
|
+
export async function shippedGuardsProbe(root: string): Promise<readonly VendoredCopy[]> {
|
|
86
38
|
const paths = await guardPaths(root);
|
|
87
39
|
const held = await Promise.all(
|
|
88
40
|
paths.map(async (path) => ({ path, source: await Bun.file(join(root, path)).text() })),
|
|
89
41
|
);
|
|
90
|
-
|
|
91
|
-
...missingShippedGuards(paths),
|
|
92
|
-
...differingShippedGuards(held),
|
|
93
|
-
];
|
|
94
|
-
return entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
42
|
+
return vendoredShippedGuards(held);
|
|
95
43
|
}
|
|
96
44
|
|
|
45
|
+
/** One warning per copy — the code the `boundaries` step lists too — so the exit status stays. */
|
|
46
|
+
export const vendoredGuardWarnings = (copies: readonly VendoredCopy[]): readonly Finding[] =>
|
|
47
|
+
copies.map(vendoredFinding);
|
|
48
|
+
|
|
97
49
|
/**
|
|
98
|
-
* The listing, on a result `x doctor` already decided: `data.guards` for a machine
|
|
99
|
-
*
|
|
100
|
-
* `
|
|
50
|
+
* The listing, on a result `x doctor` already decided: `data.guards` for a machine — `missing`
|
|
51
|
+
* always empty now, `differs` each edited copy with the edit that resolves it and its diff,
|
|
52
|
+
* `vendored` every copy — and for a person, one line and an edit per copy. `ok`, the summary and
|
|
53
|
+
* the findings are returned as they came.
|
|
101
54
|
*/
|
|
102
55
|
export function withGuardListing(
|
|
103
56
|
result: CommandResult,
|
|
104
|
-
|
|
57
|
+
copies: readonly VendoredCopy[],
|
|
105
58
|
): CommandResult {
|
|
106
59
|
const data = typeof result.data === 'object' && result.data !== null ? result.data : {};
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
const lines = [
|
|
110
|
-
...(differs.length === 0
|
|
60
|
+
const lines =
|
|
61
|
+
copies.length === 0
|
|
111
62
|
? []
|
|
112
63
|
: [
|
|
113
|
-
msg('cli.doctor.guardsDiffer', { count:
|
|
114
|
-
...
|
|
115
|
-
]
|
|
116
|
-
];
|
|
64
|
+
msg('cli.doctor.guardsDiffer', { count: copies.length }),
|
|
65
|
+
...copies.map((copy) => ` ${resolvingEdit(copy)}`),
|
|
66
|
+
];
|
|
117
67
|
const guards: JsonValue = {
|
|
118
|
-
missing:
|
|
119
|
-
differs:
|
|
68
|
+
missing: [],
|
|
69
|
+
differs: copies
|
|
70
|
+
.filter(({ identical }) => !identical)
|
|
71
|
+
.map((copy) => ({ name: copy.name, refresh: resolvingEdit(copy), diff: copy.diff ?? '' })),
|
|
72
|
+
vendored: copies.map(({ name }) => name),
|
|
120
73
|
};
|
|
121
74
|
return {
|
|
122
75
|
...result,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// `x doctor`'s and `x upgrade`'s superseded workarounds: every note in an app's source or docs
|
|
2
|
+
// that names a workaround the framework has since retired (`superseded.ts`), as a warning with the
|
|
3
|
+
// edit that retires it. A warning and never the verdict: an app that upgrades with no change keeps
|
|
4
|
+
// a green doctor on `main` (`X_BREAKING_ON_MAIN`).
|
|
5
|
+
|
|
6
|
+
// why: Bun exposes no path-join primitive; Bun.file takes one already joined.
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { ERROR_DOCS_URL } from '@ultimat3/core';
|
|
9
|
+
import type { Finding } from './output';
|
|
10
|
+
import { eachSourceFile, isVendored, sortedPosix } from './source-files';
|
|
11
|
+
import type { SupersededWorkaround } from './superseded';
|
|
12
|
+
import { SUPERSEDED_WORKAROUNDS } from './superseded';
|
|
13
|
+
import type { SupersededHit } from './superseded-match';
|
|
14
|
+
import { matchSuperseded } from './superseded-match';
|
|
15
|
+
|
|
16
|
+
export const SUPERSEDED_WORKAROUND = 'X_SUPERSEDED_WORKAROUND';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Beyond the gate's source set: an app's gaps list is markdown, and a hand-written terminator or
|
|
20
|
+
* relay lives in `bin/`, which no gate step reads.
|
|
21
|
+
*/
|
|
22
|
+
const EXTRA_GLOBS = ['bin/**/*.{ts,tsx}', '*.md', 'docs/**/*.md'] as const;
|
|
23
|
+
|
|
24
|
+
/** Every file the scan reads: the gate's own source set, then `EXTRA_GLOBS`. */
|
|
25
|
+
export async function supersededPaths(root: string): Promise<readonly string[]> {
|
|
26
|
+
const paths: string[] = [];
|
|
27
|
+
for await (const path of eachSourceFile(root)) paths.push(path);
|
|
28
|
+
for (const pattern of EXTRA_GLOBS) {
|
|
29
|
+
const found: string[] = [];
|
|
30
|
+
for await (const path of new Bun.Glob(pattern).scan({ cwd: root, absolute: false })) {
|
|
31
|
+
if (!isVendored(path)) found.push(path);
|
|
32
|
+
}
|
|
33
|
+
paths.push(...sortedPosix(found));
|
|
34
|
+
}
|
|
35
|
+
return paths;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** One hit as a warning: the cause names the replacement and the version that shipped it. */
|
|
39
|
+
export function supersededFinding(hit: SupersededHit, row: SupersededWorkaround): Finding {
|
|
40
|
+
return {
|
|
41
|
+
code: SUPERSEDED_WORKAROUND,
|
|
42
|
+
cause: `${hit.at} keeps the '${row.id}' workaround; ${row.replacement} shipped in ${row.shippedIn}`,
|
|
43
|
+
fix: row.fix,
|
|
44
|
+
docs: ERROR_DOCS_URL,
|
|
45
|
+
at: hit.at.replace(/:\d+$/, ''),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The seam `x upgrade` calls too: every superseded workaround under `root`, as warnings, in file
|
|
51
|
+
* order. `rows` defaults to the table; a test passes its own.
|
|
52
|
+
*/
|
|
53
|
+
export async function supersededFindings(
|
|
54
|
+
root: string,
|
|
55
|
+
rows: readonly SupersededWorkaround[] = SUPERSEDED_WORKAROUNDS,
|
|
56
|
+
): Promise<readonly Finding[]> {
|
|
57
|
+
const byId = new Map(rows.map((row) => [row.id, row]));
|
|
58
|
+
const findings: Finding[] = [];
|
|
59
|
+
for (const path of await supersededPaths(root)) {
|
|
60
|
+
const text = await Bun.file(join(root, path)).text();
|
|
61
|
+
for (const hit of matchSuperseded(path, text, rows)) {
|
|
62
|
+
const row = byId.get(hit.id);
|
|
63
|
+
if (row !== undefined) findings.push(supersededFinding(hit, row));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return findings;
|
|
67
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// The X_* codes of how an app is HELD — `x doctor`'s floor, pin, env
|
|
2
|
-
//
|
|
3
|
-
// `error-codes.ts` at its
|
|
4
|
-
// union and registers them in its one call; nothing else imports this file.
|
|
1
|
+
// The X_* codes of how an app is HELD — `x doctor`'s floor, pin, env, row-security, guard,
|
|
2
|
+
// superseded-workaround, advisory-floor and owed-codemod checks, the `exercise` floor and `drift`'s
|
|
3
|
+
// undeclared index. Split from `error-codes.ts` at its ceiling; it folds these into the CLI's one
|
|
4
|
+
// owned union and registers them in its one call; nothing else imports this file.
|
|
5
5
|
|
|
6
6
|
/** Codes `x doctor`, the `exercise` floor and the `drift` step's index advice declare and own. */
|
|
7
7
|
export const CLI_DOCTOR_ERROR_CODES = [
|
|
@@ -12,6 +12,10 @@ export const CLI_DOCTOR_ERROR_CODES = [
|
|
|
12
12
|
'X_DB_ROW_SECURITY_OFF',
|
|
13
13
|
'X_DB_INDEX_UNDECLARED',
|
|
14
14
|
'X_SHIPPED_GUARD_MISSING',
|
|
15
|
+
'X_SUPERSEDED_WORKAROUND',
|
|
16
|
+
'X_GUARD_VENDORED',
|
|
17
|
+
'X_ADVISORY_FLOOR_UNMET',
|
|
18
|
+
'X_UPGRADE_CODEMODS_PENDING',
|
|
15
19
|
] as const;
|
|
16
20
|
|
|
17
21
|
export type CliDoctorErrorCode = (typeof CLI_DOCTOR_ERROR_CODES)[number];
|
|
@@ -25,4 +29,8 @@ export const CLI_DOCTOR_ERROR_TITLES: Readonly<Record<CliDoctorErrorCode, string
|
|
|
25
29
|
X_DB_ROW_SECURITY_OFF: 'Raw sql reaches tenant tables while database.rowSecurity is off',
|
|
26
30
|
X_DB_INDEX_UNDECLARED: 'Schema dump holds an index nothing declares',
|
|
27
31
|
X_SHIPPED_GUARD_MISSING: "A guard x new ships is not in this app's guards/",
|
|
32
|
+
X_SUPERSEDED_WORKAROUND: 'a workaround the framework has since retired is still in the app',
|
|
33
|
+
X_GUARD_VENDORED: 'a guards/ copy of a shipped guard',
|
|
34
|
+
X_ADVISORY_FLOOR_UNMET: 'a resolved dependency is below its advisory floor',
|
|
35
|
+
X_UPGRADE_CODEMODS_PENDING: 'files an older x upgrade left for codemods',
|
|
28
36
|
};
|
package/src/error-codes.ts
CHANGED
|
@@ -237,6 +237,9 @@ export const CLI_OWNED_ERROR_CODES = [
|
|
|
237
237
|
'X_DEV_PEER_REFUSED',
|
|
238
238
|
'X_PROFILE_ROUTE_FAILED',
|
|
239
239
|
'X_ROWS_SLICE_ENTITY',
|
|
240
|
+
'X_GUARD_BUILT_IN',
|
|
241
|
+
'X_REPRO_BUNDLE_INVALID',
|
|
242
|
+
'X_UPGRADE_LOCKED',
|
|
240
243
|
] as const;
|
|
241
244
|
|
|
242
245
|
/**
|
|
@@ -462,6 +465,9 @@ export const CLI_ERROR_TITLES: Readonly<Record<CliListedErrorCode, string>> = {
|
|
|
462
465
|
X_DEV_PEER_REFUSED: 'a /_x request came from a non-loopback peer',
|
|
463
466
|
X_PROFILE_ROUTE_FAILED: 'the profiled route answered an error',
|
|
464
467
|
X_ROWS_SLICE_ENTITY: "the slice's entity is not the scaffolded table",
|
|
468
|
+
X_GUARD_BUILT_IN: 'x g guard named a shipped guard',
|
|
469
|
+
X_REPRO_BUNDLE_INVALID: 'the file is not a repro bundle this version can open',
|
|
470
|
+
X_UPGRADE_LOCKED: 'another x upgrade holds this app',
|
|
465
471
|
};
|
|
466
472
|
|
|
467
473
|
// One unconditional call, so a second package claiming one of the CLI's codes throws
|
package/src/exercise-database.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// gate needs nothing listening, exactly as the `drift` step does not.
|
|
5
5
|
|
|
6
6
|
import type { Environment } from '@ultimat3/core';
|
|
7
|
-
import { ENVIRONMENT_KEY, resolveEnvironment, UltimateError } from '@ultimat3/core';
|
|
7
|
+
import { ENVIRONMENT_KEY, resolveEnvironment, UltimateError, withStoreMode } from '@ultimat3/core';
|
|
8
8
|
import type { DbClient, Migration } from '@ultimat3/db';
|
|
9
9
|
import { dbExecutor, migrate, raw, setDbClient } from '@ultimat3/db';
|
|
10
10
|
import {
|
|
@@ -59,6 +59,8 @@ const PINNED = [ENVIRONMENT_KEY, 'NODE_ENV'] as const;
|
|
|
59
59
|
* no `ULTIMATE_SECRETS_KEY`, and every row sealed here dies with the scratch database). Every
|
|
60
60
|
* variable is put back as found: a command that exits must not leave the next one a test process.
|
|
61
61
|
*
|
|
62
|
+
* Core's `storeMode` is declared `database` for the length of `work` (`withStoreMode`).
|
|
63
|
+
*
|
|
62
64
|
* The frozen clock too, and FIRST — as `bun test`'s preload freezes it before any module loads. The
|
|
63
65
|
* scratch database is PGlite, whose Postgres arms its timers off `Date.now()`: booted on the real
|
|
64
66
|
* clock and frozen under later (the pass's room), its 10 s idle-stats timer was re-armed at
|
|
@@ -80,7 +82,10 @@ export async function withExerciseProcess<T>(
|
|
|
80
82
|
if (!clock.installed) installDeterminism();
|
|
81
83
|
Object.assign(process.env, added);
|
|
82
84
|
try {
|
|
83
|
-
|
|
85
|
+
// A test process ON a database: the scratch one `withExerciseDatabase` installs. A store an
|
|
86
|
+
// app picks at load by core's `storeMode` (an api key, a device token) is that database's, or
|
|
87
|
+
// every reach writing it sends no statement and proves nothing. `bun test` stays `memory`.
|
|
88
|
+
return await withStoreMode('database', work);
|
|
84
89
|
} finally {
|
|
85
90
|
restoreCapturedDeterminism(clock);
|
|
86
91
|
for (const [key, value] of previous) {
|
package/src/generate-files.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { Generator } from './generate-kinds';
|
|
|
8
8
|
import { assertLiveSupported, assertSurfaceSupported, GENERATORS } from './generate-kinds';
|
|
9
9
|
import type { SignInMode } from './generate-sign-in-mode';
|
|
10
10
|
import { dedupe } from './generate-write';
|
|
11
|
+
import { refuseShippedGuardName } from './guards-built-in-refusal';
|
|
11
12
|
import { quoteArg } from './shell-quote';
|
|
12
13
|
import type { GeneratedFile, Surface } from './templates';
|
|
13
14
|
import {
|
|
@@ -24,7 +25,6 @@ import {
|
|
|
24
25
|
queryFiles,
|
|
25
26
|
resourceFiles,
|
|
26
27
|
routeFiles,
|
|
27
|
-
shippedGuardFiles,
|
|
28
28
|
taskFiles,
|
|
29
29
|
} from './templates';
|
|
30
30
|
import { adminCatalogFiles } from './templates/admin-catalog';
|
|
@@ -265,11 +265,12 @@ export function generate(options: GenerateOptions): readonly GeneratedFile[] {
|
|
|
265
265
|
return dedupe(islandFiles(options.name, { dir: options.at ?? `${surfaceDir}/${feature}` }));
|
|
266
266
|
// No `--at`, no surface, no feature: `guards/` is the one directory the gate discovers, and a
|
|
267
267
|
// guard that lived anywhere else would need an app-side registration to be found.
|
|
268
|
-
// A name the framework ships a guard under
|
|
269
|
-
//
|
|
270
|
-
// template.
|
|
268
|
+
// A name the framework ships a guard under is refused: that guard already runs, built in, and
|
|
269
|
+
// installing the framework is the one way to get it (`guards-built-in-refusal.ts`). Any other
|
|
270
|
+
// name is the app's own convention, from the blank template.
|
|
271
271
|
case 'guard':
|
|
272
|
-
|
|
272
|
+
refuseShippedGuardName(kebab(options.name));
|
|
273
|
+
return dedupe(guardFiles(options.name));
|
|
273
274
|
case 'admin:page':
|
|
274
275
|
// A default permission, never none: an empty list is `X_ADMIN_PAGE_UNGUARDED` on sight.
|
|
275
276
|
return dedupe(
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// The codes the shipped guards raise, as `x.manifest.json` facts: a built-in guard that runs is a
|
|
2
|
+
// code this app's gate emits, exactly as a vendored copy's was, so moving the guard into the
|
|
3
|
+
// framework (`vendored-guards`) removes no code from the app's contract. Owned by `@ultimat3/cli`.
|
|
4
|
+
|
|
5
|
+
import type { ErrorCodeFact } from '@ultimat3/manifest';
|
|
6
|
+
import { planBuiltIns, readShippedConfig } from './guards-built-in';
|
|
7
|
+
import { guardPaths } from './guards-paths';
|
|
8
|
+
import { shippedGuardCode } from './guards-shipped-names';
|
|
9
|
+
|
|
10
|
+
/** The package a built-in's code is declared by: the CLI that ships and runs it. */
|
|
11
|
+
export const BUILT_IN_GUARD_PACKAGE = '@ultimat3/cli';
|
|
12
|
+
|
|
13
|
+
const byCode = (a: ErrorCodeFact, b: ErrorCodeFact): number => a.code.localeCompare(b.code);
|
|
14
|
+
|
|
15
|
+
/** Every built-in guard this app runs — any mode but `"off"`, never one it holds a copy of. */
|
|
16
|
+
export async function builtInGuardCodes(root: string): Promise<readonly ErrorCodeFact[]> {
|
|
17
|
+
const { builtIn } = planBuiltIns(
|
|
18
|
+
await guardPaths(root),
|
|
19
|
+
(await readShippedConfig(root)).severity,
|
|
20
|
+
);
|
|
21
|
+
return builtIn
|
|
22
|
+
.map(({ name }) => ({
|
|
23
|
+
code: shippedGuardCode(name),
|
|
24
|
+
package: BUILT_IN_GUARD_PACKAGE,
|
|
25
|
+
}))
|
|
26
|
+
.sort(byCode);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The app's own declarations win a code both name; the built-ins fill the rest, sorted by code. */
|
|
30
|
+
export const withBuiltInGuardCodes = (
|
|
31
|
+
app: readonly ErrorCodeFact[],
|
|
32
|
+
builtIn: readonly ErrorCodeFact[],
|
|
33
|
+
): readonly ErrorCodeFact[] => {
|
|
34
|
+
const declared = new Set(app.map(({ code }) => code));
|
|
35
|
+
return [...app, ...builtIn.filter(({ code }) => !declared.has(code))].sort(byCode);
|
|
36
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// `x g guard <shipped name>` refused: installing the framework is the one way to get a shipped
|
|
2
|
+
// guard (axiom 1), so writing a copy is a second path — and a copy runs in place of the installed
|
|
3
|
+
// guard, never receiving a fix. The refusal names the row that changes how it reports instead.
|
|
4
|
+
|
|
5
|
+
import { UltimateError } from '@ultimat3/core';
|
|
6
|
+
import { SHIPPED_GUARD_CONFIG } from './guards-built-in';
|
|
7
|
+
import { SHIPPED_GUARD_NAMES } from './templates/scaffold-guards';
|
|
8
|
+
|
|
9
|
+
/** A string here until the coordinator registers it in `error-codes.ts`. */
|
|
10
|
+
export const GUARD_BUILT_IN_CODE = 'X_GUARD_BUILT_IN';
|
|
11
|
+
|
|
12
|
+
export class GuardBuiltInError extends UltimateError {
|
|
13
|
+
constructor(name: string) {
|
|
14
|
+
super({
|
|
15
|
+
code: GUARD_BUILT_IN_CODE,
|
|
16
|
+
cause: `${name} is a guard the framework ships, and it already runs on x verify's boundaries step from the installed version — a copy in guards/ would run in its place and never receive a fix`,
|
|
17
|
+
fix: `x verify --only boundaries --json # ${name} already runs: set "${name}": "error", "warning" or "off" in ${SHIPPED_GUARD_CONFIG}, or x g guard app-${name} for a rule of your own`,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Throws for a shipped name (already kebab-cased, as the generator reads it); any other is the app's. */
|
|
23
|
+
export function refuseShippedGuardName(name: string): void {
|
|
24
|
+
if (SHIPPED_GUARD_NAMES.includes(name)) throw new GuardBuiltInError(name);
|
|
25
|
+
}
|