Skip to content

Commit f092e2b

Browse files
committed
test: fingerprint — file-based project detection rules
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) <[email protected]>
1 parent 91fe351 commit f092e2b

1 file changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { describe, test, expect, beforeEach } from "bun:test"
2+
import { Fingerprint } from "../../src/altimate/fingerprint"
3+
import { tmpdir } from "../fixture/fixture"
4+
import * as fs from "fs/promises"
5+
import path from "path"
6+
7+
beforeEach(() => {
8+
Fingerprint.reset()
9+
})
10+
11+
describe("Fingerprint.detect: file-based project detection", () => {
12+
test("detects dbt project from dbt_project.yml", async () => {
13+
await using tmp = await tmpdir()
14+
await fs.writeFile(path.join(tmp.path, "dbt_project.yml"), "name: my_project\nversion: 1.0.0\n")
15+
const result = await Fingerprint.detect(tmp.path)
16+
expect(result.tags).toContain("dbt")
17+
expect(result.tags).toContain("data-engineering")
18+
})
19+
20+
test("detects adapter type from profiles.yml", async () => {
21+
await using tmp = await tmpdir()
22+
await fs.writeFile(
23+
path.join(tmp.path, "profiles.yml"),
24+
"my_profile:\n target: dev\n outputs:\n dev:\n type: snowflake\n",
25+
)
26+
const result = await Fingerprint.detect(tmp.path)
27+
expect(result.tags).toContain("snowflake")
28+
})
29+
30+
test("detects sql from .sqlfluff file", async () => {
31+
await using tmp = await tmpdir()
32+
await fs.writeFile(path.join(tmp.path, ".sqlfluff"), "[sqlfluff]\ndialect = bigquery\n")
33+
const result = await Fingerprint.detect(tmp.path)
34+
expect(result.tags).toContain("sql")
35+
})
36+
37+
test("detects sql from .sql files when no .sqlfluff", async () => {
38+
await using tmp = await tmpdir()
39+
await fs.writeFile(path.join(tmp.path, "query.sql"), "SELECT 1")
40+
const result = await Fingerprint.detect(tmp.path)
41+
expect(result.tags).toContain("sql")
42+
})
43+
44+
test("detects airflow from airflow.cfg", async () => {
45+
await using tmp = await tmpdir()
46+
await fs.writeFile(path.join(tmp.path, "airflow.cfg"), "[core]\nexecutor = LocalExecutor\n")
47+
const result = await Fingerprint.detect(tmp.path)
48+
expect(result.tags).toContain("airflow")
49+
})
50+
51+
test("detects airflow from dags directory", async () => {
52+
await using tmp = await tmpdir()
53+
await fs.mkdir(path.join(tmp.path, "dags"))
54+
const result = await Fingerprint.detect(tmp.path)
55+
expect(result.tags).toContain("airflow")
56+
})
57+
58+
test("detects databricks from databricks.yml", async () => {
59+
await using tmp = await tmpdir()
60+
await fs.writeFile(path.join(tmp.path, "databricks.yml"), "bundle:\n name: my_bundle\n")
61+
const result = await Fingerprint.detect(tmp.path)
62+
expect(result.tags).toContain("databricks")
63+
})
64+
65+
test("returns empty tags for vanilla project", async () => {
66+
await using tmp = await tmpdir()
67+
const result = await Fingerprint.detect(tmp.path)
68+
expect(result.tags).toEqual([])
69+
})
70+
71+
test("caches result for same cwd", async () => {
72+
await using tmp = await tmpdir()
73+
await fs.writeFile(path.join(tmp.path, "dbt_project.yml"), "name: test\n")
74+
const r1 = await Fingerprint.detect(tmp.path)
75+
// Remove the file — cached result should still have dbt
76+
await fs.rm(path.join(tmp.path, "dbt_project.yml"))
77+
const r2 = await Fingerprint.detect(tmp.path)
78+
expect(r1).toBe(r2) // Same reference (cached)
79+
})
80+
81+
test("deduplicates tags from cwd and root scanning same markers", async () => {
82+
// When cwd !== root, both directories are scanned. If both contain
83+
// dbt_project.yml, the "dbt" and "data-engineering" tags should appear
84+
// only once each (the source deduplicates via Set).
85+
await using tmp = await tmpdir()
86+
const subdir = path.join(tmp.path, "models")
87+
await fs.mkdir(subdir)
88+
// Place dbt_project.yml in BOTH root and subdir
89+
await fs.writeFile(path.join(tmp.path, "dbt_project.yml"), "name: root\n")
90+
await fs.writeFile(path.join(subdir, "dbt_project.yml"), "name: sub\n")
91+
const result = await Fingerprint.detect(subdir, tmp.path)
92+
const dbtCount = result.tags.filter((t) => t === "dbt").length
93+
expect(dbtCount).toBe(1)
94+
const deCount = result.tags.filter((t) => t === "data-engineering").length
95+
expect(deCount).toBe(1)
96+
})
97+
98+
test("scans both cwd and root when different", async () => {
99+
await using tmp = await tmpdir()
100+
const subdir = path.join(tmp.path, "models")
101+
await fs.mkdir(subdir)
102+
// dbt_project.yml only in root
103+
await fs.writeFile(path.join(tmp.path, "dbt_project.yml"), "name: test\n")
104+
// .sql file only in subdir
105+
await fs.writeFile(path.join(subdir, "model.sql"), "SELECT 1")
106+
const result = await Fingerprint.detect(subdir, tmp.path)
107+
expect(result.tags).toContain("dbt")
108+
expect(result.tags).toContain("sql")
109+
})
110+
})

0 commit comments

Comments
 (0)