Skip to content

test: improve coverage to meet 75% thresholds across all metrics - #291

Open
Ted8000 wants to merge 2 commits into
outerbase:mainfrom
Ted8000:test/issue-71-coverage
Open

test: improve coverage to meet 75% thresholds across all metrics#291
Ted8000 wants to merge 2 commits into
outerbase:mainfrom
Ted8000:test/issue-71-coverage

Conversation

@Ted8000

@Ted8000 Ted8000 commented Sep 8, 2026

Copy link
Copy Markdown

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: parseCSV used 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:

Metric Before After Threshold
Lines 77.17% 95.78% 75% ✅
Branches 47.68% 77.81% 75% ✅
Functions 82.10% 97.16% 75% ✅
Statements 76.82% 95.56% 75% ✅

/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 handling
  • src/do.advanced.test.ts (26 tests) — DurableObject: init() RPC surface, alarm get/set/delete (Date clamping, failure rethrow), getStatistics (with/without query log rows), fetch routes (/socket upgrade + non-upgrade, /socket/broadcast targeted + cleanup of dead connections, unknown ops), WebSocket lifecycle (message query actions, close with/without session tags), executeQuery raw vs object + params + failure rethrow, executeTransaction aggregation + failure, cron alarm() early exit / callback / recovery rescheduling paths
  • src/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 error
  • src/handler.advanced.test.ts (25 tests) — HTTP layer: 404 handler, OPTIONS preflight, /status/database + /status/trace, LiteREST routing, /query + /query/raw validation (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 via waitUntil, handlePreAuth authless 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 failure
  • src/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 rethrow

Verify

pnpm install
pnpm exec vitest run --coverage

All new tests pass (123 across 6 files). Coverage report shows all four metrics above 75% thresholds.

Note: src/rls/index.test.ts contains 4 pre-existing failures on main (SELECT queries with WHERE / JOIN conditions do not receive RLS policies — applyRLS returns the SQL unchanged). These failures are unrelated to this PR and reproduced on a clean checkout of main.

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

海砺 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.
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