(defsuite "harness" (defsuite "session" (deftest "make-harness creates session with default platform" (let ((h (make-harness))) (assert-true (not (nil? h))) (assert-true (not (nil? (get h "platform")))) (assert-length 0 (get h "log")))) (deftest "make-harness merges custom platform with defaults" (let ((h (make-harness :platform {:fetch (fn () "custom")}))) (assert-equal "custom" ((get (get h "platform") "fetch"))) (assert-true (not (nil? (get (get h "platform") "query")))))) (deftest "harness-reset clears log" (let ((h (make-harness)) (f (make-interceptor h "op" (fn () "ok")))) (f) (assert-equal 1 (len (get h "log"))) (harness-reset! h) (assert-length 0 (get h "log"))))) (defsuite "state" (deftest "harness-set and harness-get work" (let ((h (make-harness))) (harness-set! h "cookies" "session-abc") (assert-equal "session-abc" (harness-get h "cookies")))) (deftest "harness-get returns nil for unset keys" (let ((h (make-harness))) (assert-nil (harness-get h "nonexistent"))))) (defsuite "interceptor" (deftest "make-interceptor logs calls" (let ((h (make-harness)) (mock-fn (fn (x) (str "got:" x))) (interceptor (make-interceptor h "test-op" mock-fn))) (interceptor "hello") (assert-equal 1 (len (get h "log"))) (assert-equal "test-op" (get (first (get h "log")) "op")))) (deftest "interceptor returns mock result" (let ((h (make-harness)) (interceptor (make-interceptor h "op" (fn (x) (str "got:" x)))) (result (interceptor "hello"))) (assert-type "string" result) (assert-true (contains? result "got:")))) (deftest "interceptor records multiple calls" (let ((h (make-harness)) (interceptor (make-interceptor h "inc" (fn () "ok")))) (interceptor) (interceptor) (interceptor) (assert-equal 3 (len (get h "log")))))) (defsuite "io-queries" (deftest "io-call-count counts by operation" (let ((h (make-harness)) (f1 (make-interceptor h "fetch" (fn () nil))) (f2 (make-interceptor h "query" (fn () nil)))) (f1) (f2) (f1) (assert-equal 2 (io-call-count h "fetch")) (assert-equal 1 (io-call-count h "query")) (assert-equal 0 (io-call-count h "missing")))) (deftest "io-call-nth returns nth call entry" (let ((h (make-harness)) (f1 (make-interceptor h "fetch" (fn () nil)))) (f1) (f1) (assert-equal "fetch" (get (io-call-nth h "fetch" 0) "op")) (assert-equal "fetch" (get (io-call-nth h "fetch" 1) "op")) (assert-nil (io-call-nth h "fetch" 2))))) (defsuite "assertions" (deftest "assert-io-called passes when called" (let ((h (make-harness)) (f1 (make-interceptor h "fetch" (fn () nil)))) (f1) (assert-io-called h "fetch"))) (deftest "assert-io-called fails when not called" (let ((h (make-harness)) (result (try-call (fn () (assert-io-called h "fetch"))))) (assert-false (get result "ok")))) (deftest "assert-no-io passes when not called" (let ((h (make-harness))) (assert-no-io h "fetch"))) (deftest "assert-io-count verifies exact count" (let ((h (make-harness)) (f1 (make-interceptor h "fetch" (fn () nil)))) (f1) (f1) (assert-io-count h "fetch" 2))) (deftest "assert-state checks state bucket" (let ((h (make-harness))) (harness-set! h "cookies" "token-xyz") (assert-state h "cookies" "token-xyz")))))
