You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 33fd340
Browse filesBrowse the repository at this point in the historyBrowse files
feat(scenarios): reject quoted and materialized scenario CTE names like SQL tests (#1052)
* feat(scenarios): reject quoted and materialized scenario CTE names like SQL tests
Scenarios and macro-test scope scans no longer fall back to a Polyglot
re-parse. Quoted CTE names and AS [NOT] MATERIALIZED are located compile
errors with help on every engine, matching SQL tests.
* test(scenarios): cover scenario body spans and pass them in unit helpers
description:"a quoted CTE name is a scanner error Python may still accept with Polyglot",
67
+
description:"a quoted CTE name is Python's scanner error",
68
68
sql:"WITH \"__source__raw\" AS (SELECT 1), __expected__orders AS (SELECT 1 AS id)",
69
69
expected_json:Some(
70
-
r#"{"scanError":"SQL scenario 'tests/scenarios/orders.sql' expected a CTE name"}"#,
70
+
r#"{"error":"SQL scenario 'tests/scenarios/orders.sql' expected a CTE name"}"#,
71
71
),
72
72
},
73
73
ScenarioExtractionTestCase{
74
-
description:"an unclosed body is a scanner error naming the scenario context",
74
+
description:"an unclosed body is Python's scanner error naming the scenario context",
75
75
sql:"WITH __source__raw AS (SELECT 1",
76
-
expected_json:Some(r#"{"scanError":"SQL scenario contains an unclosed parenthesis"}"#),
76
+
expected_json:Some(r#"{"error":"SQL scenario contains an unclosed parenthesis"}"#),
77
+
},
78
+
ScenarioExtractionTestCase{
79
+
description:"a materialization hint is Python's scanner error",
80
+
sql:"WITH __source__raw AS NOT MATERIALIZED (SELECT 1), __expected__orders AS (SELECT 1)",
81
+
expected_json:Some(
82
+
r#"{"error":"SQL scenario 'tests/scenarios/orders.sql' CTE '__source__raw' must not use AS NOT MATERIALIZED; materialization hints are not supported in SQL scenario CTEs"}"#,
83
+
),
77
84
},
78
85
ScenarioExtractionTestCase{
79
86
description:"a keyword Python would match by case mapping defers",
description:"a materialization hint is located at the hint with help",
411
+
sql:"WITH h AS (SELECT 1),\n__ref__orders AS not\nmaterialized (SELECT 2)",
412
+
expected_response:json!({"error":{
413
+
"index":0,
414
+
"message":"SQL test 'tests/t.sql' CTE '__ref__orders' must not use AS NOT MATERIALIZED; materialization hints are not supported in SQL test CTEs",
415
+
"help":"remove NOT MATERIALIZED and write __ref__orders AS (...)",
416
+
"token":"not\nmaterialized",
417
+
"tokenOffset":39,
418
+
}}),
419
+
},
420
+
AuthoredCtesTestCase{
421
+
scenario:true,
422
+
description:"a scenario's quoted CTE name names the scenario",
423
+
sql:"WITH \"__source__raw_orders\" AS (SELECT 1), __expected__orders AS (SELECT 1)",
424
+
expected_response:json!({"error":{
425
+
"index":0,
426
+
"message":"SQL scenario 'tests/t.sql' CTE name \"__source__raw_orders\" must be an unquoted identifier of ASCII letters, digits and underscores",
427
+
"help":"rename the CTE, for example __source__raw_orders; quoted CTE names and names with $ or non-ASCII characters are not supported",
428
+
"token":"\"__source__raw_orders\"",
429
+
"tokenOffset":5,
430
+
}}),
431
+
},
432
+
AuthoredCtesTestCase{
433
+
scenario:true,
434
+
description:"a scenario's materialization hint names the scenario",
435
+
sql:"WITH __source__raw_orders AS MATERIALIZED (SELECT 1)",
436
+
expected_response:json!({"error":{
437
+
"index":0,
438
+
"message":"SQL scenario 'tests/t.sql' CTE '__source__raw_orders' must not use AS MATERIALIZED; materialization hints are not supported in SQL scenario CTEs",
439
+
"help":"remove MATERIALIZED and write __source__raw_orders AS (...)",
440
+
"token":"MATERIALIZED",
441
+
"tokenOffset":29,
442
+
}}),
443
+
},
444
+
AuthoredCtesTestCase{
445
+
scenario:false,
446
+
description:"a CTE name starting with a digit is located with help",
447
+
sql:"WITH 2024_orders AS (SELECT 1)",
448
+
expected_response:json!({"error":{
449
+
"index":0,
450
+
"message":"SQL test 'tests/t.sql' CTE name '2024_orders' must be an unquoted identifier of ASCII letters, digits and underscores",
451
+
"help":"rename the CTE, for example cte_2024_orders; quoted CTE names and names with $ or non-ASCII characters are not supported",
452
+
"token":"2024_orders",
453
+
"tokenOffset":5,
454
+
}}),
455
+
},
456
+
AuthoredCtesTestCase{
457
+
scenario:false,
407
458
description:"other errors are left to extraction and read as no CTEs",
0 commit comments