Repository navigation
Settle script output through one shared runtime policy - #147
Merged
Merged
Conversation
What a server or stream script's result becomes (printed, stripped of ANSI escapes, scoped to its component, refused when it is not markup, reported under scripts.onServerScriptError) was written three times: in the Node server, the Cloudflare Worker and the Netlify function, with a fourth copy in the custom adapter tutorial. Adding yielding scripts meant making the same edit in each. It now lives once, in pkg/src/lib/script-output-policy.ts, exported from @bascik/bascik/runtime as settleScriptOutput and scriptJobOutput. Each host passes a ScriptOutputPolicy naming only what is its own: where a warning goes, how a failure is described (Node maps the stack to the authored file; a function names the owner the build recorded), the error class it throws, and how it remembers a script's first refused value. No behavior changes. Characterization tests added to all three hosts before the change pin the exact bytes of a failure report, a refusal warning and stripped output, and pass unchanged after it. Also notes in the pre-push checklist that coverage-only commits can carry [skip ci]. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The commit before this one described the coverage-only convention and spelled the marker out in its message, so GitHub ran no workflow for that push. The pre-push checklist now says not to write it in any other commit's message. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Site PreviewsBuilt from f3b81d0 on
|
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.
Stacked on #146. The diff here is only the refactor; merge #146 first.
Why
What a server or stream script's result becomes was written three times, once per host, plus a fourth copy in the custom adapter tutorial:
serverScriptOutput)scripts.stripAnsiis offscripts.onServerScriptErrorto a failure, and drop a client abort silentlyBascik promises the same bytes from every host. With three copies, a fix to one can miss the others; #146 had to make the same edit in each.
What changed
pkg/src/lib/script-output-policy.ts, exported from@bascik/bascik/runtime:settleScriptOutput(result, yielded, policy)for one settled call or pullscriptJobOutput(invoked, policy)for a whole invocation, including a script that yieldsrunServerScriptJobOutput(Node), andrunGraphJobOutputin the Cloudflare and Netlify runtimes, now build aScriptOutputPolicyand call it. Their ownsettlefunctions, Node'srefusedReturnand Cloudflare'sscopeJobOutputare gone.productionisProdServer/isBuildtruewarnconsole.warnlogfirstRefusalSetkeyed by where the script startsWeakSetof jobsdescribeFailurecreateErrorServerScriptErrorErrorisSilentFailurescriptJobOutputcall. The runtime reference, package exports page, server internals page and changelog describe the new exports.No behavior change
Before touching any host I added characterization tests that pin current output byte for byte, ran them green on the old code, and kept them green:
ServerScriptErrorfor a failed call, a failed pull and a refused value; the dev refusal message with file and line; once-per-script warnings in production; a socket reset during a yield staying silent.The shared module has 42 tests of its own (printing, refusal in dev and production under each policy, failures, aborts, timeouts, a throwing
toString, yielding scripts, portability).Verification
Local, on this commit's code:
unit:all: pass in every workspace, including the Cloudflare adapter's Node-versus-workerd byte parity suiteNot verified locally:
Also in this branch
One line in the pre-push checklist: coverage-only commits can carry
[skip ci], and the PR should then be merged with a merge commit so a squash message does not skip the deploy onmain.🤖 Generated with Claude Code