Skip to content

Testing

Pummelchen edited this page Sep 11, 2026 · 32 revisions

Home · Installation · Tools Reference · Architecture · Providers · Configuration · Reliability · Security · Testing · Troubleshooting · Project Tracker


Running the suite

swift test
Property Value
Tests 186 (plus 6 opt-in live tests)
Runtime ~6 seconds
External network not required
Warnings none, from a clean build

Hermeticity

End-to-end tests launch the real executable with a scrubbed environment: PATH plus their own explicit overrides, with every documented provider variable removed.

Without that scrub, an exported TAVILY_API_KEY — exactly what the installation guide tells a user to set — would make the stub-provider test contact the live vendor and fail. This was a real defect, so it is now verified rather than assumed:

TAVILY_API_KEY=tvly-fake BRAVE_SEARCH_API_KEY=brave-fake swift test

CI runs the whole suite a second time with credentials present for the same reason.


Layout

File Covers
CoreUnitTests URL canonicalization, configuration parsing, durations, logging
FusionAndReliabilityTests RRF fusion, deduplication, diversity capping, aggregator weighting, circuit breaker, rate limiter, cache
URLPolicyTests SSRF: schemes, loopback/private/metadata literals, DNS resolution, IP classification
HTMLExtractorTests Readable-text extraction, boilerplate removal, scraper parsing, challenge detection
HTTPClientTests Retry, Retry-After, idempotency, size limits, cancellation, Latin-1 fallback
ProviderContractTests Per-adapter contract and failure taxonomy
SearchOrchestratorTests Selection, fan-out, failover, timeouts, caching, domain filtering
StdioServerTests Real MCP handshake, tool schemas, tool calls, stdout purity
ErrorReportingTests Error attribution, explicit-provider fallback, post-error liveness
LiveProviderTests Opt-in. Real API calls; skipped unless a key is present

Transport tests use a real socket

LoopbackServer binds 127.0.0.1 and speaks HTTP/1.1, so retry, Retry-After, idempotency, size limits and cancellation are verified against real socket behaviour rather than against a mock that would encode the same assumptions as the client.


Provider contract

Every covered adapter must satisfy the same contract:

Expectation Assertion
Happy path Normalized results with valid URLs and ranks
401 / 403 Classified as authentication
429 Classified as rate_limited, with Retry-After parsed
5xx Classified as transient
Malformed body Clean malformed_response failure, never junk results
Cancellation Stops in-flight work
Credentials Never appear in logs or diagnostics

Covered: Tavily, Brave, Mojeek, Exa, SearXNG, DuckDuckGo. Gaps are recorded on the Project Tracker.


Determinism

CircuitBreaker, RateLimiter and SearchCache take an injectable Clock, so cooldown and expiry tests advance a TestClock instead of sleeping. Timeout tests use short budgets rather than real waits. Fusion ordering is fully deterministic, so ranking assertions are stable.


End-to-end smoke test

python3 scripts/mcp_smoke.py

A dependency-free client that drives the built binary through a real handshake and asserts that:

  1. initialize succeeds and reports the expected server identity;
  2. tools/list exposes exactly three tools with valid object schemas;
  3. web_search with no provider configured fails as an actionable tool error;
  4. every line written to stdout is valid JSON-RPC;
  5. diagnostics appear on stderr, never stdout.

It keeps stdin open until all replies have been read, which is what the stdio transport contract requires.


CI

.github/workflows/ci.yml runs on macos-26 (Xcode 26.x, Swift 6.3) for every push and pull request to main:

  1. swift build --build-tests
  2. swift test
  3. swift build -c release
  4. python3 scripts/mcp_smoke.py against the release binary
  5. swift test again with provider credentials present, proving hermeticity

The toolchain version is asserted before anything else, because a swift-tools-version: 6.3 manifest cannot even be parsed by an older Swift.


What CI has caught

Automation is not ceremony here: it found three defects that local builds had hidden.

  1. macos-14 ships Swift 5.10, which cannot parse the manifest.
  2. Package.swift declared a resource bundle for a directory git does not track, so a clean checkout failed to build while local builds passed.
  3. A trailing-defer warning that only a from-scratch build surfaced.

Live provider tests

swift test --filter LiveProviderTests

These call real APIs, so they are opt-in and skipped by default. They run only when TAVILY_API_KEY is present, either in the environment or in a git-ignored config.env at the package root.

They are written to be frugal with a metered free tier: fast mode, small result counts, and most assertions made against a single live response. The authentication path is covered with a deliberately invalid key, which costs no credits. Coverage:

Test What it proves Cost
Invalid key A rejected credential is classified as authentication, not transient free
Search Live results normalize correctly, with scores and sequential ranks 1 credit
Recency A recency filter returns dated results, so the filter is verifiable 1 credit
Orchestration Full path with fusion and a cache hit on the repeat query 1 credit
Thorough mode The advanced-depth mapping reaches the live service 2 credits
Status A live key reports ready and the payload never contains the key free

This suite exists because it found a defect the stub tests could not: Tavily's published_date silently decoded to nil, since the DTO maps keys explicitly while the adapter had been applying .convertFromSnakeCase, which rewrites the key before those mappings are consulted.

Not covered here

Live provider behaviour is non-deterministic and free tiers are metered. A scheduled live smoke test on CI is still open work on the Project Tracker.


Home · Installation · Tools Reference · Architecture · Providers · Configuration · Reliability · Security · Testing · Troubleshooting · Project Tracker

Clone this wiki locally