| 1 | import importlib.util |
| 2 | import unittest |
| 3 | from pathlib import Path |
| 4 | from unittest import mock |
| 5 | |
| 6 | |
| 7 | def load_verify_module(): |
| 8 | path = Path(__file__).resolve().parents[1] / "skills" / "last30days" / "scripts" / "verify_v3.py" |
| 9 | spec = importlib.util.spec_from_file_location("verify_v3_module", path) |
| 10 | module = importlib.util.module_from_spec(spec) |
| 11 | assert spec and spec.loader |
| 12 | spec.loader.exec_module(module) |
| 13 | return module |
| 14 | |
| 15 | |
| 16 | class VerifyV3Tests(unittest.TestCase): |
| 17 | def test_parser_defaults(self): |
| 18 | module = load_verify_module() |
| 19 | parser = module.build_parser() |
| 20 | args = parser.parse_args([]) |
| 21 | self.assertEqual(args.baseline, "HEAD~1") |
| 22 | self.assertEqual(args.candidate, "WORKTREE") |
| 23 | self.assertFalse(args.skip_eval) |
| 24 | self.assertFalse(args.skip_latency) |
| 25 | |
| 26 | def test_smoke_and_latency_request_raw_json_profile(self): |
| 27 | module = load_verify_module() |
| 28 | completed = mock.Mock(stdout='{"clusters": [{"id":"c1"}], "ranked_candidates": [{"id":"r1"}], "provider_runtime":{"reasoning_provider":"fixture"}, "errors_by_source":{"reddit":"fixture-error"}}') |
| 29 | with mock.patch.object(module, "run_command", return_value=completed) as run: |
| 30 | module.SMOKE_CASES = [("auto", ["--quick"])] |
| 31 | module.LATENCY_PROFILES = [("quick", ["--quick"])] |
| 32 | module.LATENCY_TOPICS = ["topic"] |
| 33 | smoke = module.verify_smoke() |
| 34 | latency = module.verify_latency() |
| 35 | |
| 36 | commands = [call.args[0] for call in run.call_args_list] |
| 37 | self.assertEqual(len(commands), 2) |
| 38 | self.assertEqual(commands[0], [module.PYTHON, str(module.ENGINE), module.SMOKE_TOPIC, "--emit=json", "--json-profile=raw", "--quick"]) |
| 39 | self.assertEqual(commands[1], [module.PYTHON, str(module.ENGINE), "topic", "--emit=json", "--json-profile=raw", "--quick"]) |
| 40 | self.assertEqual(run.call_args_list[0].kwargs["env"]["LAST30DAYS_REASONING_PROVIDER"], "auto") |
| 41 | self.assertEqual(run.call_args_list[1].kwargs["env"]["LAST30DAYS_ALLOW_ENGINE_PLAN"], "1") |
| 42 | self.assertEqual(len(smoke), 1) |
| 43 | self.assertEqual({key: value for key, value in smoke[0].items() if key != "duration_seconds"}, { |
| 44 | "provider": "auto", "reasoning_provider": "fixture", "cluster_count": 1, |
| 45 | "candidate_count": 1, "error_sources": ["reddit"], |
| 46 | }) |
| 47 | self.assertEqual(set(latency), {"quick"}) |
| 48 | self.assertEqual(len(latency["quick"]["times"]), 1) |
| 49 | self.assertTrue(all("--json-profile=raw" in command for command in commands)) |
| 50 | |
| 51 | def test_unit_stage_invokes_pytest_runner(self): |
| 52 | module = load_verify_module() |
| 53 | rg_files = mock.Mock(stdout="skills/last30days/scripts/verify_v3.py\n") |
| 54 | with mock.patch.object(module, "run_command") as run, mock.patch.object( |
| 55 | module.subprocess, "run", return_value=rg_files |
| 56 | ): |
| 57 | module.verify_unit() |
| 58 | |
| 59 | runner_command = run.call_args_list[0].args[0] |
| 60 | self.assertEqual(runner_command, [module.PYTHON, "-m", "pytest", "tests"]) |
| 61 | self.assertNotIn("unittest", runner_command) |
| 62 | |
| 63 | |
| 64 | if __name__ == "__main__": |
| 65 | unittest.main() |
| 66 |