Skip to content

Commit b5060e0

Browse files
committed
Reduce safe refactor review noise
1 parent 80b8683 commit b5060e0

7 files changed

Lines changed: 85 additions & 9 deletions

File tree

‎docs/docs/usage/dbt-pr-review.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,11 @@ reviewer does **not** re-implement Jinja — it consumes dbt's own compiled outp
332332
from `target/compiled/<project>/…` (HEAD) and `target-base/compiled/…` (BASE),
333333
produced by `dbt compile`. To enable full equivalence verdicts, compile both
334334
the base and head refs in CI (the base into `target-base/`, the Recce
335-
convention). Without compiled SQL the engine lanes fall back to raw and stay
336-
*undecidable* (never fabricated) — the `dbt-patterns` lane still runs.
335+
convention). For proof-grade equivalence, also produce `target/catalog.json`
336+
with `dbt docs generate`; the catalog carries complete warehouse columns that
337+
`manifest.json` often lacks. Without compiled SQL or complete columns the
338+
engine lanes stay *undecidable* (never fabricated) — the `dbt-patterns` lane
339+
still runs.
337340

338341
## What it checks — deterministic rule catalog
339342

‎docs/internal/2026-06-08-dbt-pr-review-self-improvement-loop.md‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,16 @@ Validation:
208208
### 2. Base Compiled Artifact Support In Demo CI
209209

210210
Risk: safe refactors degrade to "could not prove equivalent" because the review
211-
has only head-side compiled SQL.
211+
has incomplete proof inputs: missing base compiled SQL or incomplete schema
212+
columns.
212213

213214
Evidence:
214215

215216
- `compiled.ts` already supports `target-base/compiled/<project>/<path>`.
216217
- The demo workflow currently runs only head-side `dbt compile`.
218+
- `demo/safe-refactor` became decidable after `dbt docs generate` produced
219+
`target/catalog.json`, but core equivalence then falsely compared CTE alias
220+
names inside the join filter.
217221

218222
Do not flag:
219223

@@ -223,8 +227,24 @@ Do not flag:
223227
Expected result:
224228

225229
- The demo workflow compiles base into `target-base` before compiling head.
226-
- `demo/safe-refactor` no longer emits an unknown semantic-change warning due
227-
solely to missing base compiled SQL.
230+
- The demo workflow produces `target/catalog.json` when a warehouse-backed dbt
231+
project is available, so equivalence has complete columns.
232+
- `demo/safe-refactor` emits no findings with local core and DuckDB catalog
233+
artifacts.
234+
235+
Implemented result:
236+
237+
- Core `L012 missing_table_alias` now ignores CTE references, removing the
238+
`order_records/customer_records` alias noise while preserving real table alias
239+
lint.
240+
- Core equivalence now resolves join predicate columns through CTE aliases to
241+
base `table.column` provenance, so CTE alias renames are equivalent but a
242+
changed join key remains material.
243+
- `altimate-code` now threads the detected dialect into
244+
`altimate_core.equivalence` and `--no-ai` correctly disables the advisory lane.
245+
- Local DuckDB safe-refactor validation: `APPROVE`, zero findings.
246+
- Real-world corpus floor preserved: 15/15 bad cases caught, 0/5 false
247+
positives.
228248

229249
### 3. PII Classification Precision Floor
230250

‎packages/opencode/src/altimate/native/altimate-core.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export function registerAll(): void {
320320
register("altimate_core.equivalence", async (params) => {
321321
try {
322322
const schema = schemaOrEmpty(params.schema_path, params.schema_context)
323-
const raw = await core.checkEquivalence(params.sql1, params.sql2, schema)
323+
const raw = await core.checkEquivalence(params.sql1, params.sql2, schema, params.dialect)
324324
const data = toData(raw)
325325
return ok(true, data)
326326
} catch (e) {

‎packages/opencode/src/altimate/native/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ export interface AltimateCoreTestgenParams {
879879
export interface AltimateCoreEquivalenceParams {
880880
sql1: string
881881
sql2: string
882+
dialect?: string
882883
schema_path?: string
883884
schema_context?: Record<string, any>
884885
}

‎packages/opencode/src/altimate/review/runner.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,13 @@ export function createDispatcherRunner(opts: DispatcherRunnerOptions): ReviewRun
470470
}
471471
},
472472

473-
async equivalence(oldSql: string, newSql: string): Promise<EquivalenceResult> {
473+
async equivalence(oldSql: string, newSql: string, dialect?: string): Promise<EquivalenceResult> {
474474
try {
475475
const schema = await resolveSchema()
476476
const res = await Dispatcher.call("altimate_core.equivalence", {
477477
sql1: oldSql,
478478
sql2: newSql,
479+
dialect,
479480
schema_context: schema,
480481
})
481482
const data = (res.data ?? {}) as Record<string, any>

‎packages/opencode/src/cli/cmd/review.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const ReviewCommand = cmd({
5858
manifestPath: args.manifest as string | undefined,
5959
mode: args.mode as ReviewMode | undefined,
6060
severityThreshold: args.severity as Severity | undefined,
61-
noAi: args.ai === false,
61+
noAi: args.noAi === true || args.ai === false,
6262
})
6363

6464
if (args.output) await fs.writeFile(args.output as string, JSON.stringify(env, null, 2))

‎packages/opencode/test/altimate/review-runner.test.ts‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
import { describe, expect, test } from "bun:test"
1+
import { afterEach, describe, expect, spyOn, test } from "bun:test"
22
import { writeFileSync } from "node:fs"
33
import path from "node:path"
44
import { createDispatcherRunner } from "../../src/altimate/review/runner"
5+
import { Dispatcher } from "../../src/altimate/native"
56
import { tmpdir } from "../fixture/fixture"
67

8+
let dispatcherSpy: ReturnType<typeof spyOn> | undefined
9+
10+
afterEach(() => {
11+
dispatcherSpy?.mockRestore()
12+
dispatcherSpy = undefined
13+
})
14+
715
describe("review manifest loading", () => {
816
test("loads a valid manifest without initializing the native dispatcher", async () => {
917
await using tmp = await tmpdir()
@@ -36,4 +44,47 @@ describe("review manifest loading", () => {
3644
testCount: 0,
3745
})
3846
})
47+
48+
test("threads adapter dialect into core equivalence", async () => {
49+
await using tmp = await tmpdir()
50+
const manifestPath = path.join(tmp.path, "manifest.json")
51+
writeFileSync(
52+
manifestPath,
53+
JSON.stringify({
54+
metadata: { adapter_type: "duckdb" },
55+
nodes: {
56+
"model.demo.orders": {
57+
resource_type: "model",
58+
name: "orders",
59+
original_file_path: "models/orders.sql",
60+
config: { materialized: "table" },
61+
depends_on: { nodes: [] },
62+
columns: { id: { name: "id", data_type: "integer" } },
63+
},
64+
},
65+
sources: {},
66+
}),
67+
)
68+
69+
let seenParams: any
70+
dispatcherSpy = spyOn(Dispatcher, "call").mockImplementation((async (method: string, params: any) => {
71+
expect(method).toBe("altimate_core.equivalence")
72+
seenParams = params
73+
return {
74+
success: true,
75+
data: {
76+
equivalent: true,
77+
confidence: 0.95,
78+
differences: [],
79+
validation_errors: [],
80+
},
81+
}
82+
}) as any)
83+
84+
const runner = createDispatcherRunner({ manifestPath })
85+
const result = await runner.equivalence("select id from orders", "select id from orders", "duckdb")
86+
87+
expect(result).toEqual({ decided: true, equivalent: true, differences: [], confidence: "high" })
88+
expect(seenParams.dialect).toBe("duckdb")
89+
})
3990
})

0 commit comments

Comments
 (0)