@ultimat3/cli 30.8.0 → 31.0.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.
Files changed (197) hide show
  1. package/CLAUDE.md +75 -64
  2. package/README.md +4 -1
  3. package/package.json +30 -29
  4. package/src/admin-registration.ts +1 -1
  5. package/src/affected.ts +5 -1
  6. package/src/app-boundaries.ts +88 -9
  7. package/src/app-load-async.ts +133 -0
  8. package/src/app-load-batch.ts +203 -0
  9. package/src/app-load-prebuilt.ts +147 -0
  10. package/src/app-load-register.ts +175 -0
  11. package/src/app-load.ts +143 -175
  12. package/src/app-loader-imports.ts +31 -0
  13. package/src/app-root.ts +13 -0
  14. package/src/app-runtime.ts +5 -1
  15. package/src/boundary-findings.ts +12 -0
  16. package/src/browser-launcher-port.ts +3 -7
  17. package/src/browser-launcher.ts +1 -1
  18. package/src/budgets-scan.ts +8 -0
  19. package/src/budgets.ts +10 -1
  20. package/src/build-registry-background.ts +59 -0
  21. package/src/build-registry.ts +207 -0
  22. package/src/cdp-shot-clock.ts +3 -11
  23. package/src/cdp-shot-driver.ts +3 -2
  24. package/src/cdp-shot-element.ts +3 -2
  25. package/src/cdp-shot-page.ts +2 -2
  26. package/src/cdp-shot-watch.ts +4 -3
  27. package/src/cmd-auth.ts +3 -3
  28. package/src/cmd-db-recount.ts +15 -0
  29. package/src/cmd-drill.ts +10 -6
  30. package/src/cmd-exercise.ts +2 -1
  31. package/src/cmd-generate-spec.ts +6 -0
  32. package/src/cmd-generate.ts +22 -4
  33. package/src/cmd-mail.ts +1 -1
  34. package/src/cmd-routes.ts +2 -2
  35. package/src/cmd-secrets-spec.ts +4 -1
  36. package/src/cmd-shot.ts +14 -4
  37. package/src/cmd-verify-spec.ts +21 -1
  38. package/src/cmd-verify.ts +16 -4
  39. package/src/coverage-source.ts +4 -1
  40. package/src/db-diagnostics.ts +8 -1
  41. package/src/dev-boot.ts +29 -15
  42. package/src/dev-dashboard-invalidations.ts +43 -0
  43. package/src/dev-dashboard.ts +13 -16
  44. package/src/dev-n-plus-one.ts +7 -3
  45. package/src/dev-rebuild.ts +2 -1
  46. package/src/dev-route-table.ts +1 -1
  47. package/src/dev-traces.ts +16 -15
  48. package/src/document-options.ts +12 -1
  49. package/src/drift-store.ts +55 -0
  50. package/src/error-catalog.ts +8 -3
  51. package/src/error-codes-boundary.ts +32 -0
  52. package/src/error-codes.ts +23 -19
  53. package/src/errors.ts +17 -7
  54. package/src/exercise-database.ts +13 -1
  55. package/src/exercise-findings.ts +36 -18
  56. package/src/exercise-services.ts +84 -0
  57. package/src/exercise-subject.ts +38 -13
  58. package/src/failure-capture-boot.ts +9 -5
  59. package/src/framework-schema.ts +5 -5
  60. package/src/generate-exercise.ts +1 -1
  61. package/src/generate-files.ts +27 -7
  62. package/src/generate-kinds.ts +5 -0
  63. package/src/generate-refresh.ts +53 -0
  64. package/src/generate-workspace.ts +169 -0
  65. package/src/generate-write.ts +8 -2
  66. package/src/hold.ts +19 -8
  67. package/src/image-prepare.ts +6 -2
  68. package/src/index.ts +5 -20
  69. package/src/island-bundle.ts +7 -3
  70. package/src/island-capture.ts +2 -2
  71. package/src/island-harness.ts +1 -1
  72. package/src/job-registration.ts +43 -6
  73. package/src/jobs-driver.ts +4 -5
  74. package/src/mcp-errors.ts +18 -4
  75. package/src/mcp-host.ts +5 -1
  76. package/src/mcp-ui-interact.ts +3 -0
  77. package/src/messages-gate.ts +4 -0
  78. package/src/new-shapes-generate.ts +1 -1
  79. package/src/otlp-export.ts +94 -29
  80. package/src/output.ts +3 -7
  81. package/src/page-sync.ts +3 -1
  82. package/src/role-load.ts +17 -11
  83. package/src/role-start.ts +5 -4
  84. package/src/role-sync.ts +7 -8
  85. package/src/route-islands-preload.ts +46 -0
  86. package/src/route-islands.ts +6 -2
  87. package/src/runtime-admin.ts +5 -1
  88. package/src/runtime-bindings.ts +25 -19
  89. package/src/runtime-boot-ports.ts +66 -0
  90. package/src/runtime-bus.ts +29 -5
  91. package/src/runtime-cache-bus.ts +53 -0
  92. package/src/runtime-cache.ts +43 -13
  93. package/src/runtime-isr-outcome.ts +5 -4
  94. package/src/runtime-jobs.ts +2 -2
  95. package/src/runtime-keys.ts +37 -0
  96. package/src/runtime-overrides.ts +148 -42
  97. package/src/runtime-port-bindings-queue.ts +36 -0
  98. package/src/runtime-port-bindings.ts +117 -0
  99. package/src/runtime-ports.ts +164 -0
  100. package/src/runtime-purge.ts +41 -28
  101. package/src/runtime-push.ts +7 -3
  102. package/src/runtime-queue.ts +70 -55
  103. package/src/runtime-realtime.ts +5 -5
  104. package/src/runtime-render-document.ts +4 -1
  105. package/src/runtime-services.ts +110 -158
  106. package/src/runtime-storage-boot.ts +111 -0
  107. package/src/runtime-storage-upload.ts +9 -7
  108. package/src/runtime-storage.ts +7 -1
  109. package/src/serve-boot.ts +8 -4
  110. package/src/serve-entry.ts +3 -0
  111. package/src/serve-env.ts +47 -14
  112. package/src/serve-prebuilt-paths.ts +3 -0
  113. package/src/serve-prebuilt.ts +15 -4
  114. package/src/serve.ts +2 -2
  115. package/src/static-cards.ts +3 -2
  116. package/src/static-report.ts +2 -2
  117. package/src/style-bundle.ts +1 -1
  118. package/src/sync-authenticator.ts +17 -18
  119. package/src/templates/action-tests.ts +4 -4
  120. package/src/templates/backfill.ts +5 -8
  121. package/src/templates/entity.ts +3 -0
  122. package/src/templates/github/ci.yml.ts +3 -1
  123. package/src/templates/github/dependabot.yml.ts +73 -0
  124. package/src/templates/job.ts +13 -22
  125. package/src/templates/naming.ts +20 -1
  126. package/src/templates/pinned/docker-compose.yml +1 -1
  127. package/src/templates/query.ts +7 -8
  128. package/src/templates/route.ts +5 -3
  129. package/src/templates/scaffold-api.ts +1 -1
  130. package/src/templates/scaffold-auth.ts +5 -3
  131. package/src/templates/scaffold-claude-commands.ts +6 -3
  132. package/src/templates/scaffold-claude.ts +4 -4
  133. package/src/templates/scaffold-container-compose.ts +2 -4
  134. package/src/templates/scaffold-domain-package.ts +1 -1
  135. package/src/templates/scaffold-entries.ts +6 -1
  136. package/src/templates/scaffold-helm-fences.ts +3 -2
  137. package/src/templates/scaffold-helm.ts +35 -6
  138. package/src/templates/scaffold-repo.ts +47 -135
  139. package/src/templates/scaffold-runtime-ports.ts +62 -0
  140. package/src/templates/scaffold-verify-floor.ts +97 -0
  141. package/src/templates/shapes/overlay.ts +1 -1
  142. package/src/templates/sign-in-oidc.ts +5 -3
  143. package/src/templates/sign-in-shared.ts +28 -10
  144. package/src/templates/workspace.ts +75 -0
  145. package/src/test-ignores.ts +5 -2
  146. package/src/test-select.ts +4 -1
  147. package/src/upgrade-gate.ts +30 -5
  148. package/src/upgrade-report.ts +7 -1
  149. package/src/verify-changed-facts.ts +53 -0
  150. package/src/verify-changed-scope.ts +161 -0
  151. package/src/verify-changed.ts +174 -0
  152. package/src/verify-checks.ts +31 -19
  153. package/src/verify-drift-owner.ts +30 -0
  154. package/src/verify-e2e.ts +2 -1
  155. package/src/verify-factories.ts +86 -0
  156. package/src/verify-run.ts +13 -11
  157. package/src/verify-step.ts +13 -0
  158. package/src/verify-tests.ts +58 -6
  159. package/src/write-line.ts +21 -6
  160. package/wiki/Actions.md +2 -2
  161. package/wiki/Adapters.md +400 -0
  162. package/wiki/Admin-Dashboard.md +2 -1
  163. package/wiki/Agents.md +9 -9
  164. package/wiki/Auth.md +78 -2
  165. package/wiki/Building-Your-Own-Base.md +1 -1
  166. package/wiki/CLI-Reference.md +34 -7
  167. package/wiki/Caching-And-Invalidation.md +17 -5
  168. package/wiki/Compared.md +8 -2
  169. package/wiki/Configuration.md +14 -14
  170. package/wiki/Deployment.md +28 -1
  171. package/wiki/Entities-And-Migrations.md +48 -2
  172. package/wiki/FAQ.md +8 -2
  173. package/wiki/Feature-Flags.md +1 -1
  174. package/wiki/Home.md +3 -2
  175. package/wiki/Jobs-And-Workflows.md +107 -6
  176. package/wiki/Known-Gaps.md +4 -3
  177. package/wiki/MCP-And-AI.md +18 -4
  178. package/wiki/Mail.md +14 -5
  179. package/wiki/Migrations-And-Backfills.md +31 -4
  180. package/wiki/Money.md +2 -0
  181. package/wiki/N-Plus-One-Detection.md +24 -22
  182. package/wiki/Notify.md +28 -4
  183. package/wiki/Observability.md +121 -15
  184. package/wiki/Queries-And-Live-Queries.md +2 -2
  185. package/wiki/Realtime.md +9 -4
  186. package/wiki/Routes-And-Render-Modes.md +5 -0
  187. package/wiki/Scraping.md +57 -11
  188. package/wiki/Shapes.md +2 -2
  189. package/wiki/Stability.md +7 -5
  190. package/wiki/Storage-And-Uploads.md +56 -4
  191. package/wiki/Testing.md +69 -56
  192. package/wiki/Troubleshooting.md +1 -1
  193. package/wiki/Tutorial-01-First-App.md +1 -1
  194. package/wiki/Tutorial-04-Jobs-And-Realtime.md +1 -1
  195. package/wiki/Tutorial-05-Deploy-Free.md +1 -1
  196. package/wiki/Tutorial-06-Growing-Up.md +8 -8
  197. package/wiki/Upgrading.md +129 -4
package/wiki/Testing.md CHANGED
@@ -91,8 +91,8 @@ Any test that can pass twice and fail the third time is worse than no test — i
91
91
  | **Seeds** | `seed(name)` builds a named, deterministic fixture graph via entity factories. Same input → identical rows, identical UUIDs |
92
92
  | **Frozen clock** | time starts at a fixed instant. `clock.advance('3d')` moves it, and it also drives `step.sleep` and cron in tests |
93
93
  | **Seeded RNG** | `Math.random`, `crypto.randomUUID`, and Bun's RNG are seeded per test file from its path — reproducible, distinct across files |
94
- | **Sealed network** | a `fetch`, a `new WebSocket(…)` or a `Bun.connect(…)` to anywhere not explicitly mocked or allowed **fails the test** with `X_TEST_NETWORK_SEALED`, naming the URL and the fix — the three dials share one gate, so the allow-list and `offline()` apply to all of them — `offline()` refuses a loopback dial too (`X_TEST_NETWORK_OFFLINE`). A dial that goes around those three globals (a `node:net` socket, `Bun.udpSocket`) is not sealed |
95
- | **Sealed names** | `Bun.dns.lookup`, `dns.lookup` and `dns.promises.lookup` ask the same gate: a host a `mockFetch` route names resolves to `MOCKED_HOST_ADDRESS` (`11.11.11.11`, public, so an SSRF screen such as `screenDial` passes it and the dial it pins still meets the mock by its `Host`); this machine, an address literal and an `allowHost` name resolve for real; offline refuses every name (`X_TEST_NETWORK_OFFLINE`); any other name is `X_TEST_NETWORK_SEALED`. A RegExp route names a host it matches at the origin or spells in its source. Not covered: `lookup` bound by a named ESM import (`import { lookup } from 'node:dns'`) before the seal, and `dns.resolve*` |
94
+ | **Sealed network** | a `fetch`, a `new WebSocket(…)`, a `Bun.connect(…)` or a `node:net` / `node:tls` / `node:http` / `node:https` / `node:http2` connection (all dial through `net.Socket#connect`, sealed there) to anywhere not explicitly mocked or allowed **fails the test** with `X_TEST_NETWORK_SEALED`, naming the URL and the fix — every dial shares one gate, so the allow-list (`allowHost('host:port')` for a socket) and `offline()` apply to all of them — `offline()` refuses a loopback dial too (`X_TEST_NETWORK_OFFLINE`). A `node:*` refusal is the socket's `error` event, as a failed real dial is. A `mockFetch` route answers `fetch` only: a `node:http` request to a mocked host is refused, never dialled. A `Bun.udpSocket` send (and `node:dgram`, which sends through it) asks the same gate per datagram, the connected peer included: a refusal throws from `send`/`sendMany` as Bun's own UDP failures do, a refused `connect` option rejects, and `dgram` hands it to the send callback — or emits `error` when there is none. A unix socket is never sealed |
95
+ | **Sealed names** | Every resolution path asks the same gate — `lookup`, every `resolve*`, `reverse`, `lookupService` (by `node:dns`, `node:dns/promises` or `Bun.dns`, a named import bound before the seal included), both `Resolver` classes and `Bun.dns.prefetch`: a host a `mockFetch` route names answers an address query (`lookup`, `A`, `ANY`) with `MOCKED_HOST_ADDRESS` (`11.11.11.11`, public, so an SSRF screen such as `screenDial` passes it and the dial it pins still meets the mock by its `Host`) and any other record type (`MX`, `TXT`, …) with `X_TEST_NETWORK_SEALED` — a mock declares an endpoint, not a zone; this machine, an `allowHost` name and a `lookup` of an address literal resolve for real (a `reverse` of a public address is sealed: it is a query); offline refuses every name (`X_TEST_NETWORK_OFFLINE`); any other name is `X_TEST_NETWORK_SEALED` — its fix opens with `mockFetch(…)` for an address query and with `allowHost('<name>')` for a record or reverse query, which no mock answers. A RegExp route names a host it matches at the origin or spells in its source |
96
96
  | **Fixed timezone + locale** | `UTC` and `en-US` unless a test declares otherwise; a tz-dependent bug fails deterministically |
97
97
  | **Ordered concurrency** | job workers in tests run deterministically; `runJobs()` drains the queue synchronously |
98
98
  | **Per-test reset** | before EVERY test, not every file, the preload puts the jobs event bus back (`installPerTestReset()`): an answer one test published never resumes the next test's waiting run, with or without `runJobs`. A test that never loaded `@ultimat3/jobs` pays nothing. `As of 2026-10` |
@@ -619,7 +619,8 @@ A `compensates: true` job is also forced to fail for good and killed while it un
619
619
  `echoProvider()` answers text; it cannot call a tool. A test that drives an `agent()` through its tools scripts the model with `scriptedProvider({ turns })`: each provider call answers the next turn, and `.seen` keeps every request in order.
620
620
 
621
621
  ```ts
622
- import { configureAi, meteredRun, providerGateway, scriptedProvider } from '@ultimat3/ai';
622
+ import { meteredRun, providerGateway, scriptedProvider } from '@ultimat3/ai';
623
+ import { installAiGateway } from '@ultimat3/ai/adapter';
623
624
 
624
625
  declare const draft: { id: string; orgId: string };
625
626
  declare function reviewDraft(input: { postId: string; orgId: string }): Promise<unknown>;
@@ -631,7 +632,7 @@ const model = scriptedProvider({
631
632
  { answer: { verdict: 'revise', notes: 'Say which rounding rule the body defends.' } },
632
633
  ],
633
634
  });
634
- configureAi({ gateway: providerGateway({ providers: [model] }) });
635
+ const release = installAiGateway(providerGateway({ providers: [model] })); // release() in the afterEach
635
636
 
636
637
  // The agent's turns and its tool's model call, as one bill: three calls.
637
638
  const { billed } = await meteredRun(() => reviewDraft({ postId: draft.id, orgId: draft.orgId }));
@@ -747,7 +748,7 @@ empty `users` are `X_INVARIANT`.
747
748
 
748
749
  ## Log lines under test
749
750
 
750
- | `LOG_LEVEL` | The terminal shows | A `setLogSink` a test installs receives |
751
+ | `LOG_LEVEL` | The terminal shows | A sink a test installs with `installLogSink` receives |
751
752
  |---|---|---|
752
753
  | unset | nothing | `info` and above |
753
754
  | `info` · `debug` · `trace` | that level and above | that level and above |
@@ -759,7 +760,7 @@ terminal and never the logger, so a test asserting on an `info` audit line passe
759
760
 
760
761
  ## An N+1 fails the test it happened in
761
762
 
762
- `x dev` warns about a query loop; CI is where nobody is watching. Destructuring `statements` installs the same detector in **throw** mode for the length of one test:
763
+ `x dev` warns about a query loop; CI is where nobody is watching. Destructuring `statements` installs the same detector in **strict** mode for the length of one test:
763
764
 
764
765
  ```ts
765
766
  test('the feed reads its authors once', async ({ statements }) => {
@@ -770,7 +771,7 @@ test('the feed reads its authors once', async ({ statements }) => {
770
771
  });
771
772
  ```
772
773
 
773
- The loop's fifth statement is what rejects, so the failing line is the loop's own — not a summary at teardown. Opting in is naming the fixture: there is no `strict: true` to remember and no switch left on for the next file.
774
+ The loop runs to its end and the verdict is raised when the fixture is disposed — the bus never lets an observer fail the read it observes — naming the shape and its count; `statements.verdicts()` reads it earlier. Opting in is naming the fixture: there is no `strict: true` to remember and no switch left on for the next file.
774
775
 
775
776
  | What | Rule |
776
777
  |---|---|
@@ -789,64 +790,73 @@ await expectedQueryLoop('one indexed lookup per searchable field', () => searchE
789
790
 
790
791
  ## Factories
791
792
 
792
- One row shape per entity, deterministic, with named variations. `defineFactory` is the only entry point — there is no bare `factory()`.
793
+ One row shape per entity, deterministic, with named variations, FactoryBot-grade (`As of 31.0.0`). `defineFactory` is the only entry point — there is no bare `factory()`.
793
794
 
794
795
  ```ts
795
- import { associate, defineFactory } from '@ultimat3/testing';
796
- import { boolean, entity, integer, text, uuid } from '@ultimat3/entity';
796
+ import { belongsTo, defineFactory, hasMany } from '@ultimat3/testing';
797
+ import { entity, text, timestamp, uuid } from '@ultimat3/entity';
797
798
 
798
- const org = entity('orgs', { columns: { id: uuid().primaryKey(), name: text() } });
799
- const post = entity('posts', {
799
+ const orgs = entity('orgs', {
800
+ columns: { id: uuid().primaryKey(), slug: text(), name: text() },
801
+ });
802
+ const posts = entity('posts', {
800
803
  columns: {
801
804
  id: uuid().primaryKey(),
802
- orgId: uuid().references(() => org.id).tenant(), // the column `associations` fills
805
+ orgId: uuid().references(() => orgs.id).tenant(),
806
+ slug: text(),
803
807
  title: text(),
804
- published: boolean().default(false),
805
- views: integer().default(0),
808
+ status: text().default('draft'),
809
+ publishedAt: timestamp().nullable(),
806
810
  },
807
811
  });
808
-
809
- const orgFactory = defineFactory(org, {
810
- defaults: (index, ids) => ({ id: ids.uuid(), name: `org-${index}` }),
812
+ const comments = entity('comments', {
813
+ columns: {
814
+ id: uuid().primaryKey(),
815
+ orgId: uuid().references(() => orgs.id).tenant(),
816
+ postId: uuid().references(() => posts.id),
817
+ body: text(),
818
+ },
811
819
  });
812
820
 
813
- const postFactory = defineFactory(post, {
814
- // `defaults` names every column; `associations` replaces `orgId` with the parent's id.
815
- defaults: (index, ids) => ({
816
- id: ids.uuid(),
817
- orgId: '',
818
- title: `post-${index}`,
819
- published: false,
820
- views: 0,
821
- }),
822
- traits: {
823
- published: { published: true },
824
- popular: (index) => ({ views: index * 100 }),
821
+ const orgFactory = defineFactory(orgs, {
822
+ defaults: (n, ids) => ({ id: ids.uuid(), slug: `org-${n}`, name: `Org ${n}` }),
823
+ });
824
+ const postBase = defineFactory(posts, {
825
+ defaults: (n, ids) => ({ id: ids.uuid(), orgId: '', slug: `post-${n}`, title: `Post ${n}` }),
826
+ traits: { published: { status: 'published', publishedAt: new Date('2026-01-05T09:00:00Z') } },
827
+ transient: { shout: false },
828
+ belongsTo: { org: belongsTo(orgFactory, 'orgId') },
829
+ afterBuild: (post, { transient }) => {
830
+ if (transient.shout) post.title = post.title.toUpperCase();
825
831
  },
826
- associations: { orgId: associate(orgFactory, (row) => row.id) },
827
832
  });
833
+ const commentFactory = defineFactory(comments, {
834
+ defaults: (n, ids) => ({ id: ids.uuid(), orgId: '', postId: '', body: `Comment ${n}` }),
835
+ belongsTo: { post: belongsTo(postBase, 'postId') },
836
+ });
837
+ const postFactory = postBase.extend({ hasMany: { comments: hasMany(commentFactory, 'postId') } });
838
+
839
+ postFactory.build(); // memory: org built alongside, nothing written
840
+ const post = await postFactory.with('published').create({ comments: 2 }); // the STORED row
841
+ const org = await orgFactory.create();
842
+ await postFactory.createList(3, { org }); // reuses that org, makes none
843
+ postFactory.attributesFor(); // an action input: no id, no orgId
828
844
  ```
829
845
 
830
- | Member | Does |
846
+ | | |
831
847
  |---|---|
832
- | `build(over?)` | an in-memory row. Pure — no database, no persister |
833
- | `buildMany(count, over?)` | the same, `count` times |
834
- | `create(over?)` | builds, creates its association parents, then persists. Returns the row |
835
- | `createMany(count, over?)` | the same, `count` times |
836
- | `with(...traits)` | a view with those traits applied |
837
- | `traits` | the declared trait names, sorted |
838
- | `table` | the entity's table |
839
- | `reset()` | restarts the sequence and both generators, and **cascades to every association** |
840
-
841
- ### Traits
842
-
843
- A trait is a `Partial<Row>` or a `(index, ids) => Partial<Row>`. Merge order is: defaults, then traits in the order applied, then the call's own `over` — last wins.
844
-
845
- A view from `with()` **shares the base sequence**, so ids never repeat across views of one factory. An unknown trait throws `X_TEST_FACTORY_TRAIT_UNKNOWN` **at the `with()` call**, not three calls later, and `cause` lists every declared trait — a typo and a trait nobody added have the same symptom, and the list is what separates them.
846
-
847
- ### Associations
848
-
849
- A column whose value comes from another factory, built with the **same strategy**: `build()` builds the parent, `create()` creates it. Parents are created **sequentially, never `Promise.all`** — concurrent parents would interleave draws from the shared seeded generators and the ids would stop being reproducible. An association is skipped entirely when the caller supplies that column.
848
+ | **strategies** | `build` (memory, never a database), `create` (writes, answers the row AS STORED: declared defaults, generated columns, timestamps), `attributesFor` (an input: no primary key, no `belongsTo` key, no transient), `buildList` / `createList` |
849
+ | **sequence** | `index` (`n` above), per factory, shared by every `with()` view and `extend()` child — ids never repeat |
850
+ | **trait** | a named partial (or `(n, ids, transient) => partial`). `with('a', 'b')` composes left to right; a call's override wins. An undeclared one fails at `with()` (`X_TEST_FACTORY_TRAIT_UNKNOWN`), and `cause` lists every declared trait |
851
+ | **transient** | declared defaults a call may override; read by `defaults`, traits and callbacks; never written |
852
+ | **callbacks** | `afterBuild(row, ctx)` on both strategies before any write; `afterCreate(storedRow, ctx)` after the row and its children are stored |
853
+ | **inheritance** | `factory.extend({ defaults, traits, transient, hasMany, afterBuild, afterCreate })` — same table, same sequence, its defaults over the parent's, callbacks chained after |
854
+ | **`belongsTo`** | the parent made with the child's strategy; `{ org: row }` reuses a row; `{ orgId }` makes none. The `defaults` must name the key, so a key that is not a column does not compile. Parents are made **sequentially, never `Promise.all`**: concurrent parents would interleave draws from the seeded generators |
855
+ | **`hasMany`** | `{ comments: 2 }` or `{ comments: [{ body: 'a' }, {}] }`: made after the parent, key set from the stored parent; on the answer as a non-enumerable `post.comments`, so the row itself `toEqual`s a read of the table |
856
+ | **tenant** | the tenant column follows the parent; the tenant's own association resolves first, so a comment, its post and its post's org share one org |
857
+ | **seeded per table** | the default seed is derived from the table name, so two tables never draw the same uuid |
858
+ | **lint** | `await assertFactoriesValid({ orgFactory, postFactory, … })` (or `lintFactories`, which answers the findings): every factory and each trait alone, built and created against its entity on a throwaway driver; one `X_TEST_FACTORY_INVALID` naming each `factory.with('trait').strategy()` and the entity's own code |
859
+ | **seeds** | `factorySeed('demo', async ({ id }) => { await postFactory.create({ org: await orgFactory.create({ id: id('org:acme') }) }) })` is a `Seed` (`x db seed demo`, or `.run({ driver })`): every sequence restarts, every write is the seed's idempotent insert — a replay writes nothing |
850
860
 
851
861
  ### Determinism
852
862
 
@@ -858,14 +868,17 @@ A column whose value comes from another factory, built with the **same strategy*
858
868
 
859
869
  ### Persisting
860
870
 
861
- `create()` needs a persister; there is one seam and it is process-global.
871
+ `create()` writes through the entity's own repository on `defaultDriver()` — no setup for an app on the default driver. An app that names its own driver installs it once, in its test preload:
862
872
 
863
873
  ```ts
864
874
  // scripts/test-setup.ts
865
- usePersister({ insert: (table, row) => repoFor(table).insert(row) });
875
+ import { entityPersister, usePersister } from '@ultimat3/testing';
876
+ import { driver } from '@app/db';
877
+
878
+ usePersister(entityPersister({ driver })); // or { client }
866
879
  ```
867
880
 
868
- Without one, `create()` throws `X_TEST_FACTORY_NOT_PERSISTED` — which means **nothing was attempted**, distinct from an insert that failed. `build()` needs no persister. `clearPersister()` and `persisterInstalled()` round out the seam.
881
+ `build()` needs no persister. `clearPersister()` and `persisterInstalled()` round out the seam.
869
882
 
870
883
  ### A whole graph: `seedGraph`
871
884
 
@@ -930,7 +943,7 @@ describe(testName('unit', 'publishPost'), () => {
930
943
 
931
944
  `behavesLike` wraps the body in `describe('behaves like <name>')`, so a failure reads `publishPost > behaves like an authenticated action > denies an anonymous actor` — the subject and the contract both named. Because it calls `describe`, it belongs at declaration scope and never inside a test body. The body runs once per `behavesLike` call.
932
945
 
933
- Two contracts ship as shared examples, for the ports an app may implement itself: `behavesLike(jobDriverConformance, () => myDriver)` holds a custom `JobDriver` to claim / ack / nack, the claim fence, lease expiry and the burial of a row whose lease lapsed on its final attempt (`onExhausted`, `dropExhausted`); `behavesLike(budgetStoreConformance, () => myStore)` races 24 concurrent `take`s on one key against an `@ultimat3/ai` `BudgetStore`. The memory and Postgres job drivers and `memoryBudgetStore()` run the same suites in `@ultimat3/testing`'s own tests.
946
+ Every adapter port's contract ships as shared examples on `@ultimat3/testing/conformance` — never `.` (31.0.0, Upgrading #46), one suite per `ADAPTER_PORTS` row, named as its `conformance` field: `behavesLike(jobDriverConformance, () => myDriver)` holds a custom `JobDriver` to claim / ack / nack, the claim fence, lease expiry and the burial of a row whose lease lapsed on its final attempt (`onExhausted`, `dropExhausted`); `behavesLike(budgetStoreConformance, () => myStore)` races 24 concurrent `take`s on one key against an `@ultimat3/ai` `BudgetStore`. Every suite and its subject: [the README's table](https://github.com/developerz-ai/ultimate/blob/main/packages/testing/README.md#conformance-a-ports-contract); per port, with the reference to copy: [Adapters](Adapters).
934
947
 
935
948
  ## Generated scaffolds
936
949
 
@@ -1000,7 +1013,7 @@ shape, same unreached code. `As of 2026-11`.
1000
1013
  | A job's org | the field(s) its `tenant(input)` reads — any name, nested, left out of the draw, or under a parent the draw left out (a scoped backfill's `payload.input.orgId`) — are set to the tenant it is enqueued in, found by reading them: A's for the control, B's for the tenant proof (B's own job, carrying A's ids). A `tenant` no input field moves (one fixed org) is `unreached`, `X_JOB_TENANT_MISMATCH`, its `fix:` the declaration: `tenant: (input) => input.orgId` |
1001
1014
  | A job's run | its own execution alone: enqueued on a queue holding nothing else, run by one worker pass. What it enqueues is left queued, as an action's is — an `enqueue` effect on its record, searched by the tenant proof, never run in its room. Its `statements`, effects, verdict and scale and plan sweeps are its own body's: a job that queues one child per row is flat, a body that reads each row is still `X_QUERY_SCALES_WITH_ROWS`. A child is judged as its own primitive. The crash proof too: its clean and killed runs claim only the job's own row, a child compared as its `enqueue:` effect |
1002
1015
  | A job's failure | judged by the action rule: a coded refusal under 500 (an app's 409) is `unreached` under its own code, never a defect; an uncoded throw or a coded 5xx is `X_CONTRACT_DEFECT` |
1003
- | Async input | an override's `input` may be `async`: it is awaited inside the call's request, as the call's actor, so it can mint what the action checks (a one-time token, a passkey assertion). It has a job queue of its own on every call it feeds — the tenant proof's, the control's and the scale sweep's — so app code in it that enqueues works, and what it queued is never the primitive's enqueue. Its rows are committed, as the call's are: a unique value it inserts is drawn per call. What it sends — a select, a row, a mail — is never the primitive's: each call is recorded alone, so it is not in the record's `statements` or `effects` and the plan sweep never plans it as the primitive's. One that throws is that primitive `unreached` under the throw's own code (an uncoded one `X_EXERCISE_INPUT_THREW`), its `fix` the entry to repair; the rest of the pass runs (`As of 2026-11-08`). `x drill`'s load skips an `async` input and says why |
1016
+ | Async input | an override's `input` may be `async`: it is awaited inside the call's request, as the call's actor, so it can mint what the action checks (a one-time token, a passkey assertion). App code in it that enqueues always has a job driver. In the control and the scale sweep it binds on the queue of the call it feeds, so a job it enqueues is there when the call looks it up by id (`jobDriver()`, a cancel, a requeue); only what the CALL adds counts as the primitive's `enqueue` effect, never what the input queued. The tenant proof's first input binds on a queue of its own: it feeds B's calls, each on B's own queue (`As of 2026-11-08`). Its rows are committed, as the call's are: a unique value it inserts is drawn per call. What it sends — a select, a row, a mail — is never the primitive's: each call is recorded alone, so it is not in the record's `statements` or `effects` and the plan sweep never plans it as the primitive's. One that throws is that primitive `unreached` under the throw's own code (an uncoded one `X_EXERCISE_INPUT_THREW`), its `fix` the entry to repair; the rest of the pass runs (`As of 2026-11-08`). `x drill`'s load skips an `async` input and says why |
1004
1017
  | Room | network sealed, mail captured, jobs in memory, clock frozen — from before the app loads and the scratch database boots, as `bun test`'s preload does, so the embedded Postgres never sees its clock jump. A call out is refused and counted, so the primitive is `unreached` |
1005
1018
  | Cost | rows are primitives × tables; statements are not: the graph is written one `insertAll` per table, each tenant-proof snapshot is one statement, and a primitive reads only its own pair's rows of the graph |
1006
1019
  | Overrides | `apps/web/exercise.ts`: `export const exercise = defineExercise({ publishPost: { actor, input }, sendInvoice: { off: '<why>' } })`. The same value is what every contract test hands `.contract({ exercise })` ([one declaration](#the-exercise-assertion)). A key is a registered name or a kind-qualified one — `'job:eraseAccount'`, `'action:eraseAccount'`, `'query:…'` — which is that kind's alone and wins over the bare name — in `x exercise`, the contract step and `x drill` alike: an action and a job sharing a name each get their own entry, and the paste line a shared name prints is the qualified key (`As of 2026-11-08`). An unknown name, or a kind the name is not registered as, is `X_DECLARATION_UNKNOWN`; a blank `off` is `X_CONTRACT_EXERCISE_UNDECLARED` |
@@ -1105,7 +1118,7 @@ Source: `packages/testing/src/scale-sweep*.ts`, `plan-oracle.ts`, `plan-sweep*.t
1105
1118
  | Sweep | What | Red |
1106
1119
  |---|---|---|
1107
1120
  | scale | every reached primitive once more in a tenant at 2 rows a table, once in one at 8; per statement shape, the counts compared. Each sized seed is written beside the graph before it: row positions (a generated integer, a factory's `index`) continue past that graph's, so ``code: `c${index}` `` on a unique column never repeats the pass's own row | a shape sent more often at 8: `X_QUERY_SCALES_WITH_ROWS`, fix `preload()` or `expectedQueryLoop('<why>', fn)` |
1108
- | plans | every distinct statement whose first relation is an app table, `PREPARE`d and explained as a generic plan with `enable_seqscan`, `enable_bitmapscan`, `enable_sort` off, in a read-only transaction | `Seq Scan`, or an index scan with no `Index Cond` no `Limit` stops: `X_QUERY_UNINDEXED`. `Sort` under `Limit`: `X_QUERY_SORT_UNSERVED`, on the table its key names. Each prints an `indexes:` entry, one per arm for an `or`; a sort no declarable index serves (an expression, an aggregate, a derived column, keys across tables, mixed directions) or an index the entity already declares prints a rewrite or `expectedSeqScan` instead |
1121
+ | plans | every distinct statement whose first relation is an app table, `PREPARE`d and explained as a generic plan with `enable_seqscan`, `enable_bitmapscan` off — and, for a statement with a `Limit`, planned again with `enable_sort` off for its sort alone — in a read-only transaction | `Seq Scan`, or an index scan with no `Index Cond` no `Limit` stops: `X_QUERY_UNINDEXED`. `Sort` under `Limit`: `X_QUERY_SORT_UNSERVED`, on the table its key names. Each prints an `indexes:` entry, one per arm for an `or`; a sort no declarable index serves (an expression, an aggregate, a derived column, keys across tables, mixed directions) or an index the entity already declares prints a rewrite or `expectedSeqScan` instead |
1109
1122
 
1110
1123
  With the planner's scans and sorts disabled it picks one only when no index can answer, so the
1111
1124
  verdict reads the schema on empty tables — no volume, no statistics. Never red: `scale.verdict`
@@ -23,7 +23,7 @@ The `--json` form is the same content as the terminal form. Paste the JSON into
23
23
  | Symptom | Likely cause | Fix |
24
24
  |---|---|---|
25
25
  | Process exits in ~40ms, `X_ENV_MISSING` | a key in the `defineEnv` schema is missing, or present but fails its schema (short secret, non-URL, bad enum) | the cause names every offending key and its constraint at once; `x doctor --json` lists them too |
26
- | `X_CONFIG_INVALID` at load | `app.config.ts` field invalid — `defaultLocale` not in `locales`, `db.pool < 1`, non-IANA `timeZone`, `realtime.transport` set without `realtime.urlEnv` | `x config show --json`, then edit the field named in `cause` |
26
+ | `X_CONFIG_INVALID` at load | `app.config.ts` field invalid — `defaultLocale` not in `locales`, `db.pool < 1`, non-IANA `timeZone`, a removed key such as `realtime.transport` | `x config show --json`, then edit the field named in `cause` |
27
27
  | `X_ROLE_INVALID` | `ROLE` is not one of `web sync worker scheduler migrate replicator all` | fix the env var on that service |
28
28
  | `X_BUN_VERSION` | below the Bun floor, `>= 1.4.4` (`engines.bun`) | `bun upgrade` |
29
29
  | Container starts then loops | `/readyz` failing, not `/healthz` — a registered check answers `failing`, and which one is in the body | `curl /readyz` **from the container itself** (`docker exec`, `kubectl exec`, a port-forward — the detail goes to `healthDetailPeers`, default `['loopback']`) and read `checks`, a map of name → `ok`/`failing`: `database` is registered always, `transport` whenever it can report a connection, so a disconnected NATS node fails on that one. Read `registered` with it: `0` means nothing was checked, so the 200 meant only that the socket was bound |
@@ -163,7 +163,7 @@ bunx x dev --once --port 3100
163
163
  ```text
164
164
  {"ts":"2026-11-03T16:48:57.124Z","level":"info","msg":"ultimate web listening on http://localhost:3100"}
165
165
  {"ts":"2026-11-03T16:48:57.118Z","level":"info","msg":"sync node ready","buildId":"e6af64a2077e5d60","path":"/_x/sync"}
166
- {"ts":"2026-11-03T16:48:57.134Z","level":"info","msg":"jobs.worker.started","workerId":"worker-01a1a250-…","queues":["myapp-default","default"]}
166
+ {"ts":"2026-11-03T16:48:57.134Z","level":"info","msg":"jobs.worker.started","workerId":"worker-01a1a250-…","queues":["default"]}
167
167
  {"ts":"2026-11-03T16:48:57.137Z","level":"info","msg":"jobs.scheduler.started","tasks":1}
168
168
  {"ts":"2026-11-03T16:48:57.142Z","level":"info","msg":"live feed in-process","detail":"the embedded database has no walsender; repository writes in this process reach subscribers"}
169
169
  roles web, sync, worker, scheduler
@@ -86,7 +86,7 @@ export const dailyDigest = task({
86
86
 
87
87
  ### Registration names it
88
88
 
89
- Export names become primitive names, and only `defineApi` (or `registerTasks`) stamps them. A task no `defineApi` lists keeps a positional name (`anonymous-task-1`, enqueuing `anonymous-job-2`); `x verify`'s `manifest` step refuses that job as `X_JOB_UNREGISTERED`. With the generator's edit to `apps/web/api/index.ts` in place:
89
+ Export names become primitive names, and only `defineApi` stamps them. A task no `defineApi` lists keeps a positional name (`anonymous-task-1`, enqueuing `anonymous-job-2`); `x verify`'s `manifest` step refuses that job as `X_JOB_UNREGISTERED`. With the generator's edit to `apps/web/api/index.ts` in place:
90
90
 
91
91
  ```bash
92
92
  bunx x tasks list
@@ -221,7 +221,7 @@ Scaling the two serving roles is the next rung, and it is not an edit to this fi
221
221
  | `/metrics` on the **app** port | `X_ROUTE_NOT_FOUND`, and that is deliberate. Every role — `web` included — serves `/metrics` on `METRICS_PORT`, default **9090**, because the Helm ingress routes `/` with no path exclusion and metrics on 3000 would be public. Scrape `http://<host>:9090/metrics`, not `:3000/metrics` |
222
222
  | `x logs tail` | planned — `X_NOT_IMPLEMENTED`, with `x dev` → the `/_x` timeline panel as its fix |
223
223
  | `x status` | planned — `x doctor --json` is the shipped answer |
224
- | OTLP export, on by default | the exporter **ships** — `otlpSpanExporter()` / `otlpMetricExporter()`, OTLP/HTTP JSON — but the default is still the no-op, so nothing leaves the process until you register one: `configureTelemetry({ exporter: otlpSpanExporter() })` with `OTEL_EXPORTER_OTLP_ENDPOINT` set to a collector's HTTP receiver (`:4318` — `:4317` is gRPC and is refused) |
224
+ | OTLP export, on by default | on when **configured**: the production boot (`apps/web/server.ts`, every `ROLE`) wires traces, metrics and logs (OTLP/HTTP JSON) from `OTEL_EXPORTER_OTLP_ENDPOINT` set to a collector's HTTP receiver (`:4318` — `:4317` is gRPC and is refused). Unset, nothing leaves the process; there is no code to write |
225
225
  | a Helm chart in your app | **`x new` writes one** `As of 2026-11-03` — `docker/helm`, 10 files — so `x deploy --method helm` works here. On 3.0.0 and below it writes none: copy [`docker/helm`](https://github.com/developerz-ai/ultimate/tree/main/docker/helm) from the framework repo, or stay on `--method compose` |
226
226
 
227
227
  ## Next
@@ -24,7 +24,7 @@ Skipping a rung to look serious buys a second product to maintain. A Kubernetes
24
24
  |---|---|
25
25
  | `DATABASE_URL`, `REDIS_URL`, `NATS_URL`, `S3_ENDPOINT` | any file under `apps/` or `packages/` |
26
26
  | `ROLE` — which process this container is | the eight primitives, their shapes, their authz |
27
- | driver constructors at boot (`setJobDriver`, `setDbClient`, `configureTelemetry`) | call sites: `db()`, `ctx.jobs.enqueue()`, `query()`, `live()` |
27
+ | driver constructors at boot (`apps/<app>/runtime.ts`, `setDbClient`, `configureTelemetry`) | call sites: `db()`, `ctx.jobs.enqueue()`, `query()`, `live()` |
28
28
  | replica counts, HPA targets | the manifest, the OpenAPI, the typed client, the MCP tools |
29
29
  | `app.config.ts` declarations | migrations already applied |
30
30
 
@@ -95,27 +95,27 @@ Per-role HPAs target `rps`, `connections` and `queue_demand` — CPU is a laggin
95
95
  | custom Kubernetes over a managed chart | node pools with real taints, affinity to node-local storage, an ingress you control | wanting the chart to look impressive |
96
96
  | distributed SQL over one Postgres | multi-region **write** locality; surviving a zone loss with no manual failover | write throughput one Postgres has not actually failed to deliver |
97
97
 
98
- Observability is the part that is not optional here, and the framework's half is done `As of 2026-08` — but **the default exporter is still the no-op**, so it emits nothing until you say so. Two lines at boot:
98
+ Observability is the part that is not optional here, and the framework's half is done `As of 2026-11`: there is no code to write. The production boot (`apps/web/server.ts`, every `ROLE`) reads the variables the OpenTelemetry SDKs read and wires all three signals — traces, metrics and **logs** — from them at boot:
99
99
 
100
- ```ts
101
- configureTelemetry({ exporter: otlpSpanExporter() }); // OTEL_EXPORTER_OTLP_ENDPOINT
102
- configureMetrics({ exporter: otlpMetricExporter() }); // same endpoint, metrics signal
100
+ ```sh
101
+ OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318 # all three signals
102
+ OTEL_LOGS_EXPORTER=none # optional: one signal off
103
103
  ```
104
104
 
105
- Point `OTEL_EXPORTER_OTLP_ENDPOINT` at your collector's **HTTP** receiver, `:4318` — `:4317` is gRPC and is refused with `X_OTLP_PROTOCOL_UNSUPPORTED`, permanently, because HTTP/2 plus protobuf is a dependency and a second wire format. Metrics also stay scrapeable at `METRICS_PORT` if you prefer an agent. [`docs/ops/03-observability.md`](https://github.com/developerz-ai/ultimate/blob/main/docs/ops/03-observability.md) says what to scrape, what to alert on, and what is still missing — no logs signal, and a rejected export is dropped rather than retried.
105
+ Point it at your collector's **HTTP** receiver, `:4318` — `:4317` is gRPC and is refused with `X_OTLP_PROTOCOL_UNSUPPORTED`, permanently, because HTTP/2 plus protobuf is a dependency and a second wire format. A credential goes in `OTEL_EXPORTER_OTLP_HEADERS`, never in the URL (`X_OTLP_ENDPOINT_INVALID`). `OTEL_SDK_DISABLED=true` turns all three off. Metrics also stay scrapeable at `METRICS_PORT` if you prefer an agent. [`docs/ops/03-observability.md`](https://github.com/developerz-ai/ultimate/blob/main/docs/ops/03-observability.md) says what to scrape and what to alert on; anything else that wants the stream subscribes to it — `subscribe('span.end', …)`, `subscribe('log.record', …)` ([Observability](Observability)).
106
106
 
107
107
  ## The seams, so nothing surprises you
108
108
 
109
109
  | Concern | Interface | Decided by |
110
110
  |---|---|---|
111
111
  | rows | `@ultimat3/db` · `DbClient` | `DATABASE_URL` — unset is PGlite, and PGlite is `x dev` only |
112
- | job queue | `@ultimat3/jobs` · `JobDriver` | `setJobDriver(postgresJobDriver({ executor }))` — there is no `jobs.driver` config line, and 5.0.0 deleted the one that never worked. Redis is an interface-complete stub that throws `X_NOT_IMPLEMENTED`; there is no NATS job driver since 25.0.0 |
112
+ | job queue | `@ultimat3/jobs` · `JobDriver` | `postgresJobDriver()`, installed by the boot; another is `jobs:` in `apps/<app>/runtime.ts` — there is no `jobs.driver` config line, and 5.0.0 deleted the one that never worked. Redis is an interface-complete stub that throws `X_NOT_IMPLEMENTED`; there is no NATS job driver since 25.0.0 |
113
113
  | realtime fanout | `@ultimat3/realtime` · `Transport` | `NATS_URL` |
114
114
  | change feed | `@ultimat3/realtime` · `ChangeFeed` | `REPLICATION_*` |
115
115
  | cache | `@ultimat3/cache` · `CacheTier` | `cache.tiers` + `REDIS_URL` |
116
116
  | object storage | `@ultimat3/storage` · `Driver` | `S3_ENDPOINT` |
117
117
  | mail | `@ultimat3/mail` · `Driver` | mail env |
118
- | tracing | `@ultimat3/core` · `SpanExporter` | `configureTelemetry()` — default no-op |
118
+ | tracing | `@ultimat3/core` · `SpanExporter`, a `span.end` subscriber | `OTEL_EXPORTER_OTLP_ENDPOINT` — unset exports nothing |
119
119
 
120
120
  Every one keys on env or a boot-time constructor. One image resolves `x dev`, a Compose host and a cluster identically.
121
121