Repository navigation
feat(review): opt-in test-gap check and focused AI batches; verifier reads every changed file #1772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/review-ai-input-coverage
Are you sure you want to change the base?
Changes from all commits
b61b137
6246b73
9f1e172
2a4a0ec
0a962cc
6c738ff
323128c
3462454
5021141
a7fe84b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,9 +19,16 @@ import type { Finding } from "./finding" | |
| import { type AiReviewFile, type AiTokens, type BatchUsage, addUsage, aiTimeoutMs, streamUsage } from "./ai-review" | ||
| import { type ReviewRunner, scanDiffLines, walkDiffLines } from "./orchestrate" | ||
| import { readStreamStep, type StepToolCall } from "../llm/stream-text" | ||
| import { isCredentialPath } from "./credentials" | ||
|
|
||
| const log = Log.create({ service: "ai-verify" }) | ||
|
|
||
| // The verifier refuses a file that may hold credentials: by name (its path or, for a rename, its | ||
| // old path; a working-tree symlink's target) on both sides of `read_file` and `compiled_sql` and in | ||
| // `grep_project` hits; by content (private keys, service-account keys) in `read_file`, `compiled_sql` | ||
| // and every file `grep_project` would show. The AI lane never gets such a file, nor one whose diff holds a key. | ||
| export { holdsCredentials, isCredentialPath } from "./credentials" | ||
|
|
||
| /** What the verifier may read: the PR's files, the engine, and the dbt project. */ | ||
| export interface AiVerifyEvidence { | ||
| dialect?: string | ||
|
|
@@ -41,6 +48,8 @@ export interface AiVerifyEvidence { | |
| prBody?: string | ||
| /** Head-side line numbers each changed file adds (see `addedLinesByFile`). */ | ||
| addedLines: Map<string, Set<number>> | ||
| /** Every file the PR changes, repo-relative, including tests and CI outside the dbt project. */ | ||
| prFiles?: string[] | ||
| } | ||
|
|
||
| export type Decision = "keep" | "discard" | "summary" | ||
|
|
@@ -382,12 +391,27 @@ export function hunkAround(diff: string | undefined, line?: number): string { | |
| : text || "(the line is outside the diff)" | ||
| } | ||
|
|
||
| /** Most PR file paths listed in a verifier message. */ | ||
| const PR_FILES_MAX = 40 | ||
|
|
||
| /** The user message for one batch: the PR title and each candidate with its hunk. Not the whole file, not the grounding. */ | ||
| export function buildVerifyMessage( | ||
| prTitle: string | undefined, | ||
| candidates: Array<{ id: string; finding: Finding; diff?: string }>, | ||
| prFiles: string[] = [], | ||
| ): string { | ||
| const parts = [`PR: ${(prTitle ?? "(untitled)").slice(0, 200)}`, "", "Candidates:"] | ||
| const parts = [`PR: ${(prTitle ?? "(untitled)").slice(0, 200)}`] | ||
| // A test-coverage claim is checked against the PR's own test files, which may sit outside the dbt project. | ||
| if (prFiles.length && candidates.some((c) => c.finding.category === "test_coverage")) { | ||
| const shown = prFiles.slice(0, PR_FILES_MAX) | ||
| parts.push( | ||
| "", | ||
| "Files this PR changes (read_file can open any of them):", | ||
| ...shown.map((p) => `- ${p}`), | ||
| ...(prFiles.length > shown.length ? [`- … and ${prFiles.length - shown.length} more`] : []), | ||
| ) | ||
| } | ||
| parts.push("", "Candidates:") | ||
| for (const { id, finding: f, diff } of candidates) { | ||
| parts.push( | ||
| "", | ||
|
|
@@ -784,8 +808,9 @@ export function verifierTools( | |
| ...ev.addedLines.keys(), | ||
| ...graph.parents.map((p) => p.path), | ||
| ...graph.downstream.map((d) => d.path), | ||
| ...(ev.prFiles ?? []), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The verifier's read allowlist now includes every PR file, including paths the user excluded with Prompt for AI agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 31cb5c4: |
||
| ]), | ||
| ] | ||
| ].filter((p) => !isCredentialPath(p)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MAJOR] Credential check only covers the new path; renames and symlinks still reach the model ].filter((p) => !isCredentialPath(p))The filter is applied to the name the PR shows, not to what is read for it. Reproduced with the real resolver on a temp repo:
With Fix: check the resolved identity, not only the requested name. In the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. The verifier wrappers now check the path actually read: on the old side
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| /** A requested path inside the review scope, as the repo-relative path to read; a project-relative path resolves too. */ | ||
| const resolve = (p: unknown): string | undefined => { | ||
| const want = String(p ?? "").replace(/^\.?\/+/, "") | ||
|
|
@@ -799,11 +824,11 @@ export function verifierTools( | |
| graph.parents.find((p) => p.name === name && (p.kind === "model" || p.kind === "snapshot"))?.path ?? | ||
| graph.downstream.find((d) => d.name === name)?.path | ||
| const side = z.enum(["old", "new"]).optional().describe("old=base, new=head (default)") | ||
| const scope = NA("outside review scope (changed files, their dbt parents and direct downstream models only)") | ||
| const scope = NA("outside review scope (files the PR changes, their dbt parents and direct downstream models only)") | ||
|
|
||
| return { | ||
| read_file: { | ||
| description: "Up to 200 numbered lines of a changed file, its dbt parents or direct children.", | ||
| description: "Up to 200 numbered lines of any file the PR changes (tests and CI included), a dbt parent or direct child.", | ||
| input: z.object({ | ||
| path: z.string(), | ||
| side, | ||
|
|
@@ -920,8 +945,9 @@ export function verifierTools( | |
| async run({ pattern, glob }) { | ||
| if (!ev.grepProject) return NA("project search unavailable") | ||
| if (String(pattern).length < 2) return NA("pattern needs at least 2 characters") | ||
| const hits = await ev.grepProject(String(pattern), glob as string | undefined) | ||
| if (!hits) return NA("the search failed (git error, timeout, or a glob outside the project); this is not evidence of absence") | ||
| const found = await ev.grepProject(String(pattern), glob as string | undefined) | ||
| if (!found) return NA("the search failed (git error, timeout, or a glob outside the project); this is not evidence of absence") | ||
| const hits = found.filter((h) => !isCredentialPath(h.path)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MINOR] Git-quoted filenames slip past the grep credential filter const hits = found.filter((h) => !isCredentialPath(h.path))
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switched
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Fixed —
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MINOR] The content guard is not applied to const hits = found.filter((h) => !isCredentialPath(h.path))
Fix: make
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 140737c. I went with the whole-file check: the evidence
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return hits.length ? hits.map((h) => `${h.path}:${h.line}: ${h.text}`).join("\n") : "no matches" | ||
| }, | ||
| }, | ||
|
|
@@ -1176,6 +1202,7 @@ export async function runAiVerify( | |
| finding: input.findings[i], | ||
| diff: fileByPath.get(input.findings[i].file)?.diff, | ||
| })), | ||
| ev.prFiles, | ||
| ) | ||
| return { idx, ids, message } | ||
| }) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||
| // Connection profiles, env files, package-registry, git, cloud, Docker and Kubernetes credential | ||||||
| // stores, service-account and OAuth client keys, key material and Terraform variables. Matched on the file name. | ||||||
| const CREDENTIAL_FILE = new RegExp( | ||||||
| "(^|/)(" + | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MINOR] Name list still misses common credential stores "profiles\\.ya?ml",
Fix: add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Fixed — every name from the report is matched ( |
||||||
| [ | ||||||
| // profiles.yml, dbt_profiles.yml, profiles-ci.yml, profiles.yml.example; not a model's | ||||||
| // schema file such as customer_profiles.yml | ||||||
| "(dbt[_-]?)?profiles([._-][^/]*)?\\.ya?ml(\\.[^/]*)?", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [MINOR] Name list: schema files hidden, other credential stores still missed "(dbt[_-]?)?profiles([._-][^/]*)?\\.ya?ml(\\.[^/]*)?",All listed names from the earlier review are covered. Two follow-ups, checked with
Fix: restrict the |
||||||
| "\\.env[^/]*", // .env, .env.local, .env-prod, .envrc | ||||||
| "[^/]+\\.env", // prod.env | ||||||
| "\\.netrc", | ||||||
| "\\.pgpass", | ||||||
| "\\.npmrc", | ||||||
| "\\.pypirc", | ||||||
| "\\.git-credentials", | ||||||
| "id_(rsa|dsa|ecdsa|ed25519)", | ||||||
| "keyfile[^/]*\\.json", | ||||||
| "[^/]*service[^/]*account[^/]*\\.json", | ||||||
| "credentials[^/]*\\.json", | ||||||
| "\\.aws/credentials", | ||||||
| "\\.docker/config\\.json", | ||||||
| "kubeconfig", | ||||||
| "secrets?\\.(ya?ml|json)", | ||||||
| "client_secret[^/]*\\.json", | ||||||
| "[^/]+\\.(pem|key|p12|pfx|p8|tfvars|tfvars\\.json)", | ||||||
| ].join("|") + | ||||||
| ")$", | ||||||
| "i", | ||||||
| ) | ||||||
|
|
||||||
| /** | ||||||
| * A path whose name says it may hold credentials. A changed file named so, now or before a | ||||||
| * rename, is not sent to the AI lane, and the verifier neither reads it (either side) nor shows its grep hits. | ||||||
| */ | ||||||
| export function isCredentialPath(path: string): boolean { | ||||||
| return CREDENTIAL_FILE.test(path) | ||||||
| } | ||||||
|
|
||||||
| const CREDENTIAL_CONTENT = /-----BEGIN (?:[A-Z0-9 ]* )?PRIVATE KEY(?: BLOCK)?-----|"type"\s*:\s*"service_account"/ | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: the content guard misses age/SOPS secret keys
Suggested change
|
||||||
|
|
||||||
| /** Text that carries a private key (PEM, OpenSSH or PGP armor) or a cloud service-account key, whatever the file is called. */ | ||||||
| export function holdsCredentials(text: string): boolean { | ||||||
| return CREDENTIAL_CONTENT.test(text) | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -991,7 +991,9 @@ export function redundantJoinPredicates(sql: string): string[] { | |||||
| } else if (rel) i += rel[0].length | ||||||
| const tail = /^\s+(?:as\s+)?(\w+)\s+on\b/i.exec(s.slice(i)) ?? /^\s+on\b/i.exec(s.slice(i)) | ||||||
| if (!tail) { | ||||||
| joins.push({ preds: [], start: m.index!, end: i, inner, outer }) | ||||||
| // A join with no ON (`cross join params as p`): step over its alias so the chain continues. | ||||||
| const bare = /^\s+(?:as\s+)?(?!(?:natural|inner|left|right|full|cross|outer|join|lateral|on|using|where|group|order|qualify|having|union|limit|window|select|from)\b)\w+\b/i.exec(s.slice(i)) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: A Prompt for AI agents
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow-up: low priority, tracked. The result is a missed redundant predicate, never a false one. |
||||||
| joins.push({ preds: [], start: m.index!, end: i + (bare?.[0].length ?? 0), inner, outer }) | ||||||
| continue | ||||||
| } | ||||||
| const fallback = rel?.[1].split(".").pop()?.toLowerCase() | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The verifier cannot discover changed files after the first 40 paths, so a test added at path 41+ can be missed by the test-gap check; add a bounded file-list tool or otherwise expose all paths to the verifier.
Prompt for AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as r4627044412; tracked.