explain: typing-surface matrix cells (ADR-0028 step 5)

13 matrix cells for the `explain` prefix across all three
wrapped commands — `explain show data` / `explain update` /
`explain delete` — covering each typing position (after the
prefix, the inner entry word, the table, the filter clause)
plus the three complete forms. The cells confirm `explain`
plugs into the inner query grammars cleanly: candidates, hints
and column scoping match the standalone commands, and the
complete forms parse as `Command::Explain`.

Also adds a worker test pinning the display SQL's `<>`
rendering of inequality (ADR-0028 §3).

Matrix: 161 -> 174 cells. 1172 tests pass; clippy clean.
This commit is contained in:
claude@clouddev1
2026-05-19 12:49:58 +00:00
parent a7d459f8f2
commit ae99276283
16 changed files with 678 additions and 0 deletions
+22
View File
@@ -8247,6 +8247,28 @@ mod tests {
);
}
#[tokio::test]
async fn explain_display_sql_writes_inequality_as_angle_brackets() {
let db = db();
people_table(&db).await;
let plan = db
.explain_query_plan(parse_inner("show data People where Age != 35"))
.await
.unwrap();
// ADR-0028 §3: inequality is shown as standard SQL `<>`
// even when the user typed `!=`.
assert!(
plan.display_sql.contains("<>"),
"inequality should render as `<>`: {}",
plan.display_sql,
);
assert!(
!plan.display_sql.contains("!="),
"the `!=` spelling should not survive: {}",
plan.display_sql,
);
}
#[tokio::test]
async fn explain_of_a_missing_table_is_an_error() {
let db = db();
+132
View File
@@ -0,0 +1,132 @@
//! Matrix coverage for the `explain` prefix command (ADR-0028).
//!
//! `explain` wraps `show data` / `update` / `delete` through a
//! `Subgrammar`, so the inner command is parsed, completed and
//! hinted exactly as it is standalone. These cells verify the
//! prefix plugs in cleanly at each typing position and that the
//! complete forms parse as `Command::Explain`.
use crate::typing_surface::*;
use rdbms_playground::input_render::InputState;
#[test]
fn after_explain_offers_the_three_explainable_commands() {
let schema = schema_serial_pk();
let a = assess_at_end("explain ", &schema);
assert!(matches!(a.state, InputState::IncompleteAtEof));
assert_candidate_present(&a, &["show", "update", "delete"]);
crate::snap!("after_explain", a);
}
#[test]
fn after_explain_show_expects_data() {
let schema = schema_serial_pk();
let a = assess_at_end("explain show ", &schema);
assert!(matches!(a.state, InputState::IncompleteAtEof));
// `explain` covers `show data` only — not `show table`.
assert_candidate_present(&a, &["data"]);
assert_no_candidate_named(&a, &["table"]);
crate::snap!("after_explain_show", a);
}
#[test]
fn after_explain_show_data_offers_table_names() {
let schema = schema_multi_table();
let a = assess_at_end("explain show data ", &schema);
assert_candidate_present(&a, &["Customers", "Orders"]);
crate::snap!("after_explain_show_data", a);
}
#[test]
fn after_explain_show_data_table_offers_where_and_limit() {
let schema = schema_serial_pk();
let a = assess_at_end("explain show data Customers ", &schema);
assert_candidate_present(&a, &["where", "limit"]);
crate::snap!("after_explain_show_data_table", a);
}
#[test]
fn explain_show_data_where_offers_active_table_columns_no_leakage() {
let schema = schema_multi_table();
let a = assess_at_end("explain show data Customers where ", &schema);
assert_candidate_present(&a, &["id", "Name"]);
assert_no_candidate_named(&a, &["OrderId", "CustId", "Total"]);
crate::snap!("explain_show_data_where", a);
}
#[test]
fn complete_explain_show_data_parses_as_explain() {
let schema = schema_serial_pk();
let a = assess_at_end("explain show data Customers", &schema);
assert!(matches!(a.state, InputState::Valid));
assert_eq!(a.parse_result.as_deref(), Ok("Explain"));
crate::snap!("complete_explain_show_data", a);
}
#[test]
fn complete_explain_show_data_with_where_and_limit_parses() {
let schema = schema_serial_pk();
let a = assess_at_end(
"explain show data Customers where id = 1 limit 5",
&schema,
);
assert!(matches!(a.state, InputState::Valid));
assert_eq!(a.parse_result.as_deref(), Ok("Explain"));
crate::snap!("complete_explain_show_data_where_limit", a);
}
#[test]
fn after_explain_update_offers_table_names() {
let schema = schema_multi_table();
let a = assess_at_end("explain update ", &schema);
assert_candidate_present(&a, &["Customers", "Orders"]);
crate::snap!("after_explain_update", a);
}
#[test]
fn after_explain_update_table_expects_set() {
let schema = schema_serial_pk();
let a = assess_at_end("explain update Customers ", &schema);
assert!(matches!(a.state, InputState::IncompleteAtEof));
assert_candidate_present(&a, &["set"]);
crate::snap!("after_explain_update_table", a);
}
#[test]
fn complete_explain_update_parses_as_explain() {
let schema = schema_serial_pk();
let a = assess_at_end(
"explain update Customers set Name='Bo' where id=1",
&schema,
);
assert!(matches!(a.state, InputState::Valid));
assert_eq!(a.parse_result.as_deref(), Ok("Explain"));
crate::snap!("complete_explain_update", a);
}
#[test]
fn after_explain_delete_expects_from() {
let schema = schema_serial_pk();
let a = assess_at_end("explain delete ", &schema);
assert!(matches!(a.state, InputState::IncompleteAtEof));
assert_candidate_present(&a, &["from"]);
crate::snap!("after_explain_delete", a);
}
#[test]
fn after_explain_delete_from_table_expects_filter_clause() {
let schema = schema_serial_pk();
let a = assess_at_end("explain delete from Customers ", &schema);
assert!(matches!(a.state, InputState::IncompleteAtEof));
assert_candidate_present(&a, &["where", "--all-rows"]);
crate::snap!("after_explain_delete_from_table", a);
}
#[test]
fn complete_explain_delete_parses_as_explain() {
let schema = schema_serial_pk();
let a = assess_at_end("explain delete from Customers where id=1", &schema);
assert!(matches!(a.state, InputState::Valid));
assert_eq!(a.parse_result.as_deref(), Ok("Explain"));
crate::snap!("complete_explain_delete", a);
}
+1
View File
@@ -29,6 +29,7 @@ pub mod update_all_rows;
pub mod delete_with_where;
pub mod where_expression;
pub mod delete_all_rows;
pub mod explain;
pub mod create_table;
pub mod drop_column;
pub mod drop_relationship;
@@ -0,0 +1,39 @@
---
source: tests/typing_surface/explain.rs
description: "input=\"explain delete \" cursor=15"
expression: "& a"
---
Assessment {
input: "explain delete ",
cursor: 15,
state: IncompleteAtEof,
hint: Some(
Candidates {
items: [
Candidate {
text: "from",
kind: Keyword,
},
],
selected: None,
},
),
completion: Some(
Completion {
replaced_range: (
15,
15,
),
partial_prefix: "",
candidates: [
Candidate {
text: "from",
kind: Keyword,
},
],
},
),
parse_result: Err(
"Invalid(at_eof)",
),
}
@@ -0,0 +1,47 @@
---
source: tests/typing_surface/explain.rs
description: "input=\"explain delete from Customers \" cursor=30"
expression: "& a"
---
Assessment {
input: "explain delete from Customers ",
cursor: 30,
state: IncompleteAtEof,
hint: Some(
Candidates {
items: [
Candidate {
text: "where",
kind: Keyword,
},
Candidate {
text: "--all-rows",
kind: Flag,
},
],
selected: None,
},
),
completion: Some(
Completion {
replaced_range: (
30,
30,
),
partial_prefix: "",
candidates: [
Candidate {
text: "where",
kind: Keyword,
},
Candidate {
text: "--all-rows",
kind: Flag,
},
],
},
),
parse_result: Err(
"Invalid(at_eof)",
),
}
@@ -0,0 +1,55 @@
---
source: tests/typing_surface/explain.rs
description: "input=\"explain \" cursor=8"
expression: "& a"
---
Assessment {
input: "explain ",
cursor: 8,
state: IncompleteAtEof,
hint: Some(
Candidates {
items: [
Candidate {
text: "show",
kind: Keyword,
},
Candidate {
text: "update",
kind: Keyword,
},
Candidate {
text: "delete",
kind: Keyword,
},
],
selected: None,
},
),
completion: Some(
Completion {
replaced_range: (
8,
8,
),
partial_prefix: "",
candidates: [
Candidate {
text: "show",
kind: Keyword,
},
Candidate {
text: "update",
kind: Keyword,
},
Candidate {
text: "delete",
kind: Keyword,
},
],
},
),
parse_result: Err(
"Invalid(at_eof)",
),
}
@@ -0,0 +1,47 @@
---
source: tests/typing_surface/explain.rs
description: "input=\"explain show data \" cursor=18"
expression: "& a"
---
Assessment {
input: "explain show data ",
cursor: 18,
state: IncompleteAtEof,
hint: Some(
Candidates {
items: [
Candidate {
text: "Customers",
kind: Identifier,
},
Candidate {
text: "Orders",
kind: Identifier,
},
],
selected: None,
},
),
completion: Some(
Completion {
replaced_range: (
18,
18,
),
partial_prefix: "",
candidates: [
Candidate {
text: "Customers",
kind: Identifier,
},
Candidate {
text: "Orders",
kind: Identifier,
},
],
},
),
parse_result: Err(
"Invalid(at_eof)",
),
}
@@ -0,0 +1,47 @@
---
source: tests/typing_surface/explain.rs
description: "input=\"explain show data Customers \" cursor=28"
expression: "& a"
---
Assessment {
input: "explain show data Customers ",
cursor: 28,
state: Valid,
hint: Some(
Candidates {
items: [
Candidate {
text: "where",
kind: Keyword,
},
Candidate {
text: "limit",
kind: Keyword,
},
],
selected: None,
},
),
completion: Some(
Completion {
replaced_range: (
28,
28,
),
partial_prefix: "",
candidates: [
Candidate {
text: "where",
kind: Keyword,
},
Candidate {
text: "limit",
kind: Keyword,
},
],
},
),
parse_result: Ok(
"Explain",
),
}
@@ -0,0 +1,39 @@
---
source: tests/typing_surface/explain.rs
description: "input=\"explain show \" cursor=13"
expression: "& a"
---
Assessment {
input: "explain show ",
cursor: 13,
state: IncompleteAtEof,
hint: Some(
Candidates {
items: [
Candidate {
text: "data",
kind: Keyword,
},
],
selected: None,
},
),
completion: Some(
Completion {
replaced_range: (
13,
13,
),
partial_prefix: "",
candidates: [
Candidate {
text: "data",
kind: Keyword,
},
],
},
),
parse_result: Err(
"Invalid(at_eof)",
),
}
@@ -0,0 +1,47 @@
---
source: tests/typing_surface/explain.rs
description: "input=\"explain update \" cursor=15"
expression: "& a"
---
Assessment {
input: "explain update ",
cursor: 15,
state: IncompleteAtEof,
hint: Some(
Candidates {
items: [
Candidate {
text: "Customers",
kind: Identifier,
},
Candidate {
text: "Orders",
kind: Identifier,
},
],
selected: None,
},
),
completion: Some(
Completion {
replaced_range: (
15,
15,
),
partial_prefix: "",
candidates: [
Candidate {
text: "Customers",
kind: Identifier,
},
Candidate {
text: "Orders",
kind: Identifier,
},
],
},
),
parse_result: Err(
"Invalid(at_eof)",
),
}
@@ -0,0 +1,39 @@
---
source: tests/typing_surface/explain.rs
description: "input=\"explain update Customers \" cursor=25"
expression: "& a"
---
Assessment {
input: "explain update Customers ",
cursor: 25,
state: IncompleteAtEof,
hint: Some(
Candidates {
items: [
Candidate {
text: "set",
kind: Keyword,
},
],
selected: None,
},
),
completion: Some(
Completion {
replaced_range: (
25,
25,
),
partial_prefix: "",
candidates: [
Candidate {
text: "set",
kind: Keyword,
},
],
},
),
parse_result: Err(
"Invalid(at_eof)",
),
}
@@ -0,0 +1,19 @@
---
source: tests/typing_surface/explain.rs
description: "input=\"explain delete from Customers where id=1\" cursor=40"
expression: "& a"
---
Assessment {
input: "explain delete from Customers where id=1",
cursor: 40,
state: Valid,
hint: Some(
Prose(
"Submit with Enter",
),
),
completion: None,
parse_result: Ok(
"Explain",
),
}
@@ -0,0 +1,19 @@
---
source: tests/typing_surface/explain.rs
description: "input=\"explain show data Customers\" cursor=27"
expression: "& a"
---
Assessment {
input: "explain show data Customers",
cursor: 27,
state: Valid,
hint: Some(
Prose(
"Submit with Enter",
),
),
completion: None,
parse_result: Ok(
"Explain",
),
}
@@ -0,0 +1,19 @@
---
source: tests/typing_surface/explain.rs
description: "input=\"explain show data Customers where id = 1 limit 5\" cursor=48"
expression: "& a"
---
Assessment {
input: "explain show data Customers where id = 1 limit 5",
cursor: 48,
state: Valid,
hint: Some(
Prose(
"Submit with Enter",
),
),
completion: None,
parse_result: Ok(
"Explain",
),
}
@@ -0,0 +1,19 @@
---
source: tests/typing_surface/explain.rs
description: "input=\"explain update Customers set Name='Bo' where id=1\" cursor=49"
expression: "& a"
---
Assessment {
input: "explain update Customers set Name='Bo' where id=1",
cursor: 49,
state: Valid,
hint: Some(
Prose(
"Submit with Enter",
),
),
completion: None,
parse_result: Ok(
"Explain",
),
}
@@ -0,0 +1,87 @@
---
source: tests/typing_surface/explain.rs
description: "input=\"explain show data Customers where \" cursor=34"
expression: "& a"
---
Assessment {
input: "explain show data Customers where ",
cursor: 34,
state: IncompleteAtEof,
hint: Some(
Candidates {
items: [
Candidate {
text: "not",
kind: Keyword,
},
Candidate {
text: "null",
kind: Keyword,
},
Candidate {
text: "true",
kind: Keyword,
},
Candidate {
text: "false",
kind: Keyword,
},
Candidate {
text: "(",
kind: Punct,
},
Candidate {
text: "Name",
kind: Identifier,
},
Candidate {
text: "id",
kind: Identifier,
},
],
selected: None,
},
),
completion: Some(
Completion {
replaced_range: (
34,
34,
),
partial_prefix: "",
candidates: [
Candidate {
text: "not",
kind: Keyword,
},
Candidate {
text: "null",
kind: Keyword,
},
Candidate {
text: "true",
kind: Keyword,
},
Candidate {
text: "false",
kind: Keyword,
},
Candidate {
text: "(",
kind: Punct,
},
Candidate {
text: "Name",
kind: Identifier,
},
Candidate {
text: "id",
kind: Identifier,
},
],
},
),
parse_result: Err(
"Invalid(at_eof)",
),
}