Commit 86cda64
agent: validate goal input in StandardAgent.solve() (#130)
Closes #76
Before this change, passing `None`, a non-string, or an empty/whitespace
string to `solve()` resulted in a confusing traceback from deep inside
either the goal preprocessor (`process(None, ...)`) or the reasoner. The
state machine could even be left in `BUSY` because validation happened
*after* `_state = AgentState.BUSY`.
This PR validates `goal` at the very top of `solve()`:
- `goal is None` → `TypeError("goal must be a non-empty str, got None")`
- `not isinstance(str)` → `TypeError("goal must be a str, got <type>")`
(informative type name in the message)
- `not goal.strip()` → `ValueError("goal must be a non-empty string ...")`
Whitespace-bearing goals like `" do the thing "` are still accepted —
we only reject *empty* or *only-whitespace* inputs.
Why these specific exceptions:
- `TypeError` for None / wrong type, matching the Python stdlib
convention for "you passed an object of the wrong shape".
- `ValueError` for empty/whitespace, matching the convention for
"right type, wrong value".
State machine invariant: validation happens *before* any state mutation,
so a rejected `solve(...)` leaves `agent.state == READY` (asserted in
every new test).
Tests (`tests/agents/test_standard_agent.py`):
- `test_solve_raises_type_error_on_none_goal`
- `test_solve_raises_type_error_on_non_string_goal` — parametrized over
`[123, 1.5, ["a"], {"x": 1}, b"bytes"]`
- `test_solve_raises_value_error_on_empty_or_whitespace_goal` —
parametrized over `["", " ", "\n", "\t \n"]`
- `test_solve_accepts_goal_with_leading_or_trailing_whitespace` —
guards against over-strict validation regression.
All 28 tests in `tests/agents/test_standard_agent.py` pass (17
existing + 11 new). `ruff check` clean on touched files. Pre-existing
mypy issues are unchanged (verified: same count on `main` vs this
branch).
AI-assisted via Cursor (Claude Opus 4.7). Personal token-burn
initiative by @adv0r to use up an expiring Cursor subscription budget
on small, useful upstream contributions.
Co-authored-by: adv0r <>
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent c375c6c commit 86cda64
2 files changed
Lines changed: 65 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
89 | 110 | | |
90 | 111 | | |
91 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
104 | 147 | | |
105 | 148 | | |
106 | 149 | | |
| |||
0 commit comments