signals.sx, engine.sx, orchestration.sx, boot.sx, router.sx, deps.sx, forms.sx, page-helpers.sx, adapters, boundary files → web/ Web tests → web/tests/ Test runners updated with _SPEC_TESTS and _WEB_TESTS paths. All 89 tests pass (20 signal + 43 CEK + 26 CEK reactive). Both bootstrappers build fully (5993 Python lines, 387KB JS). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
171 lines
6.4 KiB
Plaintext
171 lines
6.4 KiB
Plaintext
;; ==========================================================================
|
|
;; test-orchestration.sx — Tests for orchestration.sx Phase 7c + 7d
|
|
;;
|
|
;; Requires: test-framework.sx loaded first.
|
|
;; Platform functions mocked by test runner:
|
|
;; now-ms, log-info, log-warn, execute-action, try-rerender-page
|
|
;; ==========================================================================
|
|
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; 1. page-data-cache — basic cache operations
|
|
;; --------------------------------------------------------------------------
|
|
|
|
(defsuite "page-data-cache"
|
|
|
|
(deftest "cache-key bare page name"
|
|
(assert-equal "my-page" (page-data-cache-key "my-page" nil)))
|
|
|
|
(deftest "cache-key with params"
|
|
(let ((key (page-data-cache-key "my-page" {"id" "42"})))
|
|
(assert-equal "my-page:id=42" key)))
|
|
|
|
(deftest "cache-set then get"
|
|
(let ((key "test-cache-1"))
|
|
(page-data-cache-set key {"items" (list 1 2 3)})
|
|
(let ((result (page-data-cache-get key)))
|
|
(assert-equal (list 1 2 3) (get result "items")))))
|
|
|
|
(deftest "cache miss returns nil"
|
|
(assert-nil (page-data-cache-get "nonexistent-key"))))
|
|
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; 2. optimistic-cache-update — predicted mutation with snapshot
|
|
;; --------------------------------------------------------------------------
|
|
|
|
(defsuite "optimistic-cache-update"
|
|
|
|
(deftest "applies mutator to cached data"
|
|
(let ((key "opt-test-1"))
|
|
;; Seed the cache
|
|
(page-data-cache-set key {"count" 10})
|
|
;; Apply optimistic mutation
|
|
(let ((predicted (optimistic-cache-update key
|
|
(fn (data) (merge data {"count" 11})))))
|
|
(assert-equal 11 (get predicted "count")))))
|
|
|
|
(deftest "updates cache with prediction"
|
|
(let ((key "opt-test-2"))
|
|
(page-data-cache-set key {"count" 5})
|
|
(optimistic-cache-update key (fn (data) (merge data {"count" 6})))
|
|
;; Cache now has predicted value
|
|
(let ((cached (page-data-cache-get key)))
|
|
(assert-equal 6 (get cached "count")))))
|
|
|
|
(deftest "returns nil when no cached data"
|
|
(let ((result (optimistic-cache-update "no-such-key"
|
|
(fn (data) (merge data {"x" 1})))))
|
|
(assert-nil result))))
|
|
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; 3. optimistic-cache-revert — restore from snapshot
|
|
;; --------------------------------------------------------------------------
|
|
|
|
(defsuite "optimistic-cache-revert"
|
|
|
|
(deftest "reverts to original data"
|
|
(let ((key "revert-test-1"))
|
|
(page-data-cache-set key {"count" 10})
|
|
(optimistic-cache-update key (fn (data) (merge data {"count" 99})))
|
|
;; Cache now has 99
|
|
(assert-equal 99 (get (page-data-cache-get key) "count"))
|
|
;; Revert
|
|
(let ((restored (optimistic-cache-revert key)))
|
|
(assert-equal 10 (get restored "count"))
|
|
;; Cache is back to original
|
|
(assert-equal 10 (get (page-data-cache-get key) "count")))))
|
|
|
|
(deftest "returns nil when no snapshot"
|
|
(assert-nil (optimistic-cache-revert "never-mutated"))))
|
|
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; 4. optimistic-cache-confirm — discard snapshot
|
|
;; --------------------------------------------------------------------------
|
|
|
|
(defsuite "optimistic-cache-confirm"
|
|
|
|
(deftest "confirm clears snapshot"
|
|
(let ((key "confirm-test-1"))
|
|
(page-data-cache-set key {"val" "a"})
|
|
(optimistic-cache-update key (fn (data) (merge data {"val" "b"})))
|
|
;; Confirm — accepts the optimistic value
|
|
(optimistic-cache-confirm key)
|
|
;; Revert should now return nil (no snapshot)
|
|
(assert-nil (optimistic-cache-revert key))
|
|
;; Cache still has optimistic value
|
|
(assert-equal "b" (get (page-data-cache-get key) "val")))))
|
|
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; 5. offline-is-online? / offline-set-online! — connectivity tracking
|
|
;; --------------------------------------------------------------------------
|
|
|
|
(defsuite "offline-connectivity"
|
|
|
|
(deftest "initially online"
|
|
(assert-true (offline-is-online?)))
|
|
|
|
(deftest "set offline"
|
|
(offline-set-online! false)
|
|
(assert-false (offline-is-online?)))
|
|
|
|
(deftest "set back online"
|
|
(offline-set-online! true)
|
|
(assert-true (offline-is-online?))))
|
|
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; 6. offline-queue-mutation — queue entries when offline
|
|
;; --------------------------------------------------------------------------
|
|
|
|
(defsuite "offline-queue-mutation"
|
|
|
|
(deftest "queues an entry"
|
|
;; Seed cache so optimistic update works
|
|
(let ((key (page-data-cache-key "notes" nil)))
|
|
(page-data-cache-set key {"items" (list "a" "b")})
|
|
(let ((entry (offline-queue-mutation "add-note"
|
|
{"text" "c"}
|
|
"notes" nil
|
|
(fn (data) (merge data {"items" (list "a" "b" "c")})))))
|
|
(assert-equal "add-note" (get entry "action"))
|
|
(assert-equal "pending" (get entry "status")))))
|
|
|
|
(deftest "pending count increases"
|
|
;; Previous test queued 1 entry; count should be >= 1
|
|
(assert-true (> (offline-pending-count) 0))))
|
|
|
|
|
|
;; --------------------------------------------------------------------------
|
|
;; 7. offline-aware-mutation — routes by connectivity
|
|
;; --------------------------------------------------------------------------
|
|
|
|
(defsuite "offline-aware-mutation"
|
|
|
|
(deftest "when online calls submit-mutation path"
|
|
(offline-set-online! true)
|
|
(let ((key (page-data-cache-key "test-page" nil)))
|
|
(page-data-cache-set key {"v" 1})
|
|
;; This will trigger execute-action (mocked) which calls success cb
|
|
(let ((status nil))
|
|
(offline-aware-mutation "test-page" nil "do-thing" {"x" 1}
|
|
(fn (data) (merge data {"v" 2}))
|
|
(fn (s) (set! status s)))
|
|
;; Mock execute-action calls success immediately
|
|
(assert-equal "confirmed" status))))
|
|
|
|
(deftest "when offline queues mutation"
|
|
(offline-set-online! false)
|
|
(let ((key (page-data-cache-key "test-page-2" nil)))
|
|
(page-data-cache-set key {"v" 1})
|
|
(let ((status nil))
|
|
(offline-aware-mutation "test-page-2" nil "do-thing" {"x" 1}
|
|
(fn (data) (merge data {"v" 2}))
|
|
(fn (s) (set! status s)))
|
|
(assert-equal "queued" status)))
|
|
;; Clean up: go back online
|
|
(offline-set-online! true)))
|