test_model_routing_integration.py
python
sha256:c07f2f34a0db9f43fe866f157d1935322008545ff8940c06c7c921eb219c55ab
NXP-b DONE: independent BV-r2 pass + ISR (SD-17)
Human
minor
⚠ breaking
1 day ago
| 1 | """Integration tests for Track P / P-route CLI (§PR.8).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import json |
| 6 | from pathlib import Path |
| 7 | |
| 8 | import pytest |
| 9 | import yaml |
| 10 | |
| 11 | from adapters.config import load_config |
| 12 | from adapters.errors import ConfigError |
| 13 | from cli.kit_root import kit_root |
| 14 | from tests.fixtures.model_routing import seed_routing_repo, write_routing_policy |
| 15 | from tests.support import FIXTURES, git_status_runner, run_cli, write_config |
| 16 | |
| 17 | |
| 18 | def test_route_resolves_representative_triple(tmp_path: Path) -> None: |
| 19 | seed_routing_repo(tmp_path) |
| 20 | code = run_cli( |
| 21 | ["route", "--position", "overseer", "--json"], |
| 22 | cwd=tmp_path, |
| 23 | runner=git_status_runner(), |
| 24 | kit=kit_root(), |
| 25 | json_mode=True, |
| 26 | ) |
| 27 | assert code == 0 |
| 28 | |
| 29 | |
| 30 | def test_route_json_payload(tmp_path: Path, capsys) -> None: |
| 31 | seed_routing_repo(tmp_path) |
| 32 | code = run_cli( |
| 33 | ["route", "--phase-tier", "auto", "--json"], |
| 34 | cwd=tmp_path, |
| 35 | runner=git_status_runner(), |
| 36 | kit=kit_root(), |
| 37 | json_mode=True, |
| 38 | ) |
| 39 | assert code == 0 |
| 40 | payload = json.loads(capsys.readouterr().out) |
| 41 | assert payload["route_id"] == "auto-build" |
| 42 | assert payload["model_tier"] == "standard" |
| 43 | assert payload["fallback"] == ["standard", "human"] |
| 44 | |
| 45 | |
| 46 | def test_route_validate_valid(tmp_path: Path) -> None: |
| 47 | seed_routing_repo(tmp_path) |
| 48 | assert ( |
| 49 | run_cli( |
| 50 | ["route", "--validate"], |
| 51 | cwd=tmp_path, |
| 52 | runner=git_status_runner(), |
| 53 | kit=kit_root(), |
| 54 | ) |
| 55 | == 0 |
| 56 | ) |
| 57 | |
| 58 | |
| 59 | def test_route_validate_reports_first_violation(tmp_path: Path) -> None: |
| 60 | seed_routing_repo(tmp_path) |
| 61 | write_routing_policy( |
| 62 | tmp_path, |
| 63 | """ |
| 64 | version: 1 |
| 65 | defaults: |
| 66 | model_tier: standard |
| 67 | fallback: [fast, human] |
| 68 | """, |
| 69 | ) |
| 70 | assert ( |
| 71 | run_cli( |
| 72 | ["route", "--validate"], |
| 73 | cwd=tmp_path, |
| 74 | runner=git_status_runner(), |
| 75 | kit=kit_root(), |
| 76 | ) |
| 77 | == 30 |
| 78 | ) |
| 79 | |
| 80 | |
| 81 | def test_route_missing_policy_exit_31(tmp_path: Path) -> None: |
| 82 | write_config(tmp_path, "config-git-only.yaml") |
| 83 | assert ( |
| 84 | run_cli( |
| 85 | ["route", "--validate"], |
| 86 | cwd=tmp_path, |
| 87 | runner=git_status_runner(), |
| 88 | kit=kit_root(), |
| 89 | ) |
| 90 | == 31 |
| 91 | ) |
| 92 | |
| 93 | |
| 94 | def test_route_malformed_policy_exit_30(tmp_path: Path) -> None: |
| 95 | seed_routing_repo(tmp_path) |
| 96 | write_routing_policy( |
| 97 | tmp_path, |
| 98 | """ |
| 99 | version: 1 |
| 100 | defaults: |
| 101 | model_tier: standard |
| 102 | fallback: [standard] |
| 103 | """, |
| 104 | ) |
| 105 | assert ( |
| 106 | run_cli( |
| 107 | ["route"], |
| 108 | cwd=tmp_path, |
| 109 | runner=git_status_runner(), |
| 110 | kit=kit_root(), |
| 111 | ) |
| 112 | == 30 |
| 113 | ) |
| 114 | |
| 115 | |
| 116 | def test_model_routing_enabled_false_status_unchanged(tmp_path: Path, capsys) -> None: |
| 117 | seed_routing_repo(tmp_path, enabled=False) |
| 118 | (tmp_path / ".overseer" / "version.lock").write_text( |
| 119 | "lock_version: 1\nkit_version: 0.1.0\nconfig_version: 1\n" |
| 120 | "footprint_digest: sha256:0\ninstalled_at: '2026-01-01'\n" |
| 121 | "synced_at: '2026-01-01'\nfootprint: []\n", |
| 122 | encoding="utf-8", |
| 123 | ) |
| 124 | code = run_cli( |
| 125 | ["status", "--json"], |
| 126 | cwd=tmp_path, |
| 127 | runner=git_status_runner(), |
| 128 | kit=kit_root(), |
| 129 | json_mode=True, |
| 130 | ) |
| 131 | assert code == 0 |
| 132 | payload = json.loads(capsys.readouterr().out) |
| 133 | assert payload["model_routing"]["enabled"] is False |
| 134 | |
| 135 | |
| 136 | def test_model_routing_enabled_true_shows_validity(tmp_path: Path, capsys) -> None: |
| 137 | seed_routing_repo(tmp_path, enabled=True) |
| 138 | (tmp_path / ".overseer" / "version.lock").write_text( |
| 139 | "lock_version: 1\nkit_version: 0.1.0\nconfig_version: 1\n" |
| 140 | "footprint_digest: sha256:0\ninstalled_at: '2026-01-01'\n" |
| 141 | "synced_at: '2026-01-01'\nfootprint: []\n", |
| 142 | encoding="utf-8", |
| 143 | ) |
| 144 | code = run_cli( |
| 145 | ["status", "--json"], |
| 146 | cwd=tmp_path, |
| 147 | runner=git_status_runner(), |
| 148 | kit=kit_root(), |
| 149 | json_mode=True, |
| 150 | ) |
| 151 | assert code == 0 |
| 152 | payload = json.loads(capsys.readouterr().out) |
| 153 | assert payload["model_routing"]["enabled"] is True |
| 154 | assert payload["model_routing"]["valid"] is True |
| 155 | |
| 156 | |
| 157 | def test_model_routing_policy_path_escape_exit_4(tmp_path: Path) -> None: |
| 158 | write_config(tmp_path, "config-git-only.yaml") |
| 159 | cfg = tmp_path / ".overseer" / "config.yaml" |
| 160 | data = yaml.safe_load(cfg.read_text(encoding="utf-8")) |
| 161 | data["model_routing"] = {"enabled": True, "policy": "../outside.yaml"} |
| 162 | cfg.write_text(yaml.safe_dump(data, sort_keys=False), encoding="utf-8") |
| 163 | with pytest.raises(ConfigError): |
| 164 | load_config(cfg) |
| 165 | data["model_routing"] = {"enabled": True, "policy": "policy/model-routing.yaml"} |
| 166 | cfg.write_text(yaml.safe_dump(data, sort_keys=False), encoding="utf-8") |
| 167 | seed_routing_repo(tmp_path) |
| 168 | data["model_routing"] = {"enabled": True, "policy": "/etc/passwd"} |
| 169 | cfg.write_text(yaml.safe_dump(data, sort_keys=False), encoding="utf-8") |
| 170 | with pytest.raises(ConfigError, match="repo-relative"): |
| 171 | load_config(cfg) |
| 172 | |
| 173 | |
| 174 | def test_config_model_routing_defaults() -> None: |
| 175 | config = load_config(FIXTURES / "config-git-only.yaml") |
| 176 | assert config.model_routing.enabled is False |
| 177 | assert config.model_routing.policy == "policy/model-routing.yaml" |
File History
1 commit
sha256:c07f2f34a0db9f43fe866f157d1935322008545ff8940c06c7c921eb219c55ab
NXP-b DONE: independent BV-r2 pass + ISR (SD-17)
Human
minor
⚠
1 day ago