@ultimat3/cli 31.15.0 → 31.16.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 CHANGED
@@ -21,7 +21,7 @@ Commands and the `x verify` step count, `As of 2026-08`:
21
21
  | `x build --target docker\|binary\|static` | one artifact | `ROLE` selects behaviour at start |
22
22
  | `x build --target prebuilt` | the store a container boots from: island chunks, compiled stylesheets | a `RUN` line in the image build, never run by hand |
23
23
  | `x verify` | **the gate** | 21 named steps, each with pass/fail + duration; `budgets` runs `x build --target static` first when its stats are missing or older than the source |
24
- | `x exercise [<name>] [--seed n]` | every action, query and job run once on generated rows, no test written | a scratch database; `.x/exercise.json`; an `unreached` primitive is `X_CONTRACT_EXERCISE_UNREACHED` with the override to paste into `apps/web/exercise.ts` — the gate's `exercise` step |
24
+ | `x exercise [<name>] [--seed n]` | every action, query and job run once on generated rows, no test written | a scratch database; `.x/exercise.json`; an `unreached` primitive is `X_CONTRACT_EXERCISE_UNREACHED` with the override to paste into `apps/web/exercise.ts` — the gate's `exercise` step. `x.verify.json` `exercise: { unprovenMax, statementsMax }` turns unproven proofs and over-ceiling calls red; absent, warning lines |
25
25
  | `x drill [<name>] [--list] [--budget-ms n]` | the app's roles as real processes on real services, each fault played through a proxy or a signal, judged on framework contracts only | a scratch database per drill; load = anonymous site pages plus every action an anonymous POST reaches (`data.skippedWrites` names the rest and why); `X_DRILL_FAILED` per property that did not hold, `X_DRILL_SERVICE_MISSING` before anything starts. Not a gate step — CI's `fault-drills` job runs three on `examples/dummy` |
26
26
  | `x g <primitive> <name>` | scaffolds a primitive **with a passing test** | never a TODO stub |
27
27
  | `x db gen\|migrate\|reset\|branch\|backfill` | everything DB | `branch` = copy-on-write clone + preview URL; `backfill` dry-runs unless `--write`. `x db studio` is **planned** — it parses, and exits `X_NOT_IMPLEMENTED` naming `/_x`'s db panel |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/cli",
3
- "version": "31.15.0",
3
+ "version": "31.16.0",
4
4
  "description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -53,34 +53,34 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@babel/core": "^8.0.9",
56
- "@ultimat3/action": "31.15.0",
57
- "@ultimat3/admin": "31.15.0",
58
- "@ultimat3/ai": "31.15.0",
59
- "@ultimat3/auth": "31.15.0",
60
- "@ultimat3/cache": "31.15.0",
61
- "@ultimat3/core": "31.15.0",
62
- "@ultimat3/db": "31.15.0",
63
- "@ultimat3/entity": "31.15.0",
64
- "@ultimat3/flags": "31.15.0",
65
- "@ultimat3/http": "31.15.0",
66
- "@ultimat3/i18n": "31.15.0",
67
- "@ultimat3/jobs": "31.15.0",
68
- "@ultimat3/mail": "31.15.0",
69
- "@ultimat3/manifest": "31.15.0",
70
- "@ultimat3/mcp": "31.15.0",
71
- "@ultimat3/money": "31.15.0",
72
- "@ultimat3/notify": "31.15.0",
73
- "@ultimat3/policy": "31.15.0",
74
- "@ultimat3/pwa": "31.15.0",
75
- "@ultimat3/query": "31.15.0",
76
- "@ultimat3/realtime": "31.15.0",
77
- "@ultimat3/render": "31.15.0",
78
- "@ultimat3/schema": "31.15.0",
79
- "@ultimat3/scraping": "31.15.0",
80
- "@ultimat3/seo": "31.15.0",
81
- "@ultimat3/storage": "31.15.0",
82
- "@ultimat3/testing": "31.15.0",
83
- "@ultimat3/time": "31.15.0",
56
+ "@ultimat3/action": "31.16.0",
57
+ "@ultimat3/admin": "31.16.0",
58
+ "@ultimat3/ai": "31.16.0",
59
+ "@ultimat3/auth": "31.16.0",
60
+ "@ultimat3/cache": "31.16.0",
61
+ "@ultimat3/core": "31.16.0",
62
+ "@ultimat3/db": "31.16.0",
63
+ "@ultimat3/entity": "31.16.0",
64
+ "@ultimat3/flags": "31.16.0",
65
+ "@ultimat3/http": "31.16.0",
66
+ "@ultimat3/i18n": "31.16.0",
67
+ "@ultimat3/jobs": "31.16.0",
68
+ "@ultimat3/mail": "31.16.0",
69
+ "@ultimat3/manifest": "31.16.0",
70
+ "@ultimat3/mcp": "31.16.0",
71
+ "@ultimat3/money": "31.16.0",
72
+ "@ultimat3/notify": "31.16.0",
73
+ "@ultimat3/policy": "31.16.0",
74
+ "@ultimat3/pwa": "31.16.0",
75
+ "@ultimat3/query": "31.16.0",
76
+ "@ultimat3/realtime": "31.16.0",
77
+ "@ultimat3/render": "31.16.0",
78
+ "@ultimat3/schema": "31.16.0",
79
+ "@ultimat3/scraping": "31.16.0",
80
+ "@ultimat3/seo": "31.16.0",
81
+ "@ultimat3/storage": "31.16.0",
82
+ "@ultimat3/testing": "31.16.0",
83
+ "@ultimat3/time": "31.16.0",
84
84
  "babel-preset-solid": "^1.9.16"
85
85
  }
86
86
  }
package/src/cmd-doctor.ts CHANGED
@@ -20,6 +20,7 @@ import { probeFor } from './doctor-probe';
20
20
  import { rollingSinceProbe, withRollingReminder } from './doctor-rolling';
21
21
  import { sealedKeyFindings } from './doctor-sealed';
22
22
  import { typescriptFindings } from './doctor-typescript';
23
+ import { doctorWarnings, withDoctorWarnings } from './doctor-warnings';
23
24
  import { ICON_SOURCE } from './icon-assets';
24
25
  import { msg } from './messages';
25
26
  import type { CommandResult, Finding } from './output';
@@ -131,48 +132,57 @@ export async function runDoctor(probe: DoctorProbe): Promise<readonly Finding[]>
131
132
  // Sealed columns against the key ring: no key at all, or a rotation whose re-seal is pending.
132
133
  findings.push(...sealedKeyFindings(await probe.sealedKeys()));
133
134
  findings.push(...authStorageFindings(await probe.authStorage()));
135
+ // `X_FRAMEWORK_PIN_RANGE`, `X_ENV_NAME_RESERVED`, `X_DB_ROW_SECURITY_OFF` and
136
+ // `X_VERIFY_STEP_UNFLOORED` are not here: on `main` they warn beside the verdict
137
+ // (`doctor-warnings.ts`), so an upgrade with no change keeps this green.
134
138
  return findings;
135
139
  }
136
140
 
141
+ /** The whole report over one probe: the verdict, then the listings and warnings beside it. */
142
+ export async function reportDoctor(probe: DoctorProbe): Promise<CommandResult> {
143
+ // Asked once: `runDoctor` reads the verdict and the report beside it reads the numbers.
144
+ const pooler = probe.root === undefined ? NO_POOLER_FACT : await probe.pooler();
145
+ const findings = await runDoctor({ ...probe, pooler: async () => pooler });
146
+ const listed = withGuardListing(
147
+ {
148
+ ok: findings.length === 0,
149
+ command: 'doctor',
150
+ summary:
151
+ findings.length === 0
152
+ ? msg('cli.doctor.clean')
153
+ : msg('cli.doctor.findings', { count: findings.length }),
154
+ findings,
155
+ data: { count: findings.length, codes: findings.map((entry) => entry.code) },
156
+ },
157
+ // A listing beside the verdict, never part of it (`doctor-guards.ts` says why).
158
+ probe.root === undefined ? [] : await shippedGuardsProbe(probe.root),
159
+ );
160
+ // The second listing: what the coverage floor does not see (`doctor-coverage.ts`).
161
+ const covered = withCoverageExcludes(
162
+ listed,
163
+ probe.root === undefined ? [] : await coverageExcludesProbe(probe.root),
164
+ );
165
+ // The third: the monitoring templates the app's chart predates (`doctor-chart-alerts.ts`).
166
+ const charted = withChartAlertsListing(
167
+ covered,
168
+ probe.root === undefined ? [] : chartAlertsProbe(probe.root),
169
+ );
170
+ // A reminder, not a finding: the rolling rail is off until this is set (`doctor-rolling.ts`).
171
+ const reminded = withPoolerReport(
172
+ withRollingReminder(
173
+ charted,
174
+ probe.root === undefined ? undefined : await rollingSinceProbe(probe.root),
175
+ ),
176
+ pooler,
177
+ );
178
+ // Last, and beside the verdict on `main`: the 31.16.0 checks (`doctor-warnings.ts`).
179
+ return withDoctorWarnings(reminded, await doctorWarnings(probe));
180
+ }
181
+
137
182
  export const doctorCommand: CliCommand = {
138
183
  spec: doctorSpec,
139
- async run(ctx: CommandContext): Promise<CommandResult> {
184
+ run(ctx: CommandContext): Promise<CommandResult> {
140
185
  const port = doctorPort(ctx.args, ctx.env);
141
- const probe = probeFor(ctx.cwd, ctx.bunVersion, port, ctx.env);
142
- // Asked once: `runDoctor` reads the verdict and the report beside it reads the numbers.
143
- const pooler = probe.root === undefined ? NO_POOLER_FACT : await probe.pooler();
144
- const findings = await runDoctor({ ...probe, pooler: async () => pooler });
145
- const listed = withGuardListing(
146
- {
147
- ok: findings.length === 0,
148
- command: 'doctor',
149
- summary:
150
- findings.length === 0
151
- ? msg('cli.doctor.clean')
152
- : msg('cli.doctor.findings', { count: findings.length }),
153
- findings,
154
- data: { count: findings.length, codes: findings.map((entry) => entry.code) },
155
- },
156
- // A listing beside the verdict, never part of it (`doctor-guards.ts` says why).
157
- probe.root === undefined ? [] : await shippedGuardsProbe(probe.root),
158
- );
159
- // The second listing: what the coverage floor does not see (`doctor-coverage.ts`).
160
- const covered = withCoverageExcludes(
161
- listed,
162
- probe.root === undefined ? [] : await coverageExcludesProbe(probe.root),
163
- );
164
- // The third: the monitoring templates the app's chart predates (`doctor-chart-alerts.ts`).
165
- const charted = withChartAlertsListing(
166
- covered,
167
- probe.root === undefined ? [] : chartAlertsProbe(probe.root),
168
- );
169
- // A reminder, not a finding: the rolling rail is off until this is set (`doctor-rolling.ts`).
170
- return withPoolerReport(
171
- withRollingReminder(
172
- charted,
173
- probe.root === undefined ? undefined : await rollingSinceProbe(probe.root),
174
- ),
175
- pooler,
176
- );
186
+ return reportDoctor(probeFor(ctx.cwd, ctx.bunVersion, port, ctx.env));
177
187
  },
178
188
  };
@@ -31,6 +31,7 @@ import {
31
31
  renderExerciseTable,
32
32
  slowestProofLines,
33
33
  } from './exercise-findings';
34
+ import { exerciseFloorVerdict } from './exercise-floor-verdict';
34
35
  import { readExerciseOverrides } from './exercise-overrides';
35
36
  import { entityTenantFindings } from './exercise-static';
36
37
  import { subjectFindings, subjectProofFindings } from './exercise-subject';
@@ -38,6 +39,7 @@ import { readIntFlag } from './flag-number';
38
39
  import { msg } from './messages';
39
40
  import { withOfflinePorts } from './offline-ports';
40
41
  import type { CommandResult, JsonValue } from './output';
42
+ import { readVerifyFloor } from './verify-floor';
41
43
 
42
44
  /**
43
45
  * The actors `x policy explain` evaluates — `devActors()`, the `/_x` panel's own set — each a
@@ -122,6 +124,12 @@ async function exercisePass(
122
124
  // The whole pass, not a one-primitive run's slice of it, is what the file is for — but a
123
125
  // one-primitive run is still a fact worth keeping, so it is written either way.
124
126
  await Bun.write(join(root, EXERCISE_REPORT_FILE), `${JSON.stringify(report, null, 2)}\n`);
127
+ // `x.verify.json`'s `exercise` key: red where the app opted in, a warning line where it has not.
128
+ // A whole-pass floor, so never judged on a `<name>` run's slice: 1 of 1 unproven is no ratio.
129
+ const floor =
130
+ only === undefined
131
+ ? exerciseFloorVerdict(records, (await readVerifyFloor(root))?.exercise)
132
+ : { findings: [], warnings: [] };
125
133
  const findings = [
126
134
  ...loaded.findings,
127
135
  // The static half of the tenant proof (`exercise-static.ts`): the pass's own question,
@@ -131,6 +139,7 @@ async function exercisePass(
131
139
  ...subjectProofs,
132
140
  // The fix pastes into the file the app has, or hands it the file it lacks.
133
141
  ...exerciseFindings(records, overrides === undefined ? 'absent' : 'present'),
142
+ ...floor.findings,
134
143
  ];
135
144
  return {
136
145
  ok: findings.length === 0,
@@ -146,8 +155,12 @@ async function exercisePass(
146
155
  ...tenantFindingLines(records),
147
156
  ...crashFindingLines(records),
148
157
  ...planSweepLines(records),
158
+ ...floor.warnings.map((warning) => `! ${warning}`),
149
159
  ].map((line) => ` ${line}`),
150
160
  findings,
151
- data: report as unknown as JsonValue,
161
+ // The warning lines ride in `--json` too (`lines` never holds what the document lacks).
162
+ data: (floor.warnings.length === 0
163
+ ? report
164
+ : { ...report, warnings: floor.warnings }) as unknown as JsonValue,
152
165
  };
153
166
  }
@@ -146,7 +146,14 @@ async function withHeartbeat<T>(
146
146
  }
147
147
  }
148
148
 
149
- export const createUpgradeCommand = (write: (line: string) => void): CliCommand => ({
149
+ /** `YYYY-MM-DD` in UTC: the day a rebaselined floor's `why` names. */
150
+ const utcDay = (at: Date): string => at.toISOString().slice(0, 10);
151
+
152
+ export const createUpgradeCommand = (
153
+ write: (line: string) => void,
154
+ /** The clock a rebaselined coverage floor is dated by; a test pins it. */
155
+ now: () => Date = () => new Date(),
156
+ ): CliCommand => ({
150
157
  spec: upgradeSpec,
151
158
  async run(ctx: CommandContext): Promise<CommandResult> {
152
159
  const { dir: root, app } = await findUpgradeRoot(ctx.cwd);
@@ -261,7 +268,17 @@ export const createUpgradeCommand = (write: (line: string) => void): CliCommand
261
268
  });
262
269
  return { gate: undefined, scripts: ran };
263
270
  }
264
- const hopGate = await runHopGate({ runner: ctx.runner, root, onStage: stageReached });
271
+ // Bun 1.4.4 counted functions differently: a hop that moves the floor re-measures coverage.
272
+ const bunMoved =
273
+ bunRange === undefined || bunRange === bunFrom
274
+ ? undefined
275
+ : { release: hop.to, bunFrom, bunTo: bunRange, today: utcDay(now()) };
276
+ const hopGate = await runHopGate({
277
+ runner: ctx.runner,
278
+ root,
279
+ onStage: stageReached,
280
+ ...(bunMoved === undefined ? {} : { bunMoved }),
281
+ });
265
282
  return { gate: hopGate, scripts: [] };
266
283
  });
267
284
 
@@ -188,14 +188,14 @@ export async function measureCoverage(
188
188
  }
189
189
 
190
190
  /** One decimal, rounded DOWN: a printed number never claims more than was measured. */
191
- const shown = (value: number): string => (Math.floor(value * 10) / 10).toFixed(1);
191
+ export const shown = (value: number): string => (Math.floor(value * 10) / 10).toFixed(1);
192
192
 
193
193
  /**
194
194
  * The floor a measured number supports: the bar once it clears it, the whole number under it
195
195
  * below — up to a point of room, so one uncovered line in an unrelated file is not a red gate,
196
196
  * and less than `FLOOR_SLACK`, so the floor it writes is never stale the moment it is written.
197
197
  */
198
- const floorFor = (measured: number): number =>
198
+ export const floorFor = (measured: number): number =>
199
199
  measured >= COVERAGE_BAR ? COVERAGE_BAR : Math.floor(measured);
200
200
 
201
201
  const WHY_PLACEHOLDER = '<what is uncovered and who closes it>';
@@ -0,0 +1,111 @@
1
+ // `x doctor`'s env-name check: an app's own variable — declared in `envSchema` or sealed in the
2
+ // secrets file — on a name the framework reads as a switch or for itself (`FRAMEWORK_ENV`). An
3
+ // adapter's settings (`S3_BUCKET`, `SMTP_URL`) are the contract: declaring them is the configuring.
4
+
5
+ // why: Bun exposes no path-join primitive; Bun.file takes one already joined.
6
+ import { join } from 'node:path';
7
+ import type { FrameworkEnvName } from '@ultimat3/core';
8
+ import {
9
+ APP_CONFIG_FILE,
10
+ ERROR_DOCS_URL,
11
+ findMasterKey,
12
+ frameworkEnvEntry,
13
+ readSecretsFile,
14
+ secretsFileExists,
15
+ } from '@ultimat3/core';
16
+ import { ENV_SCHEMA_EXPORT, loadEnvSchema } from './app-env';
17
+ import type { Finding } from './output';
18
+
19
+ /** Where the app names its variables: what it declared, and what it sealed. */
20
+ export interface AppEnvNamesFact {
21
+ readonly declared: readonly string[];
22
+ /** The 1-based line of each declared key in `app.config.ts`, where the probe found one. */
23
+ readonly lines?: ReadonlyMap<string, number>;
24
+ /** Names in `secrets.enc.json`; empty when this machine has no key to open it with. */
25
+ readonly sealed: readonly string[];
26
+ }
27
+
28
+ export const NO_APP_ENV_NAMES: AppEnvNamesFact = Object.freeze({ declared: [], sealed: [] });
29
+
30
+ export const ENV_NAME_RESERVED = 'X_ENV_NAME_RESERVED';
31
+
32
+ /** The prefix a renamed key takes: no framework entry starts with it. */
33
+ export const APP_ENV_PREFIX = 'APP_';
34
+
35
+ /**
36
+ * A collision is a name the framework reads as a `switch` (its presence turns a behaviour on) or
37
+ * `internal` (the framework sets it, or a harness does). The deploy contract (`DATABASE_URL`,
38
+ * `PORT`) is what an app is meant to declare, and a `host` name is the platform's.
39
+ */
40
+ const collides = (name: string): FrameworkEnvName | undefined => {
41
+ const entry = frameworkEnvEntry(name);
42
+ return entry !== undefined && (entry.use === 'switch' || entry.use === 'internal')
43
+ ? entry
44
+ : undefined;
45
+ };
46
+
47
+ const what = (name: string, entry: FrameworkEnvName): string =>
48
+ entry.use === 'switch'
49
+ ? `@ultimat3/${entry.owner} also reads ${name}: set, it switches that package's behaviour on with this value`
50
+ : `${entry.prefix === true ? `every ${entry.name}* name` : name} is @ultimat3/${entry.owner}'s own, set by the framework or its harness`;
51
+
52
+ /** The rule, pure. One finding per name, a sealed name and a declared one apart. */
53
+ export function reservedEnvFindings(fact: AppEnvNamesFact): readonly Finding[] {
54
+ const findings: Finding[] = [];
55
+ for (const name of [...new Set(fact.declared)].sort()) {
56
+ const entry = collides(name);
57
+ if (entry === undefined) continue;
58
+ findings.push({
59
+ code: ENV_NAME_RESERVED,
60
+ cause: `${ENV_SCHEMA_EXPORT} in ${APP_CONFIG_FILE} declares ${name}, and ${what(name, entry)}`,
61
+ // A rename, never an allow: a name meant for the framework needs no app declaration at all.
62
+ fix: `edit ${APP_CONFIG_FILE}:${fact.lines?.get(name) ?? 1} — rename ${name} in ${ENV_SCHEMA_EXPORT} to ${APP_ENV_PREFIX}${name} (or delete it where the value is meant for @ultimat3/${entry.owner}); then: x env example --json && x doctor --json`,
63
+ docs: ERROR_DOCS_URL,
64
+ at: APP_CONFIG_FILE,
65
+ });
66
+ }
67
+ for (const name of [...new Set(fact.sealed)].sort()) {
68
+ const entry = collides(name);
69
+ if (entry === undefined) continue;
70
+ findings.push({
71
+ code: ENV_NAME_RESERVED,
72
+ cause: `secrets.enc.json seals ${name}, and ${what(name, entry)}`,
73
+ fix: `x secrets edit # rename ${name} to ${APP_ENV_PREFIX}${name} unless the value is meant for @ultimat3/${entry.owner}; then: x doctor --json`,
74
+ docs: ERROR_DOCS_URL,
75
+ at: 'secrets.enc.json',
76
+ });
77
+ }
78
+ return findings;
79
+ }
80
+
81
+ /**
82
+ * The I/O half. A config that will not import, or a secrets file this key cannot open, is another
83
+ * probe's finding (`snapshots`, `sealedKeys`); here it is simply nothing to judge.
84
+ */
85
+ export async function appEnvNamesProbe(
86
+ root: string,
87
+ env: Readonly<Record<string, string | undefined>>,
88
+ ): Promise<AppEnvNamesFact> {
89
+ const declared = await loadEnvSchema(root).then(
90
+ (schema) => Object.keys(schema ?? {}),
91
+ () => [],
92
+ );
93
+ const config = await Bun.file(join(root, APP_CONFIG_FILE))
94
+ .text()
95
+ .catch(() => '');
96
+ const lines = new Map<string, number>();
97
+ // A key that is not a plain identifier is never a framework name, and never a regex here.
98
+ for (const name of declared.filter((key) => /^[A-Za-z_]\w*$/.test(key))) {
99
+ const at = config.search(new RegExp(`^\\s*['"]?${name}['"]?\\s*:`, 'm'));
100
+ if (at >= 0) lines.set(name, config.slice(0, at).split('\n').length);
101
+ }
102
+ const key = findMasterKey(root, { ...env });
103
+ const sealed =
104
+ key === undefined || !secretsFileExists(root)
105
+ ? []
106
+ : await readSecretsFile(root, key).then(
107
+ (values) => Object.keys(values),
108
+ () => [],
109
+ );
110
+ return { declared, lines, sealed };
111
+ }
@@ -0,0 +1,62 @@
1
+ // `x doctor`'s floor check: a gate step that applies to this app — its suite files exist, its
2
+ // input is committed — and that `x.verify.json`'s `steps` does not hold. Unfloored, deleting the
3
+ // suite turns the step from green into skipped-and-green; floored, it is `X_VERIFY_SUITE_VANISHED`.
4
+
5
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
6
+ import type { Runner } from './exec';
7
+ import type { Finding } from './output';
8
+ import { quoteArg } from './shell-quote';
9
+ import { VERIFY_STEPS } from './verify-checks';
10
+ import { floorRequires, readVerifyFloor, VERIFY_FLOOR_FILE } from './verify-floor';
11
+ import type { VerifyStep, VerifyStepName } from './verify-step';
12
+
13
+ export const STEP_UNFLOORED = 'X_VERIFY_STEP_UNFLOORED';
14
+
15
+ /**
16
+ * Never proposed. `x new` writes `e2e` as an `e2eTest` that skips until the app registers a
17
+ * browser driver, so its file exists while the step runs nothing: flooring it reds a fresh app's
18
+ * gate on the scaffold's own placeholder (`scaffold-verify-floor.ts`). The gate's summary already
19
+ * names it as skipped; the floor is the app's call once a driver makes it run.
20
+ */
21
+ const NEVER_PROPOSED: ReadonlySet<VerifyStepName> = new Set<VerifyStepName>(['e2e']);
22
+
23
+ /** `applies` reads the disk alone: a step that spawned here would be asking the wrong question. */
24
+ const noRunner: Runner = async (command) => ({
25
+ command,
26
+ code: 1,
27
+ ok: false,
28
+ stdout: '',
29
+ stderr: '',
30
+ durationMs: 0,
31
+ });
32
+
33
+ /** The I/O half: each step with an `applies`, asked of this root, that the floor does not hold. */
34
+ export async function unflooredStepsProbe(
35
+ root: string,
36
+ steps: readonly VerifyStep[] = VERIFY_STEPS,
37
+ ): Promise<readonly VerifyStepName[]> {
38
+ const floor = await readVerifyFloor(root);
39
+ const unfloored: VerifyStepName[] = [];
40
+ for (const step of steps) {
41
+ if (step.applies === undefined || NEVER_PROPOSED.has(step.name)) continue;
42
+ if (floorRequires(floor, step.name)) continue;
43
+ const applies = await step.applies({ root, runner: noRunner }).catch(() => false);
44
+ if (applies) unfloored.push(step.name);
45
+ }
46
+ return unfloored;
47
+ }
48
+
49
+ /** The rule, pure: one finding naming every unfloored step, run-first, so the edit is proven. */
50
+ export function unflooredStepFindings(steps: readonly VerifyStepName[]): readonly Finding[] {
51
+ if (steps.length === 0) return [];
52
+ return [
53
+ {
54
+ code: STEP_UNFLOORED,
55
+ cause: `${steps.join(', ')} ${steps.length === 1 ? 'applies' : 'apply'} to this app and ${VERIFY_FLOOR_FILE} "steps" does not hold ${steps.length === 1 ? 'it' : 'them'}, so a deleted suite reads as skipped and the gate stays green`,
56
+ // Run first: a step that skips here would red the gate the moment the floor names it.
57
+ fix: `x verify --only ${quoteArg(steps.join(','))} --json # then add each step that passed, not skipped, to "steps" in ${VERIFY_FLOOR_FILE}`,
58
+ docs: ERROR_DOCS_URL,
59
+ at: VERIFY_FLOOR_FILE,
60
+ },
61
+ ];
62
+ }
@@ -0,0 +1,101 @@
1
+ // `x doctor`'s pin check: an `@ultimat3/*` dependency written as a range (`^31.0.0`, `latest`) in
2
+ // any of the app's manifests. The framework moves in lockstep and `x new` pins exactly; a range is a
3
+ // silent upgrade on the next install, and two of them drift into the mixed set `x upgrade` refuses.
4
+
5
+ // why: Bun exposes no path-join primitive; Bun.file takes one already joined.
6
+ import { join } from 'node:path';
7
+ import { ERROR_DOCS_URL } from '@ultimat3/core';
8
+ import { t } from '@ultimat3/schema';
9
+ import type { Finding } from './output';
10
+ import { readManifests, readPins } from './upgrade-pins';
11
+ import { pinVersion, type UpgradePin } from './upgrade-plan';
12
+
13
+ export const PIN_RANGE = 'X_FRAMEWORK_PIN_RANGE';
14
+
15
+ /** What an installed package's manifest must say to name the version `bun install` resolved. */
16
+ const INSTALLED = t.object({ version: t.string });
17
+
18
+ /** An exact release, or a prerelease of one: what `x new` and `x upgrade` write. */
19
+ const EXACT = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
20
+
21
+ /** `workspace:*`, `file:` and `link:` name a directory, never a version: nothing to move. */
22
+ const LOCAL = /^(?:workspace|file|link):/;
23
+
24
+ /** `npm:@ultimat3/core@^31.0.0` → its alias prefix and the spec it pins, the part after the last @. */
25
+ const aliasOf = (spec: string): { readonly prefix: string; readonly version: string } => {
26
+ const trimmed = spec.trim();
27
+ if (!trimmed.startsWith('npm:')) return { prefix: '', version: trimmed };
28
+ const at = trimmed.lastIndexOf('@');
29
+ return at <= 'npm:'.length
30
+ ? { prefix: trimmed, version: '' }
31
+ : { prefix: trimmed.slice(0, at + 1), version: trimmed.slice(at + 1) };
32
+ };
33
+
34
+ /**
35
+ * Everything but an exact version or a local link moves on the next install: `^`/`~`, `*`, `x`,
36
+ * a dist-tag (`latest`), a comparator pair (`>=31 <32`), a hyphen range — and an `npm:` alias is
37
+ * judged on the spec it carries.
38
+ */
39
+ const isRange = (spec: string): boolean =>
40
+ !LOCAL.test(spec.trim()) && !EXACT.test(aliasOf(spec).version);
41
+
42
+ /** The value the fix writes: the installed version, else the range's floor, alias kept. */
43
+ const exactFor = (pin: UpgradePin, installed: ReadonlyMap<string, string>): string => {
44
+ const { prefix, version } = aliasOf(pin.spec);
45
+ const exact = installed.get(pin.name) ?? pinVersion(version);
46
+ return exact === undefined
47
+ ? `<the exact version: npm view ${pin.name} version>`
48
+ : `${prefix}${exact}`;
49
+ };
50
+
51
+ export interface PinFact {
52
+ readonly pins: readonly UpgradePin[];
53
+ /** The version `bun install` resolved, per package name — what the exact pin should say. */
54
+ readonly installed: ReadonlyMap<string, string>;
55
+ /** The 1-based line of each pin, keyed `file` then `name`, where the probe read the text. */
56
+ readonly lines?: ReadonlyMap<string, ReadonlyMap<string, number>>;
57
+ }
58
+
59
+ /** The rule, pure: one finding per manifest, naming every ranged pin in it and its exact value. */
60
+ export function pinRangeFindings(fact: PinFact): readonly Finding[] {
61
+ const byFile = new Map<string, UpgradePin[]>();
62
+ for (const pin of fact.pins.filter((one) => isRange(one.spec))) {
63
+ byFile.set(pin.file, [...(byFile.get(pin.file) ?? []), pin]);
64
+ }
65
+ return [...byFile].map(([file, pins]) => {
66
+ const exact = pins.map((pin) => `"${pin.name}": "${exactFor(pin, fact.installed)}"`);
67
+ const line = fact.lines?.get(file)?.get(pins[0]?.name ?? '') ?? 1;
68
+ return {
69
+ code: PIN_RANGE,
70
+ cause: `${file} pins ${pins.map((pin) => `${pin.name} ${pin.spec}`).join(', ')} as a range; the framework releases in lockstep, so the next install may move one package without the rest`,
71
+ fix: `edit ${file}:${line} — write ${exact.join(', ')}; then: bun install && x doctor --json`,
72
+ docs: ERROR_DOCS_URL,
73
+ at: file,
74
+ };
75
+ });
76
+ }
77
+
78
+ /** The I/O half. A manifest that will not parse is `x upgrade`'s refusal; here it is nothing. */
79
+ export async function pinProbe(root: string): Promise<PinFact> {
80
+ const manifests = await readManifests(root).catch(() => []);
81
+ const pins = readPins(manifests);
82
+ const lines = new Map<string, Map<string, number>>();
83
+ for (const { file, text } of manifests) {
84
+ const byName = new Map<string, number>();
85
+ text.split('\n').forEach((row, index) => {
86
+ const name = /"(@ultimat3\/[a-z0-9-]+)"\s*:/.exec(row)?.[1];
87
+ if (name !== undefined && !byName.has(name)) byName.set(name, index + 1);
88
+ });
89
+ lines.set(file, byName);
90
+ }
91
+ const installed = new Map<string, string>();
92
+ for (const name of new Set(pins.map((pin) => pin.name))) {
93
+ const manifest: unknown = await Bun.file(join(root, 'node_modules', name, 'package.json'))
94
+ .json()
95
+ .catch(() => undefined);
96
+ const parsed = INSTALLED.safeParse(manifest);
97
+ if (parsed.issues === undefined)
98
+ installed.set(name, (parsed.value as { version: string }).version);
99
+ }
100
+ return { pins, installed, lines };
101
+ }
@@ -12,11 +12,17 @@ import { checkMigrationSnapshots } from './db-snapshot';
12
12
  import { type AuthStorageFact, authStorageProbe } from './doctor-auth';
13
13
  import type { EmbeddedDatabase } from './doctor-database';
14
14
  import { externalUrl, installedAbove, probeDatabase } from './doctor-database';
15
+ import type { AppEnvNamesFact } from './doctor-env-reserved';
16
+ import { appEnvNamesProbe, NO_APP_ENV_NAMES } from './doctor-env-reserved';
17
+ import { unflooredStepsProbe } from './doctor-floor';
15
18
  import type { OfflineFallbackFact } from './doctor-offline';
16
19
  import { offlineFallbackProbe } from './doctor-offline';
20
+ import type { PinFact } from './doctor-pins';
21
+ import { pinProbe } from './doctor-pins';
17
22
  import type { PoolerFact } from './doctor-pooler';
18
23
  import { poolerProbe } from './doctor-pooler';
19
- import { rowSecurityProbe } from './doctor-row-security';
24
+ import type { RowSecurityOffFact } from './doctor-row-security';
25
+ import { rowSecurityOffProbe, rowSecurityProbe } from './doctor-row-security';
20
26
  import type { SealedKeysFact } from './doctor-sealed';
21
27
  import { sealedKeysProbe } from './doctor-sealed';
22
28
  import { typescriptProbe } from './doctor-typescript';
@@ -25,6 +31,7 @@ import type { Finding } from './output';
25
31
  import { portFree } from './port-probe';
26
32
  import { checkMigrationDrift } from './schema-drift';
27
33
  import type { TypescriptLag } from './typescript-floor';
34
+ import type { VerifyStepName } from './verify-step';
28
35
 
29
36
  /**
30
37
  * The injection seam `runDoctor` reads instead of the environment. Not a semver surface —
@@ -98,6 +105,14 @@ export interface DoctorProbe {
98
105
  typescript(): Promise<readonly TypescriptLag[]>;
99
106
  /** With `database.rowSecurity` on, whether the serving role is exempt (`doctor-row-security.ts`). */
100
107
  rowSecurity?(): Promise<readonly Finding[]>;
108
+ /** With it off, the raw `sql` statements that name a tenant table (`doctor-row-security.ts`). */
109
+ rowSecurityOff(): Promise<RowSecurityOffFact>;
110
+ /** The app's own env names, declared and sealed (`doctor-env-reserved.ts`). */
111
+ envNames(): Promise<AppEnvNamesFact>;
112
+ /** Every `@ultimat3/*` pin and the version installed for it (`doctor-pins.ts`). */
113
+ pins(): Promise<PinFact>;
114
+ /** The gate steps that apply here and `x.verify.json` does not floor (`doctor-floor.ts`). */
115
+ unflooredSteps(): Promise<readonly VerifyStepName[]>;
101
116
  }
102
117
 
103
118
  export function probeFor(
@@ -140,6 +155,11 @@ export function probeFor(
140
155
  typescript: async () => (root === undefined ? [] : typescriptProbe(root)),
141
156
  rowSecurity: async () =>
142
157
  root === undefined ? [] : rowSecurityProbe(root, process.env['DATABASE_URL'], env),
158
+ rowSecurityOff: async () =>
159
+ root === undefined ? { declared: false, touches: [] } : rowSecurityOffProbe(root),
160
+ envNames: async () => (root === undefined ? NO_APP_ENV_NAMES : appEnvNamesProbe(root, env)),
161
+ pins: async () => (root === undefined ? { pins: [], installed: new Map() } : pinProbe(root)),
162
+ unflooredSteps: async () => (root === undefined ? [] : unflooredStepsProbe(root)),
143
163
  };
144
164
  }
145
165