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..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 @@ -30,11 +30,19 @@ 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-")) 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 + homeOverridden = true + 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 +65,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 +79,12 @@ async function writeModel(name: string, sql: string): Promise { async function teardown(): Promise { process.env.PATH = originalPath + // 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 = "" @@ -86,6 +106,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 +124,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 +141,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 +155,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 +175,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 +196,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 +214,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 +253,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 +264,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 +276,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 +350,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 +366,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 +377,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)