@ultimat3/cli 31.47.1 → 31.49.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 +30 -23
- package/README.md +96 -4
- package/package.json +29 -29
- package/src/api-registration.ts +28 -14
- package/src/app-load.ts +6 -1
- package/src/app-root.ts +7 -1
- package/src/clean-services.ts +142 -0
- package/src/cmd-auth.ts +3 -0
- package/src/cmd-clean-spec.ts +10 -3
- package/src/cmd-clean.ts +23 -9
- package/src/cmd-db-backfill.ts +6 -0
- package/src/cmd-db-branch.ts +10 -4
- package/src/cmd-db-recount.ts +5 -12
- package/src/cmd-db-rollback.ts +77 -0
- package/src/cmd-db-spec.ts +18 -2
- package/src/cmd-db-status.ts +5 -10
- package/src/cmd-db.ts +105 -33
- package/src/cmd-deploy-verify.ts +14 -6
- package/src/cmd-docs-topic.ts +94 -0
- package/src/cmd-docs.ts +15 -1
- package/src/cmd-doctor.ts +109 -41
- package/src/cmd-drill.ts +100 -19
- package/src/cmd-env.ts +30 -8
- package/src/cmd-errors-app.ts +63 -0
- package/src/cmd-errors.ts +50 -14
- package/src/cmd-generate.ts +17 -4
- package/src/cmd-heavy-spec.ts +36 -0
- package/src/cmd-heavy.ts +244 -0
- package/src/cmd-jobs.ts +27 -1
- package/src/cmd-merge-driver-spec.ts +12 -0
- package/src/cmd-merge-driver.ts +95 -0
- package/src/cmd-new.ts +23 -3
- package/src/cmd-policy-spec.ts +9 -1
- package/src/cmd-policy.ts +72 -17
- package/src/cmd-stop.ts +18 -4
- package/src/cmd-tasks-run.ts +87 -0
- package/src/cmd-tasks-spec.ts +10 -3
- package/src/cmd-tasks.ts +8 -5
- package/src/cmd-test.ts +15 -4
- package/src/cmd-upgrade-spec.ts +8 -1
- package/src/cmd-upgrade.ts +32 -5
- package/src/cmd-verify.ts +9 -41
- package/src/codemods/agents-doc-row.ts +73 -0
- package/src/codemods/define-error-leaf.ts +37 -12
- package/src/codemods/docs-many-agents.ts +26 -0
- package/src/codemods/docs-worker-commands.ts +26 -0
- package/src/codemods/index.ts +6 -0
- package/src/codemods/merge-drivers.ts +66 -0
- package/src/command.ts +3 -0
- package/src/db-applied-edits.ts +117 -0
- package/src/db-dev-wire.ts +18 -0
- package/src/db-diagnostics.ts +5 -10
- package/src/db-generate.ts +82 -7
- package/src/db-migrate-pass.ts +51 -0
- package/src/db-migrate-through-dev.ts +209 -0
- package/src/db-rollback-consent.ts +128 -0
- package/src/db-rollback-pass.ts +76 -0
- package/src/db-seed-generate.ts +5 -1
- package/src/db-seed.ts +7 -1
- package/src/deploy-verify-findings.ts +3 -0
- package/src/deploy-verify-grade.ts +3 -0
- package/src/deploy-verify-processes.ts +32 -0
- package/src/dev-boot.ts +3 -0
- package/src/dev-db-migrate.ts +155 -0
- package/src/dev-db-rollback.ts +33 -0
- package/src/dev-db-settled.ts +22 -0
- package/src/dev-lock-errors.ts +78 -0
- package/src/dev-lock-holder-dir.ts +64 -0
- package/src/dev-lock-live.ts +44 -0
- package/src/dev-lock.ts +59 -84
- package/src/dev-policy.ts +11 -8
- package/src/dev-rebuild-schema.ts +116 -13
- package/src/dev-rebuild.ts +13 -4
- package/src/dev-route-table.ts +7 -0
- package/src/dispatch.ts +21 -1
- package/src/doctor-advisory-floors.ts +30 -8
- package/src/doctor-api-listing.ts +114 -0
- package/src/doctor-guarded.ts +41 -0
- package/src/doctor-port.ts +90 -17
- package/src/doctor-probe.ts +36 -5
- package/src/doctor-processes-probe.ts +127 -0
- package/src/doctor-processes.ts +136 -0
- package/src/doctor-warnings.ts +17 -0
- package/src/error-codes-agents.ts +35 -0
- package/src/error-codes-processes.ts +30 -0
- package/src/error-codes-tooling.ts +11 -3
- package/src/error-codes.ts +12 -13
- package/src/errors-suite.ts +27 -0
- package/src/errors.ts +18 -22
- package/src/exec.ts +11 -3
- package/src/exercise-registration.ts +4 -3
- package/src/framework-env.ts +7 -3
- package/src/generate-files.ts +1 -0
- package/src/generate-grant-findings.ts +7 -5
- package/src/generate-grants.ts +9 -8
- package/src/generate-kinds.ts +30 -6
- package/src/generate-roles-file.ts +30 -0
- package/src/generate-slice-policy.ts +3 -3
- package/src/guards.ts +2 -2
- package/src/heavy-cores.ts +51 -0
- package/src/heavy-env.ts +21 -0
- package/src/heavy-errors.ts +54 -0
- package/src/heavy-flock.ts +73 -0
- package/src/heavy-holders.ts +78 -0
- package/src/heavy-ledger.ts +400 -0
- package/src/heavy-memory.ts +67 -0
- package/src/heavy-pressure.ts +104 -0
- package/src/heavy-weights.ts +47 -0
- package/src/heavy.ts +308 -0
- package/src/i18n-registration.ts +22 -2
- package/src/island-harness.ts +2 -2
- package/src/job-budget.ts +4 -2
- package/src/job-registration.ts +64 -8
- package/src/jobs-queue-known.ts +43 -0
- package/src/local-cli.ts +6 -5
- package/src/mcp-errors-agents.ts +20 -0
- package/src/mcp-errors-doctor.ts +27 -0
- package/src/mcp-errors-processes.ts +23 -0
- package/src/mcp-errors.ts +18 -29
- package/src/mcp-host.ts +2 -2
- package/src/merge-driver-catalog.ts +58 -0
- package/src/merge-driver-config.ts +43 -0
- package/src/merge-driver-lines.ts +140 -0
- package/src/merge-state.ts +105 -0
- package/src/messages-db.ts +22 -1
- package/src/messages-processes.ts +13 -0
- package/src/messages-upgrade.ts +6 -0
- package/src/messages.ts +62 -1
- package/src/output-findings.ts +48 -21
- package/src/parse.ts +37 -6
- package/src/policy-facts.ts +38 -21
- package/src/policy-row.ts +99 -0
- package/src/port-pair-free.ts +28 -0
- package/src/registry-lines.ts +110 -0
- package/src/registry.ts +4 -0
- package/src/retain-sweep.ts +1 -1
- package/src/role-replicator.ts +9 -4
- package/src/role-select.ts +86 -0
- package/src/role-start.ts +13 -55
- package/src/role-sync.ts +10 -5
- package/src/runtime-cache-frame.ts +46 -0
- package/src/runtime-cache-ttl.ts +23 -0
- package/src/runtime-cache.ts +56 -18
- package/src/runtime-database-ssl.ts +84 -0
- package/src/runtime-idempotency-scope.ts +16 -2
- package/src/runtime-jobs-share.ts +52 -0
- package/src/runtime-jobs.ts +43 -12
- package/src/runtime-overrides.ts +4 -2
- package/src/runtime-queue.ts +18 -3
- package/src/runtime-services.ts +8 -1
- package/src/schema-drift.ts +19 -2
- package/src/schema-dump-drift.ts +4 -1
- package/src/serve-boot-probe.ts +30 -2
- package/src/serve-boot.ts +11 -1
- package/src/serve-env.ts +39 -3
- package/src/serve.ts +61 -10
- package/src/stop-run-start.ts +12 -0
- package/src/supervise-boot.ts +61 -0
- package/src/supervise-cgroup.ts +84 -0
- package/src/supervise-child.ts +206 -0
- package/src/supervise-count.ts +244 -0
- package/src/supervise-errors.ts +83 -0
- package/src/supervise-facts.ts +40 -0
- package/src/supervise-messages.ts +84 -0
- package/src/supervise-policy.ts +46 -0
- package/src/supervise-pool.ts +10 -0
- package/src/supervise-probe.ts +158 -0
- package/src/supervise-run.ts +54 -0
- package/src/supervise.ts +383 -0
- package/src/templates/generate-purge.ts +6 -6
- package/src/templates/guard-animated-layout-property.ts +2 -2
- package/src/templates/guard-bare-error.ts +1 -1
- package/src/templates/guard-error-declared.ts +2 -2
- package/src/templates/guard-focus-visible.ts +1 -1
- package/src/templates/guard-image-dimensions.ts +2 -2
- package/src/templates/guard-island-mount-clears.ts +1 -1
- package/src/templates/guard-native-confirm.ts +1 -1
- package/src/templates/guard-raw-breakpoint.ts +2 -2
- package/src/templates/guard-raw-colour.ts +2 -2
- package/src/templates/guard-raw-fetch.ts +1 -1
- package/src/templates/guard-raw-interval.ts +1 -1
- package/src/templates/guard-raw-length.ts +3 -3
- package/src/templates/guard-raw-motion.ts +1 -1
- package/src/templates/guard-raw-shadow.ts +1 -1
- package/src/templates/guard-raw-z-index.ts +1 -1
- package/src/templates/guard-released-forms.ts +59 -13
- package/src/templates/guard-repo-await-in-loop.ts +1 -1
- package/src/templates/guard-repo-raw-sql.ts +4 -4
- package/src/templates/guard-repo-unbounded.ts +1 -1
- package/src/templates/guard-runtime-pin.ts +1 -1
- package/src/templates/guard-semantic-interactive.ts +2 -2
- package/src/templates/guard-unbounded-fanout.ts +1 -1
- package/src/templates/guard-undeclared-custom-property.ts +3 -3
- package/src/templates/guard-undefined-style-class.ts +3 -3
- package/src/templates/guard-unzoned-date.ts +3 -3
- package/src/templates/query-slice.ts +82 -0
- package/src/templates/query.ts +76 -30
- package/src/templates/resource-page.ts +3 -2
- package/src/templates/scaffold-bin.ts +2 -0
- package/src/templates/scaffold-claude-agents.ts +9 -6
- package/src/templates/scaffold-claude-commands.ts +7 -1
- package/src/templates/scaffold-claude.ts +4 -4
- package/src/templates/scaffold-container-compose.ts +47 -7
- package/src/templates/scaffold-docs.ts +11 -6
- package/src/templates/scaffold-gitattributes.ts +18 -1
- package/src/templates/scaffold-helm-templates.ts +9 -0
- package/src/templates/scaffold-repo.ts +4 -1
- package/src/templates/scaffold-test-services.ts +33 -11
- package/src/templates/shapes/offline.ts +0 -7
- package/src/templates/shapes/realtime.ts +2 -6
- package/src/templates/sign-in-action-tests.ts +6 -4
- package/src/templates/sign-in-challenge.ts +62 -0
- package/src/templates/sign-in-oidc-mfa.ts +31 -0
- package/src/templates/sign-in-oidc.ts +11 -3
- package/src/templates/sign-in-password.ts +18 -56
- package/src/test-batches.ts +9 -3
- package/src/test-shards.ts +117 -37
- package/src/test-slots.ts +35 -161
- package/src/test-verdict.ts +79 -0
- package/src/test-workers.ts +15 -0
- package/src/upgrade-gate-codemods.ts +5 -3
- package/src/upgrade-gate.ts +19 -1
- package/src/upgrade-merge-drivers.ts +25 -0
- package/src/upgrade-report.ts +18 -4
- package/src/upgrade-scope.ts +62 -0
- package/src/verify-checks.ts +6 -11
- package/src/verify-coverage-run.ts +9 -5
- package/src/verify-deadline.ts +18 -2
- package/src/verify-heavy-steps.ts +26 -0
- package/src/verify-live.ts +38 -14
- package/src/verify-only.ts +67 -0
- package/src/verify-progress.ts +7 -3
- package/src/verify-run.ts +20 -2
- package/src/verify-services-stack.ts +165 -0
- package/src/verify-services.ts +84 -2
- package/src/verify-test-run.ts +9 -9
- package/src/verify-tests.ts +35 -22
- package/src/verify-typecheck.ts +25 -2
- package/wiki/Actions.md +2 -1
- package/wiki/Admin-Dashboard.md +2 -2
- package/wiki/Agents.md +5 -5
- package/wiki/Auth.md +15 -5
- package/wiki/Bare-VM.md +1 -1
- package/wiki/Building-Your-Own-Base.md +15 -2
- package/wiki/CI-Parallel-Gate.md +4 -4
- package/wiki/CLI-Reference.md +127 -48
- package/wiki/Caching-And-Invalidation.md +2 -2
- package/wiki/Client-Navigation.md +1 -1
- package/wiki/Configuration.md +32 -13
- package/wiki/Deployment.md +44 -4
- package/wiki/Entities-And-Migrations.md +5 -1
- package/wiki/FAQ.md +1 -1
- package/wiki/Getting-Started.md +2 -2
- package/wiki/Home.md +2 -1
- package/wiki/I18n.md +5 -3
- package/wiki/Installation.md +12 -11
- package/wiki/Interface-Rules.md +1 -1
- package/wiki/Jobs-And-Workflows.md +24 -4
- package/wiki/Known-Gaps.md +2 -2
- package/wiki/MCP-And-AI.md +8 -5
- package/wiki/Mail.md +1 -1
- package/wiki/Many-Agents.md +127 -0
- package/wiki/Migrations-And-Backfills.md +18 -0
- package/wiki/Notify.md +1 -1
- package/wiki/Observability.md +13 -0
- package/wiki/Queries-And-Live-Queries.md +2 -2
- package/wiki/Realtime.md +10 -1
- package/wiki/Routes-And-Render-Modes.md +1 -1
- package/wiki/Scheduled-Tasks.md +4 -1
- package/wiki/Testing.md +12 -9
- package/wiki/Timezones-And-Dates.md +5 -1
- package/wiki/Troubleshooting.md +1 -0
- package/wiki/Tutorial-01-First-App.md +5 -5
- package/wiki/Tutorial-02-First-Feature.md +1 -1
- package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
- package/wiki/Upgrading.md +37 -0
package/src/cmd-doctor.ts
CHANGED
|
@@ -15,12 +15,16 @@ import { browserProbe, browserWarnings, withBrowserReport } from './doctor-brows
|
|
|
15
15
|
import { chartAlertsProbe, NOTHING_MISSING, withChartAlertsListing } from './doctor-chart-alerts';
|
|
16
16
|
import { coverageExcludesProbe, withCoverageExcludes } from './doctor-coverage';
|
|
17
17
|
import { embeddedDatabaseFinding } from './doctor-database';
|
|
18
|
+
import { guardedCheck, guardedListing } from './doctor-guarded';
|
|
18
19
|
import { shippedGuardsProbe, vendoredGuardWarnings, withGuardListing } from './doctor-guards';
|
|
19
20
|
import { offlineFallbackFinding } from './doctor-offline';
|
|
20
21
|
import { NO_POOLER_FACT, poolerFindings, withPoolerReport } from './doctor-pooler';
|
|
21
|
-
import { doctorPort, portFindings } from './doctor-port';
|
|
22
|
+
import { doctorPort, ownerAskedOnce, portFindings } from './doctor-port';
|
|
22
23
|
import type { DoctorProbe } from './doctor-probe';
|
|
23
24
|
import { probeFor } from './doctor-probe';
|
|
25
|
+
import type { ProcessesFact } from './doctor-processes';
|
|
26
|
+
import { processesWarnings, withProcessesReport } from './doctor-processes';
|
|
27
|
+
import { hostProcessesSources, processesFact } from './doctor-processes-probe';
|
|
24
28
|
import { redundantIndexesProbe, withRedundantIndexes } from './doctor-redundant-indexes';
|
|
25
29
|
import { rollingSinceProbe, withRollingReminder } from './doctor-rolling';
|
|
26
30
|
import { sealedKeyFindings } from './doctor-sealed';
|
|
@@ -31,6 +35,7 @@ import { ICON_SOURCE } from './icon-assets';
|
|
|
31
35
|
import { msg } from './messages';
|
|
32
36
|
import type { CommandResult, Finding } from './output';
|
|
33
37
|
import { cliVersion } from './registry';
|
|
38
|
+
import { withAppTls } from './runtime-database-ssl';
|
|
34
39
|
import { quoteArg } from './shell-quote';
|
|
35
40
|
|
|
36
41
|
// `src/index.ts` publishes the seam from here; its declaration lives in `doctor-probe.ts`.
|
|
@@ -70,9 +75,18 @@ export async function runDoctor(probe: DoctorProbe): Promise<readonly Finding[]>
|
|
|
70
75
|
);
|
|
71
76
|
return findings;
|
|
72
77
|
}
|
|
78
|
+
// Every check below through `check`: one that throws is that check's finding, not the report's end.
|
|
79
|
+
const check = (name: string, run: () => Promise<void>): Promise<void> =>
|
|
80
|
+
guardedCheck(name, findings, run);
|
|
81
|
+
// First of the app's checks: an unfinished merge explains most of what any later one reports.
|
|
82
|
+
await check('merge state', async () => {
|
|
83
|
+
findings.push(...((await probe.mergeState?.()) ?? []));
|
|
84
|
+
});
|
|
73
85
|
// Right after the runtime and for its reason: a compiler a major behind reds typecheck and build
|
|
74
86
|
// on the framework's own files, and every finding below is read through a gate that cannot pass.
|
|
75
|
-
|
|
87
|
+
await check('typescript', async () => {
|
|
88
|
+
findings.push(...typescriptFindings(await probe.typescript()));
|
|
89
|
+
});
|
|
76
90
|
if (!probe.exists(ENV_DEVELOPMENT)) {
|
|
77
91
|
findings.push(
|
|
78
92
|
finding(
|
|
@@ -93,7 +107,9 @@ export async function runDoctor(probe: DoctorProbe): Promise<readonly Finding[]>
|
|
|
93
107
|
// Silent in development and on a shell naming no environment; reported where this machine names
|
|
94
108
|
// a deploy. One list, one wording (`framework-env.ts`, #679).
|
|
95
109
|
findings.push(...probe.frameworkFindings);
|
|
96
|
-
|
|
110
|
+
await check('port', async () => {
|
|
111
|
+
findings.push(...(await portFindings(probe)));
|
|
112
|
+
});
|
|
97
113
|
findings.push(...appUrlFindings(probe.appUrl, probe.port));
|
|
98
114
|
// `@ultimat3/pwa`'s own codes, not CLI twins of them. `X_PWA_NO_ICON_SOURCE` and
|
|
99
115
|
// `X_PWA_NO_FALLBACK` used to be declared here for the same two conditions the package already
|
|
@@ -116,29 +132,41 @@ export async function runDoctor(probe: DoctorProbe): Promise<readonly Finding[]>
|
|
|
116
132
|
// `apps/web/app/offline.tsx`, which is not a route file at all (`assertRouteFilename` refuses
|
|
117
133
|
// it), so no app could clear the finding and its own `fix:` did not either. `doctor-offline.ts`
|
|
118
134
|
// holds the rule and the reasons.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
await check('offline fallback', async () => {
|
|
136
|
+
const offline = offlineFallbackFinding(await probe.offlineFallback());
|
|
137
|
+
if (offline !== undefined) findings.push(offline);
|
|
138
|
+
});
|
|
139
|
+
await check('database', async () => {
|
|
140
|
+
const pooler = await probe.pooler();
|
|
141
|
+
findings.push(...poolerFindings(pooler));
|
|
142
|
+
// A pooler's refusal is every other database probe's answer too, and its fix is the true one:
|
|
143
|
+
// this one's says "set DATABASE_URL" to an operator whose URL is right.
|
|
144
|
+
const database = pooler.refused === undefined ? await probe.database() : null;
|
|
145
|
+
if (database !== null) findings.push(database);
|
|
146
|
+
// The other half of the same question, and the half a bare VM lands on: `database()` is silent
|
|
147
|
+
// where there is no `DATABASE_URL`, and that silence IS the bare-VM configuration.
|
|
148
|
+
const embedded = embeddedDatabaseFinding(await probe.embeddedDatabase());
|
|
149
|
+
if (embedded !== undefined) findings.push(embedded);
|
|
150
|
+
// Asked only of a database that answered: an unreachable one is already the finding above.
|
|
151
|
+
const reachable = pooler.refused === undefined && database === null;
|
|
152
|
+
if (reachable) findings.push(...((await probe.rowSecurity?.()) ?? []));
|
|
153
|
+
});
|
|
154
|
+
await check('migration drift', async () => {
|
|
155
|
+
findings.push(...(await probe.drift()));
|
|
156
|
+
});
|
|
135
157
|
// Last, and it is why `X_CLI_UNEXPECTED`'s `fix: x doctor --json` is not a dead end on the path an
|
|
136
158
|
// author reaches it from: `x db gen` throwing `X_MIGRATION_SNAPSHOT_MISSING` used to be a
|
|
137
159
|
// condition this diagnostic could not see at all, so the fix line ran clean over a broken app.
|
|
138
|
-
|
|
160
|
+
await check('migration snapshots', async () => {
|
|
161
|
+
findings.push(...(await probe.snapshots()));
|
|
162
|
+
});
|
|
139
163
|
// Sealed columns against the key ring: no key at all, or a rotation whose re-seal is pending.
|
|
140
|
-
|
|
141
|
-
|
|
164
|
+
await check('sealed keys', async () => {
|
|
165
|
+
findings.push(...sealedKeyFindings(await probe.sealedKeys()));
|
|
166
|
+
});
|
|
167
|
+
await check('auth storage', async () => {
|
|
168
|
+
findings.push(...authStorageFindings(await probe.authStorage()));
|
|
169
|
+
});
|
|
142
170
|
// `X_FRAMEWORK_PIN_RANGE`, `X_ENV_NAME_RESERVED`, `X_DB_ROW_SECURITY_OFF` and
|
|
143
171
|
// `X_VERIFY_STEP_UNFLOORED` are not here: on `main` they warn beside the verdict
|
|
144
172
|
// (`doctor-warnings.ts`), so an upgrade with no change keeps this green.
|
|
@@ -152,14 +180,31 @@ export async function runDoctor(probe: DoctorProbe): Promise<readonly Finding[]>
|
|
|
152
180
|
export interface DoctorReportProbe extends DoctorProbe {
|
|
153
181
|
/** Which Chrome the e2e driver would launch, and whether one is required (`doctor-browser.ts`). */
|
|
154
182
|
browser(): Promise<BrowserFact | undefined>;
|
|
183
|
+
/** Processes per container and the connections they hold (`doctor-processes.ts`); unset: unasked. */
|
|
184
|
+
processes?(): Promise<ProcessesFact>;
|
|
185
|
+
/**
|
|
186
|
+
* The release codemods still owed are measured up to: the CLI's own, `cliVersion()`. A fact like
|
|
187
|
+
* the rest, never read inside the report: from the stamp, a release bump moved every report test.
|
|
188
|
+
*/
|
|
189
|
+
readonly release: string;
|
|
155
190
|
}
|
|
156
191
|
|
|
157
192
|
/** The whole report over one probe: the verdict, then the listings and warnings beside it. */
|
|
158
193
|
export async function reportDoctor(probe: DoctorReportProbe): Promise<CommandResult> {
|
|
159
|
-
//
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
|
|
194
|
+
// A listing that throws costs that listing, reported beside the rest (`doctor-guarded.ts`).
|
|
195
|
+
const failed: Finding[] = [];
|
|
196
|
+
const inApp = <T>(name: string, read: (root: string) => Promise<T>, none: T): Promise<T> => {
|
|
197
|
+
const { root } = probe;
|
|
198
|
+
return root === undefined
|
|
199
|
+
? Promise.resolve(none)
|
|
200
|
+
: guardedListing(name, failed, () => read(root), none);
|
|
201
|
+
};
|
|
202
|
+
// Asked once: `runDoctor` reads the verdict and the report beside it reads the numbers. The port's
|
|
203
|
+
// owner too: the verdict and the warnings partition one answer (`ownerAskedOnce`).
|
|
204
|
+
const pooler = await inApp('pooler', () => probe.pooler(), NO_POOLER_FACT);
|
|
205
|
+
const asked = { ...probe, pooler: async () => pooler, portOwner: ownerAskedOnce(probe) };
|
|
206
|
+
const findings = await runDoctor(asked);
|
|
207
|
+
const guardEntries = await inApp('shipped guards', shippedGuardsProbe, []);
|
|
163
208
|
const listed = withGuardListing(
|
|
164
209
|
{
|
|
165
210
|
ok: findings.length === 0,
|
|
@@ -177,37 +222,50 @@ export async function reportDoctor(probe: DoctorReportProbe): Promise<CommandRes
|
|
|
177
222
|
// The second listing: what the coverage floor does not see (`doctor-coverage.ts`).
|
|
178
223
|
const covered = withCoverageExcludes(
|
|
179
224
|
listed,
|
|
180
|
-
|
|
225
|
+
await inApp('coverage excludes', coverageExcludesProbe, []),
|
|
181
226
|
);
|
|
182
227
|
// The third: the monitoring templates and dashboard the chart predates (`doctor-chart-alerts.ts`).
|
|
183
228
|
const charted = withChartAlertsListing(
|
|
184
229
|
covered,
|
|
185
|
-
|
|
230
|
+
await inApp('chart alerts', async (root) => chartAlertsProbe(root), NOTHING_MISSING),
|
|
186
231
|
);
|
|
187
232
|
// The fourth: implicit indexes another already serves (`doctor-redundant-indexes.ts`).
|
|
188
233
|
const indexed = withRedundantIndexes(
|
|
189
234
|
charted,
|
|
190
|
-
|
|
235
|
+
await inApp('redundant indexes', redundantIndexesProbe, undefined),
|
|
191
236
|
);
|
|
192
237
|
// A reminder, not a finding: the rolling rail is off until this is set (`doctor-rolling.ts`).
|
|
193
238
|
const reminded = withPoolerReport(
|
|
194
|
-
withRollingReminder(
|
|
195
|
-
indexed,
|
|
196
|
-
probe.root === undefined ? undefined : await rollingSinceProbe(probe.root),
|
|
197
|
-
),
|
|
239
|
+
withRollingReminder(indexed, await inApp('rolling deploys', rollingSinceProbe, undefined)),
|
|
198
240
|
pooler,
|
|
199
241
|
);
|
|
200
242
|
// Last, and beside the verdict on `main`: the 31.16.0 checks (`doctor-warnings.ts`).
|
|
201
243
|
// A copy of a shipped guard among them (`X_GUARD_VENDORED`): a warning, so exit stays.
|
|
202
|
-
const browser = await probe.browser();
|
|
203
|
-
|
|
204
|
-
|
|
244
|
+
const browser = await guardedListing('browser', failed, () => probe.browser(), undefined);
|
|
245
|
+
const { processes } = probe;
|
|
246
|
+
const counted =
|
|
247
|
+
processes === undefined
|
|
248
|
+
? undefined
|
|
249
|
+
: await inApp<ProcessesFact | undefined>('processes', processes, undefined);
|
|
250
|
+
const warnings = await guardedListing('warnings', failed, () => doctorWarnings(asked), []);
|
|
251
|
+
const superseded = await inApp('superseded workarounds', supersededFindings, []);
|
|
252
|
+
const floors = await inApp('advisory floors', advisoryFloorFindings, []);
|
|
253
|
+
// An `x upgrade` driven by a CLI older than the codemod engine left files it owed.
|
|
254
|
+
const codemods = await inApp(
|
|
255
|
+
'pending codemods',
|
|
256
|
+
(root) => pendingCodemodFindings(root, probe.release),
|
|
257
|
+
[],
|
|
258
|
+
);
|
|
259
|
+
const reported = counted === undefined ? reminded : withProcessesReport(reminded, counted);
|
|
260
|
+
return withDoctorWarnings(withBrowserReport(reported, browser), [
|
|
261
|
+
...warnings,
|
|
262
|
+
...(counted === undefined ? [] : processesWarnings(counted)),
|
|
205
263
|
...vendoredGuardWarnings(guardEntries),
|
|
206
264
|
...browserWarnings(browser),
|
|
207
|
-
...
|
|
208
|
-
...
|
|
209
|
-
|
|
210
|
-
...
|
|
265
|
+
...superseded,
|
|
266
|
+
...floors,
|
|
267
|
+
...codemods,
|
|
268
|
+
...failed,
|
|
211
269
|
]);
|
|
212
270
|
}
|
|
213
271
|
|
|
@@ -216,6 +274,16 @@ export const doctorCommand: CliCommand = {
|
|
|
216
274
|
run(ctx: CommandContext): Promise<CommandResult> {
|
|
217
275
|
const port = doctorPort(ctx.args, ctx.env);
|
|
218
276
|
const probe = probeFor(ctx.cwd, ctx.bunVersion, port, ctx.env);
|
|
219
|
-
|
|
277
|
+
const { root } = probe;
|
|
278
|
+
const databaseUrl = () => withAppTls(root, ctx.env['DATABASE_URL'], ctx.env);
|
|
279
|
+
return reportDoctor({
|
|
280
|
+
...probe,
|
|
281
|
+
browser: () => browserProbe(root, ctx.env),
|
|
282
|
+
release: cliVersion(),
|
|
283
|
+
// Outside an app there is no container to count, and `reportDoctor` asks no in-app listing.
|
|
284
|
+
...(root === undefined
|
|
285
|
+
? {}
|
|
286
|
+
: { processes: () => processesFact(hostProcessesSources(root, ctx.env, databaseUrl)) }),
|
|
287
|
+
});
|
|
220
288
|
},
|
|
221
289
|
};
|
package/src/cmd-drill.ts
CHANGED
|
@@ -4,13 +4,19 @@
|
|
|
4
4
|
// and the verdict are testing's. Not a gate step: it needs Postgres, and `x verify` needs nothing.
|
|
5
5
|
|
|
6
6
|
import type { AppConfig } from '@ultimat3/core';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
DRAIN_DEADLINE_DEFAULT_MS,
|
|
9
|
+
frameworkVersion,
|
|
10
|
+
isUltimateError,
|
|
11
|
+
MAX_TIMER_MS,
|
|
12
|
+
} from '@ultimat3/core';
|
|
8
13
|
import type {
|
|
9
14
|
Drill,
|
|
10
15
|
DrillConfig,
|
|
11
16
|
DrillDeclarations,
|
|
12
17
|
DrillFleet,
|
|
13
18
|
DrillReport,
|
|
19
|
+
DrillRoleNotPlayed,
|
|
14
20
|
} from '@ultimat3/testing';
|
|
15
21
|
import {
|
|
16
22
|
bunDrillSql,
|
|
@@ -21,6 +27,7 @@ import {
|
|
|
21
27
|
drillBudgets,
|
|
22
28
|
drillNamed,
|
|
23
29
|
drillRoles,
|
|
30
|
+
drillRolesNotPlayed,
|
|
24
31
|
drillServices,
|
|
25
32
|
runDrill,
|
|
26
33
|
runRollout,
|
|
@@ -37,7 +44,9 @@ import { UnknownCommandError } from './errors';
|
|
|
37
44
|
import { readIntFlag } from './flag-number';
|
|
38
45
|
import { msg } from './messages';
|
|
39
46
|
import type { CommandResult, Finding, JsonValue } from './output';
|
|
47
|
+
import { findingFrom } from './output';
|
|
40
48
|
import { flagBool } from './parse';
|
|
49
|
+
import { replicatedRelations } from './role-replicator';
|
|
41
50
|
|
|
42
51
|
/** Read through `readIntFlag`, which refuses `5s`, `NaN` and a fraction with the flag's name. */
|
|
43
52
|
const BUDGET_FLAG = 'budget-ms';
|
|
@@ -95,7 +104,10 @@ const reportJson = (report: DrillReport): JsonValue =>
|
|
|
95
104
|
),
|
|
96
105
|
) as JsonValue;
|
|
97
106
|
|
|
98
|
-
|
|
107
|
+
/** A report's failures, each as `X_DRILL_FAILED`: the name and the verdict are all it reads. */
|
|
108
|
+
type JudgedDrill = Pick<DrillReport, 'name' | 'verdict'>;
|
|
109
|
+
|
|
110
|
+
const findingsOf = (report: JudgedDrill): readonly Finding[] =>
|
|
99
111
|
report.verdict.failures.map((failure) => {
|
|
100
112
|
const error = new DrillFailedError({ drill: report.name, failure });
|
|
101
113
|
return { code: error.code, cause: error.cause, fix: error.fix };
|
|
@@ -104,28 +116,79 @@ const findingsOf = (report: DrillReport): readonly Finding[] =>
|
|
|
104
116
|
/** The evidence connection: `bunDrillSql`'s shape, a seam so a test can make it throw. */
|
|
105
117
|
type DrillSqlConnection = ReturnType<typeof bunDrillSql>;
|
|
106
118
|
|
|
119
|
+
/**
|
|
120
|
+
* The body's value — or what it threw — and the teardown's refusal (a scratch database left
|
|
121
|
+
* behind) as a finding. Both halves on both paths: a throw must not take the leak's finding with it.
|
|
122
|
+
*/
|
|
123
|
+
export type DrillFleetRun<T> = ({ readonly value: T } | { readonly thrown: unknown }) & {
|
|
124
|
+
readonly teardown: readonly Finding[];
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/** Stop the fleet; a coded refusal is answered as a finding, so it cannot replace a verdict. */
|
|
128
|
+
async function stopFleet(fleet: Pick<DrillFleet, 'stop'>): Promise<readonly Finding[]> {
|
|
129
|
+
try {
|
|
130
|
+
await fleet.stop();
|
|
131
|
+
return [];
|
|
132
|
+
} catch (error) {
|
|
133
|
+
if (!isUltimateError(error)) throw error;
|
|
134
|
+
return [{ code: error.code, cause: error.cause, fix: error.fix }];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
107
138
|
/**
|
|
108
139
|
* One drill's body over a started fleet, which is ALWAYS stopped. The fleet is spawned role
|
|
109
140
|
* processes: the connection was opened before the `try`, so a constructor that threw (a malformed
|
|
110
141
|
* URL is a synchronous `Invalid URL`) left every role running, and a `close()` that threw skipped
|
|
111
|
-
* `stop()` the same way.
|
|
142
|
+
* `stop()` the same way. A body that threw keeps its throw, answered as `thrown`: the teardown's
|
|
143
|
+
* failure — a later, smaller fact — rides beside it and never replaces the one that ended the run.
|
|
112
144
|
*/
|
|
113
145
|
export async function withDrillFleet<T>(
|
|
114
146
|
fleet: Pick<DrillFleet, 'databaseUrl' | 'stop'>,
|
|
115
147
|
open: (url: string) => DrillSqlConnection,
|
|
116
148
|
body: (sql: DrillSqlConnection) => Promise<T>,
|
|
117
|
-
): Promise<T
|
|
149
|
+
): Promise<DrillFleetRun<T>> {
|
|
118
150
|
let sql: DrillSqlConnection | undefined;
|
|
151
|
+
let closed = false;
|
|
152
|
+
let value: T;
|
|
119
153
|
try {
|
|
120
154
|
sql = open(fleet.databaseUrl);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
155
|
+
value = await body(sql);
|
|
156
|
+
closed = true;
|
|
157
|
+
await sql.close();
|
|
158
|
+
} catch (error) {
|
|
159
|
+
const [, stopped] = await Promise.allSettled([
|
|
160
|
+
closed ? undefined : sql?.close(),
|
|
161
|
+
stopFleet(fleet),
|
|
162
|
+
]);
|
|
163
|
+
// `stopFleet` answers a coded refusal as a finding; only an uncoded throw rejects it.
|
|
164
|
+
const teardown = stopped.status === 'fulfilled' ? stopped.value : [findingFrom(stopped.reason)];
|
|
165
|
+
return { thrown: error, teardown };
|
|
128
166
|
}
|
|
167
|
+
return { value, teardown: await stopFleet(fleet) };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* A drill that threw ends the run, as it always has — red, exit 1 — with its throw first, then
|
|
172
|
+
* every finished drill's failures and every teardown finding so far: none of them is dropped.
|
|
173
|
+
*/
|
|
174
|
+
export function thrownRun(input: {
|
|
175
|
+
readonly thrown: unknown;
|
|
176
|
+
readonly reports: readonly JudgedDrill[];
|
|
177
|
+
readonly teardowns: readonly Finding[];
|
|
178
|
+
readonly notRun: readonly string[];
|
|
179
|
+
}): CommandResult {
|
|
180
|
+
const { reports } = input;
|
|
181
|
+
return {
|
|
182
|
+
ok: false,
|
|
183
|
+
command: 'drill',
|
|
184
|
+
summary: msg('cli.drill.summary', {
|
|
185
|
+
held: reports.filter((report) => report.verdict.ok).length,
|
|
186
|
+
ran: reports.length + 1,
|
|
187
|
+
notRun: input.notRun.length,
|
|
188
|
+
}),
|
|
189
|
+
findings: [findingFrom(input.thrown), ...reports.flatMap(findingsOf), ...input.teardowns],
|
|
190
|
+
exitCode: 1,
|
|
191
|
+
};
|
|
129
192
|
}
|
|
130
193
|
|
|
131
194
|
export const drillCommand: CliCommand = {
|
|
@@ -177,9 +240,21 @@ export const drillCommand: CliCommand = {
|
|
|
177
240
|
}
|
|
178
241
|
const budgets = drillBudgets(drillConfigOf(config), override);
|
|
179
242
|
const { targets, skipped } = await drillTargets(root);
|
|
243
|
+
// After `drillTargets`: loading the app is what fills the entity registry read here.
|
|
244
|
+
const publishable = replicatedRelations().length > 0;
|
|
180
245
|
const reports: DrillReport[] = [];
|
|
246
|
+
const teardowns: Finding[] = [];
|
|
247
|
+
const rolesNotPlayed: (DrillRoleNotPlayed & { readonly drill: string })[] = [];
|
|
181
248
|
for (const { drill, services } of planned) {
|
|
182
249
|
const { fault } = drill;
|
|
250
|
+
const found = {
|
|
251
|
+
bus: services.nats !== undefined,
|
|
252
|
+
logicalPostgres: services.logicalPostgres === true,
|
|
253
|
+
publishable,
|
|
254
|
+
};
|
|
255
|
+
for (const gap of drillRolesNotPlayed(drill, found)) {
|
|
256
|
+
rolesNotPlayed.push({ drill: drill.name, ...gap });
|
|
257
|
+
}
|
|
183
258
|
// The rollout order: the stamp is this package's to write, so the rewind is handed in.
|
|
184
259
|
const order =
|
|
185
260
|
fault.kind === 'order'
|
|
@@ -188,20 +263,21 @@ export const drillCommand: CliCommand = {
|
|
|
188
263
|
const fleet = await startDrillFleet({
|
|
189
264
|
root,
|
|
190
265
|
services,
|
|
191
|
-
roles: drillRoles(drill),
|
|
266
|
+
roles: drillRoles(drill, found),
|
|
192
267
|
readyTimeoutMs: READY_TIMEOUT_MS,
|
|
193
268
|
beforeMigrate: order,
|
|
194
269
|
});
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
: runRollout({ drill, fleet, budgets, readyTimeoutMs: READY_TIMEOUT_MS }),
|
|
200
|
-
),
|
|
270
|
+
const run = await withDrillFleet(fleet, bunDrillSql, (sql) =>
|
|
271
|
+
order === undefined
|
|
272
|
+
? runDrill({ drill, fleet, budgets, targets, sql, sync: drillSyncLane(fleet) })
|
|
273
|
+
: runRollout({ drill, fleet, budgets, readyTimeoutMs: READY_TIMEOUT_MS }),
|
|
201
274
|
);
|
|
275
|
+
teardowns.push(...run.teardown);
|
|
276
|
+
if ('thrown' in run) return thrownRun({ thrown: run.thrown, reports, teardowns, notRun });
|
|
277
|
+
reports.push(run.value);
|
|
202
278
|
}
|
|
203
279
|
const held = reports.filter((report) => report.verdict.ok).length;
|
|
204
|
-
const findings = reports.flatMap(findingsOf);
|
|
280
|
+
const findings = [...reports.flatMap(findingsOf), ...teardowns];
|
|
205
281
|
return {
|
|
206
282
|
ok: findings.length === 0 && held === reports.length,
|
|
207
283
|
command: 'drill',
|
|
@@ -209,6 +285,9 @@ export const drillCommand: CliCommand = {
|
|
|
209
285
|
lines: [
|
|
210
286
|
...reports.map((report) => ` ${report.verdict.ok ? 'held' : 'FAILED'} ${report.name}`),
|
|
211
287
|
...notRun.map((drill) => ` not run ${drill}`),
|
|
288
|
+
...rolesNotPlayed.map(
|
|
289
|
+
(gap) => ` not played ${gap.drill}: ${gap.role}, needs ${gap.needs}`,
|
|
290
|
+
),
|
|
212
291
|
],
|
|
213
292
|
findings,
|
|
214
293
|
data: {
|
|
@@ -218,6 +297,8 @@ export const drillCommand: CliCommand = {
|
|
|
218
297
|
skippedWrites: skipped.map((entry) => ({ ...entry })),
|
|
219
298
|
drills: reports.map(reportJson),
|
|
220
299
|
notRun,
|
|
300
|
+
// A role the rollout order left out, with what it needs: CI refuses a non-empty list.
|
|
301
|
+
rolesNotPlayed: rolesNotPlayed.map((gap) => ({ ...gap })),
|
|
221
302
|
},
|
|
222
303
|
};
|
|
223
304
|
},
|
package/src/cmd-env.ts
CHANGED
|
@@ -7,15 +7,19 @@ import { join } from 'node:path';
|
|
|
7
7
|
import {
|
|
8
8
|
checkEnv,
|
|
9
9
|
ENV_EXAMPLE_PATH,
|
|
10
|
+
ENVIRONMENT_KEY,
|
|
10
11
|
ERROR_DOCS_URL,
|
|
11
12
|
maskedEnvValues,
|
|
13
|
+
tryResolveEnvironment,
|
|
12
14
|
UltimateError,
|
|
13
15
|
} from '@ultimat3/core';
|
|
14
16
|
import { appSecretFacts, envExampleFor, loadEnvSchema } from './app-env';
|
|
15
17
|
import { requireAppRoot } from './app-root';
|
|
16
18
|
import { envSpec } from './cmd-env-spec';
|
|
17
19
|
import type { CliCommand, CommandContext } from './command';
|
|
20
|
+
import { needsDevEnvironmentDeclaration } from './dev-environment';
|
|
18
21
|
import { frameworkSecretFindings, namesNoEnvironment } from './framework-env';
|
|
22
|
+
import { isCi } from './heavy-env';
|
|
19
23
|
import { msg } from './messages';
|
|
20
24
|
import type { CommandResult, Finding, JsonValue } from './output';
|
|
21
25
|
|
|
@@ -67,6 +71,15 @@ async function writeExample(ctx: CommandContext): Promise<CommandResult> {
|
|
|
67
71
|
};
|
|
68
72
|
}
|
|
69
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Does this table get `x dev`'s answer? Only where `x dev` itself would declare `development` —
|
|
76
|
+
* neither `ULTIMATE_ENV` nor `NODE_ENV` set (`needsDevEnvironmentDeclaration`, its one rule) — and
|
|
77
|
+
* not under `CI`, where an unnamed table is a deploy's and stays fail-closed. It was production
|
|
78
|
+
* everywhere, so `x env check` exited 1 on a pristine scaffold whose `x dev` ran clean.
|
|
79
|
+
*/
|
|
80
|
+
const checkedAsDev = (env: CommandContext['env']): boolean =>
|
|
81
|
+
needsDevEnvironmentDeclaration(env) && !isCi(env);
|
|
82
|
+
|
|
70
83
|
/**
|
|
71
84
|
* The values are read from the environment the command was handed (`ctx.env`, the process's own
|
|
72
85
|
* in `bin.ts`) — one table for the app's keys and the framework's — and only ever printed through
|
|
@@ -74,18 +87,23 @@ async function writeExample(ctx: CommandContext): Promise<CommandResult> {
|
|
|
74
87
|
* return them, and a `--json` report is the last place a DSN should appear in full.
|
|
75
88
|
*
|
|
76
89
|
* The framework's deploy-required secrets (`framework-env.ts`) are asked exactly where the boot
|
|
77
|
-
* refuses them — outside development/test
|
|
90
|
+
* refuses them — outside development/test — so `ULTIMATE_ENV=production x env check` answers what
|
|
78
91
|
* the first deployed boot would, instead of each role crash-looping on one key at a time (#679).
|
|
92
|
+
*
|
|
93
|
+
* WHICH environment, when the table names none (`checkedAsDev`): `x dev`'s own rule on a developer's
|
|
94
|
+
* shell, the boot's fail-closed one under `CI`. A named environment is always checked as named.
|
|
79
95
|
*/
|
|
80
96
|
async function checkProcessEnv(ctx: CommandContext): Promise<CommandResult> {
|
|
81
97
|
const { root, schema } = await requireSchema(ctx.cwd, 'check');
|
|
82
|
-
const
|
|
98
|
+
const asDev = checkedAsDev(ctx.env);
|
|
99
|
+
const env = asDev ? { ...ctx.env, [ENVIRONMENT_KEY]: 'development' } : ctx.env;
|
|
100
|
+
const report = checkEnv(schema, { env });
|
|
83
101
|
const total = Object.keys(schema).length;
|
|
84
102
|
// A key the app's own declaration already reported is one finding, not two.
|
|
85
103
|
const reported = new Set(report.issues.map((issue) => issue.key));
|
|
86
|
-
// Gated by `deployed()` inside — the boot's own rule, so a table naming no environment
|
|
87
|
-
// checked as the production process it boots as.
|
|
88
|
-
const framework = frameworkSecretFindings(
|
|
104
|
+
// Gated by `deployed()` inside — the boot's own rule, so under CI a table naming no environment
|
|
105
|
+
// is checked as the production process it boots as.
|
|
106
|
+
const framework = frameworkSecretFindings(env, reported, await appSecretFacts(root));
|
|
89
107
|
const findings: readonly Finding[] = [
|
|
90
108
|
...report.issues.map((issue) => ({
|
|
91
109
|
code: 'X_ENV_MISSING',
|
|
@@ -112,12 +130,16 @@ async function checkProcessEnv(ctx: CommandContext): Promise<CommandResult> {
|
|
|
112
130
|
command: 'env',
|
|
113
131
|
// `x doctor` asks about this machine and stays quiet on the same shell, so an exit 1 here over
|
|
114
132
|
// a table that named nothing reads as a contradiction until this line says which question ran.
|
|
115
|
-
summary:
|
|
116
|
-
? `${verdict} — ${msg('cli.env.
|
|
117
|
-
:
|
|
133
|
+
summary: asDev
|
|
134
|
+
? `${verdict} — ${msg('cli.env.checkedAsDevelopment')}`
|
|
135
|
+
: namesNoEnvironment(env)
|
|
136
|
+
? `${verdict} — ${msg('cli.env.checkedAsProduction')}`
|
|
137
|
+
: verdict,
|
|
118
138
|
findings,
|
|
119
139
|
data: {
|
|
120
140
|
variables: total,
|
|
141
|
+
// The environment the answer is for; an unnamed table under CI is the boot's: production.
|
|
142
|
+
environment: tryResolveEnvironment({ env, fallback: 'production' }) ?? null,
|
|
121
143
|
values: maskedEnvValues(schema, report.values) as JsonValue,
|
|
122
144
|
},
|
|
123
145
|
exitCode: ok ? 0 : 1,
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// `x errors explain` for a code the APP declares with `defineError()` (`x g resource` writes one per
|
|
2
|
+
// slice). Loading the app registers it, and the answer is the registry's alone: title and status.
|
|
3
|
+
// A cause and a fix are functions of params only a throw has, so the declaring line is named instead.
|
|
4
|
+
|
|
5
|
+
import { describeErrorCode, ERROR_DOCS_URL, hasErrorCode, UltimateError } from '@ultimat3/core';
|
|
6
|
+
import { definedErrorStatus } from '@ultimat3/core/internal/error-status';
|
|
7
|
+
import { loadApp } from './app-load';
|
|
8
|
+
import { findAppRoot } from './app-root';
|
|
9
|
+
import { collectDeclaredCodes } from './error-contract';
|
|
10
|
+
import { quoteArg } from './shell-quote';
|
|
11
|
+
|
|
12
|
+
/** What an app code answers: what the registry holds for it, and the line that declares it. */
|
|
13
|
+
export interface AppCodeExplanation {
|
|
14
|
+
readonly code: string;
|
|
15
|
+
readonly title: string;
|
|
16
|
+
readonly docs: string;
|
|
17
|
+
/** `null` for an `offSocket` declaration. */
|
|
18
|
+
readonly status: number | null;
|
|
19
|
+
readonly site: { readonly at: string; readonly line: number } | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The app's declaration of `code`, or `undefined`: not inside an app, the load failed, or the app
|
|
24
|
+
* declares no such code. The caller then refuses with `AppCodeUnknownError`. The site is the
|
|
25
|
+
* `errors` step's own answer to "where is this code declared" (`collectDeclaredCodes`), never a
|
|
26
|
+
* second reading of the declaration.
|
|
27
|
+
*/
|
|
28
|
+
export async function explainAppCode(
|
|
29
|
+
code: string,
|
|
30
|
+
cwd: string,
|
|
31
|
+
): Promise<AppCodeExplanation | undefined> {
|
|
32
|
+
const root = findAppRoot(cwd)?.dir;
|
|
33
|
+
if (root === undefined) return undefined;
|
|
34
|
+
await loadApp(root);
|
|
35
|
+
if (!hasErrorCode(code)) return undefined;
|
|
36
|
+
const described = describeErrorCode(code);
|
|
37
|
+
const declared = (await collectDeclaredCodes(root)).find((site) => site.code === code);
|
|
38
|
+
return {
|
|
39
|
+
code,
|
|
40
|
+
title: described.title,
|
|
41
|
+
docs: described.docs ?? ERROR_DOCS_URL,
|
|
42
|
+
status: definedErrorStatus(code)?.status ?? null,
|
|
43
|
+
site: declared === undefined ? null : { at: declared.at, line: declared.line },
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The framework does not know the code and no app answered for it. Same code as the CLI's own
|
|
49
|
+
* `ErrorCodeUnknownError`; the fix says where an app's codes come from, which that one cannot.
|
|
50
|
+
*/
|
|
51
|
+
export class AppCodeUnknownError extends UltimateError {
|
|
52
|
+
constructor(input: { readonly code: string; readonly inApp: boolean }) {
|
|
53
|
+
super({
|
|
54
|
+
code: 'X_ERROR_CODE_UNKNOWN',
|
|
55
|
+
cause: input.inApp
|
|
56
|
+
? `"${input.code}" is neither a framework code nor one this app declares with defineError()`
|
|
57
|
+
: `"${input.code}" is not a framework code, and an app's own defineError() codes resolve only inside that app`,
|
|
58
|
+
fix: input.inApp
|
|
59
|
+
? `grep -rn ${quoteArg(input.code)} apps packages # an app code is a defineError({ code }) in a slice's errors.ts; x errors list --json lists the framework's`
|
|
60
|
+
: "x errors list --json # the framework's codes; an app's own defineError() codes answer when this runs inside the app (or with --cwd set to its directory)",
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|