fix: H1a G3 advanced usage shows all valid forms; complete near-miss matrix (ADR-0042)
The /runda DA pass found G3 over-corrected: advanced-mode `create`/`drop` showed SQL forms only, hiding the DSL fallback forms that are valid input in advanced mode (verified: `create table Foo with pk`, `drop column …` parse and dispatch). Per the user decision, the advanced usage block now shows every form valid in the mode, SQL-primary first, then the DSL fallback forms — a usage hint must never hide working input. Simple mode unchanged (DSL forms only). Matrix completion (closing the residual coverage tail): - arg-less app commands (help/rebuild/new/load/undo/redo/export/import) audited + locked — all reject trailing junk with "expected end of input" + usage. - committed multi-forms (add index/constraint/1:n relationship, drop index/constraint/relationship, show table, change column, create index, alter table add/drop) audited + locked in near_miss_matrix_committed_multiforms — each renders its own form-specific missing-keyword message + usage. Also from the DA pass: - G2 distinct+all detector empirically verified unique to projection start (no misfire at count( / union / union all / select distinct). - stale `chumsky` comment removed (app.rs import handler). - ADR-0042 Implementation-outcome section records G1–G4, the user-confirmed G3 decision, and the now-complete matrix coverage. Full suite green (lib 1578 / it 387 / typing_surface_matrix 192); clippy clean.
This commit is contained in:
@@ -64,17 +64,22 @@ fn dump(input: &str, lines: &[String]) -> String {
|
||||
/// near-correct input plus substrings that MUST appear across its
|
||||
/// rendered error lines — the structural "name the missing
|
||||
/// keyword/clause" message and the per-command usage template.
|
||||
/// These are the cases triaged as already-good; the baseline dump
|
||||
/// (`baseline_dump`, #[ignore]) shows the full rendering. Cases
|
||||
/// flagged for wording fixes (bare `add` `1`, bare `select`
|
||||
/// first-set, mode-blind usage) are deliberately NOT locked here
|
||||
/// until their fixes land.
|
||||
#[test]
|
||||
fn near_miss_matrix_simple_mode() {
|
||||
// (input, required-substrings-across-error-lines)
|
||||
let matrix: &[(&str, &[&str])] = &[
|
||||
// app-lifecycle arg errors
|
||||
// app-lifecycle arg errors. The arg-less commands all reject
|
||||
// trailing junk with "expected end of input" + their usage
|
||||
// (audited 2026-06-05); locked here as regression insurance.
|
||||
("quit now", &["after `quit`, expected end of input", " quit"]),
|
||||
("help foo", &["after `help`, expected end of input", " help"]),
|
||||
("rebuild now", &["after `rebuild`, expected end of input", " rebuild"]),
|
||||
("new foo", &["after `new`, expected end of input", " new"]),
|
||||
("load foo", &["after `load`, expected end of input", " load"]),
|
||||
("undo foo", &["after `undo`, expected end of input", " undo"]),
|
||||
("redo foo", &["after `redo`, expected end of input", " redo"]),
|
||||
("export foo bar", &["after `export foo`, expected end of input", "export [<path>]"]),
|
||||
("import a b c", &["after `import a`, expected end of input", "import <zip-path>"]),
|
||||
("save sideways", &["after `save`, expected end of input", "save | save as"]),
|
||||
("mode sideways", &["unknown mode 'sideways'", "mode simple | mode advanced"]),
|
||||
("messages louder", &["unknown messages mode 'louder'", "messages short"]),
|
||||
@@ -137,6 +142,61 @@ fn advanced_error_lines_for(input: &str) -> Vec<String> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Committed multi-form near-misses (ADR-0042 §1). A user who has
|
||||
/// already chosen a form (`add index …`, `drop constraint …`,
|
||||
/// `alter table T add …`) must get that form's specific
|
||||
/// missing-keyword/clause message and usage — not the whole family
|
||||
/// generically. Audited 2026-06-05; these render well today and are
|
||||
/// locked here as the residual systematic-pass tail.
|
||||
#[test]
|
||||
fn near_miss_matrix_committed_multiforms() {
|
||||
// (input, advanced?, required-substrings)
|
||||
let matrix: &[(&str, bool, &[&str])] = &[
|
||||
// add / drop multi-forms (simple)
|
||||
("add index", false, &["after `add index`, expected `on` or `as`", "add index [as <Name>] on"]),
|
||||
("add index on T", false, &["after `add index on T`, expected `(`", "add index [as <Name>] on"]),
|
||||
("add constraint", false, &["after `add constraint`, expected `not`, `unique`, `default`, or `check`", "add constraint not null to"]),
|
||||
("add constraint not null", false, &["after `add constraint not null`, expected `to`", "add constraint not null to"]),
|
||||
("add 1:n relationship", false, &["after `add 1:n relationship`, expected `from` or `as`", "add 1:n relationship"]),
|
||||
("add 1:n relationship from", false, &["after `add 1:n relationship from`, expected table name", "from <Parent>.<col>"]),
|
||||
("drop constraint", false, &["after `drop constraint`, expected `not`, `unique`, `default`, or `check`", "drop constraint (not null"]),
|
||||
("drop constraint not null", false, &["after `drop constraint not null`, expected `from`", "drop constraint (not null"]),
|
||||
("drop index", false, &["after `drop index`, expected `on` or index name", "drop index <Name>", "drop index on <Table>"]),
|
||||
("drop index on T", false, &["after `drop index on T`, expected `(`", "drop index on <Table>"]),
|
||||
("drop relationship", false, &["after `drop relationship`, expected `from` or relationship name", "drop relationship <Name>"]),
|
||||
("show table", false, &["after `show table`, expected table name", "show table <Table>"]),
|
||||
("change column in table T: c", false, &["after `change column in table T: c`, expected `(`", "change column [in] [table]"]),
|
||||
// advanced committed multi-forms
|
||||
("create index on", true, &["after `create index on`, expected table name", "create [unique] index"]),
|
||||
("create unique index", true, &["after `create unique index`, expected `on`, identifier, or `if`", "create [unique] index"]),
|
||||
("alter table T add", true, &["after `alter table T add`, expected `column`, `constraint`, `check`, `unique`, `foreign`, or `primary`", "alter table <Table> add column"]),
|
||||
("alter table T drop", true, &["after `alter table T drop`, expected `column` or `constraint`", "alter table <Table> drop column"]),
|
||||
];
|
||||
for (input, advanced, needles) in matrix {
|
||||
let lines = if *advanced {
|
||||
advanced_error_lines_for(input)
|
||||
} else {
|
||||
error_lines_for(input)
|
||||
};
|
||||
let dump_msg = dump(input, &lines);
|
||||
assert!(
|
||||
lines.iter().any(|l| l.starts_with("parse error")),
|
||||
"missing `parse error` line for {input:?}\n{dump_msg}",
|
||||
);
|
||||
assert!(
|
||||
!lines.iter().any(|l| l.starts_with("available commands:")),
|
||||
"committed form {input:?} fell back to available-commands\n{dump_msg}",
|
||||
);
|
||||
let joined = lines.join("\n");
|
||||
for needle in *needles {
|
||||
assert!(
|
||||
joined.contains(needle),
|
||||
"committed form {input:?} missing expected substring {needle:?}\n{dump_msg}",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn advanced_bare_select_collapses_projection_first_set() {
|
||||
// ADR-0042 G2: bare `select` dumped the full 14-item
|
||||
@@ -163,12 +223,16 @@ fn advanced_bare_select_collapses_projection_first_set() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn advanced_mode_usage_block_shows_sql_templates_not_dsl() {
|
||||
fn advanced_mode_usage_block_shows_sql_and_dsl_forms() {
|
||||
// ADR-0042 G3: `render_usage_block` was mode-blind — it
|
||||
// resolved shared entry words to the first-registered (Simple)
|
||||
// node, so advanced-mode `create` showed the DSL `create table
|
||||
// … with pk …` template, which is not valid SQL. Mode-aware
|
||||
// selection now shows the SQL forms.
|
||||
// node, so advanced-mode `create` showed ONLY the DSL `create
|
||||
// table … with pk …` template and none of the SQL forms.
|
||||
// Mode-aware selection shows every form valid in the mode,
|
||||
// SQL-primary first. In advanced mode the DSL forms remain
|
||||
// valid input (verified: `create table Foo with pk` parses and
|
||||
// runs in advanced mode), so they MUST still appear — a usage
|
||||
// hint never hides input that works.
|
||||
let lines = advanced_error_lines_for("create");
|
||||
let joined = lines.join("\n");
|
||||
let dump_msg = dump("create", &lines);
|
||||
@@ -181,9 +245,14 @@ fn advanced_mode_usage_block_shows_sql_templates_not_dsl() {
|
||||
"advanced `create` should show the SQL create-index usage\n{dump_msg}",
|
||||
);
|
||||
assert!(
|
||||
!joined.contains("with pk"),
|
||||
"advanced `create` must NOT show the DSL `with pk` template\n{dump_msg}",
|
||||
joined.contains("create table <Name> with pk"),
|
||||
"advanced `create` should ALSO show the DSL `with pk` form (valid in advanced mode)\n{dump_msg}",
|
||||
);
|
||||
// Ordering: the SQL form is listed before the DSL form
|
||||
// (mode-primary first).
|
||||
let sql_at = joined.find("create table [if not exists]").unwrap();
|
||||
let dsl_at = joined.find("create table <Name> with pk").unwrap();
|
||||
assert!(sql_at < dsl_at, "SQL form should precede the DSL form\n{dump_msg}");
|
||||
}
|
||||
|
||||
/// The advanced-mode near-miss matrix (ADR-0042 §1/§3). Mirrors
|
||||
@@ -197,11 +266,12 @@ fn near_miss_matrix_advanced_mode() {
|
||||
("select", &["expected a projection: `*`, a column, or an expression", "select (* |"]),
|
||||
("select * from", &["after `select * from`, expected table name", "select (* |"]),
|
||||
("with", &["after `with`, expected identifier or `recursive`", "with [recursive]", "as ("]),
|
||||
// create / drop / alter — SQL templates (G3)
|
||||
("create", &["after `create`, expected `table`", "create table [if not exists]", "create [unique] index"]),
|
||||
// create / drop / alter — SQL forms AND the still-valid DSL
|
||||
// fallback forms, SQL-primary first (G3).
|
||||
("create", &["after `create`, expected `table`", "create table [if not exists]", "create [unique] index", "create table <Name> with pk"]),
|
||||
("create table", &["after `create table`, expected identifier or `if`", "create table [if not exists]"]),
|
||||
("create index", &["after `create index`, expected `on`", "create [unique] index"]),
|
||||
("drop", &["after `drop`, expected `table`", "drop table [if exists]"]),
|
||||
("drop", &["after `drop`, expected `table`", "drop table [if exists]", "drop column [from]", "drop relationship"]),
|
||||
("alter", &["after `alter`, expected `table`", "alter table <Table> add column"]),
|
||||
("alter table T", &["expected `add`, `drop`, `rename`, or `alter`", "alter table <Table>"]),
|
||||
// shared insert/update/delete — must show usage, not the
|
||||
@@ -429,3 +499,7 @@ fn caret_aligns_under_offending_token() {
|
||||
"caret should sit at column 9 (under `f` of `frobulate` after the `running: ` prefix); got {leading_spaces} spaces in {caret:?}",
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user