@ultimat3/cli 31.26.0 → 31.28.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 +47 -37
- package/README.md +19 -8
- package/package.json +29 -29
- package/src/app-manifest.ts +6 -1
- package/src/app-mcp.ts +17 -3
- package/src/cmd-cache-spec.ts +5 -2
- package/src/cmd-db-spec.ts +2 -3
- package/src/cmd-db.ts +0 -2
- package/src/cmd-deploy-verify-sample.ts +93 -0
- package/src/cmd-deploy-verify.ts +2 -41
- package/src/cmd-dev-spec.ts +15 -1
- package/src/cmd-dev.ts +31 -4
- package/src/cmd-doctor.ts +15 -4
- package/src/cmd-exercise-spec.ts +7 -1
- package/src/cmd-exercise.ts +22 -10
- package/src/cmd-generate.ts +2 -0
- package/src/cmd-jobs-spec.ts +3 -6
- package/src/cmd-jobs.ts +1 -7
- package/src/cmd-logs-spec.ts +2 -1
- package/src/cmd-logs.ts +9 -28
- package/src/cmd-planned.ts +11 -45
- package/src/cmd-profile-frames.ts +99 -0
- package/src/cmd-profile-spec.ts +24 -0
- package/src/cmd-profile.ts +164 -0
- package/src/cmd-repro-spec.ts +13 -1
- package/src/cmd-repro.ts +37 -5
- package/src/cmd-status-sample.ts +57 -0
- package/src/cmd-status-spec.ts +30 -0
- package/src/cmd-status.ts +108 -0
- package/src/cmd-token-spec.ts +5 -2
- package/src/cmd-token.ts +7 -3
- package/src/cmd-upgrade-codemods.ts +71 -0
- package/src/cmd-upgrade-spec.ts +19 -5
- package/src/cmd-upgrade.ts +91 -34
- package/src/codemods/agents-dev-mcp.ts +50 -0
- package/src/codemods/authenticator-session-refusal.ts +214 -0
- package/src/codemods/biome-no-default-export.ts +58 -0
- package/src/codemods/bunfig-island-coverage.ts +33 -0
- package/src/codemods/chart-dashboard.ts +73 -0
- package/src/codemods/ci-e2e-browser-stock.ts +75 -0
- package/src/codemods/ci-e2e-browser.ts +63 -0
- package/src/codemods/codemod.ts +58 -0
- package/src/codemods/define-error-leaf.ts +73 -0
- package/src/codemods/docs-ci-parts.ts +65 -0
- package/src/codemods/docs-gate-prose.ts +53 -0
- package/src/codemods/docs-island-rows.ts +31 -0
- package/src/codemods/docs-shipped-guards.ts +100 -0
- package/src/codemods/docs-test-services.ts +62 -0
- package/src/codemods/engine-diff.ts +104 -0
- package/src/codemods/engine-edits.ts +111 -0
- package/src/codemods/engine-fs.ts +95 -0
- package/src/codemods/engine.ts +191 -0
- package/src/codemods/format-edited-hook-3122.ts +28 -0
- package/src/codemods/format-edited-hook.ts +152 -0
- package/src/codemods/helm-alerts-objective.ts +105 -0
- package/src/codemods/helm-alerts-stock.ts +108 -0
- package/src/codemods/index.ts +56 -0
- package/src/codemods/metrics-probe-healthz.ts +47 -0
- package/src/codemods/pending.ts +36 -0
- package/src/codemods/repro-gitignore.ts +40 -0
- package/src/codemods/runtime-pin-lines.ts +109 -0
- package/src/codemods/runtime-pin.ts +116 -0
- package/src/codemods/solid-floor.ts +63 -0
- package/src/codemods/test-ports.ts +86 -0
- package/src/codemods/test-suites.ts +37 -0
- package/src/codemods/theme-toggle-mount-over.ts +70 -0
- package/src/codemods/vendored-guards.ts +186 -0
- package/src/codemods/verify-floor-skips.ts +88 -0
- package/src/codemods/verify-floor-steps.ts +90 -0
- package/src/coverage-island.ts +121 -0
- package/src/coverage-lcov.ts +49 -5
- package/src/coverage-remap.ts +146 -0
- package/src/db-replay-engine-prepared.ts +66 -0
- package/src/db-replay-engine-template.ts +156 -0
- package/src/db-replay-engine.ts +4 -0
- package/src/db-replay-scratch-reap.ts +54 -0
- package/src/deploy-verify-flags.ts +9 -2
- package/src/deploy-verify-grade.ts +10 -3
- package/src/dev-boot.ts +14 -1
- package/src/dev-dashboard-guard.ts +57 -10
- package/src/dev-host.ts +46 -0
- package/src/dev-tls-cache.ts +103 -0
- package/src/dev-tls-der.ts +69 -0
- package/src/dev-tls.ts +120 -0
- package/src/doctor-advisory-floors.ts +113 -0
- package/src/doctor-browser.ts +60 -0
- package/src/doctor-guards.ts +39 -86
- package/src/doctor-superseded.ts +67 -0
- package/src/error-codes-doctor.ts +12 -4
- package/src/error-codes-verify.ts +47 -0
- package/src/error-codes.ts +20 -23
- package/src/exercise-database.ts +47 -9
- package/src/exercise-push-device.ts +51 -0
- package/src/exercise-route-api.ts +74 -0
- package/src/exercise-routes.ts +14 -5
- package/src/exercise-services.ts +3 -1
- package/src/exercise-shard-flag.ts +47 -0
- package/src/fix-command.ts +2 -2
- package/src/generate-factories.ts +5 -11
- package/src/generate-feature-required.ts +9 -4
- package/src/generate-files.ts +26 -7
- package/src/generate-kinds.ts +5 -1
- package/src/guards-built-in-codes.ts +36 -0
- package/src/guards-built-in-refusal.ts +25 -0
- package/src/guards-built-in.ts +134 -0
- package/src/guards-materialize.ts +42 -0
- package/src/guards-paths.ts +37 -0
- package/src/guards-shipped-names.ts +38 -0
- package/src/guards-vendored.ts +73 -0
- package/src/guards.ts +105 -34
- package/src/index.ts +10 -0
- package/src/island-bundle-options.ts +48 -0
- package/src/island-bundle.ts +18 -46
- package/src/island-link.ts +5 -0
- package/src/island-outputs.ts +5 -0
- package/src/lint-findings.ts +3 -3
- package/src/mcp-errors-verify.ts +35 -0
- package/src/mcp-errors.ts +21 -20
- package/src/mcp-host-logs.ts +121 -0
- package/src/mcp-host.ts +12 -73
- package/src/measure-scope.ts +23 -3
- package/src/messages-floor.ts +19 -0
- package/src/messages-repro.ts +16 -2
- package/src/messages-status.ts +10 -0
- package/src/messages-upgrade.ts +15 -0
- package/src/messages.ts +22 -1
- package/src/registry.ts +4 -0
- package/src/repro-archive-collect.ts +161 -0
- package/src/repro-archive-write.ts +96 -0
- package/src/repro-archive.ts +161 -0
- package/src/repro-bundle.ts +8 -16
- package/src/repro-errors.ts +14 -2
- package/src/repro-framework.ts +53 -0
- package/src/repro-parse.ts +87 -0
- package/src/repro-redact.ts +218 -0
- package/src/repro-scrub.ts +257 -0
- package/src/role-start-types.ts +7 -0
- package/src/role-start.ts +4 -0
- package/src/serve-boot.ts +7 -1
- package/src/serve-env-tls.ts +57 -0
- package/src/solid-loader.ts +27 -10
- package/src/superseded-match.ts +87 -0
- package/src/superseded.ts +84 -0
- package/src/templates/bun-image.ts +48 -0
- package/src/templates/generate-export-rows.ts +136 -0
- package/src/templates/generate-import-rows.ts +186 -0
- package/src/templates/generate-rows-slice.ts +95 -0
- package/src/templates/github/ci.yml.ts +5 -1
- package/src/templates/guard-released-forms.ts +112 -0
- package/src/templates/guard-runtime-pin-test.ts +54 -0
- package/src/templates/guard-runtime-pin.ts +189 -0
- package/src/templates/scaffold-claude-agents.ts +6 -6
- package/src/templates/scaffold-claude-commands.ts +1 -1
- package/src/templates/scaffold-claude-hook.ts +18 -8
- package/src/templates/scaffold-claude.ts +2 -2
- package/src/templates/scaffold-db-package.ts +3 -0
- package/src/templates/scaffold-docs.ts +34 -30
- package/src/templates/scaffold-guards.ts +73 -39
- package/src/templates/scaffold-repo.ts +4 -8
- package/src/templates/scaffold-site.ts +4 -1
- package/src/templates/scaffold-suites.ts +72 -0
- package/src/templates/scaffold-test-services.ts +35 -10
- package/src/templates/scaffold-verify-floor.ts +53 -31
- package/src/templates/shapes/api.ts +4 -0
- package/src/templates/slice-foundation.ts +3 -3
- package/src/unthrown-codes.ts +3 -1
- package/src/upgrade-bun-floor.ts +4 -0
- package/src/upgrade-clean-tree.ts +54 -0
- package/src/upgrade-gate-codemods-install.ts +40 -0
- package/src/upgrade-gate-codemods.ts +151 -0
- package/src/upgrade-gate.ts +44 -7
- package/src/upgrade-guards-baseline.ts +43 -0
- package/src/upgrade-guards.ts +37 -2
- package/src/upgrade-lock.ts +118 -0
- package/src/upgrade-plan.ts +2 -1
- package/src/upgrade-report-codemods.ts +54 -0
- package/src/upgrade-report.ts +55 -27
- package/src/upgrade-signals.ts +91 -0
- package/src/upgrade-unfinished.ts +61 -0
- package/src/verify-coverage-run.ts +42 -11
- package/src/verify-e2e.ts +115 -4
- package/src/verify-floor.ts +27 -0
- package/src/verify-guard-baseline.ts +109 -0
- package/src/verify-live.ts +72 -0
- package/src/verify-merge-skips.ts +51 -0
- package/src/verify-merge.ts +36 -2
- package/src/verify-run.ts +48 -7
- package/src/verify-services.ts +287 -0
- package/src/verify-skip-reason.ts +53 -0
- package/src/verify-strict.ts +108 -0
- package/src/verify-test-command.ts +129 -0
- package/src/verify-tests.ts +39 -126
- package/types/babel-modules.d.ts +2 -0
- package/wiki/CLI-Reference.md +200 -27
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Entities-And-Migrations.md +1 -1
- package/wiki/Interface-Rules.md +17 -8
- package/wiki/Jobs-And-Workflows.md +3 -3
- package/wiki/Known-Gaps.md +5 -1
- package/wiki/MCP-And-AI.md +1 -1
- package/wiki/Observability.md +1 -0
- package/wiki/PWA-And-Offline.md +1 -1
- package/wiki/Project-Layout.md +4 -4
- package/wiki/Troubleshooting.md +3 -3
- package/wiki/Tutorial-05-Deploy-Free.md +2 -2
- package/wiki/Upgrading.md +8 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// `x profile`'s reading of a JavaScriptCore sampling profile: which functions the samples landed
|
|
2
|
+
// in (self), and which were on the stack when they did (inclusive). Grouped per function — a line
|
|
3
|
+
// is where one sample landed, a function is what an author can go and change.
|
|
4
|
+
|
|
5
|
+
import type { SamplingProfileStackFrame, SamplingProfileStackTraces } from 'bun:jsc';
|
|
6
|
+
|
|
7
|
+
export interface HotFrame {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
/** Root-relative when the file is the app's; `native` for a frame with no source. */
|
|
10
|
+
readonly file: string;
|
|
11
|
+
/** The line most of this function's self samples landed on; null when unknown. */
|
|
12
|
+
readonly line: number | null;
|
|
13
|
+
/** Samples whose innermost frame was this function. */
|
|
14
|
+
readonly self: number;
|
|
15
|
+
/** Samples with this function anywhere on the stack, each sample counted once. */
|
|
16
|
+
readonly total: number;
|
|
17
|
+
/** `self` over every sample, as a whole-number percent — never a float a script compares. */
|
|
18
|
+
readonly selfPercent: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ProfileSummary {
|
|
22
|
+
readonly samples: number;
|
|
23
|
+
readonly intervalMicros: number;
|
|
24
|
+
readonly hottest: readonly HotFrame[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const UNKNOWN_LINE = 4_294_967_295;
|
|
28
|
+
|
|
29
|
+
const fileOf = (frame: SamplingProfileStackFrame, root: string): string => {
|
|
30
|
+
const url = frame.sourceURL;
|
|
31
|
+
if (url === undefined || url === '') return 'native';
|
|
32
|
+
return url.startsWith(`${root}/`) ? url.slice(root.length + 1) : url;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const keyOf = (frame: SamplingProfileStackFrame): string =>
|
|
36
|
+
`${frame.name}\u0000${frame.sourceURL ?? ''}`;
|
|
37
|
+
|
|
38
|
+
interface Tally {
|
|
39
|
+
frame: SamplingProfileStackFrame;
|
|
40
|
+
self: number;
|
|
41
|
+
total: number;
|
|
42
|
+
lines: Map<number, number>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const tallyFor = (tallies: Map<string, Tally>, frame: SamplingProfileStackFrame): Tally => {
|
|
46
|
+
const key = keyOf(frame);
|
|
47
|
+
const found = tallies.get(key);
|
|
48
|
+
if (found !== undefined) return found;
|
|
49
|
+
const fresh: Tally = { frame, self: 0, total: 0, lines: new Map() };
|
|
50
|
+
tallies.set(key, fresh);
|
|
51
|
+
return fresh;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const mostSampledLine = (lines: ReadonlyMap<number, number>): number | null => {
|
|
55
|
+
let best: [number, number] | undefined;
|
|
56
|
+
for (const entry of lines) if (best === undefined || entry[1] > best[1]) best = entry;
|
|
57
|
+
return best === undefined || best[0] === UNKNOWN_LINE ? null : best[0];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** The `limit` hottest functions by self samples; ties broken by total, then name. */
|
|
61
|
+
export function hottestFrames(
|
|
62
|
+
traces: SamplingProfileStackTraces,
|
|
63
|
+
root: string,
|
|
64
|
+
limit: number,
|
|
65
|
+
): ProfileSummary {
|
|
66
|
+
const tallies = new Map<string, Tally>();
|
|
67
|
+
for (const trace of traces.traces) {
|
|
68
|
+
const [innermost] = trace.frames;
|
|
69
|
+
if (innermost === undefined) continue;
|
|
70
|
+
const top = tallyFor(tallies, innermost);
|
|
71
|
+
top.self += 1;
|
|
72
|
+
top.lines.set(innermost.line, (top.lines.get(innermost.line) ?? 0) + 1);
|
|
73
|
+
const seen = new Set<string>();
|
|
74
|
+
for (const frame of trace.frames) {
|
|
75
|
+
const key = keyOf(frame);
|
|
76
|
+
if (seen.has(key)) continue; // recursion: one sample is one sample
|
|
77
|
+
seen.add(key);
|
|
78
|
+
tallyFor(tallies, frame).total += 1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const samples = traces.traces.length;
|
|
82
|
+
const hottest = [...tallies.values()]
|
|
83
|
+
.filter((tally) => tally.self > 0)
|
|
84
|
+
.sort(
|
|
85
|
+
(a, b) => b.self - a.self || b.total - a.total || a.frame.name.localeCompare(b.frame.name),
|
|
86
|
+
)
|
|
87
|
+
.slice(0, limit)
|
|
88
|
+
.map(
|
|
89
|
+
(tally): HotFrame => ({
|
|
90
|
+
name: tally.frame.name === '' ? '(anonymous)' : tally.frame.name,
|
|
91
|
+
file: fileOf(tally.frame, root),
|
|
92
|
+
line: mostSampledLine(tally.lines),
|
|
93
|
+
self: tally.self,
|
|
94
|
+
total: tally.total,
|
|
95
|
+
selfPercent: samples === 0 ? 0 : Math.round((tally.self * 100) / samples),
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
return { samples, intervalMicros: Math.round(traces.interval * 1_000_000), hottest };
|
|
99
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// `x profile`'s declaration, apart from its body: the parser, `x help` and the `errors` step
|
|
2
|
+
// read it without loading `cmd-profile.ts`, which `registry.ts` imports only when the command runs.
|
|
3
|
+
|
|
4
|
+
import type { CommandSpec } from './parse';
|
|
5
|
+
|
|
6
|
+
export const profileSpec: CommandSpec = {
|
|
7
|
+
name: 'profile',
|
|
8
|
+
summary:
|
|
9
|
+
"a CPU profile of rendering one route in-process: the app booted, the route's hottest functions",
|
|
10
|
+
usage: 'x profile <route> [--runs 20] [--top 10] [--json]',
|
|
11
|
+
requiresApp: true,
|
|
12
|
+
flags: [
|
|
13
|
+
{
|
|
14
|
+
name: 'runs',
|
|
15
|
+
type: 'string',
|
|
16
|
+
summary: 'requests profiled after one warm-up request (default 20)',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'top',
|
|
20
|
+
type: 'string',
|
|
21
|
+
summary: 'how many of the hottest functions to report (default 10)',
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// `x profile <route>` — the app booted in THIS process (`startDev`, the web role, port 0), the
|
|
2
|
+
// route requested once to warm it, then `--runs` more under JavaScriptCore's sampling profiler
|
|
3
|
+
// (`bun:jsc`'s `profile`), and the hottest functions reported (`cmd-profile-frames.ts`). In-process
|
|
4
|
+
// because a sampling profiler sees only its own thread: a running `x dev` cannot be profiled.
|
|
5
|
+
|
|
6
|
+
import { profile } from 'bun:jsc';
|
|
7
|
+
import { renderFixShellArg } from '@ultimat3/core';
|
|
8
|
+
import { requireAppRoot } from './app-root';
|
|
9
|
+
import { hottestFrames, type ProfileSummary } from './cmd-profile-frames';
|
|
10
|
+
import { profileSpec } from './cmd-profile-spec';
|
|
11
|
+
import type { CliCommand, CommandContext } from './command';
|
|
12
|
+
import { startDev } from './dev-boot';
|
|
13
|
+
import { preflight } from './dev-lock';
|
|
14
|
+
import { BadFlagError, MissingPositionalError } from './errors';
|
|
15
|
+
import { intFlagOr } from './flag-number';
|
|
16
|
+
import { msg } from './messages';
|
|
17
|
+
import type { CommandResult, Finding, JsonValue } from './output';
|
|
18
|
+
import { resolveServices } from './runtime-bindings';
|
|
19
|
+
import { DEV_BINDING } from './web-binding';
|
|
20
|
+
|
|
21
|
+
/** Fine enough to see a render of a few milliseconds; the default 1 ms saw almost none. */
|
|
22
|
+
const SAMPLE_INTERVAL_MICROS = 100;
|
|
23
|
+
|
|
24
|
+
/** The booted app as the profile needs it: the pipeline's own dispatch, and the teardown. */
|
|
25
|
+
export interface ProfileTarget {
|
|
26
|
+
fetch(request: Request): Promise<Response>;
|
|
27
|
+
stop(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type BootTarget = (root: string, ctx: CommandContext) => Promise<ProfileTarget>;
|
|
31
|
+
|
|
32
|
+
/** `startDev` behind `x dev`'s own claim on the state directory, so the two never share pgdata. */
|
|
33
|
+
const bootDev: BootTarget = async (root, ctx) => {
|
|
34
|
+
const services = resolveServices(root, ctx.env);
|
|
35
|
+
const { release } = await preflight({
|
|
36
|
+
stateDir: services.stateDir,
|
|
37
|
+
port: 0,
|
|
38
|
+
hostname: DEV_BINDING.hostname,
|
|
39
|
+
embeddedDb: services.db.mode === 'embedded',
|
|
40
|
+
});
|
|
41
|
+
const server = await startDev({ root, port: 0, env: ctx.env, roles: ['web'] }).catch(
|
|
42
|
+
(error: unknown) => {
|
|
43
|
+
release();
|
|
44
|
+
throw error;
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
const web = server.running.server;
|
|
48
|
+
return {
|
|
49
|
+
// In-process: no socket, so every sample is the render and none is the loopback round trip.
|
|
50
|
+
fetch: (request) =>
|
|
51
|
+
web === null ? Promise.resolve(new Response(null, { status: 503 })) : web.fetch(request),
|
|
52
|
+
async stop() {
|
|
53
|
+
try {
|
|
54
|
+
await server.stop();
|
|
55
|
+
} finally {
|
|
56
|
+
release();
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
function readRoute(raw: string | undefined): string {
|
|
63
|
+
if (raw === undefined || raw.trim() === '') {
|
|
64
|
+
throw new MissingPositionalError({
|
|
65
|
+
command: 'profile',
|
|
66
|
+
positional: 'route',
|
|
67
|
+
example: 'x profile / --json',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const route = raw.trim();
|
|
71
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(route)) {
|
|
72
|
+
throw new BadFlagError({
|
|
73
|
+
flag: 'route',
|
|
74
|
+
command: 'profile',
|
|
75
|
+
reason: `"${route}" is an absolute URL; x profile renders a route of this app, in this process`,
|
|
76
|
+
fix: `x profile ${renderFixShellArg(URL.parse(route)?.pathname ?? '/', '/')} --json`,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return route.startsWith('/') ? route : `/${route}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface RouteProfile {
|
|
83
|
+
/** The warm-up's status: every profiled request is the same route, and it answered this. */
|
|
84
|
+
readonly status: number;
|
|
85
|
+
readonly summary: ProfileSummary;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** One warm-up (first render compiles), then `runs` requests sampled. Bodies are read through. */
|
|
89
|
+
export async function profileRoute(input: {
|
|
90
|
+
readonly fetch: (request: Request) => Promise<Response>;
|
|
91
|
+
readonly path: string;
|
|
92
|
+
readonly runs: number;
|
|
93
|
+
readonly top: number;
|
|
94
|
+
readonly root: string;
|
|
95
|
+
}): Promise<RouteProfile> {
|
|
96
|
+
const request = (): Request => new Request(`http://localhost${input.path}`);
|
|
97
|
+
const warm = await input.fetch(request());
|
|
98
|
+
await warm.arrayBuffer();
|
|
99
|
+
const sampled = await profile(async () => {
|
|
100
|
+
for (let run = 0; run < input.runs; run += 1)
|
|
101
|
+
await (await input.fetch(request())).arrayBuffer();
|
|
102
|
+
}, SAMPLE_INTERVAL_MICROS);
|
|
103
|
+
return {
|
|
104
|
+
status: warm.status,
|
|
105
|
+
summary: hottestFrames(sampled.stackTraces, input.root, input.top),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const routeFailed = (route: string, status: number): Finding => ({
|
|
110
|
+
code: 'X_PROFILE_ROUTE_FAILED',
|
|
111
|
+
cause: `${route} answered ${status}, so the profile is of an error response rather than the route's render`,
|
|
112
|
+
fix: `x routes --json # the route table this app serves; then x profile <path> --json`,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
export const profileCommandOver = (boot: BootTarget): CliCommand => ({
|
|
116
|
+
spec: profileSpec,
|
|
117
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
118
|
+
const root = requireAppRoot('profile', ctx.cwd).dir;
|
|
119
|
+
const route = readRoute(ctx.args.positionals[0]);
|
|
120
|
+
const runs = intFlagOr(
|
|
121
|
+
ctx.args,
|
|
122
|
+
{ name: 'runs', command: 'profile', min: 1, max: 10_000, example: 'x profile / --runs 20' },
|
|
123
|
+
20,
|
|
124
|
+
);
|
|
125
|
+
const top = intFlagOr(
|
|
126
|
+
ctx.args,
|
|
127
|
+
{ name: 'top', command: 'profile', min: 1, max: 100, example: 'x profile / --top 10' },
|
|
128
|
+
10,
|
|
129
|
+
);
|
|
130
|
+
const target = await boot(root, ctx);
|
|
131
|
+
let result: RouteProfile;
|
|
132
|
+
try {
|
|
133
|
+
result = await profileRoute({ fetch: target.fetch, path: route, runs, top, root });
|
|
134
|
+
} finally {
|
|
135
|
+
await target.stop();
|
|
136
|
+
}
|
|
137
|
+
const { status, summary } = result;
|
|
138
|
+
const findings = status >= 400 ? [routeFailed(route, status)] : [];
|
|
139
|
+
const hottest: JsonValue = summary.hottest.map((frame) => ({ ...frame }));
|
|
140
|
+
return {
|
|
141
|
+
ok: findings.length === 0,
|
|
142
|
+
command: 'profile',
|
|
143
|
+
summary: msg('cli.profile.done', { route, runs, samples: summary.samples, status }),
|
|
144
|
+
findings,
|
|
145
|
+
data: {
|
|
146
|
+
route,
|
|
147
|
+
status,
|
|
148
|
+
runs,
|
|
149
|
+
samples: summary.samples,
|
|
150
|
+
intervalMicros: summary.intervalMicros,
|
|
151
|
+
hottest,
|
|
152
|
+
},
|
|
153
|
+
lines: summary.hottest.map((frame) =>
|
|
154
|
+
msg('cli.profile.frame', {
|
|
155
|
+
percent: frame.selfPercent,
|
|
156
|
+
name: frame.name,
|
|
157
|
+
at: frame.line === null ? frame.file : `${frame.file}:${frame.line}`,
|
|
158
|
+
}),
|
|
159
|
+
),
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
export const profileCommand: CliCommand = profileCommandOver(bootDev);
|
package/src/cmd-repro-spec.ts
CHANGED
|
@@ -7,7 +7,7 @@ export const reproSpec: CommandSpec = {
|
|
|
7
7
|
name: 'repro',
|
|
8
8
|
summary: 'a dead job or a captured 5xx, as a failing test: x repro <id> --write --verify',
|
|
9
9
|
usage:
|
|
10
|
-
'x repro <jobId|requestId|traceId|fingerprint> [--write] [--verify] | x repro --list [--code X_…] | x repro --from <file> [--write] [--verify] [--json]',
|
|
10
|
+
'x repro <jobId|requestId|traceId|fingerprint> [--write] [--verify] | x repro <id> --bundle [--include-rows] | x repro --list [--code X_…] | x repro --from <file> [--write] [--verify] [--bundle [--include-rows]] [--json]',
|
|
11
11
|
requiresApp: true,
|
|
12
12
|
flags: [
|
|
13
13
|
{
|
|
@@ -20,6 +20,18 @@ export const reproSpec: CommandSpec = {
|
|
|
20
20
|
type: 'boolean',
|
|
21
21
|
summary: 'run the written test and answer { reproduced, code, fingerprint }',
|
|
22
22
|
},
|
|
23
|
+
{
|
|
24
|
+
name: 'bundle',
|
|
25
|
+
type: 'boolean',
|
|
26
|
+
summary:
|
|
27
|
+
'write repro/bundle-<id>.json: the redacted failure, versions, schema and test, for an issue',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'include-rows',
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
summary:
|
|
33
|
+
'bundle: real values for non-key input, row and step fields (default: stand-ins); secrets stay masked',
|
|
34
|
+
},
|
|
23
35
|
{ name: 'list', type: 'boolean', summary: 'the captured bundles, newest first' },
|
|
24
36
|
{ name: 'code', type: 'string', summary: 'list: only bundles of this X_* code' },
|
|
25
37
|
{
|
package/src/cmd-repro.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
// `x repro <id>` — a production failure becomes a failing test. A dead job (its row, its steps) or
|
|
2
2
|
// a captured 5xx (`x_failures`, when `failureCapture` is on) is read, `--write` puts the replay in
|
|
3
|
-
// `repro/`,
|
|
4
|
-
// CLI wiring only:
|
|
3
|
+
// `repro/`, `--verify` runs it, `--list` shows what is held, `--bundle` writes the redacted archive
|
|
4
|
+
// an issue carries. CLI wiring only: reads `repro-bundle.ts`, archive `repro-archive-write.ts`.
|
|
5
5
|
|
|
6
6
|
import { postgresErrorGroupsStore } from '@ultimat3/admin/error-groups';
|
|
7
|
+
import { renderFixShellArg } from '@ultimat3/core';
|
|
7
8
|
import { postgresFailureStore } from '@ultimat3/db';
|
|
8
9
|
import { loadAppConfig } from './app-config-load';
|
|
9
10
|
import { loadApp } from './app-load';
|
|
10
11
|
import { requireAppRoot } from './app-root';
|
|
11
12
|
import { reproSpec } from './cmd-repro-spec';
|
|
12
13
|
import type { CliCommand, CommandContext } from './command';
|
|
13
|
-
import { MissingPositionalError } from './errors';
|
|
14
|
+
import { BadFlagError, MissingPositionalError } from './errors';
|
|
14
15
|
import { withJobDriver } from './jobs-driver';
|
|
15
16
|
import { msg } from './messages';
|
|
16
17
|
import type { CommandResult, JsonValue } from './output';
|
|
17
18
|
import { findingFrom } from './output';
|
|
18
19
|
import { flagBool, flagString } from './parse';
|
|
20
|
+
import { errorFromFile, errorFromStore } from './repro-archive-collect';
|
|
21
|
+
import { writeBundle } from './repro-archive-write';
|
|
19
22
|
import type { ReproSubject } from './repro-bundle';
|
|
20
23
|
import { resolveSubject, subjectFromFile } from './repro-bundle';
|
|
21
24
|
import { ReproNotReproducedError } from './repro-errors';
|
|
@@ -162,13 +165,42 @@ export const reproCommand: CliCommand = {
|
|
|
162
165
|
example: 'x repro --list --json',
|
|
163
166
|
});
|
|
164
167
|
}
|
|
168
|
+
const bundle = flagBool(ctx.args, 'bundle');
|
|
169
|
+
const includeRows = flagBool(ctx.args, 'include-rows');
|
|
170
|
+
if (includeRows && !bundle) {
|
|
171
|
+
throw new BadFlagError({
|
|
172
|
+
flag: 'include-rows',
|
|
173
|
+
command: 'repro',
|
|
174
|
+
reason: 'it chooses what a bundle carries, and no --bundle was asked for',
|
|
175
|
+
fix: `x repro ${id === undefined ? '--from <file>' : renderFixShellArg(id, '<id>')} --bundle --include-rows`,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (bundle && (flagBool(ctx.args, 'write') || flagBool(ctx.args, 'verify'))) {
|
|
179
|
+
throw new BadFlagError({
|
|
180
|
+
flag: 'bundle',
|
|
181
|
+
command: 'repro',
|
|
182
|
+
reason: 'a bundle is written for an issue, and --write/--verify run the test in this app',
|
|
183
|
+
fix: `x repro ${id === undefined ? '--from <file>' : renderFixShellArg(id, '<id>')} --bundle`,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
165
186
|
// The app's declarations are what mask a job's input and what a written test replays against.
|
|
166
187
|
await loadApp(root);
|
|
167
|
-
if (from !== undefined)
|
|
188
|
+
if (from !== undefined) {
|
|
189
|
+
const subject = await subjectFromFile(from);
|
|
190
|
+
if (bundle) {
|
|
191
|
+
return writeBundle(root, ctx, subject, await errorFromFile(from), { includeRows });
|
|
192
|
+
}
|
|
193
|
+
return answer(root, ctx, id ?? from, subject);
|
|
194
|
+
}
|
|
168
195
|
const captureOn = (await loadAppConfig(root))?.failureCapture.enabled === true;
|
|
169
196
|
return withJobDriver(root, ctx, async (driver) => {
|
|
170
197
|
if (id === undefined) return list(ctx);
|
|
171
|
-
|
|
198
|
+
const subject = await resolveSubject(driver, id, captureOn);
|
|
199
|
+
if (bundle) {
|
|
200
|
+
const error = await errorFromStore(driver, subject);
|
|
201
|
+
return writeBundle(root, ctx, subject, error, { includeRows });
|
|
202
|
+
}
|
|
203
|
+
return answer(root, ctx, id, subject);
|
|
172
204
|
});
|
|
173
205
|
},
|
|
174
206
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// `x status`'s origin half: `x deploy verify`'s own `/readyz` reader (`takeSample`) and origin
|
|
2
|
+
// check (`readOrigin`), folded into what answered — status, build header, role. No expectation,
|
|
3
|
+
// no wait: whether a build is fully out is `x deploy verify`'s question, and this only reports.
|
|
4
|
+
|
|
5
|
+
import { printableBuild, takeSample } from './cmd-deploy-verify-sample';
|
|
6
|
+
import { readOrigin } from './deploy-verify-flags';
|
|
7
|
+
import { UNREACHABLE } from './deploy-verify-grade';
|
|
8
|
+
|
|
9
|
+
/** One sample's own limit: a hung pod is one unreachable sample, never the whole read gone. */
|
|
10
|
+
const SAMPLE_TIMEOUT_MS = 10_000;
|
|
11
|
+
|
|
12
|
+
const ASKER = { command: 'status', example: 'x status --url https://app.example.com --json' };
|
|
13
|
+
|
|
14
|
+
/** `--url`'s one value, held to a bare http(s) origin by the reader `x deploy verify` uses. */
|
|
15
|
+
export const statusOrigin = (raw: string): string => readOrigin(raw, ASKER);
|
|
16
|
+
|
|
17
|
+
export interface OriginReport {
|
|
18
|
+
readonly origin: string;
|
|
19
|
+
readonly samples: number;
|
|
20
|
+
/** Roles the answering processes named (a role health port does; the app's web port does not). */
|
|
21
|
+
readonly roles: readonly string[];
|
|
22
|
+
/** Defined with `Object.fromEntries`: a server names these keys, `__proto__` included. */
|
|
23
|
+
readonly byBuild: Readonly<Record<string, number>>;
|
|
24
|
+
readonly byStatus: Readonly<Record<string, number>>;
|
|
25
|
+
/** 2xx answers that named no build: an image nobody stamped `BUILD_ID` into. */
|
|
26
|
+
readonly unstamped: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const bump = (counts: Map<string, number>, key: string): void => {
|
|
30
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const is2xx = (status: number | null): boolean => status !== null && status >= 200 && status < 300;
|
|
34
|
+
|
|
35
|
+
/** `samples` reads, one after another, folded. Sequential: each is a fresh balancer choice. */
|
|
36
|
+
export async function sampleOrigin(origin: string, samples: number): Promise<OriginReport> {
|
|
37
|
+
const byBuild = new Map<string, number>();
|
|
38
|
+
const byStatus = new Map<string, number>();
|
|
39
|
+
const roles = new Set<string>();
|
|
40
|
+
let unstamped = 0;
|
|
41
|
+
for (let index = 0; index < samples; index += 1) {
|
|
42
|
+
const answer = await takeSample(origin, SAMPLE_TIMEOUT_MS);
|
|
43
|
+
bump(byStatus, answer.status === null ? UNREACHABLE : String(answer.status));
|
|
44
|
+
// Counted under its printed name: these keys reach the terminal and the `--json` document.
|
|
45
|
+
if (answer.build !== null) bump(byBuild, printableBuild(answer.build));
|
|
46
|
+
else if (is2xx(answer.status)) unstamped += 1;
|
|
47
|
+
if (answer.role !== null) roles.add(answer.role);
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
origin,
|
|
51
|
+
samples,
|
|
52
|
+
roles: [...roles].sort(),
|
|
53
|
+
byBuild: Object.fromEntries(byBuild),
|
|
54
|
+
byStatus: Object.fromEntries(byStatus),
|
|
55
|
+
unstamped,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// `x status`'s declaration, apart from its body: the parser, `x help` and the `errors` step
|
|
2
|
+
// read it without loading `cmd-status.ts`, which `registry.ts` imports only when the command runs.
|
|
3
|
+
|
|
4
|
+
import type { CommandSpec } from './parse';
|
|
5
|
+
|
|
6
|
+
/** `/readyz` reads per origin a bare `--url` takes: enough to see two builds behind one balancer. */
|
|
7
|
+
export const STATUS_DEFAULT_SAMPLES = 5;
|
|
8
|
+
/** The most per origin: each is its own connection, and this is a read, not a load test. */
|
|
9
|
+
export const STATUS_MAX_SAMPLES = 50;
|
|
10
|
+
|
|
11
|
+
export const statusSpec: CommandSpec = {
|
|
12
|
+
name: 'status',
|
|
13
|
+
summary:
|
|
14
|
+
'what the running deployment is: the build each live worker runs, and what each --url answers',
|
|
15
|
+
usage: 'x status [--url <origin>[,<origin>…]] [--samples n] [--json]',
|
|
16
|
+
requiresApp: true,
|
|
17
|
+
flags: [
|
|
18
|
+
{
|
|
19
|
+
name: 'url',
|
|
20
|
+
type: 'string',
|
|
21
|
+
summary:
|
|
22
|
+
'origins whose /readyz to sample, comma-separated: the app, or a role’s health port (worker, scheduler, sync, replicator)',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'samples',
|
|
26
|
+
type: 'string',
|
|
27
|
+
summary: `/readyz reads per origin, each on its own connection, 1 to ${STATUS_MAX_SAMPLES} (default ${STATUS_DEFAULT_SAMPLES})`,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// `x status`: what the running deployment is, from what it already records — every live worker's
|
|
2
|
+
// row in `x_job_workers` (stamped with its build), and the build each `--url` origin answers
|
|
3
|
+
// `/readyz` with. A read, never a verdict: `x deploy verify` is the gate on one build being out.
|
|
4
|
+
|
|
5
|
+
import type { WorkerRecord } from '@ultimat3/jobs';
|
|
6
|
+
import { requireAppRoot } from './app-root';
|
|
7
|
+
import { printableBuild } from './cmd-deploy-verify-sample';
|
|
8
|
+
import { type OriginReport, sampleOrigin, statusOrigin } from './cmd-status-sample';
|
|
9
|
+
import { STATUS_DEFAULT_SAMPLES, STATUS_MAX_SAMPLES, statusSpec } from './cmd-status-spec';
|
|
10
|
+
import type { CliCommand, CommandContext } from './command';
|
|
11
|
+
import { UNKNOWN_BUILD } from './deploy-verify-grade';
|
|
12
|
+
import { parseIntFlag } from './flag-number';
|
|
13
|
+
import { withJobDriver } from './jobs-driver';
|
|
14
|
+
import { workerToJson } from './jobs-json';
|
|
15
|
+
import { msg } from './messages';
|
|
16
|
+
import type { CommandResult, JsonValue } from './output';
|
|
17
|
+
import { flagList, flagString } from './parse';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Roles whose build no fleet-wide record holds. A sync node keeps its clients' builds in its own
|
|
21
|
+
* memory (the `/_x` live panel reads them in `x dev`), the scheduler and the replicator write no
|
|
22
|
+
* row, and the web pods are only ever sampled. Each answers `/readyz` with its build, so naming its
|
|
23
|
+
* origin in `--url` is how it is read. `migrate` runs once and exits: there is nothing running.
|
|
24
|
+
*/
|
|
25
|
+
export const UNRECORDED_ROLES = ['web', 'sync', 'scheduler', 'replicator'] as const;
|
|
26
|
+
|
|
27
|
+
function readSamples(ctx: CommandContext): number {
|
|
28
|
+
const raw = flagString(ctx.args, 'samples');
|
|
29
|
+
if (raw === undefined) return STATUS_DEFAULT_SAMPLES;
|
|
30
|
+
return parseIntFlag(raw, {
|
|
31
|
+
name: 'samples',
|
|
32
|
+
command: 'status',
|
|
33
|
+
min: 1,
|
|
34
|
+
max: STATUS_MAX_SAMPLES,
|
|
35
|
+
example: 'x status --url https://app.example.com --samples 5 --json',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function workersData(workers: readonly WorkerRecord[]): { readonly [key: string]: JsonValue } {
|
|
40
|
+
const byBuild = new Map<string, number>();
|
|
41
|
+
for (const worker of workers) {
|
|
42
|
+
// Printed: a row's stamp passes the same screen a stranger's `/readyz` header does.
|
|
43
|
+
const build = worker.build === undefined ? UNKNOWN_BUILD : printableBuild(worker.build);
|
|
44
|
+
byBuild.set(build, (byBuild.get(build) ?? 0) + 1);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
count: workers.length,
|
|
48
|
+
draining: workers.filter((worker) => worker.drainingAt !== undefined).length,
|
|
49
|
+
// `fromEntries` DEFINES each key: a build id is written by whoever stamped the image.
|
|
50
|
+
byBuild: Object.fromEntries(byBuild),
|
|
51
|
+
rows: workers.map((worker) => ({
|
|
52
|
+
...(workerToJson(worker) as { readonly [key: string]: JsonValue }),
|
|
53
|
+
build: worker.build === undefined ? null : printableBuild(worker.build),
|
|
54
|
+
draining: worker.drainingAt !== undefined,
|
|
55
|
+
})),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const originJson = (report: OriginReport): JsonValue => ({
|
|
60
|
+
origin: report.origin,
|
|
61
|
+
samples: report.samples,
|
|
62
|
+
roles: [...report.roles],
|
|
63
|
+
byBuild: { ...report.byBuild },
|
|
64
|
+
byStatus: { ...report.byStatus },
|
|
65
|
+
unstamped: report.unstamped,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/** `name: count` pairs, most first: the human line of a distribution. */
|
|
69
|
+
const spread = (counts: Readonly<Record<string, number>>): string => {
|
|
70
|
+
const pairs = Object.entries(counts).sort((a, b) => b[1] - a[1]);
|
|
71
|
+
return pairs.length === 0 ? '—' : pairs.map(([key, count]) => `${key} ×${count}`).join(', ');
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const statusCommand: CliCommand = {
|
|
75
|
+
spec: statusSpec,
|
|
76
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
77
|
+
const root = requireAppRoot('status', ctx.cwd).dir;
|
|
78
|
+
// Flags first, so a typo costs neither a database connection nor a request.
|
|
79
|
+
const origins = flagList(ctx.args, 'url').map(statusOrigin);
|
|
80
|
+
const samples = readSamples(ctx);
|
|
81
|
+
const reports: OriginReport[] = [];
|
|
82
|
+
for (const origin of origins) reports.push(await sampleOrigin(origin, samples));
|
|
83
|
+
// The queue `x jobs list` reads, through the same boot: one answer to "which database".
|
|
84
|
+
return withJobDriver(root, ctx, async (driver) => {
|
|
85
|
+
const workers = (await driver.introspect?.workers()) ?? [];
|
|
86
|
+
const data = workersData(workers);
|
|
87
|
+
const lines = [
|
|
88
|
+
` ${msg('cli.status.workers', { count: workers.length, builds: spread(data['byBuild'] as Record<string, number>) })}`,
|
|
89
|
+
...reports.map(
|
|
90
|
+
(report) =>
|
|
91
|
+
` ${msg('cli.status.origin', { origin: report.origin, samples: report.samples, builds: spread(report.byBuild), statuses: spread(report.byStatus) })}`,
|
|
92
|
+
),
|
|
93
|
+
` ${msg('cli.status.unrecorded', { roles: UNRECORDED_ROLES.join(', ') })}`,
|
|
94
|
+
];
|
|
95
|
+
return {
|
|
96
|
+
ok: true,
|
|
97
|
+
command: 'status',
|
|
98
|
+
summary: msg('cli.status.summary', { workers: workers.length, origins: reports.length }),
|
|
99
|
+
lines,
|
|
100
|
+
data: {
|
|
101
|
+
workers: data,
|
|
102
|
+
origins: reports.map(originJson),
|
|
103
|
+
unrecorded: [...UNRECORDED_ROLES],
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
};
|
package/src/cmd-token-spec.ts
CHANGED
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
import type { CommandSpec } from './parse';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* No `grant`: a key's scopes are fixed when it is issued, so a wider set is a new key and a revoke
|
|
8
|
+
* of the old (`wiki/Known-Gaps.md`). It was planned until 31.x; the parser now refuses it.
|
|
9
|
+
*/
|
|
10
|
+
export const TOKEN_SUBCOMMANDS = ['create', 'list', 'revoke'] as const;
|
|
8
11
|
|
|
9
12
|
/** The longest lifetime `--days` takes: ten years is "no expiry" said out loud. */
|
|
10
13
|
export const TOKEN_MAX_DAYS = 3_650;
|
package/src/cmd-token.ts
CHANGED
|
@@ -8,10 +8,10 @@ import { describeApiKey, issueApiKey, postgresAuthAdapter, revokeApiKey } from '
|
|
|
8
8
|
import { type Clock, systemClock, tryResolveEnvironment } from '@ultimat3/core';
|
|
9
9
|
import { requireAppRoot } from './app-root';
|
|
10
10
|
import { plannedSubcommand } from './cmd-planned';
|
|
11
|
-
import { TOKEN_MAX_DAYS, tokenSpec } from './cmd-token-spec';
|
|
11
|
+
import { TOKEN_MAX_DAYS, TOKEN_SUBCOMMANDS, tokenSpec } from './cmd-token-spec';
|
|
12
12
|
import type { CliCommand, CommandContext } from './command';
|
|
13
13
|
import { ok } from './command';
|
|
14
|
-
import { BadFlagError, MissingPositionalError } from './errors';
|
|
14
|
+
import { BadFlagError, MissingPositionalError, MissingSubcommandError } from './errors';
|
|
15
15
|
import { parseIntFlag } from './flag-number';
|
|
16
16
|
import { readsAsProduction } from './mcp-db-target';
|
|
17
17
|
import { msg } from './messages';
|
|
@@ -166,7 +166,11 @@ export const tokenCommandOver = (open: OpenToken, clock: Clock = systemClock): C
|
|
|
166
166
|
if (sub === 'create') return create(ctx, open, root, clock);
|
|
167
167
|
if (sub === 'list') return list(ctx, open, root);
|
|
168
168
|
if (sub === 'revoke') return revoke(ctx, open, root, clock);
|
|
169
|
-
|
|
169
|
+
// The parser refuses a bare `x token` (no default: `create` writes a credential); this covers
|
|
170
|
+
// a `ParsedArgs` built by hand.
|
|
171
|
+
if (sub === undefined)
|
|
172
|
+
throw new MissingSubcommandError({ command: 'token', known: TOKEN_SUBCOMMANDS });
|
|
173
|
+
throw plannedSubcommand('token', sub);
|
|
170
174
|
},
|
|
171
175
|
});
|
|
172
176
|
|