@ultimat3/cli 31.16.0 → 31.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -2
- package/package.json +29 -29
- package/src/cache-graph.ts +67 -0
- package/src/cmd-cache-spec.ts +25 -0
- package/src/cmd-cache.ts +187 -0
- package/src/cmd-config-spec.ts +23 -0
- package/src/cmd-config.ts +61 -0
- package/src/cmd-doctor.ts +3 -3
- package/src/cmd-exercise.ts +34 -10
- package/src/cmd-explain-spec.ts +24 -0
- package/src/cmd-explain.ts +201 -0
- package/src/cmd-generate-spec.ts +3 -3
- package/src/cmd-generate.ts +2 -2
- package/src/cmd-logs-spec.ts +34 -0
- package/src/cmd-logs.ts +80 -0
- package/src/cmd-planned.ts +15 -29
- package/src/cmd-token-spec.ts +54 -0
- package/src/cmd-token.ts +173 -0
- package/src/cmd-verify-spec.ts +13 -3
- package/src/cmd-verify.ts +2 -0
- package/src/config-redact.ts +39 -0
- package/src/dev-boot-data-dir.ts +69 -0
- package/src/dev-boot.ts +26 -13
- package/src/doctor-chart-alerts.ts +50 -22
- package/src/error-codes-tooling.ts +6 -4
- package/src/error-codes.ts +2 -0
- package/src/errors.ts +8 -2
- package/src/exercise-entry-edit.ts +5 -1
- package/src/exercise-routes.ts +59 -0
- package/src/explain-capture.ts +38 -0
- package/src/generate-chart-alerts.ts +99 -45
- package/src/generate-exercise.ts +2 -2
- package/src/generate-factories.ts +133 -0
- package/src/generate-files.ts +15 -0
- package/src/generate-kinds.ts +15 -0
- package/src/mcp-db-target.ts +4 -3
- package/src/mcp-errors.ts +4 -0
- package/src/messages-gate.ts +2 -0
- package/src/messages-ops.ts +32 -0
- package/src/messages-upgrade.ts +1 -0
- package/src/messages.ts +4 -0
- package/src/otlp-export.ts +16 -2
- package/src/registry.ts +10 -0
- package/src/role-start.ts +11 -5
- package/src/runtime-services.ts +35 -19
- package/src/serve-boot-phases.ts +30 -0
- package/src/serve-boot-warnings.ts +62 -0
- package/src/serve-boot.ts +30 -11
- package/src/templates/chart-dashboard.ts +245 -0
- package/src/templates/generate-cron-job.ts +90 -0
- package/src/templates/generate-purge.ts +93 -0
- package/src/templates/generate-webhook-receiver.ts +274 -0
- package/src/templates/github/ci.yml.ts +101 -36
- package/src/templates/guard-repo-raw-sql-test.ts +174 -0
- package/src/templates/guard-repo-raw-sql.ts +115 -145
- package/src/templates/guard-unbounded-fanout.ts +170 -0
- package/src/templates/scaffold-claude-commands.ts +3 -2
- package/src/templates/scaffold-docs.ts +3 -2
- package/src/templates/scaffold-guards.ts +3 -0
- package/src/templates/scaffold-helm-alert-rules.ts +160 -0
- package/src/templates/scaffold-helm-alerts.ts +22 -87
- package/src/templates/scaffold-helm-templates.ts +2 -0
- package/src/templates/scaffold-helm.ts +20 -4
- package/src/upgrade-gate.ts +18 -6
- package/src/upgrade-report.ts +4 -0
- package/src/verify-plan.ts +127 -0
- package/wiki/Admin-Dashboard.md +6 -2
- package/wiki/CI-Parallel-Gate.md +38 -1
- package/wiki/CLI-Reference.md +95 -14
- package/wiki/Caching-And-Invalidation.md +10 -10
- package/wiki/Configuration.md +4 -2
- package/wiki/Known-Gaps.md +1 -1
- package/wiki/MCP-And-AI.md +1 -1
- package/wiki/Observability.md +6 -1
- package/wiki/Testing.md +64 -0
- package/wiki/Troubleshooting.md +3 -2
- package/wiki/Upgrading.md +10 -0
package/src/cmd-verify-spec.ts
CHANGED
|
@@ -5,14 +5,17 @@ import { DEFAULT_BASE_HELP } from './affected-base';
|
|
|
5
5
|
import type { CommandSpec } from './parse';
|
|
6
6
|
import { BUDGET_RULE, WORKER_BYTES, WORKER_CEILING, WORKER_FLOOR } from './test-workers';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* `run` is the gate (and what a bare `x verify` means); `merge` folds CI parts into its verdict;
|
|
10
|
+
* `plan` cuts the gate into those parts, as the matrix a workflow reads.
|
|
11
|
+
*/
|
|
12
|
+
export const VERIFY_SUBCOMMANDS = ['run', 'merge', 'plan'] as const;
|
|
10
13
|
|
|
11
14
|
export const verifySpec: CommandSpec = {
|
|
12
15
|
name: 'verify',
|
|
13
16
|
summary: 'the gate: typecheck, lint, boundaries, all tests, drift, contract, budgets',
|
|
14
17
|
usage:
|
|
15
|
-
'x verify [--only <step>[,<step>…] [--shard i/n [--timings file]] | --changed [--base <ref>] [--dirty]] [--workers N] [--isolate] [--json] · x verify merge <part.json…> [--json]',
|
|
18
|
+
'x verify [--only <step>[,<step>…] [--shard i/n [--timings file]] | --changed [--base <ref>] [--dirty]] [--workers N] [--isolate] [--json] · x verify merge <part.json…> [--json] · x verify plan [--parts n] [--json]',
|
|
16
19
|
requiresApp: true,
|
|
17
20
|
subcommands: VERIFY_SUBCOMMANDS,
|
|
18
21
|
defaultSubcommand: 'run',
|
|
@@ -74,5 +77,12 @@ export const verifySpec: CommandSpec = {
|
|
|
74
77
|
summary:
|
|
75
78
|
'a fresh global per test file (bun test --isolate) — off by default since 22.7; x.verify.json "isolate": true makes it the repo default',
|
|
76
79
|
},
|
|
80
|
+
{
|
|
81
|
+
name: 'parts',
|
|
82
|
+
type: 'string',
|
|
83
|
+
subcommands: ['plan'],
|
|
84
|
+
summary:
|
|
85
|
+
'runners to cut the gate into: 1, or 4 to 64 (default 4) — data.matrix is a GitHub strategy.matrix, each row an `x verify --only … [--shard i/n]`',
|
|
86
|
+
},
|
|
77
87
|
],
|
|
78
88
|
};
|
package/src/cmd-verify.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { readVerifyFloor } from './verify-floor';
|
|
|
26
26
|
import type { VerifyPart } from './verify-merge';
|
|
27
27
|
import { coverageRiders, mergeParts, parsePart, VerifyMergeInputError } from './verify-merge';
|
|
28
28
|
import { measurePace } from './verify-pace';
|
|
29
|
+
import { verifyPlanCommand } from './verify-plan';
|
|
29
30
|
import { withVerifyProgress } from './verify-progress';
|
|
30
31
|
import { runVerify } from './verify-run';
|
|
31
32
|
import type { ShardSpec, Timings } from './verify-shard';
|
|
@@ -45,6 +46,7 @@ export const verifyCommand: CliCommand = {
|
|
|
45
46
|
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
46
47
|
const root = requireAppRoot('verify', ctx.cwd).dir;
|
|
47
48
|
if (ctx.args.subcommand === 'merge') return mergeCommand(root, ctx.args.positionals, ctx.cwd);
|
|
49
|
+
if (ctx.args.subcommand === 'plan') return verifyPlanCommand(ctx.args);
|
|
48
50
|
// Every reader before the run: an unrunnable flag must be refused in milliseconds, not after
|
|
49
51
|
// `tsc -b` has spent fourteen seconds on a run the caller cannot use.
|
|
50
52
|
const workers = readWorkers(ctx.args);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The resolved `AppConfig` as JSON an operator may paste into an issue: every credential-named key
|
|
2
|
+
// and every `secret()` value replaced, a URL's password cut out of its userinfo. The key rule is
|
|
3
|
+
// core's `isRedactedKey` — the logger's — so a field the log line hides is hidden here too.
|
|
4
|
+
|
|
5
|
+
import { isRedactedKey, isSecret, REDACTED } from '@ultimat3/core';
|
|
6
|
+
import type { JsonValue } from './output';
|
|
7
|
+
|
|
8
|
+
/** `scheme://user:password@host` → `scheme://user:[redacted]@host`. The user stays: it is no secret. */
|
|
9
|
+
const USERINFO_PASSWORD = /^([a-z][a-z0-9+.-]*:\/\/[^:/@\s]*):[^@/\s]*@/i;
|
|
10
|
+
|
|
11
|
+
/** Past this depth a config is not data an operator wrote; the walk stops rather than recurse. */
|
|
12
|
+
const MAX_DEPTH = 16;
|
|
13
|
+
|
|
14
|
+
export function redactConfigValue(value: unknown, depth = 0): JsonValue {
|
|
15
|
+
if (isSecret(value)) return REDACTED;
|
|
16
|
+
if (value === null || value === undefined) return null;
|
|
17
|
+
if (typeof value === 'string') return value.replace(USERINFO_PASSWORD, `$1:${REDACTED}@`);
|
|
18
|
+
if (typeof value === 'number') return Number.isFinite(value) ? value : String(value);
|
|
19
|
+
if (typeof value === 'boolean') return value;
|
|
20
|
+
// A config may carry a callback (a `health` probe, a `resolve` hook): named, never its source.
|
|
21
|
+
if (typeof value === 'function') return '[function]';
|
|
22
|
+
if (typeof value === 'bigint' || typeof value === 'symbol') return String(value);
|
|
23
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value.toISOString();
|
|
24
|
+
if (value instanceof RegExp) return String(value);
|
|
25
|
+
if (depth >= MAX_DEPTH) return '[nested too deep]';
|
|
26
|
+
if (Array.isArray(value)) return value.map((item: unknown) => redactConfigValue(item, depth + 1));
|
|
27
|
+
const out: Record<string, JsonValue> = {};
|
|
28
|
+
for (const [key, item] of Object.entries(value as Record<string, unknown>)) {
|
|
29
|
+
// `defineProperty`, never `out[key] =`: a config key is the app's string, and `__proto__`
|
|
30
|
+
// assigned would re-prototype the record instead of adding a field.
|
|
31
|
+
Object.defineProperty(out, key, {
|
|
32
|
+
value: isRedactedKey(key) ? REDACTED : redactConfigValue(item, depth + 1),
|
|
33
|
+
enumerable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// `x dev`'s answer to an embedded data directory that will not open: set it aside under a dated
|
|
2
|
+
// suffix, boot a fresh one, and say so (`X_DEV_DATA_UNOPENABLE`, a notice, never a refusal). The
|
|
3
|
+
// boot used to fail with `X_DB_UNAVAILABLE`, whose fix was to run the command that had just failed.
|
|
4
|
+
|
|
5
|
+
// why: Bun ships no rename or exists API for a directory.
|
|
6
|
+
import { existsSync, renameSync } from 'node:fs';
|
|
7
|
+
import { renderThrowable } from '@ultimat3/core';
|
|
8
|
+
import { pgliteClient, pgliteDataDir, sql } from '@ultimat3/db';
|
|
9
|
+
import type { Finding } from './output';
|
|
10
|
+
import type { ServiceBinding } from './runtime-bindings';
|
|
11
|
+
|
|
12
|
+
/** `<dir>.unopenable-<UTC instant>`: sorts by date, and no two boots a second apart collide. */
|
|
13
|
+
export const asideName = (dataDir: string, now: Date): string =>
|
|
14
|
+
`${dataDir}.unopenable-${now
|
|
15
|
+
.toISOString()
|
|
16
|
+
.replace(/[-:]/g, '')
|
|
17
|
+
.replace(/\.\d+Z$/, 'Z')}`;
|
|
18
|
+
|
|
19
|
+
/** Whether PGlite opens `dataDir` and answers one statement. Costs a PGlite boot. */
|
|
20
|
+
export async function pgliteOpens(
|
|
21
|
+
dataDir: string,
|
|
22
|
+
extensions: () => Promise<readonly string[]>,
|
|
23
|
+
): Promise<boolean> {
|
|
24
|
+
const client = pgliteClient({ dataDir, extensions });
|
|
25
|
+
try {
|
|
26
|
+
await client.query(sql`select 1`);
|
|
27
|
+
return true;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
} finally {
|
|
31
|
+
await client.close().catch(() => undefined);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface StartOverOptions<T> {
|
|
36
|
+
/** The boot: `startServices`, run a second time over the fresh directory. */
|
|
37
|
+
readonly start: () => Promise<T>;
|
|
38
|
+
/** Asked only after `start` failed: does the directory open on its own? */
|
|
39
|
+
readonly opens: (dataDir: string) => Promise<boolean>;
|
|
40
|
+
readonly now: () => Date;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* `start()`, and when it fails over an embedded directory that exists and does not open by itself,
|
|
45
|
+
* that directory renamed aside and `start()` once more. Every other failure — an external database,
|
|
46
|
+
* a first boot with nothing on disk, a directory that opens — is rethrown untouched: moving a
|
|
47
|
+
* developer's data is only ever the answer to that data being unreadable. Renamed, never deleted.
|
|
48
|
+
*/
|
|
49
|
+
export async function startOverUnopenable<T>(
|
|
50
|
+
binding: ServiceBinding,
|
|
51
|
+
options: StartOverOptions<T>,
|
|
52
|
+
): Promise<{ readonly value: T; readonly notice?: Finding }> {
|
|
53
|
+
try {
|
|
54
|
+
return { value: await options.start() };
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (binding.mode !== 'embedded') throw error;
|
|
57
|
+
const dataDir = pgliteDataDir(binding.url);
|
|
58
|
+
if (!existsSync(dataDir) || (await options.opens(dataDir))) throw error;
|
|
59
|
+
const aside = asideName(dataDir, options.now());
|
|
60
|
+
renameSync(dataDir, aside);
|
|
61
|
+
const notice: Finding = {
|
|
62
|
+
code: 'X_DEV_DATA_UNOPENABLE',
|
|
63
|
+
cause: `the embedded database at ${dataDir} would not open (${renderThrowable(error)}), so it was moved to ${aside} and this boot started an empty one — the app's tables and rows are in the moved directory, not in this database`,
|
|
64
|
+
fix: 'x db migrate',
|
|
65
|
+
meta: { dataDir, aside },
|
|
66
|
+
};
|
|
67
|
+
return { value: await options.start(), notice };
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/dev-boot.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { devShellStyle } from '@ultimat3/admin/dev';
|
|
7
7
|
import type { Role } from '@ultimat3/core';
|
|
8
|
-
import { subscribe, subscribeSemconvMetrics } from '@ultimat3/core';
|
|
8
|
+
import { subscribe, subscribeSemconvMetrics, systemClock } from '@ultimat3/core';
|
|
9
9
|
import type { OverlayNotice, RequestContext } from '@ultimat3/http';
|
|
10
10
|
import { asCtx, subscribeRequestTimings } from '@ultimat3/http';
|
|
11
11
|
import { loadSignInPath } from './app-auth';
|
|
@@ -13,6 +13,7 @@ import { loadAppConfig } from './app-config-load';
|
|
|
13
13
|
import type { StalePin } from './app-reload-graph';
|
|
14
14
|
import { enableReloadTracking } from './app-reload-graph';
|
|
15
15
|
import { loadAppRuntime } from './app-runtime';
|
|
16
|
+
import { pgliteOpens, startOverUnopenable } from './dev-boot-data-dir';
|
|
16
17
|
import type { DevDashboardInput, DevStatus } from './dev-dashboard';
|
|
17
18
|
import { devPanels } from './dev-dashboard';
|
|
18
19
|
import { createInvalidationLog } from './dev-dashboard-invalidations';
|
|
@@ -25,6 +26,7 @@ import { createTraceRecorder } from './dev-traces';
|
|
|
25
26
|
import { watchTree } from './dev-watch-tree';
|
|
26
27
|
import { armFailureCapture } from './failure-capture-boot';
|
|
27
28
|
import { FRAME_STYLE } from './island-harness';
|
|
29
|
+
import { appExtensions } from './migration-extensions';
|
|
28
30
|
import type { Finding } from './output';
|
|
29
31
|
import { plainRoutes } from './plain-routes';
|
|
30
32
|
import type { RunningRoles } from './role-start';
|
|
@@ -118,22 +120,31 @@ export async function startDev(options: StartDevOptions): Promise<DevServer> {
|
|
|
118
120
|
// actions wrote to two different places in `x dev` and to one in production.
|
|
119
121
|
const appRuntime = await loadAppRuntime(options.root);
|
|
120
122
|
// The roles decide whether this boot waits for the bus, exactly as a container's one role does.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
// An embedded data directory that will not open is set aside and the boot runs again over an
|
|
124
|
+
// empty one — the developer is told where it went (`dev-boot-data-dir.ts`).
|
|
125
|
+
const started = await startOverUnopenable(resolved.db, {
|
|
126
|
+
start: () =>
|
|
127
|
+
startServices(
|
|
128
|
+
resolved,
|
|
129
|
+
env,
|
|
130
|
+
appRuntime,
|
|
131
|
+
'apply',
|
|
132
|
+
options.roles ?? DEV_ROLES,
|
|
133
|
+
// Every role in one process: a bus that is away must not take the pages down with it.
|
|
134
|
+
true,
|
|
135
|
+
),
|
|
136
|
+
opens: (dataDir) => pgliteOpens(dataDir, () => appExtensions(options.root)),
|
|
137
|
+
now: () => (appRuntime?.clock ?? systemClock).now(),
|
|
138
|
+
});
|
|
139
|
+
const runtime: RunningServices = started.value;
|
|
140
|
+
const notices = started.notice === undefined ? [] : [started.notice];
|
|
130
141
|
// The events binding the boot line reports is the bus the runtime chose, read off it.
|
|
131
142
|
const services = withRealtimeEvents(resolved, env, appRuntime?.transport !== undefined);
|
|
132
143
|
// `serve.ts`'s `releaseBoot` shape: everything acquired from here on is released, newest first,
|
|
133
144
|
// if the boot throws — a failed `x dev` left PGlite holding `.x/pgdata` for the retry to meet.
|
|
134
145
|
const acquired: (() => void | Promise<void>)[] = [() => runtime.stop()];
|
|
135
146
|
try {
|
|
136
|
-
return await bootDev(options, services, runtime, acquired, appRuntime);
|
|
147
|
+
return await bootDev(options, services, runtime, acquired, appRuntime, notices);
|
|
137
148
|
} catch (error) {
|
|
138
149
|
await releaseBoot(acquired);
|
|
139
150
|
throw error;
|
|
@@ -146,6 +157,8 @@ async function bootDev(
|
|
|
146
157
|
runtime: RunningServices,
|
|
147
158
|
acquired: (() => void | Promise<void>)[],
|
|
148
159
|
appRuntime: RuntimeOverrides | undefined,
|
|
160
|
+
/** What the boot did on the developer's behalf and must say: a set-aside data directory. */
|
|
161
|
+
notices: readonly Finding[],
|
|
149
162
|
): Promise<DevServer> {
|
|
150
163
|
// Installed before the app loads, so a span opened during registration is already recorded.
|
|
151
164
|
// Tracing is always on in the framework and free until something subscribes to `span.end`;
|
|
@@ -321,8 +334,8 @@ async function bootDev(
|
|
|
321
334
|
get findings(): readonly Finding[] {
|
|
322
335
|
const loops = statements.repeats().map(loopFacts).map(loopFinding);
|
|
323
336
|
return state.reloadFinding === undefined
|
|
324
|
-
? [...state.appFindings, ...loops]
|
|
325
|
-
: [...state.appFindings, state.reloadFinding, ...loops];
|
|
337
|
+
? [...notices, ...state.appFindings, ...loops]
|
|
338
|
+
: [...notices, ...state.appFindings, state.reloadFinding, ...loops];
|
|
326
339
|
},
|
|
327
340
|
running,
|
|
328
341
|
runtime,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// `x doctor`'s chart listing: the monitoring templates an app's Helm chart
|
|
2
|
-
// command that writes
|
|
1
|
+
// `x doctor`'s chart listing: the monitoring templates and the dashboard an app's Helm chart
|
|
2
|
+
// predates, each with the one command that writes it. A LISTING, never a finding: the chart is the app's, and a chart that
|
|
3
3
|
// declines the operator's objects (or keeps its own) is a decision `x doctor` must not overrule.
|
|
4
4
|
|
|
5
5
|
// why: a synchronous exists check; Bun.file().exists() is async and the probe is not.
|
|
@@ -9,47 +9,75 @@ import { join } from 'node:path';
|
|
|
9
9
|
import { CHART_FILE } from './generate-chart-alerts';
|
|
10
10
|
import { msg } from './messages';
|
|
11
11
|
import type { CommandResult, JsonValue } from './output';
|
|
12
|
+
import type { GeneratedFile, NameSet } from './templates';
|
|
12
13
|
import { names } from './templates';
|
|
14
|
+
import { helmDashboardFiles } from './templates/chart-dashboard';
|
|
13
15
|
import { helmMonitoringFiles } from './templates/scaffold-helm-alerts';
|
|
14
16
|
|
|
15
17
|
/** The command every row names: it writes only the files the chart lacks. */
|
|
16
18
|
export const CHART_ALERTS_ADD = 'x g chart-alerts';
|
|
19
|
+
export const CHART_DASHBOARD_ADD = 'x g chart-dashboard';
|
|
20
|
+
|
|
21
|
+
const absentOf =
|
|
22
|
+
(files: (app: NameSet) => readonly GeneratedFile[]) =>
|
|
23
|
+
(hasChart: boolean, exists: (path: string) => boolean): readonly string[] =>
|
|
24
|
+
// The paths only — they do not depend on the chart's name.
|
|
25
|
+
hasChart
|
|
26
|
+
? files(names('app'))
|
|
27
|
+
.map((file) => file.path)
|
|
28
|
+
.filter((path) => !exists(path))
|
|
29
|
+
: [];
|
|
30
|
+
|
|
31
|
+
/** The dashboard's half of the rule: its JSON and its ConfigMap, absent from a chart that exists. */
|
|
32
|
+
export const missingDashboardTemplates = absentOf(helmDashboardFiles);
|
|
17
33
|
|
|
18
34
|
/** The rule, pure: which monitoring templates are absent from a chart that exists. */
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
.filter((path) => !exists(path));
|
|
35
|
+
export const missingMonitoringTemplates = absentOf(helmMonitoringFiles);
|
|
36
|
+
|
|
37
|
+
/** What a chart lacks, per command. An app with no chart lacks nothing. */
|
|
38
|
+
export const NOTHING_MISSING: ChartListing = { alerts: [], dashboard: [] };
|
|
39
|
+
|
|
40
|
+
export interface ChartListing {
|
|
41
|
+
readonly alerts: readonly string[];
|
|
42
|
+
readonly dashboard: readonly string[];
|
|
28
43
|
}
|
|
29
44
|
|
|
30
45
|
/** The I/O half. An app with no chart deploys some other way, and is listed nothing. */
|
|
31
|
-
export function chartAlertsProbe(root: string):
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
export function chartAlertsProbe(root: string): ChartListing {
|
|
47
|
+
const hasChart = existsSync(join(root, CHART_FILE));
|
|
48
|
+
const exists = (path: string) => existsSync(join(root, path));
|
|
49
|
+
return {
|
|
50
|
+
alerts: missingMonitoringTemplates(hasChart, exists),
|
|
51
|
+
dashboard: missingDashboardTemplates(hasChart, exists),
|
|
52
|
+
};
|
|
35
53
|
}
|
|
36
54
|
|
|
37
55
|
/** The listing, on a result `x doctor` already decided: `ok` and the findings stay as they came. */
|
|
38
56
|
export function withChartAlertsListing(
|
|
39
57
|
result: CommandResult,
|
|
40
|
-
|
|
58
|
+
{ alerts, dashboard }: ChartListing,
|
|
41
59
|
): CommandResult {
|
|
42
|
-
if (
|
|
60
|
+
if (alerts.length === 0 && dashboard.length === 0) return result;
|
|
43
61
|
const data = typeof result.data === 'object' && result.data !== null ? result.data : {};
|
|
44
|
-
const
|
|
62
|
+
const rows = (missing: readonly string[], key: string, add: string): readonly string[] =>
|
|
63
|
+
missing.length === 0
|
|
64
|
+
? []
|
|
65
|
+
: [msg(key, { count: missing.length }), ...missing.map((path) => ` ${path}`), ` ${add}`];
|
|
45
66
|
return {
|
|
46
67
|
...result,
|
|
47
|
-
data: {
|
|
68
|
+
data: {
|
|
69
|
+
...(data as Record<string, JsonValue>),
|
|
70
|
+
...(alerts.length === 0
|
|
71
|
+
? {}
|
|
72
|
+
: { chartAlerts: { missing: [...alerts], add: CHART_ALERTS_ADD } }),
|
|
73
|
+
...(dashboard.length === 0
|
|
74
|
+
? {}
|
|
75
|
+
: { chartDashboard: { missing: [...dashboard], add: CHART_DASHBOARD_ADD } }),
|
|
76
|
+
},
|
|
48
77
|
lines: [
|
|
49
78
|
...(result.lines ?? []),
|
|
50
|
-
|
|
51
|
-
...
|
|
52
|
-
` ${CHART_ALERTS_ADD}`,
|
|
79
|
+
...rows(alerts, 'cli.doctor.chartAlerts', CHART_ALERTS_ADD),
|
|
80
|
+
...rows(dashboard, 'cli.doctor.chartDashboard', CHART_DASHBOARD_ADD),
|
|
53
81
|
],
|
|
54
82
|
};
|
|
55
83
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// The X_* codes of the app tooling commands — `x client`, `x graph` / `x impact
|
|
2
|
-
// split out of `error-codes.ts` at its 500-line ceiling, as `error-codes-shot.ts`
|
|
3
|
-
// folds these into the CLI's one owned union and registers them in its one call.
|
|
1
|
+
// The X_* codes of the app tooling commands — `x client`, `x graph` / `x impact`, `x repro` and
|
|
2
|
+
// `x explain` — split out of `error-codes.ts` at its 500-line ceiling, as `error-codes-shot.ts`
|
|
3
|
+
// was. That file folds these into the CLI's one owned union and registers them in its one call.
|
|
4
4
|
|
|
5
|
-
/** Codes `x client`, `x graph`, `x impact` and `x
|
|
5
|
+
/** Codes `x client`, `x graph`, `x impact`, `x repro` and `x explain` declare and own. */
|
|
6
6
|
export const CLI_TOOLING_ERROR_CODES = [
|
|
7
7
|
'X_CLIENT_SPEC_UNSUPPORTED',
|
|
8
8
|
'X_CLIENT_STALE',
|
|
@@ -12,6 +12,7 @@ export const CLI_TOOLING_ERROR_CODES = [
|
|
|
12
12
|
'X_REPRO_UNKNOWN',
|
|
13
13
|
'X_REPRO_NOT_REPRODUCED',
|
|
14
14
|
'X_REPRO_CAPTURE_OFF',
|
|
15
|
+
'X_EXPLAIN_PRODUCTION_DATABASE',
|
|
15
16
|
] as const;
|
|
16
17
|
|
|
17
18
|
export type CliToolingErrorCode = (typeof CLI_TOOLING_ERROR_CODES)[number];
|
|
@@ -26,4 +27,5 @@ export const CLI_TOOLING_ERROR_TITLES: Readonly<Record<CliToolingErrorCode, stri
|
|
|
26
27
|
X_REPRO_UNKNOWN: 'x repro was given an id nothing holds',
|
|
27
28
|
X_REPRO_NOT_REPRODUCED: 'a written repro test did not fail the way the original did',
|
|
28
29
|
X_REPRO_CAPTURE_OFF: 'x repro was given a request id while failure capture is off',
|
|
30
|
+
X_EXPLAIN_PRODUCTION_DATABASE: 'x explain refused to run on a production database',
|
|
29
31
|
};
|
package/src/error-codes.ts
CHANGED
|
@@ -242,6 +242,7 @@ export const CLI_OWNED_ERROR_CODES = [
|
|
|
242
242
|
'X_SEED_FAILED',
|
|
243
243
|
'X_NATIVE_FORM_UNANSWERED',
|
|
244
244
|
'X_ASSET_RETAIN_UNDECLARED',
|
|
245
|
+
'X_DEV_DATA_UNOPENABLE',
|
|
245
246
|
] as const;
|
|
246
247
|
|
|
247
248
|
/**
|
|
@@ -470,6 +471,7 @@ export const CLI_ERROR_TITLES: Readonly<Record<CliListedErrorCode, string>> = {
|
|
|
470
471
|
X_SEED_FAILED: 'a seed threw an uncoded error',
|
|
471
472
|
X_NATIVE_FORM_UNANSWERED: 'a page form posts to an action that declares no native answer',
|
|
472
473
|
X_ASSET_RETAIN_UNDECLARED: "A served build keeps no earlier build's assets",
|
|
474
|
+
X_DEV_DATA_UNOPENABLE: 'x dev set aside an embedded data directory that would not open',
|
|
473
475
|
};
|
|
474
476
|
|
|
475
477
|
// One unconditional call, so a second package claiming one of the CLI's codes throws
|
package/src/errors.ts
CHANGED
|
@@ -7,10 +7,16 @@ import { quoteArg } from './shell-quote';
|
|
|
7
7
|
|
|
8
8
|
/** An unknown command or subcommand. Carries a suggestion so the retry is one keystroke away. */
|
|
9
9
|
export class UnknownCommandError extends UltimateError {
|
|
10
|
-
|
|
10
|
+
/** `why`: the decision behind a name that is deliberately not a command, said after the list. */
|
|
11
|
+
constructor(input: {
|
|
12
|
+
path: string;
|
|
13
|
+
known: readonly string[];
|
|
14
|
+
suggestion?: string;
|
|
15
|
+
why?: string;
|
|
16
|
+
}) {
|
|
11
17
|
super({
|
|
12
18
|
code: 'X_CLI_UNKNOWN_COMMAND',
|
|
13
|
-
cause: `"x ${input.path}" is not a command (known: ${input.known.join(', ')})`,
|
|
19
|
+
cause: `"x ${input.path}" is not a command (known: ${input.known.join(', ')})${input.why === undefined ? '' : ` — ${input.why}`}`,
|
|
14
20
|
fix: input.suggestion === undefined ? 'x help' : `x ${input.suggestion}`,
|
|
15
21
|
});
|
|
16
22
|
}
|
|
@@ -34,6 +34,10 @@ const KEY = /^(?:([A-Za-z_$][\w$]*)|'([^']*)'|"([^"]*)")\s*(?::|$)/;
|
|
|
34
34
|
|
|
35
35
|
const refused = (reason: string): ExerciseEdit => ({ kind: 'refused', reason });
|
|
36
36
|
|
|
37
|
+
/** As an object key: bare where it is an identifier, quoted where it is not (`'billing-events'`). */
|
|
38
|
+
export const entryKey = (name: string): string =>
|
|
39
|
+
/^[A-Za-z_$][\w$]*$/.test(name) ? name : `'${name}'`;
|
|
40
|
+
|
|
37
41
|
/** `source` (or `x new`'s file when there is none) with every entry it does not name yet. */
|
|
38
42
|
export function editExerciseFile(
|
|
39
43
|
source: string | undefined,
|
|
@@ -83,7 +87,7 @@ const lineIndent = (source: string, at: number): string => {
|
|
|
83
87
|
|
|
84
88
|
/** ` name: value,` with every line of the value under `indent`. */
|
|
85
89
|
const row = (indent: string, entry: ExerciseEntry): string =>
|
|
86
|
-
`${indent}${entry.name}: ${entry.value.split('\n').join(`\n${indent}`)},`;
|
|
90
|
+
`${indent}${entryKey(entry.name)}: ${entry.value.split('\n').join(`\n${indent}`)},`;
|
|
87
91
|
|
|
88
92
|
function insertRows(
|
|
89
93
|
source: string,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// What `x exercise` says about the route `load`s the pass ran (`@ultimat3/testing`'s
|
|
2
|
+
// `exercise-route-loads.ts`), and about a primitive reached with nothing to prove: WARNING lines,
|
|
3
|
+
// each naming the route file or the primitive. Warnings on `main` — a page read was never judged
|
|
4
|
+
// before, and an app that has not opted in stays green (X_BREAKING_ON_MAIN); red needs a floor key.
|
|
5
|
+
|
|
6
|
+
import type { ExerciseRecord, RouteLoadRecord } from '@ultimat3/testing';
|
|
7
|
+
|
|
8
|
+
const where = (record: RouteLoadRecord): string => `route ${record.name} (${record.file})`;
|
|
9
|
+
|
|
10
|
+
/** Each route's load as warning lines: a loop, a call over the ceiling, a seq scan, or unrun. */
|
|
11
|
+
export function routeLoadWarnings(records: readonly RouteLoadRecord[]): readonly string[] {
|
|
12
|
+
return records.flatMap((record): readonly string[] => {
|
|
13
|
+
if (record.outcome !== 'reached') {
|
|
14
|
+
return [`${where(record)} · load not exercised: ${record.reason ?? record.outcome}`];
|
|
15
|
+
}
|
|
16
|
+
const lines: string[] = [];
|
|
17
|
+
if (record.scale?.verdict === 'grows') {
|
|
18
|
+
for (const shape of record.scale.shapes) {
|
|
19
|
+
lines.push(
|
|
20
|
+
`${where(record)} · X_QUERY_SCALES_WITH_ROWS ${shape.fingerprint} ${String(shape.small)}→${String(shape.large)} at 2→8 rows a table: its load reads once per row — fold it into one read, or wrap it in expectedQueryLoop('<why>', fn)`,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const ceiling = record.statementCeiling;
|
|
25
|
+
if (ceiling?.verdict === 'over') {
|
|
26
|
+
const top = ceiling.top.map((shape) => `${shape.fingerprint} ×${String(shape.count)}`);
|
|
27
|
+
lines.push(
|
|
28
|
+
`${where(record)} · X_STATEMENTS_OVER_BUDGET ${String(ceiling.statements)} statements in one load, max ${String(ceiling.max)}: ${top.join(', ')}`,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
for (const finding of record.plans?.findings ?? []) {
|
|
32
|
+
lines.push(`${where(record)} · ${finding.code} ${finding.table}`);
|
|
33
|
+
}
|
|
34
|
+
return lines;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** How many names an empty-reach line lists before it says how many more. */
|
|
39
|
+
const NAMED = 5;
|
|
40
|
+
|
|
41
|
+
/** The line's code (`@ultimat3/testing` registers it): a warning on `main`, never a finding. */
|
|
42
|
+
const EMPTY_REACH = 'X_EXERCISE_EMPTY_REACH';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Reached with no statement and no effect: every proof on it is vacuous — a scale sweep of nothing
|
|
46
|
+
* is "flat", a tenant proof over nothing is "proven". Said once, with the first few named.
|
|
47
|
+
*/
|
|
48
|
+
export function emptyReachWarnings(records: readonly ExerciseRecord[]): readonly string[] {
|
|
49
|
+
const empty = records.filter(
|
|
50
|
+
(record) =>
|
|
51
|
+
record.outcome === 'reached' && record.statements === 0 && record.effects.length === 0,
|
|
52
|
+
);
|
|
53
|
+
if (empty.length === 0) return [];
|
|
54
|
+
const named = empty.slice(0, NAMED).map((record) => `${record.kind} ${record.name}`);
|
|
55
|
+
const more = empty.length > NAMED ? `, and ${String(empty.length - NAMED)} more` : '';
|
|
56
|
+
return [
|
|
57
|
+
`${EMPTY_REACH} ${String(empty.length)} reached primitive(s) sent no statement and had no effect, so their proofs prove nothing: ${named.join(', ')}${more} — fix: edit exercise.ts: give each an input that reaches its work, or { off: '<why>' }`,
|
|
58
|
+
];
|
|
59
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// The statements ONE call sends, as `x explain` plans them: every `db.statement` event the call
|
|
2
|
+
// made under a marker of its own (never by time — the bus is process-wide), its text whitespace
|
|
3
|
+
// collapsed and its `expectedSeqScan` reason kept, exactly as the exercise room records them.
|
|
4
|
+
|
|
5
|
+
import { asyncContext, subscribe } from '@ultimat3/core';
|
|
6
|
+
import { expectedSeqScanReason } from '@ultimat3/db';
|
|
7
|
+
import type { SentStatement } from '@ultimat3/testing';
|
|
8
|
+
|
|
9
|
+
const scope = asyncContext<object>('x explain');
|
|
10
|
+
|
|
11
|
+
export interface Captured<T> {
|
|
12
|
+
readonly value: T;
|
|
13
|
+
/** Statement text → who sent it and why it may scan, in the shape `sweepPlans` reads. */
|
|
14
|
+
readonly sent: ReadonlyMap<string, SentStatement>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function captureStatements<T>(
|
|
18
|
+
subject: string,
|
|
19
|
+
fn: () => Promise<T>,
|
|
20
|
+
): Promise<Captured<T>> {
|
|
21
|
+
const marker = {};
|
|
22
|
+
const sent = new Map<string, { primitives: Set<string>; scan?: string }>();
|
|
23
|
+
// The bus delivers synchronously in the sender's context, so the marker read is the sender's.
|
|
24
|
+
const off = subscribe('db.statement', (event) => {
|
|
25
|
+
if (scope.get() !== marker) return;
|
|
26
|
+
const text = event.payload.text.replace(/\s+/g, ' ').trim();
|
|
27
|
+
const one = sent.get(text) ?? { primitives: new Set([subject]) };
|
|
28
|
+
const scan = expectedSeqScanReason();
|
|
29
|
+
if (scan !== undefined) one.scan = scan;
|
|
30
|
+
sent.set(text, one);
|
|
31
|
+
});
|
|
32
|
+
try {
|
|
33
|
+
const value = await scope.run(marker, fn);
|
|
34
|
+
return { value, sent };
|
|
35
|
+
} finally {
|
|
36
|
+
off();
|
|
37
|
+
}
|
|
38
|
+
}
|