From 137a48e7372e95dda525a078b0db7ea93c6ab1ba Mon Sep 17 00:00:00 2001 From: "Ralph Sto. Domingo" Date: Mon, 16 Nov 2026 21:32:29 +0800 Subject: [PATCH 1/4] fix(dbt-tools): run dbt Fusion without Python and pin the stale-manifest fixes Fusion's prerequisite check looks for a dbt 2.x binary instead of Python and dbt-core. An e2e test pins isExternalProject on a stale manifest; the skill references and the stale note follow. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VEmKQx8gR7vd6ettA3mWjP --- .../references/altimate-dbt-commands.md | 2 + .../references/altimate-dbt-commands.md | 2 + .../references/altimate-dbt-commands.md | 2 + .../references/altimate-dbt-commands.md | 2 + .../references/altimate-dbt-commands.md | 2 + .../references/altimate-dbt-commands.md | 2 + packages/dbt-tools/package.json | 2 +- packages/dbt-tools/src/adapter.ts | 3 +- packages/dbt-tools/src/check.ts | 37 ++++++- packages/dbt-tools/test/check.test.ts | 101 ++++++++++++++++++ .../dbt-tools/test/e2e/dbt-versions.test.ts | 24 ++++- .../altimate/validators/dbt-schema-verify.ts | 5 +- .../dbt-schema-verify-stale.test.ts | 54 +++++++++- 13 files changed, 226 insertions(+), 12 deletions(-) create mode 100644 packages/dbt-tools/test/check.test.ts diff --git a/.opencode/skills/dbt-analyze/references/altimate-dbt-commands.md b/.opencode/skills/dbt-analyze/references/altimate-dbt-commands.md index 8109ac84d2..6f3a2a2268 100644 --- a/.opencode/skills/dbt-analyze/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-analyze/references/altimate-dbt-commands.md @@ -49,6 +49,8 @@ altimate-dbt children --model # downstream models altimate-dbt parents --model # upstream models ``` +When the project check fails (a broken profile, a missing env var), `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from the last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. + ## Packages ```bash diff --git a/.opencode/skills/dbt-develop/references/altimate-dbt-commands.md b/.opencode/skills/dbt-develop/references/altimate-dbt-commands.md index 8109ac84d2..6f3a2a2268 100644 --- a/.opencode/skills/dbt-develop/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-develop/references/altimate-dbt-commands.md @@ -49,6 +49,8 @@ altimate-dbt children --model # downstream models altimate-dbt parents --model # upstream models ``` +When the project check fails (a broken profile, a missing env var), `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from the last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. + ## Packages ```bash diff --git a/.opencode/skills/dbt-docs/references/altimate-dbt-commands.md b/.opencode/skills/dbt-docs/references/altimate-dbt-commands.md index 8109ac84d2..6f3a2a2268 100644 --- a/.opencode/skills/dbt-docs/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-docs/references/altimate-dbt-commands.md @@ -49,6 +49,8 @@ altimate-dbt children --model # downstream models altimate-dbt parents --model # upstream models ``` +When the project check fails (a broken profile, a missing env var), `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from the last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. + ## Packages ```bash diff --git a/.opencode/skills/dbt-test/references/altimate-dbt-commands.md b/.opencode/skills/dbt-test/references/altimate-dbt-commands.md index 8109ac84d2..6f3a2a2268 100644 --- a/.opencode/skills/dbt-test/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-test/references/altimate-dbt-commands.md @@ -49,6 +49,8 @@ altimate-dbt children --model # downstream models altimate-dbt parents --model # upstream models ``` +When the project check fails (a broken profile, a missing env var), `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from the last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. + ## Packages ```bash diff --git a/.opencode/skills/dbt-troubleshoot/references/altimate-dbt-commands.md b/.opencode/skills/dbt-troubleshoot/references/altimate-dbt-commands.md index 8109ac84d2..6f3a2a2268 100644 --- a/.opencode/skills/dbt-troubleshoot/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-troubleshoot/references/altimate-dbt-commands.md @@ -49,6 +49,8 @@ altimate-dbt children --model # downstream models altimate-dbt parents --model # upstream models ``` +When the project check fails (a broken profile, a missing env var), `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from the last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. + ## Packages ```bash diff --git a/.opencode/skills/dbt-unit-tests/references/altimate-dbt-commands.md b/.opencode/skills/dbt-unit-tests/references/altimate-dbt-commands.md index 8109ac84d2..6f3a2a2268 100644 --- a/.opencode/skills/dbt-unit-tests/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-unit-tests/references/altimate-dbt-commands.md @@ -49,6 +49,8 @@ altimate-dbt children --model # downstream models altimate-dbt parents --model # upstream models ``` +When the project check fails (a broken profile, a missing env var), `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from the last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. + ## Packages ```bash diff --git a/packages/dbt-tools/package.json b/packages/dbt-tools/package.json index 66639efd2f..b033a26257 100644 --- a/packages/dbt-tools/package.json +++ b/packages/dbt-tools/package.json @@ -9,7 +9,7 @@ "scripts": { "build": "bun build src/index.ts --outdir dist --target node --format esm && bun run script/copy-python.ts", "typecheck": "tsc --noEmit", - "test": "bun test test/cli.test.ts test/config.test.ts test/dbt-cli.test.ts test/dbt-resolve.test.ts test/adapter-bun.test.ts test/stale-manifest.test.ts test/build-integrity.test.ts --timeout 30000", + "test": "bun test test/check.test.ts test/cli.test.ts test/config.test.ts test/dbt-cli.test.ts test/dbt-resolve.test.ts test/adapter-bun.test.ts test/stale-manifest.test.ts test/build-integrity.test.ts --timeout 30000", "test:e2e": "bun test test/e2e/ --timeout 300000" }, "dependencies": { diff --git a/packages/dbt-tools/src/adapter.ts b/packages/dbt-tools/src/adapter.ts index 706d43ad6c..250f0f2611 100644 --- a/packages/dbt-tools/src/adapter.ts +++ b/packages/dbt-tools/src/adapter.ts @@ -84,7 +84,8 @@ function terminal(): DBTTerminal { function env(cfg: Config): RuntimePythonEnvironment { const vars = { ...process.env } return { - pythonPath: cfg.pythonPath, + // A Fusion config may have none: dbt-integration runs Fusion with an empty one. + pythonPath: cfg.pythonPath ?? "", getEnvironmentVariables: () => vars, } } diff --git a/packages/dbt-tools/src/check.ts b/packages/dbt-tools/src/check.ts index 4e5c4d2290..7e3144fd81 100644 --- a/packages/dbt-tools/src/check.ts +++ b/packages/dbt-tools/src/check.ts @@ -39,12 +39,39 @@ function project(root: string): Status { return { ok: true } } -export async function all(cfg: Config) { - const checks = { - python: await python(cfg.pythonPath), - dbt: cfg.pythonPath && existsSync(cfg.pythonPath) ? await dbt(cfg.pythonPath) : { ok: false as const, error: "Skipped (Python not found)", fix: "Fix Python first" }, - project: project(cfg.projectRoot), +type FusionLookup = { pythonPath?: string; cwd?: string; env?: Record } + +/** How the Fusion check finds dbt: dbt-integration's own lookup, loaded only in Fusion mode. + * A field so tests can replace it. */ +export const fusionBinary = { + find: async (options: FusionLookup) => (await import("@altimateai/dbt-integration")).findDbtV2Binary(options), +} + +async function fusion(cfg: Config): Promise { + const binary = await fusionBinary.find({ + pythonPath: cfg.pythonPath || undefined, + cwd: cfg.projectRoot || undefined, + env: process.env, + }) + if (binary) return { ok: true } + const nextTo = cfg.pythonPath ? `next to ${cfg.pythonPath}, ` : "" + return { + ok: false, + error: `dbt Fusion was not found: no dbt 2.x binary ${nextTo}in ~/.local/bin or on PATH`, + fix: "Install dbt Fusion so that `dbt --version` reports 2.x, or set dbtIntegration to core in the altimate-dbt config", } +} + +export async function all(cfg: Config) { + // dbt Fusion is a native binary: it needs no Python, and no dbt-core in one. + const checks: Record = + cfg.dbtIntegration === "fusion" + ? { fusion: await fusion(cfg), project: project(cfg.projectRoot) } + : { + python: await python(cfg.pythonPath), + dbt: cfg.pythonPath && existsSync(cfg.pythonPath) ? await dbt(cfg.pythonPath) : { ok: false as const, error: "Skipped (Python not found)", fix: "Fix Python first" }, + project: project(cfg.projectRoot), + } const passed = Object.values(checks).every((c) => c.ok) return { passed, checks } } diff --git a/packages/dbt-tools/test/check.test.ts b/packages/dbt-tools/test/check.test.ts new file mode 100644 index 0000000000..c19054e5e3 --- /dev/null +++ b/packages/dbt-tools/test/check.test.ts @@ -0,0 +1,101 @@ +import { afterEach, describe, expect, test } from "bun:test" +import { mkdtempSync, rmSync, writeFileSync } from "fs" +import { tmpdir } from "os" +import { join } from "path" +import { all, fusionBinary, validate } from "../src/check" +import type { Config } from "../src/config" + +// dbt Fusion is a native binary, so a Fusion user may have no Python at all. The lookup for a +// dbt 2.x binary is replaced here; the real one is dbt-integration's `findDbtV2Binary`. +const realFind = fusionBinary.find +const dirs: string[] = [] + +afterEach(() => { + fusionBinary.find = realFind + for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true }) +}) + +function project(): string { + const dir = mkdtempSync(join(tmpdir(), "dbt-check-")) + dirs.push(dir) + writeFileSync(join(dir, "dbt_project.yml"), "name: p\n") + return dir +} + +function config(overrides: Partial): Config { + return { projectRoot: project(), pythonPath: "", dbtIntegration: "fusion", queryLimit: 500, ...overrides } +} + +const FUSION = { path: "/home/u/.local/bin/dbt", version: [2, 0, 9], location: "installer" as const } + +describe("prerequisites in dbt Fusion mode", () => { + test("need no Python when a dbt 2.x binary resolves", async () => { + const asked: unknown[] = [] + fusionBinary.find = async (options) => { + asked.push(options) + return FUSION + } + const cfg = config({}) + + const result = await all(cfg) + + expect(result.passed).toBe(true) + expect(Object.keys(result.checks).sort()).toEqual(["fusion", "project"]) + expect(asked[0]).toMatchObject({ pythonPath: undefined, cwd: cfg.projectRoot }) + expect(await validate(cfg)).toBeNull() + }) + + test("need no Python path in the config at all", async () => { + fusionBinary.find = async () => FUSION + const cfg = config({}) + delete (cfg as Partial).pythonPath + + expect((await all(cfg)).passed).toBe(true) + }) + + test("look for dbt next to a given interpreter, which needn't exist", async () => { + const asked: unknown[] = [] + fusionBinary.find = async (options) => { + asked.push(options) + return FUSION + } + + const result = await all(config({ pythonPath: "/no/venv/bin/python" })) + + expect(result.passed).toBe(true) + expect(asked[0]).toMatchObject({ pythonPath: "/no/venv/bin/python" }) + }) + + test("fail, and say where they looked, when no dbt 2.x binary resolves", async () => { + fusionBinary.find = async () => undefined + + const issue = await validate(config({})) + + expect(issue).toContain("Prerequisites not met") + expect(issue).toContain("fusion: dbt Fusion was not found: no dbt 2.x binary in ~/.local/bin or on PATH") + }) + + test("still require the project", async () => { + fusionBinary.find = async () => FUSION + + const result = await all(config({ projectRoot: "/definitely/not/a/project" })) + + expect(result.passed).toBe(false) + expect(result.checks.project?.ok).toBe(false) + }) +}) + +describe("prerequisites in other modes", () => { + test("still require Python and dbt-core, and never look for Fusion", async () => { + fusionBinary.find = async () => { + throw new Error("the Fusion lookup must not run outside Fusion mode") + } + + for (const dbtIntegration of ["core", "corecommand", "cloud"]) { + const result = await all(config({ dbtIntegration })) + expect(result.passed).toBe(false) + expect(Object.keys(result.checks).sort()).toEqual(["dbt", "project", "python"]) + expect(result.checks).toMatchObject({ python: { ok: false, error: "No Python path configured" } }) + } + }) +}) diff --git a/packages/dbt-tools/test/e2e/dbt-versions.test.ts b/packages/dbt-tools/test/e2e/dbt-versions.test.ts index a90586f872..716c91746f 100644 --- a/packages/dbt-tools/test/e2e/dbt-versions.test.ts +++ b/packages/dbt-tools/test/e2e/dbt-versions.test.ts @@ -20,7 +20,7 @@ import { describe, test, expect, beforeAll, afterAll } from "bun:test" import { execFileSync, execSync } from "child_process" -import { existsSync, mkdtempSync, cpSync, rmSync, readdirSync } from "fs" +import { existsSync, mkdtempSync, cpSync, rmSync, readdirSync, readFileSync, writeFileSync } from "fs" import { join, resolve } from "path" import { tmpdir } from "os" @@ -400,6 +400,28 @@ describe.skipIf(!HAS_DBT)("altimate-dbt e2e", () => { // ----- dbt ls / children / parents ----- describe("graph (children/parents)", () => { + test( + "on a stale manifest, children answer from the last successful parse and mark no model external", + () => { + // Rename the profile so the project check fails. The build left target/manifest.json, + // so the answer comes from it: { stale_manifest, models }. Its nodes belong to this + // project, so none may be marked as an external project. + const profiles = join(workDir, "profiles.yml") + const original = readFileSync(profiles, "utf-8") + writeFileSync(profiles, original.replace(/^test_jaffle_shop:/m, "test_jaffle_shop_renamed:")) + try { + const out = altDbt(version.pythonPath, workDir, ["children", "--model", "stg_customers"]) + expect(out.stale_manifest).toBeDefined() + const labels = (out.models ?? []).map((m: { label: string }) => m.label) + expect(labels).toContain("customers") + expect(out.models.every((m: { isExternalProject: boolean }) => m.isExternalProject === false)).toBe(true) + } finally { + writeFileSync(profiles, original) + } + }, + TEST_TIMEOUT, + ) + test( "dbt ls lists models", () => { diff --git a/packages/opencode/src/altimate/validators/dbt-schema-verify.ts b/packages/opencode/src/altimate/validators/dbt-schema-verify.ts index df629694df..aae25dfa80 100644 --- a/packages/opencode/src/altimate/validators/dbt-schema-verify.ts +++ b/packages/opencode/src/altimate/validators/dbt-schema-verify.ts @@ -149,7 +149,10 @@ function formatFixHint(mismatches: SchemaVerifyOutput[]): string { function leadWithStaleManifestNote(results: SchemaVerifyOutput[], hint: string): string { const stale = results.find((r) => r.stale_manifest)?.stale_manifest if (!stale) return hint - const written = typeof stale.written_at === "string" ? ` (written ${sanitizeForPrompt(stale.written_at, 40)})` : "" + const written = + typeof stale.written_at === "string" && stale.written_at.trim() + ? ` (written ${sanitizeForPrompt(stale.written_at, 40)})` + : "" return `The dbt project check failed, so schema-verify read the manifest of the last successful parse${written}. Its spec may not match schema.yml as it is now.\n\n${hint}` } diff --git a/packages/opencode/test/altimate/validators/dbt-schema-verify-stale.test.ts b/packages/opencode/test/altimate/validators/dbt-schema-verify-stale.test.ts index efbcf47aeb..f2c3dbda38 100644 --- a/packages/opencode/test/altimate/validators/dbt-schema-verify-stale.test.ts +++ b/packages/opencode/test/altimate/validators/dbt-schema-verify-stale.test.ts @@ -24,11 +24,17 @@ const MISMATCH = { columns_reordered: [], type_mismatches: [], } +// The validator's message for MISMATCH on a current manifest, as before the stale note existed. +const CURRENT_REASON = + "1 of 1 models you edited have a column-shape mismatch against schema.yml: orders. The build may be green, but equality tests will fail." +const CURRENT_FIX_HINT = + "Model `orders`:\n • Columns in your model NOT in spec — REMOVE: note\n\nFix the model SQL to match the schema.yml spec (do not edit the spec), rebuild, and the harness will re-check before declaring done." const NOTE_START = "The dbt project check failed, so schema-verify read the manifest of the last successful parse" let root: string let project: string let answerFile: string +let answersDir: string let originalPath: string beforeAll(async () => { @@ -36,7 +42,14 @@ beforeAll(async () => { const bin = join(root, "bin") await fs.mkdir(bin) answerFile = join(root, "answer.json") - await fs.writeFile(join(bin, "altimate-dbt"), `#!/bin/sh\ncat "${answerFile}"\n`, { mode: 0o755 }) + answersDir = join(root, "answers") + await fs.mkdir(answersDir) + // Called as `altimate-dbt schema-verify --model `: answers/.json when there is one. + await fs.writeFile( + join(bin, "altimate-dbt"), + `#!/bin/sh\nif [ -f "${answersDir}/$3.json" ]; then cat "${answersDir}/$3.json"; else cat "${answerFile}"; fi\n`, + { mode: 0o755 }, + ) originalPath = process.env.PATH ?? "" process.env.PATH = `${bin}:${originalPath}` project = join(root, "project") @@ -51,6 +64,9 @@ afterAll(async () => { afterEach(async () => { await fs.rm(answerFile, { force: true }) + await fs.rm(answersDir, { recursive: true, force: true }) + await fs.mkdir(answersDir) + await fs.rm(join(project, "models", "customers.sql"), { force: true }) }) /** Runs the validator over one model edited this session, with `answer` as schema-verify's answer. */ @@ -82,10 +98,42 @@ describe("dbt-schema-verify on a stale manifest", () => { expect(result.fixHint).toContain("altimate-dbt schema-verify ") }) - test("a current manifest's message has no note", async () => { + test("a current manifest's message is the message from before the note", async () => { const result = await check(MISMATCH) expect(result.ok).toBe(false) - expect(result.fixHint).not.toContain(NOTE_START) + expect(result.reason).toBe(CURRENT_REASON) + expect(result.fixHint).toBe(CURRENT_FIX_HINT) + }) + + test("the note only leads the message, which is otherwise the same", async () => { + const stale = await check({ stale_manifest: STALE, ...MISMATCH }) + expect(stale.reason).toBe(CURRENT_REASON) + expect(stale.fixHint).toBe( + `${NOTE_START} (written «${WRITTEN_AT}»). Its spec may not match schema.yml as it is now.\n\n${CURRENT_FIX_HINT}`, + ) + }) + + test("a parse time that isn't a non-empty string is left out", async () => { + for (const written_at of ["", " ", 1731744000, null, { at: WRITTEN_AT }, [WRITTEN_AT]]) { + const result = await check({ stale_manifest: { written_at }, ...MISMATCH }) + expect(result.fixHint?.split("\n\n")[0]).toBe( + `${NOTE_START}. Its spec may not match schema.yml as it is now.`, + ) + } + }) + + test("one stale answer among current ones still leads with the note, once", async () => { + await fs.writeFile(join(answersDir, "orders.json"), JSON.stringify({ stale_manifest: STALE, ...MISMATCH })) + await fs.writeFile( + join(answersDir, "customers.json"), + JSON.stringify({ ...MISMATCH, model: "customers", columns_extra: ["tier"] }), + ) + await fs.writeFile(join(project, "models", "customers.sql"), "select 1 as id, 2 as tier\n") + const result = await check({}) + expect(result.fixHint?.startsWith(`${NOTE_START} (written «${WRITTEN_AT}»).`)).toBe(true) + expect(result.fixHint?.split(NOTE_START).length).toBe(2) + expect(result.fixHint).toContain("REMOVE: note") + expect(result.fixHint).toContain("REMOVE: tier") }) test("the parse time is quoted on one line, whatever the answer carries", async () => { From 56ff802a7fcd93f9c7f3806d0c577bc9387a55ab Mon Sep 17 00:00:00 2001 From: "Ralph Sto. Domingo" Date: Tue, 17 Nov 2026 11:46:50 +0800 Subject: [PATCH 2/4] test(dbt-tools): pin the dbt-core check outside Fusion, and qualify the stale note A stand-in Python without dbt-core shows core modes still require it, and Fusion's message names the interpreter it looked next to. The skill references say the stale answer needs an earlier manifest. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VEmKQx8gR7vd6ettA3mWjP --- .../references/altimate-dbt-commands.md | 2 +- .../references/altimate-dbt-commands.md | 2 +- .../references/altimate-dbt-commands.md | 2 +- .../references/altimate-dbt-commands.md | 2 +- .../references/altimate-dbt-commands.md | 2 +- .../references/altimate-dbt-commands.md | 2 +- packages/dbt-tools/test/check.test.ts | 41 +++++++++++++++++-- 7 files changed, 43 insertions(+), 10 deletions(-) diff --git a/.opencode/skills/dbt-analyze/references/altimate-dbt-commands.md b/.opencode/skills/dbt-analyze/references/altimate-dbt-commands.md index 6f3a2a2268..6bdd9f694b 100644 --- a/.opencode/skills/dbt-analyze/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-analyze/references/altimate-dbt-commands.md @@ -49,7 +49,7 @@ altimate-dbt children --model # downstream models altimate-dbt parents --model # upstream models ``` -When the project check fails (a broken profile, a missing env var), `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from the last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. +When the project check fails (a broken profile, a missing env var) and an earlier parse left a manifest, `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from that last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. With no earlier manifest they answer an error. ## Packages diff --git a/.opencode/skills/dbt-develop/references/altimate-dbt-commands.md b/.opencode/skills/dbt-develop/references/altimate-dbt-commands.md index 6f3a2a2268..6bdd9f694b 100644 --- a/.opencode/skills/dbt-develop/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-develop/references/altimate-dbt-commands.md @@ -49,7 +49,7 @@ altimate-dbt children --model # downstream models altimate-dbt parents --model # upstream models ``` -When the project check fails (a broken profile, a missing env var), `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from the last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. +When the project check fails (a broken profile, a missing env var) and an earlier parse left a manifest, `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from that last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. With no earlier manifest they answer an error. ## Packages diff --git a/.opencode/skills/dbt-docs/references/altimate-dbt-commands.md b/.opencode/skills/dbt-docs/references/altimate-dbt-commands.md index 6f3a2a2268..6bdd9f694b 100644 --- a/.opencode/skills/dbt-docs/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-docs/references/altimate-dbt-commands.md @@ -49,7 +49,7 @@ altimate-dbt children --model # downstream models altimate-dbt parents --model # upstream models ``` -When the project check fails (a broken profile, a missing env var), `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from the last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. +When the project check fails (a broken profile, a missing env var) and an earlier parse left a manifest, `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from that last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. With no earlier manifest they answer an error. ## Packages diff --git a/.opencode/skills/dbt-test/references/altimate-dbt-commands.md b/.opencode/skills/dbt-test/references/altimate-dbt-commands.md index 6f3a2a2268..6bdd9f694b 100644 --- a/.opencode/skills/dbt-test/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-test/references/altimate-dbt-commands.md @@ -49,7 +49,7 @@ altimate-dbt children --model # downstream models altimate-dbt parents --model # upstream models ``` -When the project check fails (a broken profile, a missing env var), `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from the last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. +When the project check fails (a broken profile, a missing env var) and an earlier parse left a manifest, `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from that last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. With no earlier manifest they answer an error. ## Packages diff --git a/.opencode/skills/dbt-troubleshoot/references/altimate-dbt-commands.md b/.opencode/skills/dbt-troubleshoot/references/altimate-dbt-commands.md index 6f3a2a2268..6bdd9f694b 100644 --- a/.opencode/skills/dbt-troubleshoot/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-troubleshoot/references/altimate-dbt-commands.md @@ -49,7 +49,7 @@ altimate-dbt children --model # downstream models altimate-dbt parents --model # upstream models ``` -When the project check fails (a broken profile, a missing env var), `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from the last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. +When the project check fails (a broken profile, a missing env var) and an earlier parse left a manifest, `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from that last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. With no earlier manifest they answer an error. ## Packages diff --git a/.opencode/skills/dbt-unit-tests/references/altimate-dbt-commands.md b/.opencode/skills/dbt-unit-tests/references/altimate-dbt-commands.md index 6f3a2a2268..6bdd9f694b 100644 --- a/.opencode/skills/dbt-unit-tests/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-unit-tests/references/altimate-dbt-commands.md @@ -49,7 +49,7 @@ altimate-dbt children --model # downstream models altimate-dbt parents --model # upstream models ``` -When the project check fails (a broken profile, a missing env var), `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from the last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. +When the project check fails (a broken profile, a missing env var) and an earlier parse left a manifest, `children` and `parents` answer `{ stale_manifest, models }` instead of a list: `models` comes from that last successful parse and may predate the current files, so check for it before relying on the answer for impact analysis. With no earlier manifest they answer an error. ## Packages diff --git a/packages/dbt-tools/test/check.test.ts b/packages/dbt-tools/test/check.test.ts index c19054e5e3..4d652d36ee 100644 --- a/packages/dbt-tools/test/check.test.ts +++ b/packages/dbt-tools/test/check.test.ts @@ -75,6 +75,16 @@ describe("prerequisites in dbt Fusion mode", () => { expect(issue).toContain("fusion: dbt Fusion was not found: no dbt 2.x binary in ~/.local/bin or on PATH") }) + test("name the interpreter they looked next to, when the config has one", async () => { + fusionBinary.find = async () => undefined + + const issue = await validate(config({ pythonPath: "/no/venv/bin/python" })) + + expect(issue).toContain( + "fusion: dbt Fusion was not found: no dbt 2.x binary next to /no/venv/bin/python, in ~/.local/bin or on PATH", + ) + }) + test("still require the project", async () => { fusionBinary.find = async () => FUSION @@ -86,10 +96,12 @@ describe("prerequisites in dbt Fusion mode", () => { }) describe("prerequisites in other modes", () => { - test("still require Python and dbt-core, and never look for Fusion", async () => { - fusionBinary.find = async () => { - throw new Error("the Fusion lookup must not run outside Fusion mode") - } + const noFusion = async (): Promise => { + throw new Error("the Fusion lookup must not run outside Fusion mode") + } + + test("still require a Python path, and never look for Fusion", async () => { + fusionBinary.find = noFusion for (const dbtIntegration of ["core", "corecommand", "cloud"]) { const result = await all(config({ dbtIntegration })) @@ -98,4 +110,25 @@ describe("prerequisites in other modes", () => { expect(result.checks).toMatchObject({ python: { ok: false, error: "No Python path configured" } }) } }) + + // A stand-in interpreter that runs but has no dbt-core: `--version` works, every other run fails. + test.skipIf(process.platform === "win32")("still require dbt-core in a working Python", async () => { + fusionBinary.find = noFusion + const dir = mkdtempSync(join(tmpdir(), "dbt-check-py-")) + dirs.push(dir) + const python = join(dir, "python") + writeFileSync(python, '#!/bin/sh\nif [ "$1" = "--version" ]; then echo "Python 3.11.0"; exit 0; fi\nexit 1\n', { + mode: 0o755, + }) + + for (const dbtIntegration of ["core", "corecommand", "cloud"]) { + const result = await all(config({ dbtIntegration, pythonPath: python })) + expect(result.passed).toBe(false) + expect(result.checks.python?.ok).toBe(true) + expect(result.checks).toMatchObject({ + dbt: { ok: false, error: "dbt-core is not installed in the configured Python environment" }, + }) + expect(result.checks.project?.ok).toBe(true) + } + }) }) From 30302f1062d03d613ee768dc5b8c07416b9e6648 Mon Sep 17 00:00:00 2001 From: "Ralph Sto. Domingo" Date: Tue, 17 Nov 2026 19:08:25 +0800 Subject: [PATCH 3/4] fix(dbt-tools): accept a Fusion behind a script launcher, as the adapter does The Fusion check now runs script candidates and allows `--version` 15 s, as the adapter does, so asdf, nix and wrapper launchers pass; dbt Core is still rejected. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VEmKQx8gR7vd6ettA3mWjP --- packages/dbt-tools/src/check.ts | 12 +++++- packages/dbt-tools/test/check.test.ts | 57 ++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/packages/dbt-tools/src/check.ts b/packages/dbt-tools/src/check.ts index 7e3144fd81..92953d5406 100644 --- a/packages/dbt-tools/src/check.ts +++ b/packages/dbt-tools/src/check.ts @@ -39,7 +39,13 @@ function project(root: string): Status { return { ok: true } } -type FusionLookup = { pythonPath?: string; cwd?: string; env?: Record } +type FusionLookup = { + pythonPath?: string + cwd?: string + env?: Record + timeoutMs?: number + skipScripts?: boolean +} /** How the Fusion check finds dbt: dbt-integration's own lookup, loaded only in Fusion mode. * A field so tests can replace it. */ @@ -48,10 +54,14 @@ export const fusionBinary = { } async function fusion(cfg: Config): Promise { + // Judge candidates as the adapter does: it runs any `dbt` whose `--version` reports 2.x, + // script launchers (asdf, nix and company wrappers) included, and allows 15 s for it. const binary = await fusionBinary.find({ pythonPath: cfg.pythonPath || undefined, cwd: cfg.projectRoot || undefined, env: process.env, + skipScripts: false, + timeoutMs: 15_000, }) if (binary) return { ok: true } const nextTo = cfg.pythonPath ? `next to ${cfg.pythonPath}, ` : "" diff --git a/packages/dbt-tools/test/check.test.ts b/packages/dbt-tools/test/check.test.ts index 4d652d36ee..5024c7527e 100644 --- a/packages/dbt-tools/test/check.test.ts +++ b/packages/dbt-tools/test/check.test.ts @@ -1,6 +1,7 @@ import { afterEach, describe, expect, test } from "bun:test" -import { mkdtempSync, rmSync, writeFileSync } from "fs" -import { tmpdir } from "os" +import { execFileSync } from "child_process" +import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "fs" +import { homedir, tmpdir } from "os" import { join } from "path" import { all, fusionBinary, validate } from "../src/check" import type { Config } from "../src/config" @@ -42,6 +43,8 @@ describe("prerequisites in dbt Fusion mode", () => { expect(result.passed).toBe(true) expect(Object.keys(result.checks).sort()).toEqual(["fusion", "project"]) expect(asked[0]).toMatchObject({ pythonPath: undefined, cwd: cfg.projectRoot }) + // As the adapter judges a candidate: script launchers count, and `--version` gets 15 s. + expect(asked[0]).toMatchObject({ skipScripts: false, timeoutMs: 15_000 }) expect(await validate(cfg)).toBeNull() }) @@ -95,6 +98,56 @@ describe("prerequisites in dbt Fusion mode", () => { }) }) +// The real lookup, through the CLI in its own process: another test file here mocks +// `child_process`, and bun's module mocks reach every file of the run. A stand-in `dbt` is the +// only thing on PATH. The lookup always tries ~/.local/bin/dbt first (Bun ignores HOME for that), +// so the rejection test can't run where that is a real Fusion. +function realFusionInLocalBin(): boolean { + const dbt = join(homedir(), ".local", "bin", "dbt") + if (!existsSync(dbt)) return false + try { + return /^dbt(-fusion)? 2\./m.test(execFileSync(dbt, ["--version"], { encoding: "utf-8", timeout: 15_000 })) + } catch { + return false + } +} + +describe.skipIf(process.platform === "win32")("the Fusion lookup, run by `altimate-dbt doctor`", () => { + const entry = join(import.meta.dir, "../src/index.ts") + + /** `doctor` in Fusion mode with no Python path, and a `dbt` on PATH that prints `versionLine`. */ + function doctorWith(versionLine: string): { passed: boolean; checks: { check: string; status: string }[] } { + const home = mkdtempSync(join(tmpdir(), "dbt-check-home-")) + dirs.push(home) + const bin = join(home, "bin") + mkdirSync(bin) + writeFileSync(join(bin, "dbt"), `#!/bin/sh\nif [ "$1" = "--version" ]; then echo "${versionLine}"; fi\nexit 0\n`, { + mode: 0o755, + }) + mkdirSync(join(home, ".altimate-code")) + writeFileSync( + join(home, ".altimate-code", "dbt.json"), + JSON.stringify({ projectRoot: project(), dbtIntegration: "fusion", queryLimit: 500 }), + ) + const result = Bun.spawnSync([process.execPath, entry, "doctor"], { env: { HOME: home, PATH: bin } }) + return JSON.parse(result.stdout.toString()) + } + + test("accepts a Fusion behind a script launcher that reports 2.x", () => { + const report = doctorWith("dbt 2.0.9") + + expect(report.passed).toBe(true) + expect(report.checks).toContainEqual({ check: "fusion", status: "ok" }) + }) + + test.skipIf(realFusionInLocalBin())("still rejects dbt Core", () => { + const report = doctorWith("Core: installed: 1.10.23") + + expect(report.passed).toBe(false) + expect(report.checks).toContainEqual(expect.objectContaining({ check: "fusion", status: "fail" })) + }) +}) + describe("prerequisites in other modes", () => { const noFusion = async (): Promise => { throw new Error("the Fusion lookup must not run outside Fusion mode") From f515621a62039a1065d36cc9b927e16b827e4e69 Mon Sep 17 00:00:00 2001 From: "Ralph Sto. Domingo" Date: Fri, 20 Nov 2026 15:02:15 +0800 Subject: [PATCH 4/4] chore(dbt-tools): take @altimateai/dbt-integration ^0.3.20 0.3.20 runs docs generate on dbt Fusion 2.0.9+ and stops re-reporting a deleted Python interpreter on every start. No API change for dbt-tools. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VEmKQu1Qn99YbrBzhKdtAr --- bun.lock | 4 ++-- packages/dbt-tools/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bun.lock b/bun.lock index 268aeb726c..9d11e718fb 100644 --- a/bun.lock +++ b/bun.lock @@ -150,7 +150,7 @@ "altimate-dbt": "./bin/altimate-dbt", }, "dependencies": { - "@altimateai/dbt-integration": "^0.3.19", + "@altimateai/dbt-integration": "^0.3.20", }, "devDependencies": { "@tsconfig/bun": "catalog:", @@ -659,7 +659,7 @@ "@altimateai/altimate-core-win32-x64-msvc": ["@altimateai/altimate-core-win32-x64-msvc@0.9.0", "", { "os": "win32", "cpu": "x64" }, "sha512-MoELhLPzJGAxJMtL7C/g/gj464I9pbSmfJ6IamhFwsyz7nfUrKOkAnixVXuQrLEJ9I+sVZJuPMq2H1HUCkpOwA=="], - "@altimateai/dbt-integration": ["@altimateai/dbt-integration@0.3.19", "", { "dependencies": { "@altimateai/altimate-core": "0.5.0", "node-abort-controller": "^3.1.1", "node-fetch": "^3.3.2", "semver": "^7.6.3", "yaml": "^2.5.0" } }, "sha512-FsExJ+FHUzR6DEm9QNhPDBr2CscstkGgRZlU+FOIQghhPchJvnGGBSXBGz5hYiED2WPMeKUTOZk70uh5GQ8oUw=="], + "@altimateai/dbt-integration": ["@altimateai/dbt-integration@0.3.20", "", { "dependencies": { "@altimateai/altimate-core": "0.5.0", "node-abort-controller": "^3.1.1", "node-fetch": "^3.3.2", "semver": "^7.6.3", "yaml": "^2.5.0" } }, "sha512-K08nWtcTfmW9912ja3AR9vNCNjiWHrYDB5NaXbSeTN6f/MOnXbWMcLiKfYBiOm7kpLvaz5TZkbpsQDGeC4YCvg=="], "@altimateai/dbt-tools": ["@altimateai/dbt-tools@workspace:packages/dbt-tools"], diff --git a/packages/dbt-tools/package.json b/packages/dbt-tools/package.json index d26778092e..f063fb4683 100644 --- a/packages/dbt-tools/package.json +++ b/packages/dbt-tools/package.json @@ -13,7 +13,7 @@ "test:e2e": "bun test test/e2e/ --timeout 300000" }, "dependencies": { - "@altimateai/dbt-integration": "^0.3.19" + "@altimateai/dbt-integration": "^0.3.20" }, "devDependencies": { "@tsconfig/bun": "catalog:",