Skip to content

refactor(server): extract the diagnostics routes into routers/diagnostics.py (R3) - #857

Merged
byrongamatos merged 1 commit into
mainfrom
refactor/r3-router-diagnostics
Jul 10, 2026
Merged

refactor(server): extract the diagnostics routes into routers/diagnostics.py (R3)#857
byrongamatos merged 1 commit into
mainfrom
refactor/r3-router-diagnostics

Conversation

@byrongamatos

@byrongamatos byrongamatos commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

The three /api/diagnostics/* routes (export, preview, hardware) plus their exclusive payload-cap helpers and _diag_* normalisers → lib/routers/diagnostics.py.

Bodies verbatim except @app@router, CONFIG_DIRappstate.config_dir, _running_version()appstate.running_version() (new seam slot; impl stays in server.py, still called by the settings region), and the builtin-plugins lookup in _diag_plugins_roots: Path(__file__).parentPath(__file__).resolve().parents[2] (routers → lib → app root; plugins/ ships at the app root in every packaging path).

The pure caps/normalisers (_diag_cap_console/_dict/_contributions, _diag_coerce_bool, _diag_normalize_include, _DIAG_MAX_*) are re-exported from server.py so the existing server._diag_* / server._DIAG_* tests keep resolving — none monkeypatch these, so no test retargets.

server.py: 7,216 → 6,960.

Verification

  • Route table identical (143); pyflakes clean bar the intentional re-export lines.
  • Full pytest 2399 passed (77 diag/packaging + 122 diagnostic-matched cases incl the cap/coerce/normalize suites).
  • npm run lint 0; Codex 0 findings.
  • Boot smoke: /hardware, /preview, and POST /export (200 application/zip) all serve from the new router location.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added diagnostics tools for exporting a downloadable diagnostics bundle, previewing included information, and checking hardware details.
    • Added inclusion controls (what sections to capture) and a redaction option for sensitive output.
    • Added safeguards to cap diagnostic payload sizes and constrain contribution data.
  • Documentation
    • Updated documented “planned, NOT exempt” application metrics (line counts and router totals).

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bcd490cb-ffa6-4ad0-b6a4-c9dea14fd076

📥 Commits

Reviewing files that changed from the base of the PR and between 02044e5 and 358d5a9.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • docs/size-exemptions.md
  • lib/appstate.py
  • lib/routers/diagnostics.py
  • server.py
✅ Files skipped from review due to trivial changes (2)
  • docs/size-exemptions.md
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • server.py
  • lib/appstate.py

📝 Walkthrough

Walkthrough

Diagnostics endpoints are extracted into a dedicated router with input normalization and payload caps. The application publishes its running version through appstate, mounts the router, preserves compatibility exports, and updates extraction documentation and size-exemption metrics.

Changes

Diagnostics router extraction

Layer / File(s) Summary
Runtime version contract
lib/appstate.py, server.py
running_version is added as a configurable appstate slot and populated from the server’s runtime version.
Diagnostics normalization and caps
lib/routers/diagnostics.py
Request flags and optional diagnostic sections are normalized, size-limited, and filtered to known plugins.
Diagnostics endpoint flow
lib/routers/diagnostics.py
Export, preview, and hardware endpoints collect diagnostics data and return bundle, preview, or probe results.
Application wiring and tracked extraction
server.py, CHANGELOG.md, docs/size-exemptions.md
The diagnostics router is mounted, selected helpers remain re-exported for compatibility, and extraction and server metrics documentation are updated.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant diagnostics_router
  participant appstate
  participant LoadedPlugins
  participant diagnostics_bundle
  Client->>diagnostics_router: POST /api/diagnostics/export
  diagnostics_router->>appstate: Read runtime configuration and version
  diagnostics_router->>LoadedPlugins: Snapshot loaded plugins under lock
  diagnostics_router->>diagnostics_bundle: Build bundle with capped sections
  diagnostics_bundle-->>diagnostics_router: Return ZIP bytes
  diagnostics_router-->>Client: Return attachment response
Loading

Possibly related PRs

  • got-feedBack/feedBack#833: Adds appstate-managed database slots consumed by router modules, paralleling the new running_version slot.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: moving diagnostics routes out of server.py into routers/diagnostics.py.
Docstring Coverage ✅ Passed Docstring coverage is 92.31% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/r3-router-diagnostics

Comment @coderabbitai help to get the list of available commands.

@byrongamatos
byrongamatos force-pushed the refactor/r3-router-diagnostics branch from 13dc6ad to 02044e5 Compare July 10, 2026 23:18
…tics.py (R3)

The three /api/diagnostics/* routes (export, preview, hardware) plus their
exclusive payload-cap helpers and the `_diag_*` normalisers. Bodies verbatim
except @app->@router, CONFIG_DIR->appstate.config_dir, _running_version()->
appstate.running_version() (a new seam slot; the impl stays in server.py where
the settings region also calls it), and the builtin-plugins lookup in
_diag_plugins_roots: Path(__file__).parent -> Path(__file__).resolve().parents[2]
(routers -> lib -> app root; plugins/ ships at the app root in every packaging
path).

The pure caps/normalisers (_diag_cap_console/_dict/_contributions,
_diag_coerce_bool, _diag_normalize_include, _DIAG_MAX_*) are re-exported from
server.py so the existing `server._diag_*` / `server._DIAG_*` tests keep
resolving — none of them monkeypatch these, so no test retargets.

server.py: 7,216 -> 6,960.

Verified: pyflakes clean (bar the intentional re-export lines); route table
IDENTICAL (143); full pytest 2399 passed (77 diag/packaging + 122 diagnostic-
matched cases incl the cap/coerce/normalize suites); eslint 0; Codex pending.
Boot smoke: /hardware, /preview, and POST /export (200 application/zip) all
serve from the new router location.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@byrongamatos
byrongamatos force-pushed the refactor/r3-router-diagnostics branch from 02044e5 to 358d5a9 Compare July 10, 2026 23:20
@byrongamatos
byrongamatos merged commit cce95cb into main Jul 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant