@ultimat3/cli 31.16.0 → 31.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/package.json +29 -29
- package/src/cache-graph.ts +67 -0
- package/src/cmd-cache-spec.ts +25 -0
- package/src/cmd-cache.ts +187 -0
- package/src/cmd-config-spec.ts +23 -0
- package/src/cmd-config.ts +61 -0
- package/src/cmd-exercise.ts +34 -10
- package/src/cmd-explain-spec.ts +24 -0
- package/src/cmd-explain.ts +201 -0
- package/src/cmd-logs-spec.ts +34 -0
- package/src/cmd-logs.ts +80 -0
- package/src/cmd-planned.ts +15 -29
- package/src/cmd-token-spec.ts +54 -0
- package/src/cmd-token.ts +173 -0
- package/src/cmd-verify-spec.ts +13 -3
- package/src/cmd-verify.ts +2 -0
- package/src/config-redact.ts +39 -0
- package/src/dev-boot-data-dir.ts +69 -0
- package/src/dev-boot.ts +26 -13
- package/src/error-codes-tooling.ts +6 -4
- package/src/error-codes.ts +2 -0
- package/src/errors.ts +8 -2
- package/src/exercise-entry-edit.ts +5 -1
- package/src/exercise-routes.ts +59 -0
- package/src/explain-capture.ts +38 -0
- package/src/generate-exercise.ts +2 -2
- package/src/generate-factories.ts +133 -0
- package/src/generate-files.ts +11 -0
- package/src/generate-kinds.ts +13 -0
- package/src/mcp-db-target.ts +4 -3
- package/src/mcp-errors.ts +4 -0
- package/src/messages-gate.ts +2 -0
- package/src/messages-ops.ts +32 -0
- package/src/messages-upgrade.ts +1 -0
- package/src/messages.ts +2 -0
- package/src/otlp-export.ts +16 -2
- package/src/registry.ts +10 -0
- package/src/role-start.ts +11 -5
- package/src/runtime-services.ts +35 -19
- package/src/serve-boot-phases.ts +30 -0
- package/src/serve-boot-warnings.ts +62 -0
- package/src/serve-boot.ts +30 -11
- package/src/templates/generate-cron-job.ts +90 -0
- package/src/templates/generate-purge.ts +93 -0
- package/src/templates/generate-webhook-receiver.ts +274 -0
- package/src/templates/github/ci.yml.ts +101 -36
- package/src/templates/guard-repo-raw-sql-test.ts +174 -0
- package/src/templates/guard-repo-raw-sql.ts +115 -145
- package/src/templates/guard-unbounded-fanout.ts +170 -0
- package/src/templates/scaffold-claude-commands.ts +3 -2
- package/src/templates/scaffold-docs.ts +3 -2
- package/src/templates/scaffold-guards.ts +3 -0
- package/src/upgrade-gate.ts +18 -6
- package/src/upgrade-report.ts +4 -0
- package/src/verify-plan.ts +127 -0
- package/wiki/CI-Parallel-Gate.md +38 -1
- package/wiki/CLI-Reference.md +90 -12
- package/wiki/Caching-And-Invalidation.md +10 -10
- package/wiki/Configuration.md +4 -2
- package/wiki/Known-Gaps.md +1 -1
- package/wiki/MCP-And-AI.md +1 -1
- package/wiki/Testing.md +32 -0
- package/wiki/Troubleshooting.md +3 -2
- package/wiki/Upgrading.md +6 -0
package/README.md
CHANGED
|
@@ -21,7 +21,8 @@ Commands and the `x verify` step count, `As of 2026-08`:
|
|
|
21
21
|
| `x build --target docker\|binary\|static` | one artifact | `ROLE` selects behaviour at start |
|
|
22
22
|
| `x build --target prebuilt` | the store a container boots from: island chunks, compiled stylesheets | a `RUN` line in the image build, never run by hand |
|
|
23
23
|
| `x verify` | **the gate** | 21 named steps, each with pass/fail + duration; `budgets` runs `x build --target static` first when its stats are missing or older than the source |
|
|
24
|
-
| `x
|
|
24
|
+
| `x verify plan [--parts n]` | the gate as CI parts | `data.matrix` is a GitHub `strategy.matrix` of `x verify --only … [--shard i/n]` parts; `x new`'s workflow reads it with `fromJSON`, and `x verify merge` folds the parts back |
|
|
25
|
+
| `x exercise [<name>] [--seed n]` | every action, query, job and route `load` run once on generated rows, no test written | a scratch database; `.x/exercise.json`; an `unreached` primitive is `X_CONTRACT_EXERCISE_UNREACHED` with the override to paste into `apps/web/exercise.ts` — the gate's `exercise` step. `x.verify.json` `exercise: { unprovenMax, statementsMax }` turns unproven proofs and over-ceiling calls red; absent, warning lines. Route loads land in `routes` beside `records`, their loops and seq scans as warning lines |
|
|
25
26
|
| `x drill [<name>] [--list] [--budget-ms n]` | the app's roles as real processes on real services, each fault played through a proxy or a signal, judged on framework contracts only | a scratch database per drill; load = anonymous site pages plus every action an anonymous POST reaches (`data.skippedWrites` names the rest and why); `X_DRILL_FAILED` per property that did not hold, `X_DRILL_SERVICE_MISSING` before anything starts. Not a gate step — CI's `fault-drills` job runs three on `examples/dummy` |
|
|
26
27
|
| `x g <primitive> <name>` | scaffolds a primitive **with a passing test** | never a TODO stub |
|
|
27
28
|
| `x db gen\|migrate\|reset\|branch\|backfill` | everything DB | `branch` = copy-on-write clone + preview URL; `backfill` dry-runs unless `--write`. `x db studio` is **planned** — it parses, and exits `X_NOT_IMPLEMENTED` naming `/_x`'s db panel |
|
|
@@ -47,6 +48,11 @@ Commands and the `x verify` step count, `As of 2026-08`:
|
|
|
47
48
|
| `x client vendor <name>` / `x client customer --out <dir>` | one OpenAPI compiler (`openapi-compile.ts`), two emitters: a vendor's document into `apps/web/clients/<name>/` (`outbound()` + `t`), or the app's published document into a client with no framework import | every generated file is stamped with its source and body hash; `drift` raises `X_CLIENT_STALE` / `X_CLIENT_EDITED` ([flags](../../wiki/CLI-Reference.md#x-client)) |
|
|
48
49
|
| `x fix boundary <file>` | the minimal cut for a crossed surface boundary | prints the plan and the `git mv`; never rewrites a file |
|
|
49
50
|
| `x ci [runs]` / `x ci tested` | CI triage through `gh`; `tested`: may this push reuse a green PR run of the same tree | `tested` exits 0 on every answer, `data.tested`; any doubt is `false`, a full run ([conditions](../../wiki/CLI-Reference.md#x-pr--x-ci)) |
|
|
51
|
+
| `x token create\|list\|revoke` | MCP / API tokens in `x_api_keys` | `create --scopes a,b` prints the plaintext once and stores its hash; `list --owner <id>` carries no secret; `grant` is planned ([details](../../wiki/CLI-Reference.md#x-token)) |
|
|
52
|
+
| `x config show [--section <key>]` | the resolved `app.config.ts` | defaults merged by `defineConfig`; credential keys, `secret()` values and URL passwords redacted |
|
|
53
|
+
| `x logs tail [--lines n] [--role <role>]` | the end of `.x/dev.log` or a role log | the `logs.tail` MCP tool's file and reader |
|
|
54
|
+
| `x cache graph\|bust <tag>\|clear` | the tag graph off the manifest; a bust through the app's own tiers and bus | an in-process bus is said in the summary; a failed tier is `X_CACHE_DRIVER_UNAVAILABLE`; `stats` is planned |
|
|
55
|
+
| `x explain <query> [--input <json>] [--org <id>]` | one query's statements, planned on the dev database | the `exercise` step's oracle (`sweepPlans`): an unindexed read is `X_QUERY_UNINDEXED` with the `indexes:` entry as its fix |
|
|
50
56
|
|
|
51
57
|
Everything in [CLI reference](../../wiki/CLI-Reference.md)'s planned table is also in the registry
|
|
52
58
|
and exits `X_NOT_IMPLEMENTED` with a `fix:` naming the closest shipped command — "not built yet"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.17.0",
|
|
4
4
|
"description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -53,34 +53,34 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/core": "^8.0.9",
|
|
56
|
-
"@ultimat3/action": "31.
|
|
57
|
-
"@ultimat3/admin": "31.
|
|
58
|
-
"@ultimat3/ai": "31.
|
|
59
|
-
"@ultimat3/auth": "31.
|
|
60
|
-
"@ultimat3/cache": "31.
|
|
61
|
-
"@ultimat3/core": "31.
|
|
62
|
-
"@ultimat3/db": "31.
|
|
63
|
-
"@ultimat3/entity": "31.
|
|
64
|
-
"@ultimat3/flags": "31.
|
|
65
|
-
"@ultimat3/http": "31.
|
|
66
|
-
"@ultimat3/i18n": "31.
|
|
67
|
-
"@ultimat3/jobs": "31.
|
|
68
|
-
"@ultimat3/mail": "31.
|
|
69
|
-
"@ultimat3/manifest": "31.
|
|
70
|
-
"@ultimat3/mcp": "31.
|
|
71
|
-
"@ultimat3/money": "31.
|
|
72
|
-
"@ultimat3/notify": "31.
|
|
73
|
-
"@ultimat3/policy": "31.
|
|
74
|
-
"@ultimat3/pwa": "31.
|
|
75
|
-
"@ultimat3/query": "31.
|
|
76
|
-
"@ultimat3/realtime": "31.
|
|
77
|
-
"@ultimat3/render": "31.
|
|
78
|
-
"@ultimat3/schema": "31.
|
|
79
|
-
"@ultimat3/scraping": "31.
|
|
80
|
-
"@ultimat3/seo": "31.
|
|
81
|
-
"@ultimat3/storage": "31.
|
|
82
|
-
"@ultimat3/testing": "31.
|
|
83
|
-
"@ultimat3/time": "31.
|
|
56
|
+
"@ultimat3/action": "31.17.0",
|
|
57
|
+
"@ultimat3/admin": "31.17.0",
|
|
58
|
+
"@ultimat3/ai": "31.17.0",
|
|
59
|
+
"@ultimat3/auth": "31.17.0",
|
|
60
|
+
"@ultimat3/cache": "31.17.0",
|
|
61
|
+
"@ultimat3/core": "31.17.0",
|
|
62
|
+
"@ultimat3/db": "31.17.0",
|
|
63
|
+
"@ultimat3/entity": "31.17.0",
|
|
64
|
+
"@ultimat3/flags": "31.17.0",
|
|
65
|
+
"@ultimat3/http": "31.17.0",
|
|
66
|
+
"@ultimat3/i18n": "31.17.0",
|
|
67
|
+
"@ultimat3/jobs": "31.17.0",
|
|
68
|
+
"@ultimat3/mail": "31.17.0",
|
|
69
|
+
"@ultimat3/manifest": "31.17.0",
|
|
70
|
+
"@ultimat3/mcp": "31.17.0",
|
|
71
|
+
"@ultimat3/money": "31.17.0",
|
|
72
|
+
"@ultimat3/notify": "31.17.0",
|
|
73
|
+
"@ultimat3/policy": "31.17.0",
|
|
74
|
+
"@ultimat3/pwa": "31.17.0",
|
|
75
|
+
"@ultimat3/query": "31.17.0",
|
|
76
|
+
"@ultimat3/realtime": "31.17.0",
|
|
77
|
+
"@ultimat3/render": "31.17.0",
|
|
78
|
+
"@ultimat3/schema": "31.17.0",
|
|
79
|
+
"@ultimat3/scraping": "31.17.0",
|
|
80
|
+
"@ultimat3/seo": "31.17.0",
|
|
81
|
+
"@ultimat3/storage": "31.17.0",
|
|
82
|
+
"@ultimat3/testing": "31.17.0",
|
|
83
|
+
"@ultimat3/time": "31.17.0",
|
|
84
84
|
"babel-preset-solid": "^1.9.16"
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// The static tag graph `x cache graph` prints: per declared tag, the actions whose `invalidates`
|
|
2
|
+
// name it, the queries cached under it and the ISR routes revalidated by it — read off the app's
|
|
3
|
+
// manifest, the one description of what each primitive declared. Pure: manifest in, rows out.
|
|
4
|
+
|
|
5
|
+
import { parseTag } from '@ultimat3/cache';
|
|
6
|
+
|
|
7
|
+
/** What the graph reads of a `Manifest` — the whole manifest satisfies it, so does a fixture. */
|
|
8
|
+
export interface CacheGraphSource {
|
|
9
|
+
readonly actions: readonly {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly cacheInvalidates: readonly string[];
|
|
12
|
+
}[];
|
|
13
|
+
readonly queries: readonly { readonly name: string; readonly cacheTags: readonly string[] }[];
|
|
14
|
+
readonly routes: readonly { readonly url: string; readonly revalidateTags?: readonly string[] }[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CacheGraphRow {
|
|
18
|
+
/** The entity half of the tag: `post` for both `post` and `post:42`. */
|
|
19
|
+
readonly tag: string;
|
|
20
|
+
/** Actions whose `invalidates` names it — the writes that evict. */
|
|
21
|
+
readonly writers: readonly string[];
|
|
22
|
+
/** Queries cached under it — the reads that are evicted. */
|
|
23
|
+
readonly readers: readonly string[];
|
|
24
|
+
/** Routes whose `revalidate: { tags }` names it. */
|
|
25
|
+
readonly routes: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A tag read and never written: its entries are fresh only until their TTL. */
|
|
29
|
+
export const neverEvicted = (row: CacheGraphRow): boolean =>
|
|
30
|
+
row.writers.length === 0 && (row.readers.length > 0 || row.routes.length > 0);
|
|
31
|
+
|
|
32
|
+
interface Builder {
|
|
33
|
+
readonly writers: Set<string>;
|
|
34
|
+
readonly readers: Set<string>;
|
|
35
|
+
readonly routes: Set<string>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function cacheGraph(manifest: CacheGraphSource): readonly CacheGraphRow[] {
|
|
39
|
+
// A `Map`, never a record keyed by tag: a tag is the app's string, and `__proto__` is one.
|
|
40
|
+
const rows = new Map<string, Builder>();
|
|
41
|
+
const row = (wire: string): Builder => {
|
|
42
|
+
const tag = parseTag(wire).entity;
|
|
43
|
+
const found = rows.get(tag);
|
|
44
|
+
if (found !== undefined) return found;
|
|
45
|
+
const fresh: Builder = { writers: new Set(), readers: new Set(), routes: new Set() };
|
|
46
|
+
rows.set(tag, fresh);
|
|
47
|
+
return fresh;
|
|
48
|
+
};
|
|
49
|
+
for (const action of manifest.actions) {
|
|
50
|
+
for (const wire of action.cacheInvalidates) row(wire).writers.add(action.name);
|
|
51
|
+
}
|
|
52
|
+
for (const query of manifest.queries) {
|
|
53
|
+
for (const wire of query.cacheTags) row(wire).readers.add(query.name);
|
|
54
|
+
}
|
|
55
|
+
for (const route of manifest.routes) {
|
|
56
|
+
for (const wire of route.revalidateTags ?? []) row(wire).routes.add(route.url);
|
|
57
|
+
}
|
|
58
|
+
const sorted = (set: ReadonlySet<string>): readonly string[] => [...set].sort();
|
|
59
|
+
return [...rows.entries()]
|
|
60
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
61
|
+
.map(([tag, built]) => ({
|
|
62
|
+
tag,
|
|
63
|
+
writers: sorted(built.writers),
|
|
64
|
+
readers: sorted(built.readers),
|
|
65
|
+
routes: sorted(built.routes),
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// `x cache`'s declaration, apart from its body: the parser, `x help` and the `errors` step
|
|
2
|
+
// read it without loading `cmd-cache.ts`, which `registry.ts` imports only when the command runs.
|
|
3
|
+
|
|
4
|
+
import type { CommandSpec } from './parse';
|
|
5
|
+
|
|
6
|
+
/** `stats` stays listed and answers X_NOT_IMPLEMENTED (`PLANNED_SUBCOMMANDS`): hits live in a server. */
|
|
7
|
+
export const CACHE_SUBCOMMANDS = ['graph', 'bust', 'clear', 'stats'] as const;
|
|
8
|
+
|
|
9
|
+
export const cacheSpec: CommandSpec = {
|
|
10
|
+
name: 'cache',
|
|
11
|
+
summary: 'the tag graph (what each write evicts), and a bust of one tag or of every tag',
|
|
12
|
+
usage: 'x cache graph [--tag <tag>] · x cache bust <tag> · x cache clear [--json]',
|
|
13
|
+
requiresApp: true,
|
|
14
|
+
subcommands: [...CACHE_SUBCOMMANDS],
|
|
15
|
+
// Read-only, so the bare form may mean it; `bust` and `clear` are typed or not run.
|
|
16
|
+
defaultSubcommand: 'graph',
|
|
17
|
+
flags: [
|
|
18
|
+
{
|
|
19
|
+
name: 'tag',
|
|
20
|
+
type: 'string',
|
|
21
|
+
summary: 'graph: one tag only — the blast radius of a write that names it',
|
|
22
|
+
subcommands: ['graph'],
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
};
|
package/src/cmd-cache.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// `x cache graph|bust <tag>|clear` — the tag graph off the manifest (`cache-graph.ts`), and a bust
|
|
2
|
+
// run the way an action's `invalidates` runs one: the app's own tiers registered by the same boot a
|
|
3
|
+
// role makes (`startServices`), then `invalidateTags`, which drops the shared tiers, purges the
|
|
4
|
+
// edge and publishes on the bus every replica listens to. No second eviction path.
|
|
5
|
+
|
|
6
|
+
import type { InvalidationReport } from '@ultimat3/cache';
|
|
7
|
+
import {
|
|
8
|
+
assertKnownTags,
|
|
9
|
+
CacheDriverUnavailableError,
|
|
10
|
+
invalidateTags,
|
|
11
|
+
knownTags,
|
|
12
|
+
parseTag,
|
|
13
|
+
} from '@ultimat3/cache';
|
|
14
|
+
import { renderFixShellArg } from '@ultimat3/core';
|
|
15
|
+
import { redisUrlSource } from '@ultimat3/core/redis';
|
|
16
|
+
import { InProcessTransport } from '@ultimat3/realtime/server';
|
|
17
|
+
import { loadApp } from './app-load';
|
|
18
|
+
import { appManifest } from './app-manifest';
|
|
19
|
+
import { requireAppRoot } from './app-root';
|
|
20
|
+
import { loadAppRuntime } from './app-runtime';
|
|
21
|
+
import { cacheGraph, neverEvicted } from './cache-graph';
|
|
22
|
+
import { cacheSpec } from './cmd-cache-spec';
|
|
23
|
+
import { plannedSubcommand } from './cmd-planned';
|
|
24
|
+
import type { CliCommand, CommandContext } from './command';
|
|
25
|
+
import { MissingPositionalError } from './errors';
|
|
26
|
+
import { msg } from './messages';
|
|
27
|
+
import type { CommandResult, Finding, JsonValue } from './output';
|
|
28
|
+
import { findingFrom } from './output';
|
|
29
|
+
import { flagString } from './parse';
|
|
30
|
+
import { resolveServices } from './runtime-bindings';
|
|
31
|
+
import { startServices } from './runtime-services';
|
|
32
|
+
|
|
33
|
+
/** The app's tiers and bus, booted for one bust. */
|
|
34
|
+
export interface CacheHandle {
|
|
35
|
+
invalidate(tags: readonly string[]): Promise<InvalidationReport>;
|
|
36
|
+
/** False when the bus is in-process: no other process hears this one. */
|
|
37
|
+
readonly reachesPeers: boolean;
|
|
38
|
+
/** The bus as the boot line names it — never a URL. */
|
|
39
|
+
readonly bus: string;
|
|
40
|
+
close(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type OpenCache = (root: string, ctx: CommandContext) => Promise<CacheHandle>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A role's boot with no role started: the tiers `cache.tiers` declares and the broadcast. `'ensure'`,
|
|
47
|
+
* as every CLI command but the migrate step: a bust run against production takes no migration
|
|
48
|
+
* lock, runs no framework DDL and stamps no build (`runtime-queue.ts`'s `SchemaMode`).
|
|
49
|
+
*/
|
|
50
|
+
export const openAppCacheWith =
|
|
51
|
+
(start: typeof startServices): OpenCache =>
|
|
52
|
+
async (root, ctx) => {
|
|
53
|
+
const running = await start(
|
|
54
|
+
resolveServices(root, ctx.env),
|
|
55
|
+
ctx.env,
|
|
56
|
+
await loadAppRuntime(root),
|
|
57
|
+
'ensure',
|
|
58
|
+
[],
|
|
59
|
+
);
|
|
60
|
+
return {
|
|
61
|
+
invalidate: (tags) => invalidateTags(tags.map(parseTag)),
|
|
62
|
+
reachesPeers: !(
|
|
63
|
+
running.transport instanceof InProcessTransport && redisUrlSource(ctx.env) === undefined
|
|
64
|
+
),
|
|
65
|
+
bus: running.transport.name,
|
|
66
|
+
close: () => running.stop(),
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
async function graph(root: string, only: string | undefined): Promise<CommandResult> {
|
|
71
|
+
const { manifest, findings } = await appManifest(root);
|
|
72
|
+
const tag = only === undefined ? undefined : parseTag(only);
|
|
73
|
+
// After the app loaded, so the declared set is the app's: an undeclared tag is X_CACHE_TAG_UNKNOWN
|
|
74
|
+
// naming the declared ones, never an empty graph that reads as "nothing depends on it".
|
|
75
|
+
if (tag !== undefined) assertKnownTags([tag]);
|
|
76
|
+
const rows = cacheGraph(manifest).filter((row) => tag === undefined || row.tag === tag.entity);
|
|
77
|
+
const stale = rows.filter(neverEvicted).map((row) => row.tag);
|
|
78
|
+
return {
|
|
79
|
+
ok: findings.length === 0,
|
|
80
|
+
command: 'cache',
|
|
81
|
+
summary: msg('cli.cache.graph', { tags: rows.length, stale: stale.length }),
|
|
82
|
+
findings,
|
|
83
|
+
lines: rows.map((row) =>
|
|
84
|
+
msg('cli.cache.graphRow', {
|
|
85
|
+
tag: row.tag,
|
|
86
|
+
writers: row.writers.join(', ') || '—',
|
|
87
|
+
readers: [...row.readers, ...row.routes].join(', ') || '—',
|
|
88
|
+
}),
|
|
89
|
+
),
|
|
90
|
+
data: {
|
|
91
|
+
tags: rows.map((row) => ({
|
|
92
|
+
tag: row.tag,
|
|
93
|
+
writers: [...row.writers],
|
|
94
|
+
readers: [...row.readers],
|
|
95
|
+
routes: [...row.routes],
|
|
96
|
+
})),
|
|
97
|
+
neverEvicted: stale,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** A tier that failed the bust, as the finding an operator acts on. */
|
|
103
|
+
const tierFinding = (error: { tier: string; message: string }, retry: string): Finding =>
|
|
104
|
+
findingFrom(
|
|
105
|
+
new CacheDriverUnavailableError({
|
|
106
|
+
driver: error.tier,
|
|
107
|
+
cause: error.message,
|
|
108
|
+
fix: `${retry} # again once it answers; x doctor --json names the tier's binding`,
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
async function bust(
|
|
113
|
+
ctx: CommandContext,
|
|
114
|
+
open: OpenCache,
|
|
115
|
+
root: string,
|
|
116
|
+
/** Read AFTER the app loads: `clear`'s tags are the ones its modules declare. */
|
|
117
|
+
tagsOf: () => readonly string[],
|
|
118
|
+
retry: string,
|
|
119
|
+
): Promise<CommandResult> {
|
|
120
|
+
// Loaded first: the declared tags are registered by the app's modules, and an undeclared one is
|
|
121
|
+
// refused by `invalidateTags` itself (X_CACHE_TAG_UNKNOWN) rather than busting nothing.
|
|
122
|
+
const { findings } = await loadApp(root);
|
|
123
|
+
const tags = tagsOf();
|
|
124
|
+
const handle = await open(root, ctx);
|
|
125
|
+
const report = await handle.invalidate(tags).finally(() => handle.close());
|
|
126
|
+
const failures = report.errors.map((error) => tierFinding(error, retry));
|
|
127
|
+
const data: JsonValue = {
|
|
128
|
+
tags: [...report.tags],
|
|
129
|
+
tiers: report.tiers.map((tier) => ({
|
|
130
|
+
tier: tier.tier,
|
|
131
|
+
keys: tier.keys.length,
|
|
132
|
+
...(tier.skipped === undefined ? {} : { skipped: tier.skipped }),
|
|
133
|
+
})),
|
|
134
|
+
isr: [...report.isr],
|
|
135
|
+
cdn: [...report.cdn],
|
|
136
|
+
bus: handle.bus,
|
|
137
|
+
reachesPeers: handle.reachesPeers,
|
|
138
|
+
durationMs: report.durationMs,
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
ok: findings.length === 0 && failures.length === 0,
|
|
142
|
+
command: 'cache',
|
|
143
|
+
summary: handle.reachesPeers
|
|
144
|
+
? msg('cli.cache.busted', { tags: report.tags.length, bus: handle.bus })
|
|
145
|
+
: msg('cli.cache.bustedLocal', { tags: report.tags.length }),
|
|
146
|
+
findings: [...findings, ...failures],
|
|
147
|
+
lines: report.tiers.map((tier) =>
|
|
148
|
+
msg('cli.cache.tierRow', { tier: tier.tier, keys: tier.keys.length }),
|
|
149
|
+
),
|
|
150
|
+
data,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** `open` is the seam a test hands tiers through; the shipped command boots the app's own. */
|
|
155
|
+
export const cacheCommandOver = (open: OpenCache): CliCommand => ({
|
|
156
|
+
spec: cacheSpec,
|
|
157
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
158
|
+
const root = requireAppRoot('cache', ctx.cwd).dir;
|
|
159
|
+
const sub = ctx.args.subcommand ?? 'graph';
|
|
160
|
+
if (sub === 'graph') return graph(root, flagString(ctx.args, 'tag'));
|
|
161
|
+
if (sub === 'bust') {
|
|
162
|
+
const tag = ctx.args.positionals[0];
|
|
163
|
+
if (tag === undefined) {
|
|
164
|
+
throw new MissingPositionalError({
|
|
165
|
+
command: 'cache bust',
|
|
166
|
+
positional: 'tag',
|
|
167
|
+
example: 'x cache graph --json # the declared tags; then x cache bust <tag>',
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return bust(
|
|
171
|
+
ctx,
|
|
172
|
+
open,
|
|
173
|
+
root,
|
|
174
|
+
() => [tag],
|
|
175
|
+
`x cache bust ${renderFixShellArg(tag, '<tag>')} --json`,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
if (sub === 'clear') {
|
|
179
|
+
// Every declared tag through the same bust, so each peer drops what each one covers. An
|
|
180
|
+
// entry cached under no tag is not reached: it waits for its TTL, as it would for any write.
|
|
181
|
+
return bust(ctx, open, root, knownTags, 'x cache clear --json');
|
|
182
|
+
}
|
|
183
|
+
throw plannedSubcommand('cache', sub);
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
export const cacheCommand: CliCommand = cacheCommandOver(openAppCacheWith(startServices));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// `x config`'s declaration, apart from its body: the parser, `x help` and the `errors` step
|
|
2
|
+
// read it without loading `cmd-config.ts`, which `registry.ts` imports only when the command runs.
|
|
3
|
+
|
|
4
|
+
import type { CommandSpec } from './parse';
|
|
5
|
+
|
|
6
|
+
export const CONFIG_SUBCOMMANDS = ['show'] as const;
|
|
7
|
+
|
|
8
|
+
export const configSpec: CommandSpec = {
|
|
9
|
+
name: 'config',
|
|
10
|
+
summary: 'the resolved app.config.ts, defaults included, credentials redacted',
|
|
11
|
+
usage: 'x config show [--section <key>] [--json]',
|
|
12
|
+
requiresApp: true,
|
|
13
|
+
subcommands: [...CONFIG_SUBCOMMANDS],
|
|
14
|
+
// Read-only, so the bare form may mean it.
|
|
15
|
+
defaultSubcommand: 'show',
|
|
16
|
+
flags: [
|
|
17
|
+
{
|
|
18
|
+
name: 'section',
|
|
19
|
+
type: 'string',
|
|
20
|
+
summary: 'one top-level key of the resolved config (cache, database, auth, …)',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// `x config show [--section <key>]` — the app's `AppConfig` as the boot reads it: `app.config.ts`
|
|
2
|
+
// through `loadAppConfig` (core's `defineConfig`, defaults merged), credentials redacted by
|
|
3
|
+
// `config-redact.ts`. The answer to "what is this app actually configured to do", without a boot.
|
|
4
|
+
|
|
5
|
+
import { ConfigInvalidError } from '@ultimat3/core';
|
|
6
|
+
import { loadAppConfig } from './app-config-load';
|
|
7
|
+
import { requireAppRoot } from './app-root';
|
|
8
|
+
import { configSpec } from './cmd-config-spec';
|
|
9
|
+
import type { CliCommand, CommandContext } from './command';
|
|
10
|
+
import { ok } from './command';
|
|
11
|
+
import { redactConfigValue } from './config-redact';
|
|
12
|
+
import { BadFlagError } from './errors';
|
|
13
|
+
import { msg } from './messages';
|
|
14
|
+
import type { CommandResult, JsonValue } from './output';
|
|
15
|
+
import { flagString } from './parse';
|
|
16
|
+
|
|
17
|
+
/** The record's own keys, sorted — the closed set `--section` is held to. */
|
|
18
|
+
const sectionsOf = (config: object): readonly string[] => Object.keys(config).sort();
|
|
19
|
+
|
|
20
|
+
export const configCommand: CliCommand = {
|
|
21
|
+
spec: configSpec,
|
|
22
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
23
|
+
const root = requireAppRoot('config', ctx.cwd);
|
|
24
|
+
const config = await loadAppConfig(root.dir);
|
|
25
|
+
// `requireAppRoot` found the file, so only a race with a delete lands here.
|
|
26
|
+
if (config === undefined) {
|
|
27
|
+
throw new ConfigInvalidError({
|
|
28
|
+
cause: `${root.configPath} vanished between finding the app and reading it`,
|
|
29
|
+
fix: "export const config = defineConfig({ name: 'my-app' });",
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const sections = sectionsOf(config);
|
|
33
|
+
const section = flagString(ctx.args, 'section');
|
|
34
|
+
// `Object.hasOwn`, never `config[section]` first: `--section constructor` would answer the
|
|
35
|
+
// record's prototype method as if the app had declared it.
|
|
36
|
+
if (section !== undefined && !Object.hasOwn(config, section)) {
|
|
37
|
+
throw new BadFlagError({
|
|
38
|
+
flag: 'section',
|
|
39
|
+
command: 'config show',
|
|
40
|
+
reason: `"${section}" is not a key of the resolved config (known: ${sections.join(', ')})`,
|
|
41
|
+
fix: 'x config show --section cache --json',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const whole = redactConfigValue(config) as { readonly [key: string]: JsonValue };
|
|
45
|
+
const shown: JsonValue = section === undefined ? whole : (whole[section] ?? null);
|
|
46
|
+
return ok(
|
|
47
|
+
'config',
|
|
48
|
+
section === undefined
|
|
49
|
+
? msg('cli.config.show', {
|
|
50
|
+
name: config.name,
|
|
51
|
+
count: sections.length,
|
|
52
|
+
path: root.configPath,
|
|
53
|
+
})
|
|
54
|
+
: msg('cli.config.section', { section, path: root.configPath }),
|
|
55
|
+
{
|
|
56
|
+
lines: JSON.stringify(shown, null, 2).split('\n'),
|
|
57
|
+
data: { path: root.configPath, section: section ?? null, config: shown },
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
},
|
|
61
|
+
};
|
package/src/cmd-exercise.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// `x exercise [<name>] [--seed n]` — every action, query and
|
|
1
|
+
// `x exercise [<name>] [--seed n]` — every action, query, job and route `load` run once on rows
|
|
2
2
|
// with no test written: load the app, read `apps/web/exercise.ts`, run `@ultimat3/testing`'s pass
|
|
3
3
|
// on a scratch database, write `.x/exercise.json`. CLI wiring only: the pass is testing's, the
|
|
4
4
|
// verdict is `exercise-findings.ts`'s, so the gate step and this command read one rule.
|
|
@@ -8,10 +8,16 @@ import { join } from 'node:path';
|
|
|
8
8
|
import { describeEntities, registeredEntities } from '@ultimat3/entity';
|
|
9
9
|
import { registeredSubjects } from '@ultimat3/jobs';
|
|
10
10
|
import type { NamedActor } from '@ultimat3/policy';
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
ExercisePhaseMs,
|
|
13
|
+
ExerciseRecord,
|
|
14
|
+
RouteLoadRecord,
|
|
15
|
+
SeedEntity,
|
|
16
|
+
} from '@ultimat3/testing';
|
|
12
17
|
import {
|
|
13
18
|
entitySeedWriter,
|
|
14
19
|
planSweepLines,
|
|
20
|
+
routeLoadSubjects,
|
|
15
21
|
runExercisePass,
|
|
16
22
|
tenantFindingLines,
|
|
17
23
|
} from '@ultimat3/testing';
|
|
@@ -33,6 +39,7 @@ import {
|
|
|
33
39
|
} from './exercise-findings';
|
|
34
40
|
import { exerciseFloorVerdict } from './exercise-floor-verdict';
|
|
35
41
|
import { readExerciseOverrides } from './exercise-overrides';
|
|
42
|
+
import { emptyReachWarnings, routeLoadWarnings } from './exercise-routes';
|
|
36
43
|
import { entityTenantFindings } from './exercise-static';
|
|
37
44
|
import { subjectFindings, subjectProofFindings } from './exercise-subject';
|
|
38
45
|
import { readIntFlag } from './flag-number';
|
|
@@ -96,6 +103,8 @@ async function exercisePass(
|
|
|
96
103
|
(subject) => only === undefined && !subjectStatic.some((f) => f.at === subject.entity),
|
|
97
104
|
);
|
|
98
105
|
let pass: ExercisePhaseMs | undefined;
|
|
106
|
+
let routes: readonly RouteLoadRecord[] = [];
|
|
107
|
+
const routeSubjects = await routeLoadSubjects();
|
|
99
108
|
const records: readonly ExerciseRecord[] = await withExerciseDatabase(root, ctx.env, (client) =>
|
|
100
109
|
runExercisePass({
|
|
101
110
|
entities,
|
|
@@ -104,9 +113,14 @@ async function exercisePass(
|
|
|
104
113
|
...(overrides === undefined ? {} : { overrides }),
|
|
105
114
|
...(only === undefined ? {} : { only }),
|
|
106
115
|
roles: exerciseRoles,
|
|
116
|
+
// Every `app/` and `site/` route's `load`, after the primitives: a page read is measured too.
|
|
117
|
+
...(only === undefined ? { routes: routeSubjects } : {}),
|
|
107
118
|
onPhases: (ms) => {
|
|
108
119
|
pass = ms;
|
|
109
120
|
},
|
|
121
|
+
onRoutes: (got) => {
|
|
122
|
+
routes = got;
|
|
123
|
+
},
|
|
110
124
|
}),
|
|
111
125
|
);
|
|
112
126
|
const subjectStarted = performance.now();
|
|
@@ -120,16 +134,28 @@ async function exercisePass(
|
|
|
120
134
|
);
|
|
121
135
|
const subject = Math.round(performance.now() - subjectStarted);
|
|
122
136
|
const phases = pass === undefined ? undefined : { ...pass, subject };
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
137
|
+
// `routes` beside `records`, never in it: every reader of `records` reads a primitive's.
|
|
138
|
+
const report = {
|
|
139
|
+
...exerciseReport(records, seed, phases),
|
|
140
|
+
...(routes.length === 0 ? {} : { routes }),
|
|
141
|
+
};
|
|
127
142
|
// `x.verify.json`'s `exercise` key: red where the app opted in, a warning line where it has not.
|
|
128
143
|
// A whole-pass floor, so never judged on a `<name>` run's slice: 1 of 1 unproven is no ratio.
|
|
129
144
|
const floor =
|
|
130
145
|
only === undefined
|
|
131
146
|
? exerciseFloorVerdict(records, (await readVerifyFloor(root))?.exercise)
|
|
132
147
|
: { findings: [], warnings: [] };
|
|
148
|
+
// Warnings, never red on `main`: no floor key opts a page read in yet (`exercise-routes.ts`).
|
|
149
|
+
const warnings = [
|
|
150
|
+
...floor.warnings,
|
|
151
|
+
...routeLoadWarnings(routes),
|
|
152
|
+
...(only === undefined ? emptyReachWarnings(records) : []),
|
|
153
|
+
];
|
|
154
|
+
// One document, the file's and `--json`'s, its warnings in it (`lines` never holds what it lacks).
|
|
155
|
+
const document = warnings.length === 0 ? report : { ...report, warnings };
|
|
156
|
+
// The whole pass, not a one-primitive run's slice of it, is what the file is for — but a
|
|
157
|
+
// one-primitive run is still a fact worth keeping, so it is written either way.
|
|
158
|
+
await Bun.write(join(root, EXERCISE_REPORT_FILE), `${JSON.stringify(document, null, 2)}\n`);
|
|
133
159
|
const findings = [
|
|
134
160
|
...loaded.findings,
|
|
135
161
|
// The static half of the tenant proof (`exercise-static.ts`): the pass's own question,
|
|
@@ -155,12 +181,10 @@ async function exercisePass(
|
|
|
155
181
|
...tenantFindingLines(records),
|
|
156
182
|
...crashFindingLines(records),
|
|
157
183
|
...planSweepLines(records),
|
|
158
|
-
...
|
|
184
|
+
...warnings.map((warning) => `! ${warning}`),
|
|
159
185
|
].map((line) => ` ${line}`),
|
|
160
186
|
findings,
|
|
161
187
|
// The warning lines ride in `--json` too (`lines` never holds what the document lacks).
|
|
162
|
-
data:
|
|
163
|
-
? report
|
|
164
|
-
: { ...report, warnings: floor.warnings }) as unknown as JsonValue,
|
|
188
|
+
data: document as unknown as JsonValue,
|
|
165
189
|
};
|
|
166
190
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// `x explain`'s declaration, apart from its body: the parser, `x help` and the `errors` step
|
|
2
|
+
// read it without loading `cmd-explain.ts`, which `registry.ts` imports only when the command runs.
|
|
3
|
+
|
|
4
|
+
import type { CommandSpec } from './parse';
|
|
5
|
+
|
|
6
|
+
export const explainSpec: CommandSpec = {
|
|
7
|
+
name: 'explain',
|
|
8
|
+
summary:
|
|
9
|
+
"one declared query's SQL, planned on the dev database by the exercise gate's plan oracle",
|
|
10
|
+
usage: "x explain <query> [--input '<json>'] [--org <id>] [--json]",
|
|
11
|
+
requiresApp: true,
|
|
12
|
+
flags: [
|
|
13
|
+
{
|
|
14
|
+
name: 'input',
|
|
15
|
+
type: 'string',
|
|
16
|
+
summary: "the query's input as JSON, parsed by its own schema (default {})",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'org',
|
|
20
|
+
type: 'string',
|
|
21
|
+
summary: 'the tenant the read runs in — required when it reads a tenant-scoped entity',
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
};
|