test(sandbox): cover managed process and computer-use APIs - #52
Merged
Merged
Conversation
src/sandbox.ts had drifted to 59.35% functions / 55.73% lines against the per-file 0.9 floor in bunfig.toml, so `bun test` exited 1 and took `prepublishOnly` — and therefore every publish — down with it. The file grew two whole sub-APIs (managed processes, computer-use) without tests. - tests/sandbox-processes.test.ts: 12-case wire-contract table over SandboxProcesses, plus stdin base64 encoding (UTF-8 and raw bytes), the btoa/atob fallback, and connect()'s NDJSON event union. - tests/sandbox-computer.test.ts: 43-case table across mouse, keyboard, windows, screens and desktop; screenshot raw bytes, region query, and the 404 error path. - tests/sandbox.test.ts: the ip/name getters. Each case asserts method, pathname, query, request body and the unwrapped result — not just line coverage. src/sandbox.ts is now 100/100; the floor in bunfig.toml is unchanged.
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.
Why
npm publishfails onmain. Not from a failing test —prepublishOnlyrunsbun run test, andbunfig.tomlenforces a per-file coverage floor of{ lines = 0.9, functions = 0.9 }.src/sandbox.tssat at 59.35% functions / 55.73% lines, sobun testexits 1 and blocks every publish.It drifted because the file grew to 1531 lines — two entire sub-APIs (managed processes, computer-use) landed without tests — while
tests/sandbox.test.tsstayed at 481. No CI workflow runs the unit suite onmain(onlyexamples), so nothing caught it.What
tests/sandbox-processes.test.ts(new, 297 l)SandboxProcesses;inputUTF-8→base64 andinputBytesraw bytes; thebtoa/atobfallback whenBufferis absent;connect()'s four NDJSON frame kindstests/sandbox-computer.test.ts(new, 521 l)screenshotraw PNG bytes, the six-key region query, and a 404 →CreateosSandboxNotFoundErrortests/sandbox.test.ts(+20 l)ip/namegettersEvery case asserts method + pathname + query + request body + unwrapped result, not just line coverage.
Result
src/sandbox.ts: 100% functions / 100% lines.bun run testexits 0 (257 pass, 0 fail).bunfig.tomluntouched — the floor was not lowered.Verification
bun run test(exit 0),bun run typecheck:tests,bun run lint— all clean.bun run fmt:checkstill flags exactly the same 5 pre-existing files asmain(examples/53,54,56,examples/manifest.json,src/sandbox.ts); left untouched.Follow-up, not in this PR
There is no CI job running the unit suite — that is why this rotted silently. Worth adding a workflow that runs
bun run test+typecheckon push/PR.src/sandbox.tsis also 1531 lines, past the repo's ~1100 cap; splitting the sub-APIs out is a separate refactor.