Skip to content

test(frontend): enforce 60% coverage floor + cover sdk-core/runtime.ts (#13) - #54

Merged
rawkode merged 1 commit into
mainfrom
issue-13-coverage-threshold
May 19, 2026
Merged

rawkode merged 1 commit into
mainfrom
issue-13-coverage-threshold

Conversation

@rawkode

@rawkode rawkode commented May 19, 2026

Copy link
Copy Markdown
Member

Final acceptance bullet on #13 ("Frontend tests"): enforce the 60% coverage floor so a regression that drops aggregate coverage fails CI.

Changes

`bunfig.toml` — `coverage = true` + `coverageThreshold = 0.6`. `bun test` exits non-zero if either lines or functions drop below 60% across the tested surface.

`packages/sdk-core/src/runtime.test.ts` — exhaustive coverage of `invokeOp`, the HTTP transport every generated extension client depends on:

Concern Cases
Request shaping default-null body, baseUrl override, URL-encoded segments, missing token
HTTP status mapping 400 / 401 / 403 / 404 / 409 / 503, 500 unmapped → `internal`
Transport failures fetch rejection (Error + non-Error), unparseable JSON body
Envelope precedence server-supplied `code` wins over status mapping, `path` surfaces

Coverage

  • Before: 84.85% funcs / 87.22% lines.
  • After: 90.28% funcs / 93.43% lines.
  • `runtime.ts` goes from 37.80% lines → 100%.
  • 89/89 tests pass.

#13 acceptance state after this PR

The two unchecked items genuinely depend on a DOM-layer swap (~2-3 hr of plumbing); ratcheting that into this PR would smuggle a test-infra refactor into a single-concern coverage-gate change.

Closes #13 partial; the SFC-rendering follow-up gets its own issue.

#13)

bunfig.toml now sets `coverage = true` + `coverageThreshold = 0.6`
so a regression that drops aggregate coverage below #13's 60%
acceptance bar fails `bun test` locally and in CI. `coverageReporter`
emits the existing `text` summary; `coverageSkipTestFiles` keeps
test files out of the floor calculation.

To prove the gate works against real surface area, runtime.test.ts
now exhaustively covers `invokeOp` — the HTTP transport every
generated extension client depends on:
- request shaping: default-null body, baseUrl override, URL-encoded
  path segments, missing-token branch
- error mapping per HTTP status: 400/401/403/404/409/503 and a
  500 fallback to `internal`
- fetch rejection (Error and non-Error throwable) → `unavailable`
- unparseable JSON error body falls back to text/statusText
- server-supplied `code` wins over status mapping
- server-supplied `path` is surfaced on the error envelope

Coverage post-change: 89/89 tests pass, aggregate **90.28% funcs
/ 93.43% lines** across the tested surface. runtime.ts goes from
37.80% → 100%. Bun's coverage gate exits non-zero if either drops
below 0.6, so CI catches future drift.

#13 acceptance bullets met
- [x] Minimum 60% line coverage on the tested surface — gate now
  enforced in bunfig.
- [x] Routing test covering /r/:groups+/:repo/... — PR #33.
- [x] CI fails when a touched page lacks a corresponding test
  update — page-test-coverage-gate.yml (PR #41).

Out of scope (separate follow-ups)
- Vue SFC component tests (Inbox, RepoHome, CommandPalette). happy-
  dom's Window doesn't ship Vue's SVG-namespace primitives, so a
  jsdom switch or @vue/test-utils integration is the next step.
- Extension UI smoke tests (ext_issues, ext_pull_requests). Same
  blocker as above.
Copilot AI review requested due to automatic review settings May 19, 2026 18:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a Bun test coverage gate for the frontend workspace and expands the @comtrya/sdk-core transport tests to fully exercise invokeOp (request shaping + error mapping), helping ensure coverage regressions fail CI and strengthening the SDK’s core HTTP contract.

Changes:

  • Enable Bun coverage collection and enforce an aggregate 60% coverage threshold in frontend/bunfig.toml.
  • Add a comprehensive invokeOp test suite covering status→error-code mapping, envelope precedence, transport failures, and URL/body/header shaping.
  • Reset SDK session state between tests to keep transport tests isolated.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
frontend/packages/sdk-core/src/runtime.test.ts Adds broad test coverage for invokeOp behavior (errors + request shaping) and resets session state between tests.
frontend/bunfig.toml Turns on Bun coverage and enforces a 60% aggregate coverage threshold for bun test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +205 to +211
test("missing token omits the Authorization header", async () => {
let headers: Record<string, string> | undefined;
globalThis.fetch = (async (_u, init?: RequestInit) => {
headers = init?.headers as Record<string, string>;
return new Response("null", { status: 200 });
}) as unknown as typeof fetch;
await invokeOp("ext", "i", "x");
@rawkode
rawkode added this pull request to the merge queue May 19, 2026
Merged via the queue into main with commit 209a6a5 May 19, 2026
16 of 17 checks passed
@rawkode
rawkode deleted the issue-13-coverage-threshold branch May 19, 2026 18:51
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.

[P2] Frontend tests: Vue components and routing coverage

2 participants