Skip to content

Commit 310927e

Browse files
sahrizviclaude
andcommitted
fix(review): address PR-1027 round-4 (deleted schema.yml + backtick fence + Bun-alias flake + finding attribution)
Four items from cubic-review round-3 + one CI-only test flake: - **Deleted schema.yml handling (cubic P2)** — `detectSchemaYmlPatterns` now diffs old YAML against `{}` when `status === "deleted"`, so dropping a whole schema file surfaces every prior test as a removal. `orchestrate.ts` no longer filters deleted files and skips `newContent` fetch for them (git-show at HEAD would fail). Two regression tests: 4-test deletion, and safe-degrade when `oldContent` is missing. - **Backtick-safe tierReasons rendering (cubic P3)** — `format.ts` now sizes the inline-code-span fence to `max(backtick-run) + 1` and pads leading/trailing backticks with a space, so paths like `` `foo`bar` `` can't terminate the span or inject Markdown. Regression test covers single/double/leading/trailing/both-ends cases. - **Structured attribution on removal findings (cubic P3)** — `removed_tests` findings now include `model` and `column` on the top-level Finding, not just inside `evidence.result`, so downstream dedupe / formatting / telemetry see them. - **TUI network-options test flake (CI-only)** — Bun's transpiler statically resolved the `@/cli/network` string literal in `toContain('...')` into a `file:///…/network.ts` URL, inverting the comparison. Rewritten as `toMatch(/regex/)` so the alias literal isn't recognizable to Bun's analyzer. Additional edge tests per codex round-4 review: - Deleted schema.yml with unparsable oldContent → diff-only fallback. - Deleted empty schema.yml → no fabricated findings. - tierReasons with both leading + trailing backticks → symmetric padding. Tests: 145 pass, 0 fail in touched suites; full review suite (188 tests) green. Co-Authored-By: Claude Opus 4.7 <[email protected]> Claude-Session: https://claude.ai/code/session_017zXDXMiNFh4qDPxPCfa2of
1 parent 39718d5 commit 310927e

6 files changed

Lines changed: 214 additions & 36 deletions

File tree

‎packages/opencode/src/altimate/review/dbt-patterns.ts‎

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -947,42 +947,55 @@ export function detectSchemaYmlPatterns(
947947
opts: SchemaYmlDetectContent = {},
948948
): Finding[] {
949949
const kind = classifyDbtFile(file.path)
950-
if (kind !== "schema_yml" || file.status === "deleted") return []
950+
if (kind !== "schema_yml") return []
951951

952952
const removals: Array<{ model: string; column: string; test: string }> = []
953953
let usedStructural = false
954954

955+
// Deleting a whole schema.yml removes every test declared in it — arguably
956+
// a bigger removal than dropping a single test. Treat the new side as empty
957+
// and diff the old document against `{}` so every prior test surfaces as a
958+
// removal (cubic-review P2). Requires `oldContent` from the caller.
959+
const isDeletedFile = file.status === "deleted"
960+
955961
// PREFERRED: structural YAML diff when we have both sides' content.
956962
//
957963
// "Added" file case (no `oldContent` supplied AND status marks the file as
958964
// newly-added upstream) — the old side is empty, so there's nothing to
959965
// remove; using the structural path with an empty old set is correct.
960966
//
967+
// "Deleted" file case — the new side is empty; use the structural path
968+
// with an empty new set so every old test surfaces as a removal.
969+
//
961970
// "Modified but resolver returned undefined" case (`oldContent === undefined`
962971
// for a file whose status is `modified` or `renamed`) — the resolver couldn't
963972
// read the old side. Do NOT treat this as an added file (would silently drop
964973
// real removals). Fall through to the diff-only fallback below.
965974
const isAddedFile = file.status === "added"
966975
const canUseStructural =
967-
opts.newContent !== undefined &&
968-
// For a real modification/rename we require both sides; without oldContent
969-
// fall back to diff parsing so removals in the diff still surface.
970-
(isAddedFile || opts.oldContent !== undefined)
976+
(isDeletedFile
977+
? opts.oldContent !== undefined
978+
: opts.newContent !== undefined &&
979+
// For a real modification/rename we require both sides; without oldContent
980+
// fall back to diff parsing so removals in the diff still surface.
981+
(isAddedFile || opts.oldContent !== undefined))
971982

972983
if (canUseStructural) {
973984
let oldDoc: unknown = undefined
974985
let newDoc: unknown = undefined
975-
try {
976-
newDoc = YAML.parse(opts.newContent as string)
977-
} catch (err) {
978-
// Debug telemetry: YAML parsers can trip on Jinja injected into a
979-
// schema.yml or on non-ASCII quirks; log so failures are diagnosable
980-
// rather than silently demoting to the fallback path.
981-
Log.create({ service: "review", tag: "detectSchemaYmlPatterns" }).warn(
982-
`YAML.parse failed on new content of ${file.path}; falling back to diff-only detection`,
983-
err instanceof Error ? { error: err.message } : undefined,
984-
)
985-
newDoc = undefined
986+
if (opts.newContent !== undefined) {
987+
try {
988+
newDoc = YAML.parse(opts.newContent)
989+
} catch (err) {
990+
// Debug telemetry: YAML parsers can trip on Jinja injected into a
991+
// schema.yml or on non-ASCII quirks; log so failures are diagnosable
992+
// rather than silently demoting to the fallback path.
993+
Log.create({ service: "review", tag: "detectSchemaYmlPatterns" }).warn(
994+
`YAML.parse failed on new content of ${file.path}; falling back to diff-only detection`,
995+
err instanceof Error ? { error: err.message } : undefined,
996+
)
997+
newDoc = undefined
998+
}
986999
}
9871000
if (opts.oldContent !== undefined) {
9881001
try {
@@ -995,13 +1008,18 @@ export function detectSchemaYmlPatterns(
9951008
oldDoc = undefined
9961009
}
9971010
}
998-
// Only commit to the structural path when we have a parseable new side
999-
// AND (we're on an added file OR the old side also parsed). This preserves
1000-
// "unparseable old YAML" → fallback, not "structural with empty old = every
1001-
// removed test looks like a genuine removal".
1002-
if (newDoc !== undefined && (isAddedFile || oldDoc !== undefined)) {
1011+
// Only commit to the structural path when the appropriate sides parsed:
1012+
// - deleted → old must parse; new is treated as `{}`
1013+
// - added → new must parse; old is treated as `{}`
1014+
// - modified/renamed → both must parse
1015+
// This preserves "unparseable YAML" → fallback rather than
1016+
// "structural with empty side = every test looks removed/added".
1017+
const canCommit = isDeletedFile
1018+
? oldDoc !== undefined
1019+
: newDoc !== undefined && (isAddedFile || oldDoc !== undefined)
1020+
if (canCommit) {
10031021
const oldSet = extractTestOccurrences(oldDoc ?? {})
1004-
const newSet = extractTestOccurrences(newDoc)
1022+
const newSet = extractTestOccurrences(isDeletedFile ? {} : newDoc)
10051023
for (const key of oldSet) {
10061024
if (newSet.has(key)) continue
10071025
const [model, column, test] = key.split("\x00")
@@ -1129,6 +1147,11 @@ export function detectSchemaYmlPatterns(
11291147
title,
11301148
body: bodyLead + bodyRationale + bodyTail,
11311149
file: file.path,
1150+
// Surface the extracted attribution on the top-level Finding so
1151+
// downstream consumers (dedupe, formatting, telemetry) see it —
1152+
// not just inside `evidence.result` (cubic-review P3).
1153+
model: r.model || undefined,
1154+
column: r.column || undefined,
11321155
confidence: "high",
11331156
evidence: {
11341157
tool: "dbt-patterns",

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,21 @@ export function renderSummary(env: VerdictEnvelope): string {
5757
// the signed envelope's tierReasons[]; the summary shows the first 8.
5858
if (env.tierReasons && env.tierReasons.length) {
5959
const RENDER_CAP = 8
60-
const shown = env.tierReasons.slice(0, RENDER_CAP).map((r) => `\`${r}\``).join(", ")
60+
// Pick an inline-code-span fence longer than any backtick run inside `r`
61+
// so a path like `packages/…/foo`bar`.sql` cannot terminate the span
62+
// (cubic-review P3).
63+
const shown = env.tierReasons
64+
.slice(0, RENDER_CAP)
65+
.map((r) => {
66+
const runs = r.match(/`+/g)
67+
const maxRun = runs ? Math.max(...runs.map((run) => run.length)) : 0
68+
const fence = "`".repeat(maxRun + 1)
69+
// If the reason itself starts/ends with a backtick, pad with a space so
70+
// the leading/trailing backtick isn't glued to the fence.
71+
const pad = /^`|`$/.test(r) ? " " : ""
72+
return `${fence}${pad}${r}${pad}${fence}`
73+
})
74+
.join(", ")
6175
const overflow =
6276
env.tierReasons.length > RENDER_CAP
6377
? ` (+${env.tierReasons.length - RENDER_CAP} more in verdict envelope)`

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,26 +1223,27 @@ export async function runReview(input: OrchestrateInput): Promise<VerdictEnvelop
12231223
// silently drops sibling-column edge cases). Falls back to diff-only line
12241224
// detection when a content resolver isn't wired (e.g. unit-test callers).
12251225
//
1226-
// `oldContent` is fetched for anything that has an old side — MODIFIED and
1227-
// RENAMED. A schema.yml being renamed (e.g. moved to a new subdir) that
1228-
// also drops a `unique`/`not_null` guardrail must still surface as a finding;
1229-
// the earlier `status === "modified"` gate silently skipped renames.
1226+
// `oldContent` is fetched for anything that has an old side — MODIFIED,
1227+
// RENAMED, and DELETED. A schema.yml being renamed (e.g. moved to a new
1228+
// subdir) that also drops a `unique`/`not_null` guardrail must still surface
1229+
// as a finding; the earlier `status === "modified"` gate silently skipped
1230+
// renames. A whole schema.yml being DELETED removes every test declared in
1231+
// it — an even bigger removal — so the detector runs against `oldContent`
1232+
// vs an empty new document (cubic-review P2).
1233+
//
1234+
// `newContent` fetch is skipped for deleted files (nothing at HEAD to read;
1235+
// git-show would fail).
12301236
//
12311237
// Fetches run in parallel across schema files (a schema-heavy PR could touch
12321238
// dozens of yml files; serial `git show` per file adds up).
1233-
//
1234-
// DELETED schema files are filtered upfront because `detectSchemaYmlPatterns`
1235-
// early-returns `[]` for `status === "deleted"` anyway; not filtering here
1236-
// would trigger an unnecessary `getContent(oldRef, "old")` fetch (a git-show
1237-
// round-trip) whose result is thrown away by the detector.
1238-
const schemaFiles = reviewable.filter((f) => f.kind === "schema_yml" && f.status !== "deleted")
1239+
const schemaFiles = reviewable.filter((f) => f.kind === "schema_yml")
12391240
if (schemaFiles.length) {
12401241
const schemaFindingSets = await Promise.all(
12411242
schemaFiles.map(async (file) => {
12421243
const oldRef = file.oldPath ?? file.path
12431244
const [oldContent, newContent] = await Promise.all([
12441245
file.status !== "added" ? getContent?.(oldRef, "old") : Promise.resolve(undefined),
1245-
getContent?.(file.path, "new"),
1246+
file.status !== "deleted" ? getContent?.(file.path, "new") : Promise.resolve(undefined),
12461247
])
12471248
return detectSchemaYmlPatterns(file, input.rubric, { oldContent, newContent })
12481249
}),

‎packages/opencode/test/altimate/review-dbt-patterns.test.ts‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,107 @@ models:
549549
expect(withSummary.body).toContain("`orders`")
550550
})
551551

552+
test("deleted schema.yml: every prior test surfaces as a removal finding (cubic-review P2)", () => {
553+
// Regression: deleting a whole schema.yml removes every test declared in
554+
// it — arguably a bigger removal than dropping a single test. Previously
555+
// the detector early-returned `[]` for `status === "deleted"`, so the
556+
// deletion went unnoticed. Now the detector diffs the old document against
557+
// an empty new document.
558+
const oldContent = `version: 2
559+
models:
560+
- name: customers
561+
columns:
562+
- name: customer_id
563+
tests: [unique, not_null]
564+
- name: email
565+
tests: [not_null]
566+
- name: orders
567+
columns:
568+
- name: order_id
569+
tests: [unique]
570+
`
571+
const f = detectSchemaYmlPatterns(
572+
{ path: "models/marts/_models.yml", status: "deleted", diff: undefined },
573+
DEFAULT_RUBRIC,
574+
// Only oldContent is available for a deleted file; newContent is undefined
575+
// because git-show at HEAD would fail.
576+
{ oldContent, newContent: undefined },
577+
)
578+
// 4 removals: customers.customer_id.unique, customers.customer_id.not_null,
579+
// customers.email.not_null, orders.order_id.unique
580+
expect(f.length).toBe(4)
581+
expect(has(f, "test_coverage", "warning")).toBe(true)
582+
// Structured attribution surfaces on the top-level Finding, not just in
583+
// evidence.result (cubic-review P3).
584+
const byModel = f.filter((x) => x.model === "customers")
585+
expect(byModel.length).toBe(3)
586+
const byColumn = f.filter((x) => x.column === "email")
587+
expect(byColumn.length).toBe(1)
588+
})
589+
590+
test("deleted schema.yml without oldContent: no findings (safe degrade)", () => {
591+
// Without the old side, we can't know what tests to flag as removed.
592+
// The detector should degrade to `[]` rather than fabricating findings.
593+
const f = detectSchemaYmlPatterns(
594+
{ path: "models/marts/_models.yml", status: "deleted", diff: undefined },
595+
DEFAULT_RUBRIC,
596+
{ oldContent: undefined, newContent: undefined },
597+
)
598+
expect(f.length).toBe(0)
599+
})
600+
601+
test("deleted schema.yml with unparsable oldContent + deletion diff → fallback surfaces removals", () => {
602+
// Structural path can't commit (old YAML fails to parse), so the diff-only
603+
// fallback runs. Confirms: unparsable-old → fallback, not silent drop.
604+
const oldContent = `version: 2
605+
models:
606+
- name: customers
607+
columns:
608+
- name: customer_id
609+
tests:
610+
- not_null # <-- unterminated block below causes parse failure
611+
tests: [
612+
`
613+
// Diff uses the block-list shape the fallback regex targets
614+
// (`- - unique` / `- - not_null`).
615+
const diff = `--- a/models/marts/_models.yml
616+
+++ /dev/null
617+
@@ -1,8 +0,0 @@
618+
-version: 2
619+
-models:
620+
- - name: customers
621+
- columns:
622+
- - name: customer_id
623+
- tests:
624+
- - unique
625+
- - not_null
626+
`
627+
const f = detectSchemaYmlPatterns(
628+
{ path: "models/marts/_models.yml", status: "deleted", diff },
629+
DEFAULT_RUBRIC,
630+
{ oldContent, newContent: undefined },
631+
)
632+
// Diff-only fallback picks up the removed `- unique` and `- not_null`
633+
// lines, so we still emit at least one removal finding rather than silently
634+
// dropping when the structural path couldn't commit.
635+
expect(f.length).toBeGreaterThan(0)
636+
expect(has(f, "test_coverage", "warning")).toBe(true)
637+
})
638+
639+
test("deleted empty schema.yml: no fabricated findings (locks in precision)", () => {
640+
// Old side parses cleanly but declares no tests. Ensures the structural
641+
// loop doesn't fabricate findings when oldSet is empty.
642+
const oldContent = `version: 2
643+
models: []
644+
`
645+
const f = detectSchemaYmlPatterns(
646+
{ path: "models/marts/_models.yml", status: "deleted", diff: undefined },
647+
DEFAULT_RUBRIC,
648+
{ oldContent, newContent: undefined },
649+
)
650+
expect(f.length).toBe(0)
651+
})
652+
552653
test("benign additive column produces NO dbt-pattern finding (precision)", () => {
553654
const sql = `select id, upper(status) as status_upper from {{ ref('x') }}`
554655
const f = detectModelPatterns(

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,42 @@ describe("orchestrate", () => {
18811881
expect(env.summary.degraded).toBe(true)
18821882
})
18831883

1884+
test("renderSummary escapes backticks in tierReasons (cubic-review P3)", async () => {
1885+
// Regression: a fixed single-backtick fence around each tier reason meant a
1886+
// path like `weird`path`.sql` would terminate the code span mid-way and
1887+
// inject Markdown into the summary. Fence now sizes to max(backtick-run)+1
1888+
// and pads leading/trailing backticks with a space.
1889+
const env = buildEnvelope({
1890+
findings: [],
1891+
tier: "full",
1892+
mode: "comment",
1893+
generatedAt: "2026-05-29T00:00:00Z",
1894+
tierReasons: [
1895+
"models/x.sql", // plain path — one-backtick fence still fine
1896+
"path with `single` inside", // needs 2-backtick fence
1897+
"path with ``double`` inside", // needs 3-backtick fence
1898+
"`starts-with-backtick",
1899+
"ends-with-backtick`",
1900+
"`both-ends`", // both leading + trailing backticks — symmetric padding
1901+
],
1902+
})
1903+
const summary = renderSummary(env)
1904+
// Sanity: the tier line exists
1905+
expect(summary).toContain("Tier: full")
1906+
// A path with `single` inside must be wrapped by a fence longer than the
1907+
// longest backtick run inside it. Two-backtick fence sees `single` as a
1908+
// single-backtick run inside the code span → renders correctly.
1909+
expect(summary).toContain("``path with `single` inside``")
1910+
// Three-backtick fence for two-backtick run inside.
1911+
expect(summary).toContain("```path with ``double`` inside```")
1912+
// Leading/trailing backticks get space padding so the fence doesn't fuse
1913+
// with the reason text.
1914+
expect(summary).toContain("`` `starts-with-backtick ``")
1915+
expect(summary).toContain("`` ends-with-backtick` ``")
1916+
// Both ends have backticks — same single pad wraps both sides symmetrically.
1917+
expect(summary).toContain("`` `both-ends` ``")
1918+
})
1919+
18841920
test("renderSummary + inlineComments produce marker + structured output", async () => {
18851921
const env = buildEnvelope({
18861922
findings: [

‎packages/opencode/test/cli/tui/command.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ describe("tui command", () => {
77
test("resolves network options through the config-aware resolver", async () => {
88
const source = await tuiCommandSource()
99

10-
expect(source).toContain('import { withNetworkOptions, resolveNetworkOptions } from "@/cli/network"')
11-
expect(source).toContain('import { AppRuntime } from "@/effect/app-runtime"')
10+
// Assertions use regex (not string literals) so Bun's transpiler doesn't
11+
// statically resolve `@/cli/network` into `file:///…/network.ts` in the
12+
// expected value — a CI-only cache quirk that inverts the comparison.
13+
expect(source).toMatch(/import \{ withNetworkOptions, resolveNetworkOptions \} from "@\/cli\/network"/)
14+
expect(source).toMatch(/import \{ AppRuntime \} from "@\/effect\/app-runtime"/)
1215
expect(source).toContain("await AppRuntime.runPromise(resolveNetworkOptions(args))")
1316
expect(source).not.toContain("resolveNetworkOptionsNoConfig(args)")
1417
})

0 commit comments

Comments
 (0)