| 1 | """Tests for scripts/tier_selector.py.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import json |
| 6 | |
| 7 | from scripts.tier_selector import build_config, main, select_tier |
| 8 | |
| 9 | |
| 10 | class TestSelectTier: |
| 11 | def test_normal(self): |
| 12 | assert select_tier(0.10, 2.00) == "normal" |
| 13 | |
| 14 | def test_budget_by_estimated_cost(self): |
| 15 | assert select_tier(0.50, 2.00) == "budget" |
| 16 | |
| 17 | def test_budget_by_monthly_spent(self): |
| 18 | assert select_tier(0.10, 5.00) == "budget" |
| 19 | |
| 20 | def test_minimal(self): |
| 21 | assert select_tier(0.10, 8.00) == "minimal" |
| 22 | |
| 23 | def test_emergency(self): |
| 24 | assert select_tier(0.10, 10.00) == "emergency" |
| 25 | |
| 26 | def test_emergency_custom_budget(self): |
| 27 | assert select_tier(0.10, 20.00, monthly_budget=20.00) == "emergency" |
| 28 | |
| 29 | def test_boundary_normal(self): |
| 30 | assert select_tier(0.49, 4.99) == "normal" |
| 31 | |
| 32 | def test_boundary_budget(self): |
| 33 | assert select_tier(0.50, 4.99) == "budget" |
| 34 | |
| 35 | |
| 36 | class TestBuildConfig: |
| 37 | def test_normal_config(self): |
| 38 | cfg = build_config("normal") |
| 39 | assert cfg == { |
| 40 | "tier": "normal", |
| 41 | "model": "claude-sonnet-4", |
| 42 | "max_repos": None, |
| 43 | "skip_ai": False, |
| 44 | } |
| 45 | |
| 46 | def test_budget_config(self): |
| 47 | cfg = build_config("budget") |
| 48 | assert cfg == { |
| 49 | "tier": "budget", |
| 50 | "model": "gpt-5.4-mini", |
| 51 | "max_repos": 100, |
| 52 | "skip_ai": False, |
| 53 | } |
| 54 | |
| 55 | def test_minimal_config(self): |
| 56 | cfg = build_config("minimal") |
| 57 | assert cfg == {"tier": "minimal", "model": "gpt-5-mini", "max_repos": 30, "skip_ai": False} |
| 58 | |
| 59 | def test_emergency_config(self): |
| 60 | cfg = build_config("emergency") |
| 61 | assert cfg == {"tier": "emergency", "model": None, "max_repos": None, "skip_ai": True} |
| 62 | |
| 63 | |
| 64 | class TestMain: |
| 65 | def test_normal_output(self, capsys): |
| 66 | code = main(["--estimated-cost", "0.10", "--monthly-spent", "2.00"]) |
| 67 | assert code == 0 |
| 68 | output = json.loads(capsys.readouterr().out) |
| 69 | assert output["tier"] == "normal" |
| 70 | |
| 71 | def test_emergency_output(self, capsys): |
| 72 | code = main(["--estimated-cost", "0.10", "--monthly-spent", "10.00"]) |
| 73 | assert code == 0 |
| 74 | output = json.loads(capsys.readouterr().out) |
| 75 | assert output["tier"] == "emergency" |
| 76 | assert output["skip_ai"] is True |
| 77 | |
| 78 | def test_always_exits_0(self, capsys): |
| 79 | code = main(["--estimated-cost", "5.00", "--monthly-spent", "99.00"]) |
| 80 | assert code == 0 |