| 1 | """Tests for planner.plan_query internal_subrun quiet mode.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import io |
| 6 | import unittest |
| 7 | from contextlib import redirect_stderr |
| 8 | |
| 9 | from lib import planner |
| 10 | |
| 11 | |
| 12 | class PlannerQuietModeTests(unittest.TestCase): |
| 13 | def _call(self, *, internal_subrun: bool): |
| 14 | err = io.StringIO() |
| 15 | with redirect_stderr(err): |
| 16 | plan = planner.plan_query( |
| 17 | topic="Acme Corp", |
| 18 | available_sources=["grounding", "reddit"], |
| 19 | requested_sources=None, |
| 20 | depth="default", |
| 21 | provider=None, |
| 22 | model=None, |
| 23 | internal_subrun=internal_subrun, |
| 24 | ) |
| 25 | return plan, err.getvalue() |
| 26 | |
| 27 | def test_default_emits_law7_warning(self): |
| 28 | plan, stderr = self._call(internal_subrun=False) |
| 29 | self.assertIn("No --plan passed", stderr) |
| 30 | self.assertIn("YOU ARE the planner", stderr) |
| 31 | self.assertTrue(plan.subqueries) |
| 32 | |
| 33 | def test_internal_subrun_suppresses_warning(self): |
| 34 | plan, stderr = self._call(internal_subrun=True) |
| 35 | self.assertNotIn("No --plan passed", stderr) |
| 36 | self.assertNotIn("YOU ARE the planner", stderr) |
| 37 | # Still returns a valid fallback plan |
| 38 | self.assertTrue(plan.subqueries) |
| 39 | |
| 40 | def test_internal_subrun_still_allows_other_warnings(self): |
| 41 | """Quiet mode only silences the LAW 7 block, not all planner output.""" |
| 42 | plan, _stderr = self._call(internal_subrun=True) |
| 43 | # The plan itself is deterministic fallback; verify note carries |
| 44 | # no planner-error indication. |
| 45 | self.assertGreater(len(plan.subqueries), 0) |
| 46 | |
| 47 | if __name__ == "__main__": |
| 48 | unittest.main() |
| 49 |