@ultimat3/cli 31.26.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-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/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 +5 -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/CLI-Reference.md +142 -23
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Entities-And-Migrations.md +1 -1
- 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/PWA-And-Offline.md +1 -1
- package/wiki/Troubleshooting.md +3 -3
- package/wiki/Tutorial-05-Deploy-Free.md +2 -2
- package/wiki/Upgrading.md +3 -0
package/src/island-link.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface BuiltOutput {
|
|
|
21
21
|
readonly file?: string;
|
|
22
22
|
/** Emitted code, the debug-id comment already removed. */
|
|
23
23
|
readonly code: string;
|
|
24
|
+
/** Its external source map, kept only by a coverage build (`mountIsland` records it). */
|
|
25
|
+
readonly map?: string;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export interface LinkedFile {
|
|
@@ -33,6 +35,8 @@ export interface LinkedFile {
|
|
|
33
35
|
readonly code: string;
|
|
34
36
|
/** Final basenames of the outputs this one imports, statically or by `import()`, direct only. */
|
|
35
37
|
readonly imports: readonly string[];
|
|
38
|
+
/** The output's map, unchanged: a renamed specifier stays on its line, so the lines still hold. */
|
|
39
|
+
readonly map?: string;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
/** The final basename a shared chunk is served under — beside every entry, under one base path. */
|
|
@@ -83,6 +87,7 @@ export function linkOutputs(outputs: readonly BuiltOutput[]): readonly LinkedFil
|
|
|
83
87
|
identity: contentHash(code),
|
|
84
88
|
code,
|
|
85
89
|
imports: [...new Set(imports)].sort(),
|
|
90
|
+
...(output.map === undefined ? {} : { map: output.map }),
|
|
86
91
|
};
|
|
87
92
|
visiting.delete(output.path);
|
|
88
93
|
linked.set(output.path, done);
|
package/src/island-outputs.ts
CHANGED
|
@@ -41,6 +41,7 @@ export async function builtOutputs(
|
|
|
41
41
|
files: readonly string[],
|
|
42
42
|
artifacts: readonly Bun.BuildArtifact[],
|
|
43
43
|
sourcePaths: Map<string, SourcePaths>,
|
|
44
|
+
keepMaps = false,
|
|
44
45
|
): Promise<readonly BuiltOutput[]> {
|
|
45
46
|
const byStem = new Map(files.map((file) => [withoutExtension(file), file]));
|
|
46
47
|
const maps = new Map<string, string>();
|
|
@@ -66,6 +67,8 @@ export async function builtOutputs(
|
|
|
66
67
|
path: key,
|
|
67
68
|
...(file === undefined ? {} : { file }),
|
|
68
69
|
code: stripDebugId(await artifact.text()),
|
|
70
|
+
// A coverage build's only: `mountIsland` records it, and nothing ships or serves it.
|
|
71
|
+
...(keepMaps && map !== undefined ? { map } : {}),
|
|
69
72
|
});
|
|
70
73
|
}
|
|
71
74
|
return outputs;
|
|
@@ -120,6 +123,7 @@ export function entryChunks(
|
|
|
120
123
|
...stableChunk(file, entry.identity, entry.code),
|
|
121
124
|
imports: closure(entry.imports),
|
|
122
125
|
sources: withOwnFile(file, sources.get(entry.path) ?? []),
|
|
126
|
+
...(entry.map === undefined ? {} : { map: entry.map }),
|
|
123
127
|
});
|
|
124
128
|
}
|
|
125
129
|
return chunks;
|
|
@@ -143,6 +147,7 @@ export function sharedChunks(
|
|
|
143
147
|
.map((chunk) => chunk.file)
|
|
144
148
|
.sort(),
|
|
145
149
|
sources: sources.get(one.path) ?? [],
|
|
150
|
+
...(one.map === undefined ? {} : { map: one.map }),
|
|
146
151
|
});
|
|
147
152
|
}
|
|
148
153
|
return out.sort((a, b) => (a.url < b.url ? -1 : a.url > b.url ? 1 : 0));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// `errors.explain`'s rows for the gate's own floor and run — `x.verify.json`'s ratchets, a step's
|
|
2
|
+
// deadline, the shard/merge split, the services a suite needs — split out of `mcp-errors.ts` under
|
|
3
|
+
// the 500-line ceiling. Spread into `CLI_FIXES` there, whose `Record<CliErrorCode, string>` is still
|
|
4
|
+
// what makes a code without a row a build error.
|
|
5
|
+
|
|
6
|
+
import type { CliErrorCode } from './error-codes';
|
|
7
|
+
|
|
8
|
+
export const VERIFY_FIXES = {
|
|
9
|
+
// The same two edits `vanishedSuiteFinding` names, verbatim, so both surfaces of this code hand
|
|
10
|
+
// an agent one instruction. Neither edit is scripted here on purpose: a command that rewrites
|
|
11
|
+
// x.verify.json is the gate editing its own ratchet, which is the false green the floor closes.
|
|
12
|
+
X_VERIFY_SUITE_VANISHED:
|
|
13
|
+
'x verify --json # restore the suite, or drop its name from x.verify.json in the commit that says why',
|
|
14
|
+
X_VERIFY_SHARD_INVALID: 'x verify --only unit --shard 1/4 --json',
|
|
15
|
+
X_VERIFY_MERGE_INCOMPLETE:
|
|
16
|
+
'x verify merge parts/*.json --json # after every CI job uploaded its part',
|
|
17
|
+
X_VERIFY_MERGE_INPUT: 'x verify --only unit --json > part.json # one document per part',
|
|
18
|
+
X_VERIFY_STEP_TIMEOUT:
|
|
19
|
+
'x verify --only unit --json # reproduce the step alone; one that needs longer states it under "stepTimeoutMs" in x.verify.json',
|
|
20
|
+
X_COVERAGE_BELOW_FLOOR:
|
|
21
|
+
'x verify --only unit --json # names the ten files losing the most lines; cover the worst with a test beside it',
|
|
22
|
+
X_COVERAGE_FLOOR_UNSTATED:
|
|
23
|
+
'x verify --only unit --json # the finding carries the measured numbers and the "coverage" line to add to x.verify.json',
|
|
24
|
+
X_COVERAGE_FLOOR_STALE:
|
|
25
|
+
'x verify --only unit --json # the finding carries the measured numbers; raise "coverage" in x.verify.json to them',
|
|
26
|
+
X_VERIFY_SKIPS_OVER_CEILING:
|
|
27
|
+
'x test unit --json # then set what the skipped tests need, or raise skipCeiling in x.verify.json with the reason in the diff',
|
|
28
|
+
X_TEST_SERVICES_UNAVAILABLE: 'docker compose -f docker/docker-compose.test.yml up -d --wait',
|
|
29
|
+
X_VERIFY_E2E_BROWSER_MISSING:
|
|
30
|
+
'curl -fsSLo /tmp/google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && sudo apt-get install -y /tmp/google-chrome.deb',
|
|
31
|
+
X_VERIFY_STRICT_UNRUN:
|
|
32
|
+
'x verify --json # data.skipReasons names each step that ran no check: give it a suite, or write "skip": { "<step>": "<why>" } in x.verify.json',
|
|
33
|
+
X_GUARD_OVER_BASELINE: 'x verify --only boundaries --json',
|
|
34
|
+
X_GUARD_BASELINE_STALE: 'x verify --only boundaries --json',
|
|
35
|
+
} as const satisfies Partial<Record<CliErrorCode, string>>;
|
package/src/mcp-errors.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { CliErrorCode } from './error-codes';
|
|
|
8
8
|
import { CLI_ERROR_CODES } from './error-codes';
|
|
9
9
|
import { codeFixes, codeFixScan } from './error-fixes';
|
|
10
10
|
import { SHOT_FIXES } from './mcp-errors-shot';
|
|
11
|
+
import { VERIFY_FIXES } from './mcp-errors-verify';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* One runnable command per CLI code. Typed over `CliErrorCode`, so a new code fails the build.
|
|
@@ -41,18 +42,6 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
41
42
|
X_ENV_EXAMPLE_DRIFT: 'x env example --json',
|
|
42
43
|
X_TEST_NO_FILES: 'x test --json # from the repo root, or pass --cwd to it',
|
|
43
44
|
X_TEST_BUDGET_INVALID: 'ULTIMATE_TEST_MEMORY_BUDGET=3g x verify --json',
|
|
44
|
-
X_VERIFY_SHARD_INVALID: 'x verify --only unit --shard 1/4 --json',
|
|
45
|
-
X_VERIFY_MERGE_INCOMPLETE:
|
|
46
|
-
'x verify merge parts/*.json --json # after every CI job uploaded its part',
|
|
47
|
-
X_VERIFY_MERGE_INPUT: 'x verify --only unit --json > part.json # one document per part',
|
|
48
|
-
X_VERIFY_STEP_TIMEOUT:
|
|
49
|
-
'x verify --only unit --json # reproduce the step alone; one that needs longer states it under "stepTimeoutMs" in x.verify.json',
|
|
50
|
-
X_COVERAGE_BELOW_FLOOR:
|
|
51
|
-
'x verify --only unit --json # names the ten files losing the most lines; cover the worst with a test beside it',
|
|
52
|
-
X_COVERAGE_FLOOR_UNSTATED:
|
|
53
|
-
'x verify --only unit --json # the finding carries the measured numbers and the "coverage" line to add to x.verify.json',
|
|
54
|
-
X_COVERAGE_FLOOR_STALE:
|
|
55
|
-
'x verify --only unit --json # the finding carries the measured numbers; raise "coverage" in x.verify.json to them',
|
|
56
45
|
// Unthrown since `--worker` was deleted, and kept only because this record is typed over every
|
|
57
46
|
// registered code: `--shard i/n` is the one way to rerun a slice.
|
|
58
47
|
X_TEST_SHARD_FAILED: 'x verify --only unit --shard 1/2 --json',
|
|
@@ -73,6 +62,8 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
73
62
|
'x i18n check --json # the finding names both copies and the package.json to pin',
|
|
74
63
|
// `x shot` and the `ui.*` tools: their own family, in `mcp-errors-shot.ts`.
|
|
75
64
|
...SHOT_FIXES,
|
|
65
|
+
// The gate's floor, run and split: their own family, in `mcp-errors-verify.ts`.
|
|
66
|
+
...VERIFY_FIXES,
|
|
76
67
|
X_GH_UNAVAILABLE: 'gh auth login # install first from https://cli.github.com',
|
|
77
68
|
X_GH_NOT_AUTHENTICATED: 'gh auth login',
|
|
78
69
|
X_GH_COMMAND_FAILED: 'x ci --json # the finding carries the gh invocation that failed',
|
|
@@ -90,11 +81,6 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
90
81
|
X_TYPECHECK_FAILED: 'bunx tsc -p . --pretty false',
|
|
91
82
|
X_LINT_FAILED: 'bunx biome check .',
|
|
92
83
|
X_TEST_FAILED: 'x test --json # the finding carries the exact bun test invocation that failed',
|
|
93
|
-
// The same two edits `vanishedSuiteFinding` names, verbatim, so both surfaces of this code hand
|
|
94
|
-
// an agent one instruction. Neither edit is scripted here on purpose: a command that rewrites
|
|
95
|
-
// x.verify.json is the gate editing its own ratchet, which is the false green the floor closes.
|
|
96
|
-
X_VERIFY_SUITE_VANISHED:
|
|
97
|
-
'x verify --json # restore the suite, or drop its name from x.verify.json in the commit that says why',
|
|
98
84
|
X_FILE_TOO_LONG: 'x verify --json # the finding names the file to split',
|
|
99
85
|
X_PACKAGE_SHAPE: 'bun run verify --json # every finding carries its own new-package.ts command',
|
|
100
86
|
// NOT `bunx tsc -b`: an unreferenced package is one `tsc -b` skips by definition, so it exits 0
|
|
@@ -350,8 +336,6 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
350
336
|
'export CHROME_PATH=/usr/bin/google-chrome # any Chrome, Chromium or Edge binary; or drop og.capture from the route; the gate build passes --no-capture and needs none',
|
|
351
337
|
X_IMAGE_SOURCE_UNREADABLE:
|
|
352
338
|
"x build --target static --json # lists the export; put the file under apps/web/site/assets/ and pass asset('assets/<file>') as src, or give an absolute https:// URL",
|
|
353
|
-
X_VERIFY_SKIPS_OVER_CEILING:
|
|
354
|
-
'x test unit --json # then set what the skipped tests need, or raise skipCeiling in x.verify.json with the reason in the diff',
|
|
355
339
|
X_ASSET_VARIANT_UNDECLARED:
|
|
356
340
|
"responsiveImage({ src: asset('assets/hero.png'), width, height, alt }) # no widths/formats override for a site asset; an upload under /media answers any width",
|
|
357
341
|
X_NEW_SHAPE_GENERATE_FAILED:
|
|
@@ -402,6 +386,13 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
402
386
|
'x verify --only drift --json # each X_DB_INDEX_UNDECLARED warning names the index: its DROP INDEX CONCURRENTLY IF EXISTS "<name>"; goes in a new hand-written migration (-- transaction: false), or declare it in the entity\'s indexes: [...] and x db gen "<change>"',
|
|
403
387
|
X_SHIPPED_GUARD_MISSING:
|
|
404
388
|
"x doctor --json # each X_SHIPPED_GUARD_MISSING warning's fix is the command that writes its guard, then x verify --only boundaries --json",
|
|
389
|
+
X_DEV_LOG_ABSENT:
|
|
390
|
+
'x dev --json # the dev server writes the dev log as it boots; then: x logs tail --json',
|
|
391
|
+
X_DEV_PEER_REFUSED:
|
|
392
|
+
'x doctor --json # /_x answers a loopback peer only: open it on the machine the dev server runs on, or forward the port with ssh -L',
|
|
393
|
+
X_PROFILE_ROUTE_FAILED: 'x routes --json',
|
|
394
|
+
X_ROWS_SLICE_ENTITY:
|
|
395
|
+
'x help g --json # then generate a job with the name and feature the finding names, and declare exportRows/importRows in it over the table that entity.ts declares',
|
|
405
396
|
};
|
|
406
397
|
|
|
407
398
|
const isCliCode = (code: string): code is CliErrorCode =>
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// `logs.tail`'s reader, split from `mcp-host.ts` at its size ceiling: which file a tail reads, the
|
|
2
|
+
// end-first bounded read, and a role's tail out of the one dev log `x dev` writes for every role.
|
|
3
|
+
// `x logs tail` (`cmd-logs.ts`) reads through the same path rule and reader.
|
|
4
|
+
|
|
5
|
+
// why: Bun exposes no path API; the dev log and a per-role log are joined under the state dir.
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { isRole, ROLES, stringField, UltimateError } from '@ultimat3/core';
|
|
8
|
+
import { DEV_LOG_FILENAME } from './dev-log';
|
|
9
|
+
import { BadFlagError } from './errors';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The log `logs.tail` reads. `role` is joined into a path, so it must BE a role: `'../x'` named a
|
|
13
|
+
* file outside the state directory. The tool's schema lists the roles, but a schema is advice to a
|
|
14
|
+
* client and this is the line that opens the file.
|
|
15
|
+
*/
|
|
16
|
+
export function logTailPath(dir: string, role: string | undefined): string {
|
|
17
|
+
if (role === undefined) return join(dir, DEV_LOG_FILENAME);
|
|
18
|
+
if (!isRole(role)) {
|
|
19
|
+
throw new BadFlagError({
|
|
20
|
+
flag: 'role',
|
|
21
|
+
command: 'mcp serve',
|
|
22
|
+
reason: `logs.tail's role "${role}" is not a runtime role`,
|
|
23
|
+
fix: `logs.tail({ role: 'web' }) # role is one of ${ROLES.join(', ')}; none reads dev.log`,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return join(dir, 'logs', `${role}.log`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The first window read from a log's end; each further one is four times wider. */
|
|
30
|
+
const TAIL_WINDOW_BYTES = 64 * 1024;
|
|
31
|
+
/** The most a tail ever reads: past this, lines that long are cut rather than the log loaded. */
|
|
32
|
+
const TAIL_MAX_BYTES = 1024 * 1024;
|
|
33
|
+
|
|
34
|
+
/** What `tailLines` reads of a file: its size and a byte range — `Bun.file`'s own shape. */
|
|
35
|
+
export interface TailSource {
|
|
36
|
+
readonly size: number;
|
|
37
|
+
slice(start: number, end: number): { text(): Promise<string> };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The last `lines` lines that `keep` accepts, read from the END in widening windows. `file.text()`
|
|
42
|
+
* loaded the whole `dev.log` per call, and an agent calls this in a loop against a log `x dev`
|
|
43
|
+
* never rotates. A window that does not start at byte 0 drops its first line: it may be partial,
|
|
44
|
+
* and may begin mid-character. A filtered tail answers what the last 1 MiB holds.
|
|
45
|
+
*/
|
|
46
|
+
export async function tailLines(
|
|
47
|
+
file: TailSource,
|
|
48
|
+
lines: number,
|
|
49
|
+
keep: (line: string) => boolean = () => true,
|
|
50
|
+
): Promise<readonly string[]> {
|
|
51
|
+
let window = TAIL_WINDOW_BYTES;
|
|
52
|
+
for (;;) {
|
|
53
|
+
const start = Math.max(0, file.size - Math.min(window, TAIL_MAX_BYTES));
|
|
54
|
+
const all = (await file.slice(start, file.size).text()).trimEnd().split('\n');
|
|
55
|
+
const whole = (start === 0 ? all : all.slice(1)).filter(keep);
|
|
56
|
+
if (whole.length >= lines || start === 0) return whole.slice(-lines);
|
|
57
|
+
// At the cap with no newline inside it, the one line there is longer than the cap: answered
|
|
58
|
+
// cut, never as `[]` — an empty tail reads as an empty log.
|
|
59
|
+
if (window >= TAIL_MAX_BYTES) {
|
|
60
|
+
return (whole.length === 0 ? all.filter(keep) : whole).slice(-lines);
|
|
61
|
+
}
|
|
62
|
+
window *= 4;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The runtime role a dev-log line names, when it names one. Core puts the context's `role` on
|
|
68
|
+
* every line written inside a request or a job (`context.ts`'s logger fields); a line written
|
|
69
|
+
* outside any context — the boot, a loop's own warning — names none and belongs to no role's tail.
|
|
70
|
+
*/
|
|
71
|
+
export function lineRole(line: string): string | undefined {
|
|
72
|
+
let parsed: unknown;
|
|
73
|
+
try {
|
|
74
|
+
parsed = JSON.parse(line);
|
|
75
|
+
} catch {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
// `stringField`, the total read: a parsed line is a stranger's object, never `in`-guarded then read.
|
|
79
|
+
const role = stringField(parsed, 'role');
|
|
80
|
+
return role !== undefined && isRole(role) ? role : undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** A log on disk: its size and byte ranges, or nothing. `Bun.file` unless a test hands one in. */
|
|
84
|
+
export type LogOpener = (path: string) => Promise<TailSource | undefined>;
|
|
85
|
+
|
|
86
|
+
export const openLog: LogOpener = async (path) => {
|
|
87
|
+
const file = Bun.file(path);
|
|
88
|
+
return (await file.exists()) ? file : undefined;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/** What a tail read: the file it came from, and its last lines. */
|
|
92
|
+
export interface LogTail {
|
|
93
|
+
readonly path: string;
|
|
94
|
+
readonly lines: readonly string[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* `logs.tail` and `x logs tail`, one answer: a role's own `logs/<role>.log` when one was written
|
|
99
|
+
* there (a role run with its output sent to it), else that role's lines of `dev.log` — `x dev` runs
|
|
100
|
+
* every role in one process and one log. With neither, `x dev` is the process that writes one.
|
|
101
|
+
*/
|
|
102
|
+
export async function readLogTail(
|
|
103
|
+
dir: string,
|
|
104
|
+
lines: number,
|
|
105
|
+
role: string | undefined,
|
|
106
|
+
open: LogOpener = openLog,
|
|
107
|
+
): Promise<LogTail> {
|
|
108
|
+
const ownPath = logTailPath(dir, role);
|
|
109
|
+
const own = await open(ownPath);
|
|
110
|
+
if (own !== undefined) return { path: ownPath, lines: await tailLines(own, lines) };
|
|
111
|
+
const devPath = join(dir, DEV_LOG_FILENAME);
|
|
112
|
+
const dev = role === undefined ? undefined : await open(devPath);
|
|
113
|
+
if (dev === undefined) {
|
|
114
|
+
throw new UltimateError({
|
|
115
|
+
code: 'X_DEV_LOG_ABSENT',
|
|
116
|
+
cause: `${devPath} does not exist yet: x dev writes it, every role's lines included${role === undefined ? '' : `, and no ${ownPath} was written either`}`,
|
|
117
|
+
fix: 'x dev',
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return { path: devPath, lines: await tailLines(dev, lines, (line) => lineRole(line) === role) };
|
|
121
|
+
}
|
package/src/mcp-host.ts
CHANGED
|
@@ -9,11 +9,7 @@
|
|
|
9
9
|
import { join } from 'node:path';
|
|
10
10
|
import {
|
|
11
11
|
agentActor,
|
|
12
|
-
isRole,
|
|
13
12
|
isUltimateError,
|
|
14
|
-
NotImplementedError,
|
|
15
|
-
ROLES,
|
|
16
|
-
renderFixShellArg,
|
|
17
13
|
renderThrowable,
|
|
18
14
|
retryMemo,
|
|
19
15
|
UltimateError,
|
|
@@ -46,11 +42,11 @@ import { loadAppGraph, resolveNode } from './cmd-graph-load';
|
|
|
46
42
|
import { declareDevEnvironment, needsDevEnvironmentDeclaration } from './dev-environment';
|
|
47
43
|
import { liveDevLock } from './dev-lock';
|
|
48
44
|
import { loadCodeFixes } from './error-fixes';
|
|
49
|
-
import { BadFlagError } from './errors';
|
|
50
45
|
import type { Runner } from './exec';
|
|
51
46
|
import { assertExplainTarget, devNotRunning, narrowVerify, searchDocs } from './mcp-agent-host';
|
|
52
47
|
import { databaseTarget } from './mcp-db-target';
|
|
53
48
|
import { explainErrorCode } from './mcp-errors';
|
|
49
|
+
import { readLogTail } from './mcp-host-logs';
|
|
54
50
|
import { type ShellRunInput, shellRunner, shellTests, shellVerify } from './mcp-host-shell';
|
|
55
51
|
import { requestStatements } from './mcp-request-statements';
|
|
56
52
|
import { type UiCapabilities, uiCapabilities } from './mcp-ui';
|
|
@@ -122,10 +118,13 @@ export function lazyServices(input: DevHostInput): LazyServices {
|
|
|
122
118
|
// A boot started after close() would hold the PGlite data directory for the life of the
|
|
123
119
|
// process with nobody left to stop it — the host is closed, so the call is the bug.
|
|
124
120
|
if (closed) {
|
|
125
|
-
|
|
121
|
+
// Core's code for work that arrives after shutdown: nothing is missing from this build.
|
|
122
|
+
throw new UltimateError({
|
|
123
|
+
code: 'X_DRAINING',
|
|
126
124
|
cause:
|
|
127
|
-
'an MCP tool
|
|
128
|
-
fix: 'x mcp serve --transport stdio #
|
|
125
|
+
'an MCP tool needed the database after this host closed, and a closed host is not reopened',
|
|
126
|
+
fix: 'x mcp serve --transport stdio # a new session: a closed host is replaced, never reused',
|
|
127
|
+
retry: 'terminal',
|
|
129
128
|
});
|
|
130
129
|
}
|
|
131
130
|
return boot.get();
|
|
@@ -212,54 +211,8 @@ export function migrateFailed(error: unknown): UltimateError {
|
|
|
212
211
|
});
|
|
213
212
|
}
|
|
214
213
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
* file outside the state directory. The tool's schema lists the roles, but a schema is advice to a
|
|
218
|
-
* client and this is the line that opens the file.
|
|
219
|
-
*/
|
|
220
|
-
export function logTailPath(dir: string, role: string | undefined): string {
|
|
221
|
-
if (role === undefined) return join(dir, 'dev.log');
|
|
222
|
-
if (!isRole(role)) {
|
|
223
|
-
throw new BadFlagError({
|
|
224
|
-
flag: 'role',
|
|
225
|
-
command: 'mcp serve',
|
|
226
|
-
reason: `logs.tail's role "${role}" is not a runtime role`,
|
|
227
|
-
fix: `logs.tail({ role: 'web' }) # role is one of ${ROLES.join(', ')}; none reads dev.log`,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
return join(dir, 'logs', `${role}.log`);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/** The first window read from a log's end; each further one is four times wider. */
|
|
234
|
-
const TAIL_WINDOW_BYTES = 64 * 1024;
|
|
235
|
-
/** The most a tail ever reads: past this, lines that long are cut rather than the log loaded. */
|
|
236
|
-
const TAIL_MAX_BYTES = 1024 * 1024;
|
|
237
|
-
|
|
238
|
-
/** What `tailLines` reads of a file: its size and a byte range — `Bun.file`'s own shape. */
|
|
239
|
-
export interface TailSource {
|
|
240
|
-
readonly size: number;
|
|
241
|
-
slice(start: number, end: number): { text(): Promise<string> };
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* The last `lines` lines, read from the END in widening windows. `file.text()` loaded the whole
|
|
246
|
-
* `dev.log` per call, and an agent calls this in a loop against a log `x dev` never rotates. A
|
|
247
|
-
* window that does not start at byte 0 drops its first line: it may be partial, and may begin
|
|
248
|
-
* mid-character.
|
|
249
|
-
*/
|
|
250
|
-
export async function tailLines(file: TailSource, lines: number): Promise<readonly string[]> {
|
|
251
|
-
let window = TAIL_WINDOW_BYTES;
|
|
252
|
-
for (;;) {
|
|
253
|
-
const start = Math.max(0, file.size - Math.min(window, TAIL_MAX_BYTES));
|
|
254
|
-
const all = (await file.slice(start, file.size).text()).trimEnd().split('\n');
|
|
255
|
-
const whole = start === 0 ? all : all.slice(1);
|
|
256
|
-
if (whole.length >= lines || start === 0) return whole.slice(-lines);
|
|
257
|
-
// At the cap with no newline inside it, the one line there is longer than the cap: answered
|
|
258
|
-
// cut, never as `[]` — an empty tail reads as an empty log.
|
|
259
|
-
if (window >= TAIL_MAX_BYTES) return (whole.length === 0 ? all : whole).slice(-lines);
|
|
260
|
-
window *= 4;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
214
|
+
// `logs.tail`'s reader lives in `mcp-host-logs.ts`; re-exported for `x logs tail` and the tests.
|
|
215
|
+
export { lineRole, logTailPath, type TailSource, tailLines } from './mcp-host-logs';
|
|
263
216
|
|
|
264
217
|
function capabilities(
|
|
265
218
|
input: DevHostInput,
|
|
@@ -343,23 +296,9 @@ function capabilities(
|
|
|
343
296
|
// `x test` itself, never a second test path: the files, batches and env the shell gets.
|
|
344
297
|
runTests: (filter: string | undefined) => shellTests(shell, filter),
|
|
345
298
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const file = Bun.file(path);
|
|
350
|
-
if (!(await file.exists())) {
|
|
351
|
-
// A log on disk is the only honest source: `x dev` tees every line of its own to
|
|
352
|
-
// `dev.log` (`dev-log.ts`), so starting it is the fix. No role writes a log of its own.
|
|
353
|
-
throw new NotImplementedError({
|
|
354
|
-
cause: `logs.tail without ${path} is not implemented in this build`,
|
|
355
|
-
fix:
|
|
356
|
-
role === undefined
|
|
357
|
-
? 'x dev'
|
|
358
|
-
: `mkdir -p ${renderFixShellArg(join(dir, 'logs'), '<the logs dir of the path the cause names>')} && x dev --role ${role} > ${path} 2>&1`,
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
return tailLines(file, lines);
|
|
362
|
-
},
|
|
299
|
+
// A role's own log when one was written, else its lines of the dev log (`mcp-host-logs.ts`).
|
|
300
|
+
tailLogs: async (lines: number, role: string | undefined) =>
|
|
301
|
+
(await readLogTail(lazy.services.stateDir, lines, role)).lines,
|
|
363
302
|
|
|
364
303
|
async readManifest() {
|
|
365
304
|
const file = Bun.file(join(root, MANIFEST_FILENAME));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// The suite floor's rows of the CLI catalog (`messages.ts` composes them): why a step ran no
|
|
2
|
+
// check, and the strict-floor notices. Data only — `msg()` is the one lookup.
|
|
3
|
+
|
|
4
|
+
export const FLOOR_MESSAGES = {
|
|
5
|
+
// One line per step that ran no check (`verify-skip-reason.ts`), under the step table.
|
|
6
|
+
'cli.verify.skip.line': 'skipped: {step} — {reason}',
|
|
7
|
+
'cli.verify.skip.noTypedFiles': 'no *.{type}.test.ts file in this tree',
|
|
8
|
+
'cli.verify.skip.noEval': 'not an app root, and no *.eval.test.ts file',
|
|
9
|
+
'cli.verify.skip.noApp': 'no {file} here, so there is no app to load',
|
|
10
|
+
'cli.verify.skip.noPackages': 'no workspace package under packages/',
|
|
11
|
+
'cli.verify.skip.noManifest': 'no {file} committed, so there is no contract to diff',
|
|
12
|
+
'cli.verify.skip.noRoadmap': 'no {file} here',
|
|
13
|
+
'cli.verify.skip.nothing': 'the step found nothing to check here',
|
|
14
|
+
// Without `strict`, a warning and never red: an existing app meets it on `main` (X_BREAKING_ON_MAIN).
|
|
15
|
+
'cli.verify.unwaived':
|
|
16
|
+
'not strict: {names} ran no check here — give each a suite, or a "skip" why in x.verify.json, then set "strict": true',
|
|
17
|
+
// A `skip` why over a step that ran: the reason is stale, and only a commit can drop it.
|
|
18
|
+
'cli.verify.waiverStale': 'x.verify.json "skip" excuses {step}, which ran here — drop its entry',
|
|
19
|
+
} as const;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// The `x status` rows of the CLI catalog (`messages.ts` composes them): what the running
|
|
2
|
+
// deployment records about its builds, and which roles record nothing. Data only.
|
|
3
|
+
|
|
4
|
+
export const STATUS_MESSAGES = {
|
|
5
|
+
'cli.status.summary': '{workers} live worker(s) read, {origins} origin(s) sampled',
|
|
6
|
+
'cli.status.workers': 'workers: {count} live · builds {builds}',
|
|
7
|
+
'cli.status.origin': '{origin}: {samples} sample(s) · builds {builds} · status {statuses}',
|
|
8
|
+
'cli.status.unrecorded':
|
|
9
|
+
'no fleet-wide record of {roles}: pass each one’s health origin to --url to read its build',
|
|
10
|
+
} as const;
|
package/src/messages.ts
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
import { CLIENT_MESSAGES } from './messages-client';
|
|
7
7
|
import { DB_MESSAGES } from './messages-db';
|
|
8
|
+
import { FLOOR_MESSAGES } from './messages-floor';
|
|
8
9
|
import { GATE_MESSAGES } from './messages-gate';
|
|
9
10
|
import { OPS_MESSAGES } from './messages-ops';
|
|
10
11
|
import { REPRO_MESSAGES } from './messages-repro';
|
|
11
12
|
import { SHOT_MESSAGES } from './messages-shot';
|
|
13
|
+
import { STATUS_MESSAGES } from './messages-status';
|
|
12
14
|
import { UPGRADE_MESSAGES } from './messages-upgrade';
|
|
13
15
|
|
|
14
16
|
const CATALOG = {
|
|
@@ -73,6 +75,12 @@ const CATALOG = {
|
|
|
73
75
|
'cli.dev.roles': ' roles {roles}',
|
|
74
76
|
'cli.dev.panels': ' panels {panels}',
|
|
75
77
|
'cli.dev.introspect': ' introspect {url}',
|
|
78
|
+
'cli.dev.introspectUnreachable':
|
|
79
|
+
' introspect none on {url} — /_x answers loopback only; x dev --host 0.0.0.0 keeps loopback bound beside it',
|
|
80
|
+
'cli.dev.tls':
|
|
81
|
+
' tls cert {path} — trust it once: curl --cacert {path}, or add it to the OS keychain',
|
|
82
|
+
'cli.profile.done': 'profiled {route}: {runs} run(s), {samples} sample(s), status {status}',
|
|
83
|
+
'cli.profile.frame': ' {percent}% {name} {at}',
|
|
76
84
|
'cli.dev.manifest': ' manifest {path}',
|
|
77
85
|
'cli.dev.mcp': ' mcp POST {path}',
|
|
78
86
|
// `x stop` (`cmd-stop.ts`): the lock's holder, and only it.
|
|
@@ -110,6 +118,10 @@ const CATALOG = {
|
|
|
110
118
|
// `x doctor`'s warnings: beside the verdict on `main`, red on `next` (`doctor-warnings.ts`).
|
|
111
119
|
'cli.doctor.warnings': '{count} warning(s) — not in the verdict until the next major:',
|
|
112
120
|
'cli.doctor.warning': ' {code}: {cause} — fix: {fix}',
|
|
121
|
+
// `x doctor`'s browser report (`doctor-browser.ts`): the e2e driver's Chrome, or how to get one.
|
|
122
|
+
'cli.doctor.browserFound': 'e2e browser: {path}',
|
|
123
|
+
'cli.doctor.browserMissing':
|
|
124
|
+
'e2e browser: none found, so every e2eTest skips — install one: {install}',
|
|
113
125
|
'cli.docs.code': '{code} is an error code — x errors explain answers it',
|
|
114
126
|
'cli.docs.exports': 'exports: {list}',
|
|
115
127
|
'cli.docs.installed': 'installed: {list}',
|
|
@@ -280,6 +292,13 @@ const CATALOG = {
|
|
|
280
292
|
'cli.secrets.dropped':
|
|
281
293
|
'dropped retired master key {kid} from {path} — {count} retired key(s) still declared',
|
|
282
294
|
'cli.secrets.ring': 'retired master key(s) that still open sealed values: {kids}',
|
|
295
|
+
// `verify-live.ts`: the `live` step's warnings about the test stack it found, started or could not.
|
|
296
|
+
'cli.verify.services.started':
|
|
297
|
+
'this run started {services} ({command}) — left running for the next run; stop it with {stop}',
|
|
298
|
+
'cli.verify.services.unavailable': '{code}: {cause} — fix: {fix}',
|
|
299
|
+
// `upgrade-report.ts`: a guard the tree breaks, kept at its measured count (`upgrade-guards.ts`).
|
|
300
|
+
'cli.upgrade.guardBaselined':
|
|
301
|
+
'guard installed at its baseline: guards/{name}.ts reports {count} finding(s), now "guardBaseline" in x.verify.json — fix them and lower it, it only falls',
|
|
283
302
|
...CLIENT_MESSAGES,
|
|
284
303
|
...REPRO_MESSAGES,
|
|
285
304
|
...DB_MESSAGES,
|
|
@@ -287,6 +306,8 @@ const CATALOG = {
|
|
|
287
306
|
...UPGRADE_MESSAGES,
|
|
288
307
|
...GATE_MESSAGES,
|
|
289
308
|
...OPS_MESSAGES,
|
|
309
|
+
...FLOOR_MESSAGES,
|
|
310
|
+
...STATUS_MESSAGES,
|
|
290
311
|
} as const;
|
|
291
312
|
|
|
292
313
|
export type MessageKey = keyof typeof CATALOG;
|
package/src/registry.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { explainSpec } from './cmd-explain-spec';
|
|
|
27
27
|
import { fixSpec } from './cmd-fix-spec';
|
|
28
28
|
import { generateSpec } from './cmd-generate-spec';
|
|
29
29
|
import { graphSpec } from './cmd-graph-spec';
|
|
30
|
+
import { profileSpec } from './cmd-profile-spec';
|
|
30
31
|
// Registered here, not by whichever command body happens to load: `dispatch` renders a CLI code's
|
|
31
32
|
// title for a refusal raised before any body is imported.
|
|
32
33
|
import './error-codes';
|
|
@@ -47,6 +48,7 @@ import { reproSpec } from './cmd-repro-spec';
|
|
|
47
48
|
import { routesSpec } from './cmd-routes-spec';
|
|
48
49
|
import { secretsSpec } from './cmd-secrets-spec';
|
|
49
50
|
import { shotSpec } from './cmd-shot-spec';
|
|
51
|
+
import { statusSpec } from './cmd-status-spec';
|
|
50
52
|
import { stopSpec } from './cmd-stop-spec';
|
|
51
53
|
import { tasksSpec } from './cmd-tasks-spec';
|
|
52
54
|
import { testSpec } from './cmd-test-spec';
|
|
@@ -135,6 +137,8 @@ export const LAZY_COMMANDS: readonly LazyCommand[] = [
|
|
|
135
137
|
lazy(logsSpec, async () => (await import('./cmd-logs')).logsCommand),
|
|
136
138
|
lazy(cacheSpec, async () => (await import('./cmd-cache')).cacheCommand),
|
|
137
139
|
lazy(explainSpec, async () => (await import('./cmd-explain')).explainCommand),
|
|
140
|
+
lazy(profileSpec, async () => (await import('./cmd-profile')).profileCommand),
|
|
141
|
+
lazy(statusSpec, async () => (await import('./cmd-status')).statusCommand),
|
|
138
142
|
];
|
|
139
143
|
|
|
140
144
|
/**
|
package/src/role-start-types.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { Env } from './runtime-bindings';
|
|
|
11
11
|
import type { LiveFeed } from './runtime-live-feed';
|
|
12
12
|
import type { RuntimeOverrides } from './runtime-overrides';
|
|
13
13
|
import type { RunningServices } from './runtime-services';
|
|
14
|
+
import type { ListenerTls } from './serve-env-tls';
|
|
14
15
|
import type { WebBinding } from './web-binding';
|
|
15
16
|
|
|
16
17
|
/** The roles `x dev` starts when `--role` names none, in boot order. */
|
|
@@ -33,6 +34,12 @@ export interface StartRolesOptions {
|
|
|
33
34
|
* probe, which is the same failure in four costumes.
|
|
34
35
|
*/
|
|
35
36
|
readonly http?: WebBinding;
|
|
37
|
+
/**
|
|
38
|
+
* The web role's certificate and key, PEM: its listener serves TLS. Absent is plaintext, the
|
|
39
|
+
* default — `x dev --tls` and `TLS_CERT`/`TLS_KEY` are the two callers. Never the `sync` node or
|
|
40
|
+
* the metrics endpoint: the sync socket is served on the web port too (`role-sync`).
|
|
41
|
+
*/
|
|
42
|
+
readonly tls?: ListenerTls;
|
|
36
43
|
/**
|
|
37
44
|
* The app's `auth.signInPath`. Threaded rather than read from the config here because
|
|
38
45
|
* `startRoles` takes plain values — a test starts a web role with no `app.config.ts` at all.
|
package/src/role-start.ts
CHANGED
|
@@ -207,6 +207,7 @@ function startWeb(
|
|
|
207
207
|
dev: binding.dev,
|
|
208
208
|
buildId: options.buildId,
|
|
209
209
|
hostname: binding.hostname,
|
|
210
|
+
...(options.tls === undefined ? {} : { tls: options.tls }),
|
|
210
211
|
signInPath: options.signInPath ?? null,
|
|
211
212
|
// One declaration, never half of one: `defineHttpConfig` refuses `trustProxy` without hops.
|
|
212
213
|
...(hops === null ? {} : { trustProxy: true, trustedProxyHops: hops }),
|
|
@@ -223,6 +224,9 @@ function startWeb(
|
|
|
223
224
|
// document that carries an island, so `script-src 'self'` meant no island booted anywhere
|
|
224
225
|
// the policy is enforced — every container, and never `x dev`, where it is report-only.
|
|
225
226
|
security: {
|
|
227
|
+
// A dev listener on TLS sends no HSTS: browsers pin it per HOST, so a two-year policy
|
|
228
|
+
// from `https://localhost:3000` would force every other localhost port onto https.
|
|
229
|
+
...(binding.dev && options.tls !== undefined ? { hsts: null } : {}),
|
|
226
230
|
csp: {
|
|
227
231
|
extend: {
|
|
228
232
|
'style-src': inlineStyleSources(options.inlineStyles ?? []),
|
package/src/serve-boot.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { bootTimeline } from './serve-boot-phases';
|
|
|
27
27
|
import { bootWarningConcerns, warnAtBoot } from './serve-boot-warnings';
|
|
28
28
|
import { loadDrainConfig, loadHealthConfig } from './serve-drain';
|
|
29
29
|
import { configureReporting, containerBinding, metricsPortFor, portFromEnv } from './serve-env';
|
|
30
|
+
import { type ListenerTls, tlsFromEnv } from './serve-env-tls';
|
|
30
31
|
import { adoptPrebuiltStyles, reportBootBuilds, watchBootBuilds } from './serve-prebuilt';
|
|
31
32
|
import type { ServedApp, ServeOptions } from './serve-types';
|
|
32
33
|
|
|
@@ -92,6 +93,8 @@ export async function bootServing(boot: {
|
|
|
92
93
|
readonly metrics: MetricsEndpoint;
|
|
93
94
|
}): Promise<ServedApp> {
|
|
94
95
|
const { options } = boot;
|
|
96
|
+
// Before any service starts: a half-declared pair is refused while there is nothing to unwind.
|
|
97
|
+
const tls = boot.role === 'web' ? await tlsFromEnv(options.env) : undefined;
|
|
95
98
|
// One `boot.phase` line as each step ends, so a slow boot names its slow step (U12).
|
|
96
99
|
const timeline = bootTimeline(boot.role, options.runtime?.clock);
|
|
97
100
|
const services = resolveServices(options.root, options.env);
|
|
@@ -103,7 +106,7 @@ export async function bootServing(boot: {
|
|
|
103
106
|
const runtime = await startServices(services, options.env, options.runtime, schema, [boot.role]);
|
|
104
107
|
boot.acquired.push(() => runtime.stop());
|
|
105
108
|
timeline.phase('services');
|
|
106
|
-
return bootRoles({ ...boot, runtime, timeline });
|
|
109
|
+
return bootRoles({ ...boot, runtime, timeline, ...(tls === undefined ? {} : { tls }) });
|
|
107
110
|
}
|
|
108
111
|
|
|
109
112
|
/**
|
|
@@ -138,6 +141,8 @@ async function bootRoles(boot: {
|
|
|
138
141
|
/** The scrape listener `serveApp` opened before any of this work; `startRoles` adopts it. */
|
|
139
142
|
readonly metrics: MetricsEndpoint;
|
|
140
143
|
readonly timeline: BootTimeline;
|
|
144
|
+
/** `TLS_CERT`/`TLS_KEY`, read by `bootServing`; the web role's listener serves TLS with it. */
|
|
145
|
+
readonly tls?: ListenerTls;
|
|
141
146
|
}): Promise<ServedApp> {
|
|
142
147
|
const { options, role, runtime, acquired, metrics, timeline } = boot;
|
|
143
148
|
// Before the app's modules, because importing one may register a `close` hook, and that phase
|
|
@@ -239,6 +244,7 @@ async function bootRoles(boot: {
|
|
|
239
244
|
// process and `x dev` cannot answer a browser differently.
|
|
240
245
|
root: options.root,
|
|
241
246
|
http: containerBinding(options.env, options.hostname),
|
|
247
|
+
...(boot.tls === undefined ? {} : { tls: boot.tls }),
|
|
242
248
|
// `app.config.ts`'s drain section: the readiness grace the chart's grace period is sized for.
|
|
243
249
|
...(drain === undefined ? {} : { drain }),
|
|
244
250
|
// The read-replica scope rides in FRONT of whatever the host supplied, or the host's own value
|