test_terminal_quests.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """Terminal-only Quest completion behavior."""
  2. from __future__ import annotations
  3. from pathlib import Path
  4. import pytest
  5. from src.agents.coordinator import MoneyMirrorCoordinator
  6. from .fakes import FakeRuntime
  7. ROOT = Path(__file__).resolve().parents[1]
  8. def test_cli_can_confirm_subscription_quest_and_memory_preserves_it(tmp_path: Path) -> None:
  9. coordinator = MoneyMirrorCoordinator(tmp_path / "memory.db", runtime=FakeRuntime())
  10. try:
  11. report = coordinator.analyze_csv(ROOT / "data" / "sample_01.csv")
  12. result = coordinator.complete_quest(report, "subscription_hunter", "已检查三个订阅")
  13. quest = next(item for item in report.quests if item.quest_id == "subscription_hunter")
  14. assert quest.status == "completed"
  15. assert quest.progress == quest.target
  16. assert result["gained_exp"] == quest.exp_reward
  17. # Re-analyzing the same monthly bill must retain the user-confirmed
  18. # review rather than letting deterministic transaction parsing erase it.
  19. refreshed = coordinator.analyze_csv(ROOT / "data" / "sample_01.csv")
  20. refreshed_quest = next(item for item in refreshed.quests if item.quest_id == "subscription_hunter")
  21. assert refreshed_quest.status == "completed"
  22. assert "CLI" in refreshed_quest.evidence
  23. finally:
  24. coordinator.close()
  25. def test_cli_cannot_override_spending_derived_quest(tmp_path: Path) -> None:
  26. coordinator = MoneyMirrorCoordinator(tmp_path / "memory.db", runtime=FakeRuntime())
  27. try:
  28. report = coordinator.analyze_csv(ROOT / "data" / "sample_01.csv")
  29. with pytest.raises(ValueError, match="账单自动计算"):
  30. coordinator.complete_quest(report, "late_night_guard")
  31. finally:
  32. coordinator.close()
  33. def test_main_requires_an_explicit_csv_path() -> None:
  34. """A bill path is required; no hidden default bill is selected."""
  35. import main
  36. command = main.parser()
  37. args = command.parse_args(["--csv", "bill.csv"])
  38. assert args.csv.name == "bill.csv"
  39. assert not hasattr(args, "demo")