W14: fix C22/K104 — harness logs IO before invoking the mock (+3 pins)
The interceptor appended the IO-log entry only after the mock returned, so
a throwing mock left no entry and error-path tests falsely reported "never
invoked" through assert-io-called/count (hosts.md C22, core.md K104).
spec/harness.sx make-interceptor now appends {:args :result nil :op}
BEFORE invoking the mock and updates :result in place via dict-set! on
return. This is W14-owned test infrastructure (PLAN.md W14 approach item
4), not a semantics edit.
Pins: suite gate-C22-throwing-mock-logged (throwing mock leaves an entry
with pending result; happy path updates the result; mixed throwing +
successful sequence counts all calls). Harness self-suite (15 tests) and
test-relate-picker (the only other harness consumer) verified green;
285/0 on the pins run.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -217,3 +217,37 @@
|
||||
(((fn (c) true) (fn (c) (* c 10))))
|
||||
(+ 1 (signal-condition 5)))
|
||||
51)))
|
||||
|
||||
(defsuite
|
||||
"gate-C22-throwing-mock-logged"
|
||||
(deftest
|
||||
"throwing mock still leaves an IO-log entry"
|
||||
(let
|
||||
((h (make-harness))
|
||||
(f (make-interceptor h "fetch" (fn (url) (error "boom-io")))))
|
||||
(let
|
||||
((r (try-call (fn () (f "http://a")))))
|
||||
(assert (not (get r "ok")) "mock error must propagate")
|
||||
(assert-io-called h "fetch")
|
||||
(assert-io-count h "fetch" 1)
|
||||
(assert= (get (io-call-nth h "fetch" 0) "result") nil))))
|
||||
(deftest
|
||||
"successful mock entry gets its result updated in place"
|
||||
(let
|
||||
((h (make-harness))
|
||||
(f (make-interceptor h "fetch" (fn (url) (str "got:" url)))))
|
||||
(f "http://a")
|
||||
(assert-io-count h "fetch" 1)
|
||||
(assert-io-result h "fetch" 0 "got:http://a")
|
||||
(assert-io-args h "fetch" 0 (list "http://a"))))
|
||||
(deftest
|
||||
"mixed throwing and successful calls are all counted"
|
||||
(let
|
||||
((h (make-harness))
|
||||
(bomb (make-interceptor h "action" (fn (x) (error "nope"))))
|
||||
(ok-f (make-interceptor h "action" (fn (x) "done"))))
|
||||
(try-call (fn () (bomb 1)))
|
||||
(ok-f 2)
|
||||
(try-call (fn () (bomb 3)))
|
||||
(assert-io-count h "action" 3)
|
||||
(assert= (get (io-call-nth h "action" 1) "result") "done"))))
|
||||
|
||||
Reference in New Issue
Block a user