feat: appove and go

This commit is contained in:
thanhnv
2026-07-19 09:37:16 +07:00
parent 13fae3e6c3
commit 709b6cccd6
24 changed files with 1245 additions and 70 deletions
@@ -26,6 +26,15 @@ def job_file(directory):
class ReviewerFallbackTests(unittest.TestCase):
def setUp(self):
# Production enables route preflight. Individual tests opt in explicitly
# so cached/live provider health cannot affect deterministic unit tests.
self.environment = patch.dict(
os.environ, {"CASAN_GOAL_MODEL_PREFLIGHT": "0"}, clear=False,
)
self.environment.start()
self.addCleanup(self.environment.stop)
def test_account_then_omniroute_then_local_and_persists_ledger(self):
calls = []
@@ -115,6 +124,78 @@ class ReviewerFallbackTests(unittest.TestCase):
self.assertEqual(calls, ["openai:gpt", "openai-compatible:route-a", "ollama:local"])
self.assertFalse(job["reviewer_attempts"][0]["retryable"])
def test_patch_reviewer_excludes_h2_model_and_receives_full_output_budget(self):
calls = []
def model(model, prompt, cloud, timeout, max_output_tokens=None):
calls.append((model, max_output_tokens))
return True, "reviewed patch", {}, "ok"
environment = {
"CASAN_GOAL_OMNIROUTE_MODELS": "route-a",
"CASAN_GOAL_REVIEWER_MAX_ATTEMPTS": "3",
"CASAN_GOAL_REVIEWER_DEADLINE_SEC": "30",
}
with tempfile.TemporaryDirectory() as directory, patch.dict(os.environ, environment, clear=False), patch.object(MODULE, "call_model", model):
path = job_file(directory)
ok, _, _, _, reviewer = MODULE.run_reviewer_chain(
path, "prompt", "", "openai:gpt-worker", "ollama:local",
max_output_tokens=8192, excluded_models={"openai:gpt-worker"},
)
self.assertTrue(ok)
self.assertEqual(reviewer["model"], "openai-compatible:route-a")
self.assertEqual(calls, [("openai-compatible:route-a", 8192)])
def test_local_reviewer_can_be_disabled_when_human_approval_is_available(self):
calls = []
def model(model, prompt, cloud, timeout):
calls.append(model)
return False, "", {}, "gateway_unavailable"
environment = {
"CASAN_GOAL_OMNIROUTE_MODELS": "route-a",
"CASAN_GOAL_ENABLE_LOCAL_REVIEWER": "0",
"CASAN_GOAL_REVIEWER_MAX_ATTEMPTS": "3",
"CASAN_GOAL_REVIEWER_DEADLINE_SEC": "30",
}
with tempfile.TemporaryDirectory() as directory, patch.dict(os.environ, environment, clear=False), patch.object(MODULE, "call_model", model):
path = job_file(directory)
ok, _, _, reason, _ = MODULE.run_reviewer_chain(path, "prompt", "", "", "ollama:ornith:9b")
self.assertFalse(ok)
self.assertEqual(reason, "gateway_unavailable")
self.assertEqual(calls, ["openai-compatible:route-a"])
def test_patch_reviewer_skips_unhealthy_route_before_full_generation(self):
calls = []
def model(model, prompt, cloud, timeout, max_output_tokens=None):
calls.append(model)
return True, "reviewed", {}, "ok"
environment = {
"CASAN_GOAL_OMNIROUTE_MODELS": "route-b",
"CASAN_GOAL_ENABLE_LOCAL_REVIEWER": "0",
"CASAN_GOAL_REVIEWER_MAX_ATTEMPTS": "3",
"CASAN_GOAL_REVIEWER_DEADLINE_SEC": "30",
}
with tempfile.TemporaryDirectory() as directory, patch.dict(os.environ, environment, clear=False), \
patch.object(MODULE, "model_preflight", side_effect=[(False, "gateway_503"), (True, "ok")]), \
patch.object(MODULE, "call_model", model):
path = job_file(directory)
ok, _, _, _, reviewer = MODULE.run_reviewer_chain(
path, "prompt", "", "openai-compatible:route-a", "ollama:ornith:9b", max_output_tokens=8192,
)
with open(path, encoding="utf-8") as handle:
job = json.load(handle)
self.assertTrue(ok)
self.assertEqual(reviewer["model"], "openai-compatible:route-b")
self.assertEqual(calls, ["openai-compatible:route-b"])
self.assertIn("model_preflight_failed", job["reviewer_attempts"][0]["reason"])
if __name__ == "__main__":
unittest.main()