feat(admin-ui): hide runaway budget line and link form errors to inputs

The burn-down chart drew the budget line even when it was more than ten times the spend, which flattened the spend curve. The line now hides with a note. Limits, pricing, model metadata and grant forms mark invalid inputs with aria-invalid and aria-describedby.
This commit is contained in:
2026-11-08 02:28:27 +00:00
parent 1ec8aacee7
commit e985fded45
7 changed files with 72 additions and 11 deletions
+12 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { cumulative, currentMonthDaySpan, MIN_ELAPSED_DAYS, runOutDate } from './burndown'
import { budgetLineVisible, BUDGET_LINE_MAX_RATIO, cumulative, currentMonthDaySpan, MIN_ELAPSED_DAYS, runOutDate } from './burndown'
describe('currentMonthDaySpan', () => {
it('returns the UTC day-of-month', () => {
@@ -63,3 +63,14 @@ describe('runOutDate', () => {
expect(MIN_ELAPSED_DAYS).toBe(1)
})
})
describe('budgetLineVisible', () => {
it.each([
{ spent: 0, budget: 1, visible: false },
{ spent: 1_000, budget: 1_000 * BUDGET_LINE_MAX_RATIO, visible: true },
{ spent: 1_000, budget: 1_000 * BUDGET_LINE_MAX_RATIO + 1, visible: false },
{ spent: 5_000, budget: 1_000, visible: true },
])('spent=$spent budget=$budget -> $visible', ({ spent, budget, visible }) => {
expect(budgetLineVisible(spent, budget)).toBe(visible)
})
})
+8
View File
@@ -91,3 +91,11 @@ export function runOutDate(mtdMicros: number, limitMicros: number, now: Date): D
const daysToExhaust = remainingMicros / dailyRateMicros
return new Date(now.getTime() + daysToExhaust * MS_PER_DAY)
}
/** BUDGET_LINE_MAX_RATIO is how far above spend the budget may sit before its line is hidden. */
export const BUDGET_LINE_MAX_RATIO = 10
/** budgetLineVisible hides a budget line so far above spend that it flattens the spend curve against the axis. */
export function budgetLineVisible(spentMicros: number, budgetMicros: number): boolean {
return budgetMicros <= BUDGET_LINE_MAX_RATIO * spentMicros
}