From f092e2b9c6b6039ee8154335fb0f31e6bf593a0c Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Mar 2026 18:13:33 +0000 Subject: [PATCH] =?UTF-8?q?test:=20fingerprint=20=E2=80=94=20file-based=20?= =?UTF-8?q?project=20detection=20rules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../test/altimate/fingerprint-detect.test.ts | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 packages/opencode/test/altimate/fingerprint-detect.test.ts diff --git a/packages/opencode/test/altimate/fingerprint-detect.test.ts b/packages/opencode/test/altimate/fingerprint-detect.test.ts new file mode 100644 index 000000000..70677147b --- /dev/null +++ b/packages/opencode/test/altimate/fingerprint-detect.test.ts @@ -0,0 +1,110 @@ +import { describe, test, expect, beforeEach } from "bun:test" +import { Fingerprint } from "../../src/altimate/fingerprint" +import { tmpdir } from "../fixture/fixture" +import * as fs from "fs/promises" +import path from "path" + +beforeEach(() => { + Fingerprint.reset() +}) + +describe("Fingerprint.detect: file-based project detection", () => { + test("detects dbt project from dbt_project.yml", async () => { + await using tmp = await tmpdir() + await fs.writeFile(path.join(tmp.path, "dbt_project.yml"), "name: my_project\nversion: 1.0.0\n") + const result = await Fingerprint.detect(tmp.path) + expect(result.tags).toContain("dbt") + expect(result.tags).toContain("data-engineering") + }) + + test("detects adapter type from profiles.yml", async () => { + await using tmp = await tmpdir() + await fs.writeFile( + path.join(tmp.path, "profiles.yml"), + "my_profile:\n target: dev\n outputs:\n dev:\n type: snowflake\n", + ) + const result = await Fingerprint.detect(tmp.path) + expect(result.tags).toContain("snowflake") + }) + + test("detects sql from .sqlfluff file", async () => { + await using tmp = await tmpdir() + await fs.writeFile(path.join(tmp.path, ".sqlfluff"), "[sqlfluff]\ndialect = bigquery\n") + const result = await Fingerprint.detect(tmp.path) + expect(result.tags).toContain("sql") + }) + + test("detects sql from .sql files when no .sqlfluff", async () => { + await using tmp = await tmpdir() + await fs.writeFile(path.join(tmp.path, "query.sql"), "SELECT 1") + const result = await Fingerprint.detect(tmp.path) + expect(result.tags).toContain("sql") + }) + + test("detects airflow from airflow.cfg", async () => { + await using tmp = await tmpdir() + await fs.writeFile(path.join(tmp.path, "airflow.cfg"), "[core]\nexecutor = LocalExecutor\n") + const result = await Fingerprint.detect(tmp.path) + expect(result.tags).toContain("airflow") + }) + + test("detects airflow from dags directory", async () => { + await using tmp = await tmpdir() + await fs.mkdir(path.join(tmp.path, "dags")) + const result = await Fingerprint.detect(tmp.path) + expect(result.tags).toContain("airflow") + }) + + test("detects databricks from databricks.yml", async () => { + await using tmp = await tmpdir() + await fs.writeFile(path.join(tmp.path, "databricks.yml"), "bundle:\n name: my_bundle\n") + const result = await Fingerprint.detect(tmp.path) + expect(result.tags).toContain("databricks") + }) + + test("returns empty tags for vanilla project", async () => { + await using tmp = await tmpdir() + const result = await Fingerprint.detect(tmp.path) + expect(result.tags).toEqual([]) + }) + + 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("deduplicates tags from cwd and root scanning same markers", async () => { + // When cwd !== root, both directories are scanned. If both contain + // dbt_project.yml, the "dbt" and "data-engineering" tags should appear + // only once each (the source deduplicates via Set). + await using tmp = await tmpdir() + const subdir = path.join(tmp.path, "models") + await fs.mkdir(subdir) + // Place dbt_project.yml in BOTH root and subdir + await fs.writeFile(path.join(tmp.path, "dbt_project.yml"), "name: root\n") + await fs.writeFile(path.join(subdir, "dbt_project.yml"), "name: sub\n") + const result = await Fingerprint.detect(subdir, tmp.path) + const dbtCount = result.tags.filter((t) => t === "dbt").length + expect(dbtCount).toBe(1) + const deCount = result.tags.filter((t) => t === "data-engineering").length + expect(deCount).toBe(1) + }) + + test("scans both cwd and root when different", async () => { + await using tmp = await tmpdir() + const subdir = path.join(tmp.path, "models") + await fs.mkdir(subdir) + // dbt_project.yml only in root + await fs.writeFile(path.join(tmp.path, "dbt_project.yml"), "name: test\n") + // .sql file only in subdir + await fs.writeFile(path.join(subdir, "model.sql"), "SELECT 1") + const result = await Fingerprint.detect(subdir, tmp.path) + expect(result.tags).toContain("dbt") + expect(result.tags).toContain("sql") + }) +})