test(backend): init/construct/runtime error-frame coverage#108
Open
gmaclennan wants to merge 2 commits into
Open
test(backend): init/construct/runtime error-frame coverage#108gmaclennan wants to merge 2 commits into
gmaclennan wants to merge 2 commits into
Conversation
Extract the init-payload validation into a pure `validateInit` helper and the fatal error-frame construction into `errorFrame`, then make `handleFatal`'s broadcast/sentry/exit deps injectable. Runtime behaviour is unchanged — the inline checks moved verbatim, and `handleFatal` defaults to the same module singletons. Add unit tests for the validators and spawn-based integration tests that drive a fake control-socket client to assert the process-level error frames and non-zero exit for the init, construct, and runtime phases. Wire the new top-level test file into the `node --test` runner. Closes #38 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR #36 added the rootkey handshake (
{type:"init",rootKey:"<base64>"}) and the structured error-frame broadcast on the control socket, butbackend/index.js's validation and fatal-handling logic was untested. This adds that coverage with a surgical, behaviour-preserving refactor.backend/lib/validate-init.mjs#validateInitthat returns either the 16-byteBufferor a structurederror. The inline checks moved verbatim;index.js'sinithandler now calls the helper.backend/lib/error-frame.mjs#errorFrameand madehandleFatal'sbroadcast/captureFatal/flush/exitdeps injectable (they default to the current module singletons, so runtime behaviour is unchanged).child_process.spawn-based integration tests that drive a fake control-socket client against the realloader.mjs->index.jsboot to assert the process-level error frames and non-zero exit.index.test.mjsinto thenode --testrunner (backend/package.jsontestscript).The refactor is kept minimal because
backend/index.jsis also touched by the in-flight Sentry work — this should merge before the Sentry PR (both touchbackend/index.js).Acceptance criteria (#38)
node --test; confirmed and extended to include the new top-levelindex.test.mjs."init"broadcast."construct"broadcast before exit."runtime"broadcast.Checks run
npm --prefix backend ci --ignore-scriptsthencd backend && node --test(andnpm test): 43 pass / 0 fail (35 pre-existing + 8 new acrossvalidate-init.test.mjsandindex.test.mjs).npm run types(backendtsc): my changes add no new errors. One pre-existing error remains —lib/install-polywasm.js(16): TS7016 'polywasm' has no declaration file— which is present on a pristineorigin/maincheckout (untouched file, missing@types) and unrelated to this PR.Not run locally
@comapeo/coreimporting under Node 24, which it does in this environment. CI runs the samenode --test.Closes #38
🤖 Generated with Claude Code