Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b7cfc04
feat: foundation for the dbt Power User tools
hkaltai Nov 13, 2026
1eb722e
Merge remote-tracking branch 'origin/main' into feat/pu-mods-foundation
hkaltai Nov 13, 2026
21d0494
fix: harden the dbt Power User tool foundation
hkaltai Nov 13, 2026
911061d
feat: dbt_defer_state reads the Power User defer setting and the prof…
hkaltai Nov 13, 2026
983309a
fix(tool): dbt_defer_state returns the configured directory while def…
hkaltai Nov 13, 2026
42cb121
Merge branch 'feat/pu-mods-foundation' into feat/dbt-defer-state-tool
hkaltai Nov 13, 2026
f64f065
fix(tool): dbt_defer_state expands the workspace folder to the projec…
hkaltai Nov 13, 2026
83c6711
fix(tool): dbt_defer_state treats an empty settings file as empty and…
hkaltai Nov 14, 2026
510e7be
fix(tool): dbt_defer_state tries the project and workspace paths as g…
hkaltai Nov 14, 2026
77c5748
fix(tool): dbt_defer_state reaches the real-path settings when a file…
hkaltai Nov 14, 2026
046acac
fix(tool): dbt_defer_state handles comment-only settings and symlinke…
hkaltai Nov 15, 2026
2f881ca
fix(tool): env_var defaults may hold the other quote character, a str…
hkaltai Nov 15, 2026
0570fdb
fix(tool): env_var defaults may span lines
hkaltai Nov 15, 2026
d8c3469
fix: send falsy API bodies, follow cancellation in apiRequest, check …
hkaltai Nov 15, 2026
86f4705
fix(tool): drop unused import in dbt_lineage, restore env in the doub…
hkaltai Nov 17, 2026
0d3c995
Merge remote-tracking branch 'origin/main' into feat/dbt-defer-state-…
hkaltai Nov 17, 2026
e2fba06
fix(tool): drop unused projectRoot import in dbt_lineage
hkaltai Nov 17, 2026
dace1c2
Merge remote-tracking branch 'origin/main' into feat/pu-mods-foundation
hkaltai Nov 17, 2026
18a3fc4
fix: keep the stored API key out of API errors, bound the dbt config …
hkaltai Nov 17, 2026
6024ac9
fix: redact the API key when a refused header races the caller's abor…
hkaltai Nov 17, 2026
f5159c5
docs: say which tools use the dbt adapter helper
hkaltai Nov 17, 2026
f57de3d
docs: rewrap and correct the adapter helper comments
hkaltai Nov 17, 2026
77e61ba
Merge origin/feat/pu-mods-foundation into feat/dbt-defer-state-tool
hkaltai Nov 17, 2026
191a968
fix(dbt-defer-state): say when the settings file cannot be read; keep…
hkaltai Nov 17, 2026
01c10b2
fix(dbt-defer-state): keep an unreadable settings file's report when …
hkaltai Nov 17, 2026
a6e0422
fix(dbt-defer-state): a settings file with an unclosed block comment …
hkaltai Nov 17, 2026
3f232ff
fix(dbt-defer-state): use the scan error code, not the const enum
hkaltai Nov 17, 2026
aaff414
fix: never echo a send failure's text, so a trimmed key can't leak
hkaltai Nov 17, 2026
3a98dff
fix: a rejection with no reason is a send failure, not an abort
hkaltai Nov 17, 2026
f258ae8
Merge remote-tracking branch 'origin/feat/pu-mods-foundation' into fe…
hkaltai Nov 17, 2026
099c41b
Merge remote-tracking branch 'origin/main' into feat/dbt-defer-state-…
hkaltai Nov 17, 2026
48a2af7
test(dbt-defer-state): assert the exact unreadable settings file the …
hkaltai Nov 17, 2026
686901d
fix: a TypeError on send names the URL as a possible cause, not only …
hkaltai Nov 17, 2026
0c45619
Merge origin/main into feat/dbt-defer-state-tool
hkaltai Nov 17, 2026
be4fc52
test: the placeholder checks skip dbt_defer_state, which is implemented
hkaltai Nov 17, 2026
7003d2d
fix: a settings BOM, YAML merge keys and an output named default are …
hkaltai Nov 17, 2026
a9a9cfd
fix: a profile target written as an expression this does not evaluate…
hkaltai Nov 17, 2026
1e976bf
refactor: keep the defer-state PR to its own files; no edits to dbt-p…
hkaltai Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
303 changes: 296 additions & 7 deletions packages/opencode/src/altimate/tools/dbt-defer-state.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,305 @@
import z from "zod"
import fs from "fs"
import os from "os"
import path from "path"
import { createScanner, parse as parseJsonc, stripComments, type ParseError } from "jsonc-parser"
import { Tool } from "../../tool/tool"

/** Resolve Jinja `{{ env_var('NAME') }}` and `{{ env_var('NAME', 'default') }}`, in single or double quotes. */
export function resolveEnvVars(value: unknown): unknown {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: These two helpers duplicate packages/opencode/src/altimate/native/connections/dbt-profiles.ts and have already drifted apart.

resolveEnvVars (lines 8-15) is the multi-quote version that used to live in dbt-profiles.ts:56-64; that file's copy now matches single quotes only ('([^']+)'). resolveProfilesPath (lines 17-29) copies dbt-profiles.ts:105-123 minus its DBT_PROFILES_DIR warning. The profile/target resolver and the connection resolver can now answer differently for the same profiles.yml expression (env_var("X", "y") resolves here, not there), and a fix to one never reaches the other. Re-export the existing helpers from dbt-profiles.ts, or move both to a small shared module, instead of carrying a second copy.

if (typeof value !== "string") return value
return value.replace(
/\{\{\s*env_var\s*\(\s*(['"])((?:(?!\1)[\s\S])+)\1\s*(?:,\s*(['"])((?:(?!\3)[\s\S])*)\3\s*)?\)\s*\}\}/g,
(_match, _q1: string, envName: string, _q2?: string, defaultValue?: string) => process.env[envName] ?? defaultValue ?? "",
)
}

/** dbt's profiles.yml lookup: DBT_PROFILES_DIR, then the project folder, then ~/.dbt. */
function resolveProfilesPath(projectDir?: string): string {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This adds a second implementation of the profile-path precedence already in dbt-profiles.ts. Extract the common lookup into one shared helper so profile discovery changes cannot diverge between these callers.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/opencode/src/altimate/tools/dbt-defer-state.ts, line 18:

<comment>This adds a second implementation of the profile-path precedence already in `dbt-profiles.ts`. Extract the common lookup into one shared helper so profile discovery changes cannot diverge between these callers.</comment>

<file context>
@@ -1,9 +1,32 @@
+}
+
+/** dbt's profiles.yml lookup: DBT_PROFILES_DIR, then the project folder, then ~/.dbt. */
+function resolveProfilesPath(projectDir?: string): string {
+  const envDir = process.env.DBT_PROFILES_DIR
+  if (envDir) {
</file context>

const envDir = process.env.DBT_PROFILES_DIR
if (envDir) {
const envPath = path.join(envDir, "profiles.yml")
if (fs.existsSync(envPath)) return envPath
}
if (projectDir) {
const projectPath = path.join(projectDir, "profiles.yml")
if (fs.existsSync(projectPath)) return projectPath
}
return path.join(os.homedir(), ".dbt", "profiles.yml")
}

// The Power User setting this tool reads: `dbt.deferConfigPerProject`, keyed by the dbt project's path
// relative to its workspace folder.
const SETTING = "dbt.deferConfigPerProject"

export interface DeferSetting {
deferToProduction?: boolean
favorState?: boolean
manifestPathForDeferral?: string
manifestPathType?: string
dbtCoreIntegrationId?: string | number
}

export interface DeferStateResult {
enabled: boolean
favorState: boolean
/** "local" | "remote" | "none" (no entry for this project, or a manifest type this tool does not know) */
mode: "local" | "remote" | "none"
/** Directory holding the manifest to defer to; set whenever the configured local one can be used, also while defer is off. */
stateDir?: string
/** Why the configured defer cannot be used: no usable state directory, remote mode, an unknown manifest type, a settings file that cannot be read. */
reason?: string
/** The settings key that matched, relative to the workspace folder. */
settingsKey?: string
settingsFile?: string
profile?: string
defaultTarget?: string
targets: string[]
}

/** Expand `${env:NAME}` and `${workspaceFolder}`; an unset variable is left as written. */
function expandVariables(value: string, workspaceFolder: string): string {
return value
.replace(/\$\{env:(.*?)\}/g, (match, name: string) => process.env[name] ?? match)
.replace(/\$\{workspaceFolder\}/g, () => workspaceFolder)
}

/** A `/* ...` block comment that never closes: stripComments drops it silently, but VS Code cannot read the file. */
function hasUnterminatedComment(text: string): boolean {
const scanner = createScanner(text, false)
while (scanner.scan() !== 17 /* SyntaxKind.EOF */) {
if (scanner.getTokenError() === 1 /* ScanError.UnexpectedEndOfComment */) return true
}
return false
}

const UNREADABLE = Symbol("unreadable settings")

/** The parsed settings; undefined when there is no file, UNREADABLE when there is one that cannot be trusted. */
function readSettings(file: string): Record<string, unknown> | typeof UNREADABLE | undefined {
let text: string
try {
text = fs.readFileSync(file, "utf-8")
} catch (err) {
return (err as NodeJS.ErrnoException).code === "ENOENT" || (err as NodeJS.ErrnoException).code === "ENOTDIR" ? undefined : UNREADABLE
}
// VS Code reads a file with a leading byte order mark as it reads one without.
text = text.replace(/^\uFEFF/, "")
// An empty or whitespace-only file is a settings file with nothing in it.
if (text.trim() === "") return {}
const errors: ParseError[] = []
// .vscode/settings.json allows comments and trailing commas.
const parsed = parseJsonc(text, errors, { allowTrailingComma: true })
// A file that does not parse cannot be trusted to say defer is on.
// A file holding only comments has no value to parse, which VS Code reads as empty settings; a stray token is not that.
if (parsed === undefined && stripComments(text).trim() === "" && !hasUnterminatedComment(text)) return {}
if (errors.length > 0) return UNREADABLE
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return UNREADABLE

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: A settings file that contains only comments parses to undefined with no errors, so this branch classifies it as UNREADABLE and ends the ancestor search — the same failure the whitespace-only check on line 55 was added to prevent. VS Code accepts a comment-only settings.json as empty settings, so a nested project whose own .vscode/settings.json only holds a comment would report defer off even when the workspace folder configures an entry.

Suggested change
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return UNREADABLE
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return parsed === undefined && errors.length === 0 ? {} : UNREADABLE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 046acac: a settings file with only comments (parse error ValueExpected, no value) is read as empty settings, so it no longer ends the ancestor search. Test: 'a settings file holding only a comment does not hide the workspace entry'. I used the error-code check instead of the suggested errors.length === 0, because a comment-only file does report a ValueExpected error.

return parsed as Record<string, unknown>
}

/**
* Find the entry for the project. The workspace folder is the nearest ancestor of the project (or the
* project itself) whose `.vscode/settings.json` has an entry under the project's relative path. A settings
* file that cannot be read or parsed ends the search.
*/
function lookupDeferSetting(projectDir: string, workspaceDir?: string) {
const real = (p: string) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: This real() helper is duplicated verbatim from dbt-adapter-access.ts:90, and the same PR adds isFile/isDirectory as two single-predicate wrappers over the same fs.statSync call. Consolidating them into one shared path helper (e.g. beside Filesystem in src/util/filesystem.ts) keeps the realpath fallback behaviour in one place instead of three.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined as a refactor outside this fix. real() is a four-line realpath fallback and isFile/isDirectory are single-predicate wrappers local to this tool; a shared helper in util/filesystem.ts would touch unrelated files. The duplicated sessionProject (the one that carries policy) is now shared, see the thread on dbt-adapter-access.ts.

try {
return fs.realpathSync(path.resolve(p))
} catch {
return path.resolve(p)
}
}
const search = (start: string, workspace?: string) => {
const candidates: string[] = []
if (workspace) candidates.push(workspace)
else {
for (let dir = start; ; dir = path.dirname(dir)) {
candidates.push(dir)
if (path.dirname(dir) === dir) break
}
}
for (const folder of candidates) {
const file = path.join(folder, ".vscode", "settings.json")
const settings = readSettings(file)
// The nearest settings file that cannot be read ends the search: an outer folder's entry must not stand in for it.
if (settings === UNREADABLE) return { unreadable: file }
const perProject = settings?.[SETTING]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: only <folder>/.vscode/settings.json is read, while Power User reads VS Code's merged configuration. A dbt.deferConfigPerProject in a .code-workspace file or user settings isn't found, and the project gets no --defer. That fails safe, but it's worth listing in Follow-ups.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and it fails safe as you say (no --defer). Only <folder>/.vscode/settings.json is read; a .code-workspace file or user-level setting is not merged. Listed as a follow-up in the PR description.

if (!perProject || typeof perProject !== "object") continue
const key = path.relative(folder, start)
const entry = (perProject as Record<string, unknown>)[key]
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if (entry && typeof entry === "object") {
return { entry: entry as DeferSetting, key, file, folder }
}
// A key naming the project through a symlink: compare the real paths.
const target = real(start)
for (const [k, v] of Object.entries(perProject as Record<string, unknown>)) {
if (!v || typeof v !== "object") continue
if (real(path.resolve(folder, k)) === target) return { entry: v as DeferSetting, key: k, file, folder }
}
}
return undefined
}
// The paths as given first, as VS Code builds the key; then with symlinks followed, for a workspace reached through a link.
const lexical = [path.resolve(projectDir), workspaceDir ? path.resolve(workspaceDir) : undefined] as const
const resolved = [real(projectDir), workspaceDir ? real(workspaceDir) : undefined] as const
const passes = lexical[0] === resolved[0] && lexical[1] === resolved[1] ? [lexical] : [lexical, resolved]
let unreadable: { unreadable: string } | undefined
for (const [start, workspace] of passes) {
const found = search(start, workspace)
// An unreadable file ends the search of its own pass; the pass over the real paths may still reach a readable one.
if (found && typeof found.unreadable === "string") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: The new marker is discriminated three different ways: typeof found.unreadable here, "unreadable" in found in findDeferSetting (line 183) and in resolveDeferState (line 193). The entry member of this inferred union has no unreadable property, so this is the one site that reaches across the union instead of narrowing on it. Using the in check everywhere and passing the marker straight through (unreadable ??= found) also removes the re-wrap of a field that was just tested.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: the lookup result is an inferred union whose entry member has no unreadable property, so in does not narrow it under the type checker (tried it: TS2322). The typeof check stays; it is a style choice, not a defect.

unreadable ??= { unreadable: found.unreadable }
continue
}
if (found) return found
}
return unreadable
}

function profilesFile(projectDir: string): string | undefined {
const file = resolveProfilesPath(projectDir)
return fs.existsSync(file) ? file : undefined
}

async function parseYaml(text: string): Promise<any> {
const mod = await import("yaml")
// dbt reads YAML with PyYAML, which merges `<<` keys.
return (mod.default ?? mod).parse(text, { merge: true })
}

/** The project's profile name, that profile's default `target` and its output names. */
export async function readProfileTargets(projectDir: string) {
const out: { profile?: string; defaultTarget?: string; targets: string[] } = { targets: [] }
try {
const project = await parseYaml(fs.readFileSync(path.join(projectDir, "dbt_project.yml"), "utf-8"))
const profile = resolveEnvVars(project?.profile)
if (typeof profile === "string" && profile !== "") out.profile = profile

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: The unknown-expression guard at line 192 covers target but not profile.

resolveEnvVars does not evaluate {{ var('p') }}, so a profile: written that way is stored verbatim in out.profile and returned in metadata.profile (line 293) - the same "reporting an expression as a name" problem the target guard was added to avoid. Gate it the same way: if (typeof profile === "string" && profile !== "" && !/\{[{%#]/.test(profile)) out.profile = profile. With no profile the function already returns empty targets, so nothing else changes.

} catch {
return out
}
if (!out.profile) return out
const file = profilesFile(projectDir)
if (!file) return out
try {
const profiles = await parseYaml(fs.readFileSync(file, "utf-8"))
const profile = profiles?.[out.profile]
if (profile && typeof profile === "object") {
const target = resolveEnvVars(profile.target)
if (profile.outputs && typeof profile.outputs === "object") out.targets = Object.keys(profile.outputs)
// A target dbt would render from an expression this does not evaluate is unknown, not that text.
if (typeof target === "string" && target !== "" && !/\{[{%#]/.test(target)) out.defaultTarget = target
// With no `target`, dbt runs the output named "default".
else if (profile.target === undefined && out.targets.includes("default")) out.defaultTarget = "default"
}
} catch {
// An unreadable profiles.yml leaves the target unknown.
}
return out
}

function isFile(file: string): boolean {
try {
return fs.statSync(file).isFile()
} catch {
return false
}
}

function isDirectory(dir: string): boolean {
try {
return fs.statSync(dir).isDirectory()
} catch {
return false
}
}

/** The entry for the project; undefined when there is none or the settings file cannot be trusted. */
export function findDeferSetting(projectDir: string, workspaceDir?: string) {
const found = lookupDeferSetting(projectDir, workspaceDir)
return found && "unreadable" in found ? undefined : found
}

export async function resolveDeferState(projectDir: string, workspaceDir?: string): Promise<DeferStateResult> {
const root = path.resolve(projectDir)
const targets = await readProfileTargets(root)
const base: DeferStateResult = { enabled: false, favorState: false, mode: "none", ...targets }
const found = lookupDeferSetting(root, workspaceDir)
if (!found) return base
// Said outright: the same silence as "no setting" would send the caller on without --defer and no one the wiser.
if ("unreadable" in found) return { ...base, settingsFile: found.unreadable, reason: `The settings file could not be read or parsed, so defer is left off: ${found.unreadable}` }

const { entry } = found
const result: DeferStateResult = {
...base,
settingsKey: found.key,
settingsFile: found.file,
favorState: entry.favorState === true,
}
const wanted = entry.deferToProduction === true

// Power User writes "local" or "remote"; an entry without a type is local. Anything else is not understood.
const type = entry.manifestPathType
if (type !== undefined && type !== "" && type !== "local" && type !== "remote") {
return { ...result, reason: `Unknown manifestPathType "${String(type)}": expected "local" or "remote".` }
}
if (type === "remote") {
// The request that downloads the manifest is not implemented, so remote mode cannot supply a state dir.
return { ...result, mode: "remote", reason: "Remote defer mode is not supported yet: download the manifest and use a local path." }
}
result.mode = "local"

// The directory is resolved whether or not defer is on, so a session can still switch it on.
const raw = entry.manifestPathForDeferral
if (typeof raw !== "string" || raw.trim() === "") {
return { ...result, reason: "manifestPathForDeferral is not set." }
}
// Power User expands ${workspaceFolder} to the dbt project's own folder.
const expanded = expandVariables(raw, root)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: ${workspaceFolder} is expanded to projectDir instead of the workspace folder containing the matched settings entry. A root-workspace state path such as ${workspaceFolder}/prod-state therefore becomes /repo/analytics/prod-state and defer is incorrectly reported unavailable; expand with found.folder instead.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At packages/opencode/src/altimate/tools/dbt-defer-state.ts, line 204:

<comment>`${workspaceFolder}` is expanded to `projectDir` instead of the workspace folder containing the matched settings entry. A root-workspace state path such as `${workspaceFolder}/prod-state` therefore becomes `/repo/analytics/prod-state` and defer is incorrectly reported unavailable; expand with `found.folder` instead.</comment>

<file context>
@@ -0,0 +1,250 @@
+    return { ...result, reason: "manifestPathForDeferral is not set." }
+  }
+  // Power User expands ${workspaceFolder} to the dbt project's own folder.
+  const expanded = expandVariables(raw, root)
+  const stateDir = path.isAbsolute(expanded) ? expanded : path.resolve(root, expanded)
+  if (!isDirectory(stateDir)) {
</file context>
Suggested change
const expanded = expandVariables(raw, root)
const expanded = expandVariables(raw, found.folder)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a defect. Power User expands ${workspaceFolder} to the dbt project's own folder, not the folder that holds the settings file, so ${workspaceFolder}/prod-state resolves under the project (dbt-defer-state.ts:197-204, with the comment there). This was matched on purpose in f64f065 and the tests cover it. Leaving it as is.

const stateDir = path.isAbsolute(expanded) ? expanded : path.resolve(root, expanded)
if (!isDirectory(stateDir)) {
return { ...result, reason: `manifestPathForDeferral is not a directory: ${raw}` }
}
if (!isFile(path.join(stateDir, "manifest.json"))) {
return { ...result, reason: `No manifest.json in manifestPathForDeferral: ${raw}` }
}
return { ...result, enabled: wanted, stateDir }
}

export const DbtDeferStateTool = Tool.define("dbt_defer_state", {
description: "dbt Power User's defer-to-production setting for a dbt project, and the profile's default target.",
description:
"Read the dbt Power User defer setting for a dbt project (`dbt.deferConfigPerProject` in .vscode/settings.json) and the project's profile target. Returns whether defer is on, whether to favor state, the state directory to pass as `dbt --defer --state <dir>` (use it only when `enabled` is true), and the profile's default target and target names. Read-only.",
parameters: z.object({
project_dir: z.string().describe("dbt project folder"),
project_dir: z.string().describe("The dbt project directory (the folder holding dbt_project.yml)"),
workspace_dir: z
.string()
.optional()
.describe("The workspace folder that holds .vscode/settings.json (default: the nearest ancestor of project_dir whose settings have an entry for the project)"),
}),
async execute() {
return {
title: "dbt_defer_state: not implemented",
metadata: { success: false, error: "not implemented" },
output: "dbt_defer_state is not implemented in this build of altimate-code yet.",
async execute(args) {
try {
const result = await resolveDeferState(args.project_dir, args.workspace_dir)
const lines = [
`defer: ${result.enabled ? "on" : "off"}${result.favorState ? " (favor state)" : ""}`,
`mode: ${result.mode}`,
]
if (result.stateDir) lines.push(`state dir${result.enabled ? "" : " (not used: defer is off)"}: ${result.stateDir}`)
if (result.reason) lines.push(`note: ${result.reason}`)
if (result.defaultTarget) lines.push(`default target: ${result.defaultTarget}`)
if (result.targets.length) lines.push(`targets: ${result.targets.join(", ")}`)
return {
title: `dbt Defer: ${result.enabled ? "on" : "off"}`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: This tool now answers, so the untouched placeholder test fails and CI goes red.

packages/opencode/test/altimate/dbt-adapter-access.test.ts:85-95 loops every FEATURE_TOOLS entry, which includes dbt_defer_state (line 24), and asserts result.title === "dbt_defer_state: not implemented" plus metadata { success: false, error: "not implemented", truncated: false }. This execute returns dbt Defer: off (or dbt Defer: ERROR) with success: true, so that test fails; CI runs bun test for the whole package (.github/workflows/ci.yml:565). The continue that be4fc52 added for this id was removed in 1e976bf while the test file is not part of this PR's diff. Restore the skip (below the expect(tool.id).toBe(id) check the earlier review asked to keep) or exclude implemented tools from the placeholder loop.

metadata: { success: true, error: undefined as string | undefined, ...result },
output: lines.join("\n"),
}
} catch (e) {
const msg = e instanceof Error ? e.message : String(e)
return {
title: "dbt Defer: ERROR",
metadata: { success: false, error: msg as string | undefined, enabled: false },
output: `Failed: ${msg}`,
}
}
},
})
Loading
Loading