Skip to content

test(wasm): run the worker's _lgStorage shim under node - #1093

Open
mparrett wants to merge 1 commit into
mainfrom
wt/storage-shim-test
Open

mparrett wants to merge 1 commit into
mainfrom
wt/storage-shim-test

Conversation

@mparrett

Copy link
Copy Markdown
Collaborator

Follow-up to #1080, whose review asked for a test of the _lgStorage shim.

TestWorkerStorageShim cuts workerCode out of the embedded lg-host-core.js and runs it under node with postMessage stubbed. It sends the worker an init carrying a two-key storage snapshot and a wasmExecJS that throws, so the worker stops after building _lgStorage and before any wasm loads. The test then checks:

  • length and key(i) order, including after an add, an overwrite, and a remove;
  • key past the end and getItem of a missing or removed key read null;
  • setItem stores String(v);
  • the storage-set and storage-remove messages relayed to the page, in order.

Since the test runs the shipped source, a change to the shim needs no matching change to a fixture. It skips when node is not on PATH.

Verification

  • go test ./pkg/rt/wasm/ passes.
  • With the keys = null reset on add removed from the shim, the test fails on the key order after the add.
  • GOOS=js GOARCH=wasm, linux, and plan9 builds pass.

🤖 Generated with Claude Code

Covers length, key order after an add and a remove, key past the end and
getItem of a missing key reading null, String coercion on setItem, and
the storage-set/storage-remove messages relayed to the page. The test
cuts workerCode out of the embedded lg-host-core.js, so it exercises the
shipped source; it skips when node is missing. Follow-up to #1080.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mparrett
mparrett requested a review from nooga October 22, 2026 04:55

@mparrett mparrett left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-check: No actionable findings.

The test exercises the shipped worker source rather than a duplicate shim, initializes the storage snapshot through the real init handler, and verifies key order/cache invalidation, missing-key nulls, value string coercion, and the relayed write/remove messages. Source extraction has explicit failure checks, and the Node subprocess is time-bounded. The PR changes no production behavior.

Validation at 90468cd: TestWorkerStorageShim ran under Node and passed (not skipped). I also temporarily removed the add-path key-cache invalidation in lg-host-core.js; the test failed on the after-add and after-overwrite key lists as expected. Restored the original source and confirmed no diff remained. Existing CI is green.

@mparrett
mparrett requested a review from nnunley October 22, 2026 21:47

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant