Skip to content

test: raise Vitest coverage above 75% across all metrics and fix RLS AST tests (#71) - #358

Open
dungfundopt wants to merge 1 commit into
outerbase:mainfrom
dungfundopt:test/improve-vitest-coverage-71
Open

dungfundopt wants to merge 1 commit into
outerbase:mainfrom
dungfundopt:test/improve-vitest-coverage-71

Conversation

@dungfundopt

Copy link
Copy Markdown

Summary

Brings project-wide Vitest coverage well above the 75% threshold across every metric (Statements, Branches, Functions, and Lines) with meaningful behavior/edge-case tests and zero failing suites:

  • Before (main): 4 failing tests in src/rls/index.test.ts; Coverage: Stmts 76.82%, Branches 47.68% (below 75% threshold), Funcs 82.10%, Lines 77.17%.
  • After: 22/22 test files passed (205/205 tests); Coverage: Stmts 94.82%, Branches 79.24%, Funcs 94.77%, Lines 95.13%.

Key Changes

  1. New test suites for previously uncovered modules (0% -> 96-100%):
    • src/allowlist/index.test.ts: Tests disabled mode, admin bypass, empty SQL guard, trailing-semicolon normalization, AST structural mismatches, rejection audit logging, and DB error recovery.
    • src/import/csv.test.ts: Tests empty body, unsupported Content-Type, raw text/csv, JSON-wrapped CSV with columnMapping, multipart/form-data upload/missing-file handling, partial row failures, and malformed JSON.
    • src/index.test.ts: Tests Worker fetch CORS preflight, missing/invalid auth tokens, admin/client/WebSocket auth, JWKS JWT verification & missing sub guard, pre-auth & InterfacePlugin routing, and external DB/Hyperdrive configuration.
  2. Expanded tests for core runtime modules:
    • src/operation.test.ts: Covers executeSDKQuery (PostgreSQL, MySQL, Cloudflare D1, Starbase, Turso, unsupported dialect), Hyperdrive paths, beforeQuery/afterQuery hooks, raw result transformations, and error recovery.
    • src/do.test.ts: Covers Durable Object RPC init(), alarms + failure recovery rescheduling, statistics, raw/parameterized queries, and WebSocket upgrade/message/broadcast/close flows.
    • src/handler.test.ts: Covers missing external config guard, invalid Content-Type/params/transaction validation, and handlePreAuth plugin route matching.
  3. Fixed broken RLS tests & AST traversal edge cases (src/rls/index.ts, src/rls/index.test.ts):
    • Fixed node-sql-parser subquery & CTE AST traversal (cte.stmt.ast / fromItem.expr.ast) and guarded subquery fromTable.table being undefined in applyRLSToAst.
    • Fixed shared mockConfig.role = 'admin' mutation leak across describe blocks in src/rls/index.test.ts and added tests for CTE, UNION, multi-statement, numeric policy values, and unauthorized action rejection.

Verification

pnpm vitest run --coverage
# Test Files  22 passed (22)
# Tests       205 passed (205)
# All files | 94.82% Stmts | 79.24% Branch | 94.77% Funcs | 95.13% Lines

/claim #71
Closes #71

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.

Improve test coverage with Vitest

1 participant