Skip to content

test: dbt helpers — loadRawManifest, getUniqueId, extractColumns, listModelNames#690

Open
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260410-2018
Open

test: dbt helpers — loadRawManifest, getUniqueId, extractColumns, listModelNames#690
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260410-2018

Conversation

@anandgupta42
Copy link
Copy Markdown
Contributor

@anandgupta42 anandgupta42 commented Apr 10, 2026

Summary

1. loadRawManifestsrc/altimate/native/dbt/helpers.ts (7 new tests)

This function loads and caches dbt manifest.json files by resolved path + mtime. It is the shared entry point used by dbtLineage(), generateDbtUnitTests(), and parseManifest(). Zero tests existed. A cache bug would silently serve stale manifest data to every dbt tool. New coverage includes:

  • Returns null for non-existent files
  • Parses valid JSON and returns the object
  • Throws on invalid JSON
  • Documents that JSON arrays pass through the typeof guard (not caught by the typeof !== "object" check — known edge case)
  • Throws on JSON primitives (strings)
  • Cache hit: same object reference returned when file unchanged
  • Cache miss: re-reads when content + mtime change
  • Symlink resolution before caching (real path and symlink path yield same cached result)

2. getUniqueIdsrc/altimate/native/dbt/helpers.ts (6 new tests)

Looks up a model's unique_id by either direct key match or name scan, filtering by resource_type === "model". Used by dbtLineage() to populate model_unique_id in results. A bug here means lineage silently returns the wrong model ID. New coverage includes:

  • Direct unique_id key lookup
  • Name-based scan
  • Returns undefined for non-existent models
  • Does not match test nodes by name
  • Does not match seed nodes by name
  • Does not match by unique_id when resource_type is not "model"

3. extractColumnssrc/altimate/native/dbt/helpers.ts (6 new tests)

Extracts typed ModelColumn[] from a raw manifest columns dict, with fallback chains (col.name → dict key, col.data_type → col.type → ""). Used by unit test generation and lineage. Wrong column types propagate into generated YAML. New coverage includes:

  • Standard extraction with name and data_type
  • Fallback to dict key when col.name is missing
  • Fallback to col.type when data_type is missing
  • Description preservation
  • Empty dict returns empty array
  • Combined name + type fallbacks

4. listModelNamessrc/altimate/native/dbt/helpers.ts (3 new tests)

Filters manifest nodes by resource_type === "model" and returns names. Used for error messages. New coverage includes:

  • Returns only model names, excludes tests and seeds
  • Returns empty for all-non-model nodes
  • Returns empty for empty input

Type of change

  • New feature (non-breaking change which adds functionality)

Issue for this PR

N/A — proactive test coverage for shared dbt helper functions that had zero tests

How did you verify your code works?

bun test test/altimate/dbt-helpers.test.ts                  # 23 pass
bun test test/altimate/dbt-helpers.test.ts test/altimate/dbt-lineage-helpers.test.ts  # 36 pass (no cross-file conflicts)

Marker guard check passes: bun run script/upstream/analyze.ts --markers --base main --strict

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

https://claude.ai/code/session_01627CWGKN6jHiJvoTRQVj1e


Summary by cubic

Add unit tests for shared dbt helper functions to prevent stale manifests and wrong column types from slipping through. Tests cover loadRawManifest (cache by resolved path + mtime, invalid JSON, symlinks), getUniqueId (model-only lookup by key or name), extractColumns (name/type fallbacks, descriptions), and listModelNames (model filtering).

Written for commit 0166434. Summary will update on new commits.

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suite for dbt helper functionality including manifest loading, ID resolution, column extraction, and model listing.

…mns, listModelNames

These four exported helper functions in src/altimate/native/dbt/helpers.ts
had zero test coverage. They are shared foundations used by dbtLineage(),
generateDbtUnitTests(), and parseManifest(). A cache bug in loadRawManifest
would silently serve stale manifest data to every dbt tool; a fallback-chain
bug in extractColumns would produce wrong column types in generated YAML.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

https://claude.ai/code/session_01627CWGKN6jHiJvoTRQVj1e
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

A new Bun test suite added to validate core dbt helper functions including manifest loading, unique ID resolution, column extraction, and model name listing. The tests verify filesystem interactions, caching behavior, symlink handling, and edge cases like invalid JSON and missing resources.

Changes

Cohort / File(s) Summary
dbt-helpers test suite
packages/opencode/test/altimate/dbt-helpers.test.ts
Comprehensive test coverage for loadRawManifest (including caching, symlink resolution, JSON validation), getUniqueId (unique ID and model name resolution), extractColumns (name/type extraction with fallbacks), and listModelNames (model filtering). Tests use real filesystem interactions with cleanup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

contributor

Suggested reviewers

  • suryaiyer95

Poem

🐰 A rabbit hops through test files new,
Checking manifests, columns too!
dbt helpers dance, cache sings true,
Symlinks resolve—all paths shine through! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing the required PINEAPPLE marker at the top, which is explicitly mandated in the template for AI-generated contributions. Add the word PINEAPPLE at the very top of the PR description before any other content, as required by the repository template for AI-generated contributions.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding tests for four dbt helper functions (loadRawManifest, getUniqueId, extractColumns, listModelNames).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/hourly-20260410-2018

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/opencode/test/altimate/dbt-helpers.test.ts`:
- Around line 14-42: Replace the manual tempdir lifecycle (mkdtempSync in
makeTmpDir, tmpDirs array and afterEach cleanup with rmSync) with the shared
tmpdir fixture: import tmpdir from "fixture/fixture" and in each test use "await
using const tmp = await tmpdir()" (or the project's async fixture pattern) and
reference tmp.path instead of makeTmpDir; remove makeTmpDir, tmpDirs, and the
afterEach block, and update tests that call makeTmpDir to use tmp.path so
cleanup is handled by the fixture.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dca83229-522a-4cdc-86d6-04d5a0ad7c10

📥 Commits

Reviewing files that changed from the base of the PR and between f030bf8 and 0166434.

📒 Files selected for processing (1)
  • packages/opencode/test/altimate/dbt-helpers.test.ts

Comment on lines +14 to +42
import { describe, test, expect, afterEach } from "bun:test"
import { writeFileSync, mkdtempSync, rmSync, symlinkSync, utimesSync } from "fs"
import { tmpdir } from "os"
import { join } from "path"
import {
loadRawManifest,
getUniqueId,
extractColumns,
listModelNames,
} from "../../src/altimate/native/dbt/helpers"

// ---------------------------------------------------------------------------
// Fixtures
// ---------------------------------------------------------------------------

let tmpDirs: string[] = []

function makeTmpDir(): string {
const dir = mkdtempSync(join(tmpdir(), "dbt-helpers-test-"))
tmpDirs.push(dir)
return dir
}

afterEach(() => {
for (const dir of tmpDirs) {
rmSync(dir, { recursive: true, force: true })
}
tmpDirs = []
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Use the repository tmpdir fixture pattern instead of manual mkdtemp/rm cleanup.

This test file currently bypasses the required test tempdir lifecycle (mkdtempSync + shared array + afterEach). Please switch to tmpdir() from fixture/fixture.ts with await using and tmp.path in each test.

Suggested refactor pattern
-import { describe, test, expect, afterEach } from "bun:test"
-import { writeFileSync, mkdtempSync, rmSync, symlinkSync, utimesSync } from "fs"
-import { tmpdir } from "os"
+import { describe, test, expect } from "bun:test"
+import { writeFileSync, symlinkSync, utimesSync } from "fs"
+import { tmpdir } from "../fixture/fixture"

-let tmpDirs: string[] = []
-
-function makeTmpDir(): string {
-  const dir = mkdtempSync(join(tmpdir(), "dbt-helpers-test-"))
-  tmpDirs.push(dir)
-  return dir
-}
-
-afterEach(() => {
-  for (const dir of tmpDirs) {
-    rmSync(dir, { recursive: true, force: true })
-  }
-  tmpDirs = []
-})
+// Example inside each test:
+test("parses valid JSON manifest and returns object", async () => {
+  await using tmp = tmpdir()
+  const manifestPath = join(tmp.path, "valid-manifest.json")
+  // ...
+})

As per coding guidelines: packages/opencode/test/**/*.test.ts must use tmpdir from fixture/fixture.ts, await using for cleanup, and temporary path access via tmp.path.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/altimate/dbt-helpers.test.ts` around lines 14 - 42,
Replace the manual tempdir lifecycle (mkdtempSync in makeTmpDir, tmpDirs array
and afterEach cleanup with rmSync) with the shared tmpdir fixture: import tmpdir
from "fixture/fixture" and in each test use "await using const tmp = await
tmpdir()" (or the project's async fixture pattern) and reference tmp.path
instead of makeTmpDir; remove makeTmpDir, tmpDirs, and the afterEach block, and
update tests that call makeTmpDir to use tmp.path so cleanup is handled by the
fixture.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants