feat(ops): home account-spend tiles (anthropic-cost-integration Phase 2)#441
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🔒 Security Scan Results✅ Status: PASSED - No blocking issues Summary
Total Findings: 0 🛠️ Need Help?If findings are false positives:
For emergency hotfixes:
Scanner Accuracy: ~82% (Industry-leading!) Powered by Attune AI Security Scanner | Documentation |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…gration Phase 2)
Wires Phase 1's anthropic_cost.fetch_summary into the home page route.
Adds three KPI tiles ("Today (account)", "7d (account)", "MTD (account)")
gated on cost_summary availability, with a "Connect billing" CTA when
no admin key is configured and a friendly "Key rejected" notice on
auth-failed.
Visual distinction via the .kpi-cluster-account class — thin accent
border on the left edge of each tile in the new cluster so account
spend reads as a separate data source from workflow telemetry above.
Defensive try/except in the home route swallows any unexpected
exception from fetch_summary; the page still renders, the cost
cluster simply doesn't appear, and the failure surfaces in DEBUG
logs only. Six regression tests cover all four spec-2.4 scenarios
(no key, valid summary, auth failed, ?refresh=1) plus default
?refresh=False and the exception-swallow path.
Spec: docs/specs/anthropic-cost-integration/tasks.md (Phase 2)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
83730b5 to
e364dcb
Compare
|
Rebased onto current main (which now includes #439 telemetry fix and #440 docs). The earlier diff against After rebase, the diff is exactly 4 files (+255 / -1):
40/40 tests pass post-rebase. PR is now cleanly aligned with what the title advertises. |
Summary
Wires Phase 1's
anthropic_cost.fetch_summaryinto the home page route. Adds three account-spend KPI tiles ("Today (account)", "7d (account)", "MTD (account)") gated on cost_summary availability, with a "Connect billing" CTA when no admin key is configured and a friendly "Key rejected" notice on auth-failed.Implements spec
docs/specs/anthropic-cost-integration/tasks.mdPhase 2.What's in the diff
src/attune/ops/routes/dashboard.py: home() now calls fetch_summary inside a defensive try/except, passes cost_summary and cost_error to the template; ?refresh=1 forces a cache bypasssrc/attune/ops/templates/home.html: new<section class="kpi-grid kpi-cluster-account">block after the existing telemetry cluster, with three render paths (valid summary → tiles, no_key → CTA, auth_failed → notice, other errors → silent fall-through)src/attune/ops/static/css/main.css:.kpi-cluster-accountstyles, including the thin left-edge accent border and color-coded variants for.kpi-ctaand.kpi-noticetests/unit/ops/test_anthropic_cost_home_integration.py: six new tests covering all four spec-2.4 scenarios plus the default-refresh-false and exception-swallow pathsTrade-offs / non-obvious choices
"Set up cost reporting"linking to docs/reference/) rather than option 2 ("Coming in Phase 4 …"). Cleaner, doesn't reference a future state. Easily revisited when Phase 4 lands.except Exceptionwith# noqa: BLE001) because a billing-fetch surprise must not block the dashboard render. Surfaces in DEBUG logs only — verified by the silent-degradation test which mocks fetch_summary to raise RuntimeError.attune.ops.anthropic_cost.fetch_summary(source module) rather thanattune.ops.routes.dashboard.anthropic_cost.fetch_summary(consumer site). The latter triggersmock.patch's_importerto attempt module-walk on a function attribute. Source-module patching works becausedashboard.anthropic_costIS the same module object as the source; replacing the attribute on the source flows through.Caught in flight
The formatter stripped the
from attune.ops import anthropic_costimport after my initial import-only edit (before the usage line was added), per the existing CLAUDE.md lesson about formatters stripping unused-at-the-moment imports. Re-added with the usage line in place; runtime confirmeddashboard.anthropic_costresolves to the module. Worth a session lesson: even brief edit-formatter cycles trigger this, not just multi-minute pauses.Test plan
test_anthropic_cost_home_integration.pypasstest_home.py+test_anthropic_cost.py+ new file pass (no regressions)Related
attune ops setup-billingCLI), Phase 5 (polish + docs)🤖 Generated with Claude Code