Skip to content

Commit cb53255

Browse files
committed
refactor(onboarding): dedupe against existing monorepo utilities (5 of 10)
Codex sweep + a dbt-team reviewer flagged 10 duplications where new onboarding code reinvented utilities that already existed. Fixing 5 in this commit; the other 5 stay as-is with documented rationale. Fixed (impact from worst to nicest): - dbt detection: `tool-detection.ts::detectDbtRuntime` now delegates to `dbt-tools/src/dbt-resolve.ts::{resolveDbt, validateDbt, buildDbtEnv}`. The old `execFile("dbt", "--version")` (with a `dbt.cmd` Windows fallback) was PATH-only, so users with dbt in a venv / uv / conda / pyenv / pipx / poetry etc. saw `dbt: missing` on the template's "Build & query it" branch. resolveDbt handles 16 Python env managers + Windows Scripts/ + `.exe`. Reviewer's original ask. - containment: `materialize.ts` now uses `Filesystem.containsReal` (symlink- aware realpath + `..`-segment rejection). The old lexical `startsWith(resolvedParent + path.sep)` was bypassable via a symlinked `targetParent`, which is exactly the class of attack that helper was built to catch. - atomic JSON writes: extracted `Filesystem.writeJsonAtomic` in `util/filesystem.ts`. `marker.ts::writeMarker` now uses it. Prior in-file tmp-file + rename dance was duplicated in three other places (persistence.ts, memory/store.ts, tracing.ts) — those can migrate at their own pace; extraction is the enabling step. - MATERIALIZE_ENTRIES single-sourcing: the shipped-file list previously lived in three places (materialize.ts const, publish.ts cp block, publish-parity.test.ts hardcoded copy). Now lives once in `sample-manifest.json` as an `assets` array. `readSampleAssets()` reads it in both materialize (runtime copy) and publish (release copy). The parity test collapses from "three lists in sync" to "manifest matches disk". Adding a new sample file is a one-line manifest edit. - Glob.scan in freshness test: replaced the local recursive `walk()` with `Glob.scan("models/**/*.sql")` + `Glob.scan("seeds/**/*.csv")` from the shared core util. Deferred (kept, with rationale — see PR discussion for full triage): - manifest read/parse (5): `loadRawManifest` in altimate/native/dbt caches and returns mutable shared refs; partial merge later. - sha256 file hash (6): `Hash.sha256` exists; dbtFileHash's rstrip-`\n` semantics is the value-add — keep as a thin wrapper (later). - suffix hunt (8): our findSafeTarget has richer semantics (marker awareness, hex fallback, bail-early) than core/src/project/copy.ts. - hasSampleShape (9): keep, later rename to also check sample-manifest.json. - regenerate.sh (10): maintainer script; explicit "dbt on PATH" prereq.
1 parent 33f6e3a commit cb53255

9 files changed

Lines changed: 269 additions & 169 deletions

File tree

‎packages/opencode/sample-projects/jaffle-shop-duckdb/sample-manifest.json‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,16 @@
1212
"Renamed profile from the original test fixture: `test_jaffle_shop` → `jaffle_shop`.",
1313
"DuckDB target file resolves project-relative at `target/jaffle.duckdb`; no host paths bake into the profile.",
1414
"target/manifest.json ships pre-compiled so static workflows (/discover, /review) work without dbt installed."
15+
],
16+
"$assets_comment": "Single source of truth for the file list shipped to end users. `packages/opencode/src/altimate/onboarding/materialize.ts` copies these into the user's home; `packages/opencode/script/publish.ts` copies the same list into the wrapper npm package at release time; `packages/opencode/test/altimate/onboarding/publish-parity.test.ts` cross-checks both consumers use the same list. Adding a new sample file? Add it here — everything else picks it up automatically.",
17+
"assets": [
18+
{ "from": "README.md", "kind": "file", "required": true },
19+
{ "from": "dbt_project.yml", "kind": "file", "required": true },
20+
{ "from": "profiles.yml", "kind": "file", "required": true },
21+
{ "from": "sample-manifest.json", "kind": "file", "required": true },
22+
{ "from": ".gitignore", "kind": "file", "required": false },
23+
{ "from": "models", "kind": "dir", "required": true },
24+
{ "from": "seeds", "kind": "dir", "required": true },
25+
{ "from": "target/manifest.json", "kind": "file", "required": true }
1526
]
1627
}

‎packages/opencode/sample-projects/jaffle-shop-duckdb/verify-freshness.test.ts‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { describe, expect, test } from "bun:test"
2424
import { createHash } from "node:crypto"
2525
import fs from "node:fs"
2626
import path from "node:path"
27+
import { Glob } from "@opencode-ai/core/util/glob"
2728

2829
const SAMPLE_DIR = path.resolve(__dirname)
2930
const MANIFEST_PATH = path.join(SAMPLE_DIR, "target", "manifest.json")
@@ -110,23 +111,15 @@ describe("verify-freshness — committed manifest matches source files", () => {
110111
for (const node of Object.values(nodes)) {
111112
if (node.original_file_path) manifestPaths.add(node.original_file_path)
112113
}
113-
// Enumerate the actual source tree the maintainer curates. Only files
114-
// dbt itself would compile: .sql models, .csv seeds. Docs, YAML,
115-
// manifest metadata files are not per-file compiled — dbt notices
116-
// schema.yml through its own parser and doesn't emit a checksum'd
117-
// node for it.
118-
const expectedFiles: string[] = []
119-
const walk = (relDir: string, exts: RegExp) => {
120-
const absDir = path.join(SAMPLE_DIR, relDir)
121-
if (!fs.existsSync(absDir)) return
122-
for (const entry of fs.readdirSync(absDir, { withFileTypes: true })) {
123-
const relPath = path.join(relDir, entry.name)
124-
if (entry.isDirectory()) walk(relPath, exts)
125-
else if (exts.test(entry.name)) expectedFiles.push(relPath)
126-
}
127-
}
128-
walk("models", /\.sql$/)
129-
walk("seeds", /\.csv$/)
114+
// Enumerate the actual source tree the maintainer curates via the shared
115+
// `Glob.scan` helper (re-exports node-glob). Only files dbt itself would
116+
// compile: .sql models, .csv seeds. Docs, YAML, manifest metadata files
117+
// are not per-file compiled — dbt notices schema.yml through its own
118+
// parser and doesn't emit a checksum'd node for it.
119+
const expectedFiles = [
120+
...Glob.scanSync("models/**/*.sql", { cwd: SAMPLE_DIR }),
121+
...Glob.scanSync("seeds/**/*.csv", { cwd: SAMPLE_DIR }),
122+
]
130123
const missing = expectedFiles.filter((f) => !manifestPaths.has(f))
131124
expect(
132125
missing,

‎packages/opencode/script/publish.ts‎

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,34 @@ async function copyAssets(targetDir: string) {
8383
// src/altimate/onboarding/sample-source-resolver.ts finds it here in
8484
// production. Excludes target/ except the pre-compiled manifest.json
8585
// (source of truth for /discover + /review on the shipped sample).
86-
await $`mkdir -p ${targetDir}/sample-projects/jaffle-shop-duckdb/target`
87-
// Keep this list in sync with MATERIALIZE_ENTRIES in
88-
// packages/opencode/src/altimate/onboarding/materialize.ts — if publish
89-
// omits a file the materializer expects, dev works but prod ships without
90-
// it. `.gitignore` is intentionally shipped: the materialized sample
91-
// becomes a working dbt project in the user's home and needs it to
92-
// ignore compiled artifacts.
93-
await $`cp -r ./sample-projects/jaffle-shop-duckdb/.gitignore \
94-
./sample-projects/jaffle-shop-duckdb/README.md \
95-
./sample-projects/jaffle-shop-duckdb/dbt_project.yml \
96-
./sample-projects/jaffle-shop-duckdb/profiles.yml \
97-
./sample-projects/jaffle-shop-duckdb/sample-manifest.json \
98-
./sample-projects/jaffle-shop-duckdb/models \
99-
./sample-projects/jaffle-shop-duckdb/seeds \
100-
${targetDir}/sample-projects/jaffle-shop-duckdb/`
101-
await $`cp ./sample-projects/jaffle-shop-duckdb/target/manifest.json \
102-
${targetDir}/sample-projects/jaffle-shop-duckdb/target/manifest.json`
86+
//
87+
// Single source of truth: the file list comes from `sample-manifest.json`
88+
// (assets array). materialize.ts reads the same list at runtime, and
89+
// publish-parity.test.ts asserts every asset exists in the shipped
90+
// package. Adding a new sample file? Edit sample-manifest.json.
91+
const sampleSource = "./sample-projects/jaffle-shop-duckdb"
92+
const sampleDest = `${targetDir}/sample-projects/jaffle-shop-duckdb`
93+
const sampleManifest = JSON.parse(fs.readFileSync(`${sampleSource}/sample-manifest.json`, "utf8")) as {
94+
assets: Array<{ from: string; kind: "file" | "dir"; required: boolean }>
95+
}
96+
await $`mkdir -p ${sampleDest}`
97+
for (const asset of sampleManifest.assets) {
98+
const src = `${sampleSource}/${asset.from}`
99+
const dst = `${sampleDest}/${asset.from}`
100+
if (!fs.existsSync(src)) {
101+
if (asset.required) {
102+
throw new Error(`publish: required sample asset missing at ${src} — cannot ship an incomplete package`)
103+
}
104+
continue
105+
}
106+
// Create the parent (for nested paths like target/manifest.json).
107+
await $`mkdir -p ${sampleDest}/${asset.from.includes("/") ? asset.from.split("/").slice(0, -1).join("/") : "."}`
108+
if (asset.kind === "dir") {
109+
await $`cp -r ${src} ${dst}`
110+
} else {
111+
await $`cp ${src} ${dst}`
112+
}
113+
}
103114
// altimate_change end
104115
await Bun.file(`${targetDir}/LICENSE`).write(await Bun.file("../../LICENSE").text())
105116
await Bun.file(`${targetDir}/CHANGELOG.md`).write(await Bun.file("../../CHANGELOG.md").text())

‎packages/opencode/src/altimate/onboarding/marker.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { randomBytes } from "node:crypto"
22
import fs from "node:fs"
33
import path from "node:path"
4+
import { Filesystem } from "../../util/filesystem"
45

56
/**
67
* Marker file that identifies a directory as an altimate-code-materialized
@@ -57,13 +58,11 @@ export function readMarker(dir: string): SampleMarker | undefined {
5758

5859
/** Write the marker atomically. Overwrites any existing marker in the dir.
5960
* Caller MUST have already decided the dir is safe to write (via
60-
* classifyTarget) — this function does not itself refuse. */
61+
* classifyTarget) — this function does not itself refuse. Uses the shared
62+
* {@link Filesystem.writeJsonAtomic} helper so the tmp-file + rename dance
63+
* isn't duplicated per call site. */
6164
export function writeMarker(dir: string, marker: SampleMarker): void {
62-
const markerPath = path.join(dir, MARKER_FILE_NAME)
63-
const tmpPath = `${markerPath}.tmp-${process.pid}`
64-
fs.mkdirSync(dir, { recursive: true })
65-
fs.writeFileSync(tmpPath, JSON.stringify(marker, null, 2) + "\n")
66-
fs.renameSync(tmpPath, markerPath) // atomic on POSIX
65+
Filesystem.writeJsonAtomic(path.join(dir, MARKER_FILE_NAME), marker)
6766
}
6867

6968
/** Classify a candidate materialization target. Never throws.

‎packages/opencode/src/altimate/onboarding/materialize.ts‎

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from "node:path"
55
import { Flock } from "@opencode-ai/core/util/flock"
66
import { MARKER_KIND, checkParentWritable, classifyTarget, findSafeTarget, writeMarker, type TargetState } from "./marker"
77
import { DEFAULT_SAMPLE_NAME, loadShippedManifest, resolveSampleSource, type SampleSourceLocation } from "./sample-source-resolver"
8+
import { Filesystem } from "../../util/filesystem"
89

910
/**
1011
* Materialize the shipped starter sample onto the user's filesystem.
@@ -28,24 +29,52 @@ import { DEFAULT_SAMPLE_NAME, loadShippedManifest, resolveSampleSource, type Sam
2829
* end users.
2930
*/
3031

31-
/** Files/dirs relative to the sample source that get materialized to the
32-
* user's target dir. Explicitly enumerated (no glob) so future changes
33-
* to the sample layout are a deliberate opt-in edit here. */
34-
const MATERIALIZE_ENTRIES: ReadonlyArray<{ from: string; kind: "file" | "dir"; required: boolean }> = [
35-
{ from: "README.md", kind: "file", required: true },
36-
{ from: "dbt_project.yml", kind: "file", required: true },
37-
{ from: "profiles.yml", kind: "file", required: true },
38-
{ from: "sample-manifest.json", kind: "file", required: true },
39-
// .gitignore is the ONLY optional entry — dev checkouts may lack it and
40-
// materialize should not fail. Every other entry is load-bearing for
41-
// /discover, /review, or the "Build & query it" flow; missing any of
42-
// them means a broken package and we must fail loudly rather than mark
43-
// the incomplete copy as reused-forever.
44-
{ from: ".gitignore", kind: "file", required: false },
45-
{ from: "models", kind: "dir", required: true },
46-
{ from: "seeds", kind: "dir", required: true },
47-
{ from: "target/manifest.json", kind: "file", required: true },
48-
]
32+
/** Shape of an entry in the sample-manifest.json `assets` array. */
33+
export interface SampleAsset {
34+
from: string
35+
kind: "file" | "dir"
36+
required: boolean
37+
}
38+
39+
/**
40+
* Read the asset list from a sample source's `sample-manifest.json`. Single
41+
* source of truth — publish.ts, materialize.ts, and the publish-parity test
42+
* all consume this list, so a new file added to the sample only needs to
43+
* be listed in one place. Adding a new sample entry?
44+
* Edit `sample-manifest.json`'s `assets` array; everything else picks it up.
45+
*
46+
* `.gitignore` is typically the ONLY optional entry — dev checkouts may lack
47+
* it and materialize should not fail. Every other entry should be
48+
* load-bearing for /discover, /review, or the "Build & query it" flow;
49+
* missing a required entry means a broken package and copySampleTree
50+
* fails loudly rather than mark the incomplete copy as reused-forever.
51+
*/
52+
export function readSampleAssets(sampleSourcePath: string): SampleAsset[] {
53+
const manifestPath = path.join(sampleSourcePath, "sample-manifest.json")
54+
const raw = fs.readFileSync(manifestPath, "utf8")
55+
const parsed = JSON.parse(raw) as { assets?: unknown }
56+
if (!Array.isArray(parsed.assets)) {
57+
throw new Error(
58+
`${manifestPath} must define an 'assets' array. See the docstring on SampleAsset.`,
59+
)
60+
}
61+
const out: SampleAsset[] = []
62+
for (const [i, entry] of parsed.assets.entries()) {
63+
if (
64+
entry === null ||
65+
typeof entry !== "object" ||
66+
typeof (entry as any).from !== "string" ||
67+
((entry as any).kind !== "file" && (entry as any).kind !== "dir") ||
68+
typeof (entry as any).required !== "boolean"
69+
) {
70+
throw new Error(
71+
`${manifestPath} assets[${i}] must be { from: string, kind: "file"|"dir", required: boolean }`,
72+
)
73+
}
74+
out.push(entry as SampleAsset)
75+
}
76+
return out
77+
}
4978

5079
export interface MaterializeOptions {
5180
/** Sample-source lookup name (defaults to jaffle-shop-duckdb). */
@@ -271,11 +300,13 @@ async function materializeUnderLock(
271300
// Belt-and-suspenders containment check. The name-regex above should already
272301
// guarantee this, but findSafeTarget also joins a numeric/hex suffix and any
273302
// future edit to that logic must not sneak the target outside targetParent.
274-
const resolvedParent = path.resolve(targetParent)
275-
const resolvedTarget = path.resolve(targetPath)
276-
if (resolvedTarget !== resolvedParent && !resolvedTarget.startsWith(resolvedParent + path.sep)) {
303+
// Uses `Filesystem.containsReal` (symlink-aware realpath + `..`-segment
304+
// rejection) rather than a lexical `startsWith` — an earlier version was
305+
// bypassable via a symlinked targetParent, which is exactly what
306+
// `containsReal` was built to catch.
307+
if (!Filesystem.containsReal(targetParent, targetPath)) {
277308
throw new Error(
278-
`refusing to materialize outside targetParent: resolved '${resolvedTarget}' is not under '${resolvedParent}'`,
309+
`refusing to materialize outside targetParent: '${targetPath}' is not under (or is not a symlink-safe descendant of) '${targetParent}'`,
279310
)
280311
}
281312

@@ -425,7 +456,7 @@ function sweepOrphanStaging(targetParent: string, preferredName: string): void {
425456
*/
426457
function copySampleTree(source: string, writeTo: string, finalTarget: string): void {
427458
fs.mkdirSync(writeTo, { recursive: true })
428-
for (const entry of MATERIALIZE_ENTRIES) {
459+
for (const entry of readSampleAssets(source)) {
429460
const from = path.join(source, entry.from)
430461
const to = path.join(writeTo, entry.from)
431462
if (!fs.existsSync(from)) {
Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import { execFile } from "node:child_process"
2+
// Direct cross-workspace import — `@altimateai/dbt-tools`'s `src/index.ts` is
3+
// a CLI entry (runs on import), so we bypass the package entrypoint and
4+
// consume the resolver from its file directly. This is the same pattern
5+
// other packages use to share pure utilities across workspace boundaries
6+
// without adding subpath-exports maps.
7+
import { resolveDbt, validateDbt, buildDbtEnv } from "../../../../dbt-tools/src/dbt-resolve"
28

39
/**
410
* Probe the user's machine for the toolchain the sample project needs to
@@ -10,6 +16,15 @@ import { execFile } from "node:child_process"
1016
* `dbt-duckdb` adapter installed against the same Python. We probe both so
1117
* the post-materialize UX can hide options that would silently fail.
1218
*
19+
* Delegates dbt binary lookup to `resolveDbt` + `validateDbt` from the
20+
* dbt-tools library. That path knows about every Python env manager
21+
* (venv, uv, pyenv, conda, pipx, poetry, pdm, homebrew, pip, asdf/mise,
22+
* nix, hatch, rye, docker, dbt Fusion) — most of which do NOT put dbt on
23+
* PATH. A prior implementation used plain `execFile("dbt")` which meant
24+
* users with dbt in a venv would see `dbt: missing` even though it was
25+
* right there. Reviewer flagged this; single-sourcing the resolver fixes
26+
* it and keeps future env-manager additions automatic.
27+
*
1328
* Detection is intentionally lightweight — we do NOT invoke `dbt debug`
1429
* against the materialized sample here, because this runs BEFORE
1530
* materialization (to decide which workflow entries to show in the first
@@ -22,7 +37,7 @@ import { execFile } from "node:child_process"
2237
*/
2338

2439
export interface DbtRuntime {
25-
/** `dbt --version` succeeded (dbt-core is on PATH). */
40+
/** `dbt --version` succeeded (dbt-core is on PATH or found by resolveDbt). */
2641
hasDbt: boolean
2742
/** `dbt --version` output mentions duckdb — best effort at "the adapter is
2843
* installed against the same Python that owns this `dbt`". */
@@ -59,59 +74,52 @@ export function _resetDbtRuntimeCacheForTests() {
5974
}
6075

6176
async function probe(): Promise<DbtRuntime> {
62-
// Node's `execFile("dbt")` on Windows uses CreateProcess, which honours
63-
// PATHEXT for `.exe`/`.com` but NOT `.cmd`/`.bat` (those need a shell).
64-
// Some Windows dbt install layouts (older `pip install --user`, certain
65-
// corporate distributions, WSL-bridge shims) drop a `dbt.cmd` wrapper
66-
// on PATH instead of `dbt.exe`. Without a fallback we'd tell those
67-
// users "dbt: missing" on the template's Build & query it branch even
68-
// when dbt is right there.
69-
//
70-
// Fix: on Windows, if the direct probe misses, retry through
71-
// `cmd.exe /c dbt --version` — cmd's own resolver honours the full
72-
// PATHEXT (including `.cmd`/`.bat`) and finds any of the wrapper
73-
// shapes. Args are constant strings so there's no injection surface.
74-
// On macOS/Linux we skip the retry — one shell-less probe is enough.
75-
let out = await tryExec("dbt", ["--version"], 5_000)
76-
if (!out.ok && process.platform === "win32") {
77-
out = await tryExec("cmd.exe", ["/c", "dbt", "--version"], 5_000)
78-
}
79-
if (!out.ok) return { hasDbt: false, hasDbtDuckdb: false }
77+
// resolveDbt: multi-manager search (venv/uv/pyenv/conda/pipx/poetry/…
78+
// + PATH + explicit override via ALTIMATE_DBT_PATH). Returns the first
79+
// candidate that exists + is executable.
80+
const resolved = resolveDbt()
81+
// validateDbt: runs `<path> --version`, parses version + Fusion detection.
82+
// Returns null on ENOENT/timeout/non-zero exit.
83+
const validated = validateDbt(resolved)
84+
if (!validated) return { hasDbt: false, hasDbtDuckdb: false }
8085

81-
// dbt --version on 1.x prints something like:
86+
// For the dbt-duckdb adapter check, re-run --version and grep the plugin
87+
// list. buildDbtEnv() gives us the right PATH so venv-scoped dbts find
88+
// their adapters. validateDbt doesn't return raw output, so this is the
89+
// one bit of duplicate subprocess work we accept — cheaper than teaching
90+
// validateDbt to expose plugins.
91+
const versionOut = await captureVersionOutput(resolved.path, buildDbtEnv(resolved))
92+
// dbt --version on 1.x prints:
8293
// Core:
8394
// - installed: 1.11.8
84-
// - latest: 1.12.0 - Update available!
8595
// Plugins:
8696
// - duckdb: 1.11.4 - Update available!
87-
// We look for the plugin line specifically ("- duckdb:") rather than any
88-
// "duckdb" substring so the presence of the word inside an upgrade hint
89-
// ("Try dbt-duckdb...") doesn't false-positive.
90-
const combined = `${out.stdout}\n${out.stderr}`
91-
const hasDbtDuckdb = /^\s*-\s*duckdb:/m.test(combined)
92-
93-
const versionMatch = combined.match(/-\s*installed:\s*([0-9]+\.[0-9]+\.[0-9]+)/)
94-
const dbtCoreVersion = versionMatch?.[1]
97+
// Match the plugin line specifically ("- duckdb:") — a generic "duckdb"
98+
// substring would false-positive on an "install dbt-duckdb" upgrade hint.
99+
const hasDbtDuckdb = /^\s*-\s*duckdb:/m.test(versionOut)
95100

101+
// Version fallback: some dbt 1.x builds write `--version` output to
102+
// STDERR (with color codes). validateDbt uses execFileSync which reads
103+
// stdout only, so it reports "unknown" for those. We already collected
104+
// stdout+stderr via captureVersionOutput for the plugin check — reuse
105+
// that combined text to recover the version.
106+
let dbtCoreVersion = validated.version === "unknown" ? undefined : validated.version
107+
if (!dbtCoreVersion) {
108+
const m = versionOut.match(/-\s*installed:\s*([0-9]+\.[0-9]+\.[0-9]+\S*)/) ?? versionOut.match(/core=([0-9]+\.[0-9]+\.[0-9]+\S*)/)
109+
if (m) dbtCoreVersion = m[1]
110+
}
96111
return { hasDbt: true, hasDbtDuckdb, dbtCoreVersion }
97112
}
98113

99-
interface ExecResult {
100-
ok: boolean
101-
stdout: string
102-
stderr: string
103-
}
104-
105-
function tryExec(cmd: string, args: string[], timeoutMs: number): Promise<ExecResult> {
114+
/** One extra `<dbt> --version` invocation to grab the plugin list, using
115+
* the environment resolveDbt/buildDbtEnv gave us (correct PATH for
116+
* venv-scoped installs). Falls through as empty on any error — the outer
117+
* `hasDbt` flag from validateDbt has already told us dbt itself works. */
118+
function captureVersionOutput(dbtPath: string, env: Record<string, string | undefined>): Promise<string> {
106119
return new Promise((resolve) => {
107-
execFile(cmd, args, { timeout: timeoutMs }, (error, stdout, stderr) => {
108-
if (error) {
109-
// ENOENT = not on PATH; timeout, non-zero exit, other errors all
110-
// resolve as "not usable". Never rejects.
111-
resolve({ ok: false, stdout: stdout || "", stderr: stderr || String(error) })
112-
return
113-
}
114-
resolve({ ok: true, stdout: stdout || "", stderr: stderr || "" })
120+
execFile(dbtPath, ["--version"], { timeout: 5_000, env: env as NodeJS.ProcessEnv }, (_error, stdout, stderr) => {
121+
resolve(`${stdout || ""}\n${stderr || ""}`)
115122
})
116123
})
117124
}
125+

0 commit comments

Comments
 (0)