Skip to content

Commit 76ce370

Browse files
anandgupta42claude
andcommitted
fix: [#827] address consensus review — test determinism + error consistency + formatter completeness
Third-pass on PR #828 after follow-up code review. Three follow-ups in scope. 1. Test determinism (MINOR per reviewer) `test/altimate/schema-finops-dbt.test.ts` was reading the warehouse resolver's error message verbatim ("not configured") to assert the unknown-warehouse path. That message only appears when the registry has at least one warehouse configured — if the test ran in a fresh sandbox or hermetic CI, the resolver would return "...none are set up..." and the assertion would silently fail. Added a beforeAll / afterAll block that captures the prior registry state, pins a known two-warehouse config for the test, and restores afterwards. 2. Error stringification consistency (MINOR) The first PR commit upgraded most `catch (e) { error: String(e) }` to `e instanceof Error ? e.message : String(e)`, but role-access.ts was missed (three handlers). Normalized all three to match the credit-analyzer / query-history pattern — driver errors now surface as `"...message..."` rather than `"Error: ...message..."`. 3. Formatter completeness (NIT) `finops-query-history.ts` formatter surfaced only avg_execution_time even though the underlying handler emits total_execution_time_sec and error_count too. Added both: total exec time always shown; error count shown only when > 0 to avoid cluttering the typical 0-error case. Validation - `tsgo --noEmit`: pass. - `bun test test/altimate/schema-finops-dbt.test.ts test/altimate/finops-warehouse-resolver.test.ts test/altimate/finops-recommendations.test.ts`: 95 pass / 0 fail. - Marker check: pass (no upstream-shared files in these paths). Reviewer note - GPT-5.4 second-opinion was unavailable (OpenRouter credit exhaustion). Single-reviewer Claude analysis. Deferred to follow-up - Surface auto-picked warehouse name in handler success metadata (reviewer NIT — separate ROADMAP item already tracked). - Restore role-access BigQuery-IAM / Databricks-Unity hints lost in the resolver rewrite (reviewer NIT — would require per-operation `hint` field on `ResolveOptions`, separate enhancement). - Tool-level integration test for the auto-pick path (reviewer suggestion — requires Dispatcher mock scaffolding). Closes review feedback for PR #828 (third pass). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent ed6f247 commit 76ce370

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

‎packages/opencode/src/altimate/native/finops/role-access.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export async function queryGrants(params: RoleGrantsParams): Promise<RoleGrantsR
216216
grants: [],
217217
grant_count: 0,
218218
privilege_summary: {},
219-
error: String(e),
219+
error: e instanceof Error ? e.message : String(e),
220220
}
221221
}
222222
}
@@ -257,7 +257,7 @@ export async function queryRoleHierarchy(params: RoleHierarchyParams): Promise<R
257257
success: false,
258258
hierarchy: [],
259259
role_count: 0,
260-
error: String(e),
260+
error: e instanceof Error ? e.message : String(e),
261261
}
262262
}
263263
}
@@ -298,7 +298,7 @@ export async function queryUserRoles(params: UserRolesParams): Promise<UserRoles
298298
success: false,
299299
assignments: [],
300300
assignment_count: 0,
301-
error: String(e),
301+
error: e instanceof Error ? e.message : String(e),
302302
}
303303
}
304304
}

‎packages/opencode/src/altimate/tools/finops-query-history.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ function formatQueryHistory(summary: Record<string, unknown>, queries: unknown[]
1111
lines.push(`Total queries: ${summary.query_count ?? 0}`)
1212
if (summary.avg_execution_time_sec !== undefined)
1313
lines.push(`Avg execution time: ${Number(summary.avg_execution_time_sec).toFixed(2)}s`)
14+
if (summary.total_execution_time_sec !== undefined)
15+
lines.push(`Total execution time: ${Number(summary.total_execution_time_sec).toFixed(2)}s`)
16+
if (summary.error_count !== undefined && Number(summary.error_count) > 0)
17+
lines.push(`Failed queries: ${summary.error_count}`)
1418
if (summary.total_bytes_scanned !== undefined)
1519
lines.push(`Total bytes scanned: ${formatBytes(Number(summary.total_bytes_scanned))}`)
1620
if (summary.period_days !== undefined) lines.push(`Period: ${summary.period_days} days`)

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, expect, test, beforeAll, afterAll } from "bun:test"
22
import * as Dispatcher from "../../src/altimate/native/dispatcher"
3+
import * as Registry from "../../src/altimate/native/connections/registry"
34

45
// Disable telemetry via env var instead of mock.module
56
beforeAll(() => { process.env.ALTIMATE_TELEMETRY_DISABLED = "true" })
@@ -645,6 +646,31 @@ describe("Local: type mapping", () => {
645646
})
646647

647648
describe("FinOps: handler error paths (no warehouse configured)", () => {
649+
// Reviewer (2026-05-22) flagged that the previous version of these tests
650+
// depended on ambient registry state — if a developer / CI ran with no
651+
// warehouses configured, the resolver would return "...none are set up..."
652+
// (no "not configured" substring) and the assertions would silently fail.
653+
// Pin a deterministic registry state for the whole block.
654+
const PRIOR_CONFIGS = new Map<string, any>()
655+
beforeAll(() => {
656+
// Capture whatever was there so the suite is hermetic.
657+
for (const w of Registry.list().warehouses) {
658+
const cfg = Registry.getConfig(w.name)
659+
if (cfg) PRIOR_CONFIGS.set(w.name, cfg)
660+
}
661+
Registry.setConfigs({
662+
test_pg: { type: "postgres", host: "localhost" } as any,
663+
test_sf: { type: "snowflake", account: "x", user: "u", password: "p" } as any,
664+
})
665+
})
666+
afterAll(() => {
667+
if (PRIOR_CONFIGS.size > 0) {
668+
Registry.setConfigs(Object.fromEntries(PRIOR_CONFIGS))
669+
} else {
670+
Registry.reset()
671+
}
672+
})
673+
648674
test("finops.query_history returns error when no warehouse type found", async () => {
649675
const result = await Dispatcher.call("finops.query_history", {
650676
warehouse: "nonexistent",
@@ -665,9 +691,10 @@ describe("FinOps: handler error paths (no warehouse configured)", () => {
665691
warehouse: "nonexistent",
666692
} as any)
667693
expect(result.success).toBe(false)
668-
// The new warehouse resolver returns "not configured" (more precise than
669-
// the old "not available for X" message — the warehouse doesn't exist at
670-
// all, regardless of type).
694+
// The resolver returns one of two messages depending on whether ANY
695+
// warehouses are configured: "not configured. Available: ..." (some
696+
// exist) or "...none are set up..." (registry empty). The beforeAll
697+
// above pins the first branch.
671698
expect(result.error).toContain("not configured")
672699
})
673700

0 commit comments

Comments
 (0)