Context
Call assertions resolve their state from a dynamically-named global
(_BASHUNIT_SPY_<name>_TIMES_FILE). When the name was never spied, the global is
unset, bashunit::spy::times_to_slot reports 0 calls
(src/test_doubles.sh:20-23), and the assertion behaves as if the command exists
and was simply never invoked.
Evidence
Both of these pass today:
function test_typo_in_spy_name_passes_silently() {
bashunit::spy touch
touch x
assert_not_called tuoch # PASSES — typo, asserts nothing
}
function test_zero_times_on_unspied_command() {
assert_have_been_called_times 0 never_spied_at_all # PASSES
}
And asserting arguments on a name that was never spied produces a diff with no
hint about the real cause:
✗ Failed: Assert without spy gives no hint
Expected 'foo'
but got ''
Proposal
Track registered spies (the name is already appended to
_BASHUNIT_MOCKED_FUNCTIONS in bashunit::spy) and, when a call assertion
targets a name that is not in that list, fail with a distinct message instead of
reporting zero calls:
✗ Failed: Assert not called
'tuoch' was never registered as a spy
Did you mean 'touch'? Call bashunit::spy 'tuoch' first.
The "did you mean" suggestion is optional; the hard requirement is that
asserting on an unregistered name fails rather than silently passing.
Note the deliberate exception: assert_have_been_called_times 0 <spy> /
assert_not_called <spy> on a registered spy must keep passing — that is the
whole point of those assertions.
Why this matters for agentic coding
assert_not_called and assert_have_been_called_times 0 are exactly the
assertions an agent reaches for to prove a guard clause works ("the destructive
command was not run"). A typo in the command name makes that proof vacuous while
still printing green, and there is nothing in the output for the agent to notice.
An agent has no intuition to re-read the spy name; it needs the framework to say
so.
Acceptance criteria
Context
Call assertions resolve their state from a dynamically-named global
(
_BASHUNIT_SPY_<name>_TIMES_FILE). When the name was never spied, the global isunset,
bashunit::spy::times_to_slotreports0calls(
src/test_doubles.sh:20-23), and the assertion behaves as if the command existsand was simply never invoked.
Evidence
Both of these pass today:
And asserting arguments on a name that was never spied produces a diff with no
hint about the real cause:
Proposal
Track registered spies (the name is already appended to
_BASHUNIT_MOCKED_FUNCTIONSinbashunit::spy) and, when a call assertiontargets a name that is not in that list, fail with a distinct message instead of
reporting zero calls:
The "did you mean" suggestion is optional; the hard requirement is that
asserting on an unregistered name fails rather than silently passing.
Note the deliberate exception:
assert_have_been_called_times 0 <spy>/assert_not_called <spy>on a registered spy must keep passing — that is thewhole point of those assertions.
Why this matters for agentic coding
assert_not_calledandassert_have_been_called_times 0are exactly theassertions an agent reaches for to prove a guard clause works ("the destructive
command was not run"). A typo in the command name makes that proof vacuous while
still printing green, and there is nothing in the output for the agent to notice.
An agent has no intuition to re-read the spy name; it needs the framework to say
so.
Acceptance criteria
assert_not_called/_times 0on a registered spy still passbashunit::unmocking a spy and then asserting on it fails the same waytests/functional/doubles_test.sh(useassert_fails)docs/test-doubles.md+docs/ai-agents.mdmake sa+make lintgreen