Skip to content

Commit cd8f16c

Browse files
committed
test: fingerprint + context — fill coverage gaps in core utilities
Add tests for Fingerprint.refresh() cache invalidation and dbt-packages tag detection (both untested code paths), plus first-ever unit tests for the Context utility (AsyncLocalStorage wrapper) used by every module. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> https://claude.ai/code/session_01N8kgPYhXX7SrYnZKJLiTfC
1 parent 9ba2114 commit cd8f16c

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

‎packages/opencode/test/altimate/fingerprint-detect.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,37 @@ describe("Fingerprint.detect: file-based project detection", () => {
107107
expect(result.tags).toContain("dbt")
108108
expect(result.tags).toContain("sql")
109109
})
110+
111+
test("detects dbt-packages from dbt_packages.yml", async () => {
112+
await using tmp = await tmpdir()
113+
await fs.writeFile(path.join(tmp.path, "dbt_packages.yml"), "packages:\n - package: dbt-labs/dbt_utils\n")
114+
const result = await Fingerprint.detect(tmp.path)
115+
expect(result.tags).toContain("dbt-packages")
116+
})
117+
118+
test("combined project detects multiple technologies", async () => {
119+
await using tmp = await tmpdir()
120+
await fs.writeFile(path.join(tmp.path, "dbt_project.yml"), "name: test\n")
121+
await fs.writeFile(path.join(tmp.path, "airflow.cfg"), "[core]\n")
122+
await fs.writeFile(path.join(tmp.path, "databricks.yml"), "bundle:\n name: test\n")
123+
const result = await Fingerprint.detect(tmp.path)
124+
expect(result.tags).toContain("dbt")
125+
expect(result.tags).toContain("airflow")
126+
expect(result.tags).toContain("databricks")
127+
expect(result.tags).toContain("data-engineering")
128+
})
129+
})
130+
131+
describe("Fingerprint.refresh", () => {
132+
test("invalidates cache and re-detects new files", async () => {
133+
await using tmp = await tmpdir()
134+
// Initial detect — no tags
135+
const r1 = await Fingerprint.detect(tmp.path)
136+
expect(r1.tags).toEqual([])
137+
// Add dbt_project.yml after initial detect
138+
await fs.writeFile(path.join(tmp.path, "dbt_project.yml"), "name: test\n")
139+
// refresh() should invalidate cache and pick up the new file
140+
const r3 = await Fingerprint.refresh()
141+
expect(r3.tags).toContain("dbt")
142+
})
110143
})
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { describe, test, expect } from "bun:test"
2+
import { Context } from "../../src/util/context"
3+
4+
describe("Context: provide and use", () => {
5+
test("use() returns provided value", () => {
6+
const ctx = Context.create<{ id: number }>("test")
7+
const result = ctx.provide({ id: 42 }, () => ctx.use())
8+
expect(result).toEqual({ id: 42 })
9+
})
10+
11+
test("use() throws NotFound outside provider", () => {
12+
const ctx = Context.create<{ id: number }>("myctx")
13+
expect(() => ctx.use()).toThrow(Context.NotFound)
14+
expect(() => ctx.use()).toThrow("No context found for myctx")
15+
})
16+
17+
test("nested provide uses innermost value", () => {
18+
const ctx = Context.create<{ val: string }>("nest")
19+
const result = ctx.provide({ val: "outer" }, () =>
20+
ctx.provide({ val: "inner" }, () => ctx.use().val),
21+
)
22+
expect(result).toBe("inner")
23+
})
24+
25+
test("provide passes through callback return value", () => {
26+
const ctx = Context.create<{ val: string }>("passthrough")
27+
const result = ctx.provide({ val: "x" }, () => 42)
28+
expect(result).toBe(42)
29+
})
30+
31+
test("concurrent contexts are isolated", async () => {
32+
const ctx = Context.create<{ id: number }>("concurrent")
33+
const results = await Promise.all([
34+
ctx.provide({ id: 1 }, async () => {
35+
await new Promise((r) => setTimeout(r, 10))
36+
return ctx.use().id
37+
}),
38+
ctx.provide({ id: 2 }, async () => {
39+
await new Promise((r) => setTimeout(r, 5))
40+
return ctx.use().id
41+
}),
42+
])
43+
expect(results).toEqual([1, 2])
44+
})
45+
})

0 commit comments

Comments
 (0)