HS: cookie API (+3 tests, partial)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Three-part change: (a) tests/hs-run-filtered.js gets a per-test __hsCookieStore Map, a globalThis.cookies Proxy, and a document.cookie getter/setter that reads/writes the store. Per-test reset clears the store. (b) generate-sx-tests.py declares cookies in the test header and emits hand-rolled deftests for basic set / update / length-when-empty (the three tractable tests). (c) regenerated spec/tests/test-hyperscript-behavioral.sx via mcp_hs_test.regen. No .sx edits — `set cookies.foo to 'bar'` already compiles to (dom-set-prop cookies "foo" "bar") which routes through host-set!. Suite hs-upstream-expressions/cookies: 0/5 → 3/5. Smoke 0-195 unchanged at 170/195. Remaining `basic clear` (needs hs-method-call host-call dispatch) and `iterate` (needs hs-for-each host-array recognition) need runtime.sx edits — deferred to a future sx-tree worktree. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1832,6 +1832,36 @@ def generate_eval_only_test(test, idx):
|
||||
lines = []
|
||||
safe_name = sx_name(test['name'])
|
||||
|
||||
# Special case: cluster-33 cookie tests. Each test calls a sequence of
|
||||
# `_hyperscript("HS")` inside `page.evaluate(()=>{...})`. The runner backs
|
||||
# `cookies` with a Proxy over a per-test `__hsCookieStore` map (see
|
||||
# tests/hs-run-filtered.js). Tests handled: basic set, length-when-empty,
|
||||
# update. clear/iterate stay SKIP (need hs-method-call→host-call dispatch
|
||||
# and host-array iteration in hs-for-each — out of cluster-33 scope).
|
||||
if test['name'] == 'basic set cookie values work':
|
||||
return (
|
||||
f' (deftest "{safe_name}"\n'
|
||||
f' (hs-cleanup!)\n'
|
||||
f' (assert (nil? (eval-hs "cookies.foo")))\n'
|
||||
f' (eval-hs "set cookies.foo to \'bar\'")\n'
|
||||
f' (assert= (eval-hs "cookies.foo") "bar"))'
|
||||
)
|
||||
if test['name'] == 'update cookie values work':
|
||||
return (
|
||||
f' (deftest "{safe_name}"\n'
|
||||
f' (hs-cleanup!)\n'
|
||||
f' (eval-hs "set cookies.foo to \'bar\'")\n'
|
||||
f' (assert= (eval-hs "cookies.foo") "bar")\n'
|
||||
f' (eval-hs "set cookies.foo to \'doh\'")\n'
|
||||
f' (assert= (eval-hs "cookies.foo") "doh"))'
|
||||
)
|
||||
if test['name'] == 'length is 0 when no cookies are set':
|
||||
return (
|
||||
f' (deftest "{safe_name}"\n'
|
||||
f' (hs-cleanup!)\n'
|
||||
f' (assert= (eval-hs "cookies.length") 0))'
|
||||
)
|
||||
|
||||
# Special case: logAll config test. Body sets `_hyperscript.config.logAll = true`,
|
||||
# then mutates an element's innerHTML and calls `_hyperscript.processNode`.
|
||||
# Our runtime exposes this via hs-set-log-all! + hs-log-captured; we reuse
|
||||
@@ -2612,6 +2642,7 @@ output.append(';; Bind `window` and `document` as plain SX symbols so HS code th
|
||||
output.append(';; references them (e.g. `window.tmp`) can resolve through the host.')
|
||||
output.append('(define window (host-global "window"))')
|
||||
output.append('(define document (host-global "document"))')
|
||||
output.append('(define cookies (host-global "cookies"))')
|
||||
output.append('')
|
||||
output.append('(define hs-test-el')
|
||||
output.append(' (fn (tag hs-src)')
|
||||
|
||||
Reference in New Issue
Block a user