Skip to content

tests: cmd/cosift round-4 — fake fetcher + fake cluster#5

Merged
TeoSlayer merged 1 commit into
mainfrom
cosift-cmd-round4
May 28, 2026
Merged

tests: cmd/cosift round-4 — fake fetcher + fake cluster#5
TeoSlayer merged 1 commit into
mainfrom
cosift-cmd-round4

Conversation

@TeoSlayer
Copy link
Copy Markdown
Contributor

Summary

Round-4 coverage push for cmd/cosift. Lifts coverage from 50.5% (post-round-3) to 65.3% by extending the round-3 scaffolds (OpenAI httptest mock + populated Pebble fixture) with a fake peer cluster and whole-runner sweeps.

What's new

  • fakeCluster — array of httptest.Server peer shards. Drives scatterSearch + the four gateway handlers (handleSearchGateway, handleFindSimilarGateway, handleAnswerGateway, handleResearchGateway) end-to-end without spinning up real cosift instances.
  • Whole-runner sweeps for previously 0%-covered entries:
    • runServe — full lifecycle (free-port pick, /healthz round-trip, graceful shutdown) + the admin-token / trusted-proxies / chunker / defaults wiring branches + bad-CIDR error path.
    • runCrawl — sqlite + pebble backends, -seeds-file (happy + missing + comments/blanks), -duration, pre-cancelled ctx, unknown backend.
    • runEval-api short-circuit against a fake httptest endpoint (with -save), local-bm25 path against a synthesized corpus, unknown-retriever guard, dense-without-key guard.
    • runBench — vector / bm25 / storage / -json modes (tiny N so the suite stays fast).
    • runAnswerEval -dry-run + bad-key/bad-corpus/bad-queries guards.
    • runAnswerEvalCompare — multi-strategy diff with per-query moves, no-moves, wrong-arg, missing-baseline, missing-new paths.
    • runCrawlErrors (empty + custom-limit) and runVerifyPebble (local + via -server happy + drift + -json).
  • Direct unit tests for the iter-391 hnswPassageWriter bridge (UpsertPassage, UpsertPassageBatch, MarkURLInvalid + ctx-cancelled).
  • Eval-side retriever adapters via stub Retriever + stub ChatClient: hybridAdapter, rerankAdapter (happy / inner-err / single-URL short-circuit / rerank-err fallback / candidateK default), paraphraseRetriever (chat-err / main-weight / inner-err / cache hit), plannerRetriever (happy / chat-err / unparseable / cap-at-5), httpAPIRetriever (happy / non-200 / dial-err / bad JSON).
  • SSE coverage for streamAnswer + streamResearch via real httptest.NewServer (httptest.NewRecorder doesn't implement http.Flusher).
  • doRerank counter wrapper (happy + err) via a realFakeReranker that satisfies the real rerank.Reranker interface.
  • applyBM25EnvOverrides — valid / malformed / negative / unset.
  • Admin endpoint happy-path + non-auth branches not already covered by round 2 (handleCheckpoint, handleCrawlEnqueue happy/hook-err/bad-body, handleSitemapImport happy/bad-body/hook-err, handleFrontierPurgeHost happy/bad-body, handleSitePack bad-host/missing-host, handlePQTrain no-hnsw, handlePQEncode no-codebook, handleWETImportBulk bad-body/manifest-unreachable, handleCrawlNow empty-urls).

Test plan

  • go test -race -count=1 -timeout 180s ./cmd/cosift/... passes
  • Coverage 65.3% (baseline 50.5%) — verified via go tool cover -func=…
  • No production code modified — only cmd/cosift/zz_round4_test.go added (2061 LOC)
  • Builds on existing round-3 scaffolds (openaiTestServer, populatedPebbleStore, seedTinyStore, captureStdoutCosift); no duplicate test names with rounds 2 or 3

What's still gated

  • runReembed (16.2%), expandQuery (8.7%), handleEvalQuick (10.4%), handleEmbedBackfill (13.8%), handlePQTrain (12.9%), and the streaming-detail tails inside streamAnswer / streamResearch still have uncovered branches — most need either a working OpenAI key, a deep multi-step setup with passages persisted to disk, or the iter-402 in-serve crawler (startInProcessCrawl) which is currently entirely 0% and would require a substantial new fake-fetcher harness.
  • main() is unreachable from unit tests.
  • The four eval-internal adapter Search methods at main.go:2547 (denseAdapter), 2592 (rerankAdapter — partly covered), etc. — denseAdapter is still 0% because it requires a working Embedder; the mock embedder could be wired here in a follow-up round.

Lifts cmd/cosift coverage from 50.5% (post-round-3) to 65.3% by adding:

- fakeCluster: array of httptest peer shards for scatterSearch + the four
  gateway handlers (search / find_similar / answer / research)
- Whole-runner sweeps for runServe (with /healthz round-trip + graceful
  shutdown), runCrawl (sqlite + pebble + seeds-file + duration paths),
  runEval (-api short-circuit + local bm25 + unknown-retriever guards),
  runBench (vector/bm25/storage/json modes), runAnswerEval (-dry-run),
  runAnswerEvalCompare (multi-strategy diff + missing-file guards),
  runCrawlErrors, runVerifyPebble (local + via -server + drift)
- Direct unit tests for the iter-391 hnswPassageWriter bridge
- Direct unit tests for eval-side retriever adapters (hybridAdapter,
  rerankAdapter, paraphraseRetriever, plannerRetriever, httpAPIRetriever)
  via stub Retriever / stub ChatClient
- SSE coverage for streamAnswer + streamResearch via real httptest.Server
  (httptest.NewRecorder doesn't implement http.Flusher)
- doRerank counter wrapper (happy + error) via a realFakeReranker

All scaffolding builds on the round-3 openaiTestServer +
populatedPebbleStore fixtures from zz_round3_test.go. No production code
modified.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@TeoSlayer TeoSlayer merged commit 7de7e45 into main May 28, 2026
3 checks passed
@TeoSlayer TeoSlayer deleted the cosift-cmd-round4 branch May 28, 2026 16:49
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