@ultimat3/cli 31.29.0 → 31.31.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/package.json +30 -30
- package/src/app-migrations-verdict.ts +2 -1
- package/src/ci-runs.ts +20 -5
- package/src/cmd-db-recount.ts +38 -43
- package/src/cmd-db-spec.ts +3 -2
- package/src/cmd-db-status.ts +80 -0
- package/src/cmd-db.ts +4 -2
- package/src/cmd-doctor.ts +14 -3
- package/src/db-client-displace.ts +65 -0
- package/src/db-diagnostics.ts +25 -28
- package/src/db-status.ts +185 -0
- package/src/mcp-errors.ts +3 -3
- package/src/messages-db.ts +12 -0
- package/src/runtime-queue.ts +20 -2
- package/wiki/CLI-Reference.md +2 -0
- package/wiki/Known-Gaps.md +30 -0
- package/wiki/Scraping.md +20 -0
- package/wiki/Stability.md +21 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.31.0",
|
|
4
4
|
"description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -52,35 +52,35 @@
|
|
|
52
52
|
"dev": "bun run src/bin.ts dev"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@babel/core": "^8.0.
|
|
56
|
-
"@ultimat3/action": "31.
|
|
57
|
-
"@ultimat3/admin": "31.
|
|
58
|
-
"@ultimat3/ai": "31.
|
|
59
|
-
"@ultimat3/auth": "31.
|
|
60
|
-
"@ultimat3/cache": "31.
|
|
61
|
-
"@ultimat3/core": "31.
|
|
62
|
-
"@ultimat3/db": "31.
|
|
63
|
-
"@ultimat3/entity": "31.
|
|
64
|
-
"@ultimat3/flags": "31.
|
|
65
|
-
"@ultimat3/http": "31.
|
|
66
|
-
"@ultimat3/i18n": "31.
|
|
67
|
-
"@ultimat3/jobs": "31.
|
|
68
|
-
"@ultimat3/mail": "31.
|
|
69
|
-
"@ultimat3/manifest": "31.
|
|
70
|
-
"@ultimat3/mcp": "31.
|
|
71
|
-
"@ultimat3/money": "31.
|
|
72
|
-
"@ultimat3/notify": "31.
|
|
73
|
-
"@ultimat3/policy": "31.
|
|
74
|
-
"@ultimat3/pwa": "31.
|
|
75
|
-
"@ultimat3/query": "31.
|
|
76
|
-
"@ultimat3/realtime": "31.
|
|
77
|
-
"@ultimat3/render": "31.
|
|
78
|
-
"@ultimat3/schema": "31.
|
|
79
|
-
"@ultimat3/scraping": "31.
|
|
80
|
-
"@ultimat3/seo": "31.
|
|
81
|
-
"@ultimat3/storage": "31.
|
|
82
|
-
"@ultimat3/testing": "31.
|
|
83
|
-
"@ultimat3/time": "31.
|
|
55
|
+
"@babel/core": "^8.0.10",
|
|
56
|
+
"@ultimat3/action": "31.31.0",
|
|
57
|
+
"@ultimat3/admin": "31.31.0",
|
|
58
|
+
"@ultimat3/ai": "31.31.0",
|
|
59
|
+
"@ultimat3/auth": "31.31.0",
|
|
60
|
+
"@ultimat3/cache": "31.31.0",
|
|
61
|
+
"@ultimat3/core": "31.31.0",
|
|
62
|
+
"@ultimat3/db": "31.31.0",
|
|
63
|
+
"@ultimat3/entity": "31.31.0",
|
|
64
|
+
"@ultimat3/flags": "31.31.0",
|
|
65
|
+
"@ultimat3/http": "31.31.0",
|
|
66
|
+
"@ultimat3/i18n": "31.31.0",
|
|
67
|
+
"@ultimat3/jobs": "31.31.0",
|
|
68
|
+
"@ultimat3/mail": "31.31.0",
|
|
69
|
+
"@ultimat3/manifest": "31.31.0",
|
|
70
|
+
"@ultimat3/mcp": "31.31.0",
|
|
71
|
+
"@ultimat3/money": "31.31.0",
|
|
72
|
+
"@ultimat3/notify": "31.31.0",
|
|
73
|
+
"@ultimat3/policy": "31.31.0",
|
|
74
|
+
"@ultimat3/pwa": "31.31.0",
|
|
75
|
+
"@ultimat3/query": "31.31.0",
|
|
76
|
+
"@ultimat3/realtime": "31.31.0",
|
|
77
|
+
"@ultimat3/render": "31.31.0",
|
|
78
|
+
"@ultimat3/schema": "31.31.0",
|
|
79
|
+
"@ultimat3/scraping": "31.31.0",
|
|
80
|
+
"@ultimat3/seo": "31.31.0",
|
|
81
|
+
"@ultimat3/storage": "31.31.0",
|
|
82
|
+
"@ultimat3/testing": "31.31.0",
|
|
83
|
+
"@ultimat3/time": "31.31.0",
|
|
84
84
|
"babel-preset-solid": "^1.9.16"
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -79,6 +79,7 @@ export function reportAppMigrationsAhead(unknown: readonly string[]): void {
|
|
|
79
79
|
logger.warn('ultimate app migrations ahead', {
|
|
80
80
|
migrations: unknown.length,
|
|
81
81
|
cause: `the database holds ${String(unknown.length)} migration(s) this build does not ship — ${named(unknown)}: a newer release migrated and this one is mid-rollout or rolled back`,
|
|
82
|
-
|
|
82
|
+
// The read that lists them beside the framework stamp, and writes nothing.
|
|
83
|
+
fix: 'x db status --json',
|
|
83
84
|
});
|
|
84
85
|
}
|
package/src/ci-runs.ts
CHANGED
|
@@ -11,10 +11,20 @@ import type { GhRepo } from './gh-target';
|
|
|
11
11
|
export const RUN_FIELDS =
|
|
12
12
|
'databaseId,status,conclusion,headBranch,displayTitle,workflowName,url,createdAt,headSha';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* A run's, a job's or a step's verdict as `gh` prints it: `""` until it has one (captured
|
|
16
|
+
* 2026-11-16, `ci-runs-fixture.ts`), so the empty string is read here and becomes `null` below.
|
|
17
|
+
*/
|
|
18
|
+
const VERDICT = t.nullable(t.string.min(0));
|
|
19
|
+
|
|
20
|
+
/** `""` is no verdict yet: the one spelling the rest of `x ci` reads is `null`. */
|
|
21
|
+
const verdictOf = (conclusion: string | null): string | null =>
|
|
22
|
+
conclusion === '' ? null : conclusion;
|
|
23
|
+
|
|
14
24
|
const RUN_ROW = t.object({
|
|
15
25
|
databaseId: t.number,
|
|
16
26
|
status: t.string,
|
|
17
|
-
conclusion:
|
|
27
|
+
conclusion: VERDICT,
|
|
18
28
|
headBranch: t.string,
|
|
19
29
|
headSha: t.string,
|
|
20
30
|
displayTitle: t.string,
|
|
@@ -23,12 +33,12 @@ const RUN_ROW = t.object({
|
|
|
23
33
|
createdAt: t.string,
|
|
24
34
|
});
|
|
25
35
|
|
|
26
|
-
const STEP = t.object({ name: t.string, conclusion:
|
|
36
|
+
const STEP = t.object({ name: t.string, conclusion: VERDICT, number: t.number });
|
|
27
37
|
|
|
28
38
|
const JOB = t.object({
|
|
29
39
|
name: t.string,
|
|
30
40
|
status: t.string,
|
|
31
|
-
conclusion:
|
|
41
|
+
conclusion: VERDICT,
|
|
32
42
|
url: t.string,
|
|
33
43
|
steps: t.array(STEP),
|
|
34
44
|
});
|
|
@@ -97,7 +107,7 @@ interface RunRow {
|
|
|
97
107
|
const runOf = (row: RunRow): CiRun => ({
|
|
98
108
|
id: row.databaseId,
|
|
99
109
|
status: row.status,
|
|
100
|
-
conclusion: row.conclusion,
|
|
110
|
+
conclusion: verdictOf(row.conclusion),
|
|
101
111
|
branch: row.headBranch,
|
|
102
112
|
headSha: row.headSha,
|
|
103
113
|
title: row.displayTitle,
|
|
@@ -170,7 +180,12 @@ export async function viewRun(
|
|
|
170
180
|
RUN_VIEW,
|
|
171
181
|
{ label: `gh run view ${id}`, fix: `x ci --run ${id} --repo ${repo.slug} --json` },
|
|
172
182
|
);
|
|
173
|
-
|
|
183
|
+
const jobs = viewed.jobs.map((job) => ({
|
|
184
|
+
...job,
|
|
185
|
+
conclusion: verdictOf(job.conclusion),
|
|
186
|
+
steps: job.steps.map((step) => ({ ...step, conclusion: verdictOf(step.conclusion) })),
|
|
187
|
+
}));
|
|
188
|
+
return { run: runOf(viewed), jobs };
|
|
174
189
|
}
|
|
175
190
|
|
|
176
191
|
/**
|
package/src/cmd-db-recount.ts
CHANGED
|
@@ -6,14 +6,11 @@
|
|
|
6
6
|
import { finiteCount } from '@ultimat3/core';
|
|
7
7
|
import type { CounterDescriptionLike, DbClient } from '@ultimat3/db';
|
|
8
8
|
import {
|
|
9
|
-
baseClient,
|
|
10
9
|
CROSS_TENANT_SETTING,
|
|
11
|
-
dbClientInstalled,
|
|
12
10
|
recountBatchSql,
|
|
13
11
|
recountDriftBatchSql,
|
|
14
12
|
recountLockSql,
|
|
15
13
|
recountWindowSql,
|
|
16
|
-
setDbClient,
|
|
17
14
|
setLocal,
|
|
18
15
|
withTransaction,
|
|
19
16
|
} from '@ultimat3/db';
|
|
@@ -21,6 +18,7 @@ import { countersOf, describeCounter, getEntity } from '@ultimat3/entity';
|
|
|
21
18
|
import { loadApp } from './app-load';
|
|
22
19
|
import { loadAppRuntime } from './app-runtime';
|
|
23
20
|
import type { CommandContext } from './command';
|
|
21
|
+
import { withOpenedDb } from './db-client-displace';
|
|
24
22
|
import { DevAlreadyRunningError, liveDevLock } from './dev-lock';
|
|
25
23
|
import { BadFlagError } from './errors';
|
|
26
24
|
import { msg } from './messages';
|
|
@@ -156,44 +154,41 @@ async function recount(ctx: CommandContext, root: string): Promise<CommandResult
|
|
|
156
154
|
});
|
|
157
155
|
}
|
|
158
156
|
}
|
|
159
|
-
// `startDb` installs its client as the process's `db()
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
await started.client.close();
|
|
197
|
-
await started.replica?.close();
|
|
198
|
-
}
|
|
157
|
+
// `startDb` installs its client as the process's `db()`; `withOpenedDb` puts back what was there
|
|
158
|
+
// (closing a lazy default it dropped) and closes both pools, as `db-diagnostics.ts` does.
|
|
159
|
+
return withOpenedDb(
|
|
160
|
+
() => startDb(services, ctx.env),
|
|
161
|
+
async (client) => {
|
|
162
|
+
const report = await recountInBatches(client, parent.$table, counter, { write });
|
|
163
|
+
const drift = report.rows;
|
|
164
|
+
return {
|
|
165
|
+
ok: findings.length === 0 && (write || report.drifted === 0),
|
|
166
|
+
command: 'db',
|
|
167
|
+
summary: msg(write ? 'cli.db.recount.repaired' : 'cli.db.recount.drift', {
|
|
168
|
+
target,
|
|
169
|
+
count: report.drifted,
|
|
170
|
+
}),
|
|
171
|
+
findings: [
|
|
172
|
+
...findings,
|
|
173
|
+
...(write || report.drifted === 0
|
|
174
|
+
? []
|
|
175
|
+
: [
|
|
176
|
+
{
|
|
177
|
+
code: 'X_LIFECYCLE_TRIGGER_MISSING',
|
|
178
|
+
cause: `${report.drifted} row(s) of ${parent.$table} hold a ${counter.column} that is not the count of ${counter.table} rows pointing at them`,
|
|
179
|
+
fix: `x db recount ${quoteArg(target)} --write --json`,
|
|
180
|
+
},
|
|
181
|
+
]),
|
|
182
|
+
],
|
|
183
|
+
lines: drift.map((row) => ` ${row.key} stored ${row.stored} actual ${row.actual}`),
|
|
184
|
+
data: {
|
|
185
|
+
target,
|
|
186
|
+
write,
|
|
187
|
+
drifted: report.drifted,
|
|
188
|
+
batches: report.batches,
|
|
189
|
+
rows: drift.map((row) => ({ ...row })),
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
},
|
|
193
|
+
);
|
|
199
194
|
}
|
package/src/cmd-db-spec.ts
CHANGED
|
@@ -13,13 +13,14 @@ export const DB_SUBCOMMANDS = [
|
|
|
13
13
|
'backfill',
|
|
14
14
|
'diagnostics',
|
|
15
15
|
'recount',
|
|
16
|
+
'status',
|
|
16
17
|
] as const;
|
|
17
18
|
|
|
18
19
|
export const dbSpec: CommandSpec = {
|
|
19
20
|
name: 'db',
|
|
20
|
-
summary: 'gen, migrate, reset, seed, branch, backfill, diagnostics, recount',
|
|
21
|
+
summary: 'gen, migrate, reset, seed, branch, backfill, diagnostics, recount, status',
|
|
21
22
|
usage:
|
|
22
|
-
'x db gen "add publish_at" [--drop-redundant] | migrate | reset | seed [<name>] [--tier reference|dev] [--dry-run] | seed --generate [--rows n] [--seed n] [--dry-run] | branch list | branch create <name> | branch delete <name> | backfill [<name>|--all] [--write] [--force] | backfill --pending | backfill --list [--name n] [--status s] [--limit n] | diagnostics [--limit n] | recount <entity>.<column> [--write]',
|
|
23
|
+
'x db gen "add publish_at" [--drop-redundant] | migrate | reset | seed [<name>] [--tier reference|dev] [--dry-run] | seed --generate [--rows n] [--seed n] [--dry-run] | branch list | branch create <name> | branch delete <name> | backfill [<name>|--all] [--write] [--force] | backfill --pending | backfill --list [--name n] [--status s] [--limit n] | diagnostics [--limit n] | recount <entity>.<column> [--write] | status',
|
|
23
24
|
requiresApp: true,
|
|
24
25
|
subcommands: DB_SUBCOMMANDS,
|
|
25
26
|
// Declared from the constant `runBranchCommand` validates against, never a second literal: it
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// `x db status`: one read of the app's database — the framework stamp and the `x_migrations`
|
|
2
|
+
// ledger — judged by `db-status.ts` against the migrations this build ships. No DDL, no ledger
|
|
3
|
+
// write, no migrate lock: `startDb`, never `startQueue` (the queue's boot applies framework
|
|
4
|
+
// tables). An embedded database never created is reported as such, never initialised to say so.
|
|
5
|
+
|
|
6
|
+
// why: Bun has no directory probe — `Bun.file().exists()` answers about a file.
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
|
+
import {
|
|
9
|
+
type DbClient,
|
|
10
|
+
isLedgerMissing,
|
|
11
|
+
pgliteDataDir,
|
|
12
|
+
ROLLBACK_ALLOW_DESTRUCTIVE_ENV,
|
|
13
|
+
readLedger,
|
|
14
|
+
} from '@ultimat3/db';
|
|
15
|
+
import type { CommandContext } from './command';
|
|
16
|
+
import { withOpenedDb } from './db-client-displace';
|
|
17
|
+
import {
|
|
18
|
+
type DbStatusRead,
|
|
19
|
+
dbStatus,
|
|
20
|
+
dbStatusFindings,
|
|
21
|
+
dbStatusJson,
|
|
22
|
+
dbStatusLines,
|
|
23
|
+
} from './db-status';
|
|
24
|
+
import { DevAlreadyRunningError, liveDevLock } from './dev-lock';
|
|
25
|
+
import { readStamp, thisBuild } from './framework-schema-apply';
|
|
26
|
+
import { msg } from './messages';
|
|
27
|
+
import { readMigrations } from './migrations';
|
|
28
|
+
import type { CommandResult } from './output';
|
|
29
|
+
import { resolveServices } from './runtime-bindings';
|
|
30
|
+
import { startDb } from './runtime-queue';
|
|
31
|
+
|
|
32
|
+
/** The stamp, then the ledger; a missing ledger (`42P01`) is a fact, every other failure throws. */
|
|
33
|
+
export async function readDbStatus(client: DbClient): Promise<DbStatusRead> {
|
|
34
|
+
const stamp = await readStamp(client);
|
|
35
|
+
try {
|
|
36
|
+
return { stamp, ledger: await readLedger(client) };
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (!isLedgerMissing(error)) throw error;
|
|
39
|
+
return { stamp, ledger: undefined };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Opens the database the way every role does, reads once, and puts the process's `db()` back. */
|
|
44
|
+
async function readFromApp(ctx: CommandContext, root: string): Promise<DbStatusRead> {
|
|
45
|
+
const services = resolveServices(root, ctx.env);
|
|
46
|
+
if (services.db.mode === 'embedded') {
|
|
47
|
+
if (!existsSync(pgliteDataDir(services.db.url))) return { stamp: null, ledger: undefined };
|
|
48
|
+
// PGlite's data directory has one writer: an `x dev` holding it is refused, as diagnostics is.
|
|
49
|
+
const holder = liveDevLock(services.stateDir);
|
|
50
|
+
if (holder !== undefined) {
|
|
51
|
+
throw new DevAlreadyRunningError({
|
|
52
|
+
lock: holder,
|
|
53
|
+
stateDir: services.stateDir,
|
|
54
|
+
embeddedDb: true,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return withOpenedDb(() => startDb(services, ctx.env), readDbStatus);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function runDbStatus(ctx: CommandContext, root: string): Promise<CommandResult> {
|
|
62
|
+
const migrations = await readMigrations(root);
|
|
63
|
+
const read = await readFromApp(ctx, root);
|
|
64
|
+
const status = dbStatus(read, migrations, thisBuild());
|
|
65
|
+
const findings = dbStatusFindings(status, migrations, read.ledger, {
|
|
66
|
+
allow: ctx.env[ROLLBACK_ALLOW_DESTRUCTIVE_ENV],
|
|
67
|
+
appVersion: ctx.env['APP_VERSION'],
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
ok: findings.length === 0,
|
|
71
|
+
command: 'db',
|
|
72
|
+
summary:
|
|
73
|
+
findings.length === 0
|
|
74
|
+
? msg('cli.db.status.current')
|
|
75
|
+
: msg('cli.db.status.behind', { count: findings.length }),
|
|
76
|
+
findings,
|
|
77
|
+
lines: dbStatusLines(status),
|
|
78
|
+
data: dbStatusJson(status),
|
|
79
|
+
};
|
|
80
|
+
}
|
package/src/cmd-db.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// `x db gen|migrate|reset|seed|studio|branch|backfill|diagnostics|recount` — everything that touches the
|
|
1
|
+
// `x db gen|migrate|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`.
|
|
4
|
+
// is `db-diagnostics.ts`, `status` is `cmd-db-status.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
|
|
@@ -20,6 +20,7 @@ import { runBackfillCommand } from './cmd-db-backfill';
|
|
|
20
20
|
import { runBranchCommand } from './cmd-db-branch';
|
|
21
21
|
import { runRecountCommand } from './cmd-db-recount';
|
|
22
22
|
import { DB_SUBCOMMANDS, dbSpec } from './cmd-db-spec';
|
|
23
|
+
import { runDbStatus } from './cmd-db-status';
|
|
23
24
|
import type { CliCommand, CommandContext } from './command';
|
|
24
25
|
import { runDiagnostics } from './db-diagnostics';
|
|
25
26
|
import { stepFinding } from './db-finding';
|
|
@@ -71,6 +72,7 @@ export const dbCommand: CliCommand = {
|
|
|
71
72
|
if (sub === 'branch') return runBranchCommand(ctx, root);
|
|
72
73
|
if (sub === 'diagnostics') return runDiagnostics(ctx, root);
|
|
73
74
|
if (sub === 'recount') return runRecountCommand(ctx, root);
|
|
75
|
+
if (sub === 'status') return runDbStatus(ctx, root);
|
|
74
76
|
|
|
75
77
|
// Never a fall-through. This used to end `return runBranch(ctx, root, argument ?? 'preview')`,
|
|
76
78
|
// so ANY subcommand the parser had not already refused was reinterpreted as a branch NAME and
|
package/src/cmd-doctor.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { CliCommand, CommandContext } from './command';
|
|
|
10
10
|
import { advisoryFloorFindings } from './doctor-advisory-floors';
|
|
11
11
|
import { appUrlFindings } from './doctor-app-url';
|
|
12
12
|
import { authStorageFindings } from './doctor-auth';
|
|
13
|
+
import type { BrowserFact } from './doctor-browser';
|
|
13
14
|
import { browserProbe, browserWarnings, withBrowserReport } from './doctor-browser';
|
|
14
15
|
import { chartAlertsProbe, NOTHING_MISSING, withChartAlertsListing } from './doctor-chart-alerts';
|
|
15
16
|
import { coverageExcludesProbe, withCoverageExcludes } from './doctor-coverage';
|
|
@@ -144,8 +145,17 @@ export async function runDoctor(probe: DoctorProbe): Promise<readonly Finding[]>
|
|
|
144
145
|
return findings;
|
|
145
146
|
}
|
|
146
147
|
|
|
148
|
+
/**
|
|
149
|
+
* The report's probe: the verdict's, and the browser listed beside it. Its own member, never asked
|
|
150
|
+
* from inside the report: a `chrome --version` there was every report test's, on its clock.
|
|
151
|
+
*/
|
|
152
|
+
export interface DoctorReportProbe extends DoctorProbe {
|
|
153
|
+
/** Which Chrome the e2e driver would launch, and whether one is required (`doctor-browser.ts`). */
|
|
154
|
+
browser(): Promise<BrowserFact | undefined>;
|
|
155
|
+
}
|
|
156
|
+
|
|
147
157
|
/** The whole report over one probe: the verdict, then the listings and warnings beside it. */
|
|
148
|
-
export async function reportDoctor(probe:
|
|
158
|
+
export async function reportDoctor(probe: DoctorReportProbe): Promise<CommandResult> {
|
|
149
159
|
// Asked once: `runDoctor` reads the verdict and the report beside it reads the numbers.
|
|
150
160
|
const pooler = probe.root === undefined ? NO_POOLER_FACT : await probe.pooler();
|
|
151
161
|
const findings = await runDoctor({ ...probe, pooler: async () => pooler });
|
|
@@ -189,7 +199,7 @@ export async function reportDoctor(probe: DoctorProbe): Promise<CommandResult> {
|
|
|
189
199
|
);
|
|
190
200
|
// Last, and beside the verdict on `main`: the 31.16.0 checks (`doctor-warnings.ts`).
|
|
191
201
|
// A copy of a shipped guard among them (`X_GUARD_VENDORED`): a warning, so exit stays.
|
|
192
|
-
const browser = await
|
|
202
|
+
const browser = await probe.browser();
|
|
193
203
|
return withDoctorWarnings(withBrowserReport(reminded, browser), [
|
|
194
204
|
...(await doctorWarnings(probe)),
|
|
195
205
|
...vendoredGuardWarnings(guardEntries),
|
|
@@ -205,6 +215,7 @@ export const doctorCommand: CliCommand = {
|
|
|
205
215
|
spec: doctorSpec,
|
|
206
216
|
run(ctx: CommandContext): Promise<CommandResult> {
|
|
207
217
|
const port = doctorPort(ctx.args, ctx.env);
|
|
208
|
-
|
|
218
|
+
const probe = probeFor(ctx.cwd, ctx.bunVersion, port, ctx.env);
|
|
219
|
+
return reportDoctor({ ...probe, browser: () => browserProbe(probe.root, ctx.env) });
|
|
209
220
|
},
|
|
210
221
|
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// A CLI command that opens the app's database for one run (`startDb`) and owes the process its
|
|
2
|
+
// `db()` back: an installed client as it was, a lazily built default it dropped closed — never
|
|
3
|
+
// orphaned — and both of its own pools closed whatever the run did.
|
|
4
|
+
|
|
5
|
+
import { logger, renderThrowable } from '@ultimat3/core';
|
|
6
|
+
import { ambientClient, type DbClient, dbClientInstalled, setDbClient } from '@ultimat3/db';
|
|
7
|
+
|
|
8
|
+
const closable = (client: DbClient): client is DbClient & { close(): Promise<void> } =>
|
|
9
|
+
'close' in client && typeof client.close === 'function';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Read BEFORE the command installs anything; call what it returns once it is done. `db()` is put
|
|
13
|
+
* back synchronously on the call, so a caller may settle the returned close beside its own.
|
|
14
|
+
*/
|
|
15
|
+
export function displaceAmbient(): () => Promise<void> {
|
|
16
|
+
const installed = dbClientInstalled();
|
|
17
|
+
const previous = ambientClient();
|
|
18
|
+
return async () => {
|
|
19
|
+
if (installed) {
|
|
20
|
+
setDbClient(previous);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
setDbClient(undefined);
|
|
24
|
+
if (previous !== undefined && closable(previous)) await previous.close();
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface Closable {
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Open, run, then put `db()` back and close every pool whatever happened. The open is inside the
|
|
34
|
+
* guarded scope (`startDb` installs before it returns); one rejected close never skips another.
|
|
35
|
+
* The run's own failure is what is thrown, a close failure beside it is logged; after a good run a
|
|
36
|
+
* close failure is thrown.
|
|
37
|
+
*/
|
|
38
|
+
export async function withOpenedDb<T>(
|
|
39
|
+
open: () => { readonly client: DbClient & Closable; readonly replica?: Closable | undefined },
|
|
40
|
+
run: (client: DbClient) => Promise<T>,
|
|
41
|
+
): Promise<T> {
|
|
42
|
+
const restore = displaceAmbient();
|
|
43
|
+
let opened: ReturnType<typeof open> | undefined;
|
|
44
|
+
let outcome: { readonly value: T } | { readonly error: unknown };
|
|
45
|
+
try {
|
|
46
|
+
opened = open();
|
|
47
|
+
outcome = { value: await run(opened.client) };
|
|
48
|
+
} catch (error) {
|
|
49
|
+
outcome = { error };
|
|
50
|
+
}
|
|
51
|
+
const closed = await Promise.allSettled([
|
|
52
|
+
restore(),
|
|
53
|
+
opened?.client.close(),
|
|
54
|
+
opened?.replica?.close(),
|
|
55
|
+
]);
|
|
56
|
+
const rejected = closed.flatMap((one) => (one.status === 'rejected' ? [one.reason] : []));
|
|
57
|
+
if ('error' in outcome) {
|
|
58
|
+
for (const reason of rejected) {
|
|
59
|
+
logger.warn('x db could not close its database', { cause: renderThrowable(reason) });
|
|
60
|
+
}
|
|
61
|
+
throw outcome.error;
|
|
62
|
+
}
|
|
63
|
+
if (rejected.length > 0) throw rejected[0];
|
|
64
|
+
return outcome.value;
|
|
65
|
+
}
|
package/src/db-diagnostics.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// `dbDiagnostics()` and renders one table per answered section. Facts, never a verdict: exit 0
|
|
3
3
|
// whatever they say, and the one failure is a connection that never opens (`X_DB_UNAVAILABLE`).
|
|
4
4
|
|
|
5
|
-
import { baseClient, dbClientInstalled, setDbClient } from '@ultimat3/db';
|
|
6
5
|
import {
|
|
7
6
|
type DbDiagnostics,
|
|
8
7
|
type DiagnosticSection,
|
|
9
8
|
dbDiagnostics,
|
|
10
9
|
} from '@ultimat3/db/diagnostics';
|
|
11
10
|
import type { CommandContext } from './command';
|
|
11
|
+
import { withOpenedDb } from './db-client-displace';
|
|
12
12
|
import { DevAlreadyRunningError, liveDevLock } from './dev-lock';
|
|
13
13
|
import { readIntFlag } from './flag-number';
|
|
14
14
|
import { msg } from './messages';
|
|
@@ -89,31 +89,28 @@ export async function runDiagnostics(ctx: CommandContext, root: string): Promise
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
// `startDb` installs its client as the process's `db()
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
await started.client.close();
|
|
117
|
-
await started.replica?.close();
|
|
118
|
-
}
|
|
92
|
+
// `startDb` installs its client as the process's `db()`; `withOpenedDb` puts back what was there
|
|
93
|
+
// (closing a lazy default it dropped) and closes both pools, or every later `db()` in an
|
|
94
|
+
// embedding process reaches a dead pool.
|
|
95
|
+
return withOpenedDb(
|
|
96
|
+
() => startDb(services, ctx.env),
|
|
97
|
+
async (client) => {
|
|
98
|
+
// Embedded, the probe IS the boot — a WASM compile and an initdb, 12.6 s cold under coverage —
|
|
99
|
+
// so the 3 s probe wait answered a healthy database X_DB_UNAVAILABLE. A server keeps the default.
|
|
100
|
+
const deadlineMs =
|
|
101
|
+
services.db.mode === 'embedded' ? EMBEDDED_DIAGNOSTICS_DEADLINE_MS : undefined;
|
|
102
|
+
const report = await dbDiagnostics({ client, limit, deadlineMs });
|
|
103
|
+
const sections = Object.values(report);
|
|
104
|
+
return {
|
|
105
|
+
ok: true,
|
|
106
|
+
command: 'db',
|
|
107
|
+
summary: msg('cli.db.diagnostics.done', {
|
|
108
|
+
available: sections.filter((section) => section.available).length,
|
|
109
|
+
total: sections.length,
|
|
110
|
+
}),
|
|
111
|
+
lines: renderDiagnostics(report),
|
|
112
|
+
data: diagnosticsJson(report),
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
);
|
|
119
116
|
}
|
package/src/db-status.ts
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// `x db status`'s verdict, pure: the app migrations this build ships against the `x_migrations`
|
|
2
|
+
// ledger (`appMigrationsVerdict`, the boot's own rule), an applied migration edited since, and the
|
|
3
|
+
// framework stamp (`stampVerdict`). A finding only where a serving role would wait or `x db migrate`
|
|
4
|
+
// would refuse; the read is `cmd-db-status.ts`'s.
|
|
5
|
+
|
|
6
|
+
import type { LedgerRow, Migration } from '@ultimat3/db';
|
|
7
|
+
import {
|
|
8
|
+
auditLedger,
|
|
9
|
+
ledgerAheadOfBuild,
|
|
10
|
+
migrationChecksum,
|
|
11
|
+
runningAppVersion,
|
|
12
|
+
} from '@ultimat3/db';
|
|
13
|
+
import { AppMigrationsUnappliedError, appMigrationsVerdict } from './app-migrations-verdict';
|
|
14
|
+
import {
|
|
15
|
+
aheadByMajor,
|
|
16
|
+
FrameworkSchemaUnappliedError,
|
|
17
|
+
parseStamp,
|
|
18
|
+
type StampEntry,
|
|
19
|
+
stampVerdict,
|
|
20
|
+
} from './framework-schema-stamp';
|
|
21
|
+
import { msg } from './messages';
|
|
22
|
+
import type { Finding, JsonValue } from './output';
|
|
23
|
+
import { findingFrom } from './output';
|
|
24
|
+
|
|
25
|
+
/** The one read: the stamp comment and the ledger rows, `undefined` when `x_migrations` is absent. */
|
|
26
|
+
export interface DbStatusRead {
|
|
27
|
+
readonly stamp: string | null;
|
|
28
|
+
readonly ledger: readonly LedgerRow[] | undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface FrameworkStatus {
|
|
32
|
+
readonly version: string;
|
|
33
|
+
readonly schema: string;
|
|
34
|
+
readonly applied: boolean;
|
|
35
|
+
/** The newest build the stamp records, when this one is not in it. */
|
|
36
|
+
readonly newest?: StampEntry;
|
|
37
|
+
/** The newest build, when this one is applied and the newest is another major. */
|
|
38
|
+
readonly skew?: StampEntry;
|
|
39
|
+
readonly aheadByMajor: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface DbStatus {
|
|
43
|
+
readonly shipped: readonly string[];
|
|
44
|
+
/** `null` when the ledger table does not exist: no migrate step has run here. */
|
|
45
|
+
readonly applied: readonly string[] | null;
|
|
46
|
+
readonly pending: readonly string[];
|
|
47
|
+
readonly ahead: readonly string[];
|
|
48
|
+
/** Applied, and its file now hashes otherwise. */
|
|
49
|
+
readonly edited: readonly string[];
|
|
50
|
+
readonly framework: FrameworkStatus;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function dbStatus(
|
|
54
|
+
read: DbStatusRead,
|
|
55
|
+
migrations: readonly Migration[],
|
|
56
|
+
mine: StampEntry,
|
|
57
|
+
): DbStatus {
|
|
58
|
+
const shipped = migrations.map((migration) => migration.id);
|
|
59
|
+
const applied = read.ledger?.map((row) => row.id);
|
|
60
|
+
const verdict = appMigrationsVerdict(shipped, applied);
|
|
61
|
+
const files = new Map(migrations.map((migration) => [migration.id, migration]));
|
|
62
|
+
const edited = (read.ledger ?? []).flatMap((row) => {
|
|
63
|
+
const file = files.get(row.id);
|
|
64
|
+
return file !== undefined && migrationChecksum(file) !== row.checksum ? [row.id] : [];
|
|
65
|
+
});
|
|
66
|
+
const stamp = stampVerdict(parseStamp(read.stamp), mine);
|
|
67
|
+
const framework: FrameworkStatus = stamp.applied
|
|
68
|
+
? {
|
|
69
|
+
...mine,
|
|
70
|
+
applied: true,
|
|
71
|
+
...(stamp.skew === undefined ? {} : { skew: stamp.skew }),
|
|
72
|
+
aheadByMajor: false,
|
|
73
|
+
}
|
|
74
|
+
: {
|
|
75
|
+
...mine,
|
|
76
|
+
applied: false,
|
|
77
|
+
...(stamp.newest === undefined ? {} : { newest: stamp.newest }),
|
|
78
|
+
aheadByMajor: aheadByMajor(stamp.newest, mine),
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
shipped,
|
|
82
|
+
applied: applied ?? null,
|
|
83
|
+
pending: verdict.missing,
|
|
84
|
+
ahead: verdict.unknown,
|
|
85
|
+
edited,
|
|
86
|
+
framework,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The boot's refusals and the migrator's, as findings — each the error the real path throws, so the
|
|
92
|
+
* code and fix are theirs. Ahead is not one: a serving role serves it with a warning (a rollback).
|
|
93
|
+
*/
|
|
94
|
+
export function dbStatusFindings(
|
|
95
|
+
status: DbStatus,
|
|
96
|
+
migrations: readonly Migration[],
|
|
97
|
+
ledger: DbStatusRead['ledger'],
|
|
98
|
+
options: {
|
|
99
|
+
/** `ROLLBACK_ALLOW_DESTRUCTIVE` as the migrate role would read it. */
|
|
100
|
+
readonly allow?: string | undefined;
|
|
101
|
+
/** `APP_VERSION` from the command's env, as `runMigrations` hands it to `migrate()`. */
|
|
102
|
+
readonly appVersion?: string | undefined;
|
|
103
|
+
} = {},
|
|
104
|
+
): Finding[] {
|
|
105
|
+
const findings: Finding[] = [];
|
|
106
|
+
const { framework } = status;
|
|
107
|
+
if (!framework.applied) {
|
|
108
|
+
const mine = { version: framework.version, schema: framework.schema };
|
|
109
|
+
findings.push(
|
|
110
|
+
findingFrom(new FrameworkSchemaUnappliedError({ mine, newest: framework.newest })),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
if (status.pending.length > 0) {
|
|
114
|
+
findings.push(
|
|
115
|
+
findingFrom(
|
|
116
|
+
new AppMigrationsUnappliedError({
|
|
117
|
+
missing: status.pending,
|
|
118
|
+
ledger: status.applied !== null,
|
|
119
|
+
}),
|
|
120
|
+
),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
if (ledger !== undefined) {
|
|
124
|
+
// `x db migrate`'s own two steps, in its order (migrate.ts): a ledger that is exactly a
|
|
125
|
+
// rollback is accepted and audited over its known rows; anything else ahead, and any applied
|
|
126
|
+
// migration edited since, is the conflict it refuses with — never a second spelling of either.
|
|
127
|
+
try {
|
|
128
|
+
const rolledBack = ledgerAheadOfBuild(ledger, migrations, { allow: options.allow });
|
|
129
|
+
// `migrate()`'s own reader of the build's name, so both commands' causes name the same one.
|
|
130
|
+
auditLedger(rolledBack?.known ?? ledger, migrations, runningAppVersion(options.appVersion));
|
|
131
|
+
} catch (error) {
|
|
132
|
+
findings.push(findingFrom(error));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return findings;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const idsOrNone = (ids: readonly string[]): string =>
|
|
139
|
+
ids.length === 0 ? msg('cli.db.status.none') : ids.join(', ');
|
|
140
|
+
|
|
141
|
+
export function dbStatusLines(status: DbStatus): readonly string[] {
|
|
142
|
+
const { framework } = status;
|
|
143
|
+
const newest = framework.newest ?? framework.skew;
|
|
144
|
+
return [
|
|
145
|
+
msg('cli.db.status.framework', {
|
|
146
|
+
verdict: msg(framework.applied ? 'cli.db.status.applied' : 'cli.db.status.unapplied'),
|
|
147
|
+
version: framework.version,
|
|
148
|
+
schema: framework.schema,
|
|
149
|
+
}),
|
|
150
|
+
...(newest === undefined
|
|
151
|
+
? []
|
|
152
|
+
: [msg('cli.db.status.newest', { version: newest.version, schema: newest.schema })]),
|
|
153
|
+
msg('cli.db.status.migrations', {
|
|
154
|
+
shipped: status.shipped.length,
|
|
155
|
+
applied:
|
|
156
|
+
status.applied === null ? msg('cli.db.status.noLedger') : String(status.applied.length),
|
|
157
|
+
}),
|
|
158
|
+
msg('cli.db.status.pending', { ids: idsOrNone(status.pending) }),
|
|
159
|
+
msg('cli.db.status.ahead', { ids: idsOrNone(status.ahead) }),
|
|
160
|
+
...(status.edited.length === 0
|
|
161
|
+
? []
|
|
162
|
+
: [msg('cli.db.status.edited', { ids: status.edited.join(', ') })]),
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** The `--json` body: the same facts the lines print. */
|
|
167
|
+
export function dbStatusJson(status: DbStatus): { readonly [key: string]: JsonValue } {
|
|
168
|
+
const entry = (one: StampEntry | undefined): JsonValue =>
|
|
169
|
+
one === undefined ? null : { version: one.version, schema: one.schema };
|
|
170
|
+
return {
|
|
171
|
+
shipped: [...status.shipped],
|
|
172
|
+
applied: status.applied === null ? null : [...status.applied],
|
|
173
|
+
pending: [...status.pending],
|
|
174
|
+
ahead: [...status.ahead],
|
|
175
|
+
edited: [...status.edited],
|
|
176
|
+
framework: {
|
|
177
|
+
version: status.framework.version,
|
|
178
|
+
schema: status.framework.schema,
|
|
179
|
+
applied: status.framework.applied,
|
|
180
|
+
newest: entry(status.framework.newest),
|
|
181
|
+
skew: entry(status.framework.skew),
|
|
182
|
+
aheadByMajor: status.framework.aheadByMajor,
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
}
|
package/src/mcp-errors.ts
CHANGED
|
@@ -143,9 +143,9 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
143
143
|
// The path, not `x dev`: the boot has already refused and rerunning it refuses again. The
|
|
144
144
|
// error's own `fix:` carries the resolved `.x/dev.lock`; this table cannot know the state dir.
|
|
145
145
|
X_DEV_LOCK_UNREADABLE: 'rm .x/dev.lock # then: x dev --json',
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
//
|
|
146
|
+
// `x doctor`, not `x db status`: generation failing is a reachability question, and `x db status`
|
|
147
|
+
// reads the migration ledger only. `x doctor` is already this table's answer for
|
|
148
|
+
// X_DB_STUDIO_FAILED.
|
|
149
149
|
X_DB_GEN_FAILED: 'x doctor --json # cause carries the Postgres error verbatim',
|
|
150
150
|
// Both directions resolve through the same command, and the CAUSE is what differs: one names a
|
|
151
151
|
// declaration the migrations never carried, the other one they carry and nothing declares. The
|
package/src/messages-db.ts
CHANGED
|
@@ -53,4 +53,16 @@ export const DB_MESSAGES = {
|
|
|
53
53
|
'cli.db.seed.dryRun': '{count} seed(s) would run — nothing written while --dry-run is set',
|
|
54
54
|
'cli.db.seed.failed': '{failed} of {count} seed(s) failed',
|
|
55
55
|
'cli.db.seed.none': 'no seed matched — nothing to run',
|
|
56
|
+
'cli.db.status.current': 'this database is at this build: every shipped migration applied',
|
|
57
|
+
'cli.db.status.behind': '{count} finding(s): this database is not at this build',
|
|
58
|
+
'cli.db.status.framework': 'framework {verdict} — this build {version} ({schema})',
|
|
59
|
+
'cli.db.status.applied': 'applied',
|
|
60
|
+
'cli.db.status.unapplied': 'NOT applied',
|
|
61
|
+
'cli.db.status.newest': 'newest {version} ({schema}) in the stamp',
|
|
62
|
+
'cli.db.status.migrations': 'migrations {shipped} shipped, {applied} applied',
|
|
63
|
+
'cli.db.status.noLedger': 'none (no x_migrations ledger)',
|
|
64
|
+
'cli.db.status.pending': 'pending {ids}',
|
|
65
|
+
'cli.db.status.ahead': 'ahead {ids}',
|
|
66
|
+
'cli.db.status.edited': 'edited {ids} (applied, the file hashes otherwise)',
|
|
67
|
+
'cli.db.status.none': '-',
|
|
56
68
|
} as const;
|
package/src/runtime-queue.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
postgresMeterStore,
|
|
11
11
|
requestDeadlineMs,
|
|
12
12
|
} from '@ultimat3/action';
|
|
13
|
+
import { logger, renderThrowable } from '@ultimat3/core';
|
|
13
14
|
import type { PgliteClient, PostgresClient } from '@ultimat3/db';
|
|
14
15
|
import {
|
|
15
16
|
baseClient,
|
|
@@ -92,7 +93,12 @@ export interface RunningQueue {
|
|
|
92
93
|
* neither reports anything. A default here is what let the caller forget; the type is what stops
|
|
93
94
|
* the next one. Exported for the test that proves which environment decides.
|
|
94
95
|
*/
|
|
95
|
-
export function startDb(
|
|
96
|
+
export function startDb(
|
|
97
|
+
services: DevServices,
|
|
98
|
+
env: ReplicaEnv,
|
|
99
|
+
// A seam for the one failure after the primary exists: the standby refused at construction.
|
|
100
|
+
attach: typeof attachReplica = attachReplica,
|
|
101
|
+
): StartedDb {
|
|
96
102
|
const binding = services.db;
|
|
97
103
|
// `DATABASE_POOL_MAX` from the env the boot was HANDED, for `env`'s reason below. Installing a
|
|
98
104
|
// client here means `defaultClient()` — the only other reader — never runs in a served role, so
|
|
@@ -112,7 +118,19 @@ export function startDb(services: DevServices, env: ReplicaEnv): StartedDb {
|
|
|
112
118
|
extensions: () => appExtensions(services.root),
|
|
113
119
|
})
|
|
114
120
|
: postgresClient({ url: binding.url, profile, env });
|
|
115
|
-
|
|
121
|
+
let attached: ReturnType<typeof attachReplica>;
|
|
122
|
+
try {
|
|
123
|
+
attached = attach(client, replicaUrlFor(binding, env), profile);
|
|
124
|
+
} catch (error) {
|
|
125
|
+
// The primary is built and nothing will hold it: close it here, and say so if that fails too,
|
|
126
|
+
// without letting the close's answer replace the error the caller is handed.
|
|
127
|
+
client.close().catch((closeError: unknown) => {
|
|
128
|
+
logger.warn('ultimate db could not close the primary after the replica failed', {
|
|
129
|
+
cause: renderThrowable(closeError),
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
116
134
|
setDbClient(attached.client);
|
|
117
135
|
return { client, replica: attached.replica };
|
|
118
136
|
}
|
package/wiki/CLI-Reference.md
CHANGED
|
@@ -485,6 +485,7 @@ x db gen "add publish_at" | migrate | reset
|
|
|
485
485
|
| backfill --pending [--json]
|
|
486
486
|
| backfill <name>|--all [--write] [--force] [--json]
|
|
487
487
|
| diagnostics [--limit n] [--json]
|
|
488
|
+
| status [--json]
|
|
488
489
|
```
|
|
489
490
|
|
|
490
491
|
| Subcommand | Does | Notes |
|
|
@@ -501,6 +502,7 @@ x db gen "add publish_at" | migrate | reset
|
|
|
501
502
|
| `backfill <name>` / `backfill --all` | gate one sweep (or every pending one) and enqueue it | **dry run by default** — `--write` is never implied. `--write` enqueues; the workers perform the pass, because the queue is a job's execution surface. `--all` isolates per name and continues past a failure, exiting non-zero naming each |
|
|
502
503
|
| `diagnostics` | what the database is doing now: `blockers` (each waiting `pid` and the `blockedBy` pid holding it, at `data.blockers.rows[]`), `activity`, `slowQueries`, `unusedIndexes`, `invalidIndexes`, `notValidConstraints`, `deadTuples` | **facts, never a verdict: exit 0** whatever they say. The one failure is a connection that never opens, `X_DB_UNAVAILABLE`. Every section is one catalog read in its own `BEGIN READ ONLY` with a 2 s `statement_timeout`, capped at `--limit` rows (default 20, at most 1000). A section that fails is `{ available: false, code, reason, fix }` in place and the other six still answer; `slowQueries` is unavailable until an operator installs `pg_stat_statements` (never on the embedded database). No user table is read; session SQL is printed with every literal as `?`; a credential in a reason is masked. **Whoever runs it sees the redacted SQL of every session on the app's database role** (every role, when it holds `pg_read_all_stats`): statement shape and identifiers, never values. `unusedIndexes` skips unique and primary indexes and carries `statsAgeSeconds` and `replica`. Opens the database without applying the framework tables; an embedded one `x dev` holds is refused (`X_DEV_ALREADY_RUNNING`). `--json`: `data.<section>`. Arbitrary read-only SQL is `db.query` over [`x mcp serve`](MCP-And-AI) |
|
|
503
504
|
| `recount <entity>.<column>` | compare a `countedIn` counter with the true count of its child rows | **dry run by default**: lists the drifted rows (at most 50, the count whole) and exits non-zero with `X_LIFECYCLE_TRIGGER_MISSING` when any drifted. The parent is walked in windows of 1,000 keys, in key order, each window one cross-tenant transaction (`As of 31.23`). `--write` repairs each window's drift inside its transaction and exits 0. An unknown `<entity>.<column>` is `X_CLI_BAD_FLAG`. `--json`: `data` = `{ target, write, drifted, batches, rows }` |
|
|
505
|
+
| `status` | is this database at this build? The app migrations this build ships against the `x_migrations` ledger (`pending`: shipped, not applied; `ahead`: applied, not shipped; `edited`: applied, the file now hashes otherwise), and the framework stamp (`framework.applied`, the newest build it records, a major skew) | **one read, no writes**, `As of 2026-11-15`: the stamp comment and the ledger rows, judged by the rules a serving role's boot applies (`appMigrationsVerdict`, `stampVerdict`). No DDL, no ledger created, no migrate lock; an embedded database never created is reported as nothing applied without being initialised, one `x dev` holds is refused (`X_DEV_ALREADY_RUNNING`). **Non-zero exit** with the boot's own findings when behind — `X_FRAMEWORK_SCHEMA_UNAPPLIED`, `X_APP_MIGRATIONS_UNAPPLIED` (fix `x db migrate`) — and the ledger judged as `x db migrate` judges it (`ledgerAheadOfBuild`, then `auditLedger`): an edited migration, or an `ahead` row that is not exactly a rollback — one sorting before the newest migration this build ships, or beside a pending one — is `X_MIGRATION_CONFLICT`; a rollback over a row recorded destructive is `X_MIGRATION_ROLLBACK_DESTRUCTIVE` unless `ROLLBACK_ALLOW_DESTRUCTIVE` names it. An `ahead` that is exactly a rollback exits 0: `x db migrate` accepts it and a serving role serves it with a warning (a rollback, or a rollout's old pods). `--json`: `data` = `{ shipped, applied, pending, ahead, edited, framework: { version, schema, applied, newest, skew, aheadByMajor } }`, `applied` `null` when no ledger exists |
|
|
504
506
|
|
|
505
507
|
A bare `x db backfill` is `X_CLI_BAD_FLAG` naming a shape that works: the four answer four different questions, and defaulting to one of them is the ambiguity axiom 1 refuses.
|
|
506
508
|
|
package/wiki/Known-Gaps.md
CHANGED
|
@@ -116,6 +116,36 @@ downstream app on Ultimate and of systems built without it; no row is a defect i
|
|
|
116
116
|
The test-kit row of that plan's table shipped in 23.0.0 work (`renderView`, `runJobs({ actor })`,
|
|
117
117
|
`mountIslandState`) and is not repeated here.
|
|
118
118
|
|
|
119
|
+
## Carried from the 2026-11 plans
|
|
120
|
+
|
|
121
|
+
`As of 2026-11-15`. The open rows of the
|
|
122
|
+
[2026/11/02](https://github.com/developerz-ai/ultimate/blob/main/docs/plans/2026/11/02/101-absorb-reinvented-patterns/status.yml)
|
|
123
|
+
and [2026/11/11](https://github.com/developerz-ai/ultimate/blob/main/docs/plans/2026/11/11/101-full-stack-efficiency-sweeps/status.yml)
|
|
124
|
+
plans that no slice of the
|
|
125
|
+
[live plan](https://github.com/developerz-ai/ultimate/blob/main/docs/plans/2026/11/14/101-finished-and-self-maintained/overview.md)
|
|
126
|
+
owns. Both trackers read `superseded`; each of their slice rows names where its open work went.
|
|
127
|
+
**Build** is owed work, **deferred** waits on the reason given, **rejected** will not be built. A
|
|
128
|
+
plan tracker left `in_progress` with no commit in its directory for 30 days fails the `roadmap`
|
|
129
|
+
step (`X_ROADMAP_TRACKER_STALE`), so this list, not a stale tracker, is where open work waits.
|
|
130
|
+
|
|
131
|
+
| Gap | Decision | Why, and the record |
|
|
132
|
+
|---|---|---|
|
|
133
|
+
| CI's critical path: `cli`'s own slow tests (the `x upgrade` hop, the scaffold typecheck) | deferred | speed, not correctness: every job is inside its timeout. Re-measure from the run history (`x ci runs --json`) before acting on a figure. 2026/11/02 slice 33 |
|
|
134
|
+
| The framework's own gate at `"isolate": false` | rejected | its suites exercise process-global registries on purpose; the slice's own fallback (keep the flag, record why) holds, [Testing](Testing) states it. Apps run without isolation by default. 2026/11/02 slice 31, step 4 |
|
|
135
|
+
| `x branch` previews, expand/contract renames, CRDT collaboration, mobile, more chart kinds, N-pane docking | deferred | each needs a plan of its own; none is rejected. [`90-deferred.md`](https://github.com/developerz-ai/ultimate/blob/main/docs/plans/2026/11/02/101-absorb-reinvented-patterns/90-deferred.md), "Too large for this plan" |
|
|
136
|
+
| A per-route request ceiling (`X_ISLAND_REQUESTS_OVER_BUDGET`) | deferred | requests per route are measured into `.x/build-stats.json` already; a ceiling waits for the first app that declares one. 2026/11/11 slice 11, I2 |
|
|
137
|
+
| One stylesheet per route instead of per surface | rejected | measured 23.8 kB gzip, immutable and cached across navigations; a per-route split costs requests for bytes the cache already holds. 2026/11/11 slice 11, I7 |
|
|
138
|
+
| Re-running the 2026-11-11 scaffold-and-break session (timing and error-grade tables) | deferred | evidence, not code: `scaffold-smoke` gates two scaffold shapes on every push; the session re-runs against the next change that claims a DX gain. 2026/11/11 slice 19, step 5 |
|
|
139
|
+
| Chart resource requests for the `sync` and `replicator` roles | deferred | unmeasured, so they keep their previous values; measure idle as `web`, `worker` and `scheduler` were before changing them. 2026/11/11 slice 20, O6 |
|
|
140
|
+
| Guards run on changed files only (`--changed`) | deferred | never measured; the slice's own rule drops it if the local saving is under 5 s. 2026/11/11 slice 16, step 5 |
|
|
141
|
+
| A faster `unit` step from the determinism work | rejected | measured at 2–5 %, inside run-to-run noise; determinism is the goal, not speed. 2026/11/11 slice 17 |
|
|
142
|
+
| Rolling the replicator only when its own image or config changed | deferred | the image updater repins every container naming the image and every build is a new digest, so a digest test rolls it every time; needs a per-role change signal. 2026/11/11 slice 30, I13 |
|
|
143
|
+
| Sign-in e2e against an out-of-process stub identity provider, in the reference app | deferred | the e2e suites sign in with the development viewer, which answers only a cookie-less request under `x dev`; a stub provider is a second process the e2e harness does not start. 2026/11/11 slice 18, A7 |
|
|
144
|
+
| A sync-node subscribe fixture for the deployed demo app (`dummy/social-media-clone`) | deferred | needs the app's API importable without its demo seeding side effect (`apps/web/api/index.ts`). 2026/11/11 slice 18, A8 |
|
|
145
|
+
| The reference app's three hourly task + job pairs, as `cronJob()` | build | the reference app shows every primitive once and idiomatically, and a hand-written pair beside the factory teaches the second way. 2026/11/11 slice 18, A13 |
|
|
146
|
+
| One shared `OnTheWire<T>` type | deferred | named once by the tracked-app pass with no second caller measured. 2026/11/11 slice 18 |
|
|
147
|
+
| The reference app's identity model (`members.userId` against `x_users.id == members.id`) | deferred | a schema change in the reference app with no defect behind it. 2026/11/11 slice 18 |
|
|
148
|
+
|
|
119
149
|
## Closed
|
|
120
150
|
|
|
121
151
|
**Historical:** every row is a defect that shipped; the third column is for readers still pinned below
|
package/wiki/Scraping.md
CHANGED
|
@@ -549,6 +549,26 @@ A test passes `renderer:` (any `PdfRenderer`); `chromePdfRenderer({ launch })` t
|
|
|
549
549
|
|
|
550
550
|
**The CDP launcher moved.** `findChrome`, `launchChrome`, `launchFoundChrome`, `cdpConnect`, `cdpConnectOver`, the `Cdp*Error` classes and the `CHROME_*` / `LAUNCH_*` constants live in `@ultimat3/scraping/cdp` since 31.0.0 (its own entry, importing core only), and `X_CDP_*` are registered by scraping. It is their one import path: `@ultimat3/testing` no longer re-exports them, and `E2E_BROWSER_CLOSE_MS` is `LAUNCHED_CLOSE_MS` here ([Upgrading](Upgrading) #53).
|
|
551
551
|
|
|
552
|
+
**A test launches through `launchReady`** (`As of 2026-11-15`), from the same entry: `launchChrome`, then ready once the page it was handed EXISTS — heard as `Target.targetCreated`, never polled for, so a cold start (a Windows runner) is waited for rather than read early. The test takes `launchTestMs(launchTimeoutMs)` as its deadline — `LAUNCH_TEST_MS` at the default — so the launch's own `X_CDP_LAUNCH_FAILED` is what a slow browser reports, never Bun's timeout:
|
|
553
|
+
|
|
554
|
+
```ts
|
|
555
|
+
import { test } from 'bun:test';
|
|
556
|
+
import { findChrome, LAUNCH_TEST_MS, launchReady } from '@ultimat3/scraping/cdp';
|
|
557
|
+
|
|
558
|
+
const executable = await findChrome(process.env);
|
|
559
|
+
|
|
560
|
+
test.skipIf(executable === undefined)('the page the browser was handed', async () => {
|
|
561
|
+
const browser = await launchReady({ executable: executable ?? '', timeoutMs: 20_000 });
|
|
562
|
+
try {
|
|
563
|
+
await browser.connection.send('Target.getTargets');
|
|
564
|
+
} finally {
|
|
565
|
+
await browser.close();
|
|
566
|
+
}
|
|
567
|
+
}, LAUNCH_TEST_MS);
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
`bun run scripts/launch-deadline.ts` refuses a test that awaits a launch under a deadline of its own (`X_TEST_LAUNCH_DEADLINE`).
|
|
571
|
+
|
|
552
572
|
A social card for a row published at runtime is the same shape: `page.screenshot()` of the row's
|
|
553
573
|
1200 x 630 card page, `disk().put()`, then `og: { image }` — [SEO](SEO#a-card-the-build-photographs-ogcapture)
|
|
554
574
|
covers the cards a static build takes itself. `examples/dummy`'s `runs/jobs/print-statement.ts` is
|
package/wiki/Stability.md
CHANGED
|
@@ -50,6 +50,24 @@ Never "stable forever": a covered surface can change, in a scheduled major, with
|
|
|
50
50
|
|
|
51
51
|
Ruling 2026-11-09: the clock moved from v30 to v31. v30 shipped 2026-11-07 while only our own apps ran Ultimate in production, so the window protected no one yet; v31 carries the breaks of plan 101-final-hardening-before-v31, and the window protects adopters from there.
|
|
52
52
|
|
|
53
|
+
## Supported runtimes
|
|
54
|
+
|
|
55
|
+
**A runtime is supported when something runs the gate on it.** The gate runs one Bun, one Postgres and one Solid — the pins below — on every push and pull request; `compat.yml` runs the gate's `unit` and `live` steps weekly on each other version listed (`gh workflow run compat.yml` runs it now). A red cell files or updates one `compat` issue, closed by that cell's next green run: `gh issue list --label compat --state open`. Generated from the workflow's matrix and the pins; a hand edit fails the gate's `unit` step.
|
|
56
|
+
|
|
57
|
+
<!-- generated: compat-table — bun run scripts/compat-table.ts --write -->
|
|
58
|
+
| Runtime | Version | Run by | Status |
|
|
59
|
+
|---|---|---|---|
|
|
60
|
+
| Bun | `1.4.4`, the pin (`.bun-version`) | the gate, every push and pull request (`ci.yml`) | supported |
|
|
61
|
+
| Bun | newest stable | `compat.yml` cell `bun-latest`, weekly | supported |
|
|
62
|
+
| Bun | canary | `compat.yml` cell `bun-canary`, weekly | watched: tested, never promised |
|
|
63
|
+
| Postgres | `17`, the pin (`docker/docker-compose.test.yml`) | the gate, every push and pull request (`ci.yml`) | supported |
|
|
64
|
+
| Postgres | newest `16.x` image | `compat.yml` cell `postgres-16`, weekly | supported |
|
|
65
|
+
| Postgres | newest `17.x` image | `compat.yml` cell `postgres-17`, weekly | supported |
|
|
66
|
+
| Postgres | newest `18.x` image | `compat.yml` cell `postgres-18`, weekly | supported |
|
|
67
|
+
| Solid | `1.9.18`, the pin (root `package.json`) | the gate, every push and pull request (`ci.yml`) | supported |
|
|
68
|
+
| Solid | newest `1.x` | `compat.yml` cell `solid-1`, weekly | supported |
|
|
69
|
+
<!-- end generated -->
|
|
70
|
+
|
|
53
71
|
## The support window
|
|
54
72
|
|
|
55
73
|
| Major | Status | Security fixes until |
|
|
@@ -58,7 +76,7 @@ Ruling 2026-11-09: the clock moved from v30 to v31. v30 shipped 2026-11-07 while
|
|
|
58
76
|
| the previous major | security fixes, as patches on `release/<major>.x` | 6 months after the current major's `## X.0.0` date |
|
|
59
77
|
| anything older | none | [Upgrading](Upgrading), one major per `x upgrade` run |
|
|
60
78
|
|
|
61
|
-
|
|
79
|
+
`release/<major>.x` is cut by `bun run scripts/release-maint.ts --major <N>` (idempotent, `--dry-run` first) at the major's last tag, with `maint-<N>` on every package; on it `scripts/release.ts` ships patches only (`X_RELEASE_LANE_PATCH_ONLY`). Its name is enforced: `ci.yml` and `release-tag.yml` match exactly `release/[0-9]+.x`, and `scripts/release.ts --bump` refuses any other `release/*` branch (`X_RELEASE_BRANCH_NAME`). A bump PR's own branch is `chore/release-X.Y.Z`, never `release/X.Y.Z` (#1054). Once it exists, a patch is `latest` while its major is current and `maint-<major>` once its successor ships. `scripts/dist-tag.ts` decides the tag from the registry's `latest`, and `npm publish` never runs without it.
|
|
62
80
|
|
|
63
81
|
## Deprecation
|
|
64
82
|
|
|
@@ -69,7 +87,7 @@ A removal or a rename ships its alias, marked `@deprecated`, on `main` for at le
|
|
|
69
87
|
| Branch | Holds |
|
|
70
88
|
|---|---|
|
|
71
89
|
| `main` | minors and patches only while the window is closed; a `BREAKING —` changelog entry there is refused |
|
|
72
|
-
| `next` | every breaking change waiting for the window.
|
|
90
|
+
| `next` | every breaking change waiting for the window. `next-sync.yml` merges `main` into it weekly (a conflict, or a workflow-file change the job token may not push, opens one issue with the exact command, closed by the next clean merge), so it never falls behind a fix; `ci.yml` gates every push to it. `scripts/release-due.ts` proposes it as the `chore: release X.0.0` PR once the window opens; a person merges |
|
|
73
91
|
| `release/<major>.x` | the previous major's security patches |
|
|
74
92
|
|
|
75
93
|
A change with both kinds of edit splits into two pull requests: the non-breaking half to `main`, the break to `next`.
|
|
@@ -97,4 +115,5 @@ The maintainer bot judges whether a release is due and which kind (`.dz/briefs/r
|
|
|
97
115
|
| a removal was deprecated first | `bun run scripts/deprecation-window.ts` and the gate | `X_RELEASE_UNDEPRECATED_REMOVAL` |
|
|
98
116
|
| every release from 30.0.0 opens with Highlights, the Release body | `bun run changelog-check` and the gate, over `docs/changelog/` | `X_CHANGELOG_HIGHLIGHTS_MISSING` |
|
|
99
117
|
| a bump branch is `chore/release-X.Y.Z`; `release/*` is only `release/<major>.x` | `scripts/release.ts --bump`; `ci.yml` and `release-tag.yml` filter on `release/[0-9]+.x` (`scripts/release-tag-workflow-shape.test.ts`) | `X_RELEASE_BRANCH_NAME` |
|
|
118
|
+
| the supported runtimes are the ones `compat.yml` and the gate run | `scripts/compat-table.test.ts`, in the gate's `unit` step | `X_COMPAT_TABLE_DRIFT` |
|
|
100
119
|
| a maintenance publish never moves `latest` | `scripts/dist-tag.ts` in `release.yml`; `scripts/registry-audit.ts` audits `latest` and each `maint-*` tag | `X_REGISTRY_LATEST_DRIFT` |
|