Skip to content

Commit a3e2a89

Browse files
committed
fix(review): PR #1041 pre-merge review findings
Bot review on the v0.9.3 release PR caught three correctness gaps and a CI-blocking branding-audit trip. All fixed here so the release stays clean: - **`cliVersion` default in `reviewPullRequest`.** Only the CLI command forwarded `Installation.VERSION`; the agent-invoked `dbt_pr_review` tool wrapper never did, so tool-path verdicts silently dropped `engine.cliVersion` and defeated the audit-trail promise the field was added for. Default the option to `Installation.VERSION` inside `reviewPullRequest` so both entry points populate it. (cubic P2 conf 9) - **`staleManifest` deletion false-negative.** `detectStaleManifest` previously took `changedPaths: string[]` and tried to `stat` each — a deletion of a manifest-affecting model reported CLEAN because the file no longer exists on disk. The signed envelope then falsely certified a verdict against ghost models. Pass the full `ChangedFile[]` through instead and treat `deleted` / `renamed` manifest-affecting entries as unconditionally stale (they can't be stat'd but the manifest still references them, so the metadata is by definition out of date). Rename covers both sides so a rename-away and a rename-to both trip. (cubic P2 conf 8) - **Docs boundary-matching wording + non-match example.** The `riskTierPathTokens` doc claimed "case-insensitive substrings" but `compilePathTokenResolver` actually anchors tokens at path/word/digit boundaries — `cost` fires on `mrt_cost_daily.sql` but not on `broadcaster.sql`. Correct the wording and add the non-match example so users don't configure tokens that don't match their intent. (cubic P2 conf 5 + coderabbit) - **Branding-audit trip in `script/release-preflight.ts:609`.** The operational instruction telling the operator how to add the upstream remote (`git remote add upstream https://github.com/anomalyco/opencode.git`) legitimately names the upstream URL. The CI branding audit doesn't know operational text from branding drift; wrap the block in `altimate_change` markers so the audit skips it.
1 parent afcca83 commit a3e2a89

3 files changed

Lines changed: 56 additions & 16 deletions

File tree

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,16 @@ rubric:
251251
252252
Named categories under `riskTierPathTokens` promote any diff touching a matching
253253
path to `full` review tier, so those areas never auto-approve on `trivial`
254-
classification. Values are case-insensitive substrings; the `preset:finops` marker
255-
expands to the built-in FinOps keyword list (cost, billing, spend, revenue, etc.).
256-
Prior to v0.9.3 the FinOps list was hardcoded and always on; it is now opt-in via
257-
this config. When a category value is invalid the CLI logs a stderr warning AND
258-
surfaces the error in the verdict envelope's `tierReasons[]` (and in the PR
259-
comment), so a typo can't silently kill your opt-in.
254+
classification. Tokens are matched **case-insensitively at path, word, or digit
255+
boundaries** — not as arbitrary substrings. For example, the token `cost` fires
256+
on `models/marts/mrt_cost_daily.sql` (bounded by `_` and `_`) but **not** on
257+
`models/broadcaster.sql` (the substring lives inside a longer word). The
258+
`preset:finops` marker expands to the built-in FinOps keyword list (cost,
259+
billing, spend, revenue, etc.). Before v0.9.3 the FinOps list was hardcoded and
260+
always on; it is now opt-in via this config. When a category value is invalid
261+
the CLI logs a stderr warning AND surfaces the error in the verdict envelope's
262+
`tierReasons[]` (and in the PR comment), so a typo can't silently kill your
263+
opt-in.
260264

261265
## Data-diff in CI
262266

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

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from "node:path"
22
import { readFile, realpath, stat, access } from "node:fs/promises"
3+
import { Installation } from "../../installation"
34
import { loadReviewConfig, resolveRubric } from "./config"
45
import type { Severity } from "./finding"
56
import { collectChangedFiles, makeContentResolver, defaultBaseRef, gitRepoRoot, manifestHash } from "./git"
@@ -152,28 +153,51 @@ export function isManifestAffecting(rel: string): boolean {
152153
* the review proceeds against the (possibly stale) manifest and the
153154
* caller mirrors the flag onto the signed envelope so a downstream
154155
* auditor can distinguish stale-manifest verdicts from clean ones
155-
* (stderr alone is easy for CI to swallow). */
156-
async function detectStaleManifest(manifestAbs: string, changedPaths: string[], fsRoot: string): Promise<boolean> {
156+
* (stderr alone is easy for CI to swallow).
157+
*
158+
* A deleted or renamed manifest-affecting file is treated as unconditionally
159+
* stale: the file's mtime cannot be checked (the path is gone) but the
160+
* manifest still references it, so the metadata is by definition out of date
161+
* (cubic-review PR #1041 — the prior path-only signature silently reported
162+
* clean for deletions and could false-certify verdicts against ghost models). */
163+
async function detectStaleManifest(manifestAbs: string, changed: ChangedFile[], fsRoot: string): Promise<boolean> {
157164
try {
158165
const manifestMtime = (await stat(manifestAbs)).mtimeMs
159-
for (const rel of changedPaths) {
160-
if (!isManifestAffecting(rel)) continue
161-
// `changedPaths` are repo-root relative (from `git diff --name-status`),
166+
for (const f of changed) {
167+
// For renamed files, the OLD path is what the manifest still knows about;
168+
// check both sides so both a rename-away and a rename-to a
169+
// manifest-affecting shape trigger the signal.
170+
const paths: string[] = [f.path]
171+
if (f.status === "renamed" && f.oldPath) paths.push(f.oldPath)
172+
if (!paths.some(isManifestAffecting)) continue
173+
174+
// Deleted / renamed files no longer exist at their old path on disk, so
175+
// stat would fail. The manifest still references them though, so the
176+
// metadata is stale by definition — fire immediately.
177+
if (f.status === "deleted" || f.status === "renamed") {
178+
process.stderr.write(
179+
`⚠️ manifest ${manifestAbs} appears stale — ${f.status} \`${f.path}\` is a manifest-affecting path. ` +
180+
`Re-run \`dbt compile\` (or \`dbt build\`) to refresh before reviewing.\n`,
181+
)
182+
return true
183+
}
184+
185+
// `changed` paths are repo-root relative (from `git diff --name-status`),
162186
// so root at the git top-level rather than the caller's cwd. When the
163187
// CLI is invoked from a subdir the naive path.join(cwd, rel) points at
164188
// a non-existent path and the stale check silently no-ops.
165-
const abs = path.isAbsolute(rel) ? rel : path.join(fsRoot, rel)
189+
const abs = path.isAbsolute(f.path) ? f.path : path.join(fsRoot, f.path)
166190
try {
167191
const changedMtime = (await stat(abs)).mtimeMs
168192
if (changedMtime > manifestMtime) {
169193
process.stderr.write(
170-
`⚠️ manifest ${manifestAbs} appears stale — ${rel} was modified after the manifest was written. ` +
194+
`⚠️ manifest ${manifestAbs} appears stale — ${f.path} was modified after the manifest was written. ` +
171195
`Re-run \`dbt compile\` (or \`dbt build\`) to refresh before reviewing.\n`,
172196
)
173197
return true
174198
}
175199
} catch {
176-
/* file not on disk (e.g. removed by the change) — skip */
200+
/* file not on disk for an added/modified entry — skip (rare race) */
177201
}
178202
}
179203
} catch {
@@ -256,7 +280,7 @@ export async function reviewPullRequest(opts: ReviewPullRequestOptions): Promise
256280
// is limited to files that would materially change the manifest
257281
// (`isManifestAffecting`), so noise is bounded. Return value is stamped
258282
// into the signed envelope so downstream auditors see it too.
259-
const staleManifest = await detectStaleManifest(manifestAbs, changedFiles.map((f) => f.path), gitRoot)
283+
const staleManifest = await detectStaleManifest(manifestAbs, changedFiles, gitRoot)
260284

261285
// Resolve the SQL dialect: explicit config wins; otherwise auto-detect from
262286
// the dbt manifest's `adapter_type` (so a BigQuery/Redshift project isn't
@@ -317,7 +341,12 @@ export async function reviewPullRequest(opts: ReviewPullRequestOptions): Promise
317341
manifestHash: mhash,
318342
modelVersion: opts.modelVersion,
319343
coreVersion: opts.coreVersion,
320-
cliVersion: opts.cliVersion,
344+
// Default cliVersion so agent-invoked callers (dbt_pr_review tool) that
345+
// don't thread the version get the audit-trail field populated too.
346+
// Only the CLI command explicitly forwards Installation.VERSION today,
347+
// so a missing default silently regresses envelope provenance for tool-
348+
// path verdicts (cubic-review PR #1041).
349+
cliVersion: opts.cliVersion ?? Installation.VERSION,
321350
aiReview: opts.noAi || config.ai === false ? undefined : runAiReview,
322351
prTitle: opts.prTitle,
323352
prBody: opts.prBody,

‎script/release-preflight.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,18 @@ async function main(): Promise<void> {
603603
// it only pattern-matches packages/opencode/src/ and can miss unmarked
604604
// changes in other upstream-owned packages. A release machine must have
605605
// the real remote — fail closed.
606+
// altimate_change start — the operator instruction below names the
607+
// upstream repo URL so a release engineer can wire the remote up. The
608+
// branding-audit LEAK_PATTERNS flag this as an upstream reference; it
609+
// is legitimate operational text (an actionable fix hint for the
610+
// failing check), not accidental branding drift. Contained in an
611+
// altimate_change block so the audit skips it.
606612
add({
607613
name: "marker guard",
608614
status: "FAIL",
609615
detail: `upstream remote unavailable — guard ran in degraded pattern-only mode, coverage incomplete.\nAdd it: git remote add upstream https://github.com/anomalyco/opencode.git && git fetch upstream --no-tags\n${fullOutput}`,
610616
})
617+
// altimate_change end
611618
} else {
612619
add({ name: "marker guard", status: "PASS", detail: fullOutput || "no unmarked upstream-shared changes" })
613620
}

0 commit comments

Comments
 (0)