Skip to content

test: raise coverage to ~94% (target: 95)#23

Closed
mastermanas805 wants to merge 1 commit into
masterfrom
coverage/raise-to-95
Closed

test: raise coverage to ~94% (target: 95)#23
mastermanas805 wants to merge 1 commit into
masterfrom
coverage/raise-to-95

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

Summary

  • Adds 25 new unit tests in test/client-unit.test.ts covering src/client.ts edge branches that the in-process integration suite does not exercise: fetch network errors, non-JSON response coercion, empty-2xx safe sentinels, requireAuth gating, multipart create_deploy client-side validation, ApiError envelope field bubbling.
  • Coverage on the unit-test compile tree: client.js 93.71% lines / 76.77% branches / 68.97% funcs. Test count: 62 -> 87, all passing.

Coverage measurement note

Node's built-in --experimental-test-coverage doesn't cross-link two compile outputs. The unit tests import from ../src/client.js which tsconfig.test.json compiles to dist-test/src/client.js, distinct from the production dist/client.js that npm run build produces and that the spawned-server integration suite exercises.

  • Production dist/client.js (exercised by integration suite): 90.47% lines / 62.96% branches.
  • Test-tree dist-test/src/client.js (exercised by these new unit tests): 93.71% lines / 76.77% branches.

The logical coverage of src/client.ts (the source of truth for both compiled copies) is now ~94%. To make the canonical coverage number reflect the unit tests, the integration test runner would need to import the same fetch-stubbed paths, OR the test compile target could be unified - left as follow-up.

Branches covered (uncovered before this PR)

  • request<T>(): network error -> ApiError(0); non-JSON 2xx body; non-JSON non-2xx body; empty-2xx safe sentinel; requireAuth gating.
  • requestMultipart<T>(): same four paths.
  • createDeploy(): oversized tarball client-side reject; allowed_ips without private=true; private=true with empty allowed_ips; JSON error envelope with all five fields (code, message, upgrade_url, agent_action, claim_url).
  • dashboardURL() + apiBaseURL(): env-var-fresh reads + trailing slash stripping.
  • getApiToken(): default name "instanode-mcp" vs supplied name.
  • createVector(): dimensions field passthrough + omission.
  • ApiError + AuthRequiredError constructor field round-trip.

Test plan

  • npm run build - clean
  • npm test - 87 tests pass (was 62)
  • node --experimental-test-coverage --test ... - 93.71% on client.js
  • CI green

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

Adds 1 test file with 25 unit tests covering src/client.ts edge branches:
  - fetch network-error path (ApiError(0))
  - non-JSON 2xx + non-2xx response body coercion
  - empty-2xx safe sentinel (redeploy + multipart)
  - requireAuth gating without INSTANODE_TOKEN
  - createDeploy client-side validation (oversized tarball, allowed_ips
    without private=true, private without allowed_ips)
  - ApiError envelope field bubbling (agent_action, upgrade_url, claim_url)
  - dashboardURL / apiBaseURL env-var-fresh reads
  - createVector dimensions hint passthrough
  - getApiToken default + supplied name handling

Coverage (measured on the test-compiled copy at dist-test/src/client.js,
since the test compile tree is what the unit tests import — node's coverage
reporter does not cross-link the two compile outputs):
  client.js: 93.71% lines / 76.77% branches / 68.97% funcs

The production-built dist/client.js (exercised separately by the
integration suite) remains at 90.47% lines / 62.96% branches — these
unit tests increase the *logical* coverage to ~94% but the dist/ count
will need test/integration.test.ts to import the unit-level paths to
reflect in the canonical report.

Test count: 62 → 87 (all passing).

Remaining gap: src/index.ts is at 92.29% lines — uncovered lines are
mostly tool-handler error-formatting branches that fire only on rare
API error envelopes (PAT-creating-PAT 403, anonymous-recycle 429, etc.)
and are caught structurally by the existing mock-api integration tests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mastermanas805
Copy link
Copy Markdown
Member Author

Superseded by #24, which included these commits and reached >=95% coverage. Merged to master.

@mastermanas805 mastermanas805 deleted the coverage/raise-to-95 branch May 22, 2026 02:11
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.

2 participants