Add orchestration test suite: 17 tests for Phase 7c+7d
Tests cover page data cache, optimistic cache update/revert/confirm, offline connectivity tracking, offline queue mutation, and offline-aware routing. Registered in test runner with mocked platform functions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -143,6 +143,7 @@ SPECS = {
|
||||
"render": {"file": "test-render.sx", "needs": ["render-html"]},
|
||||
"deps": {"file": "test-deps.sx", "needs": []},
|
||||
"engine": {"file": "test-engine.sx", "needs": []},
|
||||
"orchestration": {"file": "test-orchestration.sx", "needs": []},
|
||||
}
|
||||
|
||||
REF_DIR = os.path.join(_HERE, "..", "ref")
|
||||
@@ -333,6 +334,65 @@ def _load_engine_from_bootstrap(env):
|
||||
eval_file("engine.sx", env)
|
||||
|
||||
|
||||
def _load_orchestration(env):
|
||||
"""Load orchestration.sx with mocked platform functions for testing.
|
||||
|
||||
Orchestration defines many browser-wiring functions (DOM, fetch, etc.)
|
||||
but the Phase 7c/7d tests only exercise the cache, optimistic, and
|
||||
offline functions. Lambda bodies referencing DOM/fetch are never called,
|
||||
so we only need to mock the functions actually invoked by the tests:
|
||||
now-ms, log-info, log-warn, execute-action, try-rerender-page.
|
||||
"""
|
||||
_mock_ts = [1000] # mutable so mock can advance time
|
||||
|
||||
def _mock_now_ms():
|
||||
return _mock_ts[0]
|
||||
|
||||
def _noop(*_a, **_kw):
|
||||
return NIL
|
||||
|
||||
def _mock_execute_action(action, payload, on_success, on_error):
|
||||
"""Mock: immediately calls on_success with payload as 'server truth'."""
|
||||
on_success(payload)
|
||||
return NIL
|
||||
|
||||
def _dict_delete(d, k):
|
||||
if isinstance(d, dict) and k in d:
|
||||
del d[k]
|
||||
return NIL
|
||||
|
||||
env["now-ms"] = _mock_now_ms
|
||||
env["log-info"] = _noop
|
||||
env["log-warn"] = _noop
|
||||
env["execute-action"] = _mock_execute_action
|
||||
env["try-rerender-page"] = _noop
|
||||
env["persist-offline-data"] = _noop
|
||||
env["retrieve-offline-data"] = lambda: NIL
|
||||
env["dict-delete!"] = _dict_delete
|
||||
# DOM / browser stubs (never called by tests, but referenced in lambdas
|
||||
# that the evaluator might try to resolve at call time)
|
||||
for stub in [
|
||||
"try-parse-json", "dom-dispatch", "dom-query-selector",
|
||||
"dom-get-attribute", "dom-set-attribute", "dom-set-text-content",
|
||||
"dom-append", "dom-insert-html-adjacent", "dom-remove",
|
||||
"dom-outer-html", "dom-inner-html", "dom-create-element",
|
||||
"dom-set-inner-html", "dom-morph", "dom-get-tag",
|
||||
"dom-query-selector-all", "dom-add-event-listener",
|
||||
"dom-set-timeout", "dom-prevent-default", "dom-closest",
|
||||
"dom-matches", "dom-get-id", "dom-set-id", "dom-form-data",
|
||||
"dom-is-form", "browser-location-href", "browser-push-state",
|
||||
"browser-replace-state", "sx-hydrate-elements", "render-to-dom",
|
||||
"hoist-head-elements-full", "url-pathname",
|
||||
]:
|
||||
if stub not in env:
|
||||
env[stub] = _noop
|
||||
|
||||
# Load engine.sx first (orchestration depends on it)
|
||||
_load_engine_from_bootstrap(env)
|
||||
# Load orchestration.sx
|
||||
eval_file("orchestration.sx", env)
|
||||
|
||||
|
||||
def _load_forms_from_bootstrap(env):
|
||||
"""Load forms functions (including streaming protocol) from sx_ref.py."""
|
||||
try:
|
||||
@@ -395,6 +455,8 @@ def main():
|
||||
_load_deps_from_bootstrap(env)
|
||||
if spec_name == "engine":
|
||||
_load_engine_from_bootstrap(env)
|
||||
if spec_name == "orchestration":
|
||||
_load_orchestration(env)
|
||||
|
||||
print(f"# --- {spec_name} ---")
|
||||
eval_file(spec["file"], env)
|
||||
|
||||
Reference in New Issue
Block a user