@ultimat3/cli 30.7.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/package.json +28 -28
- package/src/exercise-subject.ts +9 -2
- package/wiki/Testing.md +17 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "30.
|
|
3
|
+
"version": "30.8.0",
|
|
4
4
|
"description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -53,33 +53,33 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/core": "^8.0.7",
|
|
56
|
-
"@ultimat3/action": "30.
|
|
57
|
-
"@ultimat3/admin": "30.
|
|
58
|
-
"@ultimat3/ai": "30.
|
|
59
|
-
"@ultimat3/auth": "30.
|
|
60
|
-
"@ultimat3/cache": "30.
|
|
61
|
-
"@ultimat3/core": "30.
|
|
62
|
-
"@ultimat3/db": "30.
|
|
63
|
-
"@ultimat3/entity": "30.
|
|
64
|
-
"@ultimat3/flags": "30.
|
|
65
|
-
"@ultimat3/http": "30.
|
|
66
|
-
"@ultimat3/i18n": "30.
|
|
67
|
-
"@ultimat3/jobs": "30.
|
|
68
|
-
"@ultimat3/mail": "30.
|
|
69
|
-
"@ultimat3/manifest": "30.
|
|
70
|
-
"@ultimat3/mcp": "30.
|
|
71
|
-
"@ultimat3/money": "30.
|
|
72
|
-
"@ultimat3/notify": "30.
|
|
73
|
-
"@ultimat3/policy": "30.
|
|
74
|
-
"@ultimat3/pwa": "30.
|
|
75
|
-
"@ultimat3/query": "30.
|
|
76
|
-
"@ultimat3/realtime": "30.
|
|
77
|
-
"@ultimat3/render": "30.
|
|
78
|
-
"@ultimat3/schema": "30.
|
|
79
|
-
"@ultimat3/seo": "30.
|
|
80
|
-
"@ultimat3/storage": "30.
|
|
81
|
-
"@ultimat3/testing": "30.
|
|
82
|
-
"@ultimat3/time": "30.
|
|
56
|
+
"@ultimat3/action": "30.8.0",
|
|
57
|
+
"@ultimat3/admin": "30.8.0",
|
|
58
|
+
"@ultimat3/ai": "30.8.0",
|
|
59
|
+
"@ultimat3/auth": "30.8.0",
|
|
60
|
+
"@ultimat3/cache": "30.8.0",
|
|
61
|
+
"@ultimat3/core": "30.8.0",
|
|
62
|
+
"@ultimat3/db": "30.8.0",
|
|
63
|
+
"@ultimat3/entity": "30.8.0",
|
|
64
|
+
"@ultimat3/flags": "30.8.0",
|
|
65
|
+
"@ultimat3/http": "30.8.0",
|
|
66
|
+
"@ultimat3/i18n": "30.8.0",
|
|
67
|
+
"@ultimat3/jobs": "30.8.0",
|
|
68
|
+
"@ultimat3/mail": "30.8.0",
|
|
69
|
+
"@ultimat3/manifest": "30.8.0",
|
|
70
|
+
"@ultimat3/mcp": "30.8.0",
|
|
71
|
+
"@ultimat3/money": "30.8.0",
|
|
72
|
+
"@ultimat3/notify": "30.8.0",
|
|
73
|
+
"@ultimat3/policy": "30.8.0",
|
|
74
|
+
"@ultimat3/pwa": "30.8.0",
|
|
75
|
+
"@ultimat3/query": "30.8.0",
|
|
76
|
+
"@ultimat3/realtime": "30.8.0",
|
|
77
|
+
"@ultimat3/render": "30.8.0",
|
|
78
|
+
"@ultimat3/schema": "30.8.0",
|
|
79
|
+
"@ultimat3/seo": "30.8.0",
|
|
80
|
+
"@ultimat3/storage": "30.8.0",
|
|
81
|
+
"@ultimat3/testing": "30.8.0",
|
|
82
|
+
"@ultimat3/time": "30.8.0",
|
|
83
83
|
"babel-preset-solid": "^1.9.16"
|
|
84
84
|
}
|
|
85
85
|
}
|
package/src/exercise-subject.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { identifier, sql } from '@ultimat3/db';
|
|
|
9
9
|
import type { EntityCore, RegistryEntry } from '@ultimat3/entity';
|
|
10
10
|
import type { Subject } from '@ultimat3/jobs';
|
|
11
11
|
import { planSubject } from '@ultimat3/jobs';
|
|
12
|
-
import type { SeedFactory } from '@ultimat3/testing';
|
|
12
|
+
import type { SeedFactory, SeedGraph } from '@ultimat3/testing';
|
|
13
13
|
import { entitySeedWriter, subjectProof } from '@ultimat3/testing';
|
|
14
14
|
import type { Finding } from './output';
|
|
15
15
|
|
|
@@ -43,6 +43,9 @@ export async function subjectProofFindings(
|
|
|
43
43
|
factories?: Readonly<Record<string, SeedFactory>>,
|
|
44
44
|
): Promise<readonly Finding[]> {
|
|
45
45
|
const findings: Finding[] = [];
|
|
46
|
+
// Every subject's graph lands on this one database: each is seeded beside the last written, so a
|
|
47
|
+
// factory value built from the row index never repeats an earlier subject's on a unique column.
|
|
48
|
+
let beside: SeedGraph | undefined;
|
|
46
49
|
for (const [index, subject] of subjects.entries()) {
|
|
47
50
|
// A plan the static half refused is reported there, once; an erase that throws is a finding.
|
|
48
51
|
const problems = await subjectProof(subject, {
|
|
@@ -52,8 +55,12 @@ export async function subjectProofFindings(
|
|
|
52
55
|
client.query<Record<string, unknown>>(sql`select * from ${identifier(entity.$table)}`),
|
|
53
56
|
seed: SUBJECT_PROOF_SEED + index,
|
|
54
57
|
factories,
|
|
58
|
+
beside,
|
|
55
59
|
}).then(
|
|
56
|
-
(result) =>
|
|
60
|
+
(result) => {
|
|
61
|
+
beside = result.graph ?? beside;
|
|
62
|
+
return result.problems.filter((p) => p.code === 'X_SUBJECT_ERASE_INCOMPLETE');
|
|
63
|
+
},
|
|
57
64
|
(error: unknown) => (isUltimateError(error) ? [error] : Promise.reject(error)),
|
|
58
65
|
);
|
|
59
66
|
for (const problem of problems) {
|
package/wiki/Testing.md
CHANGED
|
@@ -905,6 +905,7 @@ await insertSeedGraph(graph, writer);
|
|
|
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 |
|
|
@@ -994,16 +995,17 @@ shape, same unreached code. `As of 2026-11`.
|
|
|
994
995
|
|---|---|
|
|
995
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 |
|
|
996
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)) |
|
|
997
|
-
| Actor | the entry's `actor` when it declares one, seated in the primitive's tenant — and a top-level value of its bound input 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`) |
|
|
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`) |
|
|
998
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` |
|
|
999
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` |
|
|
1000
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 |
|
|
1001
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` |
|
|
1002
|
-
| 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 |
|
|
1003
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` |
|
|
1004
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 |
|
|
1005
|
-
| 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)). An unknown name is `X_DECLARATION_UNKNOWN`; a blank `off` is `X_CONTRACT_EXERCISE_UNDECLARED` |
|
|
1006
|
-
| 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`) |
|
|
1007
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` |
|
|
1008
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`) |
|
|
1009
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 |
|
|
@@ -1052,8 +1054,11 @@ capability is proven); it excuses nothing on an action or a query, which answer
|
|
|
1052
1054
|
job B handed one of A's ids — that is B choosing A's row, crossed as ever. `tenant: 'none'` excuses
|
|
1053
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
|
|
1054
1056
|
write to A's row with no id in the input is a statement no tenant predicate scopes, crossed. A
|
|
1055
|
-
finding prints paths, tables and seeded ids, never a bound value
|
|
1056
|
-
|
|
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
|
|
1057
1062
|
does not walk — a `route` `load`, a `task` — is
|
|
1058
1063
|
[Policies and authz](Policies-And-Authz#the-dynamic-tenant-proof).
|
|
1059
1064
|
|
|
@@ -1099,14 +1104,18 @@ Source: `packages/testing/src/scale-sweep*.ts`, `plan-oracle.ts`, `plan-sweep*.t
|
|
|
1099
1104
|
|
|
1100
1105
|
| Sweep | What | Red |
|
|
1101
1106
|
|---|---|---|
|
|
1102
|
-
| 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)` |
|
|
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)` |
|
|
1103
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 |
|
|
1104
1109
|
|
|
1105
1110
|
With the planner's scans and sorts disabled it picks one only when no index can answer, so the
|
|
1106
1111
|
verdict reads the schema on empty tables — no volume, no statistics. Never red: `scale.verdict`
|
|
1107
1112
|
`flat` (a declared loop listed in `expected` with its reason) or `unproven` (a call that did not
|
|
1108
1113
|
answer at both sizes); a statement whose equality pins a unique key; one a partial index serves once
|
|
1109
|
-
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>'`
|
|
1110
1119
|
(`plans.exempt`); one generic planning refuses (`plans.unplannable`). A server below Postgres 12:
|
|
1111
1120
|
`X_QUERY_PLAN_UNAVAILABLE`.
|
|
1112
1121
|
|