test: raise coverage to ~94% (target: 95)#23
Closed
mastermanas805 wants to merge 1 commit into
Closed
Conversation
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>
Member
Author
|
Superseded by #24, which included these commits and reached >=95% coverage. Merged to master. |
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.
Summary
test/client-unit.test.tscoveringsrc/client.tsedge 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 measurement note
Node's built-in
--experimental-test-coveragedoesn't cross-link two compile outputs. The unit tests import from../src/client.jswhichtsconfig.test.jsoncompiles todist-test/src/client.js, distinct from the productiondist/client.jsthatnpm run buildproduces and that the spawned-server integration suite exercises.dist/client.js(exercised by integration suite): 90.47% lines / 62.96% branches.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_ipswithoutprivate=true;private=truewith emptyallowed_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+AuthRequiredErrorconstructor field round-trip.Test plan
npm run build- cleannpm test- 87 tests pass (was 62)node --experimental-test-coverage --test ...- 93.71% on client.jsCo-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com