Skip to content

Commit a8a08c6

Browse files
anandgupta42claude
andcommitted
test: add release-validation coverage for post-v0.8.7 merged PRs
Adds regression tests for the 8 PRs merged since `v0.8.7`, authored during pre-release validation. Two independent authoring passes (suffix `-codex.test.ts` from the codex CLI track, plus `release-validation/*.test.ts` from the Claude multi-agent track) intentionally overlap to maximize edge-case coverage. opencode (`packages/opencode/test/release-validation/`): - `question-937*` non-interactive question tool: `ALTIMATE_NON_INTERACTIVE` / `ALTIMATE_FORCE_INTERACTIVE` / `ALTIMATE_AUTO_ANSWER` matrix, output-text contract, `run.ts`/`bash.ts` env guards - `mcp-datamate-893*` MCP config normalize/merge, enabled-state persistence, recursive `**/mcp.json` discovery, datamate transport selection - `session-transcript-941*` transcript REST endpoint: query coercion, content negotiation, tool/thinking detail gating, error schema - `serve-upgrade-940*` headless `serve` startup upgrade check: scheduling, failure isolation, version-compare boundaries - `serve-trace-log-929*` trace-directory startup logging - `chunk-timeout-844*` `DEFAULT_CHUNK_TIMEOUT` SSE watchdog behavior - `windows-installer-930*` `install.ps1` static analysis (HTTPS URLs, error handling, PATH safety, idempotency, no secret leakage) + win32 dispatch dbt-tools (`packages/dbt-tools/test/`): - `dbt-cli-release-validation.test.ts` #933 error-bubbling: malformed JSON, exit-code redaction, ANSI stripping, no-signal fallback - `dbt-cli-extra-codex.test.ts` result-shape, `--limit` boundaries, last-error selection, inline-compile error paths All new tests pass and are typecheck-clean. 4 `test.todo` markers document real, pre-existing edge cases surfaced during review (transcript path-traversal -> 500, `normalizeMcpConfig` dropping `updatedAt`, `install.ps1` missing archive checksum, `execDbtCompile` stale-manifest fallback). No source files are modified. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7039545 commit a8a08c6

14 files changed

Lines changed: 4238 additions & 0 deletions
Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
import { describe, test, expect } from "bun:test"
2+
import { mock, beforeEach, afterEach } from "bun:test"
3+
import * as realChildProcess from "child_process"
4+
import { chmodSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs"
5+
import { join } from "path"
6+
7+
const tmpRoot = join(import.meta.dir, ".tmp-extra-codex")
8+
const defaultDbtPath = join(tmpRoot, "bin", "dbt")
9+
const originalAltimateDbtPath = process.env.ALTIMATE_DBT_PATH
10+
11+
const mockExecFile = mock((cmd: string, args: string[], opts: any, cb: Function) => {
12+
cb(null, "", "")
13+
})
14+
15+
mock.module("child_process", () => ({
16+
...realChildProcess,
17+
execFile: mockExecFile,
18+
}))
19+
20+
const { configure, execDbtShow, execDbtCompileInline } = await import("../src/dbt-cli")
21+
22+
function makeFakeExecutable(path: string) {
23+
mkdirSync(join(path, ".."), { recursive: true })
24+
writeFileSync(path, "#!/bin/sh\nexit 0\n")
25+
chmodSync(path, 0o755)
26+
}
27+
28+
function commandFailed(message: string, fields: Record<string, unknown> = {}) {
29+
const err: any = new Error(message)
30+
Object.assign(err, fields)
31+
return err
32+
}
33+
34+
describe("dbt-cli extra regression coverage for PR #933", () => {
35+
beforeEach(() => {
36+
rmSync(tmpRoot, { recursive: true, force: true })
37+
makeFakeExecutable(defaultDbtPath)
38+
process.env.ALTIMATE_DBT_PATH = defaultDbtPath
39+
configure({})
40+
mockExecFile.mockReset()
41+
})
42+
43+
afterEach(() => {
44+
rmSync(tmpRoot, { recursive: true, force: true })
45+
if (originalAltimateDbtPath === undefined) delete process.env.ALTIMATE_DBT_PATH
46+
else process.env.ALTIMATE_DBT_PATH = originalAltimateDbtPath
47+
configure({})
48+
})
49+
50+
test("execDbtShow returns the complete query result shape from mixed JSON and garbage stdout", async () => {
51+
const rawSql = "select 1 as n"
52+
const compiledSql = "SELECT 1 AS n"
53+
const stdout = [
54+
"",
55+
"not json at all",
56+
JSON.stringify({ info: { level: "info", msg: "Running with dbt=1.9.0" } }),
57+
"{truncated",
58+
JSON.stringify({ data: { compiled_sql: compiledSql } }),
59+
JSON.stringify({ data: { preview: JSON.stringify([{ n: 1, label: "one" }]) } }),
60+
].join("\n")
61+
62+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
63+
cb(null, stdout, "")
64+
})
65+
66+
const result = await execDbtShow(rawSql)
67+
expect(result).toEqual({
68+
columnNames: ["n", "label"],
69+
columnTypes: ["string", "string"],
70+
data: [{ n: 1, label: "one" }],
71+
rawSql,
72+
compiledSql,
73+
})
74+
})
75+
76+
test("execDbtShow treats an empty preview array as a successful zero-row result without fallback", async () => {
77+
let calls = 0
78+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
79+
calls++
80+
cb(null, JSON.stringify({ result: { preview: [], sql: "SELECT * FROM empty_table" } }), "")
81+
})
82+
83+
const result = await execDbtShow("select * from empty_table")
84+
expect(result.columnNames).toEqual([])
85+
expect(result.columnTypes).toEqual([])
86+
expect(result.data).toEqual([])
87+
expect(result.compiledSql).toBe("SELECT * FROM empty_table")
88+
expect(calls).toBe(1)
89+
})
90+
91+
test("execDbtShow passes --limit 0 through to both JSON mode and plain-text fallback", async () => {
92+
const seenArgs: string[][] = []
93+
mockExecFile.mockImplementation((_cmd: string, args: string[], _opts: any, cb: Function) => {
94+
seenArgs.push([...args])
95+
if (seenArgs.length === 1) {
96+
cb(null, JSON.stringify({ info: { msg: "unrecognized successful shape" } }), "")
97+
} else {
98+
cb(null, ["| n |", "| - |", "| 1 |"].join("\n"), "")
99+
}
100+
})
101+
102+
const result = await execDbtShow("select 1 as n", 0)
103+
expect(result.data).toEqual([{ n: "1" }])
104+
expect(seenArgs).toHaveLength(2)
105+
expect(seenArgs[0]).toContain("--limit")
106+
expect(seenArgs[0]?.[seenArgs[0].indexOf("--limit") + 1]).toBe("0")
107+
expect(seenArgs[1]).toEqual(["show", "--inline", "select 1 as n", "--limit", "0"])
108+
})
109+
110+
test("execDbtShow omits --limit entirely when the limit is undefined", async () => {
111+
mockExecFile.mockImplementation((_cmd: string, args: string[], _opts: any, cb: Function) => {
112+
expect(args).not.toContain("--limit")
113+
cb(null, JSON.stringify({ data: { preview: '[{"n": 1}]' } }), "")
114+
})
115+
116+
await expect(execDbtShow("select 1")).resolves.toMatchObject({ data: [{ n: 1 }] })
117+
})
118+
119+
test("execDbtShow uses the last error-level log event across top-level and nested dbt shapes", async () => {
120+
const sensitiveSql = "select 'do_not_log_this_show_secret' as token"
121+
const stdout = [
122+
JSON.stringify({ level: "error", msg: "Encountered an error:" }),
123+
JSON.stringify({ info: { level: "error", msg: "Compilation Error: undefined macro final_macro" } }),
124+
].join("\n")
125+
126+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
127+
cb(commandFailed(`Command failed: dbt show --inline ${sensitiveSql}`, { code: 1 }), stdout, "generic stderr")
128+
})
129+
130+
const caught = (await execDbtShow(sensitiveSql).catch((e) => e)) as Error
131+
expect(caught.message).toBe("Compilation Error: undefined macro final_macro")
132+
expect(caught.message).not.toContain("Encountered an error")
133+
expect(caught.message).not.toContain("do_not_log_this_show_secret")
134+
})
135+
136+
test("execDbtShow strips nested ANSI SGR sequences from structured error text", async () => {
137+
const stdout = JSON.stringify({
138+
info: {
139+
level: "error",
140+
msg: "\u001b[1mCompilation \u001b[31mError\u001b[0m\u001b[22m: bad ref",
141+
},
142+
})
143+
144+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
145+
cb(commandFailed("Command failed", { code: 1 }), stdout, "")
146+
})
147+
148+
const caught = (await execDbtShow("select 1").catch((e) => e)) as Error
149+
expect(caught.message).toBe("Compilation Error: bad ref")
150+
expect(caught.message).not.toContain("\u001b[")
151+
})
152+
153+
test("execDbtShow redacts SQL when JSON parsing fails and only the plain-text fallback rejects", async () => {
154+
const sensitiveSql = "select 'plain_fallback_secret' as token"
155+
let calls = 0
156+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
157+
calls++
158+
if (calls === 1) {
159+
cb(null, JSON.stringify({ info: { msg: "valid but unparseable success payload" } }), "")
160+
} else {
161+
cb(
162+
commandFailed(`Command failed: dbt show --inline ${sensitiveSql}`, { code: 3 }),
163+
"",
164+
"",
165+
)
166+
}
167+
})
168+
169+
const caught = (await execDbtShow(sensitiveSql).catch((e) => e)) as Error
170+
expect(caught.message).toBe(
171+
"Could not parse dbt show JSON output, and plain-text fallback failed: dbt exited with status 3",
172+
)
173+
expect(caught.message).not.toContain("plain_fallback_secret")
174+
expect(caught.message).not.toContain("--inline")
175+
})
176+
177+
test("execDbtCompileInline parses compiled SQL despite mixed garbage JSON-line output", async () => {
178+
const stdout = [
179+
"dbt wrote a non-json warning",
180+
JSON.stringify({ info: { msg: "still running" } }),
181+
"{bad",
182+
JSON.stringify({ result: { compiled_code: "SELECT id FROM analytics.customers" } }),
183+
].join("\n")
184+
185+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
186+
cb(null, stdout, "")
187+
})
188+
189+
await expect(execDbtCompileInline("select * from {{ ref('customers') }}")).resolves.toEqual({
190+
sql: "SELECT id FROM analytics.customers",
191+
})
192+
})
193+
194+
test("execDbtCompileInline falls back to trimmed plain text when JSON mode succeeds with no SQL", async () => {
195+
const seenArgs: string[][] = []
196+
mockExecFile.mockImplementation((_cmd: string, args: string[], _opts: any, cb: Function) => {
197+
seenArgs.push([...args])
198+
if (seenArgs.length === 1) cb(null, JSON.stringify({ info: { msg: "done" } }), "")
199+
else cb(null, "\n SELECT 2 AS n \n", "")
200+
})
201+
202+
const result = await execDbtCompileInline("select 2 as n")
203+
expect(result).toEqual({ sql: "SELECT 2 AS n" })
204+
expect(seenArgs[0]).toEqual(["compile", "--inline", "select 2 as n", "--output", "json", "--log-format", "json"])
205+
expect(seenArgs[1]).toEqual(["compile", "--inline", "select 2 as n"])
206+
})
207+
208+
test("execDbtCompileInline does not use SQL-looking stdout from a failed JSON-mode run", async () => {
209+
let calls = 0
210+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
211+
calls++
212+
if (calls === 1) {
213+
const trap = JSON.stringify({ payload: { compiled: "SELECT should_not_be_returned FROM failed_stdout" } })
214+
cb(commandFailed("Command failed", { code: 1 }), trap, "Compilation Error: missing source")
215+
} else {
216+
cb(commandFailed("Command failed", { code: 1 }), "", "Compilation Error: missing source")
217+
}
218+
})
219+
220+
await expect(execDbtCompileInline("select * from missing_source")).rejects.toThrow(
221+
"Compilation Error: missing source",
222+
)
223+
expect(calls).toBe(2)
224+
})
225+
226+
test("execDbtCompileInline chooses the last structured error and redacts command-line SQL fallback text", async () => {
227+
const sensitiveSql = "select 'compile_inline_last_error_secret' as token"
228+
const stdout = [
229+
JSON.stringify({ info: { level: "error", msg: "Encountered an error:" } }),
230+
JSON.stringify({ level: "error", msg: "Runtime Error: final actionable inline failure" }),
231+
].join("\n")
232+
233+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
234+
cb(commandFailed(`Command failed: dbt compile --inline ${sensitiveSql}`, { code: 2 }), stdout, "")
235+
})
236+
237+
const caught = (await execDbtCompileInline(sensitiveSql).catch((e) => e)) as Error
238+
expect(caught.message).toBe("Runtime Error: final actionable inline failure")
239+
expect(caught.message).not.toContain("Encountered an error")
240+
expect(caught.message).not.toContain("compile_inline_last_error_secret")
241+
})
242+
243+
test("execDbtCompileInline surfaces spawn-time failures without adding command-line SQL", async () => {
244+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
245+
cb(commandFailed("spawn /missing/dbt ENOENT", { code: "ENOENT" }), "", "")
246+
})
247+
248+
const caught = (await execDbtCompileInline("select 'spawn_secret'").catch((e) => e)) as Error
249+
expect(caught.message).toBe("dbt compile inline failed: spawn /missing/dbt ENOENT")
250+
expect(caught.message).not.toContain("spawn_secret")
251+
expect(caught.message).not.toContain("--inline")
252+
})
253+
254+
test("configure resets dbt resolution and run options honor pythonPath/projectRoot", async () => {
255+
delete process.env.ALTIMATE_DBT_PATH
256+
const projectRoot = join(tmpRoot, "project")
257+
const binDir = join(projectRoot, ".venv", "bin")
258+
const pythonPath = join(binDir, "python")
259+
const dbtPath = join(binDir, "dbt")
260+
makeFakeExecutable(pythonPath)
261+
makeFakeExecutable(dbtPath)
262+
configure({ pythonPath, projectRoot })
263+
264+
mockExecFile.mockImplementation((cmd: string, _args: string[], opts: any, cb: Function) => {
265+
expect(cmd).toBe(dbtPath)
266+
expect(opts.cwd).toBe(projectRoot)
267+
expect(String(opts.env.PATH).startsWith(`${binDir}:`)).toBe(true)
268+
cb(null, JSON.stringify({ data: { preview: '[{"ok": true}]' } }), "")
269+
})
270+
271+
await expect(execDbtShow("select true as ok")).resolves.toMatchObject({ data: [{ ok: true }] })
272+
})
273+
})
274+
275+
describe("install.ps1 static safety checks", () => {
276+
test("Windows installer stays Bun-standalone and does not invoke npm/node install flows", () => {
277+
const text = readFileSync(join(import.meta.dir, "../../../install.ps1"), "utf-8")
278+
const executableLines = text
279+
.split(/\r?\n/)
280+
.map((line) => line.trim())
281+
.filter((line) => line.length > 0 && !line.startsWith("#") && !line.startsWith("Write-"))
282+
.join("\n")
283+
284+
expect(text).toContain("Bun-compiled standalone executable")
285+
expect(text).toContain("does NOT depend on npm/Node")
286+
expect(text).toContain("github.com/AltimateAI/altimate-code/releases")
287+
expect(executableLines).not.toMatch(/\bnpm\s+(install|i)\b/i)
288+
expect(executableLines).not.toMatch(/\bnode\s+.*install\b/i)
289+
})
290+
})
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { describe, test, expect, mock, beforeEach, afterEach } from "bun:test"
2+
import * as realChildProcess from "child_process"
3+
import { mkdirSync, rmSync, writeFileSync } from "fs"
4+
import { join } from "path"
5+
6+
const mockExecFile = mock((cmd: string, args: string[], opts: any, cb: Function) => {
7+
cb(null, "", "")
8+
})
9+
10+
mock.module("child_process", () => ({
11+
...realChildProcess,
12+
execFile: mockExecFile,
13+
}))
14+
15+
const { configure, execDbtShow, execDbtCompile, execDbtCompileInline } = await import("../src/dbt-cli")
16+
17+
const tmpRoot = join(import.meta.dir, ".tmp-release-validation")
18+
19+
describe("dbt-cli release validation: error bubbling", () => {
20+
beforeEach(() => {
21+
mockExecFile.mockReset()
22+
rmSync(tmpRoot, { recursive: true, force: true })
23+
configure({})
24+
})
25+
26+
afterEach(() => {
27+
rmSync(tmpRoot, { recursive: true, force: true })
28+
configure({})
29+
})
30+
31+
test("execDbtShow ignores malformed JSON log fragments and still bubbles the valid structured error", async () => {
32+
const stdout = [
33+
"{not complete json",
34+
JSON.stringify({ info: { level: "info", msg: "Running with dbt=1.9.0" } }),
35+
JSON.stringify({ info: { level: "error", msg: "Database Error: syntax error at or near \"from\"" } }),
36+
].join("\n")
37+
38+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
39+
const err: any = new Error("Command failed")
40+
err.code = 1
41+
cb(err, stdout, "")
42+
})
43+
44+
await expect(execDbtShow("select * from")).rejects.toThrow('Database Error: syntax error at or near "from"')
45+
})
46+
47+
test("execDbtShow redacts Command-failed fallback when exit code is a string", async () => {
48+
const sensitiveSql = "select 'release_validation_secret' as token"
49+
50+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
51+
const err: any = new Error(`Command failed: dbt show --inline ${sensitiveSql} --output json`)
52+
err.code = "EX_CONFIG"
53+
cb(err, "", "")
54+
})
55+
56+
const caught = (await execDbtShow(sensitiveSql).catch((e) => e)) as Error
57+
expect(caught.message).toBe("dbt show failed: dbt failed: EX_CONFIG")
58+
expect(caught.message).not.toContain("release_validation_secret")
59+
expect(caught.message).not.toContain("--inline")
60+
})
61+
62+
test("execDbtShow has a safe fallback for non-zero exits with no stderr, code, or signal", async () => {
63+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
64+
cb(new Error("Command failed: dbt show --inline select 1"), "", "")
65+
})
66+
67+
await expect(execDbtShow("select 1")).rejects.toThrow("dbt show failed: dbt failed (no exit code reported)")
68+
})
69+
70+
test("execDbtCompileInline strips ANSI SGR codes from stderr, not just structured stdout", async () => {
71+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
72+
const err: any = new Error("Command failed")
73+
err.code = 1
74+
cb(err, "", "\u001b[31mCompilation Error\u001b[0m: undefined macro")
75+
})
76+
77+
const caught = (await execDbtCompileInline("select {{ missing_macro() }}").catch((e) => e)) as Error
78+
expect(caught.message).toBe("Compilation Error: undefined macro")
79+
expect(caught.message).not.toContain("\u001b[")
80+
})
81+
82+
test.todo("BUG: execDbtCompile should not return stale manifest SQL after the current dbt compile fails", async () => {
83+
const projectRoot = tmpRoot
84+
mkdirSync(join(projectRoot, "target"), { recursive: true })
85+
writeFileSync(
86+
join(projectRoot, "target", "manifest.json"),
87+
JSON.stringify({
88+
nodes: {
89+
"model.project.orders": {
90+
name: "orders",
91+
compiled_code: "select * from stale_previous_compile",
92+
},
93+
},
94+
}),
95+
)
96+
configure({ projectRoot })
97+
98+
mockExecFile.mockImplementation((_cmd: string, _args: string[], _opts: any, cb: Function) => {
99+
const err: any = new Error("Command failed")
100+
err.code = 1
101+
cb(err, "", "Compilation Error: model orders depends on a missing source")
102+
})
103+
104+
await expect(execDbtCompile("orders")).rejects.toThrow("Compilation Error: model orders depends on a missing source")
105+
})
106+
})

0 commit comments

Comments
 (0)