Skip to content

refactor(server): extract /api/tunings into routers/tunings.py + lib/appconfig.py (R3) - #858

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

byrongamatos merged 1 commit into
mainfrom
refactor/r3-router-tunings

Conversation

@byrongamatos

@byrongamatos byrongamatos commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

The merged-tuning-catalog route → lib/routers/tunings.py, verbatim except @app@router, CONFIG_DIRappstate.config_dir, and two reusable seam substrates:

  • lib/appconfig.py — the pure config.json reader _load_config (used by ~11 server sites + future config-reading routers). server.py re-imports it, so those call sites and any server._load_config test reference are unchanged.
  • appstate.tuning_providers — the TuningProviderRegistry instance injected by reference (a stable object mutated in place via register()/unregister()), so the router reads the same registry plugins populate via plugin_context. The instance stays defined in server.py, so server.tuning_providers still resolves — zero test retargets.

Tuning constants (DEFAULT_REFERENCE_PITCH, TUNING_PRESET_MIDIS, freqs_to_midis) already live in lib/tunings.py and import directly.

server.py: 6,960 → 6,917.

Verification

  • Route table identical (143); pyflakes clean bar the pre-existing unused tuning_name import.
  • Full pytest 2400 passed (110 tuning/config cases); npm run lint 0; Codex 0 findings.
  • Boot smoke: /api/tunings serves referencePitch + tunings + tuningMidis.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a tuning catalog API that returns available tunings, reference pitch, and MIDI representations.
    • Added support for shared tuning configuration and provider data across the application.
  • Bug Fixes

    • Invalid or missing reference-pitch settings now safely fall back to the default value.
  • Documentation

    • Updated size-exemption tracking for the latest routing changes.

…appconfig.py (R3)

The merged-tuning-catalog route moves to lib/routers/tunings.py, verbatim except
@app->@router, CONFIG_DIR->appstate.config_dir, and the two seam substrates it
needed:

  - lib/appconfig.py — the pure config.json reader `_load_config` (used by ~11
    server sites + future config-reading routers). server.py re-imports it, so
    those call sites and any `server._load_config` test reference are unchanged.
  - appstate.tuning_providers — the TuningProviderRegistry instance injected by
    reference (a stable object mutated in place via register()/unregister()), so
    the router reads the same registry plugins populate through plugin_context.
    The instance stays defined in server.py, so `server.tuning_providers` still
    resolves — zero test retargets.

The tuning constants (DEFAULT_REFERENCE_PITCH, TUNING_PRESET_MIDIS,
freqs_to_midis) already live in lib/tunings.py and are imported directly.

server.py: 6,960 -> 6,917.

Verified: pyflakes clean (bar the pre-existing unused `tuning_name` import);
route table IDENTICAL (143); full pytest 2400 passed (110 tuning/config cases);
eslint 0. Boot smoke: /api/tunings serves referencePitch + tunings + tuningMidis.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@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: 5e616abf-0b23-4dff-bfa0-1d0e6446772c

📥 Commits

Reviewing files that changed from the base of the PR and between cce95cb and 5641a89.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • docs/size-exemptions.md
  • lib/appconfig.py
  • lib/appstate.py
  • lib/routers/tunings.py
  • server.py

📝 Walkthrough

Walkthrough

The tuning API implementation moves from server.py into routers/tunings.py. Configuration loading becomes shared, the provider registry is injected through appstate, and the server registers the new router while removing the inline endpoint.

Changes

Tuning API extraction

Layer / File(s) Summary
Shared configuration and state seams
lib/appconfig.py, lib/appstate.py
Adds _load_config() for safe JSON dictionary loading and exposes tuning_providers through the appstate injection slots.
Tuning router endpoint
lib/routers/tunings.py
Adds GET /api/tunings, including reference-pitch validation, merged tuning retrieval, MIDI metadata generation, and response construction.
Server wiring and release metadata
server.py, CHANGELOG.md, docs/size-exemptions.md
Registers the tuning router, publishes the server-owned provider registry, removes the inline implementation, and updates related tracking entries.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant get_tunings
  participant _load_config
  participant tuning_providers
  Client->>get_tunings: GET /api/tunings
  get_tunings->>_load_config: Read config.json
  get_tunings->>tuning_providers: get_merged(referencePitch)
  tuning_providers-->>get_tunings: Merged tunings
  get_tunings-->>Client: referencePitch, tunings, tuningMidis
Loading
🚥 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 refactor: moving /api/tunings into routers/tunings.py and adding lib/appconfig.py.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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-tunings

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

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