Repository navigation
feat(entity): allOf and anyOf, the conjunction and disjunction of invariant predicates - #1338
Conversation
🟡 Reviewed4 actionable comment(s) · grounded on your code |
There was a problem hiding this comment.
Verdict: Approved.
Review summary: 10 file(s), 6 finding(s).
Critical 0 · Major 0 · Minor 6 · Nit 0
Adds allOf and anyOf to entity CHECKs and partial indexes. Dotted keys can hide operand dependencies, and the NULL documentation, parity tests, and arity repair need fixes. The tests cover SQL generation but miss two application verdict regressions.
| File | Findings |
|---|---|
packages/entity/src/expr-connectives.test.ts |
3 minor |
packages/entity/src/expr-connectives.ts |
2 minor |
wiki/Entities-And-Migrations.md |
1 minor |
Superseded: a newer review of this pull request, on commit 4ed04ae, replaces this approval.
There was a problem hiding this comment.
Verdict: Approved.
Review summary: 3 file(s), 4 finding(s).
Critical 0 · Major 0 · Minor 4 · Nit 0
Adds allOf and anyOf for entity CHECKs and partial indexes. The follow-up leaves a misleading NULL guarantee, unusable arity fixes, and gaps in the parity tests. The parity tests miss false taking precedence over unknown in allOf and can pass without the SQL allOf probe constraint.
| File | Findings |
|---|---|
packages/entity/src/expr-connectives.test.ts |
2 minor |
packages/entity/src/expr-connectives.ts |
1 minor |
wiki/Entities-And-Migrations.md |
1 minor |
4 non-blocking finding(s) below major (no thread on a re-review, only blocking findings open threads)
packages/entity/src/expr-connectives.test.ts:65minor · test The mixed false/NULL probe passes even ifallOfreturns UNKNOWN instead of FALSE oranyOfreturns FALSE instead of UNKNOWN, becauseiff(..., false)accepts both. Add aniffprobe against a true predicate for this row to distinguish the two outcomes.packages/entity/src/expr-connectives.test.ts:125minor · test The SQL assertion stays green if theall_not_trueCHECK is omitted:any_not_truealready rejects every row thatall_not_truerejects. Test each CHECK on its own table so its refusal is observable independently.packages/entity/src/expr-connectives.ts:63minor · bug The arity fix forallOf(c.title.isNotNull())is prose that cannot be pasted as TypeScript, and the fix forallOf()references undefinedfirstandsecond. Follow CLAUDE.md andkb:review/learnings: give a pasteable repair, with any explanation in the comment.wiki/Entities-And-Migrations.md:157minor · docs The paragraph still opens by promising that a rule over a nullable column passes NULL, but its ownallOfexample rejectsa = NULL, b = 2. Scope the opening claim to individual comparisons and say that a composite CHECK accepts TRUE or UNKNOWN only as its final verdict.
Reviewed with gpt-6.2-sol
…ariant predicates
An index `where` or a CHECK over several columns at once ("both null",
"at most one set") had no form: `iff` was the one combinator, so a
partial index on `a is null and b is null` was hand-written and drew
`X_DB_INDEX_UNDECLARED` as drift.
- `allOf(...predicates)` / `anyOf(...predicates)`: two or more operands,
SQL `(a) and (b)` / `(a) or (b)`, the app verdict in SQL's three
values. One app-only operand makes the whole rule app-only (an index
`where` refuses that by name); a `unique` operand or fewer than two
is `X_INVARIANT_VIOLATED` at declaration.
- `iff`'s operand rules move to `expr-connectives.ts` and are shared.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured with the metafile walk; each raise names its module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ue; paths keep their segments - a row only the first allOf operand refuses; each connective inside iff against a decided false, so unknown passes and true is refused, app and CHECK alike. - operandPaths keys a path by its whole segment list. - the one-operand refusal names only the author's own column. - the NULL guarantee is stated per comparison; a composite's final verdict decides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… ceilings re-measured Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4ed04ae to
1364851
Compare
There was a problem hiding this comment.
Verdict: Approved.
Review summary: 10 file(s), 4 finding(s).
Critical 0 · Major 0 · Minor 4 · Nit 0
Adds three-valued allOf and anyOf predicates for entity checks and partial indexes. The database parity test can miss a dropped allOf check, and the arity diagnostic can suggest an unbound call.
| File | Findings |
|---|---|
packages/entity/src/expr-connectives.test.ts |
3 minor |
packages/entity/src/expr-connectives.ts |
1 minor |
4 non-blocking finding(s) below major (no thread on a re-review, only blocking findings open threads)
packages/entity/src/expr-connectives.test.ts:29minor · test EveryallOffixture has two operands, so an evaluator that ignores the third operand passes these tests. Add a three-operand conjunction with a row where only the third predicate is false and assert that bothholdsand the CHECK reject it.packages/entity/src/expr-connectives.test.ts:111minor · test On both mixed rows whereallOfis UNKNOWN, theanyOfCHECK already rejects the insert, so renderingallOfas TRUE still passes the SQL test, andiffagainst FALSE alone cannot distinguish UNKNOWN from FALSE in the app. Test each connective independently withiffagainst both TRUE and FALS…packages/entity/src/expr-connectives.test.ts:125minor · test The database probe still passes if the migration omitsall_not_true: every row that check should reject is also rejected byany_not_true. Put the two checks on separate probe tables and compare each insert outcome to its own expected verdict.packages/entity/src/expr-connectives.ts:63minor · bug WithallOf(), the fix starts withallOf(first, second), which fails when pasted because neither name is bound. Branch on operand count and lead with the actual edit: remove the empty declaration or unwrap the existing predicate for a singleton.
Reviewed with gpt-6.2-sol
What
An entity's index
whereor CHECK could not say two conditions at once — "both null", "at most one set":iffwas the one combinator. A partial index ona is null and b is nullhad to be hand-written, and the drift step reported it asX_DB_INDEX_UNDECLARED.allOf(...predicates)(a) and (b) …andin three values: false if any is false, else unknown if any is unknown (a CHECK passes it), else trueanyOf(...predicates)(a) or (b) …or: true if any is true, else unknown if any is unknown, else falseX_INVARIANT_VIOLATED(the author left a condition out). Auniqueoperand is refused asiffrefuses it — the rule now lives inexpr-connectives.ts, shared by all three.matches(fn)) makes the whole rulesql: null, never half of it; an indexwhererefuses that by name, as before.notstays absent:isNull/isNotNullare the negations a CHECK needs.Proof
expr-connectives.test.ts: one corpus judged by the app and by the migration's CHECK on PGlite — agree on every row, NULL included; the SQL text; a partial index whosepg_indexes.indexdefreadsWHERE ((a IS NULL) AND (b IS NULL)); an app-only operand; one operand and auniqueoperand refused. New file, so it failed before.refuse.test.tsholds the new refusal site.bun test ./packages/entity/src: 2288 pass, 0 fail.bun run boundariesclean;scripts/public-api.ts: 0 breaks.Docs:
wiki/Entities-And-Migrations.md(the invariant table), CHANGELOG.🤖 Generated with Claude Code