diff --git a/.opencode/skills/dbt-analyze/SKILL.md b/.opencode/skills/dbt-analyze/SKILL.md index f993e17974..d300284e86 100644 --- a/.opencode/skills/dbt-analyze/SKILL.md +++ b/.opencode/skills/dbt-analyze/SKILL.md @@ -111,7 +111,7 @@ If no manifest is available: 1. Run `lineage_check` on the changed SQL 2. Show column-level data flow 3. Note: downstream impact requires a manifest -4. Suggest: `altimate-dbt build-project` to generate one +4. Suggest: `altimate-dbt build` to generate one ## Common Mistakes diff --git a/.opencode/skills/dbt-analyze/references/altimate-dbt-commands.md b/.opencode/skills/dbt-analyze/references/altimate-dbt-commands.md index 6dbb8e9731..6bad491756 100644 --- a/.opencode/skills/dbt-analyze/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-analyze/references/altimate-dbt-commands.md @@ -20,10 +20,10 @@ altimate-dbt info # Project name, adapter, root ## Build & Run ```bash -altimate-dbt build --model [--downstream] # compile + run + test +altimate-dbt build # full project build (compile + run + test) +altimate-dbt build --model [--downstream] # build a single model altimate-dbt run --model [--downstream] # materialize only altimate-dbt test --model # run tests only -altimate-dbt build-project # full project build ``` ## Compile diff --git a/.opencode/skills/dbt-develop/references/altimate-dbt-commands.md b/.opencode/skills/dbt-develop/references/altimate-dbt-commands.md index 6dbb8e9731..6bad491756 100644 --- a/.opencode/skills/dbt-develop/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-develop/references/altimate-dbt-commands.md @@ -20,10 +20,10 @@ altimate-dbt info # Project name, adapter, root ## Build & Run ```bash -altimate-dbt build --model [--downstream] # compile + run + test +altimate-dbt build # full project build (compile + run + test) +altimate-dbt build --model [--downstream] # build a single model altimate-dbt run --model [--downstream] # materialize only altimate-dbt test --model # run tests only -altimate-dbt build-project # full project build ``` ## Compile diff --git a/.opencode/skills/dbt-docs/references/altimate-dbt-commands.md b/.opencode/skills/dbt-docs/references/altimate-dbt-commands.md index 6dbb8e9731..6bad491756 100644 --- a/.opencode/skills/dbt-docs/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-docs/references/altimate-dbt-commands.md @@ -20,10 +20,10 @@ altimate-dbt info # Project name, adapter, root ## Build & Run ```bash -altimate-dbt build --model [--downstream] # compile + run + test +altimate-dbt build # full project build (compile + run + test) +altimate-dbt build --model [--downstream] # build a single model altimate-dbt run --model [--downstream] # materialize only altimate-dbt test --model # run tests only -altimate-dbt build-project # full project build ``` ## Compile diff --git a/.opencode/skills/dbt-test/references/altimate-dbt-commands.md b/.opencode/skills/dbt-test/references/altimate-dbt-commands.md index 6dbb8e9731..6bad491756 100644 --- a/.opencode/skills/dbt-test/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-test/references/altimate-dbt-commands.md @@ -20,10 +20,10 @@ altimate-dbt info # Project name, adapter, root ## Build & Run ```bash -altimate-dbt build --model [--downstream] # compile + run + test +altimate-dbt build # full project build (compile + run + test) +altimate-dbt build --model [--downstream] # build a single model altimate-dbt run --model [--downstream] # materialize only altimate-dbt test --model # run tests only -altimate-dbt build-project # full project build ``` ## Compile diff --git a/.opencode/skills/dbt-troubleshoot/references/altimate-dbt-commands.md b/.opencode/skills/dbt-troubleshoot/references/altimate-dbt-commands.md index 6dbb8e9731..6bad491756 100644 --- a/.opencode/skills/dbt-troubleshoot/references/altimate-dbt-commands.md +++ b/.opencode/skills/dbt-troubleshoot/references/altimate-dbt-commands.md @@ -20,10 +20,10 @@ altimate-dbt info # Project name, adapter, root ## Build & Run ```bash -altimate-dbt build --model [--downstream] # compile + run + test +altimate-dbt build # full project build (compile + run + test) +altimate-dbt build --model [--downstream] # build a single model altimate-dbt run --model [--downstream] # materialize only altimate-dbt test --model # run tests only -altimate-dbt build-project # full project build ``` ## Compile diff --git a/packages/dbt-tools/src/commands/build.ts b/packages/dbt-tools/src/commands/build.ts index 07432ea4ad..5d796c764f 100644 --- a/packages/dbt-tools/src/commands/build.ts +++ b/packages/dbt-tools/src/commands/build.ts @@ -2,7 +2,7 @@ import type { DBTProjectIntegrationAdapter, CommandProcessResult } from "@altima export async function build(adapter: DBTProjectIntegrationAdapter, args: string[]) { const model = flag(args, "model") - if (!model) return { error: "Missing --model" } + if (!model) return project(adapter) const downstream = args.includes("--downstream") const result = await adapter.unsafeBuildModelImmediately({ plusOperatorLeft: "", diff --git a/packages/dbt-tools/test/build.test.ts b/packages/dbt-tools/test/build.test.ts new file mode 100644 index 0000000000..586c1b1f19 --- /dev/null +++ b/packages/dbt-tools/test/build.test.ts @@ -0,0 +1,47 @@ +import { describe, test, expect, mock } from "bun:test" +import { build, project } from "../src/commands/build" +import type { DBTProjectIntegrationAdapter } from "@altimateai/dbt-integration" + +function makeAdapter(overrides: Partial = {}): DBTProjectIntegrationAdapter { + return { + unsafeBuildModelImmediately: mock(() => Promise.resolve({ stdout: "model built", stderr: "" })), + unsafeBuildProjectImmediately: mock(() => Promise.resolve({ stdout: "project built", stderr: "" })), + unsafeRunModelImmediately: mock(() => Promise.resolve({ stdout: "", stderr: "" })), + unsafeRunModelTestImmediately: mock(() => Promise.resolve({ stdout: "", stderr: "" })), + dispose: mock(() => Promise.resolve()), + ...overrides, + } as unknown as DBTProjectIntegrationAdapter +} + +describe("build command", () => { + test("build without --model builds entire project", async () => { + const adapter = makeAdapter() + const result = await build(adapter, []) + expect(adapter.unsafeBuildProjectImmediately).toHaveBeenCalledTimes(1) + expect(adapter.unsafeBuildModelImmediately).not.toHaveBeenCalled() + expect(result).toEqual({ stdout: "project built" }) + }) + + test("build --model builds single model", async () => { + const adapter = makeAdapter() + const result = await build(adapter, ["--model", "orders"]) + expect(adapter.unsafeBuildModelImmediately).toHaveBeenCalledTimes(1) + expect(adapter.unsafeBuildModelImmediately).toHaveBeenCalledWith({ + plusOperatorLeft: "", + modelName: "orders", + plusOperatorRight: "", + }) + expect(adapter.unsafeBuildProjectImmediately).not.toHaveBeenCalled() + expect(result).toEqual({ stdout: "model built" }) + }) + + test("build --model --downstream sets plusOperatorRight", async () => { + const adapter = makeAdapter() + await build(adapter, ["--model", "orders", "--downstream"]) + expect(adapter.unsafeBuildModelImmediately).toHaveBeenCalledWith({ + plusOperatorLeft: "", + modelName: "orders", + plusOperatorRight: "+", + }) + }) +})