Skip to content

test: fingerprint — file-based project detection rules#479

Closed
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260326-1813
Closed

test: fingerprint — file-based project detection rules#479
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260326-1813

Conversation

@anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Mar 26, 2026

What does this PR do?

1. Fingerprint.detectsrc/altimate/fingerprint/index.ts (11 new tests)

This module detects project type by scanning for well-known files (dbt_project.yml, profiles.yml, .sqlfluff, airflow.cfg, databricks.yml, dags/ directory, *.sql files). It feeds into selectSkillsWithLLM() and SystemPrompt.skills() — if fingerprinting is wrong, users get irrelevant skills in their session.

The existing fingerprint.test.ts only smoke-tested against the real project root directory. None of its tests verified that a specific file produces a specific tag. A regression in any detection rule (e.g., changing the profiles.yml regex, renaming a marker file check) would pass all existing tests silently.

New coverage includes:

  • Individual marker detection: each of the 7 detection rules verified in isolation (dbt, snowflake adapter from profiles.yml, sqlfluff, raw .sql files, airflow.cfg, dags directory, databricks.yml)
  • Empty project baseline: vanilla directory returns zero tags
  • Cache correctness: same cwd returns cached reference; file removal after caching doesn't change result
  • Tag deduplication across directories: when both cwd and root contain the same marker, tags appear only once (exercises the Set dedup logic)
  • Two-directory scanning: detect(subdir, root) picks up markers from both directories (real scenario: user opens a subdirectory of a dbt monorepo)

Type of change

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

Issue for this PR

N/A — proactive test coverage for untested project detection logic

How did you verify your code works?

bun test test/altimate/fingerprint-detect.test.ts   # 11 pass

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_015TPuQ2dEJD2CYoHF3LTQzD

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suite for project detection functionality to verify correct identification and caching behavior.

Fingerprint.detect() drives skill selection and system prompt generation but
had zero tests verifying that specific project markers (dbt_project.yml,
profiles.yml, .sqlfluff, airflow.cfg, databricks.yml) produce the correct tags.

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

@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.

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

@coderabbitai
Copy link

coderabbitai bot commented Mar 26, 2026

📝 Walkthrough

Walkthrough

A new Bun test suite for Fingerprint.detect was added to validate file-based project detection. The tests create temporary directories with marker files and verify that the detection correctly identifies project types through tags, while also testing memoization, caching, and deduplication behaviors.

Changes

Cohort / File(s) Summary
Fingerprint Detection Tests
packages/opencode/test/altimate/fingerprint-detect.test.ts
New test suite validating project detection via marker files (dbt_project.yml, profiles.yml, .sqlfluff, airflow.cfg, databricks.yml), tag assignment (dbt, data-engineering, snowflake, sql, airflow, databricks), memoization/caching behavior with repeated calls, and tag deduplication across multiple scan locations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

contributor

Poem

🐰 A fingerprint so fine, we test it with care,
Marker files scattered here and there,
Tags bloom forth from temporary ground,
Caching whispers, no dupes around,
Detection dreams made real at last! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main addition: new tests for the fingerprint module's file-based project detection rules.
Description check ✅ Passed The description is comprehensive and includes all required template sections: it explains what changed (new tests for Fingerprint.detect), how it was tested (bun test results), and marks the checklist items as complete.
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-20260326-1813

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

@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.

🧹 Nitpick comments (1)
packages/opencode/test/altimate/fingerprint-detect.test.ts (1)

71-79: Add a cache-key regression case for root changes.

The cache implementation uses only cwd as the cache key (line 34) but the detect() method accepts an optional root parameter that affects detection (line 40). If detect() is called with the same cwd but different root values, the second call returns a stale cached result from the first call. Add a test to guard against this regression:

Suggested test addition
  test("caches result for same cwd", async () => {
    await using tmp = await tmpdir()
    await fs.writeFile(path.join(tmp.path, "dbt_project.yml"), "name: test\n")
    const r1 = await Fingerprint.detect(tmp.path)
    // Remove the file — cached result should still have dbt
    await fs.rm(path.join(tmp.path, "dbt_project.yml"))
    const r2 = await Fingerprint.detect(tmp.path)
    expect(r1).toBe(r2) // Same reference (cached)
  })
+
+  test("does not return stale tags when root changes for same cwd", async () => {
+    await using tmp = await tmpdir()
+    const subdir = path.join(tmp.path, "models")
+    await fs.mkdir(subdir)
+    await fs.writeFile(path.join(subdir, "model.sql"), "SELECT 1")
+
+    const first = await Fingerprint.detect(subdir)
+    expect(first.tags).toContain("sql")
+    expect(first.tags).not.toContain("dbt")
+
+    await fs.writeFile(path.join(tmp.path, "dbt_project.yml"), "name: test\n")
+    const second = await Fingerprint.detect(subdir, tmp.path)
+    expect(second.tags).toContain("dbt")
+  })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/altimate/fingerprint-detect.test.ts` around lines 71 -
79, The cache currently keys only by cwd causing stale results when detect is
called with different root values; update the Fingerprint.detect caching to
include the optional root in the cache key (e.g., combine cwd and root or use a
nested Map keyed by cwd then root) so cached results are distinct per (cwd,
root) pair, and add the regression test that calls Fingerprint.detect(tmp.path)
then Fingerprint.detect(tmp.path, differentRoot) to assert they are not the same
cached reference.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/opencode/test/altimate/fingerprint-detect.test.ts`:
- Around line 71-79: The cache currently keys only by cwd causing stale results
when detect is called with different root values; update the Fingerprint.detect
caching to include the optional root in the cache key (e.g., combine cwd and
root or use a nested Map keyed by cwd then root) so cached results are distinct
per (cwd, root) pair, and add the regression test that calls
Fingerprint.detect(tmp.path) then Fingerprint.detect(tmp.path, differentRoot) to
assert they are not the same cached reference.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b54b07d1-225f-45c8-b527-b930ba635265

📥 Commits

Reviewing files that changed from the base of the PR and between 91fe351 and f092e2b.

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

anandgupta42 added a commit that referenced this pull request Mar 27, 2026
Consolidates tests from PRs #440, #441, #479, #483, #484, #485, #490, #491, #492, #495, #496.
Deduplicates overlapping MongoDB normalize tests (3 PRs → 1), `keybind` tests (2 PRs → 1),
and `connections.test.ts` additions (4 PRs → 1 merged file).

New test files:
- `sql-analyze-tool.test.ts` — `SqlAnalyzeTool` formatting (6 tests)
- `sql-analyze-format.test.ts` — `sql.analyze` success semantics + dispatcher (5 tests)
- `builtin-commands.test.ts` — altimate builtin command registration (10 tests)
- `hints-discover-mcps.test.ts` — `Command.hints()` + discover-and-add-mcps (11 tests)
- `fingerprint-detect.test.ts` — file-based project detection rules (11 tests)
- `dbt-lineage-helpers.test.ts` — dbt lineage helper functions (13 tests)
- `registry-env-loading.test.ts` — `ALTIMATE_CODE_CONN_*` env var loading (8 tests)
- `warehouse-telemetry.test.ts` — MongoDB auth detection telemetry (4 tests)
- `bus-event.test.ts` — bus event registry payloads (5 tests)
- `git.test.ts` — git utility functions (5 tests)
- `keybind.test.ts` — keybind parsing, matching, `fromParsedKey` (22 tests)

Merged into existing files:
- `connections.test.ts` — `loadFromEnv` (5), `detectAuthMethod` (14), credential stripping (1),
  `containerToConfig` (1), dbt profiles edge cases (3)
- `driver-normalize.test.ts` — MongoDB alias resolution (13 tests)

Fixes:
- `fixture.ts` — disable `commit.gpgsign` in test tmpdir to prevent CI failures
- `hints-discover-mcps.test.ts` — corrected sort order expectation
- `registry-env-loading.test.ts` — fixed flaky assertion that assumed isolated env

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

Consolidated into #498. Tests deduplicated and merged into a single PR.

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