test: integration tests for the NL→SQL query pipeline#19
Merged
Conversation
Run execute_nl_query / execute_raw_sql end-to-end through the real agents (composer, validator, error handler, interpreter), prompt plumbing, policy masking/limits, and audit/cost recording — faking only the process edges (scripted LLM provider, scripted connector, fake DB session, pre-built semantic context). Covers the happy path, validation repair, the 3-retry bound with unsafe SQL blocked + audited, execution-error retries, retry exhaustion, policy column masking reaching neither the response nor the interpreter prompt, and raw-SQL safety blocking. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds integration tests for the core NL→SQL query pipeline (
execute_nl_query/execute_raw_sql), exercising the real composer, validator, error-handler, and interpreter agents end-to-end.Why
The query pipeline — the product's core loop — had no test coverage: the retry logic, safety gates, policy enforcement, and audit/cost recording could all regress silently on refactor. These tests pin that behavior while staying fast and dependency-free (no live DB or LLM), consistent with the existing suite.
Changes
backend/tests/test_query_pipeline.py(10 tests, no new dependencies):FakeLLMProvider(records every prompt), a scriptedFakeConnector, a minimalFakeSession, and a pre-builtBuiltContext— everything in between runs real code, including prompt templates, JSON repair/parsing, policy masking/limits, and audit/cost writes.query.executedaudit event, cost attribution, and connection limits passed to the connector.retry_count == 1).query.blocked, and never reaches the database; a handler that gives up yields 422.🤖 Generated with Claude Code