From 1d89b3e8dcd330c83bef470a750ec9717aa243f5 Mon Sep 17 00:00:00 2001 From: Manush Murali Date: Tue, 10 Nov 2026 14:04:10 -0800 Subject: [PATCH 01/12] Hold canonical wire bodies to their exact sections The wire behavior check replaced the recorded payload snapshot but only looked at selected fields, so a key added to a body, its metadata or its output (a leaked client_* key, say) passed. Assert each body's exact top-level keys and compare metadata and output whole, and seed those four faults in the release contract test. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Manush Murali --- scripts/check_wire_behavior.py | 39 +++++++++++++++++++++++----------- tests/test_release_contract.py | 12 +++++++++++ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/scripts/check_wire_behavior.py b/scripts/check_wire_behavior.py index 7bafaf1f8..00034f58e 100644 --- a/scripts/check_wire_behavior.py +++ b/scripts/check_wire_behavior.py @@ -209,13 +209,24 @@ def assert_behavior(cases): people = [ [i, 20.0 + i, 'north' if i % 3 else 'south', i % 2] for i in range(12) ] + sections = { + 'model', + 'task', + 'context', + 'predict', + 'schema', + 'output', + 'metadata', + } for name, calls in cases.items(): assert len(calls) == 1, name body = calls[0] - assert body['metadata']['request_id'] == _FIXED_REQUEST_ID if name.startswith('relational/'): + assert set(body) == sections | {'inference'}, name _assert_relational(body, people) continue + assert set(body) == sections, name + assert body['metadata'] == {'request_id': _FIXED_REQUEST_ID} target, kind, dtype = targets[ name.removeprefix('tabular/').split('#')[0] ] @@ -224,11 +235,13 @@ def assert_behavior(cases): 'kind': kind, 'target': {'column_name': target, 'dtype': dtype}, } - assert body['output']['fields'] == ( - ['prediction', 'probabilities'] - if '#default-outputs' in name - else ['prediction'] - ) + assert body['output'] == { + 'fields': ( + ['prediction', 'probabilities'] + if '#default-outputs' in name + else ['prediction'] + ) + } start = 3 if '/pql-' in name else 0 assert ( _rows(body['context']['instance_table'], columns) == people[start:] @@ -274,12 +287,14 @@ def _assert_relational(body, people): 'run_mode': 'fast', 'use_prediction_time': False, } - assert body['metadata']['num_context_examples'] == 84 - assert body['metadata']['num_prediction_examples'] == 3 - assert ( - body['metadata']['source_query'] - == 'PREDICT COUNT(orders.*, 0, 30, days) FOR EACH people.user_id' - ) + assert body['metadata'] == { + 'source_query': ( + 'PREDICT COUNT(orders.*, 0, 30, days) FOR EACH people.user_id' + ), + 'num_context_examples': 84, + 'num_prediction_examples': 3, + 'request_id': _FIXED_REQUEST_ID, + } start = pd.Timestamp('2026-01-01', tz='UTC') seen = set() for half in ('context', 'predict'): diff --git a/tests/test_release_contract.py b/tests/test_release_contract.py index a89b99576..a48a537e6 100644 --- a/tests/test_release_contract.py +++ b/tests/test_release_contract.py @@ -829,6 +829,10 @@ def _current_wire_payloads(): 'history', 'relationship', 'schema_type', + 'client_key', + 'tabular_inference', + 'metadata_key', + 'output_statistic', ], ) def test_wire_assertions_reject_behavior_changes(damage): @@ -859,6 +863,14 @@ def test_wire_assertions_reject_behavior_changes(damage): relational['schema']['related_tables']['orders']['columns']['price'][ 'dtype' ] = 'int64' + elif damage == 'client_key': + relational['client_generated_keys'] = {'orders': '__node_id'} + elif damage == 'tabular_inference': + direct['inference'] = {'run_mode': 'fast'} + elif damage == 'metadata_key': + relational['metadata']['client_rows'] = 3 + elif damage == 'output_statistic': + direct['output']['prediction_statistic'] = 'median' with pytest.raises(AssertionError): _loaded('check_wire_behavior').assert_behavior(cases) From d0a05715df13d12e1e214e6f8d6fa367cec62b0a Mon Sep 17 00:00:00 2001 From: Manush Murali Date: Tue, 10 Nov 2026 14:04:58 -0800 Subject: [PATCH 02/12] Expect the PostgreSQL wide-key case to succeed as SQLite does The PostgreSQL branch expected 1.0.0's bare OverflowError at from_source, but the client reads keys past int64 as exact text there and succeeds, so the test failed whenever a Postgres DSN was set. CI never set one for contract/tests, which hid it. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Manush Murali --- contract/tests/test_public_error_messages.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contract/tests/test_public_error_messages.py b/contract/tests/test_public_error_messages.py index c363d4752..65f4205c4 100644 --- a/contract/tests/test_public_error_messages.py +++ b/contract/tests/test_public_error_messages.py @@ -294,13 +294,13 @@ def test_public_refusal_names_the_invalid_input(case_key: str) -> None: 'INVALID_REQUEST', ) required_words = ['users.d', 'type string', 'constant', 'quotes'] - elif case_key == 'key.uint64-above-int64-max@sqlite': - # The maintained SQLite path now handles this input successfully. + elif case_key in { + 'key.uint64-above-int64-max@sqlite', + 'key.uint64-above-int64-max@postgres', + }: + # SQLite and PostgreSQL read these keys as exact text and succeed. assert _outcome(got['outcome']) == ('success', 'predict', None, None) return - elif case_key == 'key.uint64-above-int64-max@postgres': - expected = ('refusal', 'from_source', 'OverflowError', None) - required_words = ['int'] assert same_outcome(expected, _outcome(got['outcome'])), case_key said = _words(got['message']) assert not said.startswith(GENERIC), ( From 897b7de49485964a8bd4f04214604aabf3f2ed40 Mon Sep 17 00:00:00 2001 From: Manush Murali Date: Tue, 10 Nov 2026 14:06:42 -0800 Subject: [PATCH 03/12] Drop fixture notes and the reader the cleanup left behind The maintained-fixture README still described label-expectations.json and eight sdm-shared-fixture/1 files, none of which remain, and rust/testdata/fixture_tables.rs no longer has an includer. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Manush Murali --- contract/fixtures/maintained/README.md | 9 ---- rust/testdata/fixture_tables.rs | 70 -------------------------- 2 files changed, 79 deletions(-) delete mode 100644 rust/testdata/fixture_tables.rs diff --git a/contract/fixtures/maintained/README.md b/contract/fixtures/maintained/README.md index 7dd149825..fb4483949 100644 --- a/contract/fixtures/maintained/README.md +++ b/contract/fixtures/maintained/README.md @@ -7,8 +7,6 @@ These fixtures hold independent expected facts for current correctness tests. Tests need only this checkout; historical clients, archives and recording tools are not dependencies. -- `label-expectations.json` contains only the four label cases' expected context rows and counts. - Write-guard and provider-layout tests exercise these facts without loading full driver result logs. - `snowflake.json` contains the statements and result references for the 14 cases used by the public Python Snowflake tests. `snowflake/` shares identical Arrow IPC streams by their SHA-256 names. Original driver Arrow bytes are preserved, including their types and metadata. @@ -18,13 +16,6 @@ Tests need only this checkout; historical clients, archives and recording tools - `consumers.json` names the current consumers and reviewed byte limits for large retained fixtures. New oversized fixtures require an explicit entry and explanation. -Eight fixtures elsewhere under `contract/` use `sdm-shared-fixture/1`. -Named fields have dictionaries of literal values; ordered rows reference those dictionaries, with `-1` for an absent field. -Nested tables can reference only earlier tables. -This shares repeated inputs and expected results while preserving every case, its order, nulls and JSON types. -The expanded SHA-256 binds the complete original logical JSON document. -The Python and Rust test helpers expand these literals without calling product code to compute expectations. - The original extraction tool and recording-completeness tests were migration-only and have been removed. Git history retains their implementation and original fixtures. Maintain expected values from documented behavior and independently calculated examples; do not regenerate expected answers from the product under test. diff --git a/rust/testdata/fixture_tables.rs b/rust/testdata/fixture_tables.rs deleted file mode 100644 index ae394324a..000000000 --- a/rust/testdata/fixture_tables.rs +++ /dev/null @@ -1,70 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. -// All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -//! Decode shared literal fixture fields. No product code computes expectations. -use serde_json::{Map, Value}; - -pub fn read(text: &str) -> Value { - let file: Value = serde_json::from_str(text).unwrap(); - if file["format"] != "sdm-shared-fixture/1" { - return file; - } - let tables = file["tables"].as_array().unwrap(); - expand(&file["document"], tables, tables.len()) -} - -fn expand(node: &Value, tables: &[Value], before: usize) -> Value { - match node { - Value::Object(object) if object.contains_key("$fixture_table") => { - assert_eq!(object.len(), 1); - let index = object["$fixture_table"].as_u64().unwrap() as usize; - assert!(index < before, "invalid or cyclic fixture table reference"); - let table = &tables[index]; - let fields = table["fields"].as_array().unwrap(); - let columns = table["values"].as_array().unwrap(); - assert_eq!(fields.len(), columns.len()); - Value::Array( - table["rows"] - .as_array() - .unwrap() - .iter() - .map(|row| { - let cells = row.as_array().unwrap(); - assert_eq!(cells.len(), fields.len()); - let mut record = Map::new(); - for ((field, column), cell) in fields.iter().zip(columns).zip(cells) { - let cell = cell.as_i64().unwrap(); - assert!(cell >= -1); - if cell >= 0 { - let value = &column.as_array().unwrap()[cell as usize]; - assert!( - record - .insert( - field.as_str().unwrap().to_owned(), - expand(value, tables, index) - ) - .is_none() - ); - } - } - Value::Object(record) - }) - .collect(), - ) - } - Value::Object(object) => Value::Object( - object - .iter() - .map(|(key, value)| (key.clone(), expand(value, tables, before))) - .collect(), - ), - Value::Array(items) => Value::Array( - items - .iter() - .map(|value| expand(value, tables, before)) - .collect(), - ), - value => value.clone(), - } -} From 7ea43884b5949d07e07c20b7d6906460b9388483 Mon Sep 17 00:00:00 2001 From: Manush Murali Date: Tue, 10 Nov 2026 14:07:38 -0800 Subject: [PATCH 04/12] Hold every session word to the untrusted-expression rule Only current_user was checked once the expression vectors went, so dropping session_user, current_role or localtimestamp from the session words would let an untrusted view read session identity or the clock without failing a test. List all thirteen, in both dialects. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Manush Murali --- rust/crates/sdm-data/tests/view_expr.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rust/crates/sdm-data/tests/view_expr.rs b/rust/crates/sdm-data/tests/view_expr.rs index 9cf22ec33..b8904ab5d 100644 --- a/rust/crates/sdm-data/tests/view_expr.rs +++ b/rust/crates/sdm-data/tests/view_expr.rs @@ -87,7 +87,20 @@ fn pure_calls_are_allowed_but_user_code_and_session_values_require_trust() { "secret('scope', 'key')", "custom_function(x)", "db.custom_function(x)", + "current_catalog", + "current_database", + "current_date", + "current_path", + "current_role", + "current_schema", + "current_time", + "current_timestamp", "current_user", + "localtime", + "localtimestamp", + "session_user", + "user", + "x + CURRENT_USER", ] { let verdict = view_expr::expression_verdict(expr, dialect, false, &["x"], spaces()).unwrap(); From 5a210e0fdcd4c74307cd98224f05ac7ad4d5ae29 Mon Sep 17 00:00:00 2001 From: Manush Murali Date: Tue, 10 Nov 2026 14:08:19 -0800 Subject: [PATCH 05/12] Run contract/tests against the Postgres service contract/tests runs only in contract-python (pandas3, duckdb), which had no Postgres DSN, so every @postgres case in it skipped. With the fixture cleanup those cases became the only check of their PostgreSQL expectations, and one of them was wrong without CI noticing. Give the job the shared service and require it for that step. Locally, against PostgreSQL 16: 2,483 passed; the one failure is the service-version check, which wants CI's 17. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Manush Murali --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 194c48bd7..e37cb2edc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -830,6 +830,8 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 needs: [configuration, native-wheel, native-test-ops] + services: + postgres: *postgres-service env: CELL: ref-pandas3 CELL_PINS: pandas==3.0.6 pyarrow==25.0.1 numpy==2.5.3 @@ -872,6 +874,9 @@ jobs: "$RUNNER_TEMP/kit/bin/python" -I -c 'import sdm_client._native as n; assert n.TEST_OPS' echo "SDM_KIT_PYTHON=$RUNNER_TEMP/kit/bin/python" >> "$GITHUB_ENV" - name: The runner's controls and the route tests + env: + SDM_POSTGRES_TEST_DSN: postgresql://postgres:postgres@localhost:5432/sdm_test + SDM_REQUIRE_POSTGRES: '1' run: python -m pytest contract/tests -q -m 'not tooling' -n auto --dist loadfile --timeout=600 --max-worker-restart=0 # Observe the installed native client in each supported dependency cell. - &contract-gate From 5ab95181923b739d080c143ba13414c65484417f Mon Sep 17 00:00:00 2001 From: Manush Murali Date: Tue, 10 Nov 2026 14:08:54 -0800 Subject: [PATCH 06/12] Pin the Databricks seed CTE for each key type The keyed-read check looked only for "posexplode(from_json(?, 'array<", so rendering int64 keys as array (read as 32-bit) passed every test once the goldens went; the Python Databricks fakes replace that CTE before running the read. Assert the whole CTE for bigint, double and string keys and for a windowed neighbor's struct. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Manush Murali --- .../crates/sdm-data/tests/databricks_plans.rs | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/rust/crates/sdm-data/tests/databricks_plans.rs b/rust/crates/sdm-data/tests/databricks_plans.rs index 432bc6e55..39443c2d2 100644 --- a/rust/crates/sdm-data/tests/databricks_plans.rs +++ b/rust/crates/sdm-data/tests/databricks_plans.rs @@ -127,12 +127,30 @@ fn qualified_identifiers_preserve_each_part_and_escape_backticks() { #[test] fn keyed_reads_unpack_the_bound_json_parameter_by_position() { - for kind in ["lookup", "neighbors"] { + let cte = |columns: &str, element: &str| { + format!( + "WITH TMP AS (\n SELECT CAST(pos AS BIGINT) AS `batch`, {columns}\n FROM posexplode(from_json(?, 'array<{element}>'))\n)\n" + ) + }; + let cases = [ + ("lookup", "int64", cte("col AS `key`", "bigint")), + ("lookup", "float64", cte("col AS `key`", "double")), + ("lookup", "utf8", cte("col AS `key`", "string")), + ( + "neighbors", + "int64", + cte( + "col.id AS `key`, col.e AS `end`", + "struct", + ), + ), + ]; + for (kind, key_type, expected) in cases { let mut input = serde_json::json!({ "request":kind,"table":{"source":["main","shop","users"]}, "key":["id"],"columns":["id","at"], "seeds":{"attachment":7,"columns":[ - {"name":"key","nullable":false,"type":{"type":"int64"}}, + {"name":"key","nullable":false,"type":{"type":key_type}}, {"name":"batch","nullable":false,"type":{"type":"int64"}} ]} }); @@ -157,11 +175,10 @@ fn keyed_reads_unpack_the_bound_json_parameter_by_position() { assert_eq!(bound.len(), 1); let statement = bound[0]; assert!( - statement.text.contains("posexplode(from_json(?, 'array<"), - "{}", + statement.text.starts_with(&expected), + "{kind} {key_type}: {}", statement.text ); - assert!(statement.text.contains("key") && statement.text.contains("batch")); let SqlParam::KeySet { keys, .. } = &statement.params[0] else { panic!("key parameter") }; From 08d14e43881092deff95e59a2e4b70ab7f7a420e Mon Sep 17 00:00:00 2001 From: Manush Murali Date: Tue, 10 Nov 2026 14:11:32 -0800 Subject: [PATCH 07/12] Word every view-expression refusal reason exactly With view-expr-vectors.json gone, only five of the expression refusal reasons kept their user-facing wording under test; the session-value, SQL-keyword, parenthesis, qualified, quoted-name, IDENTIFIER() and Databricks-quote reasons could be reworded silently. Pin one example of each, with the wording 1.0.0 gave it. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Manush Murali --- rust/crates/sdm-core/tests/view_words.rs | 82 ++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/rust/crates/sdm-core/tests/view_words.rs b/rust/crates/sdm-core/tests/view_words.rs index dbd743c77..0866c4610 100644 --- a/rust/crates/sdm-core/tests/view_words.rs +++ b/rust/crates/sdm-core/tests/view_words.rs @@ -216,6 +216,88 @@ fn unsafe_text_and_untrusted_calls_are_worded_by_name() { ); } +#[test] +fn every_expression_refusal_reason_keeps_its_wording() { + for (expr, dialect, expected) in [ + ( + "\u{1c}select\u{1c}1", + None, + "it contains the SQL keyword 'select'", + ), + ("x --", None, "it contains '--'"), + ("x)", None, "it closes a '(' it never opened"), + ("(x", None, "it leaves a '(' unclosed"), + ( + "a$$ + secret(x) + b$$", + None, + "it leaves '$$' unpaired, so which part of it is quoted text cannot be established", + ), + ( + "$$x$$", + Some(ExprDialect::Databricks), + "it contains '$$', which Databricks SQL does not quote with", + ), + ( + "\"MY\\COL\" * 2", + Some(ExprDialect::Snowflake), + "it has a backslash inside a double-quoted name", + ), + ] { + let reason = view_expr::unsafe_reason(expr, dialect, spaces()) + .map(|r| view_words::expr_reason(&r, dialect_words(&r))); + assert_eq!(reason.as_deref(), Some(expected), "{expr:?}"); + } + let wide = ["a", "col", "d", "name", "order_date", "x", "y", "z"]; + for (expr, dialect, columns, expected) in [ + ( + "cat.sch.f(x)", + ExprDialect::Databricks, + &wide[..], + "it calls the qualified function 'f'", + ), + ( + "`f`(x)", + ExprDialect::Databricks, + &wide[..], + "it calls a function by a quoted name", + ), + ( + "a[0](x)", + ExprDialect::Databricks, + &wide[..], + "it calls the result of an expression", + ), + ( + "identifier(x)", + ExprDialect::Databricks, + &["x"][..], + "it names a function through IDENTIFIER()", + ), + ( + "user", + ExprDialect::Databricks, + &["x"][..], + "it reads the session value 'user'", + ), + ( + "`user`", + ExprDialect::Databricks, + &["x"][..], + "it reads the session value `user`", + ), + ( + "\"user\"", + ExprDialect::Snowflake, + &["x"][..], + "it reads the session value \"user\"", + ), + ] { + let reason = view_expr::untrusted_call_reason(expr, dialect, columns, spaces()) + .map(|r| view_words::expr_reason(&r, dialect_words(&r))); + assert_eq!(reason.as_deref(), Some(expected), "{expr:?}"); + } +} + #[test] fn yaml_defaults_have_explicit_values_and_refusals() { for (kind, input, expected) in [ From de8e01206d0a8294fe1af2200235f01d6ec35f65 Mon Sep 17 00:00:00 2001 From: Manush Murali Date: Tue, 10 Nov 2026 14:12:20 -0800 Subject: [PATCH 08/12] Hold column-name refusals to their whole message The fragment list dropped the typo diagnostic's "row 1, column 12" position and the rest of each sentence, so either could change for an unusual column name without failing. Compare every scenario's message with its kind's full wording, the query text substituted, as the ordinary-name twins gave it. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Manush Murali --- .../tests/test_column_name_diagnostics.py | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/contract/tests/test_column_name_diagnostics.py b/contract/tests/test_column_name_diagnostics.py index ac91cf81a..b0bd234c8 100644 --- a/contract/tests/test_column_name_diagnostics.py +++ b/contract/tests/test_column_name_diagnostics.py @@ -37,6 +37,27 @@ def _module(name: str, path: Path) -> ModuleType: ROOT / 'contract/support/column_name_scenarios.py', ) +MESSAGES = { + 'task': ( + "[INVALID_REQUEST] task='regression' settles what a single-table " + 'question is asking, which is the only route that has to decide. A ' + 'relational query resolves to its own kind, so state it in the ' + 'query rather than beside it' + ), + 'typo': ( + "[INVALID_REQUEST] '' is not a query a relational model can " + "answer: row 1, column 12: Column 'pricee' does not exist in table " + "'orders'. Please be mindful of case sensitivity and ensure that the " + 'name is spelled correctly.' + ), + 'parts': ( + '[INVALID_REQUEST] 2 forecast steps means 2 calls, one for each, ' + 'because the model has no task that answers them together. That is ' + 'past the 1 this will do without being told to; ask about fewer, or ' + 'raise sdm_client.decompose.MOST_PARTS if the wait is what you want.' + ), +} + def reachable(database: str) -> bool: if database != 'postgres' or os.environ.get('SDM_POSTGRES_TEST_DSN'): @@ -59,25 +80,6 @@ def test_column_names_preserve_actionable_diagnostics(vector) -> None: 'StructuredDataError', 'INVALID_REQUEST', ) - fragments = { - 'task': [ - "task='regression'", - 'single-table', - 'relational query', - 'state it in the query', - ], - 'typo': [ - vector['pql'], - "Column 'pricee' does not exist in table 'orders'", - 'case sensitivity', - 'spelled correctly', - ], - 'parts': [ - '2 forecast steps means 2 calls', - 'past the 1 this will do', - 'ask about fewer', - 'raise sdm_client.decompose.MOST_PARTS', - ], - } - for fragment in fragments[vector['kind']]: - assert fragment in got['message'] + assert got['message'] == MESSAGES[vector['kind']].replace( + '', vector['pql'] + ) From 3f389d0c6be817a9d9978be6018d9284f11a989f Mon Sep 17 00:00:00 2001 From: Manush Murali Date: Tue, 10 Nov 2026 14:13:15 -0800 Subject: [PATCH 09/12] Compare the sampler and time-column warnings word for word The rewrite kept a count and a few substrings of each labelled warning, so the context-before-data, anchor-after-data, missing-index and guessed-time-column sentences could be reworded without a failure; no other test holds them. Assert each one whole, as the 1.0.0 recordings did. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Manush Murali --- contract/tests/test_public_error_messages.py | 55 +++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/contract/tests/test_public_error_messages.py b/contract/tests/test_public_error_messages.py index 65f4205c4..97ff11959 100644 --- a/contract/tests/test_public_error_messages.py +++ b/contract/tests/test_public_error_messages.py @@ -349,24 +349,33 @@ def test_public_warnings_name_source_bounds_and_index_requirements( assert len(warnings) == count, (case_key, label, got['warnings']) if not count: return - message = warnings[0][1] - if label == 'context-before-data': - bounds = ( - ('2023-12-03', '2024-01-01') - if case_id == 'shape.star.customers' - else ('2022-12-31', '2023-01-01') - ) - assert all(bound in message for bound in bounds), message - elif label == 'anchor-after-data': - assert '2030-01-01' in message and '2024-07-07' in message - elif label == 'missing-indices': - counts = ('7', '4') if case_id == 'shape.star.customers' else ('3', '2') - assert ( - f'Missing {counts[0]} indices in {counts[1]} tables' in message - ), message - assert 'primary' in message and 'foreign' in message, message - else: - assert message == 'overflow encountered in cast' + star = case_id == 'shape.star.customers' + expected_message = { + 'context-before-data': ( + 'Context anchor timestamp is too early or aggregation time range ' + 'is too large. To form proper input data, we would need data back ' + "to '{}', however, your data only contains data back to '{}'." + ).format( + *( + ('2023-12-03 00:00:00', '2024-01-01 00:00:00') + if star + else ('2022-12-31 00:00:00', '2023-01-01 00:00:00') + ) + ), + 'anchor-after-data': ( + "Anchor timestamp '2030-01-01 00:00:00' is after the latest " + "timestamp '2024-07-07 00:00:00' in the data. Please make sure " + 'this is intended.' + ), + 'missing-indices': ( + 'Missing {} indices in {} tables for optimal database querying. ' + 'For improving runtime, we strongly suggest to create indices for ' + 'primary and foreign keys, e.g., automatically by instantiating ' + 'Kumo Relational via `KumoRelational(graph, optimize=True)`.' + ).format(*((7, 4) if star else (3, 2))), + 'runtime-warning': 'overflow encountered in cast', + }[label] + assert warnings[0][1] == expected_message @pytest.mark.parametrize('name', sorted(INFINITY_SHOWN)) @@ -383,8 +392,14 @@ def test_infinite_timestamp_bounds_have_actionable_warning(name: str) -> None: warning for warning in got['warnings'] if 'time column' in warning[1] ] assert len(guessed) == 1 - assert guessed[0][0] == 'SDMWarning' - assert INFINITY_SHOWN[name] in guessed[0][1] + assert guessed[0] == [ + 'SDMWarning', + 'Some time columns were inferred, or refused, on a guess about what ' + 'a column holds:\n- events.f was not taken as the time column because ' + f'every row that holds a value holds {INFINITY_SHOWN[name]}. If it ' + 'does say when a row became true, name it: ' + "time_columns={'events': 'f'}.", + ] def test_diagnostic_cases_and_connector_selectors_are_complete() -> None: From cf22ed488a6bfa77b1449fe4eb3a3548007a0707 Mon Sep 17 00:00:00 2001 From: Manush Murali Date: Tue, 10 Nov 2026 14:13:53 -0800 Subject: [PATCH 10/12] Require an inner join in Snowflake keyed reads The lookup and neighbor checks only looked for the JOIN target, so a LEFT JOIN, which returns an all-null row for a seed key the table lacks, passed every test once the recorded statements went. Require "FROM TMP JOIN" in every keyed read and compare the plain lookup's whole statement. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Manush Murali --- rust/crates/sdm-testkit/tests/snowflake.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rust/crates/sdm-testkit/tests/snowflake.rs b/rust/crates/sdm-testkit/tests/snowflake.rs index 0b3c63005..f62743d6d 100644 --- a/rust/crates/sdm-testkit/tests/snowflake.rs +++ b/rust/crates/sdm-testkit/tests/snowflake.rs @@ -1194,6 +1194,10 @@ fn assert_bound_payload(sent: &[(String, String, Vec)], payload: &str) - let sql = sent[0].0.split_whitespace().collect::>().join(" "); assert!(sql.contains("f.index as __KUMO_BATCH__")); assert!(sql.contains("FLATTEN(INPUT => PARSE_JSON(?))")); + assert!( + sql.contains("FROM TMP JOIN \"{catalog}\".\"{schema}\"."), + "{sql}" + ); assert!(sql.contains("ON \"user_id\" = TMP.__KUMO_ID__")); sql } @@ -1313,6 +1317,15 @@ fn lookup_preserves_seed_identity_and_duplicate_policy() { sql.contains("COUNT(*) OVER (PARTITION BY TMP.__KUMO_BATCH__) AS \"__kumo_matches__\""), count ); + if !qualify && !count { + assert_eq!( + sql, + "WITH TMP as ( SELECT f.index as __KUMO_BATCH__, f.value::NUMBER as __KUMO_ID__ \ + FROM TABLE(FLATTEN(INPUT => PARSE_JSON(?))) f ) \ + SELECT TMP.__KUMO_BATCH__ as __KUMO_BATCH__, \"user_id\", \"age\", \"country\" \ + FROM TMP JOIN \"{catalog}\".\"{schema}\".\"users\" ON \"user_id\" = TMP.__KUMO_ID__" + ); + } } } From d5ab325d1c3ef3521f003eb93e608d8ff2aaa3aa Mon Sep 17 00:00:00 2001 From: Manush Murali Date: Tue, 10 Nov 2026 14:14:58 -0800 Subject: [PATCH 11/12] Compare the decimal case's whole public schema again The rewrite checked only orders.d's dtype and stype, so the other columns' types, the keys, the time column and the link could change on any database without failing. Assert the whole schema on DuckDB, SQLite and PostgreSQL, as the recorded expectation did. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Manush Murali --- contract/tests/test_decimal_semantic_types.py | 56 +++++++++++++------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/contract/tests/test_decimal_semantic_types.py b/contract/tests/test_decimal_semantic_types.py index 31b0541e8..a4294235d 100644 --- a/contract/tests/test_decimal_semantic_types.py +++ b/contract/tests/test_decimal_semantic_types.py @@ -51,15 +51,6 @@ def case() -> tuple[dict[str, Any], str]: return loaded, digest -def column_d(line: dict[str, Any]) -> dict[str, Any]: - r"""``orders.d`` in a line's public schema.""" - [orders] = [ - t for t in line['public']['schema']['tables'] if t['name'] == 'orders' - ] - [d] = [c for c in orders['columns'] if c['name'] == 'd'] - return d - - def test_the_case_is_a_scaled_decimal_past_float64() -> None: r"""The case is what it names: one setup statement adding ``orders.d``, a ``DECIMAL(38, 18)`` stepping by 1e-18 over the shop base's 80 orders, @@ -129,10 +120,43 @@ def test_decimal_column_has_connector_specific_semantic_type( assert 'describe_source' in line['identity']['operations'] assert line['outcome']['result'] == 'success' assert line['outcome']['stage'] == 'from_source' - expected = ( - {'dtype': 'string', 'stype': 'text'} - if database == 'sqlite' - else {'dtype': 'float64', 'stype': 'categorical'} - ) - column = column_d(line) - assert {name: column[name] for name in expected} == expected + sqlite = database == 'sqlite' + + def column(name: str, dtype: str, stype: str) -> dict[str, str]: + return {'dtype': dtype, 'name': name, 'stype': stype} + + assert line['public']['schema'] == { + 'links': [['orders', 'user_id', 'users', 'user_id']], + 'tables': [ + { + 'columns': [ + column('order_id', 'int64', 'ID'), + column('user_id', 'int64', 'ID'), + column('price', 'float64', 'numerical'), + column( + 'ts', + 'string' if sqlite else 'timestamp[us]', + 'timestamp', + ), + column('d', 'string', 'text') + if sqlite + else column('d', 'float64', 'categorical'), + ], + 'duplicate_keys': 0, + 'name': 'orders', + 'primary_key': 'order_id', + 'time_column': 'ts', + }, + { + 'columns': [ + column('user_id', 'int64', 'ID'), + column('age', 'int64', 'numerical'), + column('country', 'string', 'categorical'), + ], + 'duplicate_keys': 0, + 'name': 'users', + 'primary_key': 'user_id', + 'time_column': None, + }, + ], + } From 156389b28b7065f7b4c432c7b61cff6e91e3a88a Mon Sep 17 00:00:00 2001 From: Adi Wadaskar Date: Wed, 11 Nov 2026 03:04:03 +0000 Subject: [PATCH 12/12] Test Snowflake comment refusal wording Signed-off-by: Adi Wadaskar --- rust/crates/sdm-core/tests/view_words.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rust/crates/sdm-core/tests/view_words.rs b/rust/crates/sdm-core/tests/view_words.rs index 0866c4610..b2fbd064a 100644 --- a/rust/crates/sdm-core/tests/view_words.rs +++ b/rust/crates/sdm-core/tests/view_words.rs @@ -225,6 +225,11 @@ fn every_expression_refusal_reason_keeps_its_wording() { "it contains the SQL keyword 'select'", ), ("x --", None, "it contains '--'"), + ( + "X FROM PAYROLL //", + Some(ExprDialect::Snowflake), + "it contains '//'", + ), ("x)", None, "it closes a '(' it never opened"), ("(x", None, "it leaves a '(' unclosed"), (