Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 49 additions & 22 deletions packages/opencode/test/altimate/validators/e2e-real-dbt-5.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ const E2E_TIMEOUT = 90_000

let dir = ""
let originalPath = ""
let originalHome: string | undefined
let homeOverridden = false

async function setupProject(): Promise<string> {
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")
Comment thread
ralphstodomingo marked this conversation as resolved.
Resolved
await fs.mkdir(process.env.HOME)
await fs.writeFile(join(dir, "dbt_project.yml"), `name: e2e
version: '1.0'
config-version: 2
Expand All @@ -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) {
Comment thread
ralphstodomingo marked this conversation as resolved.
Resolved
return spawnSync(ALTIMATE_DBT_BIN, args, { cwd: dir, encoding: "utf8", timeout, env: process.env })
}

async function writeModel(name: string, sql: string): Promise<void> {
await fs.writeFile(join(dir, "models", `${name}.sql`), sql)
const now = Date.now()
Expand All @@ -65,6 +79,12 @@ async function writeModel(name: string, sql: string): Promise<void> {

async function teardown(): Promise<void> {
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 = ""
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading