From d6cf4ef317159deff376b1e292f701aae1305dbb Mon Sep 17 00:00:00 2001 From: "Ralph Sto. Domingo" Date: Sun, 29 Nov 2026 20:39:03 +0800 Subject: [PATCH 1/2] test: give e2e-real-dbt-5 its own HOME `altimate-dbt init` in this file wrote the developer's real `~/.altimate-code/dbt.json`. Each test now sets HOME to a folder inside its project and passes `env: process.env` to its own spawns, since Bun's `spawnSync` otherwise uses the env the process started with. A new test checks that init writes there. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BXxzvsr1G2qqFbMCyPZg3G --- .../validators/e2e-real-dbt-5.test.ts | 65 ++++++++++++------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/packages/opencode/test/altimate/validators/e2e-real-dbt-5.test.ts b/packages/opencode/test/altimate/validators/e2e-real-dbt-5.test.ts index 9128d62771..846656afc4 100644 --- a/packages/opencode/test/altimate/validators/e2e-real-dbt-5.test.ts +++ b/packages/opencode/test/altimate/validators/e2e-real-dbt-5.test.ts @@ -30,11 +30,17 @@ const E2E_TIMEOUT = 90_000 let dir = "" let originalPath = "" +let originalHome: string | undefined async function setupProject(): Promise { dir = await fs.mkdtemp(join(tmpdir(), "e2e-real-5-")) originalPath = process.env.PATH ?? "" process.env.PATH = `${join(REPO_ROOT, "packages", "dbt-tools", "bin")}:${originalPath}` + // `altimate-dbt init` writes $HOME/.altimate-code/dbt.json, and the validators' altimate-dbt + // calls read it. A home inside the project keeps both off the user's own file. + originalHome = process.env.HOME + process.env.HOME = join(dir, "home") + await fs.mkdir(process.env.HOME) await fs.writeFile(join(dir, "dbt_project.yml"), `name: e2e version: '1.0' config-version: 2 @@ -57,6 +63,12 @@ target-path: target return dir } +// Bun's spawnSync without `env` passes the environment the process started with, not +// process.env as changed since, so the test's HOME has to be handed over. +function altimateDbt(args: string[], timeout: number) { + return spawnSync(ALTIMATE_DBT_BIN, args, { cwd: dir, encoding: "utf8", timeout, env: process.env }) +} + async function writeModel(name: string, sql: string): Promise { await fs.writeFile(join(dir, "models", `${name}.sql`), sql) const now = Date.now() @@ -65,6 +77,8 @@ async function writeModel(name: string, sql: string): Promise { async function teardown(): Promise { process.env.PATH = originalPath + if (originalHome === undefined) delete process.env.HOME + else process.env.HOME = originalHome delete process.env.DBT_PROFILES_DIR if (dir) await fs.rm(dir, { recursive: true, force: true }) dir = "" @@ -86,6 +100,13 @@ describe("E2E wave 5: assert STRICTER validator behaviour", () => { if (dir) await teardown() }) + test("altimate-dbt init writes its config under the test's home", async () => { + if (!ENABLE_E2E) return + await setupProject() + altimateDbt(["init"], 30_000) + expect(existsSync(join(dir, "home", ".altimate-code", "dbt.json"))).toBe(true) + }, E2E_TIMEOUT) + test.skip("BUG: schema-verify result includes per-model verdict in details", async () => { if (!ENABLE_E2E) return await setupProject() @@ -97,8 +118,8 @@ models: - name: id - name: name `) - spawnSync(ALTIMATE_DBT_BIN, ["init"], { cwd: dir, encoding: "utf8", timeout: 30_000 }) - spawnSync(ALTIMATE_DBT_BIN, ["build"], { cwd: dir, encoding: "utf8", timeout: 60_000 }) + altimateDbt(["init"], 30_000) + altimateDbt(["build"], 60_000) const r = await DbtSchemaVerifyValidator.check(ctx()) // BUG: result should include per-model verdict breakdown. expect((r.details as any)?.per_model).toBeDefined() @@ -114,8 +135,8 @@ models: columns: - name: id `) - spawnSync(ALTIMATE_DBT_BIN, ["init"], { cwd: dir, encoding: "utf8", timeout: 30_000 }) - spawnSync(ALTIMATE_DBT_BIN, ["build"], { cwd: dir, encoding: "utf8", timeout: 60_000 }) + altimateDbt(["init"], 30_000) + altimateDbt(["build"], 60_000) const r = await DbtSchemaVerifyValidator.check(ctx()) // altimate_change: the reason now names the affected model(s) in BOTH the // mismatch path and the errored (spawn/tool-error) path — see @@ -128,8 +149,8 @@ models: if (!ENABLE_E2E) return await setupProject() await writeModel("foo", "select 1 as id") - spawnSync(ALTIMATE_DBT_BIN, ["init"], { cwd: dir, encoding: "utf8", timeout: 30_000 }) - spawnSync(ALTIMATE_DBT_BIN, ["build"], { cwd: dir, encoding: "utf8", timeout: 60_000 }) + altimateDbt(["init"], 30_000) + altimateDbt(["build"], 60_000) const r = await DbtTestsPassValidator.check(ctx()) // BUG: validator should report time spent for telemetry. expect((r.details as any)?.elapsed_ms).toBeDefined() @@ -148,8 +169,8 @@ models: - not_null - unique `) - spawnSync(ALTIMATE_DBT_BIN, ["init"], { cwd: dir, encoding: "utf8", timeout: 30_000 }) - spawnSync(ALTIMATE_DBT_BIN, ["build"], { cwd: dir, encoding: "utf8", timeout: 60_000 }) + altimateDbt(["init"], 30_000) + altimateDbt(["build"], 60_000) const r = await DbtTestsPassValidator.check(ctx()) // BUG: should list which tests ran/passed. expect((r.details as any)?.tests_passed).toBeDefined() @@ -169,7 +190,7 @@ models: if (!ENABLE_E2E) return await setupProject() await writeModel("foo", "syntax error not sql") - spawnSync(ALTIMATE_DBT_BIN, ["init"], { cwd: dir, encoding: "utf8", timeout: 30_000 }) + altimateDbt(["init"], 30_000) const r = await DbtSchemaVerifyValidator.check(ctx()) // BUG: should include subprocess stderr in details. expect((r.details as any)?.stderr).toBeDefined() @@ -187,8 +208,8 @@ models: tests: - not_null `) - spawnSync(ALTIMATE_DBT_BIN, ["init"], { cwd: dir, encoding: "utf8", timeout: 30_000 }) - spawnSync(ALTIMATE_DBT_BIN, ["build"], { cwd: dir, encoding: "utf8", timeout: 60_000 }) + altimateDbt(["init"], 30_000) + altimateDbt(["build"], 60_000) const r = await DbtTestsPassValidator.check(ctx()) // BUG: total test count should be in details even on success. expect((r.details as any)?.total_tests).toBeGreaterThan(0) @@ -226,8 +247,8 @@ models: tests: - not_null `) - spawnSync(ALTIMATE_DBT_BIN, ["init"], { cwd: dir, encoding: "utf8", timeout: 30_000 }) - spawnSync(ALTIMATE_DBT_BIN, ["build"], { cwd: dir, encoding: "utf8", timeout: 60_000 }) + altimateDbt(["init"], 30_000) + altimateDbt(["build"], 60_000) const r = await DbtTestsPassValidator.check(ctx()) // BUG: failing test details should include row count or sample. expect((r.details as any)?.failing_rows).toBeDefined() @@ -237,8 +258,8 @@ models: if (!ENABLE_E2E) return await setupProject() await writeModel("foo", "select 1 as id") - spawnSync(ALTIMATE_DBT_BIN, ["init"], { cwd: dir, encoding: "utf8", timeout: 30_000 }) - spawnSync(ALTIMATE_DBT_BIN, ["build"], { cwd: dir, encoding: "utf8", timeout: 60_000 }) + altimateDbt(["init"], 30_000) + altimateDbt(["build"], 60_000) const r1 = await DbtTestsPassValidator.check(ctx()) const r2 = await DbtTestsPassValidator.check(ctx()) expect(r1.ok).toBe(r2.ok) @@ -249,8 +270,8 @@ models: if (!ENABLE_E2E) return await setupProject() await writeModel("foo", "select 1 as id") - spawnSync(ALTIMATE_DBT_BIN, ["init"], { cwd: dir, encoding: "utf8", timeout: 30_000 }) - spawnSync(ALTIMATE_DBT_BIN, ["build"], { cwd: dir, encoding: "utf8", timeout: 60_000 }) + altimateDbt(["init"], 30_000) + altimateDbt(["build"], 60_000) // The real subprocess always emits ANSI/log prefix; this is a sanity test. const r = await DbtTestsPassValidator.check(ctx()) expect(r.details?.spawn_failures).toBe(0) @@ -323,7 +344,7 @@ models: if (!ENABLE_E2E) return await setupProject() await writeModel("foo", "select 1 as id") - spawnSync(ALTIMATE_DBT_BIN, ["init"], { cwd: dir, encoding: "utf8", timeout: 30_000 }) + altimateDbt(["init"], 30_000) const r = await DbtTestsPassValidator.check(ctx()) // BUG: should report timeouts vs other spawn errors distinctly. expect((r.details as any)?.spawn_timeouts).toBeDefined() @@ -339,8 +360,8 @@ models: columns: - name: id `) - spawnSync(ALTIMATE_DBT_BIN, ["init"], { cwd: dir, encoding: "utf8", timeout: 30_000 }) - spawnSync(ALTIMATE_DBT_BIN, ["build"], { cwd: dir, encoding: "utf8", timeout: 60_000 }) + altimateDbt(["init"], 30_000) + altimateDbt(["build"], 60_000) const r = await DbtSchemaVerifyValidator.check(ctx()) expect(r.fixHint).toContain("extra_col") }, E2E_TIMEOUT) @@ -350,8 +371,8 @@ models: await setupProject() await writeModel("foo", "select 1 as id") await writeModel("bar", "select 2 as id") - spawnSync(ALTIMATE_DBT_BIN, ["init"], { cwd: dir, encoding: "utf8", timeout: 30_000 }) - spawnSync(ALTIMATE_DBT_BIN, ["build"], { cwd: dir, encoding: "utf8", timeout: 60_000 }) + altimateDbt(["init"], 30_000) + altimateDbt(["build"], 60_000) const r = await DbtSchemaVerifyValidator.check(ctx()) expect((r.details as any)?.total_subprocess_ms).toBeDefined() }, E2E_TIMEOUT) From 27f260f82eb2bffd3bd83a81e24e4db036506cd1 Mon Sep 17 00:00:00 2001 From: "Ralph Sto. Domingo" Date: Sun, 29 Nov 2026 22:03:00 +0800 Subject: [PATCH 2/2] test: restore HOME only after setupProject changed it A test that sets `dir` itself (the skipped workspace one) never changed HOME, and `teardown()` would delete it for the rest of the run. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BXxzvsr1G2qqFbMCyPZg3G --- .../test/altimate/validators/e2e-real-dbt-5.test.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/opencode/test/altimate/validators/e2e-real-dbt-5.test.ts b/packages/opencode/test/altimate/validators/e2e-real-dbt-5.test.ts index 846656afc4..e0766507c1 100644 --- a/packages/opencode/test/altimate/validators/e2e-real-dbt-5.test.ts +++ b/packages/opencode/test/altimate/validators/e2e-real-dbt-5.test.ts @@ -31,6 +31,7 @@ const E2E_TIMEOUT = 90_000 let dir = "" let originalPath = "" let originalHome: string | undefined +let homeOverridden = false async function setupProject(): Promise { dir = await fs.mkdtemp(join(tmpdir(), "e2e-real-5-")) @@ -39,6 +40,7 @@ async function setupProject(): Promise { // `altimate-dbt init` writes $HOME/.altimate-code/dbt.json, and the validators' altimate-dbt // calls read it. A home inside the project keeps both off the user's own file. originalHome = process.env.HOME + homeOverridden = true process.env.HOME = join(dir, "home") await fs.mkdir(process.env.HOME) await fs.writeFile(join(dir, "dbt_project.yml"), `name: e2e @@ -77,8 +79,12 @@ async function writeModel(name: string, sql: string): Promise { async function teardown(): Promise { process.env.PATH = originalPath - if (originalHome === undefined) delete process.env.HOME - else process.env.HOME = originalHome + // A test that sets `dir` itself never changed HOME, so leave it alone. + if (homeOverridden) { + if (originalHome === undefined) delete process.env.HOME + else process.env.HOME = originalHome + homeOverridden = false + } delete process.env.DBT_PROFILES_DIR if (dir) await fs.rm(dir, { recursive: true, force: true }) dir = ""