|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +"""Model selection for the ACP entry point.""" |
| 4 | + |
| 5 | +import click.testing |
| 6 | +import pytest |
| 7 | +from nooa_acp.cli import command |
| 8 | + |
| 9 | + |
| 10 | +@pytest.fixture |
| 11 | +def stubbed_serve(monkeypatch): |
| 12 | + """Capture the llm_factory the command builds instead of serving.""" |
| 13 | + captured = {} |
| 14 | + |
| 15 | + def fake_serve(llm_factory): |
| 16 | + captured["llm_factory"] = llm_factory |
| 17 | + return "coroutine-placeholder" |
| 18 | + |
| 19 | + monkeypatch.setattr("nooa_acp.server.serve", fake_serve) |
| 20 | + monkeypatch.setattr("nooa_acp.cli.asyncio.run", lambda coro: coro) |
| 21 | + monkeypatch.setattr("nooa.secrets.load_secrets_into_env", lambda *a, **k: None) |
| 22 | + return captured |
| 23 | + |
| 24 | + |
| 25 | +def test_model_is_required(monkeypatch): |
| 26 | + monkeypatch.delenv("NOOA_MODEL", raising=False) |
| 27 | + |
| 28 | + result = click.testing.CliRunner().invoke(command, []) |
| 29 | + |
| 30 | + # No default model: the caller has to choose one. |
| 31 | + assert result.exit_code == 2 |
| 32 | + assert "--model" in result.output |
| 33 | + |
| 34 | + |
| 35 | +def test_model_is_read_from_the_environment(monkeypatch, stubbed_serve): |
| 36 | + monkeypatch.setenv("NOOA_MODEL", "openai/gpt-4o-mini") |
| 37 | + requested = {} |
| 38 | + monkeypatch.setattr( |
| 39 | + "nooa.unifiedllm.get_llm_client", |
| 40 | + lambda name, **kwargs: requested.setdefault("name", name), |
| 41 | + ) |
| 42 | + |
| 43 | + result = click.testing.CliRunner().invoke(command, []) |
| 44 | + |
| 45 | + assert result.exit_code == 0, result.output |
| 46 | + stubbed_serve["llm_factory"]() |
| 47 | + assert requested["name"] == "openai/gpt-4o-mini" |
| 48 | + |
| 49 | + |
| 50 | +def test_explicit_flag_overrides_the_environment(monkeypatch, stubbed_serve): |
| 51 | + monkeypatch.setenv("NOOA_MODEL", "openai/gpt-4o-mini") |
| 52 | + requested = {} |
| 53 | + monkeypatch.setattr( |
| 54 | + "nooa.unifiedllm.get_llm_client", |
| 55 | + lambda name, **kwargs: requested.setdefault("name", name), |
| 56 | + ) |
| 57 | + |
| 58 | + result = click.testing.CliRunner().invoke(command, ["--model", "anthropic/claude-sonnet-4-5"]) |
| 59 | + |
| 60 | + assert result.exit_code == 0, result.output |
| 61 | + stubbed_serve["llm_factory"]() |
| 62 | + assert requested["name"] == "anthropic/claude-sonnet-4-5" |
0 commit comments