@ultimat3/cli 31.47.1 → 31.49.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 +30 -23
- package/README.md +96 -4
- package/package.json +29 -29
- package/src/api-registration.ts +28 -14
- package/src/app-load.ts +6 -1
- package/src/app-root.ts +7 -1
- package/src/clean-services.ts +142 -0
- package/src/cmd-auth.ts +3 -0
- package/src/cmd-clean-spec.ts +10 -3
- package/src/cmd-clean.ts +23 -9
- package/src/cmd-db-backfill.ts +6 -0
- package/src/cmd-db-branch.ts +10 -4
- package/src/cmd-db-recount.ts +5 -12
- package/src/cmd-db-rollback.ts +77 -0
- package/src/cmd-db-spec.ts +18 -2
- package/src/cmd-db-status.ts +5 -10
- package/src/cmd-db.ts +105 -33
- package/src/cmd-deploy-verify.ts +14 -6
- package/src/cmd-docs-topic.ts +94 -0
- package/src/cmd-docs.ts +15 -1
- package/src/cmd-doctor.ts +109 -41
- package/src/cmd-drill.ts +100 -19
- package/src/cmd-env.ts +30 -8
- package/src/cmd-errors-app.ts +63 -0
- package/src/cmd-errors.ts +50 -14
- package/src/cmd-generate.ts +17 -4
- package/src/cmd-heavy-spec.ts +36 -0
- package/src/cmd-heavy.ts +244 -0
- package/src/cmd-jobs.ts +27 -1
- package/src/cmd-merge-driver-spec.ts +12 -0
- package/src/cmd-merge-driver.ts +95 -0
- package/src/cmd-new.ts +23 -3
- package/src/cmd-policy-spec.ts +9 -1
- package/src/cmd-policy.ts +72 -17
- package/src/cmd-stop.ts +18 -4
- package/src/cmd-tasks-run.ts +87 -0
- package/src/cmd-tasks-spec.ts +10 -3
- package/src/cmd-tasks.ts +8 -5
- package/src/cmd-test.ts +15 -4
- package/src/cmd-upgrade-spec.ts +8 -1
- package/src/cmd-upgrade.ts +32 -5
- package/src/cmd-verify.ts +9 -41
- package/src/codemods/agents-doc-row.ts +73 -0
- package/src/codemods/define-error-leaf.ts +37 -12
- package/src/codemods/docs-many-agents.ts +26 -0
- package/src/codemods/docs-worker-commands.ts +26 -0
- package/src/codemods/index.ts +6 -0
- package/src/codemods/merge-drivers.ts +66 -0
- package/src/command.ts +3 -0
- package/src/db-applied-edits.ts +117 -0
- package/src/db-dev-wire.ts +18 -0
- package/src/db-diagnostics.ts +5 -10
- package/src/db-generate.ts +82 -7
- package/src/db-migrate-pass.ts +51 -0
- package/src/db-migrate-through-dev.ts +209 -0
- package/src/db-rollback-consent.ts +128 -0
- package/src/db-rollback-pass.ts +76 -0
- package/src/db-seed-generate.ts +5 -1
- package/src/db-seed.ts +7 -1
- package/src/deploy-verify-findings.ts +3 -0
- package/src/deploy-verify-grade.ts +3 -0
- package/src/deploy-verify-processes.ts +32 -0
- package/src/dev-boot.ts +3 -0
- package/src/dev-db-migrate.ts +155 -0
- package/src/dev-db-rollback.ts +33 -0
- package/src/dev-db-settled.ts +22 -0
- package/src/dev-lock-errors.ts +78 -0
- package/src/dev-lock-holder-dir.ts +64 -0
- package/src/dev-lock-live.ts +44 -0
- package/src/dev-lock.ts +59 -84
- package/src/dev-policy.ts +11 -8
- package/src/dev-rebuild-schema.ts +116 -13
- package/src/dev-rebuild.ts +13 -4
- package/src/dev-route-table.ts +7 -0
- package/src/dispatch.ts +21 -1
- package/src/doctor-advisory-floors.ts +30 -8
- package/src/doctor-api-listing.ts +114 -0
- package/src/doctor-guarded.ts +41 -0
- package/src/doctor-port.ts +90 -17
- package/src/doctor-probe.ts +36 -5
- package/src/doctor-processes-probe.ts +127 -0
- package/src/doctor-processes.ts +136 -0
- package/src/doctor-warnings.ts +17 -0
- package/src/error-codes-agents.ts +35 -0
- package/src/error-codes-processes.ts +30 -0
- package/src/error-codes-tooling.ts +11 -3
- package/src/error-codes.ts +12 -13
- package/src/errors-suite.ts +27 -0
- package/src/errors.ts +18 -22
- package/src/exec.ts +11 -3
- package/src/exercise-registration.ts +4 -3
- package/src/framework-env.ts +7 -3
- package/src/generate-files.ts +1 -0
- package/src/generate-grant-findings.ts +7 -5
- package/src/generate-grants.ts +9 -8
- package/src/generate-kinds.ts +30 -6
- package/src/generate-roles-file.ts +30 -0
- package/src/generate-slice-policy.ts +3 -3
- package/src/guards.ts +2 -2
- package/src/heavy-cores.ts +51 -0
- package/src/heavy-env.ts +21 -0
- package/src/heavy-errors.ts +54 -0
- package/src/heavy-flock.ts +73 -0
- package/src/heavy-holders.ts +78 -0
- package/src/heavy-ledger.ts +400 -0
- package/src/heavy-memory.ts +67 -0
- package/src/heavy-pressure.ts +104 -0
- package/src/heavy-weights.ts +47 -0
- package/src/heavy.ts +308 -0
- package/src/i18n-registration.ts +22 -2
- package/src/island-harness.ts +2 -2
- package/src/job-budget.ts +4 -2
- package/src/job-registration.ts +64 -8
- package/src/jobs-queue-known.ts +43 -0
- package/src/local-cli.ts +6 -5
- package/src/mcp-errors-agents.ts +20 -0
- package/src/mcp-errors-doctor.ts +27 -0
- package/src/mcp-errors-processes.ts +23 -0
- package/src/mcp-errors.ts +18 -29
- package/src/mcp-host.ts +2 -2
- package/src/merge-driver-catalog.ts +58 -0
- package/src/merge-driver-config.ts +43 -0
- package/src/merge-driver-lines.ts +140 -0
- package/src/merge-state.ts +105 -0
- package/src/messages-db.ts +22 -1
- package/src/messages-processes.ts +13 -0
- package/src/messages-upgrade.ts +6 -0
- package/src/messages.ts +62 -1
- package/src/output-findings.ts +48 -21
- package/src/parse.ts +37 -6
- package/src/policy-facts.ts +38 -21
- package/src/policy-row.ts +99 -0
- package/src/port-pair-free.ts +28 -0
- package/src/registry-lines.ts +110 -0
- package/src/registry.ts +4 -0
- package/src/retain-sweep.ts +1 -1
- package/src/role-replicator.ts +9 -4
- package/src/role-select.ts +86 -0
- package/src/role-start.ts +13 -55
- package/src/role-sync.ts +10 -5
- package/src/runtime-cache-frame.ts +46 -0
- package/src/runtime-cache-ttl.ts +23 -0
- package/src/runtime-cache.ts +56 -18
- package/src/runtime-database-ssl.ts +84 -0
- package/src/runtime-idempotency-scope.ts +16 -2
- package/src/runtime-jobs-share.ts +52 -0
- package/src/runtime-jobs.ts +43 -12
- package/src/runtime-overrides.ts +4 -2
- package/src/runtime-queue.ts +18 -3
- package/src/runtime-services.ts +8 -1
- package/src/schema-drift.ts +19 -2
- package/src/schema-dump-drift.ts +4 -1
- package/src/serve-boot-probe.ts +30 -2
- package/src/serve-boot.ts +11 -1
- package/src/serve-env.ts +39 -3
- package/src/serve.ts +61 -10
- package/src/stop-run-start.ts +12 -0
- package/src/supervise-boot.ts +61 -0
- package/src/supervise-cgroup.ts +84 -0
- package/src/supervise-child.ts +206 -0
- package/src/supervise-count.ts +244 -0
- package/src/supervise-errors.ts +83 -0
- package/src/supervise-facts.ts +40 -0
- package/src/supervise-messages.ts +84 -0
- package/src/supervise-policy.ts +46 -0
- package/src/supervise-pool.ts +10 -0
- package/src/supervise-probe.ts +158 -0
- package/src/supervise-run.ts +54 -0
- package/src/supervise.ts +383 -0
- package/src/templates/generate-purge.ts +6 -6
- package/src/templates/guard-animated-layout-property.ts +2 -2
- package/src/templates/guard-bare-error.ts +1 -1
- package/src/templates/guard-error-declared.ts +2 -2
- package/src/templates/guard-focus-visible.ts +1 -1
- package/src/templates/guard-image-dimensions.ts +2 -2
- package/src/templates/guard-island-mount-clears.ts +1 -1
- package/src/templates/guard-native-confirm.ts +1 -1
- package/src/templates/guard-raw-breakpoint.ts +2 -2
- package/src/templates/guard-raw-colour.ts +2 -2
- package/src/templates/guard-raw-fetch.ts +1 -1
- package/src/templates/guard-raw-interval.ts +1 -1
- package/src/templates/guard-raw-length.ts +3 -3
- package/src/templates/guard-raw-motion.ts +1 -1
- package/src/templates/guard-raw-shadow.ts +1 -1
- package/src/templates/guard-raw-z-index.ts +1 -1
- package/src/templates/guard-released-forms.ts +59 -13
- package/src/templates/guard-repo-await-in-loop.ts +1 -1
- package/src/templates/guard-repo-raw-sql.ts +4 -4
- package/src/templates/guard-repo-unbounded.ts +1 -1
- package/src/templates/guard-runtime-pin.ts +1 -1
- package/src/templates/guard-semantic-interactive.ts +2 -2
- package/src/templates/guard-unbounded-fanout.ts +1 -1
- package/src/templates/guard-undeclared-custom-property.ts +3 -3
- package/src/templates/guard-undefined-style-class.ts +3 -3
- package/src/templates/guard-unzoned-date.ts +3 -3
- package/src/templates/query-slice.ts +82 -0
- package/src/templates/query.ts +76 -30
- package/src/templates/resource-page.ts +3 -2
- package/src/templates/scaffold-bin.ts +2 -0
- package/src/templates/scaffold-claude-agents.ts +9 -6
- package/src/templates/scaffold-claude-commands.ts +7 -1
- package/src/templates/scaffold-claude.ts +4 -4
- package/src/templates/scaffold-container-compose.ts +47 -7
- package/src/templates/scaffold-docs.ts +11 -6
- package/src/templates/scaffold-gitattributes.ts +18 -1
- package/src/templates/scaffold-helm-templates.ts +9 -0
- package/src/templates/scaffold-repo.ts +4 -1
- package/src/templates/scaffold-test-services.ts +33 -11
- package/src/templates/shapes/offline.ts +0 -7
- package/src/templates/shapes/realtime.ts +2 -6
- package/src/templates/sign-in-action-tests.ts +6 -4
- package/src/templates/sign-in-challenge.ts +62 -0
- package/src/templates/sign-in-oidc-mfa.ts +31 -0
- package/src/templates/sign-in-oidc.ts +11 -3
- package/src/templates/sign-in-password.ts +18 -56
- package/src/test-batches.ts +9 -3
- package/src/test-shards.ts +117 -37
- package/src/test-slots.ts +35 -161
- package/src/test-verdict.ts +79 -0
- package/src/test-workers.ts +15 -0
- package/src/upgrade-gate-codemods.ts +5 -3
- package/src/upgrade-gate.ts +19 -1
- package/src/upgrade-merge-drivers.ts +25 -0
- package/src/upgrade-report.ts +18 -4
- package/src/upgrade-scope.ts +62 -0
- package/src/verify-checks.ts +6 -11
- package/src/verify-coverage-run.ts +9 -5
- package/src/verify-deadline.ts +18 -2
- package/src/verify-heavy-steps.ts +26 -0
- package/src/verify-live.ts +38 -14
- package/src/verify-only.ts +67 -0
- package/src/verify-progress.ts +7 -3
- package/src/verify-run.ts +20 -2
- package/src/verify-services-stack.ts +165 -0
- package/src/verify-services.ts +84 -2
- package/src/verify-test-run.ts +9 -9
- package/src/verify-tests.ts +35 -22
- package/src/verify-typecheck.ts +25 -2
- package/wiki/Actions.md +2 -1
- package/wiki/Admin-Dashboard.md +2 -2
- package/wiki/Agents.md +5 -5
- package/wiki/Auth.md +15 -5
- package/wiki/Bare-VM.md +1 -1
- package/wiki/Building-Your-Own-Base.md +15 -2
- package/wiki/CI-Parallel-Gate.md +4 -4
- package/wiki/CLI-Reference.md +127 -48
- package/wiki/Caching-And-Invalidation.md +2 -2
- package/wiki/Client-Navigation.md +1 -1
- package/wiki/Configuration.md +32 -13
- package/wiki/Deployment.md +44 -4
- package/wiki/Entities-And-Migrations.md +5 -1
- package/wiki/FAQ.md +1 -1
- package/wiki/Getting-Started.md +2 -2
- package/wiki/Home.md +2 -1
- package/wiki/I18n.md +5 -3
- package/wiki/Installation.md +12 -11
- package/wiki/Interface-Rules.md +1 -1
- package/wiki/Jobs-And-Workflows.md +24 -4
- package/wiki/Known-Gaps.md +2 -2
- package/wiki/MCP-And-AI.md +8 -5
- package/wiki/Mail.md +1 -1
- package/wiki/Many-Agents.md +127 -0
- package/wiki/Migrations-And-Backfills.md +18 -0
- package/wiki/Notify.md +1 -1
- package/wiki/Observability.md +13 -0
- package/wiki/Queries-And-Live-Queries.md +2 -2
- package/wiki/Realtime.md +10 -1
- package/wiki/Routes-And-Render-Modes.md +1 -1
- package/wiki/Scheduled-Tasks.md +4 -1
- package/wiki/Testing.md +12 -9
- package/wiki/Timezones-And-Dates.md +5 -1
- package/wiki/Troubleshooting.md +1 -0
- package/wiki/Tutorial-01-First-App.md +5 -5
- package/wiki/Tutorial-02-First-Feature.md +1 -1
- package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
- package/wiki/Upgrading.md +37 -0
package/src/doctor-port.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
// `x doctor`'s port checks: both ports `x dev` binds, probed by role, and the one reading of which
|
|
2
2
|
// port that is (`--port`, then `PORT`, then 3000).
|
|
3
3
|
|
|
4
|
+
// why: Bun ships no realpath primitive.
|
|
5
|
+
import { realpathSync } from 'node:fs';
|
|
6
|
+
// why: Bun ships no path-separator primitive.
|
|
7
|
+
import { sep } from 'node:path';
|
|
4
8
|
import { ERROR_DOCS_URL } from '@ultimat3/core';
|
|
9
|
+
import type { PortOwner } from './dev-lock-holder-dir';
|
|
10
|
+
import { ownerText, portOwner } from './dev-lock-holder-dir';
|
|
5
11
|
import type { DoctorProbe } from './doctor-probe';
|
|
6
|
-
import { PORT_RANGE,
|
|
12
|
+
import { PORT_RANGE, readIntFlag } from './flag-number';
|
|
7
13
|
import type { Finding } from './output';
|
|
8
14
|
import { findingFrom } from './output';
|
|
9
15
|
import type { ParsedArgs } from './parse';
|
|
16
|
+
import { freeDevPortPair } from './port-pair-free';
|
|
17
|
+
import { portFree } from './port-probe';
|
|
10
18
|
import { syncPortFor } from './role-sync';
|
|
11
19
|
import { portFromEnv } from './serve-env';
|
|
12
20
|
import { quoteArg } from './shell-quote';
|
|
@@ -18,6 +26,53 @@ const finding = (code: string, cause: string, fix: string): Finding => ({
|
|
|
18
26
|
docs: ERROR_DOCS_URL,
|
|
19
27
|
});
|
|
20
28
|
|
|
29
|
+
export type PortProbe = Pick<DoctorProbe, 'port' | 'portFree' | 'root'> & {
|
|
30
|
+
/** Who holds a port. Absent: the OS is asked, unless `portFree` is a test's stand-in. */
|
|
31
|
+
readonly portOwner?: (port: number) => Promise<PortOwner>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const real = (path: string): string => {
|
|
35
|
+
try {
|
|
36
|
+
return realpathSync(path);
|
|
37
|
+
} catch {
|
|
38
|
+
return path;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Only a directory the OS named and that lies outside this app: unknown is never "not yours". */
|
|
43
|
+
function inAnotherCheckout(owner: PortOwner, root: string | undefined): boolean {
|
|
44
|
+
if (owner.cwd === undefined || root === undefined) return false;
|
|
45
|
+
const [dir, app] = [real(owner.cwd), real(root)];
|
|
46
|
+
return dir !== app && !dir.startsWith(`${app}${sep}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A stand-in `portFree` describes an imagined machine; the real one has no say about it. */
|
|
50
|
+
const ownerLookup = (probe: PortProbe): ((port: number) => Promise<PortOwner>) =>
|
|
51
|
+
probe.portOwner ?? (probe.portFree === portFree ? (port) => portOwner(port) : async () => ({}));
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The probe's owner lookup, asked at most once per port for this run. The verdict and the warnings
|
|
55
|
+
* each read the report, and each asked the OS: on a loaded CI runner the first `ss` named nobody (a
|
|
56
|
+
* finding) and the second another checkout (a warning) — one taken port, reported twice. Pinned,
|
|
57
|
+
* the two halves partition one answer. Per run, never per process: a port's holder changes.
|
|
58
|
+
*/
|
|
59
|
+
export function ownerAskedOnce(probe: PortProbe): (port: number) => Promise<PortOwner> {
|
|
60
|
+
const lookup = ownerLookup(probe);
|
|
61
|
+
const asked = new Map<number, Promise<PortOwner>>();
|
|
62
|
+
return (port) => {
|
|
63
|
+
const known = asked.get(port);
|
|
64
|
+
if (known !== undefined) return known;
|
|
65
|
+
const owner = lookup(port);
|
|
66
|
+
asked.set(port, owner);
|
|
67
|
+
return owner;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface PortReport {
|
|
72
|
+
readonly findings: readonly Finding[];
|
|
73
|
+
readonly warnings: readonly Finding[];
|
|
74
|
+
}
|
|
75
|
+
|
|
21
76
|
/**
|
|
22
77
|
* Both ports `x dev` binds, each labelled with the role that wants it. `x dev --port 3999` printed
|
|
23
78
|
* `web listening on 3999`, then died on 4000 as `X_CLI_UNEXPECTED` with a caught `Error` rendered
|
|
@@ -29,8 +84,11 @@ const finding = (code: string, cause: string, fix: string): Finding => ({
|
|
|
29
84
|
* The suggested port moves BOTH: `x dev --port N` occupies N and N+1, so a free N beside a taken
|
|
30
85
|
* N+1 is still not a runnable command. It did not move both until 2026-09 — the line was
|
|
31
86
|
* `neighbouringPort(probe.port)`, which for the sync finding IS the port the finding is about, and
|
|
32
|
-
* a docblock claiming otherwise is how it survived. `
|
|
33
|
-
*
|
|
87
|
+
* a docblock claiming otherwise is how it survived. `freeDevPortPair` also asks that the pair is free:
|
|
88
|
+
* beside two dev servers the next pair was often the second one's.
|
|
89
|
+
*
|
|
90
|
+
* A port held from ANOTHER checkout is a warning: a neighbour's dev server says nothing about this
|
|
91
|
+
* environment, and it turned `x doctor` red in every other app on the machine.
|
|
34
92
|
*
|
|
35
93
|
* The sync port is `syncPortFor`, never `neighbouringPort` again: that helper answers 65534 for a
|
|
36
94
|
* web port of 65535 — BELOW the web port, and a port `x dev` never binds — where the boot refuses
|
|
@@ -39,35 +97,50 @@ const finding = (code: string, cause: string, fix: string): Finding => ({
|
|
|
39
97
|
* reported instead of a probe. Alone, and ahead of the web port: there is no runnable `x dev` at
|
|
40
98
|
* this port whatever the other one answers, and a second finding about it is noise over the cause.
|
|
41
99
|
*/
|
|
42
|
-
|
|
43
|
-
probe: Pick<DoctorProbe, 'port' | 'portFree'>,
|
|
44
|
-
): Promise<readonly Finding[]> {
|
|
100
|
+
async function portReport(probe: PortProbe): Promise<PortReport> {
|
|
45
101
|
let syncPort: number;
|
|
46
102
|
try {
|
|
47
103
|
syncPort = syncPortFor(probe.port);
|
|
48
104
|
} catch (error) {
|
|
49
105
|
// The boot's own error, carried whole — `findingFrom` reads its code, cause and fix off the
|
|
50
106
|
// value rather than rendering it, which is what `scripts/catch-render.ts` requires.
|
|
51
|
-
return [findingFrom(error)];
|
|
107
|
+
return { findings: [findingFrom(error)], warnings: [] };
|
|
52
108
|
}
|
|
53
109
|
const wanted = [
|
|
54
110
|
{ port: probe.port, role: 'web' },
|
|
55
111
|
{ port: syncPort, role: 'sync' },
|
|
56
112
|
] as const;
|
|
113
|
+
const taken = [];
|
|
114
|
+
for (const entry of wanted) if (!(await probe.portFree(entry.port))) taken.push(entry);
|
|
115
|
+
if (taken.length === 0) return { findings: [], warnings: [] };
|
|
116
|
+
const fix = `x dev --port ${quoteArg(String(await freeDevPortPair(probe.port, probe.portFree)))}`;
|
|
117
|
+
const lookup = ownerLookup(probe);
|
|
57
118
|
const findings: Finding[] = [];
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
)
|
|
66
|
-
|
|
119
|
+
const warnings: Finding[] = [];
|
|
120
|
+
for (const entry of taken) {
|
|
121
|
+
const owner = await lookup(entry.port);
|
|
122
|
+
const named = ownerText(owner);
|
|
123
|
+
const need = `\`x dev --port ${probe.port}\` binds it for the ${entry.role} role`;
|
|
124
|
+
if (inAnotherCheckout(owner, probe.root)) {
|
|
125
|
+
const cause = `port ${entry.port} is held by ${named ?? 'another process'}, another checkout, and ${need} — nothing is wrong with this environment`;
|
|
126
|
+
warnings.push(finding('X_PORT_IN_USE', cause, fix));
|
|
127
|
+
} else {
|
|
128
|
+
const held = named === undefined ? '' : ` (${named})`;
|
|
129
|
+
const cause = `port ${entry.port} is already listening${held}, and ${need}`;
|
|
130
|
+
findings.push(finding('X_PORT_IN_USE', cause, fix));
|
|
131
|
+
}
|
|
67
132
|
}
|
|
68
|
-
return findings;
|
|
133
|
+
return { findings, warnings };
|
|
69
134
|
}
|
|
70
135
|
|
|
136
|
+
/** The taken ports that are this environment's problem: `x doctor`'s verdict. */
|
|
137
|
+
export const portFindings = async (probe: PortProbe): Promise<readonly Finding[]> =>
|
|
138
|
+
(await portReport(probe)).findings;
|
|
139
|
+
|
|
140
|
+
/** The taken ports another checkout holds: reported beside the verdict. */
|
|
141
|
+
export const portWarnings = async (probe: PortProbe): Promise<readonly Finding[]> =>
|
|
142
|
+
(await portReport(probe)).warnings;
|
|
143
|
+
|
|
71
144
|
/**
|
|
72
145
|
* The port to TEST, and the one place `x doctor` reads it: `devPortFor`'s order — `--port`, then
|
|
73
146
|
* `PORT` (`portFromEnv`, the one reader of it), then 3000 — so the probe answers about the port
|
package/src/doctor-probe.ts
CHANGED
|
@@ -9,6 +9,9 @@ import { loadApp } from './app-load';
|
|
|
9
9
|
import { IMPORT_UNRESOLVED } from './app-load-unresolved';
|
|
10
10
|
import { findAppRoot } from './app-root';
|
|
11
11
|
import { checkMigrationSnapshots } from './db-snapshot';
|
|
12
|
+
import type { PortOwner } from './dev-lock-holder-dir';
|
|
13
|
+
import { portOwner } from './dev-lock-holder-dir';
|
|
14
|
+
import { unlistedPrimitiveFindings } from './doctor-api-listing';
|
|
12
15
|
import { type AuthStorageFact, authStorageProbe } from './doctor-auth';
|
|
13
16
|
import type { EmbeddedDatabase } from './doctor-database';
|
|
14
17
|
import { externalUrl, installedAbove, probeDatabase } from './doctor-database';
|
|
@@ -26,9 +29,13 @@ import { rowSecurityOffProbe, rowSecurityProbe } from './doctor-row-security';
|
|
|
26
29
|
import type { SealedKeysFact } from './doctor-sealed';
|
|
27
30
|
import { sealedKeysProbe } from './doctor-sealed';
|
|
28
31
|
import { typescriptProbe } from './doctor-typescript';
|
|
32
|
+
import { exec } from './exec';
|
|
29
33
|
import { machineSecretFindings } from './framework-env';
|
|
34
|
+
import { driverUnset } from './merge-driver-config';
|
|
35
|
+
import { catalogFileFindings, unmergedFindings } from './merge-state';
|
|
30
36
|
import type { Finding } from './output';
|
|
31
37
|
import { portFree } from './port-probe';
|
|
38
|
+
import { withAppTls } from './runtime-database-ssl';
|
|
32
39
|
import { checkMigrationDrift } from './schema-drift';
|
|
33
40
|
import type { TypescriptLag } from './typescript-floor';
|
|
34
41
|
import type { VerifyStepName } from './verify-step';
|
|
@@ -49,12 +56,19 @@ export interface DoctorProbe {
|
|
|
49
56
|
/**
|
|
50
57
|
* The framework's own secrets this machine lacks — `framework-env.ts`'s
|
|
51
58
|
* `machineSecretFindings`, gated by `namedDeployed`: only an environment NAMED staging or
|
|
52
|
-
* production (an unnamed developer shell owes nothing; `x env check` is the fail-closed answer
|
|
59
|
+
* production (an unnamed developer shell owes nothing; `x env check` is the fail-closed answer
|
|
60
|
+
* under `CI` only — elsewhere it checks an unnamed shell as development, as `x dev` runs).
|
|
53
61
|
* The list's own `needed`/`unsafe` decide; doctor reports.
|
|
54
62
|
*/
|
|
55
63
|
readonly frameworkFindings: readonly Finding[];
|
|
56
64
|
exists(relativePath: string): boolean;
|
|
57
65
|
portFree(port: number): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* Who holds a taken port: another checkout's server is a warning, this one's a finding. This and
|
|
68
|
+
* the two merge facts below are optional against the rule above: the type is exported, and the
|
|
69
|
+
* public-API lock reads a required member added on `main` as a break. Absent asks the OS.
|
|
70
|
+
*/
|
|
71
|
+
readonly portOwner?: (port: number) => Promise<PortOwner>;
|
|
58
72
|
/**
|
|
59
73
|
* Is the configured database reachable, and what refused? `null` is "reachable, or there is
|
|
60
74
|
* nothing external to reach" — an unset `DATABASE_URL` is embedded PGlite, which `x dev` owns
|
|
@@ -113,6 +127,12 @@ export interface DoctorProbe {
|
|
|
113
127
|
pins(): Promise<PinFact>;
|
|
114
128
|
/** The gate steps that apply here and `x.verify.json` does not floor (`doctor-floor.ts`). */
|
|
115
129
|
unflooredSteps(): Promise<readonly VerifyStepName[]>;
|
|
130
|
+
/** What a merge left: unmerged paths, catalogs that do not parse (`merge-state.ts`). Absent: none. */
|
|
131
|
+
readonly mergeState?: () => Promise<readonly Finding[]>;
|
|
132
|
+
/** Whether `.gitattributes` names a merge driver this clone has not installed. Absent: no. */
|
|
133
|
+
readonly mergeDriverUnset?: () => Promise<boolean>;
|
|
134
|
+
/** Actions and queries no `defineApi()` lists (`doctor-api-listing.ts`). Absent: none. */
|
|
135
|
+
readonly unlistedPrimitives?: () => Promise<readonly Finding[]>;
|
|
116
136
|
}
|
|
117
137
|
|
|
118
138
|
export function probeFor(
|
|
@@ -123,6 +143,10 @@ export function probeFor(
|
|
|
123
143
|
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
124
144
|
): DoctorProbe {
|
|
125
145
|
const root = findAppRoot(cwd)?.dir;
|
|
146
|
+
// As the boot dials it: `database.ssl` requires TLS where the URL and `PGSSLMODE` state no mode,
|
|
147
|
+
// so a probe never answers green over a connection the app itself would refuse to make.
|
|
148
|
+
const databaseUrl = (): Promise<string | undefined> =>
|
|
149
|
+
withAppTls(root, process.env['DATABASE_URL'], env);
|
|
126
150
|
return {
|
|
127
151
|
bunVersion,
|
|
128
152
|
root,
|
|
@@ -131,7 +155,8 @@ export function probeFor(
|
|
|
131
155
|
frameworkFindings: machineSecretFindings(env),
|
|
132
156
|
exists: (relativePath) => (root === undefined ? false : existsSync(join(root, relativePath))),
|
|
133
157
|
portFree,
|
|
134
|
-
|
|
158
|
+
portOwner,
|
|
159
|
+
database: async () => probeDatabase(await databaseUrl(), env),
|
|
135
160
|
// `root ?? cwd` because the walk needs a directory that exists; outside an app `runDoctor`
|
|
136
161
|
// returns on `X_NOT_IN_APP` before this is ever asked, so the value only has to be honest.
|
|
137
162
|
embeddedDatabase: async () => ({
|
|
@@ -150,16 +175,22 @@ export function probeFor(
|
|
|
150
175
|
root === undefined ? { fallback: null, routes: undefined } : offlineFallbackProbe(root),
|
|
151
176
|
sealedKeys: async () =>
|
|
152
177
|
root === undefined ? { columns: undefined, keys: undefined } : sealedKeysProbe(root),
|
|
153
|
-
authStorage: () => authStorageProbe(
|
|
154
|
-
pooler: () => poolerProbe(
|
|
178
|
+
authStorage: async () => authStorageProbe(await databaseUrl(), env),
|
|
179
|
+
pooler: async () => poolerProbe(await databaseUrl(), env),
|
|
155
180
|
typescript: async () => (root === undefined ? [] : typescriptProbe(root)),
|
|
156
181
|
rowSecurity: async () =>
|
|
157
|
-
root === undefined ? [] : rowSecurityProbe(root,
|
|
182
|
+
root === undefined ? [] : rowSecurityProbe(root, await databaseUrl(), env),
|
|
158
183
|
rowSecurityOff: async () =>
|
|
159
184
|
root === undefined ? { declared: false, touches: [] } : rowSecurityOffProbe(root),
|
|
160
185
|
envNames: async () => (root === undefined ? NO_APP_ENV_NAMES : appEnvNamesProbe(root, env)),
|
|
161
186
|
pins: async () => (root === undefined ? { pins: [], installed: new Map() } : pinProbe(root)),
|
|
162
187
|
unflooredSteps: async () => (root === undefined ? [] : unflooredStepsProbe(root)),
|
|
188
|
+
mergeState: async () =>
|
|
189
|
+
root === undefined
|
|
190
|
+
? []
|
|
191
|
+
: [...(await unmergedFindings(root)), ...(await catalogFileFindings(root))],
|
|
192
|
+
mergeDriverUnset: async () => (root === undefined ? false : driverUnset(root, exec)),
|
|
193
|
+
unlistedPrimitives: async () => (root === undefined ? [] : unlistedPrimitiveFindings(root)),
|
|
163
194
|
};
|
|
164
195
|
}
|
|
165
196
|
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// `x doctor`'s processes fact, read: each role through the boot's own `resolveProcessCount` as a
|
|
2
|
+
// production container on this host would ask it (cgroup, cores, pool, shared state), the
|
|
3
|
+
// `tcp_migrate_req` sysctl, and the server's `max_connections`. `doctor-processes.ts` judges it.
|
|
4
|
+
|
|
5
|
+
import type { Role } from '@ultimat3/core';
|
|
6
|
+
import { ROLES, resolveEnvironment } from '@ultimat3/core';
|
|
7
|
+
import { POOL_PROFILES, poolMaxFromEnv, postgresClient, sql } from '@ultimat3/db';
|
|
8
|
+
import { loadAppRuntime } from './app-runtime';
|
|
9
|
+
import type { ProcessesFact, RoleProcesses } from './doctor-processes';
|
|
10
|
+
import { findingFrom } from './output';
|
|
11
|
+
import type { RuntimeOverrides } from './runtime-overrides';
|
|
12
|
+
import type { ReadText } from './supervise-cgroup';
|
|
13
|
+
import { readCgroup, readText } from './supervise-cgroup';
|
|
14
|
+
import { resolveProcessCount } from './supervise-count';
|
|
15
|
+
import { sharedStateFacts } from './supervise-facts';
|
|
16
|
+
|
|
17
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
18
|
+
|
|
19
|
+
/** Every role a container runs as; `migrate` runs once and exits, so it holds nothing. */
|
|
20
|
+
const REPORTED: readonly Role[] = ROLES.filter((role) => role !== 'migrate');
|
|
21
|
+
|
|
22
|
+
export const MIGRATE_REQ_PATH = '/proc/sys/net/ipv4/tcp_migrate_req';
|
|
23
|
+
|
|
24
|
+
export interface ProcessesSources {
|
|
25
|
+
readonly root: string;
|
|
26
|
+
readonly env: Env;
|
|
27
|
+
/** `apps/<app>/runtime.ts`'s overrides: its stores and transport are shared state or not. */
|
|
28
|
+
readonly runtime: () => Promise<RuntimeOverrides | undefined>;
|
|
29
|
+
readonly platform: string;
|
|
30
|
+
readonly cores: number;
|
|
31
|
+
readonly read: ReadText;
|
|
32
|
+
readonly maxConnections: () => Promise<number | undefined>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Asked as `production`: the fact answers what a deployed container here would run, which `x dev`
|
|
37
|
+
* (always one process) never does. The image is taken as prebuilt (the Dockerfile's `x build
|
|
38
|
+
* --target prebuilt`): the boot itself clamps on that, and its line names the clamp.
|
|
39
|
+
*/
|
|
40
|
+
export async function processesFact(sources: ProcessesSources): Promise<ProcessesFact> {
|
|
41
|
+
const { env } = sources;
|
|
42
|
+
const runtime = await sources.runtime();
|
|
43
|
+
// The boot's own reader of shared state (`supervise-facts.ts`) over the same `runtime.ts`, so
|
|
44
|
+
// doctor and the boot cannot name different clamps.
|
|
45
|
+
const options = { root: sources.root, env, ...(runtime === undefined ? {} : { runtime }) };
|
|
46
|
+
const cgroup = await readCgroup(sources.read);
|
|
47
|
+
const poolOf = (role: Role): number => poolMaxFromEnv(env).max ?? POOL_PROFILES[role].max;
|
|
48
|
+
const roles = await Promise.all(
|
|
49
|
+
REPORTED.map(async (role): Promise<RoleProcesses> => {
|
|
50
|
+
const listen = role === 'worker' ? 1 : 0;
|
|
51
|
+
try {
|
|
52
|
+
const resolved = await resolveProcessCount({
|
|
53
|
+
env,
|
|
54
|
+
role,
|
|
55
|
+
platform: sources.platform,
|
|
56
|
+
environment: 'production',
|
|
57
|
+
cgroup: async () => cgroup,
|
|
58
|
+
parallelism: () => sources.cores,
|
|
59
|
+
pool: () => poolOf(role),
|
|
60
|
+
shared: () => sharedStateFacts(options, role),
|
|
61
|
+
prebuilt: async () => true,
|
|
62
|
+
});
|
|
63
|
+
return { role, resolved, pool: poolOf(role), listen };
|
|
64
|
+
} catch (error) {
|
|
65
|
+
return {
|
|
66
|
+
role,
|
|
67
|
+
resolved: { refused: findingFrom(error) },
|
|
68
|
+
pool: POOL_PROFILES[role].max,
|
|
69
|
+
listen,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
const requested = env['ULTIMATE_PROCESSES']?.trim() ?? '';
|
|
75
|
+
return {
|
|
76
|
+
environment: resolveEnvironment({ env }),
|
|
77
|
+
cores: sources.cores,
|
|
78
|
+
cpuBudget: cgroup.cpus,
|
|
79
|
+
explicit: requested !== '' && requested !== 'auto',
|
|
80
|
+
migrateReq: (await sources.read(MIGRATE_REQ_PATH))?.trim(),
|
|
81
|
+
roles,
|
|
82
|
+
maxConnections: await sources.maxConnections(),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** `max_connections` over one connection (the pool fills to max on first use); none on any failure. */
|
|
87
|
+
export async function maxConnectionsOf(
|
|
88
|
+
url: string | undefined,
|
|
89
|
+
env: Env,
|
|
90
|
+
): Promise<number | undefined> {
|
|
91
|
+
if (url === undefined || url.trim() === '') return undefined;
|
|
92
|
+
let client: ReturnType<typeof postgresClient> | undefined;
|
|
93
|
+
try {
|
|
94
|
+
client = postgresClient({
|
|
95
|
+
url,
|
|
96
|
+
role: 'web',
|
|
97
|
+
env,
|
|
98
|
+
applicationName: 'x-doctor',
|
|
99
|
+
profile: { max: 1 },
|
|
100
|
+
});
|
|
101
|
+
const rows = await client.query<{ readonly setting: string }>(
|
|
102
|
+
sql`select setting from pg_settings where name = 'max_connections'`,
|
|
103
|
+
);
|
|
104
|
+
const max = Number(rows[0]?.setting);
|
|
105
|
+
return Number.isSafeInteger(max) && max > 0 ? max : undefined;
|
|
106
|
+
} catch {
|
|
107
|
+
// Unreachable is `database()`'s finding to make; this fact only omits the comparison.
|
|
108
|
+
return undefined;
|
|
109
|
+
} finally {
|
|
110
|
+
await client?.close();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The real sources: this host's files, cores, app and database. */
|
|
115
|
+
export const hostProcessesSources = (
|
|
116
|
+
root: string,
|
|
117
|
+
env: Env,
|
|
118
|
+
databaseUrl: () => Promise<string | undefined>,
|
|
119
|
+
): ProcessesSources => ({
|
|
120
|
+
root,
|
|
121
|
+
env,
|
|
122
|
+
runtime: () => loadAppRuntime(root),
|
|
123
|
+
platform: process.platform,
|
|
124
|
+
cores: navigator.hardwareConcurrency,
|
|
125
|
+
read: readText,
|
|
126
|
+
maxConnections: async () => maxConnectionsOf(await databaseUrl(), env),
|
|
127
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// `x doctor`'s processes fact, pure: how many processes a production container of each role runs
|
|
2
|
+
// here (`resolveProcessCount`, and the clamp that bound it), the connections one container holds
|
|
3
|
+
// (Σ child pool shares + one LISTEN session per worker process), and the two warnings a production
|
|
4
|
+
// host owes: no CPU budget declared, and N > 1 with `net.ipv4.tcp_migrate_req` off.
|
|
5
|
+
|
|
6
|
+
import type { Environment, Role } from '@ultimat3/core';
|
|
7
|
+
import { ERROR_DOCS_URL } from '@ultimat3/core';
|
|
8
|
+
import { msg } from './messages';
|
|
9
|
+
import type { CommandResult, Finding, JsonValue } from './output';
|
|
10
|
+
import type { ProcessCount } from './supervise-count';
|
|
11
|
+
|
|
12
|
+
/** One role, resolved: its count, or the refusal an explicit `ULTIMATE_PROCESSES` met. */
|
|
13
|
+
export interface RoleProcesses {
|
|
14
|
+
readonly role: Role;
|
|
15
|
+
readonly resolved: ProcessCount | { readonly refused: Finding };
|
|
16
|
+
/** The container's pool: `DATABASE_POOL_MAX`, else the role's profile. */
|
|
17
|
+
readonly pool: number;
|
|
18
|
+
/** LISTEN sessions per process: the worker's queue wake holds one outside the pool. */
|
|
19
|
+
readonly listen: 0 | 1;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ProcessesFact {
|
|
23
|
+
readonly environment: Environment;
|
|
24
|
+
/** Cores this process sees (`navigator.hardwareConcurrency`): every host core without a quota. */
|
|
25
|
+
readonly cores: number;
|
|
26
|
+
/** Whole CPUs the cgroup declares; `undefined` when none is. */
|
|
27
|
+
readonly cpuBudget: number | undefined;
|
|
28
|
+
/** `ULTIMATE_PROCESSES` was set to a count, so the operator chose and the CPU warning is moot. */
|
|
29
|
+
readonly explicit: boolean;
|
|
30
|
+
/** `/proc/sys/net/ipv4/tcp_migrate_req`, trimmed; `undefined` off Linux or unreadable. */
|
|
31
|
+
readonly migrateReq: string | undefined;
|
|
32
|
+
readonly roles: readonly RoleProcesses[];
|
|
33
|
+
/** The server's `max_connections`; `undefined` when no external database answered. */
|
|
34
|
+
readonly maxConnections: number | undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const PRODUCTION_LIKE: ReadonlySet<Environment> = new Set(['production', 'staging']);
|
|
38
|
+
|
|
39
|
+
const countOf = (entry: RoleProcesses): number | undefined =>
|
|
40
|
+
'count' in entry.resolved ? entry.resolved.count : undefined;
|
|
41
|
+
|
|
42
|
+
/** Σ childShare(pool, i, N) is max(pool, N); each process adds its LISTEN session. */
|
|
43
|
+
export const connectionsOf = (entry: RoleProcesses): number | undefined => {
|
|
44
|
+
const count = countOf(entry);
|
|
45
|
+
return count === undefined ? undefined : Math.max(entry.pool, count) + count * entry.listen;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const COMPOSE = 'docker/docker-compose.prod.yml';
|
|
49
|
+
|
|
50
|
+
/** Warnings, on a production-like host only: a laptop declares no CPU budget and owes none. */
|
|
51
|
+
export function processesWarnings(fact: ProcessesFact): readonly Finding[] {
|
|
52
|
+
const refused = fact.roles.flatMap((entry) =>
|
|
53
|
+
'refused' in entry.resolved ? [entry.resolved.refused] : [],
|
|
54
|
+
);
|
|
55
|
+
if (!PRODUCTION_LIKE.has(fact.environment)) return refused;
|
|
56
|
+
const warnings: Finding[] = [...refused];
|
|
57
|
+
if (fact.cpuBudget === undefined && fact.cores > 1 && !fact.explicit) {
|
|
58
|
+
warnings.push({
|
|
59
|
+
code: 'X_PROCESSES_CPU_UNDECLARED',
|
|
60
|
+
cause: `this container declares no CPU budget on a host with ${fact.cores} cores, so ULTIMATE_PROCESSES=auto runs 1 process per role`,
|
|
61
|
+
fix: `cpus: '2' # on the role's service in ${COMPOSE} (resources.limits.cpu in Kubernetes); or ULTIMATE_PROCESSES=1 to say one is meant`,
|
|
62
|
+
docs: ERROR_DOCS_URL,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Only where the knob exists and reads 0: a kernel before 5.14 has none (`migrateReq` undefined),
|
|
66
|
+
// and the compose line would then stop the container from being created at all.
|
|
67
|
+
const shared = fact.roles.filter((entry) => (countOf(entry) ?? 1) > 1);
|
|
68
|
+
if (shared.length > 0 && fact.migrateReq === '0') {
|
|
69
|
+
const roles = shared.map((entry) => `${entry.role} (${countOf(entry)})`).join(', ');
|
|
70
|
+
warnings.push({
|
|
71
|
+
code: 'X_PROCESSES_MIGRATE_REQ_OFF',
|
|
72
|
+
cause: `this kernel has net.ipv4.tcp_migrate_req and it reads 0 while ${roles} share a port: a process that closes its listener resets every connection queued on it (measured 93–109 of 200; 0 with the sysctl)`,
|
|
73
|
+
fix: `sysctls: { net.ipv4.tcp_migrate_req: 1 } # uncomment it on web and sync in ${COMPOSE}; Linux >= 5.14 only — this host has the knob, an older kernel refuses to create the container`,
|
|
74
|
+
docs: ERROR_DOCS_URL,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return warnings;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const roleJson = (entry: RoleProcesses): JsonValue =>
|
|
81
|
+
'refused' in entry.resolved
|
|
82
|
+
? { role: entry.role, refused: entry.resolved.refused.code }
|
|
83
|
+
: {
|
|
84
|
+
role: entry.role,
|
|
85
|
+
count: entry.resolved.count,
|
|
86
|
+
binding: entry.resolved.binding,
|
|
87
|
+
pool: entry.pool,
|
|
88
|
+
listen: entry.listen * entry.resolved.count,
|
|
89
|
+
connections: connectionsOf(entry) ?? null,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/** The fact beside the verdict: `data.processes` for a machine, a line per role for a person. */
|
|
93
|
+
export function withProcessesReport(result: CommandResult, fact: ProcessesFact): CommandResult {
|
|
94
|
+
const data = typeof result.data === 'object' && result.data !== null ? result.data : {};
|
|
95
|
+
const perContainer = fact.roles.reduce((sum, entry) => sum + (connectionsOf(entry) ?? 0), 0);
|
|
96
|
+
const lines = [
|
|
97
|
+
msg('cli.doctor.processes', {
|
|
98
|
+
cores: fact.cores,
|
|
99
|
+
budget: fact.cpuBudget ?? msg('cli.doctor.processesUndeclared'),
|
|
100
|
+
}),
|
|
101
|
+
...fact.roles.map((entry) =>
|
|
102
|
+
'refused' in entry.resolved
|
|
103
|
+
? msg('cli.doctor.processesRefused', {
|
|
104
|
+
role: entry.role,
|
|
105
|
+
code: entry.resolved.refused.code,
|
|
106
|
+
})
|
|
107
|
+
: msg('cli.doctor.processesRole', {
|
|
108
|
+
role: entry.role,
|
|
109
|
+
count: entry.resolved.count,
|
|
110
|
+
binding: entry.resolved.binding,
|
|
111
|
+
pool: entry.pool,
|
|
112
|
+
listen: entry.listen * entry.resolved.count,
|
|
113
|
+
connections: connectionsOf(entry) ?? 0,
|
|
114
|
+
}),
|
|
115
|
+
),
|
|
116
|
+
...(fact.maxConnections === undefined
|
|
117
|
+
? []
|
|
118
|
+
: [
|
|
119
|
+
msg('cli.doctor.processesConnections', { total: perContainer, max: fact.maxConnections }),
|
|
120
|
+
]),
|
|
121
|
+
];
|
|
122
|
+
const processes: JsonValue = {
|
|
123
|
+
environment: fact.environment,
|
|
124
|
+
cores: fact.cores,
|
|
125
|
+
cpuBudget: fact.cpuBudget ?? null,
|
|
126
|
+
migrateReq: fact.migrateReq ?? null,
|
|
127
|
+
roles: fact.roles.map(roleJson),
|
|
128
|
+
connectionsOneOfEach: perContainer,
|
|
129
|
+
maxConnections: fact.maxConnections ?? null,
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
...result,
|
|
133
|
+
data: { ...(data as Record<string, JsonValue>), processes },
|
|
134
|
+
lines: [...(result.lines ?? []), ...lines],
|
|
135
|
+
};
|
|
136
|
+
}
|
package/src/doctor-warnings.ts
CHANGED
|
@@ -2,14 +2,25 @@
|
|
|
2
2
|
// never in it. On `main` an app that upgrades with no change keeps a green doctor
|
|
3
3
|
// (`X_BREAKING_ON_MAIN`); on `next` these move into `runDoctor`'s findings and the verdict.
|
|
4
4
|
|
|
5
|
+
import { ERROR_DOCS_URL } from '@ultimat3/core';
|
|
5
6
|
import { reservedEnvFindings } from './doctor-env-reserved';
|
|
6
7
|
import { unflooredStepFindings } from './doctor-floor';
|
|
7
8
|
import { pinRangeFindings } from './doctor-pins';
|
|
9
|
+
import { portWarnings } from './doctor-port';
|
|
8
10
|
import type { DoctorProbe } from './doctor-probe';
|
|
9
11
|
import { rowSecurityOffFindings } from './doctor-row-security';
|
|
12
|
+
import { REGISTRY_DRIVER } from './merge-driver-config';
|
|
10
13
|
import { msg } from './messages';
|
|
11
14
|
import type { CommandResult, Finding, JsonValue } from './output';
|
|
12
15
|
|
|
16
|
+
const MERGE_DRIVER_UNSET: Finding = {
|
|
17
|
+
code: 'X_MERGE_DRIVER_UNSET',
|
|
18
|
+
cause: `.gitattributes names merge=${REGISTRY_DRIVER}, and this clone has no such driver, so two branches' generated features conflict`,
|
|
19
|
+
fix: 'bunx x merge-driver install',
|
|
20
|
+
docs: ERROR_DOCS_URL,
|
|
21
|
+
at: '.gitattributes',
|
|
22
|
+
};
|
|
23
|
+
|
|
13
24
|
/** The probes that only warn on `main`. Asked inside an app only; outside one there is no app. */
|
|
14
25
|
export async function doctorWarnings(probe: DoctorProbe): Promise<readonly Finding[]> {
|
|
15
26
|
if (probe.root === undefined) return [];
|
|
@@ -22,6 +33,12 @@ export async function doctorWarnings(probe: DoctorProbe): Promise<readonly Findi
|
|
|
22
33
|
...rowSecurityOffFindings(await probe.rowSecurityOff()),
|
|
23
34
|
// A floor gap is the gate's blind spot, never a reason anything else is red.
|
|
24
35
|
...unflooredStepFindings(await probe.unflooredSteps()),
|
|
36
|
+
// A clone that merges by hand what its drivers would have merged: slower, never wrong.
|
|
37
|
+
...((await probe.mergeDriverUnset?.()) === true ? [MERGE_DRIVER_UNSET] : []),
|
|
38
|
+
// A port another checkout's dev server holds: nothing is wrong with this environment.
|
|
39
|
+
...(await portWarnings(probe)),
|
|
40
|
+
// Served by the scan, so never refused: an action or query the typed client cannot see.
|
|
41
|
+
...((await probe.unlistedPrimitives?.()) ?? []),
|
|
25
42
|
];
|
|
26
43
|
}
|
|
27
44
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The X_* codes of agents sharing one machine and repository: a checkout, port or app another
|
|
2
|
+
// process holds, a ledger wait given up, a half-done merge, a catalog a merge broke, a doctor check
|
|
3
|
+
// that threw. Split from `error-codes.ts` at its ceiling, which folds these into the CLI's one owned
|
|
4
|
+
// union and registers them in its one call; nothing else imports this file.
|
|
5
|
+
|
|
6
|
+
/** Codes `x dev`, `x upgrade`, `x heavy`, `x merge-driver`, `x doctor` and the catalog loader own. */
|
|
7
|
+
export const CLI_AGENTS_ERROR_CODES = [
|
|
8
|
+
'X_DEV_ALREADY_RUNNING',
|
|
9
|
+
// The OTHER thing the preflight can find, and it was reported as the one above: an unreadable
|
|
10
|
+
// lock this process could not remove made `DevAlreadyRunningError` name THIS pid as the holder,
|
|
11
|
+
// so the remedy printed was `kill <self>` — unrunnable, and a cause that was simply untrue.
|
|
12
|
+
'X_DEV_LOCK_UNREADABLE',
|
|
13
|
+
'X_PORT_IN_USE',
|
|
14
|
+
'X_UPGRADE_LOCKED',
|
|
15
|
+
'X_HEAVY_WAIT_EXPIRED',
|
|
16
|
+
'X_MERGE_UNRESOLVED',
|
|
17
|
+
'X_MERGE_DRIVER_UNSET',
|
|
18
|
+
'X_CATALOG_UNPARSEABLE',
|
|
19
|
+
'X_DOCTOR_PROBE_FAILED',
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
export type CliAgentsErrorCode = (typeof CLI_AGENTS_ERROR_CODES)[number];
|
|
23
|
+
|
|
24
|
+
/** Their titles, typed over the list above so a code without one is a build error. */
|
|
25
|
+
export const CLI_AGENTS_ERROR_TITLES: Readonly<Record<CliAgentsErrorCode, string>> = {
|
|
26
|
+
X_DEV_ALREADY_RUNNING: 'another x dev already owns this checkout',
|
|
27
|
+
X_DEV_LOCK_UNREADABLE: 'the dev lock file cannot be read or removed',
|
|
28
|
+
X_PORT_IN_USE: 'the dev port is taken',
|
|
29
|
+
X_UPGRADE_LOCKED: 'another x upgrade holds this app',
|
|
30
|
+
X_HEAVY_WAIT_EXPIRED: 'x heavy run stopped waiting for the machine ledger',
|
|
31
|
+
X_MERGE_UNRESOLVED: 'a merge left conflicts in the app',
|
|
32
|
+
X_MERGE_DRIVER_UNSET: 'the merge drivers .gitattributes names are not configured',
|
|
33
|
+
X_CATALOG_UNPARSEABLE: 'an i18n catalog is not valid JSON',
|
|
34
|
+
X_DOCTOR_PROBE_FAILED: 'one x doctor check could not run',
|
|
35
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The X_* codes of processes per container (`ULTIMATE_PROCESSES`): the count's refusals, the
|
|
2
|
+
// supervisor's crash loop and `x doctor`'s two warnings — split out of `error-codes.ts` at its
|
|
3
|
+
// 500-line ceiling. `error-codes.ts` folds these into the CLI's one owned union and registers them
|
|
4
|
+
// in its one call; nothing else imports this file.
|
|
5
|
+
|
|
6
|
+
/** Codes the supervisor (`supervise*.ts`) and `doctor-processes.ts` declare and own. */
|
|
7
|
+
export const CLI_PROCESSES_ERROR_CODES = [
|
|
8
|
+
'X_PROCESSES_INVALID',
|
|
9
|
+
'X_PROCESSES_ROLE_SINGLETON',
|
|
10
|
+
'X_PROCESSES_UNSHARED_STATE',
|
|
11
|
+
'X_PROCESSES_OVER_POOL',
|
|
12
|
+
'X_PROCESSES_UNBALANCED',
|
|
13
|
+
'X_PROCESS_CRASH_LOOP',
|
|
14
|
+
'X_PROCESSES_CPU_UNDECLARED',
|
|
15
|
+
'X_PROCESSES_MIGRATE_REQ_OFF',
|
|
16
|
+
] as const;
|
|
17
|
+
|
|
18
|
+
export type CliProcessesErrorCode = (typeof CLI_PROCESSES_ERROR_CODES)[number];
|
|
19
|
+
|
|
20
|
+
/** Their titles, typed over the list above so a code without one is a build error. */
|
|
21
|
+
export const CLI_PROCESSES_ERROR_TITLES: Readonly<Record<CliProcessesErrorCode, string>> = {
|
|
22
|
+
X_PROCESSES_INVALID: 'ULTIMATE_PROCESSES is not auto or a count',
|
|
23
|
+
X_PROCESSES_ROLE_SINGLETON: 'this role runs as one process per container',
|
|
24
|
+
X_PROCESSES_UNSHARED_STATE: 'more than one process over per-process state',
|
|
25
|
+
X_PROCESSES_OVER_POOL: 'more processes than database pool connections',
|
|
26
|
+
X_PROCESSES_UNBALANCED: 'SO_REUSEPORT does not balance on this platform',
|
|
27
|
+
X_PROCESS_CRASH_LOOP: 'a child process kept crashing',
|
|
28
|
+
X_PROCESSES_CPU_UNDECLARED: 'no CPU budget declared on a multi-core host',
|
|
29
|
+
X_PROCESSES_MIGRATE_REQ_OFF: 'shared-port listeners reset queued connections',
|
|
30
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// The X_* codes of the
|
|
2
|
-
// `x
|
|
1
|
+
// The X_* codes of the tooling commands — `x client`, `x graph` / `x impact`, `x repro`, `x explain`
|
|
2
|
+
// and `x heavy` — split out of `error-codes.ts` at its 500-line ceiling, as `error-codes-shot.ts`
|
|
3
3
|
// was. That file folds these into the CLI's one owned union and registers them in its one call.
|
|
4
4
|
|
|
5
|
-
/** Codes `x client`, `x graph`, `x impact`, `x repro` and `x
|
|
5
|
+
/** Codes `x client`, `x graph`, `x impact`, `x repro`, `x explain` and `x heavy` own. */
|
|
6
6
|
export const CLI_TOOLING_ERROR_CODES = [
|
|
7
7
|
'X_CLIENT_SPEC_UNSUPPORTED',
|
|
8
8
|
'X_CLIENT_STALE',
|
|
@@ -12,7 +12,11 @@ export const CLI_TOOLING_ERROR_CODES = [
|
|
|
12
12
|
'X_REPRO_UNKNOWN',
|
|
13
13
|
'X_REPRO_NOT_REPRODUCED',
|
|
14
14
|
'X_REPRO_CAPTURE_OFF',
|
|
15
|
+
'X_REPRO_BUNDLE_INVALID',
|
|
15
16
|
'X_EXPLAIN_PRODUCTION_DATABASE',
|
|
17
|
+
'X_HEAVY_LEDGER_UNAVAILABLE',
|
|
18
|
+
'X_HEAVY_MEMORY_INVALID',
|
|
19
|
+
'X_HEAVY_COMMAND_NOT_FOUND',
|
|
16
20
|
] as const;
|
|
17
21
|
|
|
18
22
|
export type CliToolingErrorCode = (typeof CLI_TOOLING_ERROR_CODES)[number];
|
|
@@ -27,5 +31,9 @@ export const CLI_TOOLING_ERROR_TITLES: Readonly<Record<CliToolingErrorCode, stri
|
|
|
27
31
|
X_REPRO_UNKNOWN: 'x repro was given an id nothing holds',
|
|
28
32
|
X_REPRO_NOT_REPRODUCED: 'a written repro test did not fail the way the original did',
|
|
29
33
|
X_REPRO_CAPTURE_OFF: 'x repro was given a request id while failure capture is off',
|
|
34
|
+
X_REPRO_BUNDLE_INVALID: 'the file is not a repro bundle this version can open',
|
|
30
35
|
X_EXPLAIN_PRODUCTION_DATABASE: 'x explain refused to run on a production database',
|
|
36
|
+
X_HEAVY_LEDGER_UNAVAILABLE: 'the machine memory ledger cannot be used here',
|
|
37
|
+
X_HEAVY_MEMORY_INVALID: 'ULTIMATE_HEAVY_MEMORY is not a size',
|
|
38
|
+
X_HEAVY_COMMAND_NOT_FOUND: 'x heavy run was given a command that is not on PATH',
|
|
31
39
|
};
|