@ultimat3/cli 30.9.0 → 31.1.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 +80 -64
- package/README.md +4 -1
- package/package.json +30 -29
- package/src/admin-registration.ts +1 -1
- package/src/affected-base.ts +51 -0
- package/src/affected.ts +34 -11
- package/src/app-boundaries.ts +88 -9
- package/src/app-load-async.ts +133 -0
- package/src/app-load-batch.ts +203 -0
- package/src/app-load-prebuilt.ts +147 -0
- package/src/app-load-register.ts +175 -0
- package/src/app-load.ts +143 -175
- package/src/app-loader-imports.ts +31 -0
- package/src/app-root.ts +13 -0
- package/src/app-runtime.ts +5 -1
- package/src/boundary-findings.ts +12 -0
- package/src/browser-launcher-port.ts +3 -7
- package/src/browser-launcher.ts +1 -1
- package/src/budgets-scan.ts +8 -0
- package/src/budgets.ts +10 -1
- package/src/build-registry-background.ts +59 -0
- package/src/build-registry.ts +207 -0
- package/src/cdp-shot-clock.ts +3 -11
- package/src/cdp-shot-driver.ts +3 -2
- package/src/cdp-shot-element.ts +3 -2
- package/src/cdp-shot-page.ts +2 -2
- package/src/cdp-shot-watch.ts +4 -3
- package/src/ci-log.ts +76 -13
- package/src/cmd-affected-spec.ts +7 -3
- package/src/cmd-affected.ts +91 -77
- package/src/cmd-auth.ts +3 -3
- package/src/cmd-ci.ts +6 -3
- package/src/cmd-db-recount.ts +15 -0
- package/src/cmd-drill.ts +10 -6
- package/src/cmd-exercise.ts +2 -1
- package/src/cmd-generate-spec.ts +6 -0
- package/src/cmd-generate.ts +22 -4
- package/src/cmd-mail.ts +1 -1
- package/src/cmd-pr-spec.ts +1 -1
- package/src/cmd-pr.ts +72 -1
- package/src/cmd-routes.ts +2 -2
- package/src/cmd-secrets-spec.ts +4 -1
- package/src/cmd-shot.ts +14 -262
- package/src/cmd-test-spec.ts +2 -2
- package/src/cmd-verify-spec.ts +21 -1
- package/src/cmd-verify.ts +16 -4
- package/src/coverage-source.ts +4 -1
- package/src/db-diagnostics.ts +8 -1
- package/src/dev-boot.ts +29 -15
- package/src/dev-dashboard-invalidations.ts +43 -0
- package/src/dev-dashboard.ts +13 -16
- package/src/dev-n-plus-one.ts +7 -3
- package/src/dev-rebuild.ts +2 -1
- package/src/dev-route-table.ts +1 -1
- package/src/dev-traces.ts +16 -15
- package/src/document-options.ts +12 -1
- package/src/drift-store.ts +55 -0
- package/src/error-catalog.ts +8 -3
- package/src/error-codes-boundary.ts +32 -0
- package/src/error-codes-package.ts +38 -0
- package/src/error-codes.ts +28 -40
- package/src/errors.ts +17 -7
- package/src/exercise-database.ts +13 -1
- package/src/exercise-findings.ts +36 -18
- package/src/exercise-services.ts +84 -0
- package/src/exercise-subject.ts +38 -13
- package/src/failure-capture-boot.ts +9 -5
- package/src/framework-schema.ts +5 -5
- package/src/generate-exercise.ts +1 -1
- package/src/generate-files.ts +27 -7
- package/src/generate-kinds.ts +5 -0
- package/src/generate-refresh.ts +53 -0
- package/src/generate-workspace.ts +169 -0
- package/src/generate-write.ts +8 -2
- package/src/hold.ts +19 -8
- package/src/image-prepare.ts +6 -2
- package/src/index.ts +5 -20
- package/src/island-bundle.ts +7 -3
- package/src/island-capture.ts +2 -2
- package/src/island-harness.ts +1 -1
- package/src/job-registration.ts +43 -6
- package/src/jobs-driver.ts +4 -5
- package/src/mcp-errors.ts +20 -4
- package/src/mcp-host.ts +5 -1
- package/src/mcp-ui-interact.ts +3 -0
- package/src/messages-gate.ts +10 -0
- package/src/new-shapes-generate.ts +1 -1
- package/src/otlp-export.ts +94 -29
- package/src/output.ts +24 -10
- package/src/page-sync.ts +3 -1
- package/src/pr-activity.ts +150 -0
- package/src/pr-bots.ts +109 -0
- package/src/pr-threads.ts +7 -2
- package/src/role-load.ts +17 -11
- package/src/role-start.ts +5 -4
- package/src/role-sync.ts +7 -8
- package/src/route-islands-preload.ts +46 -0
- package/src/route-islands.ts +6 -2
- package/src/runtime-admin.ts +5 -1
- package/src/runtime-bindings.ts +25 -19
- package/src/runtime-boot-ports.ts +66 -0
- package/src/runtime-bus.ts +29 -5
- package/src/runtime-cache-bus.ts +53 -0
- package/src/runtime-cache.ts +43 -13
- package/src/runtime-isr-outcome.ts +5 -4
- package/src/runtime-jobs.ts +2 -2
- package/src/runtime-keys.ts +37 -0
- package/src/runtime-overrides.ts +148 -42
- package/src/runtime-port-bindings-queue.ts +36 -0
- package/src/runtime-port-bindings.ts +117 -0
- package/src/runtime-ports.ts +164 -0
- package/src/runtime-purge.ts +41 -28
- package/src/runtime-push.ts +7 -3
- package/src/runtime-queue.ts +70 -55
- package/src/runtime-realtime.ts +5 -5
- package/src/runtime-render-document.ts +4 -1
- package/src/runtime-services.ts +110 -158
- package/src/runtime-storage-boot.ts +111 -0
- package/src/runtime-storage-upload.ts +9 -7
- package/src/runtime-storage.ts +7 -1
- package/src/serve-boot.ts +8 -4
- package/src/serve-entry.ts +3 -0
- package/src/serve-env.ts +47 -14
- package/src/serve-prebuilt-paths.ts +3 -0
- package/src/serve-prebuilt.ts +15 -4
- package/src/serve.ts +2 -2
- package/src/shot-gpu.ts +61 -0
- package/src/shot-route.ts +95 -0
- package/src/shot-run.ts +189 -0
- package/src/shot-verdict.ts +5 -0
- package/src/static-cards.ts +3 -2
- package/src/static-report.ts +2 -2
- package/src/style-bundle.ts +1 -1
- package/src/sync-authenticator.ts +17 -18
- package/src/templates/action-tests.ts +4 -4
- package/src/templates/backfill.ts +5 -8
- package/src/templates/entity.ts +3 -0
- package/src/templates/github/ci.yml.ts +3 -1
- package/src/templates/github/dependabot.yml.ts +73 -0
- package/src/templates/job.ts +13 -22
- package/src/templates/naming.ts +20 -1
- package/src/templates/pinned/docker-compose.yml +1 -1
- package/src/templates/query.ts +7 -8
- package/src/templates/route.ts +5 -3
- package/src/templates/scaffold-api.ts +1 -1
- package/src/templates/scaffold-auth.ts +5 -3
- package/src/templates/scaffold-claude-commands.ts +6 -3
- package/src/templates/scaffold-claude.ts +4 -4
- package/src/templates/scaffold-container-compose.ts +2 -4
- package/src/templates/scaffold-domain-package.ts +1 -1
- package/src/templates/scaffold-entries.ts +6 -1
- package/src/templates/scaffold-helm-fences.ts +3 -2
- package/src/templates/scaffold-helm.ts +35 -6
- package/src/templates/scaffold-repo.ts +47 -135
- package/src/templates/scaffold-runtime-ports.ts +62 -0
- package/src/templates/scaffold-verify-floor.ts +97 -0
- package/src/templates/shapes/overlay.ts +1 -1
- package/src/templates/sign-in-oidc.ts +5 -3
- package/src/templates/sign-in-shared.ts +28 -10
- package/src/templates/workspace.ts +75 -0
- package/src/test-ignores.ts +5 -2
- package/src/test-select.ts +4 -1
- package/src/tsconfig-aliases.ts +85 -0
- package/src/upgrade-gate.ts +30 -5
- package/src/upgrade-report.ts +7 -1
- package/src/verify-changed-facts.ts +53 -0
- package/src/verify-changed-scope.ts +162 -0
- package/src/verify-changed.ts +174 -0
- package/src/verify-checks.ts +33 -19
- package/src/verify-drift-owner.ts +30 -0
- package/src/verify-e2e.ts +2 -1
- package/src/verify-factories.ts +86 -0
- package/src/verify-run.ts +13 -11
- package/src/verify-step.ts +13 -0
- package/src/verify-tests.ts +58 -6
- package/src/workspace-external-deps.ts +164 -0
- package/src/write-line.ts +21 -6
- package/wiki/Actions.md +2 -2
- package/wiki/Adapters.md +400 -0
- package/wiki/Admin-Dashboard.md +1 -1
- package/wiki/Agents.md +9 -9
- package/wiki/Auth.md +78 -2
- package/wiki/Building-Your-Own-Base.md +1 -1
- package/wiki/CLI-Reference.md +45 -14
- package/wiki/Caching-And-Invalidation.md +17 -5
- package/wiki/Compared.md +8 -2
- package/wiki/Configuration.md +14 -14
- package/wiki/Deployment.md +28 -1
- package/wiki/Entities-And-Migrations.md +47 -1
- package/wiki/FAQ.md +8 -2
- package/wiki/Feature-Flags.md +1 -1
- package/wiki/Home.md +3 -2
- package/wiki/Jobs-And-Workflows.md +107 -6
- package/wiki/Known-Gaps.md +4 -3
- package/wiki/MCP-And-AI.md +18 -4
- package/wiki/Mail.md +14 -5
- package/wiki/Migrations-And-Backfills.md +29 -4
- package/wiki/Money.md +2 -0
- package/wiki/N-Plus-One-Detection.md +24 -22
- package/wiki/Notify.md +28 -4
- package/wiki/Observability.md +121 -15
- package/wiki/Queries-And-Live-Queries.md +2 -2
- package/wiki/Realtime.md +9 -4
- package/wiki/Routes-And-Render-Modes.md +5 -0
- package/wiki/Scraping.md +57 -11
- package/wiki/Shapes.md +2 -2
- package/wiki/Stability.md +7 -5
- package/wiki/Storage-And-Uploads.md +56 -4
- package/wiki/Testing.md +65 -52
- package/wiki/Troubleshooting.md +1 -1
- package/wiki/Tutorial-01-First-App.md +1 -1
- package/wiki/Tutorial-04-Jobs-And-Realtime.md +1 -1
- package/wiki/Tutorial-05-Deploy-Free.md +1 -1
- package/wiki/Tutorial-06-Growing-Up.md +8 -8
- package/wiki/Upgrading.md +136 -5
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The `drift` step's ownership rail: one repository is ONE app — one `app.config.ts` at the root,
|
|
2
|
+
// one registry every `apps/*` workspace boots into, one image whose `ROLE` picks the process, one
|
|
3
|
+
// `packages/db/migrations`. A second `app.config.ts` inside a workspace makes `x` treat that
|
|
4
|
+
// directory as its own root (its own migrations, its own image), so it is refused here by code.
|
|
5
|
+
|
|
6
|
+
import { ERROR_DOCS_URL } from '@ultimat3/core';
|
|
7
|
+
import { commentSafe } from './comment-safe';
|
|
8
|
+
import type { Finding } from './output';
|
|
9
|
+
import { hasPathSegment } from './path-segments';
|
|
10
|
+
import { toPosix } from './posix-path';
|
|
11
|
+
|
|
12
|
+
const NESTED_CONFIG = '{apps,packages}/**/app.config.ts';
|
|
13
|
+
|
|
14
|
+
/** Every `app.config.ts` below `apps/` or `packages/`, sorted, never a dependency's. */
|
|
15
|
+
export async function nestedAppRootFindings(root: string): Promise<readonly Finding[]> {
|
|
16
|
+
const found: string[] = [];
|
|
17
|
+
for await (const path of new Bun.Glob(NESTED_CONFIG).scan({ cwd: root, absolute: false })) {
|
|
18
|
+
if (!hasPathSegment(path, 'node_modules')) found.push(toPosix(path));
|
|
19
|
+
}
|
|
20
|
+
return found.sort().map((path) => {
|
|
21
|
+
const workspace = path.slice(0, -'/app.config.ts'.length);
|
|
22
|
+
return {
|
|
23
|
+
code: 'X_APP_ROOT_NESTED',
|
|
24
|
+
cause: `${path} makes ${workspace} a second app root — its own registry, migrations and image. One repository is one app: every apps/* workspace boots in the one image (ROLE picks the process) and packages/db/migrations is the one migration owner`,
|
|
25
|
+
fix: `x verify --only drift --json # after deleting ${commentSafe(path)} and moving what it configured into the root app.config.ts`,
|
|
26
|
+
docs: ERROR_DOCS_URL,
|
|
27
|
+
at: path,
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
package/src/verify-e2e.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
// app: the suite runs as before and its browser-backed cases skip — or refuse under
|
|
5
5
|
// `E2E_BROWSER_REQUIRED=1`.
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { findChrome } from '@ultimat3/scraping/cdp';
|
|
8
|
+
import { E2E_ROOT_ENV } from '@ultimat3/testing';
|
|
8
9
|
import type { ExecResult } from './exec';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// The factory lint on the `unit` step: an app's `packages/db/factories.ts` exports `factories`, and
|
|
2
|
+
// every factory — bare and with each trait — must build a row its entity accepts and create one it
|
|
3
|
+
// stores (`@ultimat3/testing`'s `lintFactories`). No file is no factories: the step says nothing.
|
|
4
|
+
|
|
5
|
+
// why: a synchronous exists check decides whether the child is spawned at all.
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
// why: Bun exposes no path-join primitive.
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { ERROR_DOCS_URL } from '@ultimat3/core';
|
|
10
|
+
import type { Infer } from '@ultimat3/schema';
|
|
11
|
+
import { parse, t } from '@ultimat3/schema';
|
|
12
|
+
import type { Runner } from './exec';
|
|
13
|
+
import type { Finding } from './output';
|
|
14
|
+
|
|
15
|
+
/** The one place an app's factories live. One convention, so the gate can find them. */
|
|
16
|
+
export const FACTORIES_FILE = 'packages/db/factories.ts';
|
|
17
|
+
/** The export that file makes: a `FactorySet` (`Record<name, factory>`). */
|
|
18
|
+
export const FACTORIES_EXPORT = 'factories';
|
|
19
|
+
|
|
20
|
+
const CODE = 'X_TEST_FACTORY_INVALID';
|
|
21
|
+
|
|
22
|
+
const findingSchema = t.object({
|
|
23
|
+
factory: t.string,
|
|
24
|
+
trait: t.nullable(t.string),
|
|
25
|
+
strategy: t.string,
|
|
26
|
+
code: t.string,
|
|
27
|
+
cause: t.string,
|
|
28
|
+
});
|
|
29
|
+
const reportSchema = t.array(findingSchema);
|
|
30
|
+
type LintFinding = Infer<typeof findingSchema>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Run in a CHILD, from the app's root: the factories and `lintFactories` must share the app's own
|
|
34
|
+
* copy of `@ultimat3/testing` (the persister slot is module state), and the app's entities must not
|
|
35
|
+
* register into this process's registries. The last stdout line is the report.
|
|
36
|
+
*/
|
|
37
|
+
const SCRIPT = `const mod = await import(\`\${process.cwd()}/${FACTORIES_FILE}\`);
|
|
38
|
+
const set = mod[${JSON.stringify(FACTORIES_EXPORT)}];
|
|
39
|
+
if (typeof set !== 'object' || set === null) {
|
|
40
|
+
console.log(JSON.stringify([{ factory: '*', trait: null, strategy: 'build', code: '${CODE}', cause: '${FACTORIES_FILE} exports no ${FACTORIES_EXPORT} object' }]));
|
|
41
|
+
} else {
|
|
42
|
+
const { lintFactories } = await import('@ultimat3/testing');
|
|
43
|
+
console.log(JSON.stringify(await lintFactories(set)));
|
|
44
|
+
}`;
|
|
45
|
+
|
|
46
|
+
const label = (finding: LintFinding): string =>
|
|
47
|
+
`${finding.factory}${finding.trait === null ? '' : `.with('${finding.trait}')`}.${finding.strategy}()`;
|
|
48
|
+
|
|
49
|
+
/** One finding per factory × trait × strategy, each naming what to edit. */
|
|
50
|
+
export const factoryFinding = (finding: LintFinding): Finding => ({
|
|
51
|
+
code: CODE,
|
|
52
|
+
cause: `${label(finding)} is refused: ${finding.code} — ${finding.cause}`,
|
|
53
|
+
// A code shape to paste into the file, opened by what to change — never a sentence (`fix-prose`).
|
|
54
|
+
fix:
|
|
55
|
+
finding.trait === null
|
|
56
|
+
? `defaults: (n, ids) => ({ /* every column ${finding.factory}'s entity requires, valid */ }) // factory "${finding.factory}" in ${FACTORIES_FILE}`
|
|
57
|
+
: `traits: { ${JSON.stringify(finding.trait)}: { /* only columns the entity declares, valid */ } } // factory "${finding.factory}" in ${FACTORIES_FILE}`,
|
|
58
|
+
docs: ERROR_DOCS_URL,
|
|
59
|
+
at: FACTORIES_FILE,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/** The child's last stdout line, parsed — or one finding saying the file would not load. */
|
|
63
|
+
function readReport(stdout: string, stderr: string): readonly LintFinding[] {
|
|
64
|
+
const last = stdout.trim().split('\n').at(-1) ?? '';
|
|
65
|
+
try {
|
|
66
|
+
return parse(reportSchema, JSON.parse(last));
|
|
67
|
+
} catch {
|
|
68
|
+
const reason = stderr.trim().split('\n').slice(-3).join(' ') || 'no report was printed';
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
factory: '*',
|
|
72
|
+
trait: null,
|
|
73
|
+
strategy: 'build',
|
|
74
|
+
code: CODE,
|
|
75
|
+
cause: `${FACTORIES_FILE} did not load: ${reason}`,
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The lint's findings for the app at `root`; none when it keeps no factories file. */
|
|
82
|
+
export async function factoryFindings(root: string, runner: Runner): Promise<readonly Finding[]> {
|
|
83
|
+
if (!existsSync(join(root, FACTORIES_FILE))) return [];
|
|
84
|
+
const result = await runner(['bun', '--eval', SCRIPT], { cwd: root });
|
|
85
|
+
return readReport(result.stdout, result.stderr).map(factoryFinding);
|
|
86
|
+
}
|
package/src/verify-run.ts
CHANGED
|
@@ -79,17 +79,19 @@ export async function runVerify(
|
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
const began = performance.now();
|
|
82
|
-
// The static steps wait for the serial suites and then run BESIDE
|
|
83
|
-
//
|
|
84
|
-
|
|
82
|
+
// The static steps wait for the serial suites and then run BESIDE the first one listed: `live`
|
|
83
|
+
// in a whole gate, `eval` in CI's static part (the `live` shards may name no other step). A list
|
|
84
|
+
// with no serial suite — a one-step `--only` among them — keeps declared order.
|
|
85
85
|
// The second serial lane (`verify-e2e-lane.ts`): `e2e` beside `live`, its children stripped of
|
|
86
|
-
// every service URL, in a package monorepo only.
|
|
87
|
-
const e2eLane =
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
// every service URL, in a package monorepo only — so only when `live` is listed.
|
|
87
|
+
const e2eLane = selected.some((step) => step.name === SERIAL_SUITES[0]) && e2eBesideLive(ctx);
|
|
88
|
+
const grouped = selected.filter(
|
|
89
|
+
(step) => BESIDE_SERIAL_SUITES.has(step.name) || (e2eLane && step.name === 'e2e'),
|
|
90
|
+
);
|
|
91
|
+
const anchor = selected.find(
|
|
92
|
+
(step) => SERIAL_SUITES.includes(step.name) && !grouped.includes(step),
|
|
93
|
+
);
|
|
94
|
+
const beside = anchor === undefined ? [] : grouped;
|
|
93
95
|
let pending: Promise<void> | undefined;
|
|
94
96
|
const join = async (): Promise<void> => {
|
|
95
97
|
await pending;
|
|
@@ -105,7 +107,7 @@ export async function runVerify(
|
|
|
105
107
|
const shared: VerifyContext = base;
|
|
106
108
|
for (const step of selected) {
|
|
107
109
|
if (beside.includes(step)) continue;
|
|
108
|
-
if (step
|
|
110
|
+
if (step === anchor) {
|
|
109
111
|
pending = Promise.all(
|
|
110
112
|
beside.map((other) => run(other, other.name === 'e2e' ? besideLive(base) : base)),
|
|
111
113
|
).then(() => undefined);
|
package/src/verify-step.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// implementation can live beside the code it checks without importing the list.
|
|
4
4
|
|
|
5
5
|
import { ERROR_DOCS_URL } from '@ultimat3/core';
|
|
6
|
+
import type { AppTestScope } from './affected-tests';
|
|
6
7
|
import type { CoverageMap } from './coverage-lcov';
|
|
7
8
|
import type { ExecResult, Runner } from './exec';
|
|
8
9
|
import { execOutput } from './exec';
|
|
@@ -70,6 +71,12 @@ export type VerifyStepName = (typeof VERIFY_STEP_NAMES)[number];
|
|
|
70
71
|
*/
|
|
71
72
|
export type HostCheck = (root: string) => Promise<readonly Finding[]>;
|
|
72
73
|
|
|
74
|
+
/** `VerifyContext.tests`: `x test --affected`'s selection, and the suites that run whole anyway. */
|
|
75
|
+
export interface ChangedTestSelection {
|
|
76
|
+
readonly scope: AppTestScope;
|
|
77
|
+
readonly whole: readonly VerifyStepName[];
|
|
78
|
+
}
|
|
79
|
+
|
|
73
80
|
export interface VerifyContext {
|
|
74
81
|
readonly root: string;
|
|
75
82
|
readonly runner: Runner;
|
|
@@ -114,6 +121,12 @@ export interface VerifyContext {
|
|
|
114
121
|
* name is accepted for the callers that narrow to one (`scripts/verify.ts`).
|
|
115
122
|
*/
|
|
116
123
|
readonly only?: VerifyStepName | readonly VerifyStepName[];
|
|
124
|
+
/**
|
|
125
|
+
* `x verify --changed`: each suite but `eval` and those in `whole` runs what `x test --affected`
|
|
126
|
+
* would (`narrowToApp` over `scope`: the closure's tests and every test the graph never read); a
|
|
127
|
+
* suite left nothing spawns nothing; the unit floor is not judged on a subset. Absent: every test.
|
|
128
|
+
*/
|
|
129
|
+
readonly tests?: ChangedTestSelection;
|
|
117
130
|
/**
|
|
118
131
|
* Per-step deadlines in milliseconds that beat `x.verify.json`'s `stepTimeoutMs`, which beat the
|
|
119
132
|
* step class's declared number (`verify-deadline.ts`). A step past its deadline fails by name
|
package/src/verify-tests.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { join } from 'node:path';
|
|
|
13
13
|
import { APP_CONFIG_FILE } from '@ultimat3/core';
|
|
14
14
|
import type { TestType } from '@ultimat3/testing';
|
|
15
15
|
import { TEST_TYPES } from '@ultimat3/testing';
|
|
16
|
+
import { narrowToApp } from './affected-tests';
|
|
16
17
|
import { checkEvalBaselines, checkEvalCoverage, checkEvalRecording } from './app-evals';
|
|
17
18
|
import { judgeCoverage } from './coverage-floor';
|
|
18
19
|
import { msg } from './messages';
|
|
@@ -27,11 +28,12 @@ import type { WorkerPlan } from './test-workers';
|
|
|
27
28
|
import { availableCpus, SERIAL_TYPES, totalMemory, workerPlan } from './test-workers';
|
|
28
29
|
import { runCovered } from './verify-coverage-run';
|
|
29
30
|
import { withE2eApp } from './verify-e2e';
|
|
31
|
+
import { factoryFindings } from './verify-factories';
|
|
30
32
|
import { readVerifyFloor } from './verify-floor';
|
|
31
33
|
import type { MachinePace } from './verify-pace';
|
|
32
34
|
import { DECLARED_PACE, defaultTimeoutArgs, pacedMs, paceEnv } from './verify-pace';
|
|
33
35
|
import { shardFiles } from './verify-shard';
|
|
34
|
-
import type { StepOutcome, VerifyContext, VerifyStep } from './verify-step';
|
|
36
|
+
import type { ChangedTestSelection, StepOutcome, VerifyContext, VerifyStep } from './verify-step';
|
|
35
37
|
import { fromExec, fromFindings } from './verify-step';
|
|
36
38
|
import { runParallel } from './verify-test-run';
|
|
37
39
|
|
|
@@ -150,6 +152,17 @@ const ignoreFlags = (patterns: readonly string[]): readonly string[] =>
|
|
|
150
152
|
export const typeFiltersOf = (type: Exclude<TestType, 'unit'>): readonly string[] =>
|
|
151
153
|
OWNERSHIP.filter(([owner]) => owner === type).map(([, filter]) => filter);
|
|
152
154
|
|
|
155
|
+
/**
|
|
156
|
+
* What an e2e test's path is, as globs: the e2e step's own substrings (`typeFiltersOf('e2e')`),
|
|
157
|
+
* each spelt as the glob matching the same paths. One definition, read three ways — the e2e step
|
|
158
|
+
* selects by the substrings, the unit step ignores these globs, and `scripts/coverage-gate.ts`
|
|
159
|
+
* leaves them out of a package's coverage: an e2e suite drives a built app through a browser and
|
|
160
|
+
* child processes no in-process lcov sees, and it already runs in its own gate step.
|
|
161
|
+
*/
|
|
162
|
+
export const E2E_PATH_GLOBS: readonly string[] = typeFiltersOf('e2e').map((filter) =>
|
|
163
|
+
filter.endsWith('/') ? `**/*${filter}**` : `**/*${filter}*`,
|
|
164
|
+
);
|
|
165
|
+
|
|
153
166
|
/**
|
|
154
167
|
* An e2e test's own budget: a first navigation waits on `x dev` compiling the route and its island,
|
|
155
168
|
* which bun's default 5 s does not cover — a timeout there reads as an app bug that is not one.
|
|
@@ -166,7 +179,7 @@ export const testStepCommand = (type: TestType, pace?: MachinePace): readonly st
|
|
|
166
179
|
'bun',
|
|
167
180
|
'test',
|
|
168
181
|
...defaultTimeoutArgs(pace),
|
|
169
|
-
...ignoreFlags([...NEVER_A_TEST,
|
|
182
|
+
...ignoreFlags([...NEVER_A_TEST, ...E2E_PATH_GLOBS, `**/*.${TYPED_SUFFIXES}.test.*`]),
|
|
170
183
|
]
|
|
171
184
|
: [
|
|
172
185
|
'bun',
|
|
@@ -245,9 +258,34 @@ const runSerial = async (
|
|
|
245
258
|
};
|
|
246
259
|
};
|
|
247
260
|
|
|
261
|
+
/**
|
|
262
|
+
* `--changed`'s selection, through `x test --affected`'s own rule (`narrowToApp`: a test the module
|
|
263
|
+
* graph never read is KEPT). Never for `eval` (its rules reach past its files) or a suite a doc
|
|
264
|
+
* selected (`whole`): those run every test.
|
|
265
|
+
*/
|
|
266
|
+
const selectionFor = (ctx: VerifyContext, type: TestType): ChangedTestSelection | undefined =>
|
|
267
|
+
ctx.tests === undefined || type === 'eval' || ctx.tests.whole.includes(type)
|
|
268
|
+
? undefined
|
|
269
|
+
: ctx.tests;
|
|
270
|
+
|
|
248
271
|
const runType = async (ctx: VerifyContext, type: TestType): Promise<StepOutcome> => {
|
|
249
|
-
|
|
250
|
-
|
|
272
|
+
const selected = selectionFor(ctx, type);
|
|
273
|
+
if (isSerial(type) && ctx.shard === undefined && selected === undefined) {
|
|
274
|
+
return runSerial(ctx, type);
|
|
275
|
+
}
|
|
276
|
+
const all = await filesFor(ctx.root, type);
|
|
277
|
+
const discoveredFiles =
|
|
278
|
+
selected === undefined ? all : narrowToApp(all, ctx.root, selected.scope).kept;
|
|
279
|
+
if (selected !== undefined) {
|
|
280
|
+
// No `tests` on the outcome: nothing was spawned, which is not a suite that ran zero tests.
|
|
281
|
+
if (discoveredFiles.length === 0) return { ok: true, findings: [], workers: 0 };
|
|
282
|
+
if (isSerial(type))
|
|
283
|
+
return runSerial(
|
|
284
|
+
ctx,
|
|
285
|
+
type,
|
|
286
|
+
discoveredFiles.map((file) => file.path),
|
|
287
|
+
);
|
|
288
|
+
}
|
|
251
289
|
// Under `--shard`, this job runs its slice and says which — `x verify merge` checks the slices.
|
|
252
290
|
// An EMPTY slice is a pass with zero tests, never the serial fallback below (which would run
|
|
253
291
|
// the whole type): the zero-tests floor is `merge`'s to apply, on the summed counts.
|
|
@@ -281,7 +319,8 @@ const runType = async (ctx: VerifyContext, type: TestType): Promise<StepOutcome>
|
|
|
281
319
|
: files.length < plan.workers
|
|
282
320
|
? `${String(files.length)} of ${plan.reason}`
|
|
283
321
|
: plan.reason;
|
|
284
|
-
|
|
322
|
+
// A subset cannot hold the whole tree's coverage floor: only a full unit run is judged.
|
|
323
|
+
if (type === 'unit' && isApp(ctx.root) && selected === undefined) {
|
|
285
324
|
return coveredUnit(ctx, {
|
|
286
325
|
files: files.map((file) => file.path),
|
|
287
326
|
workers,
|
|
@@ -409,12 +448,25 @@ const evalStep: VerifyStep = {
|
|
|
409
448
|
const summaryOf = (type: TypedTest): string =>
|
|
410
449
|
Object.hasOwn(SUMMARIES, type) ? SUMMARIES[type] : `${type} tests`;
|
|
411
450
|
|
|
451
|
+
/**
|
|
452
|
+
* The unit suite, and an app's factory lint beside it (`verify-factories.ts`): a factory that
|
|
453
|
+
* builds a row its entity refuses is a failing test in every file that uses it, found here once.
|
|
454
|
+
* Under `--shard` only slice 1 lints, so `x verify merge` reports each finding once.
|
|
455
|
+
*/
|
|
456
|
+
const unitStep = async (ctx: VerifyContext): Promise<StepOutcome> => {
|
|
457
|
+
const suite = await runType(ctx, 'unit');
|
|
458
|
+
if (!isApp(ctx.root) || (ctx.shard !== undefined && ctx.shard.index !== 1)) return suite;
|
|
459
|
+
const factories = await factoryFindings(ctx.root, ctx.runner);
|
|
460
|
+
if (factories.length === 0) return suite;
|
|
461
|
+
return { ...suite, ok: false, findings: [...factories, ...suite.findings] };
|
|
462
|
+
};
|
|
463
|
+
|
|
412
464
|
const stepFor = (type: TestType): VerifyStep => {
|
|
413
465
|
if (type === 'unit') {
|
|
414
466
|
return {
|
|
415
467
|
name: 'unit',
|
|
416
468
|
summary: 'pure logic — no database, no network',
|
|
417
|
-
run:
|
|
469
|
+
run: unitStep,
|
|
418
470
|
};
|
|
419
471
|
}
|
|
420
472
|
if (type === 'eval') return evalStep;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Every registry package a workspace's shipped source imports is declared in THAT workspace's own
|
|
2
|
+
// manifest. Bun hoists one copy to the root `node_modules`, so an import a sibling happens to declare
|
|
3
|
+
// resolves for `tsc`, `boundaries` and the tests alike — until a clean or filtered install stops
|
|
4
|
+
// hoisting it and CI breaks on a tree every step called green (`bitecs`, an adopter, v31).
|
|
5
|
+
|
|
6
|
+
// why: Bun has no native "is this specifier a runtime builtin" predicate; `bun` and `bun:*` included.
|
|
7
|
+
import { isBuiltin } from 'node:module';
|
|
8
|
+
import { join } from 'node:path'; // why: Bun exposes no path-join primitive.
|
|
9
|
+
import { ERROR_DOCS_URL, renderFixShellArg } from '@ultimat3/core';
|
|
10
|
+
import { scanRuntimeImports, stripShebang } from './import-scan';
|
|
11
|
+
import type { Finding } from './output';
|
|
12
|
+
import { FIXTURE_SUFFIX } from './publish-closure';
|
|
13
|
+
import { eachSourceFile, isGenerated, isTest } from './source-files';
|
|
14
|
+
import { tsconfigAliases } from './tsconfig-aliases';
|
|
15
|
+
import { importedPackages, packageOfSpecifier, scanWorkspaces } from './workspace-graph';
|
|
16
|
+
|
|
17
|
+
/** Every field a package manager installs from — the same four `workspace-graph` reads. */
|
|
18
|
+
const DEPENDENCY_FIELDS = [
|
|
19
|
+
'dependencies',
|
|
20
|
+
'devDependencies',
|
|
21
|
+
'peerDependencies',
|
|
22
|
+
'optionalDependencies',
|
|
23
|
+
] as const;
|
|
24
|
+
|
|
25
|
+
const asRecord = (value: unknown): Readonly<Record<string, unknown>> | undefined =>
|
|
26
|
+
typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
27
|
+
? (value as Record<string, unknown>)
|
|
28
|
+
: undefined;
|
|
29
|
+
|
|
30
|
+
/** JSONC: a tsconfig may carry comments; absent and unreadable both mean "declares nothing". */
|
|
31
|
+
async function readObject(path: string): Promise<Readonly<Record<string, unknown>> | undefined> {
|
|
32
|
+
const file = Bun.file(path);
|
|
33
|
+
if (!(await file.exists())) return undefined;
|
|
34
|
+
try {
|
|
35
|
+
return asRecord(Bun.JSONC.parse(await file.text()));
|
|
36
|
+
} catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** name → range, across every installing field; the first field to declare a name wins. */
|
|
42
|
+
const declaredOf = (
|
|
43
|
+
manifest: Readonly<Record<string, unknown>> | undefined,
|
|
44
|
+
): Map<string, string> => {
|
|
45
|
+
const declared = new Map<string, string>();
|
|
46
|
+
for (const field of DEPENDENCY_FIELDS) {
|
|
47
|
+
for (const [name, range] of Object.entries(asRecord(manifest?.[field]) ?? {})) {
|
|
48
|
+
if (!declared.has(name)) declared.set(name, typeof range === 'string' ? range : '');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return declared;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** `@types/scope__name` types `@scope/name`; `@types/name` types `name`. */
|
|
55
|
+
const typesPackageFor = (name: string): string =>
|
|
56
|
+
`@types/${name.startsWith('@') ? name.slice(1).replace('/', '__') : name}`;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* `@types/<pkg>` types a package; it does not install it. It covers a TYPE-ONLY import (`import
|
|
60
|
+
* type`, `typeof import()`) and never a runtime one, which still needs the package itself.
|
|
61
|
+
*/
|
|
62
|
+
const covers = (declared: ReadonlyMap<string, string>, name: string, typeOnly: boolean): boolean =>
|
|
63
|
+
declared.has(name) || (typeOnly && declared.has(typesPackageFor(name)));
|
|
64
|
+
|
|
65
|
+
/** The packages a file needs at RUNTIME: what survives type erasure. */
|
|
66
|
+
const runtimePackages = (source: string, path: string): ReadonlySet<string> =>
|
|
67
|
+
new Set(
|
|
68
|
+
scanRuntimeImports({ path, source: stripShebang(source) }).flatMap((specifier) => {
|
|
69
|
+
const name = packageOfSpecifier(specifier);
|
|
70
|
+
return name === undefined ? [] : [name];
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Whether the file names the package itself. Bun's transpiler injects `react/jsx-dev-runtime` into
|
|
76
|
+
* every `.tsx` scan — an import the author never wrote and the app's `jsxImportSource` replaces —
|
|
77
|
+
* so a package only counts when a quoted specifier in the text starts with its name.
|
|
78
|
+
*/
|
|
79
|
+
const spelledIn = (source: string, name: string): boolean =>
|
|
80
|
+
new RegExp(`['"\`]${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:['"\`/])`).test(source);
|
|
81
|
+
|
|
82
|
+
interface Owner {
|
|
83
|
+
readonly dir: string;
|
|
84
|
+
readonly name: string;
|
|
85
|
+
readonly declared: ReadonlyMap<string, string>;
|
|
86
|
+
/** Root and workspace tsconfig `paths` aliases, each read through its `extends` chain. */
|
|
87
|
+
readonly aliases: ReadonlySet<string>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const undeclaredExternalDepFinding = (
|
|
91
|
+
owner: { readonly dir: string },
|
|
92
|
+
dependency: string,
|
|
93
|
+
at: string,
|
|
94
|
+
range?: string,
|
|
95
|
+
): Finding => {
|
|
96
|
+
// The range a sibling already pins, when it travels through a shell verbatim: one version of a
|
|
97
|
+
// package across the app, rather than whatever the registry calls latest today.
|
|
98
|
+
const pinned = range === undefined ? dependency : `${dependency}@${range}`;
|
|
99
|
+
const spec = renderFixShellArg(pinned, '') === '' ? dependency : pinned;
|
|
100
|
+
const dev = at.endsWith(FIXTURE_SUFFIX) ? ' --dev' : '';
|
|
101
|
+
return {
|
|
102
|
+
code: 'X_WORKSPACE_EXTERNAL_DEP_UNDECLARED',
|
|
103
|
+
cause: `${at} imports ${dependency}, which neither ${owner.dir}/package.json nor the root package.json declares — it resolves only while another workspace's copy is hoisted`,
|
|
104
|
+
fix: `bun add ${renderFixShellArg(spec, '<the package>')}${dev} --cwd ${renderFixShellArg(owner.dir, '<the workspace directory>')}`,
|
|
105
|
+
docs: ERROR_DOCS_URL,
|
|
106
|
+
at: `${owner.dir}/package.json`,
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The declared registry graph must cover the imported one, per workspace. Workspace siblings are
|
|
112
|
+
* `checkWorkspaceDependencies`' question and are skipped here; `@ultimat3/*` in an app is a
|
|
113
|
+
* registry package like any other and must be declared. Tests are out of scope for the same reason
|
|
114
|
+
* they are there: they resolve through the root's devDependencies and never reach a tarball.
|
|
115
|
+
*
|
|
116
|
+
* One finding per (workspace, package) pair: the fix is one command, not one per import site.
|
|
117
|
+
*/
|
|
118
|
+
export async function checkExternalDependencies(root: string): Promise<readonly Finding[]> {
|
|
119
|
+
const { nodes } = await scanWorkspaces(root);
|
|
120
|
+
if (nodes.length === 0) return [];
|
|
121
|
+
const workspaceNames = new Set(nodes.map((node) => node.name));
|
|
122
|
+
// The root's own declarations resolve from every workspace under every linker: the root
|
|
123
|
+
// `node_modules` is on each one's lookup path, hoisted or isolated. A SIBLING's is not.
|
|
124
|
+
const rootDeclared = declaredOf(await readObject(join(root, 'package.json')));
|
|
125
|
+
const owners: Owner[] = [];
|
|
126
|
+
for (const node of nodes) {
|
|
127
|
+
const manifest = await readObject(join(root, node.dir, 'package.json'));
|
|
128
|
+
// Unioned rather than the workspace's alone: `tsc -b` compiles a file under the workspace's
|
|
129
|
+
// tsconfig, while a root-level `tsc` or Bun's resolver may read the root's.
|
|
130
|
+
const aliases = await tsconfigAliases([root, join(root, node.dir)]);
|
|
131
|
+
owners.push({ dir: node.dir, name: node.name, declared: declaredOf(manifest), aliases });
|
|
132
|
+
}
|
|
133
|
+
// Deepest directory first: a nested workspace's files are its own, never its parent's.
|
|
134
|
+
owners.sort((left, right) => right.dir.length - left.dir.length);
|
|
135
|
+
// The range the app already uses for a package, from whichever manifest declares it first.
|
|
136
|
+
const ranges = new Map<string, string>();
|
|
137
|
+
for (const [name, range] of rootDeclared) ranges.set(name, range);
|
|
138
|
+
for (const owner of [...owners].sort((left, right) => left.dir.localeCompare(right.dir))) {
|
|
139
|
+
for (const [name, range] of owner.declared) if (!ranges.has(name)) ranges.set(name, range);
|
|
140
|
+
}
|
|
141
|
+
const findings: Finding[] = [];
|
|
142
|
+
const reported = new Set<string>();
|
|
143
|
+
for await (const path of eachSourceFile(root)) {
|
|
144
|
+
if (isTest(path) || isGenerated(path)) continue;
|
|
145
|
+
const owner = owners.find((candidate) => path.startsWith(`${candidate.dir}/`));
|
|
146
|
+
if (owner === undefined) continue;
|
|
147
|
+
const source = await Bun.file(join(root, path)).text();
|
|
148
|
+
const runtime = runtimePackages(source, path);
|
|
149
|
+
for (const name of importedPackages(source, path)) {
|
|
150
|
+
if (isBuiltin(name) || workspaceNames.has(name) || owner.aliases.has(name)) continue;
|
|
151
|
+
if (!spelledIn(source, name)) continue;
|
|
152
|
+
const typeOnly = !runtime.has(name);
|
|
153
|
+
if (covers(owner.declared, name, typeOnly) || covers(rootDeclared, name, typeOnly)) continue;
|
|
154
|
+
const pair = `${owner.dir} ${name}`;
|
|
155
|
+
if (reported.has(pair)) continue;
|
|
156
|
+
reported.add(pair);
|
|
157
|
+
const range = ranges.get(name);
|
|
158
|
+
findings.push(
|
|
159
|
+
undeclaredExternalDepFinding(owner, name, path, range === '' ? undefined : range),
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return findings;
|
|
164
|
+
}
|
package/src/write-line.ts
CHANGED
|
@@ -51,14 +51,21 @@ let dropped = 0;
|
|
|
51
51
|
/**
|
|
52
52
|
* Per fd, because fd 1 and fd 2 are two readers. `degraded`: the last line was dropped, so the next
|
|
53
53
|
* gets one attempt. `torn`: it was dropped HALF-written, so the next line that arrives opens with
|
|
54
|
-
* the newline the torn one never got — otherwise the two glue into one unparseable line.
|
|
54
|
+
* the newline the torn one never got — otherwise the two glue into one unparseable line. `gone`:
|
|
55
|
+
* the reader closed its end (`EPIPE`, `| head -c 10`) and nothing written to it can arrive again.
|
|
55
56
|
*/
|
|
56
|
-
|
|
57
|
+
interface PipeState {
|
|
58
|
+
degraded: boolean;
|
|
59
|
+
torn: boolean;
|
|
60
|
+
gone: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const pipes = new Map<number, PipeState>();
|
|
57
64
|
|
|
58
|
-
const pipeOf = (fd: number):
|
|
65
|
+
const pipeOf = (fd: number): PipeState => {
|
|
59
66
|
let pipe = pipes.get(fd);
|
|
60
67
|
if (pipe === undefined) {
|
|
61
|
-
pipe = { degraded: false, torn: false };
|
|
68
|
+
pipe = { degraded: false, torn: false, gone: false };
|
|
62
69
|
pipes.set(fd, pipe);
|
|
63
70
|
}
|
|
64
71
|
return pipe;
|
|
@@ -71,7 +78,7 @@ export const droppedLineCount = (): number => dropped;
|
|
|
71
78
|
|
|
72
79
|
/**
|
|
73
80
|
* Write every byte of `buffer` to `fd`, or drop it after `EAGAIN_ATTEMPTS` stalls in a row — one
|
|
74
|
-
* stall while the fd is degraded. Returns whether it all arrived. A write of zero bytes is a stall
|
|
81
|
+
* stall while the fd is degraded — or abandon it, and every later line, once the reader is gone. Returns whether it all arrived. A write of zero bytes is a stall
|
|
75
82
|
* too, so no path spins.
|
|
76
83
|
*/
|
|
77
84
|
export function writeAll(
|
|
@@ -81,6 +88,7 @@ export function writeAll(
|
|
|
81
88
|
sleep: (ms: number) => void = Bun.sleepSync,
|
|
82
89
|
): boolean {
|
|
83
90
|
const pipe = pipeOf(fd);
|
|
91
|
+
if (pipe.gone) return false;
|
|
84
92
|
const prefix = pipe.torn ? 1 : 0;
|
|
85
93
|
const bytes = prefix === 0 ? buffer : Buffer.concat([Uint8Array.of(NEWLINE), buffer]);
|
|
86
94
|
let written = 0;
|
|
@@ -93,7 +101,14 @@ export function writeAll(
|
|
|
93
101
|
// `stringField`, never a cast plus a property read — the rule `metrics-endpoint.ts` states
|
|
94
102
|
// and `caught-value-reads.test.ts` enforces. Here it is also the difference between
|
|
95
103
|
// rethrowing and retrying: a `code` that cannot be read must not read as `EAGAIN`.
|
|
96
|
-
|
|
104
|
+
const code = stringField(cause, 'code');
|
|
105
|
+
// The reader closed its end: its choice, not the command's failure. Stop writing to it and
|
|
106
|
+
// let the command exit with the code it decided — never a stack trace and exit 1.
|
|
107
|
+
if (code === 'EPIPE') {
|
|
108
|
+
pipe.gone = true;
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (code !== 'EAGAIN') throw cause;
|
|
97
112
|
}
|
|
98
113
|
if (progress > 0) {
|
|
99
114
|
written += progress;
|
package/wiki/Actions.md
CHANGED
|
@@ -30,7 +30,7 @@ Declared one per file in a feature's `actions/` (`actions/publish-post.ts`, what
|
|
|
30
30
|
| `mcp.expose` | `boolean` | no (opt-in) | only a literal `true` makes the action a tool; silence exposes nothing. One predicate answers it everywhere — the tool, the LLM tool list, `describe().mcp.expose`, and `openapi.json`'s `x-ultimate.mcpTool` (which is `null` when there is no tool). Listing an un-exposed action in `defineAppMcp` is `X_MCP_TOOL_UNDECLARED` at boot |
|
|
31
31
|
| `mcp.description` | `string` | no | the tool description an agent reads, and the OpenAPI `summary`. Contract text, so it stays outside `t()` — `openapi.json` must not depend on a locale. Write it for a stranger |
|
|
32
32
|
| `mcp.visibleTo` | `readonly string[]` | no | roles that may see the projected tool; a caller whose role is not named gets ToolNotFound, never Forbidden — the policy still decides every call |
|
|
33
|
-
| `rateLimit` | `{ limit: number \| (({ ctx }) => number \| Promise<number>); windowMs: number }` | no | `limit` may be resolved **per call** from `ctx` (the tenant's plan, read by the app), before any bucket is touched; a resolver answering `NaN`, `0`, `Infinity` or a non-number is `X_RATE_LIMIT_INVALID`, never allow-all. A per-call limit publishes as `rateLimit: null` + `rateLimitPerCall: { windowMs }` in `describe()` and `x-ultimate.rateLimit.limit: 'per-call'` in `openapi.json`. Spent **inside `invoke`**, so the HTTP route, the MCP tool, the in-app agent's tool call and `.job()` draw on ONE bucket — the third call to a `limit: 2` action is `X_RATE_LIMITED` whichever surface it came through; a direct in-process call spends nothing. Keyed actor → org → IP; counted in `@ultimat3/http`'s installed store
|
|
33
|
+
| `rateLimit` | `{ limit: number \| (({ ctx }) => number \| Promise<number>); windowMs: number }` | no | `limit` may be resolved **per call** from `ctx` (the tenant's plan, read by the app), before any bucket is touched; a resolver answering `NaN`, `0`, `Infinity` or a non-number is `X_RATE_LIMIT_INVALID`, never allow-all. A per-call limit publishes as `rateLimit: null` + `rateLimitPerCall: { windowMs }` in `describe()` and `x-ultimate.rateLimit.limit: 'per-call'` in `openapi.json`. Spent **inside `invoke`**, so the HTTP route, the MCP tool, the in-app agent's tool call and `.job()` draw on ONE bucket — the third call to a `limit: 2` action is `X_RATE_LIMITED` whichever surface it came through; a direct in-process call spends nothing. Keyed actor → org → IP; counted in `@ultimat3/http`'s installed store — the `rateLimitStore` adapter port, filled by the boot on every role, `postgresRateLimitStore` unless `apps/<app>/runtime.ts` names one ([Adapters](Adapters#ratelimitstore)). Over HTTP the refusal is `429` + `Retry-After` and `RateLimit-*`, and the route is not also capped by the `default` bucket; the same `toBucket` conversion feeds `openapi.json`, so the published numbers are the enforced ones. `/mcp` additionally buckets by verb class (`MCP_RATE_LIMITS`, read 120/min, write 20/min per token) |
|
|
34
34
|
| `meter` | `{ name, period: 'hour' \| 'day' \| 'month', limit, warnAt?, onWarn? }` | no | a durable per-period allowance — see [Usage meters](#usage-meters-meter). Drawn on **every** surface, `server` included, after the policy and before `handle`; spent, `X_METER_EXCEEDED` (429) |
|
|
35
35
|
| `idempotent` | `boolean` | no — **required `true` on a `mutator`** | marks the action safe to retry with an `Idempotency-Key` header — over MCP, the tool's optional `idempotencyKey` argument. Inside a transaction the Postgres store settles the record with the write's own `COMMIT`, so a rollback never leaves a `settled` record behind. A field core redacts by name (`apiKey`, `password`, `*Token`…) or a `Secret` is stored as `[redacted]`, and the replay of such an answer is `X_IDEMPOTENT_REPLAY_REDACTED` |
|
|
36
36
|
| `http.path` | `string` | no | pins the URL whatever the app's `pathStyle` derives — for a path a caller already holds (`'/api/uploads/signed'`) or a resource-shaped one (`'/orders/:id/refund'`). Lowercase static segments and `:param`s, never `/_x`; each `:param` a REQUIRED `t.string` key of `input:`, else `X_ACTION_HTTP_PATH_INVALID` at registration. The URL's value joins the body before the input is parsed, so the schema, the policy, `row` and the handler read one object; a body naming the key with another value is **400** `X_HTTP_PATH_INPUT_CONFLICT`, never overridden. Under a bearer mount the pin is served at the prefix (`/v1/orders/:id/refund`) — and still at its own path, with the cookie session, as every pin is; the policy decides both. `derivePath(name)` refuses a template; `actionHttpPath(name, { id })` fills it. A `deprecated.replacedBy` naming one is `X_ACTION_DEPRECATION_INVALID`. An inbound webhook is not this door: it is `webhookReceiver()` ([Jobs and workflows](Jobs-And-Workflows#inbound-webhooks)) |
|
|
@@ -133,7 +133,7 @@ Every projection this package owns is a method on the action — `publishPost.op
|
|
|
133
133
|
|
|
134
134
|
`handle` and `row` — the declaration's two functions — are unreachable by design: neither lifted nor described. The declaration lives in a private store inside `invoke.ts` and `@ultimat3/action` exports no reader for it, so `invoke` is the only thing that can run them — one execution path and one authz path, structurally rather than by convention. A hand-rolled object with `kind: 'action'` is `X_ACTION_FOREIGN`, never a registered action.
|
|
135
135
|
|
|
136
|
-
Every projection needs the name `
|
|
136
|
+
Every projection needs the name `defineApi({ actions })` stamps on at boot. It names the export in place, so `import { publishPost }` is the action that projects once the app has booted — there is no second, differently-named twin to remember.
|
|
137
137
|
|
|
138
138
|
## Six generated artifacts
|
|
139
139
|
|