@ultimat3/cli 30.6.0 → 30.8.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 +2 -1
- package/package.json +28 -28
- package/src/cmd-exercise.ts +13 -2
- package/src/cmd-generate.ts +15 -2
- package/src/cmd-new.ts +4 -2
- package/src/error-codes.ts +2 -0
- package/src/exercise-entry-edit.ts +169 -0
- package/src/exercise-findings.ts +74 -4
- package/src/exercise-registration.ts +10 -14
- package/src/exercise-subject.ts +9 -2
- package/src/generate-exercise.ts +77 -0
- package/src/generate-follow-ups.ts +16 -3
- package/src/mcp-errors.ts +2 -0
- package/src/messages.ts +2 -0
- package/src/templates/action-exercise.ts +71 -0
- package/src/templates/action-tests.ts +10 -34
- package/src/templates/action.ts +8 -3
- package/src/templates/naming.ts +7 -0
- package/src/templates/resource-create.ts +10 -4
- package/src/templates/scaffold-auth.ts +17 -1
- package/src/templates/scaffold-exercise.ts +2 -1
- package/wiki/Actions.md +1 -1
- package/wiki/CLI-Reference.md +1 -1
- package/wiki/Policies-And-Authz.md +3 -2
- package/wiki/Testing.md +50 -26
- package/wiki/Tutorial-02-First-Feature.md +3 -3
- package/wiki/Tutorial-03-Auth-And-Admin.md +1 -1
package/wiki/Testing.md
CHANGED
|
@@ -609,7 +609,7 @@ Enforced through it, keyed or not: `concurrency` and `whenBusy` — each pass is
|
|
|
609
609
|
|
|
610
610
|
| Call | Runs | Answers |
|
|
611
611
|
|---|---|---|
|
|
612
|
-
| `crashProof(job, input)` | one clean run, then one per boundary it crossed (each step write landing, each settle), the worker killed there and the next one reclaiming; then each
|
|
612
|
+
| `crashProof(job, input)` | one clean run, then one per distinct boundary it crossed (each step write landing, each settle), the worker killed there and the next one reclaiming; then each again with the write's answer lost. A loop's steps named by row id (`fanout:${row.id}`, `page-3` — a uuid, a digit run, an 8+ character token with a digit) are one point, killed at its first and last row: the cost is the job's steps, never the rows seeded. Over `CRASH_POINT_BOUND` (32) points per mode it throws `X_JOB_CRASH_UNBOUNDED` after the clean run, never a pass | `{ boundaries, crossed, divergences, reruns }` — `boundaries` the kills, `crossed` every boundary they stand for. A divergence carries `error`, an `X_JOB_CRASH_DIVERGED` naming the effect and the step it follows — `throw report.divergences[0].error`. A rerun is at-least-once, reported, never red |
|
|
613
613
|
| `simulateJobs({ jobs: [{ handle, input }], workers, faults, invariant })` | `seeds` (20) seeds from `seed` (1), N workers, every driver call interleaved and faulted by a seeded picker: `kill`, `answer-lost`, `lease-lapse`, `duplicate-claim`, `clock-jump` (`ALL_FAULTS`) | throws `X_JOB_SIM_INVARIANT` with the seed and its faults when `invariant(state)` throws or answers `false`; `X_JOB_SIM_NONDETERMINISTIC` when one seed traces two ways. `x test job --seed <n>` replays one |
|
|
614
614
|
|
|
615
615
|
A `compensates: true` job is also forced to fail for good and killed while it unwinds: each `compensate:*` once, last in first out. A kill inside `step.run(…, { once: true })` ends `X_STEP_OUTCOME_UNKNOWN` and is green. Postgres is not simulated. The reference: `examples/dummy/apps/web/app/posts/jobs.job.test.ts`.
|
|
@@ -896,15 +896,16 @@ await insertSeedGraph(graph, writer);
|
|
|
896
896
|
| Rule | What it does |
|
|
897
897
|
|---|---|
|
|
898
898
|
| order | parents before children, over the entities' own `$references()` |
|
|
899
|
-
| tenancy | each child points at a parent of its **own** tenant; the entity a tenant column references holds one row per tenant, keyed by the tenant. A table with no tenant column whose references reach a tenant-owned one, and no `shared` reason, is seeded per tenant too, under its own tenant's parent — `row.tenant` is that parent's tenant |
|
|
899
|
+
| tenancy | each child points at a parent of its **own** tenant; the entity a tenant column references holds one row per tenant, keyed by the tenant. A table with no tenant column whose references reach a tenant-owned one, and no `shared` reason, is seeded per tenant too, under its own tenant's parent — `row.tenant` is that parent's tenant. A `shared` (or tenantless) table a tenant-owned one references through a key unique across the table — the unique holds the reference and not the tenant column — seeds `perTable` rows **per tenant**, still `tenant: null`, so every tenant's unique children find a parent row no other tenant took (`As of 2026-11-08`) |
|
|
900
900
|
| a cycle | broken at a nullable key: inserted `null`, set by an entry of `graph.updates` once its target exists. The break prefers a table that takes updates — never an `appendOnly` one, whose key stays `null` when it is the only break. In `x exercise`, a deferred update the database refuses (a trigger no declaration carries) leaves the key `null`; an environment failure still fails. A cycle with no nullable key is `X_SEED_GRAPH_UNSATISFIED` |
|
|
901
901
|
| values | read off the declaration, as `factoriesFor` reads them, and kept only if `$parse` accepts them |
|
|
902
|
-
| patterns and schemas | a `matches(/…/)` pattern adds strings drawn from the pattern itself: literals, classes, `.`, groups, `\|`, quantifiers, anchors. Lookaround, backreferences, `\b` and `\p{…}` add nothing, so the column's other candidates stand. A `json(schema)` column draws from its schema, as the contract step's `arbitrary` does. Both are seeded by the row, so the same seed gives the same bytes |
|
|
902
|
+
| patterns and schemas | a `matches(/…/)` pattern adds strings drawn from the pattern itself — `patternSamples` (`@ultimat3/schema/sample`), the one generator the input sampler uses too: literals, classes, `.`, groups, `\|`, quantifiers, anchors. Lookaround, backreferences, `\b` and `\p{…}` add nothing, so the column's other candidates stand. A `json(schema)` column draws from its schema, as the contract step's `arbitrary` does. Both are seeded by the row, so the same seed gives the same bytes |
|
|
903
903
|
| rules | every invariant, the primary key, unique columns and unique indexes are kept; a partial unique is treated as total. A unique column that runs out of values ends its table early — but a table-wide unique that runs out before every tenant holds a row is `X_SEED_GRAPH_UNSATISFIED` (`… runs out of values before tenant 2 of 2 holds a row`): that tenant's children would have no parent |
|
|
904
904
|
| an unseeded target | a key — the tenant column included — whose target entity is not in the set is `X_SEED_GRAPH_UNSATISFIED` (`… which is not in the set seeded — pass it too`) |
|
|
905
905
|
| soft delete | a soft-deleting table's `deletedAt` is `null` unless a factory builds it: seeded rows are live |
|
|
906
906
|
| `factories` | `{ factories: { posts: myFactory } }` — what the factory builds wins, except keys and the tenant column, which stay the graph's |
|
|
907
907
|
| determinism | defaults `tenants: 2`, `perTable: 3` (per tenant for a tenant-scoped table), `seed` the package's `DEFAULT_SEED`. Same seed, same bytes |
|
|
908
|
+
| `beside` | `{ beside: earlier }` — a graph already written to the same database. Each table's row positions (the ordinal a generated integer, date or money is built from; a factory's `index`, reached by replaying its builds after `reset()`) continue past `earlier.next[table]`, so no value built from a position repeats one of its rows on a unique column. `graph.next` is cumulative: chain a third graph beside the second |
|
|
908
909
|
| canaries | each row's generated text carries a token; `graph.canaries` lists it per row with the columns holding it, so a later read can say whose row it saw |
|
|
909
910
|
| writing | `insertSeedGraph(graph, writer)`: every insert in order, then every update, sequentially. `entitySeedWriter({ entities, client })` (Postgres or PGlite) or `entitySeedWriter({ entities, driver? })` (a driver; default `defaultDriver()`) writes through each entity's own repository. A row whose entity the writer was not given is `X_SEED_GRAPH_ENTITY_UNKNOWN` |
|
|
910
911
|
| `snapshot(rows)` | **required** on a `SeedWriter`: one digest per row, read back by primary key, in the order given; `null` for a row gone. Soft-deleted rows are read too. `entitySeedWriter` answers `md5(t::text)` per row over a client — the whole stored row, undeclared columns included — and an md5 of the row's sorted JSON over a driver. The tenant proof's write half |
|
|
@@ -960,10 +961,12 @@ A legal input that crashes the handler is red in `contract`, the day the action
|
|
|
960
961
|
|
|
961
962
|
| Rule | |
|
|
962
963
|
|---|---|
|
|
963
|
-
|
|
|
964
|
-
|
|
|
965
|
-
|
|
|
966
|
-
|
|
|
964
|
+
| **One declaration** | in an app, an action's exercise lives in `apps/web/exercise.ts` and nowhere else: `import { exercise } from '<…>/exercise'` then `action.contract({ exercise })` — the whole `defineExercise()` value, of which the contract reads the entry named for the action. `x exercise` reads the same entry, so a test and the pass cannot disagree on who acts. An entry declared only inline in a test is one `x exercise` cannot see (it reports the primitive `unreached`). `As of 2026-11-08` |
|
|
965
|
+
| Who acts | the entry's `actor`. Required unless the policy admits an anonymous caller: no entry is `X_CONTRACT_EXERCISE_UNDECLARED`, its `fix:` the `defineExercise({ <name>: { actor } })` line to paste. An entry with no `actor` (`{ input }` alone, which typechecks) runs signed out where the policy admits it, else is `X_CONTRACT_EXERCISE_UNDECLARED` too: `x exercise` picks a role, a contract test has none to pick from (`As of 2026-11-08`). There is no bypass: a policy that denies `actor` makes an unreached run |
|
|
966
|
+
| Inline, for a test's own world | `action.contract({ exercise: { actor, input } })` — one entry, not the app's — only when the test binds rows it seeded itself (`seed('dev').pick(…)`, an `actorFor`): those ids exist in that test alone. Kept and not deprecated; the who-acts of the primitive still belongs in `apps/web/exercise.ts` |
|
|
967
|
+
| A row | `{ actor, input: (drawn) => ({ ...drawn, postId }) }` binds what a generated uuid cannot resolve |
|
|
968
|
+
| Opting out | `{ off: '<reason>' }` as the entry. The reason is in the test's name. A blank one is `X_CONTRACT_EXERCISE_UNDECLARED` (`defineExercise` refuses it as the file loads) |
|
|
969
|
+
| Runs | 16 (`EXERCISE_RUNS` from `@ultimat3/core`), `runs` from 1 to 64. Runs 0-3 sit on the IR's bounds (`minLength`, `maxLength`, `minimum`, `maximum`, `minItems`). The rest draw multibyte text, every enum and union member, optional keys on and off, `null` where nullable. A format value (`t.uuid`, `t.email`, …) is never varied. A `t.string.pattern(/…/)` no drawn text meets is walked from the pattern itself (days, months, hex digests, digit ids, base64url tokens), inside its length bounds; the minimal draw keeps `'sample'` when the pattern accepts it (`As of 2026-11-08`) |
|
|
967
970
|
| Seed | `fnv1a(<action name>)`, never time, so a red run replays: `bun test <file> -t '<name>: handler survives generated input'` |
|
|
968
971
|
| Rolled back | each run inside a memory transaction, always, and in it `withTransaction` when SQL can hold the writes: a SAVEPOINT in a test's open transaction, a root transaction once `setDbClient` installed a client. Both always roll back. The handler's SQL writes, its memory-store writes (`storeMode` `memory`, `tx` passed or not, since `memoryTransactor().run` is ambient), the outbox stage and the post-commit bust drop with it (`packages/action/src/tx-scope.ts` `inRolledBackScope`) |
|
|
969
972
|
| **Not rolled back** | a write on a second client or `outsideTransaction`. A job enqueued with `outbox: false`. Storage puts. Mail and outbound fetch: the test preload seals both, so a real one is only sent where a test opted out. An audit record a non-database sink accepted |
|
|
@@ -972,14 +975,14 @@ A legal input that crashes the handler is red in `contract`, the day the action
|
|
|
972
975
|
| Pass | the output parsed, or a coded refusal under 500 |
|
|
973
976
|
| Defect, `X_CONTRACT_DEFECT` | an uncoded throw, `X_OUTPUT_INVALID`, or a coded 5xx (an undeclared `errors:` code is one). `meta.run`, `meta.input`, `meta.failure` |
|
|
974
977
|
| Red, `X_CONTRACT_EXERCISE_UNREACHED` | no run reached the handler. `X_TEST_NETWORK_SEALED` counts as unreached, its host in `meta.outcomes` |
|
|
975
|
-
| Red, `X_CONTRACT_DRIFT` | the schema refused every draw: a provider refinement the IR does not carry
|
|
978
|
+
| Red, `X_CONTRACT_DRIFT` | the schema refused every draw: a provider refinement the IR does not carry, or a `pattern` past the generator's subset (lookaround, backreferences, `\b`, `\p{…}`), named in the cause as `field (must match …)`. Bind it with `exercise.input` |
|
|
976
979
|
|
|
977
|
-
A query has the same assertion: `orgFeed.contract({ exercise
|
|
980
|
+
A query has the same assertion, read off the same file: `orgFeed.contract({ exercise })`, named
|
|
978
981
|
`<name>: read survives generated input`. "Reached" is `sql()` building a source, and a read
|
|
979
982
|
writes nothing, so no transaction wraps it; it refuses a deploy the same way. Both are one loop,
|
|
980
983
|
`@ultimat3/core`'s `runExercise`: the verdicts above are the same words for a read and a write.
|
|
981
|
-
The generators
|
|
982
|
-
`can('<perm>')`, or `{ off }` when its grant cannot be read.
|
|
984
|
+
The generators declare an actor (`x g action`, `x g resource`), holding the slice's grant: a hand-written `policy.ts`'s one literal
|
|
985
|
+
`can('<perm>')`, or `{ off }` when its grant cannot be read. As of 2026-11-08 the call is `target.contract({ exercise })` and the actor is the ENTRY the generator inserts into `apps/web/exercise.ts` (`userActor({ id: 'member', orgId, permissions: [grant] })`, its draw's `orgId` bound under a tenancy rule; `x new` writes its example slice's the same way). The file is created from `x new`'s when absent; a file the generator cannot edit — no single `export const exercise = defineExercise({ … })` — is `X_EXERCISE_FILE_UNEDITABLE`, the entry to paste in its `fix:`. `x g query` emits no `.contract()` call: `x exercise` picks a reader by role.
|
|
983
986
|
`@ultimat3/schema/sample`'s `arbitrary(schema, { seed, run })` is the draw, off the barrel.
|
|
984
987
|
|
|
985
988
|
## The exercise pass
|
|
@@ -992,17 +995,19 @@ shape, same unreached code. `As of 2026-11`.
|
|
|
992
995
|
|---|---|
|
|
993
996
|
| Database | a scratch one with the framework tables and every migration applied; never the developer's. The pass commits, so the tenant proof can read rows after the call |
|
|
994
997
|
| Rows | one seed graph for the pass, a fresh pair of tenants per primitive in it — the first the actor's (A), the second the tenant proof's intruder (B); every table seeded off its declaration, parents first, same-tenant keys (`x db seed --generate`'s graph). A view and a `readOnly: '<why>'` table get no row; a NOT NULL key into a `readOnly` one is `X_SEED_GRAPH_UNSATISFIED` naming it ([Read-only tables](Entities-And-Migrations#read-only-tables)) |
|
|
995
|
-
| Actor | the first of `x policy explain`'s actors the policy allows, in the primitive's tenant. None allowed is `refused`, by design |
|
|
998
|
+
| Actor | the entry's `actor` when it declares one, seated in the primitive's tenant — and a top-level value of its bound input — or of its `facts`, a string or an array holding it — equal to the org the entry declared becomes that tenant too, so `input: (drawn) => ({ ...drawn, orgId: '<the actor's org>' })` holds in every tenant the pass seeds; otherwise the first of `x policy explain`'s actors the policy allows, in the primitive's tenant (an `{ input }`-only entry keeps this pick and still binds its input). None allowed is `refused`, by design. Its id has a user's shape: a uuid per role × tenant, the same on every run (`exerciseActorId`), never the role's name. Where the database has `x_users` (the framework schema every pass database is built with) each actor the pass acts as gets its row first — `<id>@exercise.invalid`, its tenant, roles, permissions, scopes — so `findUserById(ctx.actor.id)` finds it; a refused insert is `X_EXERCISE_ACTOR_USER_UNSEATED`. `defineExercise(…, { actor: members })` makes the id a seeded row's key instead (`As of 2026-11-08`) |
|
|
996
999
|
| Input | the override, then an id field whose stem names a seeded entity (`postId` → `posts`), then the schema's minimal draw. A wrong guess shows as `unreached` |
|
|
997
1000
|
| 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` |
|
|
998
1001
|
| 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 |
|
|
999
1002
|
| 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` |
|
|
1000
|
-
| 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). `x drill`'s load skips an `async` input and says why |
|
|
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 |
|
|
1001
1004
|
| 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` |
|
|
1002
1005
|
| 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 |
|
|
1003
|
-
| Overrides | `apps/web/exercise.ts`: `export const exercise = defineExercise({ publishPost: { actor, input }, sendInvoice: { off: '<why>' } })`.
|
|
1004
|
-
| A handler that calls a vendor | `defineExercise({ … }, { setup: () => { mockFetch('https://api.vendor.test/*', handler); } })` — or `setup: () => cassette(import.meta.dir, 'exercise')`. Runs once in the exercise process, after the seal and before the first row; what it returns is disposed after the pass. A call a setup route answers is reached, not refused. `allowHost` in it is `X_EXERCISE_SETUP_UNSEALED` |
|
|
1006
|
+
| 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` |
|
|
1007
|
+
| A handler that calls a vendor | `defineExercise({ … }, { setup: () => { mockFetch('https://api.vendor.test/*', handler); } })` — or `setup: () => cassette(import.meta.dir, 'exercise')`. Runs once in the exercise process, after the seal and before the first row; what it returns is disposed after the pass. A call a setup route answers is reached, not refused. Several feature groups: `setup: [setupBilling, setupKyc]` — run in order, disposed in reverse, and one that throws disposes those that already ran before the pass refuses (`As of 2026-11-08`). `allowHost` in it is `X_EXERCISE_SETUP_UNSEALED` |
|
|
1008
|
+
| A step held by a cookie | `defineExercise({ finishSignIn: { request: { cookies: { pending: '<value>' } } } })` — the call's inbound request carries it, read by `useRequestCookie()` / `useRequestHeader()` in the handler; `headers: { … }` beside it. A function `request: async (actor) => ({ cookies: { sid: await mintSession(actor) } })` is awaited before each call, as that call's actor (A's and B's each mint their own). A cookie goes in `cookies`, never a `Cookie` header: that, a name outside the token set or a header `Headers` refuses is `X_EXERCISE_REQUEST_INVALID`. Read by `x exercise` and the contract step alike: `.contract({ exercise })` runs each generated run inside that request (`withRequestAs`, `@ultimat3/http`); with no `request` its call has none, so a handler reading a cookie there is `X_CONTRACT_DEFECT` on `X_NO_REQUEST` (`As of 2026-11-08`) |
|
|
1005
1009
|
| Rows a generated value cannot satisfy | a cross-column `c.satisfies(…)` reads `X_SEED_GRAPH_UNSATISFIED`: `defineExercise({ … }, { factories: { bosses: defineFactory(bosses, { defaults: (i) => ({ … }) }) } })`, keyed by entity name, the graph's keys kept. A column that follows from a key or reference the graph picked: `derive: (row) => ({ scopeKey: … })` beside `build`/`reset`, reading `row.ownerOrgId`. A partial unique whose columns the factory builds is the database's to judge. An unknown name is `X_DECLARATION_UNKNOWN` |
|
|
1010
|
+
| Drift | a schema no draw satisfies is `unreached`, `X_CONTRACT_DRIFT`; its `override` binds each field the sampler names as a gap with what it needs (`digest: "<must match ^[0-9a-f]{64}$>"`), the contract step's `fix:` the same `input:` (`As of 2026-11-08`) |
|
|
1006
1011
|
| Report | `.x/exercise.json` and `--json`: `{ seed, counts, records[] }`, each record `{ kind, name, outcome, code?, reason?, defect?, statements, effects, ms, override?, fix?, tenant?, crash? }` — `fix` where no override reaches it; `defect` on a 5xx: `{ cause, statement?, fields? }`, the error's own cause (a value the input held under a credential key or a `.sensitive()` field masked `[redacted]`), the SQL a database refusal names and the paths a validation failure names, all carried into the `X_CONTRACT_EXERCISE_UNREACHED` finding. The fields before `tenant` are A's call. The human table's `tenant` and `crash` columns are the verdicts, `-` where none ran |
|
|
1007
1012
|
| Gate | the `exercise` step, after `job`, runs `x exercise --json` as a child and is red on its findings: `X_CONTRACT_EXERCISE_UNREACHED`, `X_TENANT_LEAK`, `X_TENANT_WRITE_CROSSED`, `X_JOB_CRASH_DIVERGED`, and — on a whole pass, not `x exercise <name>` — `X_ENTITY_TENANT_UNDECLARED`. `unreached` is never sampled or skipped: it is a finding whose `fix:` is the entry to paste |
|
|
1008
1013
|
|
|
@@ -1038,16 +1043,23 @@ only what came back and what changed.
|
|
|
1038
1043
|
| `unproven` | A's own call was not `reached` | no — the record is already `unreached`, which is |
|
|
1039
1044
|
| `public` | the policy admits an anonymous caller with an empty input: read half skipped, write half kept | no |
|
|
1040
1045
|
| `public` | a **job** whose B leg opened `crossTenant(reason, fn)` and whose input carried none of A's marks — a declared sweep, `sendDigest` fanning out one delivery per org. The reason is quoted in the verdict; read half skipped, write half kept | no |
|
|
1046
|
+
| `public` | a **job** declaring `tenant: 'none'` whose input carried none of A's marks — a nightly cleanup across every org, input `{ occurrenceMs }`. No org and no id B chose reaches its run, so B's run is A's run: write half skipped (no snapshots taken), read half kept. Handed one of A's ids, crossed as ever. Both this and a declared sweep: both reasons, `; `-joined | no |
|
|
1041
1047
|
| `unproven` | a query whose A answer held none of A's marks: B's empty answer proves nothing | no |
|
|
1042
1048
|
| `proven` | otherwise | no |
|
|
1043
1049
|
|
|
1044
1050
|
`off` and `refused` records carry no `tenant`. A job has no policy, so it is `public` only as a
|
|
1045
|
-
declared sweep. `crossTenant()` is the one
|
|
1046
|
-
witness each scope opened, after its
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
+
declared sweep or a `tenant: 'none'` job handed nothing of A's. `crossTenant()` is the one
|
|
1052
|
+
declaration the proof reads (`@ultimat3/entity` tells a witness each scope opened, after its
|
|
1053
|
+
capability is proven); it excuses nothing on an action or a query, which answer B directly, nor on a
|
|
1054
|
+
job B handed one of A's ids — that is B choosing A's row, crossed as ever. `tenant: 'none'` excuses
|
|
1055
|
+
only the write half, and only with no id of A's handed: an action or a query runs as B's actor, so a
|
|
1056
|
+
write to A's row with no id in the input is a statement no tenant predicate scopes, crossed. A
|
|
1057
|
+
finding prints paths, tables and seeded ids, never a bound value — one per leg and code, its places
|
|
1058
|
+
listed once, a list index that only repeats collapsed (`effect.enqueue[*].input.orgId (3 each)`).
|
|
1059
|
+
The fix on each: `x exercise <name> --json`, then read or write the row through the repository
|
|
1060
|
+
scoped to `ctx.actor`; for a `tenant: 'none'` job handed nothing of A's, whose read has no org to
|
|
1061
|
+
scope to, wrap it in `crossTenant('<why <name> reads every org>', async () => …)`. What this
|
|
1062
|
+
does not walk — a `route` `load`, a `task` — is
|
|
1051
1063
|
[Policies and authz](Policies-And-Authz#the-dynamic-tenant-proof).
|
|
1052
1064
|
|
|
1053
1065
|
### The crash proof
|
|
@@ -1062,12 +1074,20 @@ actor, after the tenant proof. Source: `packages/testing/src/exercise-crash.ts`,
|
|
|
1062
1074
|
| Runs | committed on the pass's scratch database, after the control. A job body runs outside every transaction, so no rollback scope can hold its writes, and an effect is counted when it commits |
|
|
1063
1075
|
| Oracle | the effect multiset — row writes through a repository, mail, calls out, enqueues — of each killed run against the clean one. Raw SQL is no effect, and reads are none |
|
|
1064
1076
|
| A job with no step | one boundary, before the ack: an effect in its body runs again on the retry |
|
|
1077
|
+
| A sweep | one step per row is one kill point when the step is named by the row's id: a job over 1,500 seeded rows costs the runs one over 3 does. Steps named otherwise (a slug, an email) past 32 points are `unproven`, `X_JOB_CRASH_UNBOUNDED` |
|
|
1065
1078
|
|
|
1066
1079
|
| `crash.verdict` | When | Red |
|
|
1067
1080
|
|---|---|---|
|
|
1068
1081
|
| `diverged` | an effect made more often by a killed run: `findings[]` of `{ boundary, mode, effect, clean, killed, after?, inside? }` — `inside` the step whose body made it (`@ultimat3/jobs`' `currentStep()`), `after` the last step completed before it. An effect inside a step that did not complete, made FEWER times by a kill that spent one of its attempts, is not a divergence | yes: `X_JOB_CRASH_DIVERGED`, one per effect and place, every boundary named. Inside a step the fix keys its call on `${jobId}:<step>`; outside every step it wraps it in `step.run` |
|
|
1069
|
-
| `held` | otherwise; `boundaries` and `reruns` (lost answers — at-least-once, never red) counted | no |
|
|
1070
|
-
| `unproven` | the proof itself threw: `reason` | no |
|
|
1082
|
+
| `held` | otherwise; `boundaries` (kills), `crossed` (boundaries they stand for) and `reruns` (lost answers — at-least-once, never red) counted | no |
|
|
1083
|
+
| `unproven` | the proof itself threw, or could not finish in its bound: `reason`, `X_JOB_CRASH_UNBOUNDED: …` for the second | no |
|
|
1084
|
+
|
|
1085
|
+
**Where the time went.** Every record carries `proofMs: { tenant, crash, scale }` beside `ms` (the
|
|
1086
|
+
control's own call); the report carries `phases: { seed, primitives, scale, plans, subject }`, in
|
|
1087
|
+
milliseconds. No per-record plan time: one statement is planned once for every primitive that sent
|
|
1088
|
+
it. The table's `tenant ms` / `crash ms` / `scale ms` columns, then
|
|
1089
|
+
`took 44704 ms — seed 818 · primitives 41099 · … — slowest: primitives` and the five slowest
|
|
1090
|
+
proofs by record, `slowest: job billing.plan-catalog · crash 35692 ms`. `As of 2026-11`.
|
|
1071
1091
|
|
|
1072
1092
|
The human output prints one line per killed boundary,
|
|
1073
1093
|
`job chargeOrder · killed at mail · X_JOB_CRASH_DIVERGED row:payments:insert 2× (clean 1×)`. The fix
|
|
@@ -1084,14 +1104,18 @@ Source: `packages/testing/src/scale-sweep*.ts`, `plan-oracle.ts`, `plan-sweep*.t
|
|
|
1084
1104
|
|
|
1085
1105
|
| Sweep | What | Red |
|
|
1086
1106
|
|---|---|---|
|
|
1087
|
-
| 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 | a shape sent more often at 8: `X_QUERY_SCALES_WITH_ROWS`, fix `preload()` or `expectedQueryLoop('<why>', fn)` |
|
|
1088
|
-
| 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
|
|
1107
|
+
| 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 |
|
|
1089
1109
|
|
|
1090
1110
|
With the planner's scans and sorts disabled it picks one only when no index can answer, so the
|
|
1091
1111
|
verdict reads the schema on empty tables — no volume, no statistics. Never red: `scale.verdict`
|
|
1092
1112
|
`flat` (a declared loop listed in `expected` with its reason) or `unproven` (a call that did not
|
|
1093
1113
|
answer at both sizes); a statement whose equality pins a unique key; one a partial index serves once
|
|
1094
|
-
its value is bound;
|
|
1114
|
+
its value is bound; a whole read beside a join whose join column leads a declared index on that
|
|
1115
|
+
side, while the other side is bound by its own key — on empty tables a partial index the statement
|
|
1116
|
+
implies looks like one row, so the planner walks it rather than probe it per row (`As of
|
|
1117
|
+
2026-11-08`; with no such index the read is red and its `indexes:` entry is the join column); one
|
|
1118
|
+
under `expectedSeqScan('<why>', fn)` or on an entity with `scan: '<why>'`
|
|
1095
1119
|
(`plans.exempt`); one generic planning refuses (`plans.unplannable`). A server below Postgres 12:
|
|
1096
1120
|
`X_QUERY_PLAN_UNAVAILABLE`.
|
|
1097
1121
|
|
|
@@ -50,7 +50,7 @@ bunx x g resource todo --dry-run
|
|
|
50
50
|
+ apps/web/shared/roles.ts
|
|
51
51
|
+ apps/web/api/index.ts
|
|
52
52
|
+ packages/db/src/client.ts
|
|
53
|
-
✓ would write
|
|
53
|
+
✓ would write 38 file(s) for resource todo — nothing written
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
**The form is an island, not a `ui/` component** — `todo-form.island.tsx` beside the slice rather than under `ui/`. A `createSignal` needs the browser, `.island.tsx` is what puts a module in the client bundle graph, and the route's `budget.js` is what bounds it. Everything under `ui/` renders on the server and ships no JS.
|
|
@@ -62,7 +62,7 @@ bunx x g resource todo
|
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
```text
|
|
65
|
-
✓ wrote
|
|
65
|
+
✓ wrote 40 file(s) for resource todo — next: …
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
`x g` never clobbers — an existing file is `X_GENERATE_CONFLICT`; the i18n catalog is merged key-by-key rather than overwritten; and a **slice module** (`entity.ts`, `repo.ts`, `policy.ts`, `errors.ts`) the slice already has is skipped, `--force` included, because it belongs to the slice rather than to the generator that needed it. The last three lines are the wiring: the grants in `roles.ts`, the slice's actions, query and job in `api/index.ts`, and its entity in the db client (`packages/db/src/client.ts`). A file the run would leave unchanged — a catalog merge that gains no key, wiring a previous slice already wrote — is skipped rather than counted. Here `bun run setup` has written `x.manifest.json` and `openapi.json` ([tutorial 1](Tutorial-01-First-App)), so the run re-projects both and prints 39; in an app with neither it prints 37. In a `x new --no-example` app, whose two `package.json`s do not yet name the workspace packages, the same runs print 39 and 41 (42 with `--admin`).
|
|
@@ -71,7 +71,7 @@ bunx x g resource todo
|
|
|
71
71
|
|
|
72
72
|
| Generator | Emits |
|
|
73
73
|
|---|---|
|
|
74
|
-
| `x g resource <n>` | the whole slice above —
|
|
74
|
+
| `x g resource <n>` | the whole slice above — 38 files on a dry run in tutorial 1's app, 41 with `--admin` (`As of 2026-11-08`); a real run after `bun run setup` adds the two re-projected artifacts |
|
|
75
75
|
| `x g entity` / `policy` / `action` / `mutator` / `query` / `job` / `task` | that primitive plus its test — **and the slice modules its own source imports**, when the slice has none: `x g job` is 5 files into a bare slice, `x g action` 8. Which ones differ per generator, so a job plants no `policy.ts` ([CLI reference § x g](CLI-Reference)) |
|
|
76
76
|
| `x g route <path> --surface site\|app` | `page.tsx`, its stylesheet, its test, its catalog keys |
|
|
77
77
|
|
|
@@ -272,7 +272,7 @@ lists the override under `resources:` in `apps/admin/app/admin/admin.ts` in the
|
|
|
272
272
|
`todo` slice and its wiring:
|
|
273
273
|
|
|
274
274
|
```text
|
|
275
|
-
✓ wrote
|
|
275
|
+
✓ wrote 43 file(s) for resource note — next: …
|
|
276
276
|
``` The
|
|
277
277
|
override is the only hand-written part; fields, operations, filters and forms derive from the entity.
|
|
278
278
|
|