test+docs: 3k Phase-3 verification sweep — e2e DML + filled cross-cut matrix

Sub-phase 3k of ADR-0033. Adds the Tier-3 end-to-end DML suite (tests/sql_dml_e2e.rs) and the cross-cut gap-fill tests, fills the verification matrix (every row a verified file::function), and produces the phase-exit report.

- tests/sql_dml_e2e.rs: INSERT…SELECT cross-table, all-ten-type multi-row INSERT + RETURNING type recovery, UPDATE-with-subquery-in-SET, cascade DELETE, UPSERT round-trip, RETURNING x3, history.log replay, OOS rejections (full §13 table), validity-indicator-from-SQL-DML.
- walker/mod.rs, highlight.rs, completion.rs, input_render.rs: inherited-diagnostic, DML-keyword highlight, INSERT INTO completion, and advanced-mode DML hint-panel cross-cuts.
- Matrix correction (user-confirmed): predicate warnings fire on row-scoped DML slots; INSERT VALUES has no row scope (ADR-0033 §8.4).
- Auto-snapshot row marked N/A (user-confirmed): ADR-0006 unimplemented for both paths; deferred.

/runda round: added an advanced-mode DML hint-panel test (A6 was attributed to simple-mode prose under the §8 advanced heading); extended OOS coverage to the full ADR-0033 §13 table (OOS-5 INDEXED BY / OOS-6 multi-statement) + a trailing-semicolon guard.

1645 passing / 0 failing / 0 skipped / 1 ignored. Clippy clean.
This commit is contained in:
claude@clouddev1
2026-05-23 22:26:04 +00:00
parent a5cdb00a86
commit 380c4238ef
7 changed files with 1150 additions and 84 deletions
@@ -0,0 +1,283 @@
# Phase 3 (ADR-0033) — phase-exit verification report
**Date:** 2026-05-23
**Sub-phase:** 3k (verification sweep)
**Driving ADR:** [ADR-0033 — full SQL DML grammar](../adr/0033-sql-dml-grammar.md)
(+ Amendments 13)
**Plan:** [docs/plans/20260520-adr-0033-phase-3.md](../plans/20260520-adr-0033-phase-3.md)
This report closes Phase 3. It records the test totals, the filled
cross-cut verification matrix (in the plan doc), the
requirements-to-test mapping, the autonomous decisions made during
3k (both user-confirmed), and the Devil's-Advocate final review.
---
## 1. Test-suite totals
| Metric | Phase-2 baseline | Phase-3 exit (3k) | Δ |
|----------|------------------|-------------------|---|
| passed | 1446 | **1645** | +199 |
| failed | 0 | **0** | 0 |
| skipped | 0 | **0** | 0 |
| ignored | 1 (doctest) | **1** (doctest) | 0 |
- `cargo test`**1645 passed; 0 failed; 0 skipped; 1 ignored**.
The single ignored test is the unchanged `src/friendly/mod.rs`
doctest (a non-executable illustrative snippet), as in every prior
phase.
- `cargo clippy --all-targets -- -D warnings`**clean**.
- No regression from the Phase-2 baseline; every prior test stays
green.
3k itself added **19 tests** over the handoff-33 count (1626):
- `tests/sql_dml_e2e.rs` — 11 Tier-3 end-to-end DML tests (new file),
including the OOS parse-rejections (extended to the full §13 table —
OOS-1…6 — during the `/runda` round) and the single-statement
trailing-`;` guard.
- `src/dsl/walker/mod.rs::tests` — 5 inherited-diagnostic cross-cuts
(I3 DELETE/UPDATE WHERE, I6 like-numeric on DELETE WHERE, I7 the
corrected row-scoped predicate slots).
- `src/dsl/walker/highlight.rs::tests` — 1 DML-keyword highlight test.
- `src/completion.rs::tests` — 1 `INSERT INTO` target-table
completion test.
- `src/input_render.rs::tests` — 1 advanced-mode DML hint-panel test
(added in the `/runda` round; see §5.1).
---
## 2. Cross-cut verification matrix
The full matrix is filled in the plan doc:
[docs/plans/20260520-adr-0033-phase-3.md → "Cross-cut verification
matrix"](../plans/20260520-adr-0033-phase-3.md). Every row carries a
verified `file::function` (the legend maps the abbreviations) and a
status:
- **85 rows ✅** — a green test whose INPUT matches the claim source
(SQL claims take SQL-syntax input, per the handoff-29 §4.4 pin,
cross-checked at attribution time by reading each test).
- **1 row N/A** — auto-snapshot (ADR-0006), unimplemented for both
paths; see §4 / footnote [e].
- **0 rows ❌.**
Five rows carry footnotes recording resolutions surfaced during 3k
(matrix footnotes [a][e]): the Amendment-1 dispatch mechanism, the
Amendment-3 simple-mode pointer, the Amendment-2 cascade count-diff,
the corrected predicate-in-VALUES claim, and the auto-snapshot
deferral.
**Attribution integrity note.** The initial catalog pass (sub-agent
survey) produced several fabricated function names and mis-attributed
the dispatch rows to the 3a synthetic smoke tests. Every row in the
final matrix was re-verified by reading the named test, per the
project's "probe, don't reason" discipline. In particular the
inherited-diagnostic rows (I1I7) and the dispatch rows now point at
the real tests in `src/dsl/walker/mod.rs::tests` and
`src/dsl/parser.rs::tests`.
---
## 3. Requirements-to-test mapping (ADR-0033 §§113)
| § | Decision | Proven by |
|---|----------|-----------|
| §1 | INSERT/UPDATE/DELETE statement shapes | `ins::single_row_…`, `ins::multi_row_…`, `ins::no_column_list_…`, `upd::*`, `del::*` |
| §2 | Dispatch on shared entry words (Amendments 1 & 3) | `parser::advanced_ambiguous_{insert,update,delete}_routes_to_sql`, `parser::advanced_dsl_only_delete_falls_back_to_dsl`, `parser::simple_*` |
| §3 | Multi-row VALUES | `ins::multi_row_insert_persists_both_rows`, `e2e::e2e_multirow_insert_all_ten_types_…` |
| §4 | INSERT … SELECT (+ WITH-prefixed row source) | `ins::insert_select_copies_rows_and_persists`, `ins::with_prefixed_insert_select_runs_and_persists`, `e2e::e2e_insert_select_cross_table_…` |
| §5 | RETURNING on all three kinds | `ins::insert_returning_*`, `upd::update_returning_*`, `del::delete_returning_*`, `e2e::e2e_returning_on_insert_update_delete` |
| §6 | shortid auto-fill (worker post-fill) | `ins::values_autofills_*`, `ins::*_distinct_shortids`, `ins::combined_serial_and_shortid_autofill` |
| §7 | Cascade summary on DELETE (Amendment 2 — count-diff) | `del::cascade_parity_with_dsl`, `del::r2_where_with_subquery`, `del::cascade_delete_reports_summary_and_repersists_child` |
| §8.1 | `insert_arity_mismatch` (ERROR, per-row) | `walker::insert_arity_mismatch_*` |
| §8.2 | `auto_column_overridden` (WARNING) | `walker::auto_column_overridden_*` |
| §8.3 | `not_null_missing` (WARNING) | `walker::not_null_missing_*` |
| §8.4 | Inherited Phase-2 diagnostics on DML slots | `walker::insert_column_list_unknown_column_is_flagged`, `walker::sql_update_*`, `walker::sql_delete_where_*`, `walker::insert_select_where_predicate_warns` |
| §9 | UPSERT (`ON CONFLICT … DO NOTHING/UPDATE`, `excluded`) | `ins::on_conflict_*`, `completion::excluded_prefix_completes_to_target_columns`, `walker::excluded_*` |
| §10 | Three typed Command variants + worker handlers + persistence | `ins`/`upd`/`del` worker round-trips, `e2e::*` |
| §11 | Engine-error translation (reuses existing keys) | `friendly::enrich_unique_*`, `friendly::enrich_not_null_*`, `del::delete_violating_fk_fails_and_persists_nothing` |
| §12 | Result-column type recovery on RETURNING | `e2e::e2e_multirow_insert_all_ten_types_…` (all ten), `ins::insert_returning_recovers_multiple_bare_column_types` |
| §13 | OOS rejections (DEFAULT VALUES, OR REPLACE, UPDATE FROM, WITH UPDATE/DELETE) | `e2e::e2e_out_of_scope_dml_forms_parse_reject` |
---
## 4. Autonomous decisions during 3k (both user-confirmed)
Per `CLAUDE.md`: an autonomous decision without explicit user
confirmation is a verdict FAIL. Two ADR-vs-implementation mismatches
surfaced while filling the matrix; both were escalated and resolved
**before** any test or matrix edit landed (`AskUserQuestion`,
2026-05-23):
1. **Matrix row I7 — "predicate warning fires inside INSERT VALUES
sql_expr".** Probing showed the predicate-warning pass fires on
every DML `sql_expr` slot that carries a resolvable column binding
(UPDATE/DELETE WHERE, UPDATE SET incl. CASE, INSERT…SELECT
projection & WHERE) but **not** in plain `INSERT … VALUES`, because
a VALUES literal has no row scope (a bare-column predicate there is
meaningless). ADR-0033 §8.4 itself describes the pass as covering
"WHERE and CASE expressions." **User decision: correct the matrix
claim** to the realizable, row-scoped slots. Backed by new tests
`walker::sql_update_set_case_predicate_warns` and
`walker::insert_select_where_predicate_warns`. No code change.
2. **Matrix row "Auto-snapshot fires for SQL DML the same way as DSL"
(ADR-0006 / ADR-0033 §10).** ADR-0006 auto-snapshot/undo is
unimplemented for **both** the DSL and SQL paths (the U-series, per
`CLAUDE.md` "Things deliberately deferred"). **User decision: mark
N/A — deferred.** The "same as DSL" parity holds vacuously and
Phase 3 introduces no regression; ADR-0033 §10's auto-snapshot
consequence is contingent on the deferred ADR-0006 work.
No other autonomous decisions were made in 3k. (The 3d Option-A/B
escalation and the Amendment 1/2/3 decisions were resolved in their
own sub-phases with user approval, recorded in ADR-0033.)
---
## 5. Devil's-Advocate final review
Specific critiques first; verdict last (handoff-28/29 §4.1 pin — a
rubber-stamp PASS is a process failure).
### 5.1 `/runda` round (second-pass DA, user-invoked)
A user-invoked `/runda` round re-checked the matrix attributions
against the actual test inputs/modes and re-swept the requirement
sources. It found and closed two issues, and re-verified the rest:
1. **A6 (hint-panel) was attributed to Simple-mode tests under an
advanced (§8) heading.** The hint-prose tests call `ambient_hint`,
which defaults to `Mode::Simple` (the DSL value-slot prose) — so the
§8 *advanced*-surface claim had no advanced-mode attribution.
*Fixed:* added `input_render::advanced_mode_ambient_offers_dml_slot_candidates`
(column candidates at an advanced-mode `UPDATE … SET` LHS and inside
an `INSERT … (` column list); matrix footnote [f].
2. **OOS-5 / OOS-6 (ADR-0033 §13) had no tests.** The plan's matrix
scoped OOS to §13's first four rows; OOS-5 (`INDEXED BY` /
`NOT INDEXED`) and OOS-6 (multi-statement batch) were unverified.
*Probed:* all reject in Advanced mode; a single statement with a
trailing `;` still parses. *Fixed:* extended
`e2e_out_of_scope_dml_forms_parse_reject` to the full §13 table and
added `e2e_single_dml_statement_with_trailing_semicolon_parses`;
added matrix rows OOS-5/OOS-6.
Re-verified clean (no change needed):
- **requirements.md** — Q1/Q2 (SQL subset + clear out-of-subset
rejection message) and M1/M2 (mode acceptance) are multi-phase and
remain `[ ]` by design; Phase 3 contributes the DML slice without
claiming closure. Q2's *polished* rejection message is explicitly
"Implementation pending" — the 3k OOS tests assert only that the
forms parse-**reject** (ADR-0033 §13), not message quality, so no
over-claim. M4 is the deferred side-channel (Amendment 3).
- **Issue trackers** — `origin` is GitHub (`gh issue list` empty); the
configured gitea instance does not host this repo. The handoff's
"#8/#9/#12" are internal task/finding numbers, not external issues.
No external acceptance criteria exist beyond the ADRs / plan /
requirements.md.
- **Engine-neutrality** — all new Phase-3 catalog strings
(`also_valid_sql`, `insert_arity_mismatch`, `auto_column_overridden`,
`not_null_missing`, plus the reused `eq_null`/`like_numeric`/
`sql_in_simple`) are engine-neutral; a full scan of
`src/friendly/strings/en-US.yaml` for `sqlite`/`rusqlite`/`pragma`/
`strict` finds only a code comment and the internal `sqlite:` key
whose value ("database error: …") is neutral. `engine_vocabulary_audit`
is green.
- The catalog-attribution sub-agents' fabrications (noted below) were
the original trigger for verifying every row by hand; the `/runda`
pass confirmed no fabricated or mode-mismatched attribution survived.
### 5.2 Final critiques
### Critiques raised and their resolution
1. **The catalog sub-agents fabricated test names and mis-attributed
the dispatch rows.** Real risk of a matrix that points at
non-existent or wrong tests. *Resolved:* every row was re-verified
by reading the named test; the I1I7 and dispatch rows now point at
the real `walker::` / `parser::` tests, not the fabricated names or
the 3a smoke registry.
2. **Two matrix rows over-claimed vs the implementation** (predicate
warnings in VALUES; auto-snapshot). The Phase-2 lesson was "expect
at least one gap from filling the matrix" — Phase 3 surfaced two.
*Resolved:* both escalated to the user and dispositioned (§4); the
corrected predicate claim gained two backing tests, and the
auto-snapshot row is N/A-deferred, not silently dropped.
3. **R5 (ten-type recovery via RETURNING) was only 5/10 before 3k.**
The existing `insert_returning_recovers_multiple_bare_column_types`
covered int/text/decimal/real/bool only. *Resolved:* the new
`e2e::e2e_multirow_insert_all_ten_types_…` asserts column-origin
recovery for **all ten** types via a `RETURNING` list.
4. **`blob` is inserted NULL in the all-types e2e.** Honest limitation:
`src/dsl/value.rs` has no blob value-literal yet (a pre-existing,
tracked DSL gap — not a Phase-3 regression). The blob column's
*type* still round-trips through the RETURNING column-origin path,
which is what §12 claims. The data round-trip is exercised for the
other nine types.
5. **The Tier-3 e2e tests go parse → worker, not through the full
Tokio event loop.** *Mitigation:* the App dispatch seam is covered
separately (`parser::*` dispatch tests + the `sql_select.rs`
App-driven tests), and the runtime replay loop is exercised
end-to-end by `e2e::e2e_replay_phase3_dml_forms_from_a_script`
(`run_replay` → parse-in-advanced → worker → persisted state). The
full stack is covered across these seams.
6. **No requirement was silently downgraded to "later."** The only
deferrals (auto-snapshot, blob literals) are pre-existing,
user-confirmed, and tracked — not new scope reductions introduced
by 3k.
### Verdict
**PASS.** All 1645 tests green, zero failed, zero skipped, one
unchanged ignored doctest; clippy clean; no regression from the
Phase-2 1446 baseline. Every cross-cut matrix row is ✅ (85) or
N/A-deferred (1, user-confirmed), with verified `file::function`
attributions whose inputs/modes match the claim source — re-checked
in the `/runda` round (§5.1), which corrected the A6 mode mismatch and
closed the OOS-5/6 coverage gap. The two over-claims the matrix
carried (predicate-in-VALUES, auto-snapshot) were surfaced, escalated,
and resolved with the user rather than papered over.
---
## 6. State at handoff
- **Branch:** `main`. **Tests: 1645 passing, 0 failing, 0 skipped, 1
ignored.** Clippy clean.
- **Uncommitted** (this session's 3k work, pending the user's commit
approval):
- `tests/sql_dml_e2e.rs` (new — 11 Tier-3 e2e tests)
- `src/dsl/walker/mod.rs` (5 cross-cut tests)
- `src/dsl/walker/highlight.rs` (DML-keyword highlight test)
- `src/completion.rs` (INSERT INTO target-table completion test)
- `src/input_render.rs` (advanced-mode DML hint-panel test — `/runda`)
- `docs/plans/20260520-adr-0033-phase-3.md` (matrix filled +
footnotes)
- `docs/handoff/20260523-phase-3-verification.md` (this report)
- **ADR-0033** can move from *Proposed* to *Accepted* once the user
accepts this report (the plan's §5 hand-back point). Its three
amendments are already settled.
### Follow-ups (tracked, not blocking Phase 3)
Per the user's standing "extra tasks after phase 3 is complete":
- **ADR-0006 auto-snapshot/undo** (U-series) — implement for both the
DSL and SQL DML worker handlers; satisfies the N/A matrix row.
- **M4 — execution-time mode side-channel** (ADR-0033 Amendment 3;
`requirements.md`). Its own future ADR.
- **TASK #8 — ADR-0034 history journal**; **TASK #9 — replay line
format** (`<ts>|<status>|<source>`). Orthogonal to Phase 3.
- **blob value-literal** in the DSL/SQL value grammar
(`src/dsl/value.rs`) — pre-existing gap.
- The cosmetic `tests/sql_*.rs` helper names (`run_sqlinsert` etc.)
retain their dev-word-era spelling though they now parse the real
words.
+142 -84
View File
@@ -1290,101 +1290,159 @@ input" (handoff-29 §4.4 pin).
| Claim source | Claim | Test location | Status | | Claim source | Claim | Test location | Status |
|------------------------|--------------------------------------------------------------------------------|---------------|--------| |------------------------|--------------------------------------------------------------------------------|---------------|--------|
| **Statement shapes (§1)** | | | | | **Statement shapes (§1)** | | | |
| ADR-0033 §1 | Single-row VALUES INSERT runs end-to-end | TBD (3b) | | | ADR-0033 §1 | Single-row VALUES INSERT runs end-to-end | `ins::single_row_insert_persists_and_counts` | |
| ADR-0033 §1 | Multi-row VALUES INSERT runs end-to-end | TBD (3b) | | | ADR-0033 §1 | Multi-row VALUES INSERT runs end-to-end | `ins::multi_row_insert_persists_both_rows` | |
| ADR-0033 §1 | INSERT with `(column_name_list)` runs | TBD (3b) | | | ADR-0033 §1 | INSERT with `(column_name_list)` runs | `ins::single_row_insert_persists_and_counts` | |
| ADR-0033 §1 | INSERT without column list (full table arity) runs | TBD (3b) | | | ADR-0033 §1 | INSERT without column list (full table arity) runs | `ins::no_column_list_full_arity_insert_persists` | |
| ADR-0033 §4 | `INSERT … SELECT` runs | TBD (3c) | | | ADR-0033 §4 | `INSERT … SELECT` runs | `ins::insert_select_copies_rows_and_persists`, `e2e::e2e_insert_select_cross_table_copies_rows_and_persists_both` | |
| ADR-0033 §4 / R4 | `INSERT … WITH … SELECT` row source runs (Amendment-2 carry-through) | TBD (3c) | | | ADR-0033 §4 / R4 | `INSERT … WITH … SELECT` row source runs (Amendment-2 carry-through) | `ins::with_prefixed_insert_select_runs_and_persists` | |
| ADR-0033 §1 | UPDATE with WHERE runs | TBD (3e) | | | ADR-0033 §1 | UPDATE with WHERE runs | `upd::single_column_update_with_where_persists` | |
| ADR-0033 §1 / §12 | UPDATE without WHERE runs (no `--all-rows` rail) | TBD (3e) | | | ADR-0033 §1 / §12 | UPDATE without WHERE runs (no `--all-rows` rail) | `upd::update_without_where_runs_across_all_rows` | |
| ADR-0033 §1 | UPDATE with multi-column SET | TBD (3e) | | | ADR-0033 §1 | UPDATE with multi-column SET | `upd::multi_column_update_persists` | |
| ADR-0033 §1 | UPDATE with sql_expr in SET (function call, subquery, CASE) | TBD (3e) | | | ADR-0033 §1 | UPDATE with sql_expr in SET (function call, subquery, CASE) | `upd::update_with_sql_expr_in_set`, `e2e::e2e_update_with_subquery_in_set` | |
| ADR-0033 §1 | DELETE with WHERE runs | TBD (3f) | | | ADR-0033 §1 | DELETE with WHERE runs | `del::delete_with_where_persists` | |
| ADR-0033 §1 / §12 | DELETE without WHERE runs (no `--all-rows` rail) | TBD (3f) | | | ADR-0033 §1 / §12 | DELETE without WHERE runs (no `--all-rows` rail) | `del::delete_without_where_runs_across_all_rows` | |
| **Dispatch (§2)** | | | | | **Dispatch (§2)** | | | |
| ADR-0033 §2 / 3a | Guard fires BEFORE Seq commits (R1 invariant on synthetic markers) | TBD (3a) | | | ADR-0033 §2 / 3a | Guard fires BEFORE Seq commits (R1 invariant on synthetic markers) [a] | `walker::advanced_mode_dsl_input_falls_back_to_dsl` | |
| ADR-0033 §2 | Simple mode + DSL INSERT → DSL branch | TBD (3j) | | | ADR-0033 §2 | Simple mode + DSL shared word → DSL branch | `parser::simple_dsl_delete_stays_dsl` | |
| ADR-0033 §2 | Simple mode + SQL INSERT (RETURNING) → ValidationFailed `advanced_mode.sql_in_simple` | TBD (3j) | | | ADR-0033 §2 [b] | Simple mode + shared word w/ SQL-only construct → DSL parse error + combined pointer | `parser::simple_shared_word_with_sql_construct_is_a_dsl_parse_error`, `input_render::ambient_hint_combines_dsl_error_with_advanced_sql_pointer`, `app::simple_mode_submit_of_sql_construct_appends_advanced_pointer`; SQL-only *entry* word → `parser::simple_sql_only_entry_word_points_at_advanced_mode` | |
| ADR-0033 §2 | Advanced + structurally-ambiguous (`delete from t where id = 1`) → SQL branch | TBD (3j) | | | ADR-0033 §2 | Advanced + structurally-ambiguous (`delete from t where id = 1`) → SQL branch | `parser::advanced_ambiguous_delete_routes_to_sql` | |
| ADR-0033 §2 | Advanced + DSL-only (`--all-rows`) → DSL branch (Choice falls through) | TBD (3j) | | | ADR-0033 §2 | Advanced + DSL-only (`--all-rows`) → DSL branch (falls through) | `parser::advanced_dsl_only_delete_falls_back_to_dsl` | |
| ADR-0033 §2 | Same for UPDATE shared entry word | TBD (3j) | | | ADR-0033 §2 | Same for UPDATE shared entry word (+ `--all-rows` SQL-absorb counter-example) | `parser::advanced_ambiguous_update_routes_to_sql`, `e2e::e2e_update_all_rows_in_advanced_does_not_fall_back_to_dsl` | |
| ADR-0033 §2 | Same for INSERT shared entry word | TBD (3j) | | | ADR-0033 §2 | Same for INSERT shared entry word | `parser::advanced_ambiguous_insert_routes_to_sql` | |
| **RETURNING (§5 / §12)** | | | | | **RETURNING (§5 / §12)** | | | |
| ADR-0033 §5 | INSERT … RETURNING * surfaces DataResult | TBD (3g) | | | ADR-0033 §5 | INSERT … RETURNING * surfaces DataResult | `ins::insert_returning_star_returns_inserted_row`, `e2e::e2e_returning_on_insert_update_delete` | |
| ADR-0033 §5 | UPDATE … RETURNING cols surfaces DataResult | TBD (3g) | | | ADR-0033 §5 | UPDATE … RETURNING cols surfaces DataResult | `upd::update_returning_yields_modified_columns`, `e2e::e2e_returning_on_insert_update_delete` | |
| ADR-0033 §5 | DELETE … RETURNING * surfaces DataResult (pre-DELETE row) | TBD (3g) | | | ADR-0033 §5 | DELETE … RETURNING * surfaces DataResult (pre-DELETE row) | `del::delete_returning_yields_predelete_row`, `e2e::e2e_returning_on_insert_update_delete` | |
| ADR-0033 §5 | DELETE … RETURNING preserves cascade summary alongside result set | TBD (3g) | | | ADR-0033 §5 | DELETE … RETURNING preserves cascade summary alongside result set | `del::delete_returning_with_cascade_surfaces_both` | |
| ADR-0033 §12 | Result-column type recovery for each of ten playground types via RETURNING | TBD (3g) | | | ADR-0033 §12 | Result-column type recovery for each of ten playground types via RETURNING | `e2e::e2e_multirow_insert_all_ten_types_roundtrips_and_returning_recovers_each_type` (all 10), `ins::insert_returning_recovers_multiple_bare_column_types` (5) | |
| ADR-0033 §12 | Computed expression in RETURNING stays typeless | TBD (3g) | | | ADR-0033 §12 | Computed expression in RETURNING stays typeless | `ins::insert_returning_computed_expression_is_typeless` | |
| ADR-0033 §5 / R3 | Multi-row INSERT … RETURNING: column-origin same for all rows | TBD (3g) | | | ADR-0033 §5 / R3 | Multi-row INSERT … RETURNING: column-origin same for all rows | `ins::multirow_autofill_returning_yields_distinct_generated_ids`, `e2e::e2e_multirow_insert_all_ten_types_…` | |
| **shortid auto-fill (§6)** | | | | | **shortid auto-fill (§6)** | | | |
| ADR-0033 §6 | Single-row VALUES auto-fills omitted shortid PK | TBD (3d) | | | ADR-0033 §6 | Single-row VALUES auto-fills omitted shortid PK | `ins::values_autofills_omitted_shortid_pk` | |
| ADR-0033 §6 | Multi-row VALUES yields DISTINCT shortids per row | TBD (3d) | | | ADR-0033 §6 | Multi-row VALUES yields DISTINCT shortids per row | `ins::values_multirow_autofills_distinct_shortids` | |
| ADR-0033 §6 | INSERT … SELECT auto-fills shortids per yielded row | TBD (3d) | | | ADR-0033 §6 | INSERT … SELECT auto-fills shortids per yielded row | `ins::insert_select_autofills_distinct_shortids` | |
| ADR-0033 §6 | Explicit value for shortid column respected (override; warning in §8.2) | TBD (3d) | | | ADR-0033 §6 | Explicit value for shortid column respected (override; warning in §8.2) | `ins::explicit_shortid_value_is_respected` | |
| ADR-0033 §6 | serial + shortid combo: no double-fill collision | TBD (3d) | | | ADR-0033 §6 | serial + shortid combo: no double-fill collision | `ins::combined_serial_and_shortid_autofill` | |
| **Cascade summary (§7)** | | | | | **Cascade summary (§7)** | | | |
| ADR-0033 §7 | DSL parity: same schema/data, SQL DELETE produces same per-relationship summary | TBD (3f) | | | ADR-0033 §7 | DSL parity: same schema/data, SQL DELETE produces same per-relationship summary | `del::cascade_parity_with_dsl` | |
| ADR-0033 §7 / R2 | WHERE-with-subquery: cascade pre-count uses correct byte range | TBD (3f) | | | ADR-0033 §7 / R2 [c] | WHERE-with-subquery: cascade correct (count-diff, R2 withdrawn) | `del::r2_where_with_subquery` | |
| ADR-0033 §7 | Pre-count runs BEFORE execute | TBD (3f) | | | ADR-0033 §7 [c] | Cascade detection by count-diff in a transaction (before/after) | `del::cascade_delete_reports_summary_and_repersists_child` | |
| ADR-0033 §7 | Cascade-affected child tables re-persisted | TBD (3f) | | | ADR-0033 §7 | Cascade-affected child tables re-persisted | `del::cascade_delete_reports_summary_and_repersists_child`, `e2e::e2e_delete_with_cascade_reports_summary_and_repersists_children` | |
| ADR-0033 §7 | Cascade-summary formatter shared (one function, two callers) | TBD (3f) | | | ADR-0033 §7 | Cascade-summary formatter shared (one render path, DSL + SQL) | `del::cascade_parity_with_dsl` | |
| **Diagnostics (§8)** | | | | | **Diagnostics (§8)** | | | |
| ADR-0033 §8.1 | `insert_arity_mismatch` positive (single-row) | TBD (3i) | | | ADR-0033 §8.1 | `insert_arity_mismatch` positive (single-row) | `walker::insert_arity_mismatch_single_row_fires` | |
| ADR-0033 §8.1 | `insert_arity_mismatch` negative (matched arity) | TBD (3i) | | | ADR-0033 §8.1 | `insert_arity_mismatch` negative (matched arity) | `walker::insert_arity_match_is_silent` | |
| ADR-0033 §8.1 | `insert_arity_mismatch` per-row (multi-row VALUES) | TBD (3i) | | | ADR-0033 §8.1 | `insert_arity_mismatch` per-row (multi-row VALUES) | `walker::insert_arity_mismatch_emits_per_row` | |
| ADR-0033 §8.1 | `insert_arity_mismatch` on INSERT…SELECT (projection arity) | TBD (3i) | | | ADR-0033 §8.1 | `insert_arity_mismatch` on INSERT…SELECT (projection arity) | `walker::insert_select_arity_mismatch_fires` | |
| ADR-0033 §8.2 | `auto_column_overridden` positive (serial) | TBD (3i) | | | ADR-0033 §8.2 | `auto_column_overridden` positive (serial) | `walker::auto_column_overridden_fires_on_explicit_serial` | |
| ADR-0033 §8.2 | `auto_column_overridden` positive (shortid) | TBD (3i) | | | ADR-0033 §8.2 | `auto_column_overridden` positive (shortid) | `walker::auto_column_overridden_fires_on_explicit_shortid` | |
| ADR-0033 §8.2 | `auto_column_overridden` negative (omitted) | TBD (3i) | | | ADR-0033 §8.2 | `auto_column_overridden` negative (omitted) | `walker::auto_column_overridden_silent_when_omitted` | |
| ADR-0033 §8.3 | `not_null_missing` positive | TBD (3i) | | | ADR-0033 §8.3 | `not_null_missing` positive | `walker::not_null_missing_fires_when_required_column_omitted` | |
| ADR-0033 §8.3 | `not_null_missing` negative | TBD (3i) | | | ADR-0033 §8.3 | `not_null_missing` negative | `walker::not_null_missing_silent_when_included` | |
| ADR-0033 §8.3 | `not_null_missing` does NOT fire for NOT-NULL-with-default | TBD (3i) | | | ADR-0033 §8.3 | `not_null_missing` does NOT fire for NOT-NULL-with-default | `walker::not_null_missing_silent_when_column_has_default` | |
| **UPSERT (§9)** | | | | | **UPSERT (§9)** | | | |
| ADR-0033 §9 | ON CONFLICT (col) DO NOTHING runs; no-ops on conflict | TBD (3h) | | | ADR-0033 §9 | ON CONFLICT (col) DO NOTHING runs; no-ops on conflict | `ins::on_conflict_do_nothing_keeps_existing_row`, `e2e::e2e_upsert_round_trip_do_update_then_do_nothing` | |
| ADR-0033 §9 | ON CONFLICT (col) DO UPDATE SET … = excluded.… runs; row updated | TBD (3h) | | | ADR-0033 §9 | ON CONFLICT (col) DO UPDATE SET … = excluded.… runs; row updated | `ins::on_conflict_do_update_applies_excluded`, `e2e::e2e_upsert_round_trip_…` | |
| ADR-0033 §9 | ON CONFLICT DO NOTHING (no target spec) accepts any conflict | TBD (3h) | | | ADR-0033 §9 | ON CONFLICT DO NOTHING (no target spec) accepts any conflict | `ins::on_conflict_do_nothing_without_target` | |
| ADR-0033 §9 | `excluded.col` completes to target table's columns inside DO UPDATE | TBD (3h) | | | ADR-0033 §9 | `excluded.col` completes to target table's columns inside DO UPDATE | `completion::excluded_prefix_completes_to_target_columns` | |
| ADR-0033 §9 | `excluded` rejected outside DO UPDATE (scoping) | TBD (3h) | | | ADR-0033 §9 | `excluded` rejected outside DO UPDATE (scoping) | `walker::excluded_outside_do_update_is_unknown_qualifier`, `walker::excluded_in_values_flagged_even_when_do_update_present` | |
| **Inherited Phase-2 diagnostics on DML slots (§8.4)** | | | | | **Inherited Phase-2 diagnostics on DML slots (§8.4)** | | | |
| ADR-0032 §11 | `schema_existence` fires on INSERT VALUES column | TBD (3i) | | | ADR-0032 §11 | `schema_existence` fires on INSERT VALUES / col-list column | `walker::insert_column_list_unknown_column_is_flagged` | |
| ADR-0032 §11 | `schema_existence` fires on UPDATE SET | TBD (3i) | | | ADR-0032 §11 | `schema_existence` fires on UPDATE SET | `walker::sql_update_unknown_set_column_is_error` | |
| ADR-0032 §11 | `schema_existence` fires on UPDATE / DELETE WHERE | TBD (3i) | | | ADR-0032 §11 | `schema_existence` fires on UPDATE / DELETE WHERE | `walker::sql_update_where_unknown_column_is_error`, `walker::sql_delete_where_unknown_column_is_error` | |
| ADR-0032 §11 | `schema_existence` fires on RETURNING projection | TBD (3i / 3g) | | | ADR-0032 §11 | `schema_existence` fires on RETURNING projection | `walker::returning_ref_unknown_column_is_flagged`, `walker::returning_ref_in_plain_insert_validated_against_target` | |
| ADR-0032 §11.6 | Predicate warning `eq_null` fires on UPDATE WHERE | TBD (3i) | | | ADR-0032 §11.6 | Predicate warning `eq_null` fires on UPDATE WHERE | `walker::sql_update_eq_null_in_where_warns` | |
| ADR-0032 §11.6 | Predicate warning `like_numeric` fires on DELETE WHERE | TBD (3i) | | | ADR-0032 §11.6 | Predicate warning `like_numeric` fires on DELETE WHERE | `walker::sql_delete_where_like_numeric_warns` | |
| ADR-0032 §11.6 | Predicate warning fires inside INSERT VALUES sql_expr (e.g., `=` with NULL) | TBD (3i) | | | ADR-0032 §11.6 [d] | Predicate warning fires on row-scoped DML sql_expr slots (UPDATE SET CASE, INSERT…SELECT WHERE) — VALUES has no row scope | `walker::sql_update_set_case_predicate_warns`, `walker::insert_select_where_predicate_warns` | |
| **Ambient assistance (§§ from ADR-0030 §8)** | | | | | **Ambient assistance (§§ from ADR-0030 §8)** | | | |
| ADR-0030 §8 | Syntax highlighting works for SQL DML keywords (INSERT, UPDATE, DELETE, INTO, VALUES, SET, RETURNING, ON, CONFLICT) | TBD (3k) | | | ADR-0030 §8 | Syntax highlighting works for SQL DML keywords (INSERT, UPDATE, DELETE, INTO, VALUES, SET, RETURNING, ON, CONFLICT) | `highlight::sql_dml_keywords_classified` | |
| ADR-0030 §8 | Tab completion works for SQL DML entry keywords in Advanced mode | TBD (3k) | ⏳ | | ADR-0030 §8 | Tab completion works for SQL DML entry keywords | `completion::empty_input_offers_all_command_entry_keywords` | ✅ |
| ADR-0030 §8 | Tab completion works for target table after `INSERT INTO ` | TBD (3k) | | | ADR-0030 §8 | Tab completion works for target table after `INSERT INTO ` | `completion::insert_into_offers_table_names_at_target_slot` | |
| ADR-0030 §8 | Tab completion works for column names inside `(column_list)` | TBD (3k) | | | ADR-0030 §8 | Tab completion works for column names inside `(column_list)` | `completion::insert_into_open_paren_offers_current_table_columns` | |
| ADR-0030 §8 | Tab completion works for column names in UPDATE SET / WHERE | TBD (3k) | | | ADR-0030 §8 | Tab completion works for column names in UPDATE SET / WHERE | `completion::update_set_offers_only_current_table_columns`, `completion::update_where_offers_only_current_table_columns` | |
| ADR-0030 §8 | Hint-panel prose appears at representative DML slots | TBD (3k) | | | ADR-0030 §8 [f] | Hint-panel assistance appears at representative DML slots | `input_render::advanced_mode_ambient_offers_dml_slot_candidates` (advanced SQL), `input_render::ambient_hint_at_insert_first_value_shows_int_prose` / `…at_update_set_shows_per_column_prose` / `…at_where_mentions_column_name` (simple DSL prose) | |
| ADR-0030 §8 | `[ERR]`/`[WRN]` validity indicator fires for SQL DML diagnostics | TBD (3k) | | | ADR-0030 §8 | `[ERR]`/`[WRN]` validity indicator fires for SQL DML diagnostics | `e2e::e2e_validity_indicator_fires_for_sql_dml_diagnostic`, `walker::input_verdict_eq_null_is_warning`, `walking_skeleton::validity_indicator_renders_err_and_wrn_labels` | |
| ADR-0030 §8 | Per-command parse-error usage fires for SQL DML | TBD (3k) | | | ADR-0030 §8 | Per-command parse-error usage fires for SQL DML shared words | `parse_error_pedagogy::insert_partial_renders_insert_usage_template`, `…update_partial_renders_update_usage_template` | |
| **Engine-neutrality + safety** | | | | | **Engine-neutrality + safety** | | | |
| ADR-0030 §6 / ADR-0033 §1 | `__rdbms_*` rejection at INSERT target slot | TBD (3b) | | | ADR-0030 §6 / ADR-0033 §1 | `__rdbms_*` rejection at INSERT target slot | `ins::parse_path_rejects_internal_target_table` | |
| ADR-0030 §6 / ADR-0033 §1 | `__rdbms_*` rejection at UPDATE target slot | TBD (3e) | | | ADR-0030 §6 / ADR-0033 §1 | `__rdbms_*` rejection at UPDATE target slot | `sql_update.rs::internal_target_table_rejected` | |
| ADR-0030 §6 / ADR-0033 §1 | `__rdbms_*` rejection at DELETE target slot | TBD (3f) | | | ADR-0030 §6 / ADR-0033 §1 | `__rdbms_*` rejection at DELETE target slot | `del::internal_target_table_rejected_at_parse` | |
| ADR-0030 §6 / ADR-0033 §1 | `__rdbms_*` rejection in INSERT…SELECT row source's FROM | TBD (3c) | | | ADR-0030 §6 / ADR-0033 §1 | `__rdbms_*` rejection in INSERT…SELECT row source's FROM | `sql_insert.rs::select_row_source_rejects_internal_from_table` | |
| ADR-0030 §7 / ADR-0033 §11 | Engine UNIQUE constraint failure surfaces via friendly layer (engine-neutral) | TBD (3k) | | | ADR-0030 §7 / ADR-0033 §11 | Engine UNIQUE constraint failure surfaces via friendly layer (engine-neutral) | `friendly::enrich_unique_insert_resolves_table_column_value_and_pinpoint`, `ins::failed_insert_rolls_back_and_does_not_repersist` | |
| ADR-0030 §7 / ADR-0033 §11 | Engine NOT NULL constraint failure surfaces via friendly layer | TBD (3k) | | | ADR-0030 §7 / ADR-0033 §11 | Engine NOT NULL constraint failure surfaces via friendly layer | `friendly::enrich_not_null_resolves_table_and_column` | |
| ADR-0030 §7 / ADR-0033 §11 | Engine FK constraint failure on DELETE-without-cascade surfaces | TBD (3k) | | | ADR-0030 §7 / ADR-0033 §11 | Engine FK constraint failure on DELETE-without-cascade surfaces | `del::delete_violating_fk_fails_and_persists_nothing` | |
| **Persistence + history (§10–§11)** | | | | | **Persistence + history (§10–§11)** | | | |
| ADR-0030 §11 | INSERT writes history.log + re-persists target CSV | TBD (3b) | | | ADR-0030 §11 | INSERT writes history.log + re-persists target CSV | `ins::insert_appends_literal_line_to_history` | |
| ADR-0030 §11 | UPDATE writes history.log + re-persists target CSV | TBD (3e) | | | ADR-0030 §11 | UPDATE writes history.log + re-persists target CSV | `upd::update_appends_literal_line_to_history` | |
| ADR-0030 §11 | DELETE writes history.log + re-persists target + cascade-affected CSVs | TBD (3f) | | | ADR-0030 §11 | DELETE writes history.log + re-persists target + cascade-affected CSVs | `del::delete_appends_literal_line_to_history`, `e2e::e2e_delete_with_cascade_…` | |
| ADR-0030 §11 | Every Phase-3 statement form replays from history.log faithfully | TBD (3k) | | | ADR-0030 §11 | Every Phase-3 statement form replays from history.log faithfully | `e2e::e2e_replay_phase3_dml_forms_from_a_script` | |
| ADR-0033 §10 | INSERT failure does NOT re-persist CSV | TBD (3b) | | | ADR-0033 §10 | INSERT failure does NOT re-persist CSV | `ins::failed_insert_rolls_back_and_does_not_repersist` | |
| ADR-0006 / ADR-0033 §10 | Auto-snapshot fires for SQL DML the same way it does for DSL DML | TBD (3k) | ⏳ | | ADR-0006 / ADR-0033 §10 [e] | Auto-snapshot fires for SQL DML the same way it does for DSL DML | — (ADR-0006 unimplemented for BOTH paths; deferred) | N/A |
| **OOS rejections (§13)** | | | | | **OOS rejections (§13)** | | | |
| ADR-0033 §13 OOS-1 | `INSERT INTO t DEFAULT VALUES` parse-rejects | TBD (3b) | | | ADR-0033 §13 OOS-1 | `INSERT INTO t DEFAULT VALUES` parse-rejects | `e2e::e2e_out_of_scope_dml_forms_parse_reject` | |
| ADR-0033 §13 OOS-2 | `INSERT OR REPLACE` parse-rejects | TBD (3b) | | | ADR-0033 §13 OOS-2 | `INSERT OR REPLACE` / `OR IGNORE` parse-rejects | `e2e::e2e_out_of_scope_dml_forms_parse_reject` | |
| ADR-0033 §13 OOS-3 | `UPDATE … FROM other_table` parse-rejects | TBD (3e) | | | ADR-0033 §13 OOS-3 | `UPDATE … FROM other_table` parse-rejects | `e2e::e2e_out_of_scope_dml_forms_parse_reject` | |
| ADR-0033 §13 OOS-4 | `WITH x AS (…) UPDATE …` parse-rejects | TBD (3e) | | | ADR-0033 §13 OOS-4 | `WITH x AS (…) UPDATE …` parse-rejects | `e2e::e2e_out_of_scope_dml_forms_parse_reject` | |
| ADR-0033 §13 OOS-4 | `WITH x AS (…) DELETE …` parse-rejects | TBD (3f) | | | ADR-0033 §13 OOS-4 | `WITH x AS (…) DELETE …` parse-rejects | `e2e::e2e_out_of_scope_dml_forms_parse_reject` | |
| ADR-0033 §13 OOS-5 | `INDEXED BY` / `NOT INDEXED` table modifiers parse-reject | `e2e::e2e_out_of_scope_dml_forms_parse_reject` | ✅ |
| ADR-0033 §13 OOS-6 | Multi-statement batch (`…; …`) parse-rejects (single `;`-tail still parses) | `e2e::e2e_out_of_scope_dml_forms_parse_reject`, `e2e::e2e_single_dml_statement_with_trailing_semicolon_parses` | ✅ |
**Test-location legend.** `ins::` = `tests/sql_insert.rs`, `upd::` =
`tests/sql_update.rs`, `del::` = `tests/sql_delete.rs`, `e2e::` =
`tests/sql_dml_e2e.rs` (new in 3k), `walker::` =
`src/dsl/walker/mod.rs::tests`, `highlight::` =
`src/dsl/walker/highlight.rs::tests`, `completion::` =
`src/completion.rs::tests`, `parser::` = `src/dsl/parser.rs::tests`,
`input_render::` = `src/input_render.rs::tests`, `app::` =
`src/app.rs::tests`, `friendly::` = `tests/friendly_enrichment.rs`,
`parse_error_pedagogy::` = `tests/parse_error_pedagogy.rs`,
`walking_skeleton::` = `tests/walking_skeleton.rs`,
`sql_update.rs` / `sql_insert.rs` (bare) = the `#[cfg(test)]` module
inside `src/dsl/grammar/sql_update.rs` / `sql_insert.rs`.
**Footnotes (resolutions surfaced during 3k).**
- **[a]** ADR-0033 **Amendment 1** replaced `Node::Guard` with
category-grouped, mode-aware dispatch in `walker::walk`; the R1
invariant ("the SQL branch failing must not strand the DSL
candidate") is now the Advanced-mode fall-through, proven on the
dispatch smoke registry by `advanced_mode_dsl_input_falls_back_to_dsl`
and on real DML by `parser::advanced_dsl_only_delete_falls_back_to_dsl`.
- **[b]** ADR-0033 **Amendment 3** supersedes the original
"bare `ValidationFailed`" expectation for shared words: a shared
entry word in Simple mode commits the **DSL candidate** and surfaces
the real DSL parse error, with the `advanced_mode.also_valid_sql`
pointer combined at the render layer. The bare
`advanced_mode.sql_in_simple` hint is reserved for SQL-only *entry
words* (`select` / `with`).
- **[c]** ADR-0033 **Amendment 2** withdrew R2: the cascade summary is
produced by before/after **count-diff in a transaction** (DSL
parity), not WHERE-byte pre-count injection. The subquery-in-WHERE
case is correct by construction.
- **[d]** **Matrix claim corrected (user-confirmed, 3k).** Predicate
warnings fire on every DML `sql_expr` slot that carries **row scope**
(UPDATE/DELETE WHERE, UPDATE SET incl. CASE, INSERT…SELECT
projection & WHERE). Plain `INSERT … VALUES` has no row scope, so a
bare-column predicate is inapplicable there — consistent with
ADR-0033 §8.4 ("WHERE and CASE expressions"). The original example
("inside INSERT VALUES") was an over-statement of the §8.4 claim.
- **[e]** **N/A — deferred (user-confirmed, 3k).** ADR-0006
auto-snapshot / undo is unimplemented for **both** the DSL and SQL
DML paths (the U-series, per `CLAUDE.md` "Things deliberately
deferred"). The "same way as DSL" parity therefore holds vacuously
and Phase 3 introduces no regression. ADR-0033 §10's auto-snapshot
consequence is contingent on the deferred ADR-0006 work; this row is
N/A, not red, and does not block the phase exit.
- **[f]** **Attribution corrected (`/runda` round).** The ambient
hint-panel claim sits under the §8 *advanced* surface, but the
hint-prose tests run via `ambient_hint` (which defaults to
`Mode::Simple` — the DSL value-slot prose). 3k's `/runda` round added
`advanced_mode_ambient_offers_dml_slot_candidates` so the row has a
genuine **advanced-mode** DML hint-panel attribution (column
candidates at an `UPDATE … SET` LHS and inside an `INSERT … (` column
list); the simple-mode DSL prose tests remain as the DSL-surface
complement.
The implementer fills in `Test location` and `Status` The implementer fills in `Test location` and `Status`
(✅ / ❌) as 3k proceeds. A row marked red blocks the (✅ / ❌) as 3k proceeds. A row marked red blocks the
+14
View File
@@ -1896,6 +1896,20 @@ mod tests {
assert_eq!(cs, vec!["Customers".to_string(), "Orders".to_string()]); assert_eq!(cs, vec!["Customers".to_string(), "Orders".to_string()]);
} }
#[test]
fn insert_into_offers_table_names_at_target_slot() {
// 3k cross-cut (matrix A3): after `insert into ` the target
// table slot completes to the schema's table names.
let cache = SchemaCache {
tables: vec!["Customers".to_string(), "Orders".to_string()],
columns: vec![],
relationships: vec![],
..SchemaCache::default()
};
let cs = cands_with("insert into ", 12, &cache);
assert_eq!(cs, vec!["Customers".to_string(), "Orders".to_string()]);
}
#[test] #[test]
fn schema_cache_offers_column_names_at_column_slot() { fn schema_cache_offers_column_names_at_column_slot() {
let cache = SchemaCache { let cache = SchemaCache {
+34
View File
@@ -397,4 +397,38 @@ mod tests {
); );
} }
} }
#[test]
fn sql_dml_keywords_classified() {
// ADR-0030 §8 / ADR-0033 — the DML entry words and clause
// keywords (INSERT / INTO / VALUES / ON / CONFLICT /
// RETURNING / UPDATE / SET / DELETE / FROM) all get the
// Keyword class in Advanced mode. 3k cross-cut: the
// ambient highlighter covers the DML surface, not just
// SELECT.
let keywords_of = |input: &'static str| -> Vec<&'static str> {
run_advanced(input)
.into_iter()
.filter(|(_, _, c)| *c == HighlightClass::Keyword)
.map(|(s, e, _)| &input[s..e])
.collect()
};
let insert = keywords_of(
"insert into t (a) values (1) on conflict (a) do update set a = excluded.a returning a",
);
for kw in ["insert", "into", "values", "on", "conflict", "do", "update", "set", "returning"] {
assert!(insert.contains(&kw), "INSERT/UPSERT: missing `{kw}`; got {insert:?}");
}
let update = keywords_of("update t set a = 1 where id = 2 returning a");
for kw in ["update", "set", "where", "returning"] {
assert!(update.contains(&kw), "UPDATE: missing `{kw}`; got {update:?}");
}
let delete = keywords_of("delete from t where id = 1 returning *");
for kw in ["delete", "from", "where", "returning"] {
assert!(delete.contains(&kw), "DELETE: missing `{kw}`; got {delete:?}");
}
}
} }
+69
View File
@@ -5154,6 +5154,75 @@ mod tests {
); );
} }
#[test]
fn sql_delete_where_unknown_column_is_error() {
// 3k cross-cut (matrix I3): schema-existence fires on a
// top-level DELETE's WHERE, not only on INSERT/UPDATE slots.
let schema = schema_with("t", &[("id", Type::Int), ("v", Type::Int)]);
let diags = diag_keys("delete from t where nonexistent = 1", &schema);
assert!(
diags.iter().any(|d| d.contains("no such column")),
"expected unknown_column on the DELETE WHERE; got {diags:?}",
);
}
#[test]
fn sql_update_where_unknown_column_is_error() {
// 3k cross-cut (matrix I3): schema-existence fires on a
// top-level UPDATE's WHERE (the SET case is covered by
// `sql_update_unknown_set_column_is_error`).
let schema = schema_with("t", &[("id", Type::Int), ("v", Type::Int)]);
let diags = diag_keys("update t set v = 1 where nonexistent = 1", &schema);
assert!(
diags.iter().any(|d| d.contains("no such column")),
"expected unknown_column on the UPDATE WHERE; got {diags:?}",
);
}
#[test]
fn sql_delete_where_like_numeric_warns() {
// 3k cross-cut (matrix I6): the like_numeric predicate
// warning fires on a DELETE's WHERE (the prior coverage was
// SELECT / HAVING / CASE only).
let schema = schema_with("t", &[("id", Type::Int), ("count", Type::Int)]);
let diags = diag_keys("delete from t where count like 5", &schema);
assert!(
diags.iter().any(|d| d.contains("LIKE")),
"expected like_numeric warning on the DELETE WHERE; got {diags:?}",
);
}
#[test]
fn sql_update_set_case_predicate_warns() {
// 3k cross-cut (matrix I7, corrected): a predicate warning
// fires inside a CASE in an UPDATE SET RHS — a row-scoped
// DML sql_expr slot (ADR-0033 §8.4 — "WHERE and CASE").
let schema = schema_with("t", &[("id", Type::Int), ("v", Type::Int)]);
let diags = diag_keys(
"update t set v = case when v = NULL then 1 else 0 end where id = 1",
&schema,
);
assert!(
diags.iter().any(|d| d.contains("IS NULL")),
"expected eq_null warning inside the UPDATE SET CASE; got {diags:?}",
);
}
#[test]
fn insert_select_where_predicate_warns() {
// 3k cross-cut (matrix I7, corrected): the predicate-warning
// pass fires on the WHERE of an INSERT … SELECT row source
// (`b.total` is real, so `like 5` is a numeric LIKE). Plain
// INSERT VALUES carries no row scope, so the realizable
// claim is the INSERT … SELECT slot, not VALUES.
let schema = two_table_schema(); // a(id,name), b(id,total real)
let diags = diag_keys("insert into a (id) select id from b where total like 5", &schema);
assert!(
diags.iter().any(|d| d.contains("LIKE")),
"expected like_numeric on the INSERT…SELECT WHERE; got {diags:?}",
);
}
#[test] #[test]
fn cte_name_is_valid_table_source() { fn cte_name_is_valid_table_source() {
let schema = schema_with("base", &[("id", Type::Int)]); let schema = schema_with("base", &[("id", Type::Int)]);
+32
View File
@@ -903,6 +903,38 @@ mod tests {
} }
} }
#[test]
fn advanced_mode_ambient_offers_dml_slot_candidates() {
// 3k cross-cut (matrix A6, advanced surface): the ambient hint
// panel surfaces SQL DML slot assistance in Advanced mode —
// column candidates at an `UPDATE … SET` LHS slot and inside an
// `INSERT … (` column list. (The simple-mode DSL value-slot
// prose is a separate surface; this pins the §8 advanced claim.)
use crate::dsl::types::Type;
let cache = schema_with_columns(
"Customers",
&[("id", Type::Int), ("Name", Type::Text)],
);
let set_slot = "update Customers set ";
match ambient_hint_in_mode(set_slot, set_slot.len(), None, &cache, Mode::Advanced) {
Some(AmbientHint::Candidates { items, .. }) => assert!(
items.iter().any(|c| c.text == "Name" || c.text == "id"),
"UPDATE SET slot should offer column candidates; got {items:?}",
),
other => panic!("expected candidates at the UPDATE SET slot, got {other:?}"),
}
let col_list = "insert into Customers (";
match ambient_hint_in_mode(col_list, col_list.len(), None, &cache, Mode::Advanced) {
Some(AmbientHint::Candidates { items, .. }) => assert!(
items.iter().any(|c| c.text == "Name" || c.text == "id"),
"INSERT column-list slot should offer column candidates; got {items:?}",
),
other => panic!("expected candidates in the INSERT column list, got {other:?}"),
}
}
#[test] #[test]
fn simple_mode_ambient_does_not_surface_sql_candidates() { fn simple_mode_ambient_does_not_surface_sql_candidates() {
// The simple-mode entry point keeps gating SQL — advanced // The simple-mode entry point keeps gating SQL — advanced
+576
View File
@@ -0,0 +1,576 @@
//! Sub-phase 3k — Tier-3 end-to-end DML integration tests
//! (ADR-0033, plan `docs/plans/20260520-adr-0033-phase-3.md`
//! "Sub-phase 3k").
//!
//! Where the per-sub-phase `tests/sql_{insert,update,delete}.rs`
//! suites drive the worker directly with hand-written arguments,
//! these tests exercise the **full advanced-mode path**: a literal
//! line is parsed in Advanced mode (the same `parse_command`
//! dispatch the runtime uses), the resulting `Command::Sql*` is
//! executed through the worker, and the persisted CSV / history /
//! result set are asserted. They cover the real-world DML shapes
//! the 3k exit gate lists:
//!
//! - `INSERT … SELECT` cross-table
//! - multi-row `INSERT` covering all ten playground types, with
//! `RETURNING` recovering every type (matrix R5)
//! - `UPDATE` with a subquery in `SET`
//! - `DELETE` with cascade (per-relationship summary + multi-table
//! re-persistence)
//! - `UPSERT` round-trip (`DO UPDATE` then `DO NOTHING`)
//! - `RETURNING` on each of `INSERT` / `UPDATE` / `DELETE`
//! - `history.log` replay of every Phase-3 statement form
//! - the OOS parse-rejections (ADR-0033 §13)
//! - the `[ERR]`/`[WRN]` validity indicator firing on a SQL DML
//! diagnostic (matrix A7)
use ratatui::Terminal;
use ratatui::backend::TestBackend;
use rdbms_playground::app::App;
use rdbms_playground::db::{Database, DbError, DeleteResult, InsertResult, UpdateResult};
use rdbms_playground::dsl::parser::parse_command_in_mode;
use rdbms_playground::dsl::walker::Severity;
use rdbms_playground::dsl::{ColumnSpec, Command, ReferentialAction, Type, parse_command};
use rdbms_playground::event::AppEvent;
use rdbms_playground::mode::Mode;
use rdbms_playground::persistence::Persistence;
use rdbms_playground::project;
use rdbms_playground::runtime::run_replay;
use rdbms_playground::theme::Theme;
use rdbms_playground::ui;
// ---------------------------------------------------------------
// Harness — mirrors the per-sub-phase suites' helpers.
// ---------------------------------------------------------------
fn rt() -> tokio::runtime::Runtime {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("tokio rt")
}
fn open_project_db() -> (project::Project, Database, tempfile::TempDir) {
let dir = tempfile::tempdir().expect("create tempdir");
let project =
project::open_or_create(None, Some(dir.path())).expect("open or create project");
let persistence = Persistence::new(project.path().to_path_buf());
let db = Database::open_with_persistence(project.db_path(), persistence)
.expect("open db with persistence");
(project, db, dir)
}
fn read_csv(project: &project::Project, table: &str) -> Option<String> {
std::fs::read_to_string(project.path().join("data").join(format!("{table}.csv"))).ok()
}
fn create_cols(
db: &Database,
rt: &tokio::runtime::Runtime,
name: &str,
cols: &[(&str, Type)],
pk: &[&str],
) {
rt.block_on(db.create_table(
name.to_string(),
cols.iter().map(|(n, t)| ColumnSpec::new(*n, *t)).collect(),
pk.iter().map(|s| (*s).to_string()).collect(),
None,
))
.unwrap_or_else(|e| panic!("create table {name}: {e:?}"));
}
/// Parse `input` in Advanced mode and run the resulting SQL INSERT
/// through the worker — the full parse → execute path.
fn run_insert(
db: &Database,
rt: &tokio::runtime::Runtime,
input: &str,
) -> Result<InsertResult, DbError> {
match parse_command(input).unwrap_or_else(|e| panic!("parse {input:?}: {e:?}")) {
Command::SqlInsert {
sql,
target_table,
listed_columns,
row_source,
returning,
} => rt.block_on(db.run_sql_insert(
sql,
Some(input.to_string()),
target_table,
listed_columns,
row_source,
returning,
)),
other => panic!("expected Command::SqlInsert from {input:?}, got {other:?}"),
}
}
fn run_update(
db: &Database,
rt: &tokio::runtime::Runtime,
input: &str,
) -> Result<UpdateResult, DbError> {
match parse_command(input).unwrap_or_else(|e| panic!("parse {input:?}: {e:?}")) {
Command::SqlUpdate { sql, target_table, returning } => rt.block_on(
db.run_sql_update(sql, Some(input.to_string()), target_table, returning),
),
other => panic!("expected Command::SqlUpdate from {input:?}, got {other:?}"),
}
}
fn run_delete(
db: &Database,
rt: &tokio::runtime::Runtime,
input: &str,
) -> Result<DeleteResult, DbError> {
match parse_command(input).unwrap_or_else(|e| panic!("parse {input:?}: {e:?}")) {
Command::SqlDelete { sql, target_table, returning } => rt.block_on(
db.run_sql_delete(sql, Some(input.to_string()), target_table, returning),
),
other => panic!("expected Command::SqlDelete from {input:?}, got {other:?}"),
}
}
/// Seed rows through the SQL INSERT path (no auto-gen columns, so
/// the statement executes verbatim).
fn seed(db: &Database, rt: &tokio::runtime::Runtime, sql: &str) {
run_insert(db, rt, sql).unwrap_or_else(|e| panic!("seed {sql:?}: {e:?}"));
}
fn query(db: &Database, rt: &tokio::runtime::Runtime, table: &str) -> Vec<Vec<Option<String>>> {
rt.block_on(db.query_data(table.to_string(), None, None, None))
.unwrap_or_else(|e| panic!("query_data {table}: {e:?}"))
.rows
}
// ===============================================================
// INSERT … SELECT cross-table
// ===============================================================
#[test]
fn e2e_insert_select_cross_table_copies_rows_and_persists_both() {
let (project, db, _dir) = open_project_db();
let rt = rt();
create_cols(&db, &rt, "source", &[("id", Type::Int), ("v", Type::Text)], &["id"]);
create_cols(&db, &rt, "archive", &[("id", Type::Int), ("v", Type::Text)], &["id"]);
seed(&db, &rt, "insert into source (id, v) values (1, 'x'), (2, 'y')");
let result = run_insert(&db, &rt, "insert into archive select * from source")
.expect("INSERT … SELECT runs");
assert_eq!(result.rows_affected, 2, "two source rows copied");
let archive_csv = read_csv(&project, "archive").expect("archive.csv");
assert!(
archive_csv.contains('x') && archive_csv.contains('y'),
"archive reflects both copied rows: {archive_csv:?}",
);
let source_csv = read_csv(&project, "source").expect("source.csv");
assert!(
source_csv.contains('x') && source_csv.contains('y'),
"source is left intact: {source_csv:?}",
);
}
// ===============================================================
// Multi-row INSERT covering all ten playground types + RETURNING
// type recovery for every type (matrix R5).
// ===============================================================
#[test]
fn e2e_multirow_insert_all_ten_types_roundtrips_and_returning_recovers_each_type() {
let (project, db, _dir) = open_project_db();
let rt = rt();
// serial PK + shortid auto-fill; the other eight columns are
// user-supplied. `blob` has no value-literal grammar yet
// (see src/dsl/value.rs), so it is inserted NULL — its *type*
// still round-trips through the RETURNING column-origin path.
create_cols(
&db,
&rt,
"allten",
&[
("ser", Type::Serial),
("txt", Type::Text),
("i", Type::Int),
("r", Type::Real),
("dec", Type::Decimal),
("flag", Type::Bool),
("d", Type::Date),
("ts", Type::DateTime),
("bl", Type::Blob),
("sid", Type::ShortId),
],
&["ser"],
);
let result = run_insert(
&db,
&rt,
"insert into allten (txt, i, r, dec, flag, d, ts, bl) values \
('hi', 42, 1.5, 9.50, true, '2026-05-23', '2026-05-23 10:00:00', null), \
('yo', 7, 2.5, 3.25, false, '2025-01-01', '2025-01-01 00:00:00', null) \
returning ser, txt, i, r, dec, flag, d, ts, bl, sid",
)
.expect("multi-row INSERT … RETURNING runs");
assert_eq!(result.rows_affected, 2, "two rows inserted");
assert_eq!(result.data.rows.len(), 2, "RETURNING yields both rows");
// Every one of the ten playground types is recovered via the
// RETURNING column-origin path (matrix R5).
assert_eq!(
result.data.column_types,
vec![
Some(Type::Serial),
Some(Type::Text),
Some(Type::Int),
Some(Type::Real),
Some(Type::Decimal),
Some(Type::Bool),
Some(Type::Date),
Some(Type::DateTime),
Some(Type::Blob),
Some(Type::ShortId),
],
"RETURNING recovers each of the ten playground types; got {:?}",
result.data.column_types,
);
// Values round-trip: serial auto-incremented (1, 2), shortid
// auto-filled (non-empty + distinct), the user values persisted.
let rows = query(&db, &rt, "allten");
assert_eq!(rows.len(), 2, "both rows persisted");
let csv = read_csv(&project, "allten").expect("allten.csv");
assert!(csv.contains("hi") && csv.contains("yo"), "text round-trips: {csv:?}");
assert!(csv.contains("2026-05-23") && csv.contains("2025-01-01"), "dates round-trip: {csv:?}");
let sids: Vec<&str> = rows.iter().filter_map(|r| r[9].as_deref()).collect();
assert_eq!(sids.len(), 2, "both shortids present");
assert!(sids.iter().all(|s| !s.is_empty()), "shortids non-empty: {sids:?}");
assert_ne!(sids[0], sids[1], "auto-filled shortids are distinct: {sids:?}");
let sers: Vec<&str> = rows.iter().filter_map(|r| r[0].as_deref()).collect();
assert!(sers.contains(&"1") && sers.contains(&"2"), "serial auto-incremented: {sers:?}");
}
// ===============================================================
// UPDATE with a subquery in SET
// ===============================================================
#[test]
fn e2e_update_with_subquery_in_set() {
let (project, db, _dir) = open_project_db();
let rt = rt();
create_cols(
&db,
&rt,
"customers",
&[("id", Type::Int), ("name", Type::Text), ("last_order", Type::Int)],
&["id"],
);
create_cols(
&db,
&rt,
"orders",
&[("id", Type::Int), ("cust", Type::Int), ("amount", Type::Int)],
&["id"],
);
seed(&db, &rt, "insert into customers (id, name, last_order) values (1, 'A', 0), (2, 'B', 0)");
seed(&db, &rt, "insert into orders (id, cust, amount) values (10, 1, 50), (11, 1, 30), (12, 2, 99)");
let result = run_update(
&db,
&rt,
"update customers set last_order = \
(select max(amount) from orders where cust = customers.id)",
)
.expect("UPDATE with subquery in SET runs");
assert_eq!(result.rows_affected, 2, "both customers updated");
let rows = query(&db, &rt, "customers");
let c1 = rows.iter().find(|r| r[0].as_deref() == Some("1")).expect("customer 1");
let c2 = rows.iter().find(|r| r[0].as_deref() == Some("2")).expect("customer 2");
assert_eq!(c1[2].as_deref(), Some("50"), "customer 1 → max(50, 30) = 50");
assert_eq!(c2[2].as_deref(), Some("99"), "customer 2 → max(99) = 99");
let csv = read_csv(&project, "customers").expect("customers.csv");
assert!(csv.contains("50") && csv.contains("99"), "CSV reflects the update: {csv:?}");
}
// ===============================================================
// DELETE with cascade — per-relationship summary + multi-table
// re-persistence.
// ===============================================================
fn cascade_fixture(db: &Database, rt: &tokio::runtime::Runtime) {
create_cols(db, rt, "Customers", &[("id", Type::Int), ("Name", Type::Text)], &["id"]);
create_cols(db, rt, "Orders", &[("id", Type::Int), ("CustId", Type::Int)], &["id"]);
rt.block_on(db.add_relationship(
Some("places".to_string()),
"Customers".to_string(),
"id".to_string(),
"Orders".to_string(),
"CustId".to_string(),
ReferentialAction::Cascade,
ReferentialAction::NoAction,
false,
None,
))
.expect("add cascade relationship");
seed(db, rt, "insert into Customers (id, Name) values (1, 'Alice'), (2, 'Bob')");
seed(db, rt, "insert into Orders (id, CustId) values (10, 1), (11, 1), (12, 2)");
}
#[test]
fn e2e_delete_with_cascade_reports_summary_and_repersists_children() {
let (project, db, _dir) = open_project_db();
let rt = rt();
cascade_fixture(&db, &rt);
let result = run_delete(&db, &rt, "delete from Customers where id = 1")
.expect("cascading DELETE runs");
assert_eq!(result.rows_affected, 1, "one parent row deleted");
assert_eq!(result.cascade.len(), 1, "one cascade relationship affected");
let effect = &result.cascade[0];
assert_eq!(effect.child_table, "Orders");
assert_eq!(effect.rows_changed, 2, "Alice's two orders cascaded");
let orders_csv = read_csv(&project, "Orders").expect("Orders.csv re-persisted");
assert!(orders_csv.contains("12"), "Bob's order (12) preserved: {orders_csv:?}");
assert!(!orders_csv.contains("10"), "Alice's order 10 cascaded away: {orders_csv:?}");
assert!(!orders_csv.contains("11"), "Alice's order 11 cascaded away: {orders_csv:?}");
}
// ===============================================================
// UPSERT round-trip — DO UPDATE then DO NOTHING.
// ===============================================================
#[test]
fn e2e_upsert_round_trip_do_update_then_do_nothing() {
let (project, db, _dir) = open_project_db();
let rt = rt();
create_cols(&db, &rt, "kv", &[("id", Type::Int), ("name", Type::Text)], &["id"]);
seed(&db, &rt, "insert into kv (id, name) values (1, 'old')");
// DO UPDATE on a conflict mutates the existing row.
let upd = run_insert(
&db,
&rt,
"insert into kv (id, name) values (1, 'new') on conflict (id) do update set name = excluded.name",
)
.expect("UPSERT DO UPDATE runs");
assert_eq!(upd.rows_affected, 1, "DO UPDATE touches the conflicting row");
let csv = read_csv(&project, "kv").expect("kv.csv");
assert!(csv.contains("new") && !csv.contains("old"), "row updated to 'new': {csv:?}");
// DO NOTHING on a conflict is a no-op.
let nothing = run_insert(
&db,
&rt,
"insert into kv (id, name) values (1, 'ignored') on conflict (id) do nothing",
)
.expect("UPSERT DO NOTHING runs");
assert_eq!(nothing.rows_affected, 0, "DO NOTHING changes no rows");
let csv = read_csv(&project, "kv").expect("kv.csv");
assert!(csv.contains("new") && !csv.contains("ignored"), "row unchanged by DO NOTHING: {csv:?}");
}
// ===============================================================
// RETURNING on each of INSERT / UPDATE / DELETE.
// ===============================================================
#[test]
fn e2e_returning_on_insert_update_delete() {
let (_project, db, _dir) = open_project_db();
let rt = rt();
create_cols(&db, &rt, "t", &[("id", Type::Int), ("v", Type::Text)], &["id"]);
let ins = run_insert(&db, &rt, "insert into t (id, v) values (1, 'a') returning id, v")
.expect("INSERT … RETURNING runs");
assert_eq!(ins.data.rows.len(), 1, "INSERT RETURNING yields the inserted row");
assert_eq!(ins.data.rows[0][1].as_deref(), Some("a"));
let upd = run_update(&db, &rt, "update t set v = 'b' where id = 1 returning v")
.expect("UPDATE … RETURNING runs");
assert_eq!(upd.data.rows.len(), 1, "UPDATE RETURNING yields the modified row");
assert_eq!(upd.data.rows[0][0].as_deref(), Some("b"));
let del = run_delete(&db, &rt, "delete from t where id = 1 returning *")
.expect("DELETE … RETURNING runs");
assert_eq!(del.data.rows.len(), 1, "DELETE RETURNING yields the pre-delete row");
assert_eq!(del.data.rows[0][1].as_deref(), Some("b"), "pre-delete value surfaced");
assert!(query(&db, &rt, "t").is_empty(), "row is gone after the DELETE");
}
// ===============================================================
// history.log replay of every Phase-3 statement form.
// ===============================================================
#[test]
fn e2e_replay_phase3_dml_forms_from_a_script() {
let dir = tempfile::tempdir().expect("tempdir");
let project = project::open_or_create(None, Some(dir.path())).expect("project");
let db = Database::open_with_persistence(
project.db_path(),
Persistence::new(project.path().to_path_buf()),
)
.expect("db");
let rt = rt();
// A script of Phase-3 SQL DML forms (plus the DDL needed to set
// up). Replay parses each line in Advanced mode (ADR-0033
// Amendment 3), so the SQL forms route to the SQL worker path.
std::fs::write(
project.path().join("phase3.commands"),
"create table T with pk id(int)\n\
add column T: v (text)\n\
insert into T (id, v) values (1, 'a'), (2, 'b'), (3, 'c')\n\
insert into T select id + 10, v from T where id = 1\n\
update T set v = 'z' where id = 2\n\
delete from T where id = 3\n",
)
.expect("write script");
let events = rt.block_on(run_replay(&db, project.path(), "phase3.commands"));
match events.last().expect("at least one event") {
AppEvent::ReplayCompleted { count, .. } => {
assert_eq!(*count, 6, "all six lines replayed; events: {events:?}");
}
other => panic!("expected ReplayCompleted, got {other:?} (events: {events:?})"),
}
// Faithful application: multi-row insert + INSERT…SELECT +
// UPDATE + DELETE all landed.
let rows = query(&db, &rt, "T");
let mut by_id: Vec<(String, Option<String>)> = rows
.iter()
.map(|r| (r[0].clone().unwrap_or_default(), r[1].clone()))
.collect();
by_id.sort();
assert_eq!(
by_id,
vec![
("1".to_string(), Some("a".to_string())),
("11".to_string(), Some("a".to_string())), // INSERT…SELECT id+10
("2".to_string(), Some("z".to_string())), // UPDATE
// id 3 was DELETEd
]
.into_iter()
.collect::<std::collections::BTreeMap<_, _>>()
.into_iter()
.collect::<Vec<_>>(),
"replayed DML applied faithfully; got {by_id:?}",
);
}
// ===============================================================
// OOS parse-rejections (ADR-0033 §13) — behaviour confirmed; pin it.
// ===============================================================
#[test]
fn e2e_out_of_scope_dml_forms_parse_reject() {
let cases = [
("OOS-1 DEFAULT VALUES", "insert into t default values"),
("OOS-2 INSERT OR REPLACE", "insert or replace into t values (1)"),
("OOS-2 INSERT OR IGNORE", "insert or ignore into t values (1)"),
("OOS-3 UPDATE … FROM", "update t set a = b.x from other b where t.id = b.id"),
("OOS-4 WITH … UPDATE", "with x as (select 1) update t set a = 1 where id = 1"),
("OOS-4 WITH … DELETE", "with x as (select 1) delete from t where id = 1"),
("OOS-5 INDEXED BY", "delete from t indexed by idx where id = 1"),
("OOS-5 NOT INDEXED", "update t not indexed set a = 1 where id = 1"),
("OOS-6 multi-statement (DELETE; DELETE)", "delete from t where id = 1; delete from t where id = 2"),
("OOS-6 multi-statement (INSERT; INSERT)", "insert into t values (1); insert into t values (2)"),
];
for (label, src) in cases {
assert!(
parse_command_in_mode(src, Mode::Advanced).is_err(),
"{label}: {src:?} must parse-reject (ADR-0033 §13)",
);
}
}
#[test]
fn e2e_single_dml_statement_with_trailing_semicolon_parses() {
// Guard for the OOS-6 multi-statement rejection above: a *single*
// statement with a trailing `;` is still valid (ADR-0033 §1 — the
// optional `;` tail), so the rejection above is genuinely about a
// second statement, not the semicolon.
assert!(
matches!(
parse_command_in_mode("delete from t where id = 1;", Mode::Advanced),
Ok(Command::SqlDelete { .. })
),
"a single statement with a trailing semicolon must still parse",
);
}
#[test]
fn e2e_update_all_rows_in_advanced_does_not_fall_back_to_dsl() {
// ADR-0033 Amendment 3 counter-example: the SQL `UPDATE`'s
// `SET <expr>` absorbs `--all-rows` (as `42 - -all - rows`), so
// the SQL shape matches and there is no DSL fall-back. (Harmless
// at execution — the engine treats `--all-rows` as a line
// comment.)
assert!(
matches!(
parse_command_in_mode("update Orders set total = 42 --all-rows", Mode::Advanced),
Ok(Command::SqlUpdate { .. })
),
"advanced `update … --all-rows` stays SQL (no DSL fall-back)",
);
}
// ===============================================================
// Validity indicator fires on a SQL DML diagnostic (matrix A7).
// ===============================================================
fn rendered_text(app: &mut App, theme: &Theme, width: u16, height: u16) -> String {
let backend = TestBackend::new(width, height);
let mut terminal = Terminal::new(backend).expect("terminal");
terminal.draw(|f| ui::render(app, theme, f)).expect("draw");
let buffer = terminal.backend().buffer().clone();
let mut out = String::new();
for y in 0..buffer.area.height {
for x in 0..buffer.area.width {
out.push_str(buffer[(x, y)].symbol());
}
out.push('\n');
}
out
}
#[test]
fn e2e_validity_indicator_fires_for_sql_dml_diagnostic() {
// ADR-0027 §4 / ADR-0030 §8 / matrix A7: a SQL DML line whose
// WHERE carries a predicate warning (`= NULL`) lights up the
// `[WRN]` indicator in Advanced mode. The verdict is the same
// computation the runtime stores in `input_indicator`.
let mut app = App::new();
app.mode = Mode::Advanced;
// Populate the schema cache so the diagnostic pass resolves
// the column.
app.schema_cache.tables.push("t".to_string());
app.schema_cache.columns.push("v".to_string());
app.schema_cache.table_columns.insert(
"t".to_string(),
vec![rdbms_playground::completion::TableColumn {
name: "v".to_string(),
user_type: Type::Int,
not_null: false,
has_default: false,
}],
);
app.input = "update t set v = 1 where v = NULL".to_string();
assert_eq!(
app.input_validity_verdict(),
Some(Severity::Warning),
"a SQL DML `= NULL` predicate raises a WARNING verdict",
);
// And the indicator renders the `[WRN]` label.
app.input_indicator = app.input_validity_verdict();
let text = rendered_text(&mut app, &Theme::dark(), 80, 24);
assert!(text.contains("[WRN]"), "the SQL DML warning surfaces as [WRN]:\n{text}");
}