test: improve coverage to meet 75% thresholds across all metrics - #291
Open
Ted8000 wants to merge 2 commits into
Open
test: improve coverage to meet 75% thresholds across all metrics#291Ted8000 wants to merge 2 commits into
Ted8000 wants to merge 2 commits into
Conversation
added 2 commits
September 8, 2026 14:34
Adds comprehensive test suites for previously untested and undertested modules, raising global coverage from 77.17% lines / 47.68% branches to 95.74% lines / 77.47% branches (statements 95.51%, functions 97.15%). New test files: - src/index.test.ts: worker entrypoint (auth flows, JWT, data source configuration, region hints, error handling) - src/do.advanced.test.ts: DurableObject alarms, fetch routes, WebSocket lifecycle, raw/raw-less query execution, cron callback recovery - src/operation.advanced.test.ts: internal/hyperdrive/external query paths, Outerbase API param conversion, SDK connection factories, registry hooks, cache interactions - src/handler.advanced.test.ts: query/transaction route validation, export/import/rest/api routes, pre-auth plugin matching, cache expiry - src/import/csv.test.ts: CSV import content-type handling, mapping, partial failures - src/allowlist/index.test.ts: allowlist AST matching, rejection logging, error paths Note: 4 pre-existing failures in src/rls/index.test.ts (SELECT with WHERE / JOIN queries) exist on main and are unrelated to this change.
The naive comma split silently dropped rows whose values contained quoted commas (e.g. 1,"Doe, John") and corrupted doubled quotes. Replace it with a quote-aware splitter supporting RFC 4180 style escaping, and cover both cases with tests.
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.
Purpose
Resolves #71 — raise test coverage above the 75% thresholds on all metrics.
This PR adds comprehensive test suites for previously untested and undertested modules, plus one small bug fix surfaced while writing tests.
Bug fix:
parseCSVused a naive comma split, silently dropping rows with quoted values containing commas (e.g.1,"Doe, John") and mishandling escaped quotes. Replaced with a quote-aware splitter (RFC 4180 style: commas inside quotes are preserved,""unescapes to"), covered by two new tests.Global coverage before → after:
/claim #71
Tasks
src/index.test.ts(21 tests) — worker entrypoint: CORS preflight, admin/client token auth, JWT via JWKS (valid subject, missing subject), WebSocket token via query param, source header normalization (external/hyperdrive/internal), region location hints, pre-auth response, interface plugin routes, postgresql/mysql/d1/starbase/turso/hyperdrive external source configuration, error handlingsrc/do.advanced.test.ts(26 tests) — DurableObject:init()RPC surface, alarm get/set/delete (Date clamping, failure rethrow),getStatistics(with/without query log rows),fetchroutes (/socketupgrade + non-upgrade,/socket/broadcasttargeted + cleanup of dead connections, unknown ops), WebSocket lifecycle (message query actions, close with/without session tags),executeQueryraw vs object + params + failure rethrow,executeTransactionaggregation + failure, cronalarm()early exit / callback / recovery rescheduling pathssrc/operation.advanced.test.ts(27 tests) — query execution: internal RPC path, empty-result fallback, cache hit/skip/store, raw result transformation, registry before/after hooks (success + hook failure), Hyperdrive postgres pool (success, waitUntil cleanup, missing connection string, query failure), external path via Outerbase API (array param conversion, malformed responses), SDK connection factories for all five drivers + unsupported provider errorsrc/handler.advanced.test.ts(25 tests) — HTTP layer: 404 handler, OPTIONS preflight,/status/database+/status/trace, LiteREST routing,/query+/query/rawvalidation (content type, empty sql, invalid params), transaction validation (empty sql, invalid params), parse-failure 500, internal-source guards on export/import, all export/import routes,/api/*routing, cache expiration viawaitUntil,handlePreAuthauthless plugin matching (match, requiresAuth, missing pathPrefix)src/import/csv.test.ts(14 tests) — CSV import: unsupported content type, empty body, JSON-wrapped + raw + multipart file inputs, missing file, empty data, column-count mismatch skipping, column mapping, quoted values containing commas, escaped quotes, per-record failure reporting, generic error fallback, 500 on parse failuresrc/allowlist/index.test.ts(12 tests) — allowlist: disabled feature bypass, admin bypass, AST-equivalent matching, trailing-semicolon normalization, cross-source row filtering, rejection recording (statement + params), empty-SQL Error return, load failure, rejection-insert failure tolerance, partial-match and statement-type rejection, invalid SQL rethrowVerify
All new tests pass (123 across 6 files). Coverage report shows all four metrics above 75% thresholds.
Note:
src/rls/index.test.tscontains 4 pre-existing failures onmain(SELECT queries with WHERE / JOIN conditions do not receive RLS policies —applyRLSreturns the SQL unchanged). These failures are unrelated to this PR and reproduced on a clean checkout ofmain.Before
Baseline
main: lines 77.17%, branches 47.68%, functions 82.10%, statements 76.82% — branch coverage fails the 75% threshold.After
Lines 95.74%, branches 77.47%, functions 97.15%, statements 95.51% — all thresholds pass.
Demo video: https://github.com/Ted8000/starbasedb/releases/download/demo/starbasedb-demo.mp4