grammar+walker: 3j — shared insert/update/delete entry words (ADR-0033 §2 / Amendments 1 & 3)

Wire `insert`/`update`/`delete` as shared DSL/SQL entry words through the
category-grouped dispatcher (ADR-0033 Amendment 1): the Advanced SQL nodes
move off the dev words (`sqlinsert`/`sql_update`/`sql_delete`) to the real
keywords, registered alongside the Simple DSL nodes. Remove the dev-word
scaffold; collapse build_sql_{insert,update,delete} to source.trim();
de-duplicate the two REGISTRY entry-word listing sites.

Dispatch model (ADR-0033 Amendment 3, written this round):
- A command is the mode-rooted grammar-path outcome; identity is intrinsic.
  Advanced mode tries SQL first, falling back to the Simple DSL command when
  no SQL branch matches a token (`delete … --all-rows` falls back;
  `update … --all-rows` does not — the SET expression absorbs it, harmless
  since the engine treats `--all-rows` as a comment).
- Simple mode commits the DSL candidate for a shared word, surfacing the real
  DSL error; bare "this is SQL" is reserved for SQL-only entry words
  (`select`/`with`). A content rejection on the SQL candidate (internal
  table) is committed, never masked by the DSL fallback.

Combined DSL-error + advanced-SQL pointer (ADR-0033 Amendment 3): a Simple-mode
definite DSL error that would run as SQL in advanced mode gains the
`advanced_mode.also_valid_sql` suffix — in the live hint (ambient_hint_in_mode)
and on submit (dispatch_dsl), via the shared advanced_alternative_note — so the
actionable DSL fix and the mode pointer coexist (submit covers constructs that
surface only on submit, e.g. `delete … returning`).

Internal-table rejection symmetrised (/runda finding B, ADR-0030 §6): the DSL
data-command target slots (insert/update/delete/show data/show table) gained
reject_internal_table, so `__rdbms_*` tables are refused in Simple mode too —
previously only the advanced SQL grammar rejected them.

Mode-awareness: classify_input_with_schema_in_mode and
invalid_ident_at_cursor_in_mode stop leaking the advanced SQL view into
simple-mode hints for shared words.

Tests: dev-word inputs migrated to the real words (advanced); DSL grammar /
completion / phase-D / db tests parse in Simple mode (the DSL surface); replay
keeps its advanced-mode model (one stale assertion fixed); dispatcher routing,
combined-pointer, and internal-table tests added. Suite 1626 pass / 0 fail /
1 ignored; clippy --all-targets -D warnings clean.

Defer M4 (execution-time mode side-channel; tracked in requirements.md) to its
own ADR.
This commit is contained in:
claude@clouddev1
2026-05-23 21:13:39 +00:00
parent c16196fc7f
commit d5c7f63513
22 changed files with 956 additions and 314 deletions
+27 -17
View File
@@ -228,21 +228,31 @@ fn replay_aborts_on_first_parse_failure_and_reports_line() {
}
#[test]
fn replay_rejects_typed_slot_violation_at_parse_time() {
// Schema-aware replay (handoff-13 §2.1 fix): run_replay
// re-snapshots the schema per line and parses with
// parse_command_with_schema. So a wrong-type value in a
// value list is caught at *parse* time during replay —
// surfaced through the `replay.error_parse` wrapper ("parse
// error …") — exactly as the interactive path would, rather
// than only at bind time.
fn replay_rejects_wrong_type_value_in_a_hand_built_script() {
// Replay parses each line with the SAME schema-aware parser the
// interactive path uses, in **advanced mode** (the full surface),
// and executes the result — so a replayed line behaves exactly as
// if it had been typed interactively in advanced mode. Nothing is
// skipped or simplified during replay (handoff-13 §2.1: the schema
// is threaded so the parser is fully schema-aware).
//
// `'not a number'` (a string) lands in the int `count`
// slot. The schemaless parser would accept it (a string is
// a value literal) and only bind-time would reject; the
// schema-aware parser rejects it at parse time. Asserting
// the error went through the parse wrapper proves the
// schema was threaded.
// A real journal only ever contains commands that already executed
// successfully (history.log is success-only; ADR-0034's deferred
// journal replays `ok` lines only), so a wrong-type line like this
// never arises from a genuine replay. It only arises from a
// *hand-built* `.commands` script — the robustness case this test
// exercises: replay must reject the bad line and stop, leaving
// state intact, with the same error a user would see typing it.
//
// Where the rejection lands depends on the grammar the line
// matches, exactly as interactively: `insert into T values (…)` is
// SQL in advanced mode, and SQL defers column-type checking to the
// engine, so `'not a number'` in the int `count` column is rejected
// at **execute** time (the engine's column-type enforcement) rather
// than at parse time. Either way the line fails and is not applied.
// (Before sub-phase 3j, `insert` was a DSL-only entry word, so even
// advanced-mode parsing hit the DSL typed-slot rail and this was a
// parse-time rejection — ADR-0033 Amendment 3.)
let data = tempdir();
let (project, db) = open_project_db(data.path());
write_script(
@@ -261,12 +271,12 @@ fn replay_rejects_typed_slot_violation_at_parse_time() {
unreachable!()
};
assert!(
error.contains("parse error"),
"typed-slot violation should be caught at parse time, got: {error}",
!error.is_empty(),
"the rejected line must carry a reported error",
);
// The earlier two lines stayed applied; the failing insert
// did not run.
// did not run — state is intact.
let data_result = rt()
.block_on(async { db.query_data("T".to_string(), None, None, None).await })
.expect("query_data");