Skip to content

Conversation

@matdev83
Copy link
Owner

@matdev83 matdev83 commented Oct 12, 2025

Summary

  • add a --force-model CLI alias that shares the static route logic and remains mutually exclusive with --static-route
  • extend the CLI and static route tests to cover the alias and clean up environment handling
  • refresh the CLI flag snapshot and test-suite metadata

Testing

  • ./.venv/Scripts/python.exe -m pytest tests/unit/test_cli.py
  • ./.venv/Scripts/python.exe -m pytest tests/unit/test_static_route.py
  • ./.venv/Scripts/python.exe -m pytest

https://chatgpt.com/codex/tasks/task_e_68ec2580a92883338037a8e0a42c4943

Summary by CodeRabbit

  • New Features

    • Added a --force-model CLI flag to explicitly select a model at runtime. It serves as an alias to static routing and is mutually exclusive with --static-route.
  • Tests

    • Added unit tests to validate parsing and application of the new flag.
  • Chores

    • Updated the CLI flag snapshot to include the new option.
    • Refreshed test suite metadata.

@coderabbitai
Copy link

coderabbitai bot commented Oct 12, 2025

Walkthrough

Adds a new CLI flag --force-model as an alias for --static-route, integrates it into argument parsing, maps it to the same internal static routing override, updates env var handling, and extends tests. Data snapshots updated for CLI flags and test suite state.

Changes

Cohort / File(s) Summary of changes
CLI Core
src/core/cli.py
Adds --force-model in a mutually exclusive group with --static-route; maps to static route override; sets corresponding environment variable; records usage; no public API changes.
Unit Tests
tests/unit/test_cli.py, tests/unit/test_static_route.py
Adds tests for --force-model parsing and application; ensures env var STATIC_ROUTE is cleaned/restored; replaces prior rejection test with acceptance of alias; note: duplicate test function present in test_cli.py.
Data Snapshots
data/cli_flag_snapshot.txt, data/test_suite_state.json
Updates CLI flags snapshot to include --force-model; updates test count and timestamp in test suite state JSON; no structural changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant CLI as CLI Parser
  participant Core as apply_cli_args
  participant Env as Environment
  participant Cfg as Config

  User->>CLI: run command with --force-model MODEL
  CLI->>Core: args(force_model=MODEL)
  Core->>Env: set STATIC_ROUTE=MODEL
  Core->>Cfg: set backends.static_route=MODEL
  Core-->>User: return configured runtime
  note over Core,Cfg: --force-model aliases --static-route (mutually exclusive)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitched my nose at a brand-new flag,
“--force-model,” I cheerfully tag.
Hops to config, routes align,
STATIC_ROUTE set—everything fine.
Tests multiply like clover in spring—
Oops, one duplicate, a twinly thing.
Thump! The CLI’s ready to sing.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely summarizes the main change by describing the addition of the --force-model CLI alias for static routing, so scanning the history reveals the core intent without ambiguity.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-documented-code-behavior-inconsistencies

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

@codecov
Copy link

codecov bot commented Oct 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
tests/unit/test_cli.py (1)

226-236: Test coverage should verify functional behavior, not just config assignment.

The test verifies that --force-model sets config.backends.static_route, but doesn't validate whether the resulting value is correctly parsed by the backend service. Given the semantic ambiguity in the CLI help text (whether --force-model accepts "MODEL" or "BACKEND:MODEL"), consider adding an integration test that verifies the backend resolution actually works with the value set by --force-model.

Example additional test:

@pytest.mark.asyncio
async def test_cli_force_model_backend_resolution():
    """Verify that --force-model results in correct backend resolution."""
    with patch("src.core.config.app_config.load_config", return_value=AppConfig()):
        args = parse_cli_args(["--force-model", "gemini-2.5-pro"])
        config = _unwrap_config(apply_cli_args(args))
        
        # Verify the backend service can parse the static_route value
        # This test would need appropriate mocks for BackendService
        # to validate that the model resolution works correctly
tests/unit/test_static_route.py (2)

10-10: Consider moving shared test utilities to a common module.

Importing _unwrap_config from another test file (test_cli.py) creates coupling between test modules. If the structure of test_cli.py changes, this import could break. Consider moving shared test utilities to a dedicated test utilities module (e.g., tests/conftest.py or tests/utils.py).

Example:

Create tests/utils.py:

"""Shared test utilities."""
from src.core.config.app_config import AppConfig, ParameterResolution

def unwrap_config(
    result: AppConfig | tuple[AppConfig, ParameterResolution],
) -> AppConfig:
    """Unwrap config from apply_cli_args return value."""
    return result[0] if isinstance(result, tuple) else result

Then update imports:

-from tests.unit.test_cli import _unwrap_config
+from tests.utils import unwrap_config

211-219: Test should verify the full behavior chain, not just config assignment.

Similar to the test in test_cli.py, this test only verifies that --force-model sets the config value but doesn't validate whether the resulting static_route value is correctly parsed and used by the backend service. Consider extending this test to verify the end-to-end behavior using the existing test fixtures in this file.

Example extension:

@pytest.mark.asyncio
async def test_force_model_alias_routes_correctly(
    self,
    mock_session_service,
    mock_backend_factory,
    mock_wire_capture,
    mock_rate_limiter,
    mock_app_state,
):
    """Test that --force-model results in correct backend routing."""
    from src.core.cli import apply_cli_args, parse_cli_args
    
    args = parse_cli_args(["--force-model", "gemini-2.5-pro"])
    config = _unwrap_config(apply_cli_args(args))
    
    service = BackendService(
        factory=mock_backend_factory,
        rate_limiter=mock_rate_limiter,
        config=config,
        session_service=mock_session_service,
        app_state=mock_app_state,
        wire_capture=mock_wire_capture,
        failover_routes={},
    )
    
    request = ChatRequest(
        model="gpt-4",
        messages=[{"role": "user", "content": "test"}],
    )
    
    backend_type, effective_model = await service._resolve_backend_and_model(request)
    # Verify the routing works as expected
    assert effective_model == "gemini-2.5-pro"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd216cf and 6f6f6fe.

📒 Files selected for processing (5)
  • data/cli_flag_snapshot.txt (1 hunks)
  • data/test_suite_state.json (1 hunks)
  • src/core/cli.py (2 hunks)
  • tests/unit/test_cli.py (2 hunks)
  • tests/unit/test_static_route.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Avoid using emojis in Python code comments or docstrings
Follow PEP 8 and use type hints for all functions
Import order must be: standard library, third-party, then local imports, separated by blank lines
Naming conventions: snake_case for variables and functions; PascalCase for classes
Error handling: use specific exceptions and include meaningful error messages
Prefer f-strings for string formatting

Files:

  • src/core/cli.py
  • tests/unit/test_cli.py
  • tests/unit/test_static_route.py
src/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.py: Catch specific exceptions; avoid broad except Exception blocks
If a broad exception must be caught, log with exc_info=True and re-raise a specific custom exception
Use the most specific exception class from src.core.common.exceptions that accurately describes the error
Provide clear, helpful error messages and include relevant details in the details dictionary of custom exceptions

Files:

  • src/core/cli.py
🧬 Code graph analysis (2)
tests/unit/test_cli.py (1)
src/core/cli.py (1)
  • parse_cli_args (514-517)
tests/unit/test_static_route.py (2)
tests/unit/test_cli.py (1)
  • _unwrap_config (37-40)
src/core/cli.py (2)
  • apply_cli_args (520-1045)
  • parse_cli_args (514-517)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test (3.10)
🔇 Additional comments (2)
tests/unit/test_cli.py (1)

20-20: LGTM!

Good practice to include STATIC_ROUTE in the cleanup to prevent test contamination.

src/core/cli.py (1)

96-108: No changes required for --force-model
The CLI already assigns the model-only string to static_route, and the backend logic treats a no-colon override as “model only” using the configured default backend, matching the existing help text.

Likely an incorrect or invalid review comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant