---
phase: 66-expansion-qualification-adbc-tests
plan: 02
type: execute
wave: 2
depends_on:
  - 66-01
files_modified:
  - src/expand/sql_gen.rs
  - src/expand/semi_additive.rs
  - src/expand/window.rs
  - src/expand/materialization.rs
  - test/sql/phase57_introspection.test
  - test/integration/test_adbc_queries.py
autonomous: false
requirements:
  - EXPAND-CTX-01
  - EXPAND-CTX-02
must_haves:
  truths:
    - "Every `quote_table_ref(name)` emission in the four expand-path files at the lines listed in CONTEXT.md D-04 is replaced with `qualify_and_quote_table_ref(name, def)`."
    - "`build_materialized_sql` accepts `def: &SemanticViewDefinition` as a parameter and its sole caller `try_route_materialization` at materialization.rs:69 passes `def` through."
    - "`test/sql/phase57_introspection.test:76` expected output reads `FROM \"memory\".\"main\".\"p57_agg_region\"` (was `FROM \"p57_agg_region\"`)."
    - "`MIGRATION_LANDED` flag in `test/integration/test_adbc_queries.py` is flipped to `True` (or skip markers removed equivalently) so scenarios 3, 4, 5, 6, 7 run and PASS."
    - "Manual D-09 baseline evidence is recorded in the Plan 02 task verification: pre-migration `MIGRATION_LANDED = True` reproduces `Catalog Error: Table with name X does not exist!` for scenarios 3-7; post-migration the same scenarios PASS."
    - "`just test-all` returns 0; includes `cargo test`, `just test-sql` (with the updated fixture), and `just test-adbc-queries` (7/7 PASS, 0 SKIP)."
    - "D-06: `def: &SemanticViewDefinition` confirmed in scope at all 7 migration call sites — 6 directly via existing function signatures; the 7th (`build_materialized_sql`) via the one-line signature change threaded from `try_route_materialization` at materialization.rs:69."
    - "Architectural premise driving this migration (rationale-only; see CONTEXT.md): D-01 (per-call `Connection(*context.db)` borrows DatabaseInstance but does NOT inherit caller's ClientContext state — USE/search_path don't propagate); D-02 (unqualified `quote_table_ref` resolves only iff table lives in default catalog+schema; qualified form is correct across all contexts); D-03 (Phase 64 wired 3 sites; 7 remaining are incomplete Phase 64, not intentional asymmetry); D-05 (defense-in-depth completion — roadmap success scenarios all use `memory.main` so test-driven bounded migration would be a false-negative signal)."
  artifacts:
    - path: "src/expand/sql_gen.rs"
      provides: "Fact-query path emits fully-qualified table references at lines 181, 224, 244"
      contains: "qualify_and_quote_table_ref"
    - path: "src/expand/semi_additive.rs"
      provides: "Semi-additive metric inner subqueries emit fully-qualified table references at lines 195, 220, 238"
      contains: "qualify_and_quote_table_ref"
    - path: "src/expand/window.rs"
      provides: "Window metric inner subqueries emit fully-qualified table references at lines 156, 181, 199"
      contains: "qualify_and_quote_table_ref"
    - path: "src/expand/materialization.rs"
      provides: "Materialization routing target emits fully-qualified table reference at line 157; build_materialized_sql signature threads def"
      contains: "def: &SemanticViewDefinition"
    - path: "test/sql/phase57_introspection.test"
      provides: "Updated expected output line for materialization routing fixture"
      contains: "FROM \"memory\".\"main\".\"p57_agg_region\""
  key_links:
    - from: "src/expand/materialization.rs:69 (try_route_materialization)"
      to: "build_materialized_sql"
      via: "def threaded as second positional arg"
      pattern: "build_materialized_sql\\(\\s*&mat.table,\\s*def,"
    - from: "src/expand/materialization.rs build_materialized_sql"
      to: "qualify_and_quote_table_ref"
      via: "import from super::resolution + call at line 157"
      pattern: "qualify_and_quote_table_ref\\(table, def\\)"
    - from: "test/integration/test_adbc_queries.py scenarios 3-7"
      to: "qualified expand paths"
      via: "ADBC queries succeed once migration lands"
      pattern: "MIGRATION_LANDED = True"
    - from: "src/expand/materialization.rs:157 (qualified emission)"
      to: "test/sql/phase57_introspection.test:76 (expected output)"
      via: "in-same-commit fixture update"
      pattern: "FROM \"memory\".\"main\".\"p57_agg_region\""
---

<objective>
Complete the Phase 64 `qualify_and_quote_table_ref` migration across the remaining 7 sites in 4 expand-path files (EXPAND-CTX-01), update the sole affected sqllogictest fixture, and unlock Plan 01's skipped scenarios 3-7 in `test_adbc_queries.py` (EXPAND-CTX-02 fully green).

Purpose: Mechanical defense-in-depth completion of Phase 64. Every persisted semantic view has `database_name` and `schema_name` populated at CREATE time (`src/parse.rs:1928, 2058` inject `current_database()`/`current_schema()` via `json_merge_patch`), so the qualified helper always emits 3-part `"db"."schema"."name"` and resolves regardless of the per-call `Connection(*context.db)`'s default catalog/schema state. This eliminates the entire `Catalog Error: Table with name X does not exist` failure class on the ADBC path.

Output:
- 10 mechanical line replacements (`quote_table_ref(x)` → `qualify_and_quote_table_ref(x, def)`) across 4 files
- 1 function-signature change in `materialization.rs` (`build_materialized_sql`) + caller update
- 3 import-statement updates (`semi_additive.rs:30`, `window.rs:17`, `materialization.rs:11`)
- 1 sqllogictest fixture line update (`test/sql/phase57_introspection.test:76`)
- 1-line flag flip + skip-marker removal in `test/integration/test_adbc_queries.py`
- Recorded D-09 baseline evidence in task verification log
</objective>

<execution_context>
@$HOME/.claude/get-shit-done/workflows/execute-plan.md
@$HOME/.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/66-expansion-qualification-adbc-tests/66-CONTEXT.md
@.planning/phases/66-expansion-qualification-adbc-tests/66-RESEARCH.md
@.planning/phases/66-expansion-qualification-adbc-tests/66-VALIDATION.md
@.planning/phases/66-expansion-qualification-adbc-tests/66-01-SUMMARY.md

# Source of truth — the Phase 64 wired template (already in production)
@src/expand/sql_gen.rs

# Migration target files
@src/expand/semi_additive.rs
@src/expand/window.rs
@src/expand/materialization.rs

# Helper definitions — DO NOT modify; verify R-02 fallback semantics if needed
@src/expand/resolution.rs

# sqllogictest fixture
@test/sql/phase57_introspection.test

# Plan 01 test scaffolding — flip the flag here
@test/integration/test_adbc_queries.py

# Project rules — Rules 1 & 2 non-negotiable
@CLAUDE.md

<interfaces>
<!-- The migration template (already in production at src/expand/sql_gen.rs:498-499) -->

```rust
// Phase 64 wired site — pattern to apply at the 6 direct-scope sites:
sql.push_str("\nFROM ");
sql.push_str(&qualify_and_quote_table_ref(def.base_table(), def));
```

<!-- Helper signature (do not modify) -->
```rust
// src/expand/resolution.rs
pub(crate) fn qualify_and_quote_table_ref(name: &str, def: &SemanticViewDefinition) -> String;
```

<!-- materialization.rs — the one site needing a signature change -->
```rust
// Current (lines 132-152):
fn build_materialized_sql(table: &str, dims: &[&Dimension], mets: &[&Metric]) -> String { ... }

// Target signature:
fn build_materialized_sql(
    table: &str,
    def: &SemanticViewDefinition,
    dims: &[&Dimension],
    mets: &[&Metric],
) -> String { ... }

// Single caller at materialization.rs:69-73 — update positional arg list to pass `def`.
```

<!-- Existing imports -->
```rust
// src/expand/sql_gen.rs:7-8 — already imports both helpers; verify whether quote_table_ref is still used after migration.
// src/expand/semi_additive.rs:30 — current: use super::resolution::{quote_ident, quote_table_ref};
// src/expand/window.rs:17       — current: use super::resolution::{quote_ident, quote_table_ref};
// src/expand/materialization.rs:11 — current: use super::resolution::{quote_ident, quote_table_ref};
// Each needs to add (or replace) qualify_and_quote_table_ref in its use list.
```
</interfaces>
</context>

<tasks>

<\!--
  Note: 6 tasks intentional — the D-09 baseline-evidence checkpoint (Task 4) must occur
  BETWEEN the migration landing (Tasks 1-3) and the flag flip (Task 5) so that pre-migration
  failure evidence can be captured per CONTEXT.md D-09. Splitting this plan would break the
  evidence-sequencing requirement; see RESEARCH.md §R-04 + CONTEXT.md D-09.
-->

<task type="auto" tdd="true">
  <name>Task 1: Migrate 6 direct-scope sites (sql_gen.rs + semi_additive.rs + window.rs)</name>
  <files>src/expand/sql_gen.rs, src/expand/semi_additive.rs, src/expand/window.rs</files>
  <read_first>
    - src/expand/sql_gen.rs (lines 7-8 for imports; lines 181, 224, 244 for fact-query call sites; lines 498-499, 530, 550 for the wired template — source of truth)
    - src/expand/semi_additive.rs (line 30 for imports; lines 195, 220, 238 for call sites; surrounding function signatures to confirm `def: &SemanticViewDefinition` is in scope)
    - src/expand/window.rs (line 17 for imports; lines 156, 181, 199 for call sites; surrounding function signatures)
    - src/expand/resolution.rs (helper definitions; do not modify)
    - .planning/phases/66-expansion-qualification-adbc-tests/66-RESEARCH.md §Migration Target Verification table (confirms `def` scope at each site)
  </read_first>
  <behavior>
    - At each of the 9 migration lines (sql_gen.rs:181, 224, 244 / semi_additive.rs:195, 220, 238 / window.rs:156, 181, 199), the emitted SQL string MUST contain the 3-part qualified form `"<db>"."<schema>"."<table>"` whenever `def.database_name` and `def.schema_name` are both `Some`.
    - The pre-existing 3 wired sites in sql_gen.rs (lines 499, 530, 550) remain unchanged in behaviour and structure.
    - Existing unit tests in `src/expand/sql_gen.rs::tests`, `src/expand/semi_additive.rs::tests`, `src/expand/window.rs::tests` continue to pass; any tests that exercise the migrated emission output may need expected-string updates to include the qualified prefix.
  </behavior>
  <action>
At each of the 9 sites listed in `<read_first>`, replace `quote_table_ref(<arg>)` with `qualify_and_quote_table_ref(<arg>, def)` where `<arg>` is whatever the existing argument is (`def.base_table()` or `physical_table` — preserve verbatim).

Import updates:
- `src/expand/semi_additive.rs:30`: change `use super::resolution::{quote_ident, quote_table_ref};` to `use super::resolution::{qualify_and_quote_table_ref, quote_ident};` (drop `quote_table_ref` if no remaining uses — verify via `grep -n quote_table_ref src/expand/semi_additive.rs` showing zero post-migration; if any remain, keep both in the use list).
- `src/expand/window.rs:17`: same pattern.
- `src/expand/sql_gen.rs:7-8`: file already imports both. After migration, run `grep -n quote_table_ref src/expand/sql_gen.rs` — if zero uses remain, drop `quote_table_ref` from the import; if any tests or other call sites still use it, keep.

If any existing unit test in these files asserts on the exact SQL string output and includes `FROM "table_name"` (unqualified), update the expected string to `FROM "<db>"."<schema>"."table_name"` reflecting the qualified emission. Use the test fixtures' `def` to determine the expected db/schema (typically `memory`/`main` in unit test fixtures). Run `cargo test -p semantic-views --lib` early to surface any such fixture mismatches.

Do NOT touch `materialization.rs` in this task — that's Task 2 (separate because it requires a signature change).

Per Pattern 1 in RESEARCH.md, this is a mechanical refactor. No new logic, no surrounding code changes, no helper additions.
  </action>
  <verify>
    <automated>cargo test -p semantic-views --lib > /tmp/claude/cargo_test_task1.log 2>&1; RC=$?; tail -80 /tmp/claude/cargo_test_task1.log; test "$RC" -eq 0</automated>
  </verify>
  <acceptance_criteria>
    - `grep -E "\bquote_table_ref\(" src/expand/sql_gen.rs src/expand/semi_additive.rs src/expand/window.rs | wc -l` returns `0` (no bare `quote_table_ref(` call sites remain in these three files; the qualified-helper call sites are matched by a different identifier and excluded by the word-boundary anchor).
    - `grep -cn "qualify_and_quote_table_ref(" src/expand/sql_gen.rs` returns `>= 6` (the 3 pre-existing + 3 new fact-query sites).
    - `grep -cn "qualify_and_quote_table_ref(" src/expand/semi_additive.rs` returns `3`.
    - `grep -cn "qualify_and_quote_table_ref(" src/expand/window.rs` returns `3`.
    - `cargo test -p semantic-views --lib` exits 0.
    - `cargo clippy --all-targets -- -D warnings > /tmp/claude/clippy_task1.log 2>&1; tail -40 /tmp/claude/clippy_task1.log` exits 0.
    - `cargo fmt --check > /tmp/claude/fmt_task1.log 2>&1; tail -20 /tmp/claude/fmt_task1.log` exits 0 (run `cargo fmt` first if needed; never `--no-verify`).
  </acceptance_criteria>
  <done>9 mechanical migrations applied across 3 files; imports cleaned up; `cargo test` + `clippy` + `fmt --check` all green.</done>
</task>

<task type="auto" tdd="true">
  <name>Task 2: Migrate materialization.rs:157 with build_materialized_sql signature change</name>
  <files>src/expand/materialization.rs</files>
  <read_first>
    - src/expand/materialization.rs (line 11 for imports; lines 28-78 for `try_route_materialization` and its call to `build_materialized_sql` at line 69; lines 132-159 for `build_materialized_sql` definition; lines 161+ for any unit tests that exercise `build_materialized_sql` directly)
    - src/expand/resolution.rs (helper definition)
    - .planning/phases/66-expansion-qualification-adbc-tests/66-RESEARCH.md §Pattern 2 (signature update template) + §Common Pitfalls Pitfall 1 (forget to thread `def`)
    - .planning/phases/66-expansion-qualification-adbc-tests/66-CONTEXT.md D-06 (this is the one site where `def` is NOT already in scope)
  </read_first>
  <behavior>
    - `build_materialized_sql(table, def, dims, mets)` accepts a 2nd positional `def: &SemanticViewDefinition` parameter inserted between `table` and `dims`.
    - The call site at `try_route_materialization` (line 69) passes `def` (which is its own 1st parameter) through to `build_materialized_sql`.
    - The emitted SQL at line 157 reads the qualified 3-part form `"<db>"."<schema>"."<table>"` whenever `def.database_name` and `def.schema_name` are `Some`.
    - Unit tests in `materialization.rs::tests` (if any exercise `build_materialized_sql` directly) compile against the new signature.
  </behavior>
  <action>
1. Update the import at `src/expand/materialization.rs:11`: replace with `use super::resolution::{qualify_and_quote_table_ref, quote_ident};` (drop `quote_table_ref` since `build_materialized_sql` is the only caller and we're migrating it).

2. Update `build_materialized_sql` signature (lines 132): insert `def: &SemanticViewDefinition` as the 2nd parameter:
   ```
   fn build_materialized_sql(
       table: &str,
       def: &SemanticViewDefinition,
       dims: &[&Dimension],
       mets: &[&Metric],
   ) -> String
   ```
   (The `SemanticViewDefinition` type is already imported at line 9: `use crate::model::{Dimension, Metric, SemanticViewDefinition};`.)

3. At line 157 inside the function body, replace `sql.push_str(&quote_table_ref(table));` with `sql.push_str(&qualify_and_quote_table_ref(table, def));`.

4. Update the caller at `materialization.rs:69-73`. Insert `def,` as the 2nd positional argument:
   ```
   return Some(build_materialized_sql(
       &mat.table,
       def,
       resolved_dims,
       resolved_mets,
   ));
   ```
   (`def` is the 1st parameter of `try_route_materialization` at line 28, so it's directly in scope.)

5. If `#[cfg(test)] mod tests` at the bottom of the file exercises `build_materialized_sql` directly with positional args, update each call site to pass a test `def` (likely already constructed via `orders_view()` helper from `test_helpers.rs` per the test imports at line 164). If the tests use a fixture like `orders_view()` that returns a `SemanticViewDefinition`, just thread it through; if they construct ad-hoc, use the same fixture.

6. After migration, run `grep -n quote_table_ref src/expand/materialization.rs` — should return zero hits.

Per Pitfall 1: the most common failure mode is forgetting step 4 (caller update). The Rust compiler will catch this with `expected 4 arguments, found 3` — if `cargo check` is green, the wiring is correct.
  </action>
  <verify>
    <automated>cargo test -p semantic-views --lib > /tmp/claude/cargo_test_task2.log 2>&1; RC=$?; tail -80 /tmp/claude/cargo_test_task2.log; test "$RC" -eq 0</automated>
  </verify>
  <acceptance_criteria>
    - `grep -n "quote_table_ref" src/expand/materialization.rs | grep -v "qualify_and_quote_table_ref"` returns no matches (the bare helper is no longer imported or called from this file).
    - `grep -n "fn build_materialized_sql" src/expand/materialization.rs` shows the new 4-param signature including `def: &SemanticViewDefinition`.
    - `grep -A 5 "build_materialized_sql($" src/expand/materialization.rs | grep -E "^\s*def," ` shows `def,` is passed as the 2nd positional arg at the call site.
    - `cargo check -p semantic-views > /tmp/claude/cargo_check_task2.log 2>&1; tail -20 /tmp/claude/cargo_check_task2.log` exits 0 (no parameter-count mismatch).
    - `cargo test -p semantic-views --lib` exits 0 (unit tests for materialization pass with updated signature).
    - `cargo clippy --all-targets -- -D warnings > /tmp/claude/clippy_task2.log 2>&1; tail -40 /tmp/claude/clippy_task2.log` exits 0.
    - `cargo fmt --check` exits 0.
  </acceptance_criteria>
  <done>materialization.rs:157 emits qualified form; signature accepts `def`; caller passes it through; all unit tests + clippy + fmt green.</done>
</task>

<task type="auto">
  <name>Task 3: Update phase57_introspection.test fixture expected output</name>
  <files>test/sql/phase57_introspection.test</files>
  <read_first>
    - test/sql/phase57_introspection.test (lines 72-76 — the affected assertion; lines 1-30 for setup context showing the view is created in memory.main)
    - .planning/phases/66-expansion-qualification-adbc-tests/66-RESEARCH.md §R-01 (confirms this is the SOLE affected sqllogictest line)
    - CLAUDE.md (sqllogictest block-form rule — not relevant here, this is a query assertion not a statement-error)
  </read_first>
  <action>
At `test/sql/phase57_introspection.test:76`, update the expected-output line:
- Before: `FROM "p57_agg_region"`
- After: `FROM "memory"."main"."p57_agg_region"`

The query at lines 73-74 is `SELECT explain_output FROM explain_semantic_view('p57_mat_view', ...) WHERE explain_output LIKE 'FROM%p57_agg_region%'` — the `LIKE` predicate matches both qualified and unqualified forms, so only the expected-output line needs updating (the query itself is unchanged).

Per RESEARCH.md §R-01, exhaustive `rg 'FROM "[^"]*"' test/sql/` confirmed this is the ONLY affected line in the entire sqllogictest suite. Other expansion-path sqllogictests use tolerant `LIKE` predicates and are unaffected.

If `just test-sql` later surfaces additional fixture impact (unlikely given the exhaustive grep, but possible if a hidden assertion was missed), update those fixtures with the same qualified prefix.
  </action>
  <verify>
    <automated>just build > /tmp/claude/build_task3.log 2>&1 && just test-sql > /tmp/claude/test_sql_task3.log 2>&1; RC=$?; tail -80 /tmp/claude/test_sql_task3.log; test "$RC" -eq 0</automated>
  </verify>
  <acceptance_criteria>
    - `grep -n 'FROM "memory"."main"."p57_agg_region"' test/sql/phase57_introspection.test` returns exactly one match at line 76 (or near it; line number may shift by ±1 due to file edits — confirm via context).
    - `grep -cn 'FROM "p57_agg_region"' test/sql/phase57_introspection.test` returns 0 (the unqualified form is gone from the file).
    - `just build` succeeds; `just test-sql` exits 0 (full sqllogictest suite green with updated fixture and migrated emission).
    - If sandbox blocks `mktemp` during `just build` or `just test-sql`, retry with `dangerouslyDisableSandbox: true` per CLAUDE.md Rule 2.
  </acceptance_criteria>
  <done>Fixture line updated; `just test-sql` green; no other sqllogictest fixtures require updates.</done>
</task>

<task type="checkpoint:human-verify" gate="blocking">
  <name>Task 4: Record D-09 baseline evidence before flipping MIGRATION_LANDED</name>
  <files>(no files modified — verification only)</files>
  <what-built>
    Migration applied across 4 source files + 1 sqllogictest fixture. The ADBC scenarios 3-7 in `test/integration/test_adbc_queries.py` are still gated by `SKIP_UNTIL_PLAN_02` / `MIGRATION_LANDED = False` from Plan 01.
  </what-built>
  <action>Pause for human verification. Executor presents the steps under <how-to-verify> to the user and waits for the resume-signal.</action>
  <how-to-verify>
    This is the D-09 baseline-evidence gate. Before flipping `MIGRATION_LANDED = True` in Task 5, capture the pre-migration failure proof:

    1. Stash the Plan 02 migration locally (do NOT discard):
       `git stash push -m "phase66 plan02 migration" src/expand/sql_gen.rs src/expand/semi_additive.rs src/expand/window.rs src/expand/materialization.rs test/sql/phase57_introspection.test`
    2. Locally edit `test/integration/test_adbc_queries.py` to set `MIGRATION_LANDED = True` (do NOT commit).
    3. Rebuild: `just build > /tmp/claude/build_baseline.log 2>&1; tail -20 /tmp/claude/build_baseline.log`
    4. Run the test: `just test-adbc-queries > /tmp/claude/adbc_queries_baseline_fail.log 2>&1; RC=$?; tail -100 /tmp/claude/adbc_queries_baseline_fail.log; echo "RC=$RC"`
    5. EXPECTED: scenarios 3, 4, 5, 6, and 7 FAIL with `adbc_driver_manager.ProgrammingError: Catalog Error: Table with name <X> does not exist!` or `Did you mean "memory.<X>"?` — the exact error in `_notes/error_with_adbc.md`. Scenarios 1 and 2 PASS. Exit code is nonzero.
    6. SAVE the failing output: copy `/tmp/claude/adbc_queries_baseline_fail.log` to the Plan 02 SUMMARY-evidence directory (or inline a key excerpt into the SUMMARY when written). This is the D-09 evidence that the test matrix actually exercises the failure mode.
    7. Revert local edits: `git checkout -- test/integration/test_adbc_queries.py` (revert flag flip).
    8. Restore the migration: `git stash pop`
    9. Sanity-check: `git status` shows the migration files re-applied with no other diffs; `cargo check` exits 0.

    If step 5's output shows scenarios 3-7 PASSING on pre-migration HEAD, STOP and investigate — that means the test scaffolding doesn't actually exercise the failure mode (Pitfall 5). Likely the scenario set-up isn't using non-default schemas correctly. Fix in Plan 01 (file the gap) before proceeding.

    If `mktemp` is blocked at any step, retry with `dangerouslyDisableSandbox: true` per CLAUDE.md Rule 2.
  </how-to-verify>
  <verify>
    <automated>echo "Manual checkpoint — see how-to-verify steps; user confirms with resume-signal."</automated>
  </verify>
  <done>User responds to the resume-signal confirming the checkpoint passed.</done>
  <resume-signal>Type "baseline-captured" with the path to the saved failing log, or describe issues.</resume-signal>
</task>

<task type="auto">
  <name>Task 5: Flip MIGRATION_LANDED and confirm 7/7 ADBC scenarios pass</name>
  <files>test/integration/test_adbc_queries.py</files>
  <read_first>
    - test/integration/test_adbc_queries.py (the `MIGRATION_LANDED` flag location set by Plan 01 — typically near the top of the file alongside `SKIP_UNTIL_PLAN_02`)
    - .planning/phases/66-expansion-qualification-adbc-tests/66-CONTEXT.md D-09 (gate semantics — post-migration scenarios 3-7 MUST PASS)
  </read_first>
  <action>
Edit `test/integration/test_adbc_queries.py`: change `MIGRATION_LANDED = False` to `MIGRATION_LANDED = True`. Remove or no-op the `SKIP_UNTIL_PLAN_02` short-circuit so scenarios 3, 4, 5, 6, 7 now execute.

If Plan 01 implemented the skip via a different mechanism (e.g., direct `print("SKIP: ...")` in each scenario rather than a top-level flag), apply the equivalent un-skip: remove or invert the conditional so the 5 gated scenarios run.

No production code changes in this task — flag flip only.
  </action>
  <verify>
    <automated>just test-adbc-queries > /tmp/claude/adbc_queries_green.log 2>&1; RC=$?; tail -100 /tmp/claude/adbc_queries_green.log; test "$RC" -eq 0 && grep -c "PASS" /tmp/claude/adbc_queries_green.log</automated>
  </verify>
  <acceptance_criteria>
    - `grep -n "MIGRATION_LANDED" test/integration/test_adbc_queries.py` shows `MIGRATION_LANDED = True` (or equivalent un-skip).
    - `just test-adbc-queries` exits 0; stdout reports 7 PASS / 0 SKIP / 0 FAIL.
    - The previously-failing scenarios (3-7) now produce row counts matching their assertions — no `Catalog Error: Table with name X does not exist!` in the log.
    - If `mktemp` is blocked, retry with `dangerouslyDisableSandbox: true`.
  </acceptance_criteria>
  <done>All 7 ADBC query scenarios green; EXPAND-CTX-02 satisfied end-to-end.</done>
</task>

<task type="checkpoint:human-verify" gate="blocking">
  <name>Task 6: Full quality-gate run — just test-all + just ci</name>
  <files>(no files modified — verification only)</files>
  <what-built>
    Complete Phase 66 migration set: 7 site migrations + signature change + sqllogictest fixture + ADBC scenarios un-skipped + 7/7 green.
  </what-built>
  <action>Pause for human verification. Executor presents the steps under <how-to-verify> to the user and waits for the resume-signal.</action>
  <how-to-verify>
    1. `just test-all > /tmp/claude/test_all_final.log 2>&1; RC=$?; tail -120 /tmp/claude/test_all_final.log; echo "RC=$RC"` — confirm full aggregate (Rust unit + sqllogictest + DuckLake CI + vtab + caret + ADBC transactions + ADBC queries + large-view + multi-DB + readonly + concurrent) exits 0.
    2. `just ci > /tmp/claude/ci_final.log 2>&1; RC=$?; tail -120 /tmp/claude/ci_final.log; echo "RC=$RC"` — confirm CI mirror (test-all + clippy pedantic + fmt + cargo-deny + fuzz target compile) exits 0.
    3. Cross-check: `grep -E "(FAIL|panicked|error)" /tmp/claude/test_all_final.log /tmp/claude/ci_final.log | grep -v "^.*Compiling" | grep -v "test-error" | head -20` returns no unexpected failure lines (compile-time `error[E...]` would be a fail; cargo-deny advisories should be reviewed).
    4. The D-09 baseline-evidence log from Task 4 is saved and referenced in the SUMMARY.
    5. If `mktemp` is blocked at any step, retry with `dangerouslyDisableSandbox: true` per CLAUDE.md Rule 2.
  </how-to-verify>
  <verify>
    <automated>echo "Manual checkpoint — see how-to-verify steps; user confirms with resume-signal."</automated>
  </verify>
  <done>User responds to the resume-signal confirming the checkpoint passed.</done>
  <resume-signal>Type "approved" to proceed to Plan 03, or describe issues.</resume-signal>
</task>

</tasks>

<threat_model>
No new threats; see RESEARCH.md §Security Domain. Qualified emission is a marginal *improvement* against catalog-shadowing scenarios (e.g., a malicious `CREATE SCHEMA` in the caller's session that shadows a legitimate table name) by removing reliance on session-level catalog/schema state. Pre-commit hook (cargo fmt + clippy) enforces standard code-quality gates; never use `--no-verify`.
</threat_model>

<verification>
- `cargo test -p semantic-views --lib` exits 0 after each task.
- `just test-sql` exits 0 with phase57_introspection fixture updated.
- D-09 baseline evidence captured: scenarios 3-7 FAIL on pre-migration HEAD with `Catalog Error: Table with name X does not exist!`.
- `just test-adbc-queries` exits 0 with 7/7 PASS / 0 SKIP / 0 FAIL post-migration.
- `just test-all` and `just ci` both exit 0.
- No `quote_table_ref(` bare call sites remain in the 4 expand-path files (only `qualify_and_quote_table_ref` for table refs).
</verification>

<success_criteria>
- 10 mechanical migrations applied: sql_gen.rs (3), semi_additive.rs (3), window.rs (3), materialization.rs (1).
- `build_materialized_sql` signature accepts `def` and caller threads it through.
- `phase57_introspection.test:76` expects qualified shape.
- `test_adbc_queries.py` runs 7/7 PASS post-migration.
- D-09 baseline evidence recorded.
- `just test-all` and `just ci` green.
- EXPAND-CTX-01 satisfied; EXPAND-CTX-02 fully satisfied (including D-09 baseline gate).
</success_criteria>

<output>
Create `.planning/phases/66-expansion-qualification-adbc-tests/66-02-SUMMARY.md` when done. Include the D-09 baseline-evidence excerpt (key error lines from `/tmp/claude/adbc_queries_baseline_fail.log`) and the post-migration green log excerpt.

</output>
