Files
reverse-engineering-anything/bridge/agentenv/test_solve.py
T
morluto d137ffa762 test(agentenv): consolidate verification, capture and cleanup checks (#12855)
* test(agentenv): consolidate solve verification and cleanup checks

* test(agentenv): verify capture argument delivery and retention together

* test: update lifecycle registry after campaign test renames
2026-11-20 15:05:34 +00:00

69 lines
3.4 KiB
Python

"""Project selected verifier facts without importing or running agentenv."""
import unittest
from types import SimpleNamespace
from bridge.agentenv.solve import _solve_facts
def run_with(verifications, outcome="passed"):
return SimpleNamespace(context={"metadata": {"verifications": verifications}},
outcome=SimpleNamespace(value=outcome))
class SolveFactsTest(unittest.TestCase):
def test_missing_empty_and_unscored_selected_verifier_do_not_borrow_success(self):
other = {"results": [{"id": "unrelated", "result": True}], "score": 1.0}
for selected in (None, {}, {"results": [], "score": 1.0},
{"results": [{"id": 0, "result": False}]}):
for reversed_order in (False, True):
with self.subTest(selected=selected, reversed_order=reversed_order):
entries = [("other", other)]
if selected is not None:
entries.append(("wanted", selected))
if reversed_order:
entries.reverse()
expected = ([{"id": "0", "passed": False, "description": ""}]
if selected and selected.get("results") else [])
self.assertEqual(_solve_facts(run_with(dict(entries)), "wanted"),
("unscored", expected))
def test_selected_score_owns_outcome_and_checks_preserve_false_and_zero(self):
# A weighted/any-pass verifier's recorded score can pass despite a failed
# criterion; an unrelated failing score cannot override the selected one.
rows = [{"id": 0, "result": False}, {"id": "zero", "result": 0},
{"id": "yes", "result": True}]
checks = [{"id": "0", "passed": False, "description": ""},
{"id": "zero", "passed": False, "description": ""},
{"id": "yes", "passed": True, "description": ""}]
for score, prior, expected in (
(0, "passed", "scored below 1"),
(0.5, "passed", "scored below 1"),
(1, "scored below 1", "passed"),
(1.5, "scored below 1", "passed"),
):
with self.subTest(score=score):
verifications = {"other": {"score": 0},
"wanted": {"results": rows, "score": score}}
self.assertEqual(_solve_facts(run_with(verifications, prior), "wanted"),
(expected, checks))
def test_failure_and_cancellation_preserve_partial_named_checks(self):
for outcome in ("failed", "cancelled"):
with self.subTest(outcome=outcome):
run = run_with({"wanted": {"results": [{"id": "partial", "result": True}],
"score": 1.0}}, outcome)
self.assertEqual(_solve_facts(run, "wanted"),
(outcome, [{"id": "partial", "passed": True, "description": ""}]))
def test_non_numeric_or_nonfinite_scores_remain_unscored(self):
for score in (None, True, "1", float("nan"), float("inf")):
with self.subTest(score=score):
run = run_with({"wanted": {"results": [{"id": "yes", "result": True}],
"score": score}})
self.assertEqual(_solve_facts(run, "wanted")[0], "unscored")
if __name__ == "__main__":
unittest.main()