From 87f6e93c14a9365695142084bc6966d7de70f437 Mon Sep 17 00:00:00 2001 From: Rod Boev Date: Wed, 8 Jul 2026 22:13:23 -0400 Subject: [PATCH] fix(dashboard): distinguish unavailable RTK from zero stats in Docker (#1900) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description When headroom runs in Docker without `rtk` installed, the dashboard shows `0` for every RTK/context-tool metric instead of indicating the tool is unavailable. The backend already distinguishes the two states (`context_tool.available` is `false` when `get_rtk_path()` returns `None`), but the dashboard frontend never checked that field. This adds a `cliFilteringAvailable` computed property that reads `context_tool.available` from the stats payload. When the tool is absent, the headline summary shows "RTK not installed" instead of "RTK 0 this session (0.0%)", and the detailed stats row shows "not installed" instead of a zero count. When the tool is present, behavior is unchanged. Closes #1831 ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Performance improvement - [ ] Code refactoring (no functional changes) ## Changes Made - Added `cliFilteringAvailable` computed property to the Alpine.js dashboard data object, reading `stats.context_tool?.available` - Headline savings line: shows "RTK not installed" (dimmed) when the tool is absent instead of "RTK 0 this session (0.0%)" - Detailed stats breakdown: shows "not installed" for the session row and hides the lifetime row when the tool is absent - 5 new tests covering the `installed` flag propagation through `_context_tool_zero_payload`, `_read_rtk_lifetime_stats`, and the availability logic ## Testing - [x] Unit tests pass (`uv run pytest tests/test_rtk_docker_availability.py`) - [x] Linting passes (`uv run ruff check .`) - [ ] Type checking passes — N/A, dashboard is HTML/JS - [x] New tests added for new functionality when applicable - [x] Manual testing performed ### Test Output ```text tests/test_rtk_docker_availability.py ..... [100%] 5 passed in 0.15s ``` ## Real Behavior Proof - Environment: Windows 11, Python 3.12, headroom from source - Exact command: `uv run pytest tests/test_rtk_docker_availability.py -q` - Observed result: `_read_rtk_lifetime_stats()` returns `installed=False` when `get_rtk_path()` is None, and the dashboard template conditionally renders "not installed" based on `cliFilteringAvailable` - Not tested: live Docker deployment with the dashboard served over HTTP (Playwright dashboard tests are CI-only) ## Review Readiness - [x] I have performed a self-review - [x] This PR is ready for human review ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] I have updated the CHANGELOG.md if applicable ## Additional Notes CHANGELOG.md not updated: the CI/CD release pipeline generates it from conventional commits per maintainer policy. The dashboard rendering change is frontend-only and the backend `context_tool.available` field was already present. --- headroom/dashboard/templates/dashboard.html | 24 +++++++++-- tests/test_rtk_docker_availability.py | 45 +++++++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 tests/test_rtk_docker_availability.py diff --git a/headroom/dashboard/templates/dashboard.html b/headroom/dashboard/templates/dashboard.html index 3f16bc9c3..f5aa65d3c 100644 --- a/headroom/dashboard/templates/dashboard.html +++ b/headroom/dashboard/templates/dashboard.html @@ -220,7 +220,7 @@
/ - +
@@ -1056,11 +1056,15 @@ Before Compression
-
+
-
+
+ + not installed +
+
@@ -1430,7 +1434,7 @@
Based on persisted weekly buckets
-