Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 23, 2025

Makes API/CLI behavior predictable and self-documenting through explicit configuration logging, introspection endpoint, and improved error responses.

Changes

Startup Configuration Banner

  • Lifespan handler logs environment on startup: mode, auth status, GCP project/region (when applicable), preset count
  • UTF-8 logging, no secrets exposed
======================================================================
🎵 Music Track Generator API - Startup Configuration
======================================================================
Mode: gcp
API Key Authentication: yes
Google Cloud Project: my-project
Google Cloud Region: us-west1
Available Presets: 5 loaded
======================================================================

/config Endpoint

  • Returns safe runtime configuration: mode, region, project, available presets, auth status
  • Respects authentication when configured
{
  "mode": "gcp",
  "region": "us-west1",
  "project": "my-project",
  "presets_available": ["rock_anthem", "jazz_smooth", ...],
  "auth_enabled": true
}

Structured Validation Errors

  • Custom RequestValidationError handler returns 422 with field-level details
  • Clear field identification for debugging
{
  "detail": "Validation error",
  "errors": [
    {
      "field": "body.duration_seconds",
      "message": "Input should be greater than or equal to 60",
      "type": "greater_than_equal"
    }
  ]
}

Makefile

  • Common targets: venv, install, test, api, cli-help, clean

Documentation

  • README updated with expected outputs for simulate mode
  • /config endpoint documented with examples
Original prompt

Goal

Make the API/CLI behavior predictable and self-documenting, especially around environment configuration, without changing core features.

Tasks

  1. Startup Log Banner in src/music_generator/api.py:
    • Add a startup event handler that prints a banner with:
      • MUSIC_GEN_MODE value.
      • Whether MUSIC_GEN_API_KEY is set (yes/no).
      • GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_REGION when in gcp mode.
  2. New /config Endpoint:
    • Add a GET /config endpoint in api.py that returns safe configuration info:
      • mode, region, project (if any), presets_available, auth_enabled (true/false).
      • Ensure no secrets are returned.
  3. Improved Error Handling:
    • In generate_track (/tracks/generate), ensure duration_seconds is validated.
    • Return a structured 422 error with field names for validation failures.
    • Use a custom exception handler for RequestValidationError to format errors.
  4. Add a Makefile:
    • Include targets: venv, install, test, api, cli-help.
  5. Update README.md:
    • Add exact commands and expected outputs for simulate mode.
  6. Update Tests:
    • Update tests/test_api.py to include tests for the new /config endpoint and structured error responses.

Constraints

  • Keep current endpoints stable.
  • Do not implement a real Vertex AI music model call yet.
  • No silent fallbacks: print clear logs for mode/auth/config at startup.
  • UTF-8 logs and no secrets in logs.

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 23, 2025 17:27
…Makefile

Co-authored-by: kngms <167722266+kngms@users.noreply.github.com>
…alization order

Co-authored-by: kngms <167722266+kngms@users.noreply.github.com>
Copilot AI changed the title [WIP] Add startup log banner and new /config endpoint Add startup configuration banner, /config endpoint, and structured validation errors Dec 23, 2025
Copilot AI requested a review from kngms December 23, 2025 17:34
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