Commit 1998d10
committed
feat(catalog/op_bridge): D-AR-6.3 — lower ast::FieldDefinition.assert to catalog Expr (codex P2 PR #38)
P2 review comment on #38: the bridge transferred
name/table/kind from `ast::FieldDefinition` but silently dropped
`assert: Option<String>` (added in nexgen-rs#27). Result: the
catalog accepts values that the rendered SurrealQL announces it
would reject — exactly the kind of declared-vs-enforced drift the
C16c bridge exists to prevent.
# Fix
`From<ast::FieldDefinition> for catalog::FieldDefinition` now
calls `with_assert(rails_assert_to_expr(s))` so the catalog
carries the same constraint the AST renders.
# `rails_assert_to_expr` — structural lowering
The OpenProject AR-shape extractor emits exactly one expression
today: `$value != NONE` (the schema-level marker for any
`validates_constraint` triple; see PR #28 fix for why it's not
ASSERT-on-`normalizes_attribute`). We construct it structurally as
Expr::Binary {
left: Param("value"),
op: NotEqual,
right: Literal::None,
}
instead of going through surrealdb-core's SurrealQL parser (which
is `async` + heavy). One known shape, one explicit arm.
Comment stripping: PR #28's `normalize:` annotation renders as
`$value != NONE /* normalized */`. The block-comment + whitespace
canonicalisation drops the marker before matching so both inputs
lower to the same Expr. The marker is metadata; the assertion is
unchanged.
Unknown strings (e.g. a future `$value > 100 AND $value < 1000`)
return `None` — the catalog stays accept-any, matching the
previous (pre-D-AR-6.3) silent-drop behaviour. A future PR
swapping in a real mini-parser is the natural next step when the
AR-shape vocab needs richer expressions
(`validates :len, length: {minimum: 3}` → `string::len($value) >= 3`).
# Tests
+4 new under `--features op-bridge`:
- `d_ar_6_3_field_definition_bridges_assert_clause` — matches the
structural Binary($value, !=, NONE) shape.
- `d_ar_6_3_assert_normalized_comment_is_stripped` — the
`/* normalized */` marker is metadata; the lowered Expr is the
same as the bare `$value != NONE` case.
- `d_ar_6_3_no_assert_when_ast_field_has_none` — passthrough
preserves None.
- `d_ar_6_3_unknown_assert_string_lowers_to_none` — unknown
expressions don't corrupt the catalog (safety net).
# Iron-rule lock
§0 ANTI-INVENTION GUARDRAIL honoured: one new free fn
(`rails_assert_to_expr`) over the existing `Expr` / `Param` /
`Literal` types. No new variant, no new builder, no new dep.1 parent 735265c commit 1998d10
1 file changed
Lines changed: 156 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
144 | 146 | | |
145 | 147 | | |
146 | 148 | | |
147 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
148 | 213 | | |
149 | 214 | | |
150 | 215 | | |
| |||
302 | 367 | | |
303 | 368 | | |
304 | 369 | | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
305 | 459 | | |
306 | 460 | | |
307 | 461 | | |
| |||
0 commit comments