Skip to content

Commit 0b3c85e

Browse files
committed
test: finops — ClickHouse query history SQL template coverage
The ClickHouse warehouse driver (PR #574) added buildHistoryQuery("clickhouse",...) with a unique __DAYS__/__LIMIT__ placeholder format and integer clamping, but template tests were not added alongside the other 5 warehouse types. These 6 tests close that gap. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0d34855 commit 0b3c85e

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

packages/opencode/test/altimate/schema-finops-dbt.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,52 @@ describe("FinOps: SQL template generation", () => {
158158
const built = HistoryTemplates.buildHistoryQuery("databricks", 7, 50)
159159
expect(built?.sql).toContain("system.query.history")
160160
})
161+
162+
test("builds ClickHouse history SQL", () => {
163+
const built = HistoryTemplates.buildHistoryQuery("clickhouse", 7, 100)
164+
expect(built).not.toBeNull()
165+
expect(built!.sql).toContain("system.query_log")
166+
expect(built!.sql).toContain("QueryFinish")
167+
// ClickHouse uses string substitution, not bind params
168+
expect(built!.binds).toEqual([])
169+
// Verify __DAYS__ and __LIMIT__ were substituted (not left as placeholders)
170+
expect(built!.sql).not.toContain("__DAYS__")
171+
expect(built!.sql).not.toContain("__LIMIT__")
172+
expect(built!.sql).toContain("today() - 7")
173+
expect(built!.sql).toContain("LIMIT 100")
174+
})
175+
176+
test("ClickHouse clamps NaN days to 30 and NaN limit to 100", () => {
177+
const built = HistoryTemplates.buildHistoryQuery("clickhouse", NaN, NaN)
178+
expect(built).not.toBeNull()
179+
expect(built!.sql).toContain("today() - 30")
180+
expect(built!.sql).toContain("LIMIT 100")
181+
})
182+
183+
test("ClickHouse clamps negative inputs to minimum 1", () => {
184+
const built = HistoryTemplates.buildHistoryQuery("clickhouse", -5, -10)
185+
expect(built!.sql).toContain("today() - 1")
186+
expect(built!.sql).toContain("LIMIT 1")
187+
})
188+
189+
test("ClickHouse treats zero as missing input and applies defaults", () => {
190+
const built = HistoryTemplates.buildHistoryQuery("clickhouse", 0, 0)
191+
// 0 is falsy, so || defaultValue kicks in: days→30, limit→100
192+
expect(built!.sql).toContain("today() - 30")
193+
expect(built!.sql).toContain("LIMIT 100")
194+
})
195+
196+
test("ClickHouse clamps values exceeding upper bounds", () => {
197+
const built = HistoryTemplates.buildHistoryQuery("clickhouse", 999, 50000)
198+
expect(built!.sql).toContain("today() - 365")
199+
expect(built!.sql).toContain("LIMIT 10000")
200+
})
201+
202+
test("ClickHouse floors fractional inputs", () => {
203+
const built = HistoryTemplates.buildHistoryQuery("clickhouse", 3.9, 75.1)
204+
expect(built!.sql).toContain("today() - 3")
205+
expect(built!.sql).toContain("LIMIT 75")
206+
})
161207
})
162208

163209
describe("warehouse-advisor", () => {

0 commit comments

Comments
 (0)