Repository navigation
Read the measured Soniox line from spend_daily when it has rows #24945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+282
−7
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
63a6eac
Show Soniox balance as dark when vendor balance tables are missing
claude 2e16515
Read the measured Soniox line from spend_daily when it has rows
claude 1c86a2d
Disclose the dark vendor-balance reason as a missing line; test the c…
claude 665c8ec
Disclose a failed spend_daily read instead of treating it as no data
claude b9a105a
Separate a day gap from an empty spend ledger; assert the full Soniox…
claude 4c67c3a
Merge origin/main into claude/soniox-spend-stt
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| const state = vi.hoisted(() => ({ | ||
| query: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@/lib/services/gcp-billing", () => ({ | ||
| getGcpBillingClient: () => ({ query: state.query }), | ||
| })); | ||
|
|
||
| import { | ||
| darkVendorBalance, | ||
| fetchVendorBalanceHistory, | ||
| isVendorBalanceDark, | ||
| VENDOR_BALANCE_DARK_REASON, | ||
| } from "../wall-finops"; | ||
| import { bigQueryFailure } from "../wall-source-error"; | ||
|
|
||
| const TABLES = [ | ||
| "omi_finops.vendor_balance_snapshot", | ||
| "omi_finops.vendor_balance_spend_daily", | ||
| ]; | ||
| const FALLBACK = "Soniox measured STT unavailable (balance line dark)"; | ||
|
|
||
| describe("vendor balance dark state: classifier", () => { | ||
| it("marks a missing vendor-balance table as dark with a non-error reason", () => { | ||
| const failure = bigQueryFailure( | ||
| { | ||
| code: 404, | ||
| message: | ||
| "Not found: Table based-hardware:omi_finops.vendor_balance_snapshot was not found", | ||
| }, | ||
| TABLES, | ||
| FALLBACK | ||
| ); | ||
| expect(failure.message).toBe( | ||
| "omi_finops.vendor_balance_snapshot not found (table not created yet)" | ||
| ); | ||
| expect(isVendorBalanceDark(failure)).toBe(true); | ||
| }); | ||
|
|
||
| it("keeps a grant denial on a vendor-balance table as an error", () => { | ||
| const failure = bigQueryFailure( | ||
| { | ||
| code: 403, | ||
| message: | ||
| "Access Denied: Table based-hardware:omi_finops.vendor_balance_spend_daily: User does not have permission", | ||
| }, | ||
| TABLES, | ||
| FALLBACK | ||
| ); | ||
| expect(failure.message).toContain("missing dataViewer grant"); | ||
| expect(isVendorBalanceDark(failure)).toBe(false); | ||
| }); | ||
|
|
||
| it("keeps an unnamed or unrelated failure as an error", () => { | ||
| const unnamed = bigQueryFailure( | ||
| { code: 404, message: "Not found" }, | ||
| TABLES, | ||
| FALLBACK | ||
| ); | ||
| expect(isVendorBalanceDark(unnamed)).toBe(false); | ||
| expect(unnamed.message).toBe(FALLBACK); | ||
|
|
||
| const timeout = bigQueryFailure( | ||
| { code: 500, message: "Job timed out" }, | ||
| TABLES, | ||
| FALLBACK | ||
| ); | ||
| expect(isVendorBalanceDark(timeout)).toBe(false); | ||
| }); | ||
|
|
||
| it("returns an empty history carrying the dark reason", () => { | ||
| const dark = darkVendorBalance(); | ||
| expect(dark.dark).toBe(VENDOR_BALANCE_DARK_REASON); | ||
| expect(dark.dark).toBe("Soniox balance not tracked (org key off)"); | ||
| expect(dark.snapshots).toBe(0); | ||
| expect(dark.spend).toEqual({}); | ||
| expect(dark.flags).toEqual({}); | ||
| }); | ||
| }); | ||
|
|
||
| describe("vendor balance dark state: production catch path", () => { | ||
| beforeEach(() => { | ||
| state.query.mockReset(); | ||
| }); | ||
|
|
||
| it("resolves dark when the vendor-balance table does not exist yet", async () => { | ||
| state.query.mockRejectedValue({ | ||
| code: 404, | ||
| message: | ||
| "Not found: Table based-hardware:omi_finops.vendor_balance_snapshot was not found", | ||
| }); | ||
| await expect(fetchVendorBalanceHistory("2026-11-08")).resolves.toEqual( | ||
| darkVendorBalance() | ||
| ); | ||
| }); | ||
|
|
||
| it("rejects on a grant denial, so the leg stays an error", async () => { | ||
| state.query.mockRejectedValue({ | ||
| code: 403, | ||
| message: | ||
| "Access Denied: Table based-hardware:omi_finops.vendor_balance_spend_daily: User does not have permission", | ||
| }); | ||
| await expect(fetchVendorBalanceHistory("2026-11-08")).rejects.toThrow( | ||
| /missing dataViewer grant/ | ||
| ); | ||
| }); | ||
|
|
||
| it("rejects on an unrelated failure, so the leg stays an error", async () => { | ||
| state.query.mockRejectedValue({ code: 500, message: "Job timed out" }); | ||
| await expect(fetchVendorBalanceHistory("2026-11-08")).rejects.toThrow( | ||
| /balance line dark/ | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.