@ultimat3/cli 31.49.0 → 31.51.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 +1 -1
- package/package.json +30 -30
- package/src/api-registration.ts +18 -1
- package/src/api-routes.ts +1 -0
- package/src/app-boundaries.ts +2 -0
- package/src/app-dev-imports.ts +77 -0
- package/src/app-load-import-chain.ts +112 -0
- package/src/app-load-unresolved.ts +173 -16
- package/src/app-load.ts +23 -7
- package/src/app-openapi.ts +7 -1
- package/src/budgets.ts +2 -1
- package/src/cmd-i18n.ts +33 -1
- package/src/codemods/engine-fs.ts +9 -2
- package/src/codemods/merge-drivers.ts +85 -4
- package/src/dev-only-imports.ts +59 -0
- package/src/error-codes-boundary.ts +2 -0
- package/src/evaluated-walk.ts +103 -0
- package/src/exercise-services.ts +13 -3
- package/src/framework-schema.ts +15 -5
- package/src/guard-sources.ts +1 -2
- package/src/index.ts +2 -0
- package/src/mcp-errors.ts +3 -1
- package/src/messages-upgrade.ts +4 -0
- package/src/module-imports.ts +26 -15
- package/src/page-navigation.ts +5 -2
- package/src/page-route.ts +75 -0
- package/src/pwa-artifacts.ts +1 -1
- package/src/retained-assets-boot.ts +1 -1
- package/src/runtime-assets-site.ts +2 -2
- package/src/runtime-assets.ts +1 -1
- package/src/runtime-render-document.ts +1 -2
- package/src/scan-ways.ts +145 -0
- package/src/site-asset-routes.ts +2 -2
- package/src/site-assets.ts +5 -158
- package/src/sw-precache-plan.ts +1 -1
- package/src/templates/guard-raw-motion.ts +96 -0
- package/src/templates/guard-released-forms.ts +4 -1
- package/src/templates/scaffold-repo.ts +1 -1
- package/src/test-only-shipped.ts +29 -2
- package/src/test-shards.ts +20 -8
- package/src/upgrade-coverage-ratchet.ts +95 -0
- package/src/upgrade-gate.ts +31 -11
- package/src/upgrade-report.ts +14 -0
- package/src/verify-checks.ts +7 -3
- package/src/verify-e2e.ts +21 -3
- package/src/workspace-checks.ts +4 -1
- package/wiki/Actions.md +64 -2
- package/wiki/Auth.md +6 -2
- package/wiki/CLI-Reference.md +8 -2
- package/wiki/Client-Navigation.md +34 -4
- package/wiki/Configuration.md +2 -1
- package/wiki/Entities-And-Migrations.md +12 -2
- package/wiki/Home.md +2 -2
- package/wiki/I18n.md +1 -1
- package/wiki/Interface-Rules.md +3 -1
- package/wiki/Known-Gaps.md +1 -1
- package/wiki/MCP-And-AI.md +41 -9
- package/wiki/Notify.md +4 -2
- package/wiki/Outbound-HTTP.md +53 -2
- package/wiki/Policies-And-Authz.md +1 -1
- package/wiki/Realtime.md +14 -6
- package/wiki/Routes-And-Render-Modes.md +1 -1
- package/wiki/Static-Assets.md +5 -3
- package/wiki/Testing.md +82 -3
- package/wiki/Theming.md +6 -3
- package/wiki/Troubleshooting.md +1 -1
- package/wiki/UI-Components.md +1 -0
- package/wiki/Upgrading.md +2 -0
package/src/cmd-i18n.ts
CHANGED
|
@@ -308,6 +308,32 @@ async function adminCatalog(locale: string, seeded: boolean): Promise<Catalog> {
|
|
|
308
308
|
return Object.fromEntries(keys.map((key) => [key, label(key)]));
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
+
/**
|
|
312
|
+
* The admin keys just written to a second locale that the default locale's FILE lacks, written
|
|
313
|
+
* there too. The default locale answers them already — the framework's own `en` holds the admin
|
|
314
|
+
* chrome (`admin.brand.name`, `admin.x_jobs.title`), so its registry is green with no such key in
|
|
315
|
+
* the app's catalog — and syncing only the second locale left the app's catalogs with two key sets,
|
|
316
|
+
* the scaffold's own "same keys as the default" test red on the command the gate prescribed. The
|
|
317
|
+
* value is the string the default locale already renders, never a marker, so its page is unchanged.
|
|
318
|
+
*/
|
|
319
|
+
async function backfillDefault(
|
|
320
|
+
root: string,
|
|
321
|
+
catalogs: Readonly<Record<string, Catalog>>,
|
|
322
|
+
from: string,
|
|
323
|
+
adminKeys: readonly string[],
|
|
324
|
+
): Promise<readonly string[]> {
|
|
325
|
+
const target = catalogs[from] ?? {};
|
|
326
|
+
const rendered = catalogFor(from);
|
|
327
|
+
const real = (key: string): string => {
|
|
328
|
+
const value = rendered[key];
|
|
329
|
+
return value === undefined || isLoudMiss(value) ? adminKeyLabel(key) : value;
|
|
330
|
+
};
|
|
331
|
+
const source = Object.fromEntries(adminKeys.map((key) => [key, real(key)]));
|
|
332
|
+
const { merged, added } = syncCatalog(target, source);
|
|
333
|
+
if (added.length > 0) await Bun.write(join(root, catalogPath(from)), serializeCatalog(merged));
|
|
334
|
+
return added;
|
|
335
|
+
}
|
|
336
|
+
|
|
311
337
|
async function runSync(root: string, ctx: CommandContext): Promise<CommandResult> {
|
|
312
338
|
const locale = resolveOneLocale(ctx, 'sync');
|
|
313
339
|
const catalogs = await loadCatalogs(root);
|
|
@@ -330,14 +356,17 @@ async function runSync(root: string, ctx: CommandContext): Promise<CommandResult
|
|
|
330
356
|
const seeded = from === undefined || from === locale;
|
|
331
357
|
// The admin's keys first, so a value the default locale already carries for one (copied, marked)
|
|
332
358
|
// wins over a label read off the key.
|
|
359
|
+
const admin = await adminCatalog(locale, seeded);
|
|
333
360
|
const source = {
|
|
334
|
-
...
|
|
361
|
+
...admin,
|
|
335
362
|
...(seeded
|
|
336
363
|
? placeholderCatalog(await untranslatedKeys(root, catalogs, locale))
|
|
337
364
|
: seedCatalog(catalogs[from] ?? {})),
|
|
338
365
|
};
|
|
339
366
|
const { merged, added } = syncCatalog(target, source);
|
|
340
367
|
if (added.length > 0) await Bun.write(join(root, catalogPath(locale)), serializeCatalog(merged));
|
|
368
|
+
const adminAdded = added.filter((key) => Object.hasOwn(admin, key));
|
|
369
|
+
const defaultAdded = seeded ? [] : await backfillDefault(root, catalogs, from, adminAdded);
|
|
341
370
|
// Unconditional, and not only when keys moved: a catalog that reached disk some other way — a
|
|
342
371
|
// hand-created file, a `git merge` — is exactly the unregistered locale the gate refuses, and
|
|
343
372
|
// this is the command its `fix:` names. Re-deriving an index that is already correct writes the
|
|
@@ -367,6 +396,9 @@ async function runSync(root: string, ctx: CommandContext): Promise<CommandResult
|
|
|
367
396
|
// both are what `x i18n check` counts as missing until replaced, so `--json` never reports a
|
|
368
397
|
// copy as a translation.
|
|
369
398
|
placeholders: added.filter((key) => isLoudMiss(merged[key])),
|
|
399
|
+
// The admin keys also written to the default locale's catalog, so every app catalog keeps one
|
|
400
|
+
// key set (`backfillDefault`). Empty when the default locale is the one synced.
|
|
401
|
+
defaultAdded,
|
|
370
402
|
},
|
|
371
403
|
};
|
|
372
404
|
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
// why: Bun has no file-removal, rename, lstat or realpath primitive; `rm` with `force` makes a
|
|
6
6
|
// removal of nothing no error, `rename` lands a write whole, and only `realpath` answers where a
|
|
7
|
-
// symlinked component really points.
|
|
8
|
-
import { lstat, realpath, rename, rm } from 'node:fs/promises';
|
|
7
|
+
// symlinked component really points; `stat`/`chmod` carry a rewritten file's mode across the rename.
|
|
8
|
+
import { chmod, lstat, realpath, rename, rm, stat } from 'node:fs/promises';
|
|
9
9
|
// why: Bun exposes no path-resolve primitive; containment is decided on the resolved path.
|
|
10
10
|
import { dirname, resolve, sep } from 'node:path';
|
|
11
11
|
import { ScaffoldPathEscapeError } from '../errors';
|
|
@@ -60,8 +60,15 @@ export async function landFile(
|
|
|
60
60
|
move: (from: string, to: string) => Promise<void> = rename,
|
|
61
61
|
): Promise<void> {
|
|
62
62
|
const temp = `${target}.x-codemod-${String(process.pid)}-${crypto.randomUUID()}.tmp`;
|
|
63
|
+
// The temp file is born 0644: without the target's mode carried over, the rename drops `+x` —
|
|
64
|
+
// 31.49.0's merge-drivers codemod turned an app's executable `bin/setup.ts` into a plain file.
|
|
65
|
+
const mode = await stat(target).then(
|
|
66
|
+
(found) => found.mode,
|
|
67
|
+
() => undefined,
|
|
68
|
+
);
|
|
63
69
|
await Bun.write(temp, source);
|
|
64
70
|
try {
|
|
71
|
+
if (mode !== undefined) await chmod(temp, mode);
|
|
65
72
|
await move(temp, target);
|
|
66
73
|
} catch (error) {
|
|
67
74
|
await rm(temp, { force: true });
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
// 31.49.0: two branches that each generate a feature merge without a hand edit. An existing app
|
|
2
2
|
// gains the `.gitattributes` rules, the `bun run setup` step that installs the drivers, and its
|
|
3
|
-
// registries one entry per line
|
|
4
|
-
//
|
|
3
|
+
// registries one entry per line, the spread `api/index.ts` with a test that loads it. Additive: a
|
|
4
|
+
// list or a setup this cannot restate is left alone and reported; it only keeps merging by hand.
|
|
5
5
|
|
|
6
|
+
import { isJsonObject, stringField } from '@ultimat3/core';
|
|
7
|
+
import { API_INDEX } from '../app-root';
|
|
6
8
|
import { REGISTRY_FILES, withRegistryLines } from '../registry-lines';
|
|
7
9
|
import { BIN_SCRIPTS } from '../templates/scaffold-bin';
|
|
8
10
|
import { MERGE_ATTRIBUTES, ROOT_GITATTRIBUTES_PATH } from '../templates/scaffold-gitattributes';
|
|
9
|
-
import type { Codemod, CodemodApp, CodemodResult } from './codemod';
|
|
11
|
+
import type { Codemod, CodemodApp, CodemodResult, CodemodSkip } from './codemod';
|
|
10
12
|
|
|
11
13
|
const INSTALL_ANCHOR = "await bun('install');\n";
|
|
12
14
|
export const INSTALL_STEP = "await x('merge-driver', 'install');\n";
|
|
15
|
+
/** The same step for a setup script that is not `bin/setup.ts`: a shell line, pasted by hand. */
|
|
16
|
+
export const SHELL_INSTALL_STEP = 'bunx x merge-driver install';
|
|
13
17
|
|
|
14
18
|
const withAttributes = (held: string | undefined): string | undefined => {
|
|
15
19
|
if (held?.includes('merge=x-registry') === true) return undefined;
|
|
@@ -17,6 +21,69 @@ const withAttributes = (held: string | undefined): string | undefined => {
|
|
|
17
21
|
return `${held.endsWith('\n') ? held : `${held}\n`}\n${MERGE_ATTRIBUTES}`;
|
|
18
22
|
};
|
|
19
23
|
|
|
24
|
+
export const API_INDEX_TEST = API_INDEX.replace(/\.ts$/, '.test.ts');
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The registration test, for an app `x new` wrote before it shipped `api/index.test.ts`. One row
|
|
28
|
+
* per entry is more lines, and an index no unit test loads weighs every one of them at 0% against
|
|
29
|
+
* the coverage floor — an upgrade that changed no behaviour went red. Generic on purpose: it reads
|
|
30
|
+
* the lists back, so it holds for any app's registrations.
|
|
31
|
+
*/
|
|
32
|
+
export const apiIndexTest =
|
|
33
|
+
(): string => `// The registration, read back: importing the index runs \`defineApi\`, and every primitive it
|
|
34
|
+
// lists is registered under the export name it was handed over as.
|
|
35
|
+
import { expect, unitTest } from '@ultimat3/testing';
|
|
36
|
+
import { api } from './index';
|
|
37
|
+
|
|
38
|
+
unitTest('every listed primitive is registered under its export name', () => {
|
|
39
|
+
const lists: readonly object[] = [api.actions, api.queries, api.jobs, api.tasks];
|
|
40
|
+
for (const list of lists) {
|
|
41
|
+
for (const [name, primitive] of Object.entries(list)) {
|
|
42
|
+
expect(primitive).toHaveProperty('name', name);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
/** The index declares `api`, so the generic test has something to import; else it is reported. */
|
|
49
|
+
const EXPORTS_API = /^export const api = defineApi\(/m;
|
|
50
|
+
|
|
51
|
+
/** `scripts.setup` from the app's package.json, when it declares one. */
|
|
52
|
+
const setupCommand = (manifest: string | undefined): string | undefined => {
|
|
53
|
+
if (manifest === undefined) return undefined;
|
|
54
|
+
let parsed: unknown;
|
|
55
|
+
try {
|
|
56
|
+
parsed = JSON.parse(manifest);
|
|
57
|
+
} catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const scripts = isJsonObject(parsed) ? parsed['scripts'] : undefined;
|
|
61
|
+
return isJsonObject(scripts) ? stringField(scripts, 'setup') : undefined;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A setup that is not `bin/setup.ts` (a bash `bin/setup`, a Makefile) is never edited — a shell
|
|
66
|
+
* script has no anchor this can trust — but it is always reported, naming the file `bun run setup`
|
|
67
|
+
* runs when the app holds it, else `package.json`, unless that file already installs the drivers.
|
|
68
|
+
*/
|
|
69
|
+
async function foreignSetup(app: CodemodApp): Promise<CodemodSkip | undefined> {
|
|
70
|
+
const command = setupCommand(await app.read('package.json'));
|
|
71
|
+
for (const token of command?.split(/\s+/) ?? []) {
|
|
72
|
+
const path = token.replace(/^\.\//, '');
|
|
73
|
+
const held = path === '' ? undefined : await app.read(path);
|
|
74
|
+
if (held === undefined) continue;
|
|
75
|
+
if (held.includes('merge-driver install')) return undefined;
|
|
76
|
+
return {
|
|
77
|
+
path,
|
|
78
|
+
reason: `bun run setup runs ${path}, not ${BIN_SCRIPTS.setup}; add the line ${SHELL_INSTALL_STEP} after its install step`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
path: 'package.json',
|
|
83
|
+
reason: `no ${BIN_SCRIPTS.setup} and no setup script file in the app; add ${SHELL_INSTALL_STEP} to whatever bun run setup runs, after its install step`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
20
87
|
async function edit(
|
|
21
88
|
app: CodemodApp,
|
|
22
89
|
path: string,
|
|
@@ -44,7 +111,10 @@ export const codemod: Codemod = {
|
|
|
44
111
|
changed.push(ROOT_GITATTRIBUTES_PATH);
|
|
45
112
|
}
|
|
46
113
|
const setup = await app.read(BIN_SCRIPTS.setup);
|
|
47
|
-
if (setup
|
|
114
|
+
if (setup === undefined) {
|
|
115
|
+
const skip = await foreignSetup(app);
|
|
116
|
+
if (skip !== undefined) skipped.push(skip);
|
|
117
|
+
} else if (!setup.includes(INSTALL_STEP)) {
|
|
48
118
|
if (setup.includes(INSTALL_ANCHOR)) {
|
|
49
119
|
await app.write(
|
|
50
120
|
BIN_SCRIPTS.setup,
|
|
@@ -61,6 +131,17 @@ export const codemod: Codemod = {
|
|
|
61
131
|
for (const path of REGISTRY_FILES) {
|
|
62
132
|
await edit(app, path, (held) => withRegistryLines(path, held), changed);
|
|
63
133
|
}
|
|
134
|
+
if (changed.includes(API_INDEX) && !(await app.exists(API_INDEX_TEST))) {
|
|
135
|
+
if (EXPORTS_API.test((await app.read(API_INDEX)) ?? '')) {
|
|
136
|
+
await app.write(API_INDEX_TEST, apiIndexTest());
|
|
137
|
+
changed.push(API_INDEX_TEST);
|
|
138
|
+
} else {
|
|
139
|
+
skipped.push({
|
|
140
|
+
path: API_INDEX_TEST,
|
|
141
|
+
reason: `${API_INDEX} now lists one entry per line and no unit test loads it, so its lines count at 0% against the coverage floor; write a test that imports it`,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
64
145
|
return { changed, skipped };
|
|
65
146
|
},
|
|
66
147
|
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The specifiers no container role may evaluate, and the one edit that clears an app of one: where
|
|
2
|
+
// on the way from a scanned module to the import the cut is, and the line to run there. The gate's
|
|
3
|
+
// check (`app-dev-imports.ts`) and the load's explanation of a failed import
|
|
4
|
+
// (`app-load-import-chain.ts`) read one rule, so a finding at boot and one at the gate agree.
|
|
5
|
+
|
|
6
|
+
import { scannedModulePaths } from './app-load';
|
|
7
|
+
import { realPath } from './app-load-unresolved';
|
|
8
|
+
import { commentSafe } from './comment-safe';
|
|
9
|
+
import type { ChainStep } from './evaluated-walk';
|
|
10
|
+
import { quoteArg } from './shell-quote';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* `@ultimat3/cli`'s barrel is every command, template and the test harness, and it imports
|
|
14
|
+
* `@ultimat3/testing`; a role's entry is `@ultimat3/cli/serve`. `bun:test` is the runner's own.
|
|
15
|
+
*/
|
|
16
|
+
export const isDevOnlySpecifier = (specifier: string): boolean =>
|
|
17
|
+
specifier === '@ultimat3/cli' ||
|
|
18
|
+
specifier === 'bun:test' ||
|
|
19
|
+
/^@ultimat3\/testing(?:\/|$)/.test(specifier);
|
|
20
|
+
|
|
21
|
+
/** Every module the boot scan imports under `base`, links followed: what a cut may be made in. */
|
|
22
|
+
export const scannedModules = async (base: string): Promise<ReadonlySet<string>> =>
|
|
23
|
+
new Set((await scannedModulePaths(base)).map(realPath));
|
|
24
|
+
|
|
25
|
+
/** `apps/web/app/x.ts` → `apps/web/test/`: beside the surfaces, and outside every app-scan glob. */
|
|
26
|
+
const testHome = (at: string): string => {
|
|
27
|
+
const workspace = /^(?:apps|packages)\/[^/]+(?=\/)/.exec(at)?.[0];
|
|
28
|
+
return workspace === undefined ? 'a test/ directory' : `${workspace}/test/`;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Where the cut is, and the import to look for there. */
|
|
32
|
+
export interface DevOnlyCut {
|
|
33
|
+
/** Its index in the steps: the last module the boot scan imports. */
|
|
34
|
+
readonly index: number;
|
|
35
|
+
/** What that module imports on the way; `undefined` when it holds the development import itself. */
|
|
36
|
+
readonly into: string | undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The cut on the way to a development import, whose holder is the last of `steps`. The holder when
|
|
41
|
+
* the scan imports it; when it sits outside the scan (a kit under `test/`), moving it clears nothing
|
|
42
|
+
* and the cut is the scanned module's edge towards it.
|
|
43
|
+
*/
|
|
44
|
+
export function devOnlyCut(steps: readonly ChainStep[], scanned: ReadonlySet<string>): DevOnlyCut {
|
|
45
|
+
const index = Math.max(
|
|
46
|
+
0,
|
|
47
|
+
steps.findLastIndex((step) => scanned.has(step.path)),
|
|
48
|
+
);
|
|
49
|
+
return { index, into: steps[index + 1]?.specifier };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The edit, opening with the line to look at. `at` is app-root-relative: the cut's module. */
|
|
53
|
+
export function devOnlyFix(at: string, cut: DevOnlyCut, specifier: string): string {
|
|
54
|
+
const line = `grep -nF -- ${quoteArg(cut.into ?? specifier)} ${quoteArg(at)}`;
|
|
55
|
+
// `commentSafe`: a workspace directory's name is the repository's, and a newline ends a comment.
|
|
56
|
+
return cut.into === undefined
|
|
57
|
+
? `${line} # test support moves to ${commentSafe(testHome(at))}, which no role loads; a module a role needs drops this import`
|
|
58
|
+
: `${line} # it brings test support into a module a role loads: only a test imports that`;
|
|
59
|
+
}
|
|
@@ -14,6 +14,7 @@ export const CLI_BOUNDARY_ERROR_CODES = [
|
|
|
14
14
|
'X_BOUNDARY_PACKAGE_TO_APP',
|
|
15
15
|
'X_BOUNDARY_ADAPTER_IMPORT',
|
|
16
16
|
'X_BOUNDARY_LOADER_IMPORT',
|
|
17
|
+
'X_BOUNDARY_DEV_IMPORT',
|
|
17
18
|
] as const;
|
|
18
19
|
|
|
19
20
|
export type CliBoundaryErrorCode = (typeof CLI_BOUNDARY_ERROR_CODES)[number];
|
|
@@ -29,4 +30,5 @@ export const CLI_BOUNDARY_ERROR_TITLES: Readonly<Record<CliBoundaryErrorCode, st
|
|
|
29
30
|
X_BOUNDARY_PACKAGE_TO_APP: 'packages/ imported apps/ at runtime',
|
|
30
31
|
X_BOUNDARY_ADAPTER_IMPORT: 'an app module imports an adapter installer',
|
|
31
32
|
X_BOUNDARY_LOADER_IMPORT: 'an app module imports a registration loader',
|
|
33
|
+
X_BOUNDARY_DEV_IMPORT: 'a module a role loads imports a development entry',
|
|
32
34
|
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// What importing a set of modules EVALUATES, walked breadth first with the path to each module
|
|
2
|
+
// kept — so a finding about a module deep in the graph can name how it was reached. Two callers:
|
|
3
|
+
// the load's explanation of an import that failed inside a package (`app-load-import-chain.ts`)
|
|
4
|
+
// and the gate's check of what a role loads (`app-dev-imports.ts`). Never in a healthy boot.
|
|
5
|
+
|
|
6
|
+
import { importedSpecifiers, resolveImport } from './module-imports';
|
|
7
|
+
|
|
8
|
+
/** One static import, as the module at `from` spells it. `target` resolves it when it is asked. */
|
|
9
|
+
export interface EvaluatedImport {
|
|
10
|
+
readonly from: string;
|
|
11
|
+
readonly specifier: string;
|
|
12
|
+
target(): string | undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** `follow` walks the import's target, `skip` leaves it, `stop` ends the walk with it as the end. */
|
|
16
|
+
export type WalkVerdict = 'follow' | 'skip' | 'stop';
|
|
17
|
+
|
|
18
|
+
/** A module on a chain, and how the one before it spelled it — absent on the start. */
|
|
19
|
+
export interface ChainStep {
|
|
20
|
+
readonly path: string;
|
|
21
|
+
readonly specifier?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface EvaluatedWalk {
|
|
25
|
+
/** Start first, `path` last: the shortest way there. Empty for a module the walk never reached. */
|
|
26
|
+
chainTo(path: string): readonly ChainStep[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface EvaluatedGraph {
|
|
30
|
+
walk(
|
|
31
|
+
starts: readonly string[],
|
|
32
|
+
judge: (edge: EvaluatedImport) => WalkVerdict,
|
|
33
|
+
): Promise<EvaluatedWalk>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** What names an import at all: a dataset or a stylesheet is a target, and never read as source. */
|
|
37
|
+
const CODE = /\.[cm]?[jt]sx?$/;
|
|
38
|
+
|
|
39
|
+
/** One graph, however many walks: a module is read and parsed once, whoever reaches it. */
|
|
40
|
+
export function createEvaluatedGraph(): EvaluatedGraph {
|
|
41
|
+
const edges = new Map<string, readonly EvaluatedImport[]>();
|
|
42
|
+
|
|
43
|
+
async function edgesOf(path: string): Promise<readonly EvaluatedImport[]> {
|
|
44
|
+
const known = edges.get(path);
|
|
45
|
+
if (known !== undefined) return known;
|
|
46
|
+
if (!CODE.test(path)) return [];
|
|
47
|
+
// Unreadable (a builtin, an asset Bun resolves elsewhere): no edge, as an unparseable file has.
|
|
48
|
+
const source = await Bun.file(path)
|
|
49
|
+
.text()
|
|
50
|
+
.catch(() => '');
|
|
51
|
+
const found = importedSpecifiers(path, source, 'evaluated').map(
|
|
52
|
+
(specifier): EvaluatedImport => {
|
|
53
|
+
let resolved: { readonly path: string | undefined } | undefined;
|
|
54
|
+
return {
|
|
55
|
+
from: path,
|
|
56
|
+
specifier,
|
|
57
|
+
target() {
|
|
58
|
+
resolved ??= { path: resolveImport(specifier, path) };
|
|
59
|
+
return resolved.path;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
edges.set(path, found);
|
|
65
|
+
return found;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
async walk(starts, judge) {
|
|
70
|
+
const via = new Map<string, EvaluatedImport | undefined>(
|
|
71
|
+
starts.map((start): [string, undefined] => [start, undefined]),
|
|
72
|
+
);
|
|
73
|
+
const reached = [...via.keys()];
|
|
74
|
+
walking: for (const path of reached) {
|
|
75
|
+
for (const edge of await edgesOf(path)) {
|
|
76
|
+
const verdict = judge(edge);
|
|
77
|
+
if (verdict === 'skip') continue;
|
|
78
|
+
const target = edge.target();
|
|
79
|
+
if (target !== undefined && !via.has(target)) {
|
|
80
|
+
via.set(target, edge);
|
|
81
|
+
reached.push(target);
|
|
82
|
+
}
|
|
83
|
+
if (verdict === 'stop') break walking;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
chainTo(path) {
|
|
88
|
+
if (!via.has(path)) return [];
|
|
89
|
+
const chain: ChainStep[] = [];
|
|
90
|
+
for (let at: string | undefined = path; at !== undefined; ) {
|
|
91
|
+
const edge: EvaluatedImport | undefined = via.get(at);
|
|
92
|
+
chain.push({
|
|
93
|
+
path: at,
|
|
94
|
+
...(edge === undefined ? {} : { specifier: edge.specifier }),
|
|
95
|
+
});
|
|
96
|
+
at = edge?.from;
|
|
97
|
+
}
|
|
98
|
+
return chain.reverse();
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
package/src/exercise-services.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// The runtime services a server's boot installs (`runtime-services.ts`) that `x exercise` stands in
|
|
2
|
-
// for: a storage disk, a fleet-wide rate-limit store
|
|
3
|
-
// scratch database. Without them every primitive reading one stopped on a boot-only refusal and
|
|
2
|
+
// for: a storage disk, a fleet-wide rate-limit store, the fleet-wide auth limiter and the Web Push
|
|
3
|
+
// runtime, over the pass's scratch database. Without them every primitive reading one stopped on a boot-only refusal and
|
|
4
4
|
// the app had to declare `{ off }` for it — the pass's job, not the app's.
|
|
5
5
|
|
|
6
|
+
import { postgresAuthLimiter } from '@ultimat3/auth';
|
|
7
|
+
import { installAuthLimiters } from '@ultimat3/auth/adapter';
|
|
6
8
|
import type { AppConfig, PgExecutor } from '@ultimat3/core';
|
|
7
|
-
import { ENVIRONMENT_KEY } from '@ultimat3/core';
|
|
9
|
+
import { ENVIRONMENT_KEY, systemClock } from '@ultimat3/core';
|
|
8
10
|
import { postgresRateLimitStore } from '@ultimat3/http';
|
|
9
11
|
import { installRateLimitStore } from '@ultimat3/http/adapter';
|
|
10
12
|
import {
|
|
@@ -76,6 +78,14 @@ export async function installExerciseServices(inputs: ExerciseServiceInputs): Pr
|
|
|
76
78
|
// `scope: 'shared'`, as the boot's: a `rateLimit: { scope: 'shared' }` declaration is judged
|
|
77
79
|
// against the installed store, and one process' memory refused it with X_RATE_LIMIT_NOT_SHARED.
|
|
78
80
|
released.push(installRateLimitStore(postgresRateLimitStore({ executor: inputs.executor })));
|
|
81
|
+
// The boot's auth limiter for the same reason: `defineAuth({ rateLimit: { scope: 'shared' } })`
|
|
82
|
+
// judged against one process' memory refused every action that reserves an attempt with
|
|
83
|
+
// X_AUTH_LIMITER_NOT_SHARED. Built per declared policy, over the scratch `x_auth_lockouts`.
|
|
84
|
+
released.push(
|
|
85
|
+
installAuthLimiters((policy) =>
|
|
86
|
+
postgresAuthLimiter({ executor: inputs.executor, clock: systemClock, policy }),
|
|
87
|
+
),
|
|
88
|
+
);
|
|
79
89
|
// Last, and the one that can refuse (a half VAPID pair): what is already in is undone first.
|
|
80
90
|
released.push(await installPush(inputs));
|
|
81
91
|
} catch (error) {
|
package/src/framework-schema.ts
CHANGED
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
// A framework table an app has to install by hand is a table that will be missing in production on
|
|
7
7
|
// the one code path that needs it, and it surfaces as a Postgres `42P01` from inside a worker.
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
SQL_AUDIT_TABLE,
|
|
11
|
+
SQL_IDEMPOTENCY_TABLE,
|
|
12
|
+
SQL_METER_KEY_TABLE,
|
|
13
|
+
SQL_METER_TABLE,
|
|
14
|
+
} from '@ultimat3/action';
|
|
10
15
|
import {
|
|
11
16
|
ADMIN_AUDIT_TABLE,
|
|
12
17
|
ERROR_GROUPS_TABLE,
|
|
@@ -100,12 +105,17 @@ export const FRAMEWORK_SCHEMA: readonly FrameworkSchema[] = Object.freeze([
|
|
|
100
105
|
tables: Object.freeze(['x_audit']),
|
|
101
106
|
ddl: Object.freeze([SQL_AUDIT_TABLE]),
|
|
102
107
|
}),
|
|
103
|
-
// The counters behind `meter
|
|
104
|
-
// place, so it ships no purge: the table is bounded by its subjects, never by
|
|
108
|
+
// The counters behind `meter:` and `drawMeter`. One row per tenant × meter × period declaration,
|
|
109
|
+
// rolled over in place, so it ships no purge: the table is bounded by its subjects, never by
|
|
110
|
+
// time. `x_meter_key` holds one row per counted keyed draw, about two periods of them per active
|
|
111
|
+
// counter: a keyed draw that counts prunes its counter's older rows, and an idle counter keeps
|
|
112
|
+
// its last rows until its next one.
|
|
113
|
+
// `SQL_METER_KEY_TABLE` also creates `x_meter_key_counted`, the function a refused keyed draw
|
|
114
|
+
// reads its key through: not a table, so it is in no `tables` list.
|
|
105
115
|
Object.freeze({
|
|
106
116
|
pkg: '@ultimat3/action',
|
|
107
|
-
tables: Object.freeze(['x_meter']),
|
|
108
|
-
ddl: Object.freeze([SQL_METER_TABLE]),
|
|
117
|
+
tables: Object.freeze(['x_meter', 'x_meter_key']),
|
|
118
|
+
ddl: Object.freeze([SQL_METER_TABLE, SQL_METER_KEY_TABLE]),
|
|
109
119
|
}),
|
|
110
120
|
Object.freeze({
|
|
111
121
|
pkg: '@ultimat3/http',
|
package/src/guard-sources.ts
CHANGED
|
@@ -90,9 +90,8 @@ export function guardSources(
|
|
|
90
90
|
const source = await textOf(path);
|
|
91
91
|
// Imported here, not at the top: Sass loads on the first compile, and a gate run whose
|
|
92
92
|
// guards compile nothing must not pay for the compiler (`sass-lazy.test.ts`).
|
|
93
|
-
const { compileStylesheet } = await import('@ultimat3/render/server');
|
|
93
|
+
const { compileStylesheet, siteAssetTable } = await import('@ultimat3/render/server');
|
|
94
94
|
const { setAssetResolver } = await import('@ultimat3/render');
|
|
95
|
-
const { siteAssetTable } = await import('./site-assets');
|
|
96
95
|
// A sheet's `asset()` resolves through the table `loadApp` installs for the build — the same
|
|
97
96
|
// table, so a file the app holds compiles and one it does not is `X_ASSET_MISSING`. Installed
|
|
98
97
|
// around the one synchronous compile and handed back after: no await runs in between, so no
|
package/src/index.ts
CHANGED
|
@@ -109,6 +109,8 @@ export type { NewShape } from './new-shapes';
|
|
|
109
109
|
export { NEW_SHAPES } from './new-shapes';
|
|
110
110
|
export type { CommandResult, Finding, JsonValue } from './output';
|
|
111
111
|
export { exitCodeFor, findingFrom, render, renderFinding, renderHuman } from './output';
|
|
112
|
+
export type { PageRouteOptions } from './page-route';
|
|
113
|
+
export { pageRoute } from './page-route';
|
|
112
114
|
export type { CommandSpec, FlagSpec, ParsedArgs } from './parse';
|
|
113
115
|
export { flagBool, flagList, flagString, GLOBAL_FLAGS, parseArgs } from './parse';
|
|
114
116
|
export type { PrerenderedPage, PrerenderReport } from './prerender';
|
package/src/mcp-errors.ts
CHANGED
|
@@ -297,7 +297,7 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
297
297
|
X_BOUNDARY_PACKAGE_TO_APP:
|
|
298
298
|
'x verify --only boundaries --json # after moving the shared code into the package, or importing in the opposite direction',
|
|
299
299
|
X_APP_IMPORT_UNRESOLVED:
|
|
300
|
-
'x doctor --json # names the
|
|
300
|
+
'x doctor --json # names the app module, and the install or the edit that clears it',
|
|
301
301
|
X_STREAM_ALREADY_FLUSHED:
|
|
302
302
|
'load: async () => { setCookie(name, value); return data; }, // in defineRoute, never inside a Hole',
|
|
303
303
|
X_QUERY_SLICE_ENTITY:
|
|
@@ -393,6 +393,8 @@ const CLI_FIXES: Readonly<Record<CliErrorCode, string>> = {
|
|
|
393
393
|
// raised error's own `fix:` carries the named invocation; `ULTIMATE_TASK_RUN` stays in the cause.
|
|
394
394
|
X_TASK_RUN_PRODUCTION:
|
|
395
395
|
'x tasks list --json # then name the task: x tasks run <name> --production --json',
|
|
396
|
+
X_BOUNDARY_DEV_IMPORT:
|
|
397
|
+
'x verify --only boundaries --json # names the module and its import: move test support to apps/web/test/, which no role loads, or drop the import from a module a role needs',
|
|
396
398
|
};
|
|
397
399
|
|
|
398
400
|
const isCliCode = (code: string): code is CliErrorCode =>
|
package/src/messages-upgrade.ts
CHANGED
|
@@ -46,6 +46,10 @@ export const UPGRADE_MESSAGES = {
|
|
|
46
46
|
'guard not installed, its findings could not be counted — yours to take: {fix}',
|
|
47
47
|
'cli.upgrade.coverage':
|
|
48
48
|
'coverage floor: {file} {fromLines} / {fromFuncs} -> {toLines} / {toFuncs}, measured {lines}% / {funcs}% after the Bun floor moved — review the why',
|
|
49
|
+
'cli.upgrade.coverageRaised':
|
|
50
|
+
"coverage floor raised: {file} {fromLines} / {fromFuncs} -> {toLines} / {toFuncs}, measured {lines}% / {funcs}% by this hop's unit run (X_COVERAGE_FLOOR_STALE) — it may only rise",
|
|
51
|
+
'cli.upgrade.coverageRejudged':
|
|
52
|
+
'{summary}; the coverage floor rose to what unit measured, and unit re-run: {unit}',
|
|
49
53
|
'cli.upgrade.exerciseFloor':
|
|
50
54
|
'exercise floor: {file} "exercise" {figures}, measured by this hop\'s x exercise — it may only fall',
|
|
51
55
|
'cli.upgrade.coverage.unpinned': 'no engines.bun',
|
package/src/module-imports.ts
CHANGED
|
@@ -20,28 +20,39 @@ const transpilers = {
|
|
|
20
20
|
tsx: new Bun.Transpiler({ loader: 'tsx' }),
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
/** Every specifier `source` names, as written and in source order. Unparseable: it names none yet. */
|
|
24
|
+
export function importedSpecifiers(
|
|
25
|
+
path: string,
|
|
26
|
+
source: string,
|
|
27
|
+
edges: ImportEdges,
|
|
28
|
+
): readonly string[] {
|
|
28
29
|
const transpiler = path.endsWith('x') ? transpilers.tsx : transpilers.ts;
|
|
29
|
-
let specifiers: readonly { readonly path: string; readonly kind: string }[];
|
|
30
30
|
try {
|
|
31
|
-
|
|
31
|
+
const imports =
|
|
32
32
|
edges === 'referenced'
|
|
33
33
|
? transpiler.scanImports(source)
|
|
34
34
|
: transpiler.scan(source).imports.filter((one) => one.kind !== 'dynamic-import');
|
|
35
|
+
return imports.map((one) => one.path);
|
|
35
36
|
} catch {
|
|
36
37
|
return [];
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The file `specifier` is from `path`, as Bun resolves it — `undefined` when it resolves to none. */
|
|
42
|
+
export function resolveImport(specifier: string, path: string): string | undefined {
|
|
43
|
+
try {
|
|
44
|
+
return Bun.resolveSync(specifier, dirname(path));
|
|
45
|
+
} catch {
|
|
46
|
+
return undefined;
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Absolute paths, in source order. A file that will not parse imports nothing yet, and a
|
|
52
|
+
* specifier that will not resolve contributes no edge: the module's own import reports both.
|
|
53
|
+
*/
|
|
54
|
+
export function resolvedImports(path: string, source: string, edges: ImportEdges): string[] {
|
|
55
|
+
return importedSpecifiers(path, source, edges).flatMap(
|
|
56
|
+
(specifier) => resolveImport(specifier, path) ?? [],
|
|
57
|
+
);
|
|
47
58
|
}
|
package/src/page-navigation.ts
CHANGED
|
@@ -75,7 +75,9 @@ export async function loadNavigation(root: string): Promise<NavigationDeclaratio
|
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* A page declaring `navigation` on a surface with no client navigation says something no process
|
|
78
|
-
* can honour — refused at boot, before a single request, for every route in the table.
|
|
78
|
+
* can honour — refused at boot, before a single request, for every route in the table. Except
|
|
79
|
+
* `'document'`: it asks for a real document load, which is what every page of such a surface
|
|
80
|
+
* already gets, so it is honoured there as declared.
|
|
79
81
|
*/
|
|
80
82
|
export function assertRouteNavigation(
|
|
81
83
|
surfaces: readonly NavigationSurface[],
|
|
@@ -83,7 +85,8 @@ export function assertRouteNavigation(
|
|
|
83
85
|
): void {
|
|
84
86
|
for (const entry of entries) {
|
|
85
87
|
const mode = navigationModeOf(entry.config.navigation);
|
|
86
|
-
if (mode === undefined ||
|
|
88
|
+
if (mode === undefined || mode === 'document') continue;
|
|
89
|
+
if (surfaces.some((surface) => surface === entry.surface)) continue;
|
|
87
90
|
throw new RouteNavigationInvalidError(
|
|
88
91
|
`${entry.file} declares navigation: '${mode}', and its surface (${entry.surface}) is not in app.config.ts navigation.client`,
|
|
89
92
|
);
|