@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-db.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// `x db gen|migrate|reset|seed|studio|branch|backfill|diagnostics|recount|status` — everything that touches the
|
|
1
|
+
// `x db gen|migrate|rollback|reset|seed|studio|branch|backfill|diagnostics|recount|status` — everything that touches the
|
|
2
2
|
// database. One subcommand per line and no fall-through: a word this file does not know is refused,
|
|
3
3
|
// never re-read as an argument to the last branch. `branch` is `cmd-db-branch.ts`, `diagnostics`
|
|
4
|
-
// is `db-diagnostics.ts`, `status` is `cmd-db-status.ts`.
|
|
4
|
+
// is `db-diagnostics.ts`, `status` is `cmd-db-status.ts`, `rollback` is `cmd-db-rollback.ts`.
|
|
5
5
|
//
|
|
6
6
|
// Every subcommand here runs `@ultimat3/db`'s own engine, which is the engine `ROLE=migrate` runs
|
|
7
7
|
// (`serve.ts`): one `x_migrations` ledger, one checksum rule, one advisory lock, from a laptop to
|
|
@@ -13,19 +13,22 @@
|
|
|
13
13
|
import { rm } from 'node:fs/promises';
|
|
14
14
|
import { join } from 'node:path';
|
|
15
15
|
import { NotImplementedError, resolveEnvironment } from '@ultimat3/core';
|
|
16
|
-
import { type DriftReport, driftError, withTransaction } from '@ultimat3/db';
|
|
16
|
+
import { type DriftReport, driftError, migrationForked, withTransaction } from '@ultimat3/db';
|
|
17
|
+
import { migrationFork } from '@ultimat3/db/schema-dump';
|
|
17
18
|
import { postgresDriver } from '@ultimat3/entity';
|
|
18
19
|
import { requireAppRoot } from './app-root';
|
|
19
20
|
import { runBackfillCommand } from './cmd-db-backfill';
|
|
20
21
|
import { runBranchCommand } from './cmd-db-branch';
|
|
21
22
|
import { runRecountCommand } from './cmd-db-recount';
|
|
23
|
+
import { runRollbackCommand } from './cmd-db-rollback';
|
|
22
24
|
import { DB_SUBCOMMANDS, dbSpec } from './cmd-db-spec';
|
|
23
25
|
import { runDbStatus } from './cmd-db-status';
|
|
24
26
|
import type { CliCommand, CommandContext } from './command';
|
|
27
|
+
import { refuseAppliedEdits } from './db-applied-edits';
|
|
25
28
|
import { runDiagnostics } from './db-diagnostics';
|
|
26
29
|
import { stepFinding } from './db-finding';
|
|
27
30
|
import { generateAppMigration, unrenderedJson, unrenderedLines } from './db-generate';
|
|
28
|
-
import {
|
|
31
|
+
import { migratePass } from './db-migrate-pass';
|
|
29
32
|
import { layTemplate } from './db-reset-template';
|
|
30
33
|
import { schemaDumpLines } from './db-schema-dump';
|
|
31
34
|
import { afterWrittenMigration, refreshSchemaDump, schemaDumpJson } from './db-schema-refresh';
|
|
@@ -40,15 +43,16 @@ import {
|
|
|
40
43
|
selectSeeds,
|
|
41
44
|
} from './db-seed';
|
|
42
45
|
import { runGeneratedSeed } from './db-seed-generate';
|
|
43
|
-
import {
|
|
46
|
+
import { refuseBesideDev, refuseEmbeddedWriteBesideDev } from './dev-lock-live';
|
|
44
47
|
import { MissingSubcommandError, UnknownCommandError } from './errors';
|
|
48
|
+
import { type HeavyChild, withCheckoutLock } from './heavy';
|
|
45
49
|
import { withJobDriver } from './jobs-driver';
|
|
46
50
|
import { msg } from './messages';
|
|
51
|
+
import { readMigrations } from './migrations';
|
|
47
52
|
import type { CommandResult, Finding } from './output';
|
|
48
53
|
import { findingFrom } from './output';
|
|
49
54
|
import { flagBool, flagString } from './parse';
|
|
50
55
|
import { resolveServices } from './runtime-bindings';
|
|
51
|
-
import { runMigrations } from './serve';
|
|
52
56
|
|
|
53
57
|
export { DB_SUBCOMMANDS } from './cmd-db-spec';
|
|
54
58
|
|
|
@@ -66,6 +70,7 @@ export const dbCommand: CliCommand = {
|
|
|
66
70
|
|
|
67
71
|
if (sub === 'gen') return runGen(ctx, root, argument ?? 'change');
|
|
68
72
|
if (sub === 'migrate') return runMigrate(ctx, root, msg('cli.db.migrate.applied'));
|
|
73
|
+
if (sub === 'rollback') return runRollbackCommand(ctx, root);
|
|
69
74
|
if (sub === 'reset') return runReset(ctx, root);
|
|
70
75
|
if (sub === 'seed') return runSeed(ctx, root);
|
|
71
76
|
if (sub === 'backfill') return runBackfillCommand(ctx, root);
|
|
@@ -99,13 +104,34 @@ export const dbCommand: CliCommand = {
|
|
|
99
104
|
* exists when none does, or that nothing was written when the sidecar was.
|
|
100
105
|
*/
|
|
101
106
|
async function runGen(ctx: CommandContext, root: string, name: string): Promise<CommandResult> {
|
|
107
|
+
// One at a time per checkout, from reading the newest sidecar to writing the dump. Two overlapping
|
|
108
|
+
// runs each diffed the same sidecar and each wrote `create table` for every new entity: a chain
|
|
109
|
+
// that cannot replay. The kernel drops the lock when its holder dies, so no stale file can wedge it.
|
|
110
|
+
return withCheckoutLock({ name: 'db-gen', root, env: ctx.env }, NO_CHILD, () =>
|
|
111
|
+
generateLocked(ctx, root, name),
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** `x db gen` starts no process under the lock, so there is nothing to hand one. */
|
|
116
|
+
const NO_CHILD: HeavyChild = { env: {}, fds: [] };
|
|
117
|
+
|
|
118
|
+
async function generateLocked(
|
|
119
|
+
ctx: CommandContext,
|
|
120
|
+
root: string,
|
|
121
|
+
name: string,
|
|
122
|
+
): Promise<CommandResult> {
|
|
102
123
|
let generated: Awaited<ReturnType<typeof generateAppMigration>>;
|
|
124
|
+
let unchecked: string | undefined;
|
|
103
125
|
try {
|
|
126
|
+
// First, and before any file is written: over an applied migration edited since, this command
|
|
127
|
+
// rewrote the schema dump to match the edit and exited 0 (`db-applied-edits.ts`).
|
|
128
|
+
unchecked = await refuseAppliedEdits(root, ctx.env);
|
|
104
129
|
generated = await generateAppMigration(root, {
|
|
105
130
|
name,
|
|
106
131
|
allowDestructive: flagBool(ctx.args, 'allow-destructive'),
|
|
107
132
|
rollingUnsafe: flagBool(ctx.args, 'rolling-unsafe'),
|
|
108
133
|
dropRedundant: flagBool(ctx.args, 'drop-redundant'),
|
|
134
|
+
mergeFork: flagBool(ctx.args, 'merge-fork'),
|
|
109
135
|
});
|
|
110
136
|
} catch (error) {
|
|
111
137
|
return {
|
|
@@ -120,14 +146,22 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
|
|
|
120
146
|
// this build cannot project would make every one of those instructions unfollowable — the
|
|
121
147
|
// `x i18n add fr` failure, repeated. The count is the verdict; the gate's own `drift` step is
|
|
122
148
|
// where a red belongs, and it reads the same list to decide that `x db gen` is not the fix.
|
|
123
|
-
const lost =
|
|
149
|
+
const lost = [
|
|
150
|
+
...unrenderedLines(generated.unrendered),
|
|
151
|
+
...(unchecked === undefined ? [] : [msg('cli.db.gen.editsUnchecked', { reason: unchecked })]),
|
|
152
|
+
];
|
|
124
153
|
// After the migration, from the migrations alone: the dump is what replaying them produces, so
|
|
125
154
|
// it is rewritten on all three outcomes — `unchanged` included, which is what makes this
|
|
126
155
|
// command the `fix:` on `X_SCHEMA_DUMP_DRIFT` when a framework table or a hand edit moved it.
|
|
127
156
|
const dump = await refreshSchemaDump(root, ctx.env);
|
|
128
157
|
const dumpFindings = dump.finding === undefined ? [] : [dump.finding];
|
|
129
158
|
const migration = generated.migration;
|
|
159
|
+
const newest = generated.newest;
|
|
130
160
|
if (migration === undefined) {
|
|
161
|
+
const newestLine =
|
|
162
|
+
newest === undefined || generated.outcome === 'blocked'
|
|
163
|
+
? []
|
|
164
|
+
: [msg('cli.db.gen.newest', { id: newest })];
|
|
131
165
|
return {
|
|
132
166
|
ok: generated.findings.length === 0 && dumpFindings.length === 0,
|
|
133
167
|
command: 'db',
|
|
@@ -139,17 +173,32 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
|
|
|
139
173
|
summary:
|
|
140
174
|
generated.outcome === 'blocked'
|
|
141
175
|
? msg('cli.db.gen.blocked', { count: generated.findings.length })
|
|
142
|
-
: generated.outcome === '
|
|
143
|
-
? msg('cli.db.gen.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
176
|
+
: generated.outcome === 'fork-merged'
|
|
177
|
+
? msg('cli.db.gen.forkMerged', {
|
|
178
|
+
count: generated.forkRepairs ?? 0,
|
|
179
|
+
id: newest ?? '',
|
|
180
|
+
})
|
|
181
|
+
: generated.outcome === 'hash-recorded'
|
|
182
|
+
? msg('cli.db.gen.recorded', { file: generated.files[0] ?? '' })
|
|
183
|
+
: dump.status === 'written'
|
|
184
|
+
? msg('cli.db.gen.dumped', {
|
|
185
|
+
count: dump.written.length + dump.removed.length,
|
|
186
|
+
newest: newest ?? msg('cli.db.status.none'),
|
|
187
|
+
})
|
|
188
|
+
: msg('cli.db.gen.unchanged'),
|
|
147
189
|
findings: [...generated.findings, ...dumpFindings],
|
|
148
190
|
// `files` is what this command WROTE, so the empty array here was a false claim.
|
|
149
|
-
lines: [
|
|
191
|
+
lines: [
|
|
192
|
+
...generated.files.map((file) => ` ${file}`),
|
|
193
|
+
...schemaDumpLines(dump),
|
|
194
|
+
...newestLine,
|
|
195
|
+
...lost,
|
|
196
|
+
],
|
|
150
197
|
data: {
|
|
151
198
|
outcome: generated.outcome,
|
|
152
199
|
migration: null,
|
|
200
|
+
newest: newest ?? null,
|
|
201
|
+
forkRepairs: generated.forkRepairs ?? 0,
|
|
153
202
|
files: [...generated.files],
|
|
154
203
|
schemaHash: generated.schemaHash ?? null,
|
|
155
204
|
unrendered: unrenderedJson(generated.unrendered),
|
|
@@ -157,13 +206,30 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
|
|
|
157
206
|
},
|
|
158
207
|
};
|
|
159
208
|
}
|
|
209
|
+
const tables = generated.tables ?? [];
|
|
210
|
+
// Every migration written, never the first alone: the follow-up is a file to apply too.
|
|
211
|
+
const followUp = migration.followUp?.id;
|
|
212
|
+
const written = (): string =>
|
|
213
|
+
followUp === undefined
|
|
214
|
+
? tables.length === 0
|
|
215
|
+
? msg('cli.db.gen.written', { id: migration.id })
|
|
216
|
+
: msg('cli.db.gen.writtenTables', { id: migration.id, tables: tables.join(', ') })
|
|
217
|
+
: tables.length === 0
|
|
218
|
+
? msg('cli.db.gen.writtenPair', { id: migration.id, followUp })
|
|
219
|
+
: msg('cli.db.gen.writtenPairTables', {
|
|
220
|
+
id: migration.id,
|
|
221
|
+
followUp,
|
|
222
|
+
tables: tables.join(', '),
|
|
223
|
+
});
|
|
160
224
|
return {
|
|
161
225
|
ok: dumpFindings.length === 0,
|
|
162
226
|
command: 'db',
|
|
163
227
|
summary:
|
|
164
|
-
dumpFindings.length
|
|
165
|
-
? msg('cli.db.gen.
|
|
166
|
-
|
|
228
|
+
dumpFindings.length > 0
|
|
229
|
+
? msg('cli.db.gen.writtenDumpFailed', {
|
|
230
|
+
id: followUp === undefined ? migration.id : `${migration.id} and ${followUp}`,
|
|
231
|
+
})
|
|
232
|
+
: written(),
|
|
167
233
|
// Exit 1 with a migration on disk: the finding has to say so, or the next move is a duplicate.
|
|
168
234
|
findings: dumpFindings.map((finding) => afterWrittenMigration(finding, migration.id)),
|
|
169
235
|
lines: [...generated.files.map((file) => ` ${file}`), ...schemaDumpLines(dump), ...lost],
|
|
@@ -173,6 +239,9 @@ async function runGen(ctx: CommandContext, root: string, name: string): Promise<
|
|
|
173
239
|
// The `-- transaction: false` step written beside it, when the diff needed one.
|
|
174
240
|
followUp: migration.followUp?.id ?? null,
|
|
175
241
|
name: migration.name,
|
|
242
|
+
tables: [...tables],
|
|
243
|
+
newest: newest ?? migration.id,
|
|
244
|
+
forkRepairs: generated.forkRepairs ?? 0,
|
|
176
245
|
files: [...generated.files],
|
|
177
246
|
schemaHash: generated.schemaHash ?? null,
|
|
178
247
|
unrendered: unrenderedJson(generated.unrendered),
|
|
@@ -206,17 +275,20 @@ async function runMigrate(
|
|
|
206
275
|
summary: string,
|
|
207
276
|
): Promise<CommandResult> {
|
|
208
277
|
try {
|
|
209
|
-
|
|
210
|
-
|
|
278
|
+
// Before anything is applied: a forked chain either stops halfway through a replay or finishes
|
|
279
|
+
// and reports its own table as drift, and neither result says what happened.
|
|
280
|
+
const fork = migrationFork(await readMigrations(root));
|
|
281
|
+
if (fork !== undefined) throw migrationForked(fork);
|
|
282
|
+
// Applied here, or by the `x dev` that holds the embedded database (`db-migrate-pass.ts`).
|
|
283
|
+
const pass = await migratePass(root, ctx.env);
|
|
211
284
|
// A hand-written or pulled migration reaches the dump here, with no `x db gen` in between.
|
|
212
285
|
const dump = await refreshSchemaDump(root, ctx.env);
|
|
213
286
|
// The half a snapshot cannot hold: a trigger, function, view, type or sequence this database
|
|
214
287
|
// carries and no migration creates. Asked only when the replay produced a catalog to ask
|
|
215
288
|
// against — without one there is nothing that says what the migrations create.
|
|
216
|
-
const objects =
|
|
217
|
-
dump.catalog === undefined ? [] : await liveObjectDrift(root, ctx.env, dump.catalog);
|
|
289
|
+
const objects = dump.catalog === undefined ? [] : await pass.objects(dump.catalog);
|
|
218
290
|
const findings = [
|
|
219
|
-
...driftFindings(
|
|
291
|
+
...driftFindings(pass.drift),
|
|
220
292
|
...objects.map((difference) => findingFrom(driftError(difference))),
|
|
221
293
|
...(dump.finding === undefined ? [] : [dump.finding]),
|
|
222
294
|
];
|
|
@@ -227,10 +299,10 @@ async function runMigrate(
|
|
|
227
299
|
findings,
|
|
228
300
|
lines: schemaDumpLines(dump),
|
|
229
301
|
data: {
|
|
230
|
-
applied:
|
|
231
|
-
skipped:
|
|
232
|
-
appVersion:
|
|
233
|
-
durationMs:
|
|
302
|
+
applied: [...pass.applied],
|
|
303
|
+
skipped: pass.skipped,
|
|
304
|
+
appVersion: pass.appVersion,
|
|
305
|
+
durationMs: pass.durationMs,
|
|
234
306
|
schemaDump: schemaDumpJson(dump),
|
|
235
307
|
},
|
|
236
308
|
};
|
|
@@ -263,14 +335,7 @@ async function runReset(ctx: CommandContext, root: string): Promise<CommandResul
|
|
|
263
335
|
}
|
|
264
336
|
// A running `x dev` has this directory open: deleting it under a live embedded Postgres is data
|
|
265
337
|
// loss mid-write, not a reset. The dev lock is the one fact that says someone holds it.
|
|
266
|
-
|
|
267
|
-
if (holder !== undefined) {
|
|
268
|
-
throw new DevAlreadyRunningError({
|
|
269
|
-
lock: holder,
|
|
270
|
-
stateDir: services.stateDir,
|
|
271
|
-
embeddedDb: true,
|
|
272
|
-
});
|
|
273
|
-
}
|
|
338
|
+
await refuseBesideDev(services.stateDir);
|
|
274
339
|
const dataDir = join(services.stateDir, 'pgdata');
|
|
275
340
|
await rm(dataDir, { recursive: true, force: true });
|
|
276
341
|
// From the migrated template when it can be had (`db-reset-template.ts`); the migrate below runs
|
|
@@ -316,6 +381,13 @@ async function runSeed(ctx: CommandContext, root: string): Promise<CommandResult
|
|
|
316
381
|
data: seedPassToJson([]),
|
|
317
382
|
};
|
|
318
383
|
}
|
|
384
|
+
// A seed writes through this command's own boot: beside an `x dev` holding the embedded
|
|
385
|
+
// database that is a second PGlite writer, whose rows the holder's next write replaces.
|
|
386
|
+
await refuseEmbeddedWriteBesideDev(root, ctx.env, [
|
|
387
|
+
'db',
|
|
388
|
+
'seed',
|
|
389
|
+
...(name === undefined ? [] : [name]),
|
|
390
|
+
]);
|
|
319
391
|
return withJobDriver(root, ctx, async () => {
|
|
320
392
|
const rows = await runSeeds({
|
|
321
393
|
seeds: chosen,
|
package/src/cmd-deploy-verify.ts
CHANGED
|
@@ -28,9 +28,11 @@ import {
|
|
|
28
28
|
UNGRADED,
|
|
29
29
|
windowClosed,
|
|
30
30
|
} from './deploy-verify-grade';
|
|
31
|
+
import { workerContainers } from './deploy-verify-processes';
|
|
31
32
|
import { BadFlagError } from './errors';
|
|
32
33
|
import { msg } from './messages';
|
|
33
34
|
import type { CommandResult, Finding } from './output';
|
|
35
|
+
import { withAppTls } from './runtime-database-ssl';
|
|
34
36
|
|
|
35
37
|
/** One sample's own limit: a pod that hangs is a bad sample, never the whole wait gone. */
|
|
36
38
|
const SAMPLE_TIMEOUT_MS = 10_000;
|
|
@@ -160,11 +162,15 @@ async function readQueues(
|
|
|
160
162
|
disarm.abort();
|
|
161
163
|
}
|
|
162
164
|
const [workers, demand] = rows;
|
|
163
|
-
return
|
|
164
|
-
...
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
return {
|
|
166
|
+
...gradeQueues({
|
|
167
|
+
...input,
|
|
168
|
+
workers,
|
|
169
|
+
depth: new Map(demand.map((queue) => [queue.queue, queue.demand])),
|
|
170
|
+
}),
|
|
171
|
+
// N rows under one host is a container running N processes (`ULTIMATE_PROCESSES`).
|
|
172
|
+
containers: workerContainers(workers, input.build),
|
|
173
|
+
};
|
|
168
174
|
}
|
|
169
175
|
|
|
170
176
|
/**
|
|
@@ -276,7 +282,9 @@ export async function runDeployVerify(
|
|
|
276
282
|
// Read off the env directly: `resolveServices` falls back to the embedded database and would grade
|
|
277
283
|
// an empty one, so a CI job with no credentials would "pass" having read nothing.
|
|
278
284
|
const raw = ctx.env['DATABASE_URL'];
|
|
279
|
-
|
|
285
|
+
// Under `database.ssl` as the roles dial it: the grade reads the database they serve from.
|
|
286
|
+
const databaseUrl =
|
|
287
|
+
raw === undefined || raw.trim() === '' ? undefined : await withAppTls(root, raw, ctx.env);
|
|
280
288
|
const expected = databaseUrl === undefined ? undefined : await readExpected(root, options, deps);
|
|
281
289
|
if (expected !== undefined && expected.findings.length > 0) {
|
|
282
290
|
return failed(
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// `x docs <topic-id>` — the id a search lists, handed back, answered with that topic's BODY. A
|
|
2
|
+
// terminal search prints titles; the body existed only under `--json`, cut at the index's excerpt
|
|
3
|
+
// length, so an agent opened `node_modules/@ultimat3/<pkg>/README.md` by hand to read one section.
|
|
4
|
+
|
|
5
|
+
// why: Bun ships no path module; a package's guide is joined onto the scope it was scanned from.
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import type { DocEntry } from '@ultimat3/manifest';
|
|
8
|
+
import { wikiHeadings } from '@ultimat3/manifest';
|
|
9
|
+
import { msg } from './messages';
|
|
10
|
+
import type { CommandResult } from './output';
|
|
11
|
+
|
|
12
|
+
/** `@ultimat3/jobs` → `jobs`: a package's directory under a scope, installed or in this checkout. */
|
|
13
|
+
const directoryOf = (entry: DocEntry): string =>
|
|
14
|
+
entry.package.slice(entry.package.indexOf('/') + 1);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The whole section `entry` was cut from: its heading, its body and every subsection, to the next
|
|
18
|
+
* heading of the same or a higher level. `undefined` when the file or the heading is not found —
|
|
19
|
+
* the caller then prints the index's own excerpt, which is the same text, shorter.
|
|
20
|
+
*/
|
|
21
|
+
async function guideSection(
|
|
22
|
+
entry: DocEntry,
|
|
23
|
+
scopes: readonly string[],
|
|
24
|
+
): Promise<string | undefined> {
|
|
25
|
+
for (const scope of scopes) {
|
|
26
|
+
const file = Bun.file(join(scope, directoryOf(entry), entry.source));
|
|
27
|
+
if (!(await file.exists())) continue;
|
|
28
|
+
const markdown = await file.text();
|
|
29
|
+
const headings = wikiHeadings(markdown);
|
|
30
|
+
const index = headings.findIndex((heading) => heading.heading === entry.title);
|
|
31
|
+
const start = headings[index];
|
|
32
|
+
if (start === undefined) return undefined;
|
|
33
|
+
const end = headings.slice(index + 1).find((heading) => heading.level <= start.level);
|
|
34
|
+
const lines = markdown.split('\n');
|
|
35
|
+
return lines
|
|
36
|
+
.slice(start.line, end?.line ?? lines.length)
|
|
37
|
+
.join('\n')
|
|
38
|
+
.trimEnd();
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A module's header comment and what it exports; a guide's section, whole. */
|
|
44
|
+
async function bodyOf(entry: DocEntry, scopes: readonly string[]): Promise<string> {
|
|
45
|
+
if (entry.kind === 'guide') return (await guideSection(entry, scopes)) ?? entry.text;
|
|
46
|
+
return entry.text;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The entry whose topic id IS the query — exact, so a question never lands here by accident. */
|
|
50
|
+
export const topicNamed = (entries: readonly DocEntry[], query: string): DocEntry | undefined =>
|
|
51
|
+
entries.find((entry) => entry.topic === query);
|
|
52
|
+
|
|
53
|
+
/** One topic, answered with its body in the terminal and in `--json` alike. */
|
|
54
|
+
export async function topicResult(
|
|
55
|
+
entry: DocEntry,
|
|
56
|
+
scopes: readonly string[],
|
|
57
|
+
query: string,
|
|
58
|
+
): Promise<CommandResult> {
|
|
59
|
+
const text = await bodyOf(entry, scopes);
|
|
60
|
+
const exports =
|
|
61
|
+
entry.symbols.length === 0
|
|
62
|
+
? []
|
|
63
|
+
: ['', ` ${msg('cli.docs.exports', { list: entry.symbols.join(', ') })}`];
|
|
64
|
+
return {
|
|
65
|
+
ok: true,
|
|
66
|
+
command: 'docs',
|
|
67
|
+
summary: msg('cli.docs.found', { count: 1, query }),
|
|
68
|
+
// The package's own prose, verbatim: quoted source, not this command's wording.
|
|
69
|
+
lines: [
|
|
70
|
+
` ${entry.topic} ${entry.package}/${entry.source}`,
|
|
71
|
+
'',
|
|
72
|
+
...text.split('\n').map((line) => ` ${line}`),
|
|
73
|
+
...exports,
|
|
74
|
+
],
|
|
75
|
+
data: {
|
|
76
|
+
matches: [
|
|
77
|
+
{
|
|
78
|
+
topic: entry.topic,
|
|
79
|
+
package: entry.package,
|
|
80
|
+
version: entry.version,
|
|
81
|
+
kind: entry.kind,
|
|
82
|
+
title: entry.title,
|
|
83
|
+
text,
|
|
84
|
+
symbols: [...entry.symbols],
|
|
85
|
+
source: entry.source,
|
|
86
|
+
matched: [],
|
|
87
|
+
score: 0,
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
suggestions: [],
|
|
91
|
+
query,
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
package/src/cmd-docs.ts
CHANGED
|
@@ -4,19 +4,23 @@
|
|
|
4
4
|
// should not have to guess which of 29 packages holds the answer, and it must never be handed a
|
|
5
5
|
// URL: `node_modules` already contains every doc, because the published artifact IS the source.
|
|
6
6
|
|
|
7
|
+
// why: Bun ships no path module; the CLI's own scope is its package directory's parent.
|
|
8
|
+
import { dirname } from 'node:path';
|
|
7
9
|
import { ERROR_DOCS_URL } from '@ultimat3/core';
|
|
8
10
|
import type { DocEntry, DocHit } from '@ultimat3/manifest';
|
|
9
11
|
import { nearestTopics, searchDocs } from '@ultimat3/manifest';
|
|
10
12
|
import { DEFAULT_LIMIT, docsSpec } from './cmd-docs-spec';
|
|
13
|
+
import { topicNamed, topicResult } from './cmd-docs-topic';
|
|
11
14
|
import type { CliCommand, CommandContext } from './command';
|
|
12
15
|
import { parseWikiTopic, sectionResult } from './docs-section';
|
|
13
|
-
import { loadDocs, wikiSource } from './docs-sources';
|
|
16
|
+
import { cliPackageDir, loadDocs, wikiSource } from './docs-sources';
|
|
14
17
|
import { MissingPositionalError } from './errors';
|
|
15
18
|
import { frameworkScopeDir } from './framework-scope';
|
|
16
19
|
import { parseLimitFlag } from './jobs-report';
|
|
17
20
|
import { msg } from './messages';
|
|
18
21
|
import type { CommandResult, Finding, JsonValue } from './output';
|
|
19
22
|
import { flagString } from './parse';
|
|
23
|
+
import { quoteArg } from './shell-quote';
|
|
20
24
|
|
|
21
25
|
/** An install where the CLI cannot see its own dependency is broken, not merely undocumented. */
|
|
22
26
|
const unresolvedFinding = (): Finding => ({
|
|
@@ -69,6 +73,11 @@ function humanLines(hits: readonly DocHit[]): readonly string[] {
|
|
|
69
73
|
);
|
|
70
74
|
}
|
|
71
75
|
}
|
|
76
|
+
// What to type next for the body: the id above, handed back. Inline, as every command here is.
|
|
77
|
+
const [first] = hits;
|
|
78
|
+
if (first !== undefined) {
|
|
79
|
+
lines.push(` x docs ${quoteArg(first.entry.topic)} # ${msg('cli.docs.tryTopic')}`);
|
|
80
|
+
}
|
|
72
81
|
return lines;
|
|
73
82
|
}
|
|
74
83
|
|
|
@@ -173,6 +182,11 @@ export const docsCommand: CliCommand = {
|
|
|
173
182
|
|
|
174
183
|
const { entries, wiki } = await loadDocs(scope);
|
|
175
184
|
const findings = wiki === undefined ? [noWikiFinding()] : [];
|
|
185
|
+
// A topic id — what every search line starts with — is answered with that topic's body.
|
|
186
|
+
const named = topicNamed(entries, query);
|
|
187
|
+
if (named !== undefined) {
|
|
188
|
+
return topicResult(named, [scope, dirname(cliPackageDir())], query);
|
|
189
|
+
}
|
|
176
190
|
// `x jobs list --limit`'s reader, and its `command` parameter exists for exactly this second
|
|
177
191
|
// caller. A local `Number.parseInt` accepted `--limit 1e9` as 1 and answered with one match,
|
|
178
192
|
// and fell silently through to the default for `abc`, `0` and `-3` — a bound other than the one
|