fix: validate and size governed patch outputs

This commit is contained in:
thanhnv
2026-07-18 11:29:37 +07:00
parent 36b6454b8d
commit f23fb98953
3 changed files with 61 additions and 13 deletions
@@ -38,6 +38,11 @@ class GoalPatchWorkflowTests(unittest.TestCase):
value = ORCHESTRATOR.extract_patch("```diff\ndiff --git a/apps/okr/frontend/a.ts b/apps/okr/frontend/a.ts\n--- a/apps/okr/frontend/a.ts\n+++ b/apps/okr/frontend/a.ts\n@@ -1 +1 @@\n-a\n+b\n```")
self.assertTrue(value.startswith("diff --git"))
def test_write_contract_rejects_a_truncated_diff_before_h3(self):
truncated = "diff --git a/apps/okr/frontend/a.ts b/apps/okr/frontend/a.ts\n--- a/apps/okr/frontend/a.ts\n+++ b/apps/okr/frontend/a.ts\n@@ -1 +1 @@\n-a\n"
with self.assertRaisesRegex(ValueError, "goal_patch_check_failed"):
ORCHESTRATOR.validate_write_output(truncated)
def test_invalid_write_output_gets_one_bounded_repair_attempt(self):
repaired = "```diff\ndiff --git a/apps/okr/frontend/a.ts b/apps/okr/frontend/a.ts\n--- a/apps/okr/frontend/a.ts\n+++ b/apps/okr/frontend/a.ts\n@@ -1 +1 @@\n-a\n+b\n```"
with patch.dict(os.environ, {"CASAN_GOAL_PATCH_REPAIR_ATTEMPTS": "1"}, clear=False), \
@@ -68,6 +73,7 @@ class GoalPatchWorkflowTests(unittest.TestCase):
self.assertEqual(reason, "ok")
self.assertEqual(usage["repair_model"], "openai:gpt-4o-mini")
self.assertEqual(call.call_args.args[0], "openai:gpt-4o-mini")
self.assertEqual(call.call_args.kwargs["max_output_tokens"], ORCHESTRATOR.patch_output_tokens())
def test_patch_outside_workspace_is_denied(self):
job = {"workspace": {"context_roots": ["apps/okr/frontend"]}}