Skip to content

test: add comprehensive test coverage for untested modules#103

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/analyze-test-coverage
Draft

test: add comprehensive test coverage for untested modules#103
Copilot wants to merge 2 commits intomasterfrom
copilot/analyze-test-coverage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

Summary

Analyzed the test coverage of the codebase, identified modules with missing or insufficient tests, and added comprehensive test cases to improve coverage.

Changes

New Test Files (9 files, ~1,400 lines of tests)

  • tests/adapters/il-dmv.test.ts – Illinois DMV adapter (14 cases): API key not configured, VERIFIED/NOT_FOUND/REVIEW paths, HTTP error handling (404, 500, network error), score clamping, custom IDSCAN_BASE_URL, stable license number hashing, null response.data fallback
  • tests/services/polygonMumbaiAnchor.test.ts – Polygon Mumbai anchor service (7 cases): missing env vars, chain ID mismatch, success path, deterministic nullifier hashing; ethers mocked via vi.mock
  • tests/verifiers/zkmlVerifier.test.ts – ZKML verifier (8 cases): invalid feature vector length, wrong element count, non-finite values (NaN, Infinity, -Infinity); covers ZkmlVerificationError class
  • tests/verifiers/halo2Bridge.test.ts – Halo2 bridge (11 cases): --tampered/--revoked flag passing, JSON output parsing, non-zero exit, missing JSON output, malformed JSON, last-line selection, spawn error propagation; child_process mocked
  • tests/verifiers/revocationVerifier.test.ts – Revocation verifier (9 cases): empty bundle hash, ok=true/false, flag passing, Error/non-Error wrapping, RevocationVerificationError class
  • tests/verifiers/zkProofVerifier.test.ts – ZK proof verifier (9 cases): same pattern, ZkProofVerificationError class
  • packages/core/src/receipt.test.ts – Receipt building (17 cases): computeInputsCommitment, computeReceiptHash, buildReceipt with all extensions (fraudRisk, zkpAttestation, signing_key_id), toUnsignedReceiptPayload, canonical key ordering
  • packages/core/src/attom/normalize.test.ts – Normalization utilities (48 cases): normalizePin, normalizeAddress, addressSimilarity, normalizeName, tokenOverlap, nameOverlapScore, canonicalDeedHash, redact — including edge cases for null/undefined/falsy inputs
  • packages/core/src/anchor/portable.test.tsPortableAnchorManager (7 cases): anchor via active provider, verify active/historical proofs, chain switching, history accumulation across multiple switches, unknown chain error

Extended Existing Tests

  • tests/api/routes.test.ts – Added 5 cases:
    • notary_present: false covers the 0 branch in toFeatureVector
    • Non-Error rejection in verify route covers String(error) branch
    • Error instance in status lookup covers error.message branch
    • is_admin: true JWT claim tests the payload.is_admin branch in hasAdminClaim
    • buildApiServer without LOG_LEVEL set covers the ?? 'info' fallback in app.ts

Updated vitest.config.ts

Expanded coverage reporting to include newly tested source files:

  • src/verifiers/revocationVerifier.ts, src/verifiers/zkProofVerifier.ts
  • src/services/**/*.ts, src/adapters/**/*.ts
  • packages/core/src/receipt.ts, packages/core/src/attom/normalize.ts, packages/core/src/anchor/portable.ts

Coverage Results

Metric Before After
Statements 99.34% 99.62%
Branch 93.33% 97.81%
Functions 100% 100%
Lines 99.34% 99.62%

File-level highlights (branch coverage)

File Before After
src/routes/verify.ts 85.71% 100%
src/routes/status.ts 88.88% 100%
src/routes/app.ts 50% 100%
src/adapters/registries/il-dmv.ts not tracked 100%
src/services/polygonMumbaiAnchor.ts not tracked 100%
src/verifiers/revocationVerifier.ts not tracked 100%
src/verifiers/zkProofVerifier.ts not tracked 100%
packages/core/src/receipt.ts not tracked 100%
packages/core/src/attom/normalize.ts not tracked 97.67%
packages/core/src/anchor/portable.ts not tracked 100%

Remaining Uncovered Branches (all are dead/unreachable code)

  • normalize.ts:57union === 0 in tokenOverlap is unreachable; the early-return guard on empty arrays fires first
  • logger.ts:54?? Date.now() fallback requires onRequest hook not to run (impossible in practice)
  • rateLimit.ts:21DEFAULT_RETRY_AFTER_SECONDS requires @fastify/rate-limit to emit a non-finite context.after value
  • revoke.ts:17-18!payload guard requires JWT middleware to set request.user = undefined (unreachable via HTTP)

Validation

  • ✅ 209 tests pass, 3 pre-existing E2E skips (require running DB or special env)
  • ✅ Code review: no comments
  • ✅ CodeQL: 0 alerts
  • ✅ All coverage thresholds (90%) satisfied

Copilot AI and others added 2 commits April 6, 2026 03:22
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
trustsignal Error Error Apr 6, 2026 3:36am

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