Skip to content
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8784160
Add super plan for #268: scope=sample for ingested dbt tests via sqlg…
wjduenow Jul 13, 2026
2140d19
#268: mark plan phase published
wjduenow Jul 13, 2026
303de32
#268: devolve plan to beads (epic bd_1-scaffolding-ivr, 11 tasks)
wjduenow Jul 13, 2026
252add4
bd_1-scaffolding-ivr.1: harden ingest sqlglot gates (#268 US-001)
wjduenow Jul 13, 2026
3a82480
Merge bead bd_1-scaffolding-ivr.1: #268 US-001 — harden ingest sqlglo…
wjduenow Jul 13, 2026
f4709cd
bd_1-scaffolding-ivr.2: sqlglot relation locate + rewrite verificatio…
wjduenow Jul 13, 2026
98b9da9
Merge bead bd_1-scaffolding-ivr.2: #268 US-002 — sqlglot relation loc…
wjduenow Jul 13, 2026
5cd7d58
bd_1-scaffolding-ivr.3: compiler ingested-arm rewrite + fail-closed g…
wjduenow Jul 13, 2026
905bab4
Merge bead bd_1-scaffolding-ivr.3: #268 US-003 — compiler ingested-ar…
wjduenow Jul 13, 2026
16adbe3
bd_1-scaffolding-ivr.4: engine routing for sampled ingested tests (#2…
wjduenow Jul 13, 2026
9a7bfb3
Merge bead bd_1-scaffolding-ivr.4: #268 US-004 — engine routing for s…
wjduenow Jul 13, 2026
4fe0d64
bd_1-scaffolding-ivr.5: audit bypassed_to_source + compiled_sql trunc…
wjduenow Jul 13, 2026
04e5d26
Merge bead bd_1-scaffolding-ivr.5: #268 US-005 — audit bypassed_to_so…
wjduenow Jul 13, 2026
f14324d
bd_1-scaffolding-ivr.6: ingested-routing INFO + per-test DEBUG (#268 …
wjduenow Jul 13, 2026
95e496a
Merge bead bd_1-scaffolding-ivr.6: #268 US-006 — ingested-routing INF…
wjduenow Jul 13, 2026
3411b8b
bd_1-scaffolding-ivr.7: behavioural routing pins + ungated sqlglot pa…
wjduenow Jul 13, 2026
0acc8b4
Merge bead bd_1-scaffolding-ivr.7: #268 US-007 — behavioural routing …
wjduenow Jul 13, 2026
5155245
bd_1-scaffolding-ivr.8: gated BigQuery live cert for sampled ingested…
wjduenow Jul 13, 2026
605ed7a
Merge bead bd_1-scaffolding-ivr.8: #268 US-008 — gated BigQuery live …
wjduenow Jul 13, 2026
dc88a8c
bd_1-scaffolding-ivr.9: docs + CHANGELOG for sampled ingested tests (…
wjduenow Jul 13, 2026
c239989
Merge bead bd_1-scaffolding-ivr.9: #268 US-009 — docs + CHANGELOG
wjduenow Jul 13, 2026
e84126d
bd_1-scaffolding-ivr.10: Quality gate — fix bugs from code review
wjduenow Jul 13, 2026
3ca1c19
bd_1-scaffolding-ivr.11: Patterns & Memory — reconcile rules for #268
wjduenow Jul 13, 2026
026cea6
#268: Address PR review feedback (CodeRabbit + Copilot)
wjduenow Jul 14, 2026
bc870f0
#268: Address PR review feedback (CodeRabbit follow-up)
wjduenow Jul 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .claude/rules/business-rule-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,23 @@ variant WITHOUT a 7th-type extension — the differentiator is a per-candidate
- **Ingested tests are READ-ONLY** — they appear on the kept/dropped/flagged table, NEVER as
`proposed_test_files` (we didn't author them). `prune-existing` passes `render_diff(emit_test_files=False)`
unconditionally. Macro identity rides the synthesized rationale → diff `why` (DEC-015 of #154).
- **Full-scope only in pass 1** (`scope=sample` deferred, #268); dbt-expectations' `validation_errors`
wrapper makes even its `expect_table_row_count` macro row-returning/prunable.
- **`scope=sample` for ingested tests — LANDED (#268).** A batch of **≥2** samplable ingested bodies
under `sample_strategy=materialised` now rewrites the model's own relation in dbt's foreign-rendered
`compiled_code` to the `_SESSION._sf_sample_*` temp via sqlglot AST **locate** (`plan_relation_rewrite`
in `ingest/_compiled_sql`) + a byte-preserving **token splice** in the compiler (`_build_ingested_rewrite`,
no `import sqlglot` under `prune/`). `oneshot` still routes to source (the CTE approach it would need
failed on execution — sqlglot can't prepend a CTE). A #267 count-of-rows scalar is an **aggregate** →
stays at source (Direction-2). dbt-expectations' `validation_errors` wrapper makes the macro
row-returning, so those DO sample. **The Direction-1/2 rule is the load-bearing frame for the split:**
a `validation_errors`-shell body is row-level (sample it), a count scalar is metadata (keep at source);
the classifier answer is carried per-candidate in an `_IngestedSamplePlan`, and BOTH engine routing sites
(`all_bypass_to_source` + `per_test_table_ref`) read it (the #170 two-conditional rule). See
`prune-engine.md` § "Sampled manifest-ingested tests (#268)". **A count is NOT an integrity proof** — the
rewrite is gated by an AST **post-condition** on the *rewritten* SQL (`verify_relation_rewrite`: parses
clean, ZERO residual source-relation tables, exactly N temp tables), because `ast_match_count ==
span_count` is defeatable (a column-qualifier span leaves the `FROM` on production; a dotted CTE alias
shadows the relation) and either defeat silently DELETES a real test. Live-certified against BigQuery
(`tests/cli/test_e2e_bigquery_ingested_sample.py`).
- **Count-of-rows scalar bodies now graduate (#267, LANDED).** A bare `SELECT count(*) …` scalar body
(`COUNT(*)`/`COUNT(col)`/`COUNT(DISTINCT)`) is detected by `is_prunable_count_scalar` (a new
`ingest/_compiled_sql` sqlglot classifier) and pruned, not skip-recorded. The compiler restructures it
Expand Down
26 changes: 24 additions & 2 deletions .claude/rules/ingest-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,18 @@ prune gate for dbt-expectations / dbt-utils / in-house generic tests (Architectu
(`Field(default=False, exclude=True)`) distinguishes ingested-from-drafted downstream WITHOUT a
schema/audit bump (`exclude=True` keeps `candidate_hash` byte-identical — guard that invariant
with an explicit test; a mutation dropping it passed the whole suite at QG time).
- **Four-gate classification, all reusing `signalforge.ingest._compiled_sql` (sqlglot-AST):**
- **Five-gate classification, all reusing `signalforge.ingest._compiled_sql` (sqlglot-AST):**
**size cap** (`len(compiled_code.encode()) ≤ 256 KiB = `_COMPILED_CODE_SIZE_LIMIT_BYTES`, checked
BEFORE any parse; #268 — there is NO other cap on the manifest path, and an unbounded body would
reach sqlglot; over-cap → skip-record via the existing `malformed-supported-test` reason) →
presence (`compiled_code` non-null) → `is_row_returning` (skip bare-scalar `SELECT COUNT(*)`;
DEC-004) → `is_deterministic_sql` (skip `TABLESAMPLE`/`RAND`/`CURRENT_TIMESTAMP`/…; DEC-012) →
`validate_ingested_sql` (comment-tolerant safety scan; DEC-013). **Regex/substring is unsafe
`validate_ingested_sql` (comment-tolerant safety scan; DEC-013). **The three AST helpers are TOTAL
over hostile input (#268):** each catches `RecursionError` + `ValueError` alongside
`sqlglot.errors.SqlglotError` (a ~2000-deep nested-paren body raises `RecursionError` — NOT a
`SqlglotError` — and a bad `dialect=` raises `ValueError`; either escaping aborted the WHOLE prune
run with no audit rows). `read_manifest_tests` threads the active `dialect=` into every gate (was
hardcoded `"bigquery"`, which could disagree with the compiler's `dialect.name`). **Regex/substring is unsafe
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
here — a column named `random_id` false-positives; use AST.** NOTE: dbt-expectations wraps
EVERY macro (incl. `expect_table_row_count_to_be_between`) in a row-returning `validation_errors`
shell, so those ARE prunable. **Post-#267 the row-returning gate no longer skip-records a bare
Expand All @@ -113,3 +121,17 @@ prune gate for dbt-expectations / dbt-utils / in-house generic tests (Architectu
- **Stage-0 preserved.** No logging, no warehouse/LLM calls, no SQL building, no `bigquery` import.
The `_compiled_sql` helpers are self-contained (they do NOT import the warehouse `_strip_string_literals`
private — a QG fix; a stage-0 reader must not couple to another layer's `_`-internal).
- **Relation-locate helpers for `scope=sample` (#268) — ANALYSIS only, no SQL emitted.**
`plan_relation_rewrite(sql, *, relation, dialect) -> RewritePlan` parses `compiled_code`, resolves scopes
via `sqlglot.optimizer.scope`, `normalize_identifiers`-folds both sides, **exact-full-tuple**-matches the
model's own relation (never suffix — a bare `orders` would false-positive), enforces a **single physical
relation** on the AST (a JOIN/comma-join/correlated-subquery/`NOT EXISTS` is refused — the compiler's
`_JOIN_RE` regex misses those), refuses a **CTE-alias collision** (a dotted alias
`` `proj.ds.tbl` `` normalises to a Table tuple matching the relation), and returns **character spans**
(`Token.start`/`.end`, inclusive end) for the compiler to splice. It always returns a frozen `RewritePlan`
(never `None`) so a machine-readable reject `reason` (∈ `RELATION_REWRITE_REASONS`) can ride along for the
DEC-014 histogram. `verify_relation_rewrite(rewritten_sql, *, source, temp, expected_n, dialect) -> bool`
is the integrity **post-condition** (parses clean, ZERO residual source tables, exactly N temp tables) —
**a count is not a proof.** These keep sqlglot in ingest (locate) and out of `prune/` (splice); the
compiler stays a consumer, so the 2-importer confinement holds. Full contract:
`prune-engine.md` § "Sampled manifest-ingested tests (#268)".
10 changes: 10 additions & 0 deletions .claude/rules/llm-drafter.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,13 @@ did not render itself (regex false-positives on a `random_id` column; a scalar w
remains documented, not gated); `tests/prune/test_compiler_import_guard.py` still passes (it forbids
`google.cloud`/`snowflake` under `prune/`, not sqlglot). If a FOURTH sqlglot importer lands, promote
the convention to a real confinement scan.

**#268 deliberately stayed at 2 importers.** Sampling manifest-ingested tests needed sqlglot AST
relation-rewriting — the exact "hardest sqlglot component" the ticket flagged — but the work split
**locate-in-ingest / splice-in-compiler**: `signalforge.ingest._compiled_sql` grew the analysis helpers
(`plan_relation_rewrite` / `verify_relation_rewrite`, both parse-and-return-data), and
`signalforge.prune.compiler` did the rewrite as a **pure string splice** over the returned character
spans — no `import sqlglot`. So the compiler stayed a CONSUMER, no 4th importer landed, and no confinement
scan is owed. This is the reusable answer whenever a `prune/`-side transform needs sqlglot: put the parse
in ingest (stage-0 analysis, returns spans/verdicts), keep the string emission in the compiler. Verified
by `grep -rn '^import sqlglot\|^from sqlglot' src/` → still only `draft/parser.py` + `ingest/_compiled_sql.py`.
Loading
Loading