@ultimat3/cli 31.48.0 → 31.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +30 -23
- package/README.md +96 -4
- package/package.json +29 -29
- package/src/api-registration.ts +28 -14
- package/src/app-load.ts +6 -1
- package/src/app-root.ts +7 -1
- package/src/clean-services.ts +142 -0
- package/src/cmd-auth.ts +3 -0
- package/src/cmd-clean-spec.ts +10 -3
- package/src/cmd-clean.ts +23 -9
- package/src/cmd-db-backfill.ts +6 -0
- package/src/cmd-db-branch.ts +10 -4
- package/src/cmd-db-recount.ts +5 -12
- package/src/cmd-db-rollback.ts +77 -0
- package/src/cmd-db-spec.ts +18 -2
- package/src/cmd-db-status.ts +5 -10
- package/src/cmd-db.ts +105 -33
- package/src/cmd-deploy-verify.ts +14 -6
- package/src/cmd-docs-topic.ts +94 -0
- package/src/cmd-docs.ts +15 -1
- package/src/cmd-doctor.ts +109 -41
- package/src/cmd-drill.ts +80 -18
- package/src/cmd-env.ts +30 -8
- package/src/cmd-errors-app.ts +63 -0
- package/src/cmd-errors.ts +50 -14
- package/src/cmd-generate.ts +17 -4
- package/src/cmd-heavy-spec.ts +9 -1
- package/src/cmd-heavy.ts +111 -27
- package/src/cmd-jobs.ts +27 -1
- package/src/cmd-merge-driver-spec.ts +12 -0
- package/src/cmd-merge-driver.ts +95 -0
- package/src/cmd-new.ts +23 -3
- package/src/cmd-policy-spec.ts +9 -1
- package/src/cmd-policy.ts +72 -17
- package/src/cmd-stop.ts +18 -4
- package/src/cmd-tasks-run.ts +87 -0
- package/src/cmd-tasks-spec.ts +10 -3
- package/src/cmd-tasks.ts +8 -5
- package/src/cmd-test.ts +2 -1
- package/src/cmd-upgrade-spec.ts +8 -1
- package/src/cmd-upgrade.ts +15 -1
- package/src/cmd-verify.ts +9 -41
- package/src/codemods/agents-doc-row.ts +73 -0
- package/src/codemods/define-error-leaf.ts +37 -12
- package/src/codemods/docs-many-agents.ts +11 -15
- package/src/codemods/docs-worker-commands.ts +26 -0
- package/src/codemods/index.ts +4 -0
- package/src/codemods/merge-drivers.ts +66 -0
- package/src/command.ts +3 -0
- package/src/db-applied-edits.ts +117 -0
- package/src/db-dev-wire.ts +18 -0
- package/src/db-diagnostics.ts +5 -10
- package/src/db-generate.ts +82 -7
- package/src/db-migrate-pass.ts +51 -0
- package/src/db-migrate-through-dev.ts +209 -0
- package/src/db-rollback-consent.ts +128 -0
- package/src/db-rollback-pass.ts +76 -0
- package/src/db-seed-generate.ts +5 -1
- package/src/db-seed.ts +7 -1
- package/src/deploy-verify-findings.ts +3 -0
- package/src/deploy-verify-grade.ts +3 -0
- package/src/deploy-verify-processes.ts +32 -0
- package/src/dev-boot.ts +3 -0
- package/src/dev-db-migrate.ts +155 -0
- package/src/dev-db-rollback.ts +33 -0
- package/src/dev-db-settled.ts +22 -0
- package/src/dev-lock-errors.ts +78 -0
- package/src/dev-lock-holder-dir.ts +64 -0
- package/src/dev-lock-live.ts +44 -0
- package/src/dev-lock.ts +59 -84
- package/src/dev-policy.ts +11 -8
- package/src/dev-rebuild-schema.ts +116 -13
- package/src/dev-rebuild.ts +13 -4
- package/src/dev-route-table.ts +7 -0
- package/src/dispatch.ts +21 -1
- package/src/doctor-api-listing.ts +114 -0
- package/src/doctor-guarded.ts +41 -0
- package/src/doctor-port.ts +90 -17
- package/src/doctor-probe.ts +36 -5
- package/src/doctor-processes-probe.ts +127 -0
- package/src/doctor-processes.ts +136 -0
- package/src/doctor-warnings.ts +17 -0
- package/src/error-codes-agents.ts +35 -0
- package/src/error-codes-processes.ts +30 -0
- package/src/error-codes-tooling.ts +2 -0
- package/src/error-codes.ts +12 -13
- package/src/errors-suite.ts +27 -0
- package/src/errors.ts +18 -22
- package/src/exercise-registration.ts +4 -3
- package/src/framework-env.ts +7 -3
- package/src/generate-files.ts +1 -0
- package/src/generate-grant-findings.ts +7 -5
- package/src/generate-grants.ts +9 -8
- package/src/generate-kinds.ts +30 -6
- package/src/generate-roles-file.ts +30 -0
- package/src/generate-slice-policy.ts +3 -3
- package/src/guards.ts +2 -2
- package/src/heavy-env.ts +2 -0
- package/src/heavy-errors.ts +18 -0
- package/src/heavy-holders.ts +78 -0
- package/src/heavy-ledger.ts +56 -14
- package/src/heavy-pressure.ts +104 -0
- package/src/heavy.ts +31 -13
- package/src/i18n-registration.ts +22 -2
- package/src/island-harness.ts +2 -2
- package/src/job-budget.ts +4 -2
- package/src/job-registration.ts +64 -8
- package/src/jobs-queue-known.ts +43 -0
- package/src/mcp-errors-agents.ts +20 -0
- package/src/mcp-errors-doctor.ts +27 -0
- package/src/mcp-errors-processes.ts +23 -0
- package/src/mcp-errors.ts +15 -29
- package/src/mcp-host.ts +2 -2
- package/src/merge-driver-catalog.ts +58 -0
- package/src/merge-driver-config.ts +43 -0
- package/src/merge-driver-lines.ts +140 -0
- package/src/merge-state.ts +105 -0
- package/src/messages-db.ts +22 -1
- package/src/messages-processes.ts +13 -0
- package/src/messages-upgrade.ts +6 -0
- package/src/messages.ts +54 -4
- package/src/output-findings.ts +48 -21
- package/src/parse.ts +37 -6
- package/src/policy-facts.ts +38 -21
- package/src/policy-row.ts +99 -0
- package/src/port-pair-free.ts +28 -0
- package/src/registry-lines.ts +110 -0
- package/src/registry.ts +2 -0
- package/src/retain-sweep.ts +1 -1
- package/src/role-replicator.ts +4 -1
- package/src/role-select.ts +86 -0
- package/src/role-start.ts +13 -55
- package/src/role-sync.ts +10 -5
- package/src/runtime-cache-frame.ts +46 -0
- package/src/runtime-cache-ttl.ts +23 -0
- package/src/runtime-cache.ts +33 -16
- package/src/runtime-database-ssl.ts +84 -0
- package/src/runtime-idempotency-scope.ts +16 -2
- package/src/runtime-jobs-share.ts +52 -0
- package/src/runtime-jobs.ts +43 -12
- package/src/runtime-queue.ts +18 -3
- package/src/runtime-services.ts +8 -1
- package/src/schema-drift.ts +19 -2
- package/src/schema-dump-drift.ts +4 -1
- package/src/serve-boot-probe.ts +30 -2
- package/src/serve-boot.ts +11 -1
- package/src/serve-env.ts +39 -3
- package/src/serve.ts +61 -10
- package/src/stop-run-start.ts +12 -0
- package/src/supervise-boot.ts +61 -0
- package/src/supervise-cgroup.ts +84 -0
- package/src/supervise-child.ts +206 -0
- package/src/supervise-count.ts +244 -0
- package/src/supervise-errors.ts +83 -0
- package/src/supervise-facts.ts +40 -0
- package/src/supervise-messages.ts +84 -0
- package/src/supervise-policy.ts +46 -0
- package/src/supervise-pool.ts +10 -0
- package/src/supervise-probe.ts +158 -0
- package/src/supervise-run.ts +54 -0
- package/src/supervise.ts +383 -0
- package/src/templates/generate-purge.ts +6 -6
- package/src/templates/guard-animated-layout-property.ts +2 -2
- package/src/templates/guard-bare-error.ts +1 -1
- package/src/templates/guard-error-declared.ts +2 -2
- package/src/templates/guard-focus-visible.ts +1 -1
- package/src/templates/guard-image-dimensions.ts +2 -2
- package/src/templates/guard-island-mount-clears.ts +1 -1
- package/src/templates/guard-native-confirm.ts +1 -1
- package/src/templates/guard-raw-breakpoint.ts +2 -2
- package/src/templates/guard-raw-colour.ts +2 -2
- package/src/templates/guard-raw-fetch.ts +1 -1
- package/src/templates/guard-raw-interval.ts +1 -1
- package/src/templates/guard-raw-length.ts +3 -3
- package/src/templates/guard-raw-motion.ts +1 -1
- package/src/templates/guard-raw-shadow.ts +1 -1
- package/src/templates/guard-raw-z-index.ts +1 -1
- package/src/templates/guard-released-forms.ts +54 -8
- package/src/templates/guard-repo-await-in-loop.ts +1 -1
- package/src/templates/guard-repo-raw-sql.ts +4 -4
- package/src/templates/guard-repo-unbounded.ts +1 -1
- package/src/templates/guard-runtime-pin.ts +1 -1
- package/src/templates/guard-semantic-interactive.ts +2 -2
- package/src/templates/guard-unbounded-fanout.ts +1 -1
- package/src/templates/guard-undeclared-custom-property.ts +3 -3
- package/src/templates/guard-undefined-style-class.ts +3 -3
- package/src/templates/guard-unzoned-date.ts +3 -3
- package/src/templates/query-slice.ts +82 -0
- package/src/templates/query.ts +76 -30
- package/src/templates/resource-page.ts +3 -2
- package/src/templates/scaffold-bin.ts +2 -0
- package/src/templates/scaffold-claude-commands.ts +6 -0
- package/src/templates/scaffold-claude.ts +4 -4
- package/src/templates/scaffold-container-compose.ts +47 -7
- package/src/templates/scaffold-docs.ts +7 -3
- package/src/templates/scaffold-gitattributes.ts +18 -1
- package/src/templates/scaffold-helm-templates.ts +9 -0
- package/src/templates/scaffold-repo.ts +4 -1
- package/src/templates/scaffold-test-services.ts +33 -11
- package/src/templates/shapes/offline.ts +0 -7
- package/src/templates/shapes/realtime.ts +2 -6
- package/src/templates/sign-in-action-tests.ts +6 -4
- package/src/templates/sign-in-challenge.ts +62 -0
- package/src/templates/sign-in-oidc-mfa.ts +31 -0
- package/src/templates/sign-in-oidc.ts +11 -3
- package/src/templates/sign-in-password.ts +18 -56
- package/src/test-shards.ts +114 -34
- package/src/test-verdict.ts +79 -0
- package/src/test-workers.ts +15 -0
- package/src/upgrade-gate-codemods.ts +5 -3
- package/src/upgrade-gate.ts +19 -1
- package/src/upgrade-merge-drivers.ts +25 -0
- package/src/upgrade-report.ts +18 -4
- package/src/upgrade-scope.ts +62 -0
- package/src/verify-checks.ts +2 -8
- package/src/verify-coverage-run.ts +4 -1
- package/src/verify-live.ts +38 -14
- package/src/verify-only.ts +67 -0
- package/src/verify-progress.ts +7 -3
- package/src/verify-run.ts +20 -2
- package/src/verify-services-stack.ts +165 -0
- package/src/verify-services.ts +84 -2
- package/src/verify-test-run.ts +6 -7
- package/src/verify-tests.ts +8 -2
- package/src/verify-typecheck.ts +25 -2
- package/wiki/Actions.md +2 -1
- package/wiki/Admin-Dashboard.md +2 -2
- package/wiki/Agents.md +5 -5
- package/wiki/Auth.md +15 -5
- package/wiki/Bare-VM.md +1 -1
- package/wiki/CI-Parallel-Gate.md +2 -1
- package/wiki/CLI-Reference.md +107 -40
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Client-Navigation.md +1 -1
- package/wiki/Configuration.md +10 -9
- package/wiki/Deployment.md +44 -4
- package/wiki/Entities-And-Migrations.md +5 -1
- package/wiki/FAQ.md +1 -1
- package/wiki/Getting-Started.md +2 -2
- package/wiki/Home.md +1 -1
- package/wiki/I18n.md +5 -3
- package/wiki/Installation.md +12 -11
- package/wiki/Jobs-And-Workflows.md +24 -4
- package/wiki/Known-Gaps.md +1 -1
- package/wiki/MCP-And-AI.md +8 -5
- package/wiki/Many-Agents.md +69 -2
- package/wiki/Migrations-And-Backfills.md +18 -0
- package/wiki/Notify.md +1 -1
- package/wiki/Observability.md +13 -0
- package/wiki/Queries-And-Live-Queries.md +2 -2
- package/wiki/Realtime.md +10 -1
- package/wiki/Routes-And-Render-Modes.md +1 -1
- package/wiki/Scheduled-Tasks.md +4 -1
- package/wiki/Testing.md +7 -4
- package/wiki/Timezones-And-Dates.md +5 -1
- package/wiki/Troubleshooting.md +1 -0
- package/wiki/Tutorial-01-First-App.md +3 -3
- package/wiki/Tutorial-02-First-Feature.md +1 -1
- package/wiki/Tutorial-03-Auth-And-Admin.md +7 -6
- package/wiki/Upgrading.md +37 -0
package/src/templates/query.ts
CHANGED
|
@@ -2,11 +2,16 @@
|
|
|
2
2
|
// generated declaration always carries `orderBy` + `limit` and the generated test pins them:
|
|
3
3
|
// an unbounded live query is a memory leak that only shows up under load.
|
|
4
4
|
|
|
5
|
-
import { UltimateError } from '@ultimat3/core';
|
|
6
5
|
import type { FeatureTarget } from './entity';
|
|
7
6
|
import { sortedImports } from './imports';
|
|
8
7
|
import type { GeneratedFile, NameSet } from './naming';
|
|
9
8
|
import { names } from './naming';
|
|
9
|
+
import {
|
|
10
|
+
assertSliceExports,
|
|
11
|
+
QuerySliceEntityError,
|
|
12
|
+
readsThroughView,
|
|
13
|
+
withoutOwnedTests,
|
|
14
|
+
} from './query-slice';
|
|
10
15
|
import { PLACEHOLDER_DB_MODULE } from './scaffold-db-client';
|
|
11
16
|
import { foreignSliceEntity, sliceFoundation, sliceTakesScaffoldRow } from './slice-foundation';
|
|
12
17
|
import { wrapImport } from './wrap';
|
|
@@ -15,22 +20,50 @@ import { wrapImport } from './wrap';
|
|
|
15
20
|
const cacheLine = (feature: NameSet, live: boolean): string =>
|
|
16
21
|
live ? '' : `\n cache: { tags: [${feature.camel}Tag], ttlMs: 30_000 },`;
|
|
17
22
|
|
|
23
|
+
/**
|
|
24
|
+
* The projection a read answers through: the slice's `<Feature>View`, the shape its actions
|
|
25
|
+
* already answer — so a column added to the entity reaches the wire only by an edit to the view,
|
|
26
|
+
* and the tenant column never does. Live too: `@ultimat3/realtime` narrows every patch to the
|
|
27
|
+
* columns the snapshot's rows carry (`narrowRow`).
|
|
28
|
+
*/
|
|
29
|
+
const viewProjection = (feature: NameSet): string => `
|
|
30
|
+
/**
|
|
31
|
+
* What this read answers: the slice's \`${feature.pascal}View\`, the shape its actions answer —
|
|
32
|
+
* never the whole row. A column added to the entity reaches the wire only once the view lists it,
|
|
33
|
+
* and the tenant column never does.
|
|
34
|
+
*/
|
|
35
|
+
const viewOf = (row: ${feature.pascal}): ${feature.pascal}View => {
|
|
36
|
+
const keys = ${feature.pascal}View.$keys;
|
|
37
|
+
return Object.fromEntries(keys.map((key) => [key, row[key]])) as ${feature.pascal}View;
|
|
38
|
+
};
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
/** The `sql:` thunk: the repo's page, through the view when the slice declares one. */
|
|
42
|
+
const readThunk = (feature: NameSet, view: boolean): string =>
|
|
43
|
+
view
|
|
44
|
+
? `from<${feature.pascal}View>('${feature.table}', async () => {
|
|
45
|
+
const rows = await repo.list(limit, sort, dir);
|
|
46
|
+
return rows.map(viewOf);
|
|
47
|
+
})`
|
|
48
|
+
: `from<${feature.pascal}>('${feature.table}', () => repo.list(limit, sort, dir))`;
|
|
49
|
+
|
|
18
50
|
const querySource = (
|
|
19
51
|
name: NameSet,
|
|
20
52
|
feature: NameSet,
|
|
21
53
|
live: boolean,
|
|
54
|
+
view: boolean,
|
|
22
55
|
): string => `// ${name.camel}: a ${live ? 'live (subscribable)' : 'one-shot'} read over ${feature.pluralKebab}.
|
|
23
56
|
// Bounded and ordered — required for${live ? ' live queries' : ' predictable pagination'}.
|
|
24
57
|
// \`t\` comes from @ultimat3/query, not @ultimat3/schema: a query file imports one package.
|
|
25
58
|
|
|
26
59
|
import { from, query, t } from '@ultimat3/query';
|
|
27
|
-
import type { ${feature.pascal} } from '../entity'
|
|
60
|
+
${view ? wrapImport([`type ${feature.pascal}`, `${feature.pascal}View`], '../entity') : `import type { ${feature.pascal} } from '../entity';`}
|
|
28
61
|
${wrapImport(
|
|
29
62
|
live ? [`can${feature.pascal}Read`] : [`can${feature.pascal}Read`, `${feature.camel}Tag`],
|
|
30
63
|
'../policy',
|
|
31
64
|
)}
|
|
32
65
|
import * as repo from '../repo';
|
|
33
|
-
|
|
66
|
+
${view ? viewProjection(feature) : ''}
|
|
34
67
|
/** The columns this read sorts by: \`repo.ListSort\`, and what a page's \`listUrl\` offers. */
|
|
35
68
|
export const ${name.camel}Sorts = ['createdAt', 'title'] as const;
|
|
36
69
|
|
|
@@ -56,7 +89,7 @@ export const ${name.camel} = query({
|
|
|
56
89
|
sql: ({ limit, sort, dir }) =>
|
|
57
90
|
// \`feature.table\`, not the kebab plural: \`from()\` quotes the identifier into the SQL text,
|
|
58
91
|
// and the entity created the table as snake_case.
|
|
59
|
-
|
|
92
|
+
${readThunk(feature, view)}
|
|
60
93
|
// \`repo.list\`'s own order. These lines are ONE read spelled twice: the thunk is what the
|
|
61
94
|
// in-memory driver answers and this chain is the SQL Postgres runs, so a sort or a direction
|
|
62
95
|
// that differs here is a bounded page holding different rows on each.
|
|
@@ -87,7 +120,7 @@ const queryTest = (name: NameSet, feature: NameSet, shape: ReadShape): string =>
|
|
|
87
120
|
? [`import { expect, ${wrapper} } from '@ultimat3/testing';`]
|
|
88
121
|
: readImports(shape, ['expect', wrapper]);
|
|
89
122
|
const repo = shape.storesRow
|
|
90
|
-
? `${subscribes ? `\nimport type { ${feature.pascal} } from '../entity';` : ''}\nimport * as repo from '../repo';`
|
|
123
|
+
? `${subscribes ? `\nimport type { ${rowType(feature, shape)} } from '../entity';` : ''}${!live && shape.view ? `\nimport { ${feature.pascal}View } from '../entity';` : ''}\nimport * as repo from '../repo';`
|
|
91
124
|
: '';
|
|
92
125
|
return `// ${name.camel}: the shape it reads, the policy it asserts, and the actor it refuses. The read is
|
|
93
126
|
// declarative, so what a test can get wrong is the authz, and that is what this pins.
|
|
@@ -165,7 +198,7 @@ ${wrapper}('the read is offered to no agent until its tool is described', () =>
|
|
|
165
198
|
expect(target.kind).toBe('query');
|
|
166
199
|
expect(target.mcp).toBeUndefined();
|
|
167
200
|
});
|
|
168
|
-
${subscribes ? subscribeTest(name, feature) : ''}`;
|
|
201
|
+
${subscribes ? subscribeTest(name, feature, shape) : ''}`;
|
|
169
202
|
};
|
|
170
203
|
|
|
171
204
|
/**
|
|
@@ -175,13 +208,13 @@ ${subscribes ? subscribeTest(name, feature) : ''}`;
|
|
|
175
208
|
* `repo.list` — read fine there while every real subscriber was answered `X_TENANCY_UNSCOPED`.
|
|
176
209
|
* Two orgs, a snapshot and a write: the window a subscriber is served from is its own org's.
|
|
177
210
|
*/
|
|
178
|
-
const subscribeTest = (name: NameSet, feature: NameSet): string => `
|
|
211
|
+
const subscribeTest = (name: NameSet, feature: NameSet, shape: ReadShape): string => `
|
|
179
212
|
// The module's own export under its own name, through \`defineApi\` as the boot hands it over, so
|
|
180
213
|
// a subscribe frame naming it reaches this declaration.
|
|
181
214
|
const api = defineApi({ queries: { ${name.camel} } });
|
|
182
215
|
const live = api.queries.${name.camel};
|
|
183
216
|
|
|
184
|
-
type Row = ${feature
|
|
217
|
+
type Row = ${rowType(feature, shape)};
|
|
185
218
|
|
|
186
219
|
const otherOrg = '${OTHER_ORG}';
|
|
187
220
|
|
|
@@ -223,10 +256,29 @@ liveTest('two orgs subscribe: each is sent its own rows and writes', async ({ su
|
|
|
223
256
|
await theirs.settled();
|
|
224
257
|
expect(ours.rows().map((row) => row.title)).toEqual(['ours too', 'ours']);
|
|
225
258
|
expect(theirs.rows().map((row) => row.title)).toEqual(['theirs']);
|
|
226
|
-
expect(theirs.patches()).toEqual([])
|
|
259
|
+
expect(theirs.patches()).toEqual([]);${shape.view ? NARROWED_PATCH : ''}
|
|
227
260
|
});
|
|
228
261
|
`;
|
|
229
262
|
|
|
263
|
+
/** A patch is narrowed to the snapshot's columns (`narrowRow`): the view's, never the org's. */
|
|
264
|
+
const NARROWED_PATCH = `
|
|
265
|
+
// The patched row is narrowed to the columns the snapshot carried — the view's — so the tenant
|
|
266
|
+
// column a change event holds never reaches a subscriber.
|
|
267
|
+
for (const row of ours.rows()) expect(row).not.toHaveProperty('orgId');`;
|
|
268
|
+
|
|
269
|
+
/** The row type a read answers: the slice's view, or the row when the slice declares none. */
|
|
270
|
+
const rowType = (feature: NameSet, shape: ReadShape): string =>
|
|
271
|
+
shape.view ? `${feature.pascal}View` : feature.pascal;
|
|
272
|
+
|
|
273
|
+
/** What the stored-rows case pins about the wire: the view's keys, and never the tenant column. */
|
|
274
|
+
const wireShape = (feature: NameSet): string => `
|
|
275
|
+
// What leaves the server is the slice's view: its keys exactly, and never the tenant column — a
|
|
276
|
+
// column added to the entity reaches the wire only once the view lists it.
|
|
277
|
+
for (const row of page) {
|
|
278
|
+
expect(Object.keys(row).sort()).toEqual([...${feature.pascal}View.$keys].sort());
|
|
279
|
+
expect(row).not.toHaveProperty('orgId');
|
|
280
|
+
}`;
|
|
281
|
+
|
|
230
282
|
const ORG = '00000000-0000-4000-8000-000000000002';
|
|
231
283
|
|
|
232
284
|
/** The org the reader and its rows belong to — an actor's, never the read's input. */
|
|
@@ -241,6 +293,8 @@ interface ReadShape {
|
|
|
241
293
|
readonly live: boolean;
|
|
242
294
|
/** The slice still takes the row `x g entity` scaffolds, so the test may store some. */
|
|
243
295
|
readonly storesRow: boolean;
|
|
296
|
+
/** The read answers through the slice's `<Feature>View` (`readsThroughView`). */
|
|
297
|
+
readonly view: boolean;
|
|
244
298
|
readonly dbModule: string;
|
|
245
299
|
}
|
|
246
300
|
|
|
@@ -249,7 +303,7 @@ interface ReadShape {
|
|
|
249
303
|
* it. Three rows a second apart, a page of two — so an order that is not newest-first, a missing
|
|
250
304
|
* bound and another org's row each fail it on their own.
|
|
251
305
|
*/
|
|
252
|
-
const storedRowsTest = (): string => `
|
|
306
|
+
const storedRowsTest = (feature: NameSet, shape: ReadShape): string => `
|
|
253
307
|
const otherOrg = '${OTHER_ORG}';
|
|
254
308
|
|
|
255
309
|
// The request clock, so \`createdAt\` is an instant this file chose and "newest" is decidable.
|
|
@@ -275,7 +329,7 @@ unitTest('stored rows read back newest first, bounded, and never another org', a
|
|
|
275
329
|
// The declaration's order over the repo's rows: what the SQL names on Postgres, read here
|
|
276
330
|
// from the in-memory driver. A page of two is the two NEWEST, on both.
|
|
277
331
|
const page = await target.as(member, { limit: 2 });
|
|
278
|
-
expect(page.map((row) => row.title)).toEqual(['third', 'second'])
|
|
332
|
+
expect(page.map((row) => row.title)).toEqual(['third', 'second']);${shape.view ? wireShape(feature) : ''}
|
|
279
333
|
// The same input, an actor in the other org: its own row, and nothing of this org's.
|
|
280
334
|
const outsider = testActor('outsider', { orgId: otherOrg, permissions: [read] }).actor;
|
|
281
335
|
const theirs = await target.as(outsider, { limit: 50 });
|
|
@@ -324,7 +378,7 @@ unitTest('the read runs as its caller: an org with no rows reads empty', async (
|
|
|
324
378
|
// in-memory driver.
|
|
325
379
|
expect(await target.as(member, { limit: 50 })).toEqual([]);
|
|
326
380
|
});
|
|
327
|
-
${shape.storesRow ? storedRowsTest() : ''}`;
|
|
381
|
+
${shape.storesRow ? storedRowsTest(feature, shape) : ''}`;
|
|
328
382
|
|
|
329
383
|
/** The imports the read cases need, over whatever the file they land in already imports. */
|
|
330
384
|
const readImports = (shape: ReadShape, testing: readonly string[]): readonly string[] => [
|
|
@@ -342,7 +396,7 @@ const liveReadTest = (
|
|
|
342
396
|
shape: ReadShape,
|
|
343
397
|
): string => `// ${name.camel}, READ: what a caller gets back, through the repo and the in-memory driver. The
|
|
344
398
|
// subscription — the snapshot and the patches a write produces — is the live suite's, next door.
|
|
345
|
-
${sortedImports([...readImports(shape, ['expect', 'unitTest']), "import { testActor } from '@ultimat3/policy';"])}${shape.storesRow ?
|
|
399
|
+
${sortedImports([...readImports(shape, ['expect', 'unitTest']), "import { testActor } from '@ultimat3/policy';"])}${shape.storesRow ? `${shape.view ? `\nimport { ${feature.pascal}View } from '../entity';` : ''}\nimport * as repo from '../repo';` : ''}
|
|
346
400
|
import { ${name.camel} } from './${name.kebab}';
|
|
347
401
|
|
|
348
402
|
const orgId = '${ORG}';
|
|
@@ -364,21 +418,11 @@ export interface QueryOptions extends FeatureTarget {
|
|
|
364
418
|
readonly sliceEntity?: string;
|
|
365
419
|
/** The slice's `repo.ts` as it stands on disk, or absent alongside `sliceEntity`. */
|
|
366
420
|
readonly sliceRepo?: string;
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
*/
|
|
373
|
-
export class QuerySliceEntityError extends UltimateError {
|
|
374
|
-
constructor(input: { readonly path: string; readonly binding: string; readonly table: string }) {
|
|
375
|
-
super({
|
|
376
|
-
code: 'X_QUERY_SLICE_ENTITY',
|
|
377
|
-
cause: `x g query reads the slice's own scaffolded table, and its entity.ts declares ${input.binding} (${input.table}) instead — the generated read would import a row type and a repo that do not exist`,
|
|
378
|
-
fix: `x queries list --json # then declare query({ sql: … from('${input.table}', …) }) by hand in ${input.path}, over ../entity's ${input.binding}`,
|
|
379
|
-
meta: { binding: input.binding, table: input.table },
|
|
380
|
-
});
|
|
381
|
-
}
|
|
421
|
+
/**
|
|
422
|
+
* The slice's `policy.ts` as it stands on disk, absent when the slice has none yet (and then the
|
|
423
|
+
* scaffolded one is written). The read IMPORTS `can<Feature>Read` from it — `action.ts`'s reason.
|
|
424
|
+
*/
|
|
425
|
+
readonly slicePolicy?: string;
|
|
382
426
|
}
|
|
383
427
|
|
|
384
428
|
export function queryFiles(rawName: string, target: QueryOptions): readonly GeneratedFile[] {
|
|
@@ -390,17 +434,19 @@ export function queryFiles(rawName: string, target: QueryOptions): readonly Gene
|
|
|
390
434
|
if (foreign !== undefined) {
|
|
391
435
|
throw new QuerySliceEntityError({ path: `${dir}/${name.kebab}.ts`, ...foreign });
|
|
392
436
|
}
|
|
437
|
+
assertSliceExports(target, feature, live);
|
|
393
438
|
const shape: ReadShape = {
|
|
394
439
|
live,
|
|
395
440
|
storesRow: sliceTakesScaffoldRow(target, target.sliceEntity, target.sliceRepo),
|
|
441
|
+
view: readsThroughView(feature, target.sliceEntity),
|
|
396
442
|
dbModule: target.dbModule ?? PLACEHOLDER_DB_MODULE,
|
|
397
443
|
};
|
|
398
444
|
return [
|
|
399
445
|
// A read declares the row type it returns (`../entity`), the rule that admits it (`../policy`)
|
|
400
446
|
// and the one module allowed to query the table (`../repo`) — all three are the slice's, and
|
|
401
447
|
// `--live` changes only which directory this file lands in.
|
|
402
|
-
...sliceFoundation(target, ['entity', 'policy'], target.locales),
|
|
403
|
-
{ path: `${dir}/${name.kebab}.ts`, contents: querySource(name, feature, live) },
|
|
448
|
+
...withoutOwnedTests(sliceFoundation(target, ['entity', 'policy'], target.locales), target),
|
|
449
|
+
{ path: `${dir}/${name.kebab}.ts`, contents: querySource(name, feature, live, shape.view) },
|
|
404
450
|
// The suffix follows the WRAPPER, which follows `--live`: a `liveTest` in a plain
|
|
405
451
|
// `<name>.test.ts` runs under `unit`, so `x test live` had no files in an app full of them.
|
|
406
452
|
{
|
|
@@ -98,7 +98,7 @@ ${sortedImports([
|
|
|
98
98
|
"import { defineRoute, Hole, island } from '@ultimat3/render';",
|
|
99
99
|
"import {\n DataTable,\n type ListUrl,\n listUrl,\n Money,\n PageHeader,\n Section,\n Skeleton,\n} from '@ultimat3/ui';",
|
|
100
100
|
])}
|
|
101
|
-
${options.shell ? "import { Shell } from '../../shared/shell';\n" : ''}import type { ${feature.pascal} } from '../${feature.kebab}/entity';
|
|
101
|
+
${options.shell ? "import { Shell } from '../../shared/shell';\n" : ''}import type { ${feature.pascal}View } from '../${feature.kebab}/entity';
|
|
102
102
|
${wrapImport([list, `${list}Sorts`], `../${feature.kebab}/live/${feature.kebab}-list`)}
|
|
103
103
|
import styles from './page.module.scss';
|
|
104
104
|
|
|
@@ -108,7 +108,8 @@ const PAGE_ROWS = 50;
|
|
|
108
108
|
/** The currency a price is typed in; the form sends integer minor units of it. */
|
|
109
109
|
const CURRENCY = 'USD';
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
/** What the slice's list query answers: its view, never the whole row (no tenant column). */
|
|
112
|
+
type Row = ${feature.pascal}View;
|
|
112
113
|
|
|
113
114
|
/** The read's outcome as DATA, so the table renders each of its states. */
|
|
114
115
|
export type PageData = AsyncState<RowPage<Row>>;
|
|
@@ -55,6 +55,8 @@ const hasMigration = (): boolean => {
|
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
await bun('install');
|
|
58
|
+
// Merge drivers live in .git/config, which no clone inherits. Outside a git checkout this is a no-op.
|
|
59
|
+
await x('merge-driver', 'install');
|
|
58
60
|
ensureFile('.env.development.local', PER_BOX);
|
|
59
61
|
if (!hasMigration()) await x('db', 'gen', 'initial');
|
|
60
62
|
await x('db', 'migrate', ...process.argv.slice(2));
|
|
@@ -19,6 +19,9 @@ anything — it is the short form of every rule below, and it wins where the two
|
|
|
19
19
|
**Done means \`bun run verify\` green.** A passing unit test is not done. A working \`bunx x dev\` is not done.
|
|
20
20
|
Report what you actually ran, never what you assume passed.
|
|
21
21
|
|
|
22
|
+
**Given a file set, you are a worker:** skip the gate, the coordinator runs it once. Run
|
|
23
|
+
\`bun test ./<file>\`, \`bunx x test --filter <path>\`, and \`bunx x verify --only typecheck\` once at the end.
|
|
24
|
+
|
|
22
25
|
## Request
|
|
23
26
|
$ARGUMENTS
|
|
24
27
|
|
|
@@ -206,6 +209,9 @@ allowed-tools: Read, Write, Edit, Glob, Grep, Bash
|
|
|
206
209
|
|
|
207
210
|
Run \`bun run verify\`.
|
|
208
211
|
|
|
212
|
+
**Given a file set, do not:** the coordinator runs the gate once. Run your own files
|
|
213
|
+
(\`bun test ./<file>\`, \`bunx x test --filter <path>\`) and report.
|
|
214
|
+
|
|
209
215
|
It is \`bunx x verify\`, and it is THE gate — the one CI runs (\`.github/workflows/ci.yml\`) and the
|
|
210
216
|
one \`README.md\` names. Its \`budgets\` step builds what it weighs, so nothing runs before it.
|
|
211
217
|
|
|
@@ -26,12 +26,12 @@ const settings = (): string => `{
|
|
|
26
26
|
"allow": [
|
|
27
27
|
"Bash(bun install)",
|
|
28
28
|
"Bash(bun test:*)",
|
|
29
|
-
"Bash(bun run typecheck)",
|
|
30
|
-
"Bash(bun run lint)",
|
|
31
29
|
"Bash(bun run verify:*)",
|
|
32
30
|
"Bash(bunx @biomejs/biome check:*)",
|
|
33
31
|
"Bash(bunx x verify:*)",
|
|
34
32
|
"Bash(bunx x test:*)",
|
|
33
|
+
"Bash(bunx x heavy:*)",
|
|
34
|
+
"Bash(bunx x stop:*)",
|
|
35
35
|
"Bash(bunx x doctor:*)",
|
|
36
36
|
"Bash(bunx x g:*)",
|
|
37
37
|
"Bash(bunx x routes:*)",
|
|
@@ -133,8 +133,8 @@ with the command that re-checks the file, instead of surfacing later as a red \`
|
|
|
133
133
|
|
|
134
134
|
It is not a typecheck, because a *scoped* one does not exist: \`tsc\` needs the project, and even
|
|
135
135
|
\`bunx x verify --only typecheck\` checks the whole tree — and says \`NOT A GATE RUN\`, because green
|
|
136
|
-
means the run with no flag. There is no \`--skip\`.
|
|
137
|
-
|
|
136
|
+
means the run with no flag. There is no \`--skip\`. Run it once, when the work is otherwise done: it
|
|
137
|
+
queues for the machine's memory, which \`bun run typecheck\` does not.
|
|
138
138
|
|
|
139
139
|
## Where the rules live
|
|
140
140
|
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
import type { NameSet } from './naming';
|
|
6
6
|
import { RUNTIME_UID } from './scaffold-helm';
|
|
7
7
|
|
|
8
|
+
/** The compose database: the tag and its multi-arch index digest, as `docker/*.yml` pin theirs. */
|
|
9
|
+
export const POSTGRES_IMAGE =
|
|
10
|
+
'postgres:18-alpine@sha256:ff64c9e3bdf8e2120107d3559de8db314e8305f7e38c5105903c6295876738ff';
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
13
|
* The production env file, relative to the app root. Named once because two readers must agree:
|
|
10
14
|
* the compose file's \`env_file:\` (what the containers see) and \`x deploy\`'s \`--env-file\` (what
|
|
@@ -12,6 +16,13 @@ import { RUNTIME_UID } from './scaffold-helm';
|
|
|
12
16
|
*/
|
|
13
17
|
export const PROD_ENV_FILE = '.env.production';
|
|
14
18
|
|
|
19
|
+
/**
|
|
20
|
+
* A compose interpolation, `${expr}` in the written file: one `$`, which compose reads (its `$$` is
|
|
21
|
+
* a literal `$`). Never `\${` in the template below: CodeQL reads that escape as a regex one
|
|
22
|
+
* (js/useless-regexp-character-escape), and the bytes are the same.
|
|
23
|
+
*/
|
|
24
|
+
const composeVar = (expr: string): string => `${'$'}{${expr}}`;
|
|
25
|
+
|
|
15
26
|
/** The production topology `x new` writes at `docker/docker-compose.prod.yml`. */
|
|
16
27
|
export const composeProdFile = (
|
|
17
28
|
app: NameSet,
|
|
@@ -22,7 +33,7 @@ export const composeProdFile = (
|
|
|
22
33
|
#
|
|
23
34
|
# ${PROD_ENV_FILE} first: \`x env init --production\` writes every value below with fresh secrets.
|
|
24
35
|
#
|
|
25
|
-
# By hand, always with \`--env-file ${PROD_ENV_FILE}\`: Compose fills
|
|
36
|
+
# By hand, always with \`--env-file ${PROD_ENV_FILE}\`: Compose fills \`${composeVar('VAR:?…')}\` below from the shell
|
|
26
37
|
# and \`--env-file\` only, NEVER from \`env_file:\`, so without it a value set only in that file is
|
|
27
38
|
# "missing" and the parse fails. \`x deploy\` passes it on every step.
|
|
28
39
|
#
|
|
@@ -38,6 +49,14 @@ export const composeProdFile = (
|
|
|
38
49
|
# file, is the chart \`x deploy --method helm\` installs. To scale them on one box anyway, drop
|
|
39
50
|
# \`ports:\` and put your own proxy on this network — the service name resolves to every replica
|
|
40
51
|
# over the compose DNS round robin.
|
|
52
|
+
#
|
|
53
|
+
# \`cpus:\` is the knob \`ULTIMATE_PROCESSES=auto\` (the default) reads: K whole cores run K processes
|
|
54
|
+
# of the role on one port; no \`cpus:\` runs one. Most of a request's wall time is I/O wait, so the
|
|
55
|
+
# budgets are modest: raise a role's \`cpus\` when its process sits above ~70% of one core. Memory
|
|
56
|
+
# is 256 MiB per process plus headroom; jobs.concurrency, jobs.maxInFlight and DATABASE_POOL_MAX
|
|
57
|
+
# are per CONTAINER, split across its processes. \`net.ipv4.tcp_migrate_req\` is a commented opt-in
|
|
58
|
+
# on web and sync, never active: a kernel older than Linux 5.14 has no such knob, and Docker then
|
|
59
|
+
# refuses to create the container at all.
|
|
41
60
|
name: ${app.kebab}
|
|
42
61
|
|
|
43
62
|
# Every service's logs, rotated. Docker's default json-file driver never rotates, so a chatty role
|
|
@@ -47,10 +66,13 @@ x-logging: &logging
|
|
|
47
66
|
options: { max-size: 10m, max-file: '3' }
|
|
48
67
|
|
|
49
68
|
x-image: &image
|
|
50
|
-
image:
|
|
69
|
+
image: ${composeVar(`IMAGE:-${app.kebab}:dev`)}
|
|
51
70
|
env_file: [../${PROD_ENV_FILE}]
|
|
52
71
|
restart: unless-stopped
|
|
53
72
|
logging: *logging
|
|
73
|
+
# An init as PID 1: Bun as PID 1 never reaps an orphaned grandchild, and ignores SIGTERM until a
|
|
74
|
+
# handler is installed, so \`docker stop\` waited out the grace and SIGKILLed.
|
|
75
|
+
init: true
|
|
54
76
|
# SIGTERM → /readyz answers 503 for the readiness grace (5s outside local environments), then the
|
|
55
77
|
# drain of in-flight requests, jobs and sockets (25s). 40s leaves 10s before Docker SIGKILLs.
|
|
56
78
|
stop_grace_period: 40s
|
|
@@ -88,10 +110,12 @@ x-run-once-probe: &run-once-probe
|
|
|
88
110
|
services:
|
|
89
111
|
db:
|
|
90
112
|
# Postgres 18 images keep the cluster under /var/lib/postgresql/18/docker, so the volume is the
|
|
91
|
-
# parent — mounted at .../data, as for 17, the image refuses to start.
|
|
92
|
-
|
|
113
|
+
# parent — mounted at .../data, as for 17, the image refuses to start. Pinned by digest: a tag
|
|
114
|
+
# is whatever the registry serves on the day this box pulls. To move it, read the new one with
|
|
115
|
+
# \`docker buildx imagetools inspect postgres:18-alpine\` and take a backup first.
|
|
116
|
+
image: ${POSTGRES_IMAGE}
|
|
93
117
|
environment:
|
|
94
|
-
POSTGRES_PASSWORD:
|
|
118
|
+
POSTGRES_PASSWORD: ${composeVar('POSTGRES_PASSWORD:?set POSTGRES_PASSWORD')}
|
|
95
119
|
POSTGRES_DB: ${app.kebab}
|
|
96
120
|
volumes: ['pgdata:/var/lib/postgresql']
|
|
97
121
|
healthcheck:
|
|
@@ -99,6 +123,7 @@ services:
|
|
|
99
123
|
interval: 5s
|
|
100
124
|
restart: unless-stopped
|
|
101
125
|
logging: *logging
|
|
126
|
+
init: true
|
|
102
127
|
|
|
103
128
|
# The release phase. Applies pending migrations under an advisory lock and exits; every serving
|
|
104
129
|
# role waits for it to complete, so no replica ever serves against a schema it does not ship.
|
|
@@ -133,12 +158,19 @@ services:
|
|
|
133
158
|
<<: *image
|
|
134
159
|
# The page dials SYNC_URL; unset, it dials /_x/sync on :3000, which web does not serve here.
|
|
135
160
|
# Set it in ${PROD_ENV_FILE}: \`--env-file\` (header) is what lets this line read it there.
|
|
136
|
-
environment: [ROLE=web, 'SYNC_URL
|
|
161
|
+
environment: [ROLE=web, 'SYNC_URL=${composeVar('SYNC_URL:?set SYNC_URL=ws://<host>:3001/_x/sync, see wiki/Deployment.md')}']
|
|
137
162
|
depends_on:
|
|
138
163
|
db: { condition: service_healthy }
|
|
139
164
|
migrate: { condition: service_completed_successfully }
|
|
140
165
|
deploy: { replicas: 1 } # stateless, scales on RPS — pinned by the published port
|
|
141
166
|
ports: ['3000:3000']
|
|
167
|
+
# Two processes on one port; 2 x 256 MiB plus headroom fits in the anchor's 1g.
|
|
168
|
+
cpus: '2'
|
|
169
|
+
# Opt-in, Linux >= 5.14 only (Docker refuses to create the container on an older kernel —
|
|
170
|
+
# RHEL 8, Ubuntu 20.04, Amazon Linux 2). With more than one process here, a stopping process's
|
|
171
|
+
# queued connections move to a sibling instead of being reset: 93-109 of 200 reset without it,
|
|
172
|
+
# 0 with it. \`x doctor\` warns when the knob exists, reads 0 and N > 1.
|
|
173
|
+
# sysctls: { net.ipv4.tcp_migrate_req: 1 }
|
|
142
174
|
|
|
143
175
|
sync:
|
|
144
176
|
<<: *image
|
|
@@ -146,7 +178,7 @@ services:
|
|
|
146
178
|
# APP_URL's origin and no other once declared (scheme, host and port, exactly); undeclared, from
|
|
147
179
|
# the origin it was reached on. Unset, every websocket is 403 X_SOCKET_ORIGIN_REFUSED, so it is
|
|
148
180
|
# required: the same value web builds its links from.
|
|
149
|
-
environment: [ROLE=sync, 'APP_URL
|
|
181
|
+
environment: [ROLE=sync, 'APP_URL=${composeVar('APP_URL:?set APP_URL=http://<host>:3000 — the origin the pages are served on, see wiki/Deployment.md')}']
|
|
150
182
|
depends_on:
|
|
151
183
|
db: { condition: service_healthy }
|
|
152
184
|
migrate: { condition: service_completed_successfully }
|
|
@@ -159,6 +191,10 @@ services:
|
|
|
159
191
|
deploy: { replicas: 0 } # when on: scales on concurrent websockets — pinned to 1 by the port
|
|
160
192
|
# The sync role binds PORT + 1. PORT is unset here, so it is 3000 and this listens on 3001.
|
|
161
193
|
ports: ['3001:3001']
|
|
194
|
+
# One process; a second needs NATS_URL. With a second, the opt-in below (Linux >= 5.14 only, as
|
|
195
|
+
# on web) keeps a stopping process's queued sockets instead of resetting them.
|
|
196
|
+
cpus: '1'
|
|
197
|
+
# sysctls: { net.ipv4.tcp_migrate_req: 1 }
|
|
162
198
|
# ...which is why the image's own HEALTHCHECK cannot be inherited here. It fetches $PORT —
|
|
163
199
|
# 3000 — and this role never binds it, so the container reports \`unhealthy\` from
|
|
164
200
|
# \`start_period\` onward and never recovers, and anything gated on \`sync: service_healthy\`
|
|
@@ -180,6 +216,9 @@ services:
|
|
|
180
216
|
migrate: { condition: service_completed_successfully }
|
|
181
217
|
healthcheck: *metrics-probe
|
|
182
218
|
deploy: { replicas: 1 } # scales on queue depth
|
|
219
|
+
# One process per replica. CPU-heavy queues raise it: a synchronous handler blocks every job in
|
|
220
|
+
# its process and their lease renewals.
|
|
221
|
+
cpus: '1'
|
|
183
222
|
|
|
184
223
|
scheduler:
|
|
185
224
|
<<: *image
|
|
@@ -193,6 +232,7 @@ services:
|
|
|
193
232
|
# holds one. A second instance is harmless but idle.
|
|
194
233
|
healthcheck: *metrics-probe
|
|
195
234
|
deploy: { replicas: 1 }
|
|
235
|
+
cpus: '0.5' # always one process: a small budget
|
|
196
236
|
|
|
197
237
|
volumes:
|
|
198
238
|
pgdata:
|
|
@@ -40,7 +40,7 @@ queries, jobs, MCP tools, published operations and tests it touches, each with p
|
|
|
40
40
|
|---|---|---|
|
|
41
41
|
| One gate | \`bun run verify\` — \`bunx x verify\`, which builds what its \`budgets\` step weighs. Green means shippable; never merge red. CI runs the same gate, cut into parts: \`bun run verify plan --json\` names them, each runner runs \`bun run setup && bun run verify --only <steps>\`, and \`bun run verify merge\` is the verdict | the gate itself, and \`.github/workflows/ci.yml\` on every push and pull request; \`.github/workflows/image.yml\` publishes only a commit it passed |
|
|
42
42
|
| Coverage | the unit suite covers 95% of the lines and functions of this app's own source — every file under \`apps/\` and \`packages/\`, one no test loads counted at 0%. A floor, not the goal: a test added to raise it is proven by mutation — break the source, watch it go red, restore | \`X_COVERAGE_BELOW_FLOOR\` on the \`unit\` step; \`coverage\` in \`x.verify.json\` states the floor, and it only rises |
|
|
43
|
-
| Many agents | a worker
|
|
43
|
+
| Many agents | a worker: \`bun test ./<file>\`, \`bunx x test --filter <path>\`; the coordinator: the gate, once | review |
|
|
44
44
|
| One way | generators, not hand-rolled files: \`bunx x g resource\`, \`bunx x g action\`, \`bunx x g route\` | review |
|
|
45
45
|
| Surfaces | \`site/\` is 0kb JS and may not import \`app/\`; \`shared/\` is a leaf | \`X_BOUNDARY_SITE_TO_APP\` |
|
|
46
46
|
| Data | routes call actions and queries; only \`repo.ts\` touches the database | \`X_BOUNDARY_ROUTE_TO_DB\` |
|
|
@@ -170,6 +170,10 @@ bun run verify
|
|
|
170
170
|
\`x db gen "initial"\` for you on a fresh clone. Until it has, \`x verify\`'s \`drift\` step is red
|
|
171
171
|
with \`X_DB_DRIFT\`, and that is the fix it names.
|
|
172
172
|
|
|
173
|
+
**Merging two features:** two branches' \`x g\` output merges with no hand edit once \`bun run setup\`
|
|
174
|
+
has run (\`x merge-driver install\`). After the merge run \`bunx x manifest\`. A conflict that remains
|
|
175
|
+
(\`git diff --name-only --diff-filter=U\`) is a real one: both branches changed the same existing line.
|
|
176
|
+
|
|
173
177
|
## 🗺 Layout
|
|
174
178
|
|
|
175
179
|
| Path | Holds |
|
|
@@ -239,7 +243,7 @@ volumes:
|
|
|
239
243
|
`;
|
|
240
244
|
|
|
241
245
|
/** Docs, shims and container files for a new app, in the order a reader meets them. */
|
|
242
|
-
export function docsFiles(app: NameSet): readonly GeneratedFile[] {
|
|
246
|
+
export function docsFiles(app: NameSet, root?: string): readonly GeneratedFile[] {
|
|
243
247
|
return [
|
|
244
248
|
{ path: 'README.md', contents: readme(app) },
|
|
245
249
|
{ path: 'CLAUDE.md', contents: conventions(app) },
|
|
@@ -252,7 +256,7 @@ export function docsFiles(app: NameSet): readonly GeneratedFile[] {
|
|
|
252
256
|
...binFiles(),
|
|
253
257
|
{ path: 'docker/docker-compose.dev.yml', contents: composeDev(app) },
|
|
254
258
|
// What the suites run against — in RAM, silent; ci.yml starts it before the gate.
|
|
255
|
-
...testServicesFiles(app),
|
|
259
|
+
...testServicesFiles(app, root),
|
|
256
260
|
// The harness half of the same job AGENTS.md does. It lands in the app's own repo rather than
|
|
257
261
|
// in a global config, so it is visible in the scaffold's diff and deletable in one line.
|
|
258
262
|
...claudeFiles(app),
|
|
@@ -46,8 +46,25 @@ export const LINE_ENDING_ATTRIBUTES = `# Every text file is LF, in the index and
|
|
|
46
46
|
${BINARY_EXTENSIONS.map((extension) => `*.${extension} binary`).join('\n')}
|
|
47
47
|
`;
|
|
48
48
|
|
|
49
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* How two branches' features merge. `bunx x merge-driver install` (a step of `bun run setup`) defines
|
|
51
|
+
* the drivers in `.git/config`; a clone without them gets git's ordinary text merge, so nothing here
|
|
52
|
+
* can lose work. Also carried into existing apps by the `merge-drivers` codemod.
|
|
53
|
+
*/
|
|
54
|
+
export const MERGE_ATTRIBUTES = `# Merging two features. x-registry keeps what both branches added and leaves a real conflict alone;
|
|
55
|
+
# x-generated keeps our copy of a projection, which \`bunx x manifest\` then rebuilds.
|
|
56
|
+
apps/web/api/index.ts merge=x-registry
|
|
57
|
+
apps/web/exercise.ts merge=x-registry
|
|
58
|
+
apps/web/shared/roles.ts merge=x-registry
|
|
59
|
+
packages/db/src/client.ts merge=x-registry
|
|
60
|
+
packages/i18n/catalogs/*.json merge=x-registry
|
|
61
|
+
x.manifest.json merge=x-generated
|
|
62
|
+
openapi.json merge=x-generated
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
/** The app's root file: the shared block, the merge rules, the generated file git should collapse. */
|
|
50
66
|
export const rootGitattributes = (): string => `${LINE_ENDING_ATTRIBUTES}
|
|
67
|
+
${MERGE_ATTRIBUTES}
|
|
51
68
|
# Bun's lockfile. Regenerated by \`bun install\`, never edited by hand.
|
|
52
69
|
bun.lock -diff linguist-generated=true
|
|
53
70
|
`;
|
|
@@ -86,6 +86,15 @@ nobody bound. Derived here rather than stated twice in values.yaml, where the tw
|
|
|
86
86
|
value: {{ $root.Values.metricsPort | quote }}
|
|
87
87
|
{{- end }}
|
|
88
88
|
{{- /*
|
|
89
|
+
One process per pod: per-pod parallelism is the HPA's. This chart sets CPU requests only, so
|
|
90
|
+
auto already resolves to 1; the pin makes the count explicit, and a CPU limit added later
|
|
91
|
+
cannot change it. env.ULTIMATE_PROCESSES wins when set.
|
|
92
|
+
*/}}
|
|
93
|
+
{{- if not (hasKey $root.Values.env "ULTIMATE_PROCESSES") }}
|
|
94
|
+
- name: ULTIMATE_PROCESSES
|
|
95
|
+
value: "1"
|
|
96
|
+
{{- end }}
|
|
97
|
+
{{- /*
|
|
89
98
|
The sync node's page origin, from the one place this chart already knows it. Undeclared, a node
|
|
90
99
|
reached over plain http behind this Ingress admits BOTH spellings of its host — the plain-http
|
|
91
100
|
page included. env.APP_URL wins when set; an APP_URL kept in the Secret is shadowed for this
|
|
@@ -107,6 +107,7 @@ const rootPackage = (app: NameSet, version: string): string => `{
|
|
|
107
107
|
"@ultimat3/policy": "${version}",
|
|
108
108
|
"@ultimat3/pwa": "${version}",
|
|
109
109
|
"@ultimat3/query": "${version}",
|
|
110
|
+
"@ultimat3/realtime": "${version}",
|
|
110
111
|
"@ultimat3/render": "${version}",
|
|
111
112
|
"@ultimat3/schema": "${version}",
|
|
112
113
|
"@ultimat3/seo": "${version}",
|
|
@@ -384,9 +385,11 @@ export function repoFiles(
|
|
|
384
385
|
app: NameSet,
|
|
385
386
|
version: string,
|
|
386
387
|
example: boolean,
|
|
388
|
+
/** The app's directory, when known: the test stack's name and ports (`scaffold-test-services`). */
|
|
389
|
+
root?: string,
|
|
387
390
|
): readonly GeneratedFile[] {
|
|
388
391
|
return [
|
|
389
|
-
...docsFiles(app),
|
|
392
|
+
...docsFiles(app, root),
|
|
390
393
|
{ path: 'package.json', contents: rootPackage(app, version) },
|
|
391
394
|
{ path: 'tsconfig.json', contents: rootTsconfig(app) },
|
|
392
395
|
{ path: 'biome.json', contents: biome() },
|
|
@@ -18,14 +18,19 @@ export const TEST_PORT_SPREAD = 500;
|
|
|
18
18
|
|
|
19
19
|
type TestPorts = { readonly [K in keyof typeof TEST_PORTS]: number };
|
|
20
20
|
|
|
21
|
+
/** The app's name, and the checkout's root when the scaffold knows it: what keys its own stack. */
|
|
22
|
+
const stackKey = (app: NameSet, root: string | undefined): string =>
|
|
23
|
+
root === undefined ? app.kebab : `${app.kebab}\0${root}`;
|
|
24
|
+
|
|
21
25
|
/**
|
|
22
26
|
* This app's host ports, one place: the compose file publishes them and the env file names them.
|
|
23
27
|
* One fixed set made two scaffolds on one machine share 55432, so the second app's live suites
|
|
24
|
-
* dialled the first app's container; the app's name
|
|
28
|
+
* dialled the first app's container; the app's name — and its root, when the scaffold knows it, so
|
|
29
|
+
* two scaffolds of one name differ too — picks its offset into each band.
|
|
25
30
|
*/
|
|
26
|
-
export const testPorts = (app: NameSet): TestPorts => {
|
|
27
|
-
// FNV-1a
|
|
28
|
-
const offset = fnv1a(app
|
|
31
|
+
export const testPorts = (app: NameSet, root?: string): TestPorts => {
|
|
32
|
+
// FNV-1a: stable across machines and runs.
|
|
33
|
+
const offset = fnv1a(stackKey(app, root)) % TEST_PORT_SPREAD;
|
|
29
34
|
return {
|
|
30
35
|
postgres: TEST_PORTS.postgres + offset,
|
|
31
36
|
redis: TEST_PORTS.redis + offset,
|
|
@@ -34,9 +39,21 @@ export const testPorts = (app: NameSet): TestPorts => {
|
|
|
34
39
|
};
|
|
35
40
|
};
|
|
36
41
|
|
|
42
|
+
/**
|
|
43
|
+
* The compose project, written into the file as its `name:` — so every reader (`x verify`,
|
|
44
|
+
* `x clean --services`, CI, a hand-typed `docker compose -f`) resolves the same one, and a name
|
|
45
|
+
* an app wrote itself is never second-guessed. `<app>-test` alone made every scaffold of one name
|
|
46
|
+
* on one machine one project; with the root, each scaffold's is its own (clones of it share it).
|
|
47
|
+
*/
|
|
48
|
+
export const testProjectName = (app: NameSet, root?: string): string =>
|
|
49
|
+
root === undefined
|
|
50
|
+
? `${app.kebab}-test`
|
|
51
|
+
: `${app.kebab}-test-${fnv1a(root).toString(16).padStart(8, '0')}`;
|
|
52
|
+
|
|
37
53
|
const composeTest = (
|
|
38
54
|
app: NameSet,
|
|
39
|
-
|
|
55
|
+
root: string | undefined,
|
|
56
|
+
ports: TestPorts = testPorts(app, root),
|
|
40
57
|
): string => `# The services the test suites run against — in RAM, and silent.
|
|
41
58
|
#
|
|
42
59
|
# docker compose -f ${TEST_COMPOSE_PATH} up -d --wait
|
|
@@ -58,7 +75,7 @@ const composeTest = (
|
|
|
58
75
|
# watch one that will not start, run it attached: \`docker compose -f ${TEST_COMPOSE_PATH} up postgres\`.
|
|
59
76
|
#
|
|
60
77
|
# Every port binds 127.0.0.1: the credentials are in this file.
|
|
61
|
-
name: ${app
|
|
78
|
+
name: ${testProjectName(app, root)}
|
|
62
79
|
|
|
63
80
|
x-silent: &silent
|
|
64
81
|
logging: { driver: none }
|
|
@@ -151,7 +168,8 @@ services:
|
|
|
151
168
|
|
|
152
169
|
const testEnv = (
|
|
153
170
|
app: NameSet,
|
|
154
|
-
|
|
171
|
+
root: string | undefined,
|
|
172
|
+
ports: TestPorts = testPorts(app, root),
|
|
155
173
|
): string => `# Where the suites find the services ${TEST_COMPOSE_PATH} starts — the one place these URLs are
|
|
156
174
|
# written. A laptop sources it (\`set -a; . ${TEST_ENV_PATH}; set +a\`); CI appends it to $GITHUB_ENV.
|
|
157
175
|
# TEST_DATABASE_URL is what @ultimat3/testing clones one database per test worker from.
|
|
@@ -161,10 +179,14 @@ TEST_NATS_URL=nats://127.0.0.1:${ports.nats}
|
|
|
161
179
|
TEST_S3_URL=http://${app.kebab}:${app.kebab}-test@127.0.0.1:${ports.s3}/${app.kebab}-test
|
|
162
180
|
`;
|
|
163
181
|
|
|
164
|
-
/**
|
|
165
|
-
|
|
182
|
+
/**
|
|
183
|
+
* The test stack and its env file. `root`, the absolute directory `x new` writes into, makes the
|
|
184
|
+
* project name and ports this scaffold's own; without it the bytes are the name-only ones every
|
|
185
|
+
* earlier scaffold wrote, which the codemods compare against.
|
|
186
|
+
*/
|
|
187
|
+
export function testServicesFiles(app: NameSet, root?: string): readonly GeneratedFile[] {
|
|
166
188
|
return [
|
|
167
|
-
{ path: TEST_COMPOSE_PATH, contents: composeTest(app) },
|
|
168
|
-
{ path: TEST_ENV_PATH, contents: testEnv(app) },
|
|
189
|
+
{ path: TEST_COMPOSE_PATH, contents: composeTest(app, root) },
|
|
190
|
+
{ path: TEST_ENV_PATH, contents: testEnv(app, root) },
|
|
169
191
|
];
|
|
170
192
|
}
|