Skip to content

test(settings-api): add pytest suite for settings, voice, and model-swap endpoints#452

Closed
buddy0323 wants to merge 2 commits intoLight-Heart-Labs:mainfrom
buddy0323:test/dashboard-settings-api
Closed

test(settings-api): add pytest suite for settings, voice, and model-swap endpoints#452
buddy0323 wants to merge 2 commits intoLight-Heart-Labs:mainfrom
buddy0323:test/dashboard-settings-api

Conversation

@buddy0323
Copy link
Contributor

Summary

  • Add tests/test_settings.py — 456-line pytest suite covering env_utils helpers, GET/PATCH /api/settings, GET/PATCH /api/settings/voice, and POST /api/model/swap
  • Add env_utils.py — shared helpers for reading/writing .env and loading/validating against .env.schema.json (no shell evaluation; pure regex)
  • Add routers/settings.pyGET /api/settings and PATCH /api/settings; secret keys (from schema "secret": true) are stripped from every response
  • Add routers/voice_settings.pyGET /api/settings/voice and PATCH /api/settings/voice; all fields validated against .env.schema.json before any write; rejects the whole request if any field fails (no partial writes)
  • Add routers/model_swap.pyPOST /api/model/swap; tier whitelist validated before any subprocess is launched; streams dream-cli output as SSE; ANSI codes stripped from log events
  • Extend models.py with SettingsResponse, SettingsPatch, VoiceSettingsResponse, VoiceSettingsPatch, ModelSwapRequest
  • Update main.py to register all three new routers
  • Extend .env.schema.json with WHISPER_MODEL enum and WHISPER_VAD_THRESHOLD number bounds

Test plan

  • GET /api/settings returns all required fields (llm_model, mode, tier, gpu_backend, enabled_services, voice_enabled, rag_enabled)
  • GET /api/settings — secret values (WEBUI_SECRET, LITELLM_KEY, OPENCLAW_TOKEN, …) are absent from the raw response body and not present as response keys
  • PATCH /api/settings with mode: "cloud"DREAM_MODE=cloud written to .env; response reflects new value
  • PATCH /api/settings with invalid mode: "turbo" → 422; .env unchanged
  • PATCH /api/settings with both invalid mode and blank llm_model → 422 with two errors (no partial write)
  • GET /api/settings/voice falls back to schema defaults when keys are absent; returns allowed_whisper_models list from schema
  • PATCH /api/settings/voice with whisper_model: "giant" → 422 with "must be one of" message
  • PATCH /api/settings/voice with whisper_vad_threshold: 1.5 → 422; valid boundaries 0.0 and 1.0 are accepted
  • PATCH /api/settings/voice with one invalid field alongside valid fields → no partial write
  • POST /api/model/swap with unknown tier → 422 containing the bad tier name
  • POST /api/model/swap when dream-cli not found → 501
  • POST /api/model/swap streams text/event-stream; final event has type: "done" on success or type: "error" on non-zero exit; ANSI codes stripped from log events; cache-control: no-cache header present
  • All endpoints return 401 without a Bearer token

@Lightheartdevs
Copy link
Collaborator

Closing as part of v2.1.0 stabilization. We're pausing new feature PRs while we solidify the installer and CI gates. If this is still relevant for v2.2.0 (targeting April 1), please rebase and resubmit. Thank you for contributing.

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.

2 participants