Sitelet https://github.com/NodeOps-app/createos-sandbox-sdk/pull/52
Skip to content

test(sandbox): cover managed process and computer-use APIs - #52

Merged
pratikbin merged 1 commit into
mainfrom
test/sandbox-coverage
Sep 9, 2026
Merged

pratikbin merged 1 commit into
mainfrom
test/sandbox-coverage

Conversation

@pratikbin

Copy link
Copy Markdown
Contributor

Why

npm publish fails on main. Not from a failing test — prepublishOnly runs bun run test, and bunfig.toml enforces a per-file coverage floor of { lines = 0.9, functions = 0.9 }. src/sandbox.ts sat at 59.35% functions / 55.73% lines, so bun test exits 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.ts stayed at 481. No CI workflow runs the unit suite on main (only examples), so nothing caught it.

What

file covers
tests/sandbox-processes.test.ts (new, 297 l) 12-case wire table over SandboxProcesses; input UTF-8→base64 and inputBytes raw bytes; the btoa/atob fallback when Buffer is absent; connect()'s four NDJSON frame kinds
tests/sandbox-computer.test.ts (new, 521 l) 43-case table across mouse / keyboard / windows / screens / desktop; screenshot raw PNG bytes, the six-key region query, and a 404 → CreateosSandboxNotFoundError
tests/sandbox.test.ts (+20 l) the ip / name getters

Every case asserts method + pathname + query + request body + unwrapped result, not just line coverage.

Result

src/sandbox.ts: 100% functions / 100% lines. bun run test exits 0 (257 pass, 0 fail). bunfig.toml untouched — the floor was not lowered.

Verification

bun run test (exit 0), bun run typecheck:tests, bun run lint — all clean. bun run fmt:check still flags exactly the same 5 pre-existing files as main (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 + typecheck on push/PR. src/sandbox.ts is also 1531 lines, past the repo's ~1100 cap; splitting the sub-APIs out is a separate refactor.

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.
@pratikbin
pratikbin merged commit 8f0863f into main Sep 9, 2026
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