@ultimat3/cli 31.25.0 → 31.27.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 +44 -36
- package/README.md +5 -4
- package/package.json +29 -29
- package/src/app-mcp.ts +17 -3
- package/src/cmd-cache-spec.ts +5 -2
- package/src/cmd-db-recount.ts +7 -0
- 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 +4 -1
- 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-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/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/dispatch.ts +6 -1
- package/src/doctor-browser.ts +60 -0
- package/src/error-codes-verify.ts +47 -0
- package/src/error-codes.ts +14 -23
- package/src/exercise-database.ts +40 -7
- 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 +9 -11
- package/src/generate-feature-required.ts +9 -4
- package/src/generate-files.ts +20 -2
- package/src/generate-kinds.ts +5 -1
- package/src/guards.ts +21 -6
- 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/mcp-errors-verify.ts +35 -0
- package/src/mcp-errors.ts +10 -19
- package/src/mcp-host-logs.ts +121 -0
- package/src/mcp-host.ts +12 -73
- package/src/messages-floor.ts +19 -0
- package/src/messages-status.ts +10 -0
- package/src/messages.ts +21 -0
- package/src/registry.ts +4 -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/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 +4 -0
- package/src/templates/scaffold-db-package.ts +3 -0
- package/src/templates/scaffold-docs.ts +8 -6
- package/src/templates/scaffold-repo.ts +2 -7
- 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 +1 -1
- package/src/upgrade-gate.ts +6 -1
- package/src/upgrade-guards-baseline.ts +43 -0
- package/src/upgrade-guards.ts +37 -2
- package/src/upgrade-report.ts +3 -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/Agents.md +2 -5
- package/wiki/CLI-Reference.md +142 -23
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Entities-And-Migrations.md +1 -1
- package/wiki/Interface-Rules.md +5 -0
- package/wiki/Jobs-And-Workflows.md +3 -3
- package/wiki/Known-Gaps.md +5 -1
- package/wiki/MCP-And-AI.md +103 -2
- package/wiki/Mail.md +52 -0
- package/wiki/PWA-And-Offline.md +1 -1
- package/wiki/Scraping.md +19 -4
- package/wiki/Troubleshooting.md +3 -3
- package/wiki/Tutorial-05-Deploy-Free.md +2 -2
- package/wiki/Upgrading.md +3 -0
|
@@ -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);
|
|
@@ -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
|
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// One coverage slice's island chunks, folded into its per-file facts: the source maps `mountIsland`
|
|
2
|
+
// recorded under `ISLAND_COVERAGE_ENV`, read, and each chunk's lcov record credited back to the
|
|
3
|
+
// app sources it was built from (`coverage-remap.ts`).
|
|
4
|
+
|
|
5
|
+
// why: Bun ships no directory-exists probe (`Bun.file` answers files only).
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
// why: Bun ships no path API; `posix` names a module, `resolve` places a map's sources.
|
|
8
|
+
import { join, posix, resolve, sep } from 'node:path';
|
|
9
|
+
import type { CoverageMap, FileCoverage, LcovRecord } from './coverage-lcov';
|
|
10
|
+
import type { ChunkLines, ChunkMap } from './coverage-remap';
|
|
11
|
+
import { chunkLines, withChunkLines } from './coverage-remap';
|
|
12
|
+
import { readSource } from './coverage-source';
|
|
13
|
+
import { posixRelative } from './posix-path';
|
|
14
|
+
|
|
15
|
+
/** The subdirectory of a slice's coverage directory its island maps land in. */
|
|
16
|
+
export const ISLAND_MAPS_DIR = 'islands';
|
|
17
|
+
|
|
18
|
+
const strings = (value: unknown): readonly string[] | undefined =>
|
|
19
|
+
Array.isArray(value) && value.every((one) => typeof one === 'string') ? value : undefined;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* One sidecar `{ module, cwd, map }` as a `ChunkMap`, or nothing when it is not one — a map the
|
|
23
|
+
* builder handed over malformed credits no line, so the floor reads LOWER, never higher.
|
|
24
|
+
*/
|
|
25
|
+
export function parseChunkMap(text: string): ChunkMap | undefined {
|
|
26
|
+
let outer: unknown;
|
|
27
|
+
let map: unknown;
|
|
28
|
+
try {
|
|
29
|
+
outer = JSON.parse(text);
|
|
30
|
+
const raw = (outer as Record<string, unknown> | null)?.['map'];
|
|
31
|
+
map = typeof raw === 'string' ? JSON.parse(raw) : undefined;
|
|
32
|
+
} catch {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const { module, cwd } = (outer ?? {}) as { module?: unknown; cwd?: unknown };
|
|
36
|
+
const { sources, sourcesContent, mappings } = (map ?? {}) as Record<string, unknown>;
|
|
37
|
+
const listed = strings(sources);
|
|
38
|
+
if (typeof module !== 'string' || typeof cwd !== 'string' || typeof mappings !== 'string') {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
if (listed === undefined || !Array.isArray(sourcesContent)) return undefined;
|
|
42
|
+
return {
|
|
43
|
+
module,
|
|
44
|
+
// Bun writes each source relative to the BUILDING process's cwd (`island-sources.ts`).
|
|
45
|
+
sources: listed.map((one) => resolve(cwd, one).split(sep).join('/')),
|
|
46
|
+
sourcesContent: sourcesContent.map((one: unknown) =>
|
|
47
|
+
typeof one === 'string' ? one : undefined,
|
|
48
|
+
),
|
|
49
|
+
mappings,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Every map one slice recorded, by the module name its `SF:` line ends in. */
|
|
54
|
+
export async function readChunkMaps(dir: string): Promise<ReadonlyMap<string, ChunkMap>> {
|
|
55
|
+
const out = new Map<string, ChunkMap>();
|
|
56
|
+
const at = join(dir, ISLAND_MAPS_DIR);
|
|
57
|
+
// Absent: the slice mounted no island with a map, so there is nothing to fold.
|
|
58
|
+
if (!existsSync(at)) return out;
|
|
59
|
+
for await (const name of new Bun.Glob('*.json').scan({ cwd: at })) {
|
|
60
|
+
const parsed = parseChunkMap(await Bun.file(join(at, name)).text());
|
|
61
|
+
if (parsed !== undefined) out.set(parsed.module, parsed);
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The app's coverage key for an absolute path, when it is the app's own source. */
|
|
67
|
+
const appKey =
|
|
68
|
+
(root: string) =>
|
|
69
|
+
(absolute: string): string | undefined => {
|
|
70
|
+
const key = posixRelative(root, absolute);
|
|
71
|
+
return /^(?:apps|packages)\//.test(key) && !key.includes('/node_modules/') ? key : undefined;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** One slice's lcov records and the island maps it recorded. */
|
|
75
|
+
export interface ChunkPart {
|
|
76
|
+
readonly records: readonly LcovRecord[];
|
|
77
|
+
readonly maps: ReadonlyMap<string, ChunkMap>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* `merged` — every slice's direct records already folded — with every chunk record that has a map
|
|
82
|
+
* credited to the sources behind it. After the fold, never per slice: a source one slice only
|
|
83
|
+
* mounted and another loaded directly then has the direct line set, rather than two line sets
|
|
84
|
+
* the fold would reconcile by dropping the misses one of them did not list. A record whose module
|
|
85
|
+
* has no map is left alone — a framework file or an island built without one.
|
|
86
|
+
*/
|
|
87
|
+
export async function withIslandChunks(
|
|
88
|
+
root: string,
|
|
89
|
+
merged: CoverageMap,
|
|
90
|
+
parts: readonly ChunkPart[],
|
|
91
|
+
): Promise<CoverageMap> {
|
|
92
|
+
if (parts.every((part) => part.maps.size === 0)) return merged;
|
|
93
|
+
const texts = new Map<string, string | undefined>();
|
|
94
|
+
const credited = new Map<string, { hit: Set<number>; miss: Set<number> }>();
|
|
95
|
+
for (const { records, maps } of parts)
|
|
96
|
+
for (const record of records) {
|
|
97
|
+
const map = maps.get(posix.basename(record.file));
|
|
98
|
+
if (map === undefined) continue;
|
|
99
|
+
for (const source of map.sources) {
|
|
100
|
+
const key = appKey(root)(source);
|
|
101
|
+
if (key !== undefined && !texts.has(key)) texts.set(key, await readSource(root, key));
|
|
102
|
+
}
|
|
103
|
+
for (const [key, lines] of chunkLines(record, map, appKey(root), (k) => texts.get(k))) {
|
|
104
|
+
const into = credited.get(key) ?? { hit: new Set<number>(), miss: new Set<number>() };
|
|
105
|
+
for (const line of lines.hit) into.hit.add(line);
|
|
106
|
+
for (const line of lines.miss) into.miss.add(line);
|
|
107
|
+
credited.set(key, into);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const out: Record<string, FileCoverage> = { ...merged };
|
|
111
|
+
for (const [key, lines] of credited) {
|
|
112
|
+
const source = texts.get(key);
|
|
113
|
+
if (source === undefined) continue;
|
|
114
|
+
const settled: ChunkLines = {
|
|
115
|
+
hit: lines.hit,
|
|
116
|
+
miss: new Set([...lines.miss].filter((line) => !lines.hit.has(line))),
|
|
117
|
+
};
|
|
118
|
+
out[key] = withChunkLines(merged[key], settled);
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
package/src/coverage-lcov.ts
CHANGED
|
@@ -65,6 +65,12 @@ export interface FileCoverage {
|
|
|
65
65
|
readonly miss: readonly number[];
|
|
66
66
|
readonly funcsFound: number;
|
|
67
67
|
readonly funcsHit: number;
|
|
68
|
+
/**
|
|
69
|
+
* Reached only through an island's built chunk (`coverage-remap.ts`): its lines are the ones the
|
|
70
|
+
* chunk's map names, not Bun's line set for the source. Folded under a direct record, never
|
|
71
|
+
* beside it (`mergeFileCoverage`).
|
|
72
|
+
*/
|
|
73
|
+
readonly chunkOnly?: true;
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
export const fileCoverageOf = (record: LcovRecord): FileCoverage => {
|
|
@@ -93,6 +99,21 @@ export const fileCoverageOf = (record: LcovRecord): FileCoverage => {
|
|
|
93
99
|
*/
|
|
94
100
|
export function mergeFileCoverage(parts: readonly FileCoverage[]): FileCoverage {
|
|
95
101
|
if (parts.length === 1) return parts[0] as FileCoverage;
|
|
102
|
+
// A chunk-only part names a smaller line set, so beside a direct record it would drop every
|
|
103
|
+
// miss the direct one lists outside it. The direct line set wins, as in one run: the chunk only
|
|
104
|
+
// turns its misses into hits. Only when NO part loaded the file are chunk parts folded alone.
|
|
105
|
+
const direct = parts.filter((part) => part.chunkOnly !== true);
|
|
106
|
+
if (direct.length > 0 && direct.length < parts.length) {
|
|
107
|
+
const base = mergeFileCoverage(direct);
|
|
108
|
+
const ran = new Set(parts.flatMap((part) => (part.chunkOnly === true ? part.hit : [])));
|
|
109
|
+
const turned = base.miss.filter((line) => ran.has(line));
|
|
110
|
+
if (turned.length === 0) return base;
|
|
111
|
+
return {
|
|
112
|
+
...base,
|
|
113
|
+
hit: [...base.hit, ...turned].sort((a, b) => a - b),
|
|
114
|
+
miss: base.miss.filter((line) => !ran.has(line)),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
96
117
|
const hit = new Set<number>();
|
|
97
118
|
for (const part of parts) for (const line of part.hit) hit.add(line);
|
|
98
119
|
const missIn = parts.map((part) => new Set(part.miss));
|
|
@@ -104,6 +125,7 @@ export function mergeFileCoverage(parts: readonly FileCoverage[]): FileCoverage
|
|
|
104
125
|
miss: miss.sort((a, b) => a - b),
|
|
105
126
|
funcsFound: Math.max(0, ...parts.map((part) => part.funcsFound)),
|
|
106
127
|
funcsHit: Math.max(0, ...parts.map((part) => part.funcsHit)),
|
|
128
|
+
...(direct.length === 0 ? { chunkOnly: true as const } : {}),
|
|
107
129
|
};
|
|
108
130
|
}
|
|
109
131
|
|
|
@@ -166,16 +188,32 @@ export function decodeLines(text: string): readonly number[] {
|
|
|
166
188
|
return lines;
|
|
167
189
|
}
|
|
168
190
|
|
|
169
|
-
/**
|
|
191
|
+
/**
|
|
192
|
+
* A file's facts as they cross `--json`: hit runs, miss runs, `[funcsFound, funcsHit]`, and
|
|
193
|
+
* `c: 1` on a chunk-only record. Absent `c` is a direct record — every part written before it.
|
|
194
|
+
*/
|
|
170
195
|
export type CoverageWire = Readonly<
|
|
171
|
-
Record<
|
|
196
|
+
Record<
|
|
197
|
+
string,
|
|
198
|
+
{
|
|
199
|
+
readonly h: string;
|
|
200
|
+
readonly m: string;
|
|
201
|
+
readonly f: readonly [number, number];
|
|
202
|
+
readonly c?: 1;
|
|
203
|
+
}
|
|
204
|
+
>
|
|
172
205
|
>;
|
|
173
206
|
|
|
174
207
|
export const encodeCoverage = (map: CoverageMap): CoverageWire =>
|
|
175
208
|
Object.fromEntries(
|
|
176
209
|
Object.entries(map).map(([file, one]) => [
|
|
177
210
|
file,
|
|
178
|
-
{
|
|
211
|
+
{
|
|
212
|
+
h: encodeLines(one.hit),
|
|
213
|
+
m: encodeLines(one.miss),
|
|
214
|
+
f: [one.funcsFound, one.funcsHit],
|
|
215
|
+
...(one.chunkOnly === true ? { c: 1 as const } : {}),
|
|
216
|
+
},
|
|
179
217
|
]),
|
|
180
218
|
);
|
|
181
219
|
|
|
@@ -185,11 +223,17 @@ export function decodeCoverage(value: unknown): CoverageMap | undefined {
|
|
|
185
223
|
const out = new Map<string, FileCoverage>();
|
|
186
224
|
for (const [file, raw] of Object.entries(value)) {
|
|
187
225
|
if (typeof raw !== 'object' || raw === null) return undefined;
|
|
188
|
-
const { h, m, f } = raw as { h?: unknown; m?: unknown; f?: unknown };
|
|
226
|
+
const { h, m, f, c } = raw as { h?: unknown; m?: unknown; f?: unknown; c?: unknown };
|
|
189
227
|
if (typeof h !== 'string' || typeof m !== 'string' || !Array.isArray(f)) return undefined;
|
|
190
228
|
const [found, hit] = f as unknown[];
|
|
191
229
|
if (typeof found !== 'number' || typeof hit !== 'number') return undefined;
|
|
192
|
-
out.set(file, {
|
|
230
|
+
out.set(file, {
|
|
231
|
+
hit: decodeLines(h),
|
|
232
|
+
miss: decodeLines(m),
|
|
233
|
+
funcsFound: found,
|
|
234
|
+
funcsHit: hit,
|
|
235
|
+
...(c === 1 ? { chunkOnly: true as const } : {}),
|
|
236
|
+
});
|
|
193
237
|
}
|
|
194
238
|
return Object.fromEntries(out);
|
|
195
239
|
}
|