+++
title = "[TRIAGE] Test harness: how to import and start quotesdb-api in tests (workers-rs vs native build target)"
priority = 9
status = "done"
ticket_type = "task"
dependencies = []
+++
This is a triage decision ticket. It must be resolved before dependent implementation tickets can proceed.
Test harness: how do we import and start the quotesdb-api binary in integration tests when it uses workers-rs, which targets the Cloudflare Workers runtime rather than a native Rust binary?
1. **Native feature flag** — add a `#[cfg(not(target_env = "worker"))]` branch in `main.rs` that exposes a plain Axum server. Integration tests use this branch (compiled for host target).
2. **Separate test binary** — create a `src/bin/api_test.rs` that is a native Axum server without workers-rs, used only in tests.
3. **Wrangler dev** — run `wrangler dev` in the background and point tests at it. Complex setup, slower CI.
**Option 1 variant: `cfg(target_arch = "wasm32")` split — no feature flag, no separate binary.**
The `cfg(target_arch)` approach in Cargo.toml means that when `cargo test` runs on the native
host, the workers-rs crate is never pulled in (it is a `[target.'cfg(target_arch = "wasm32")'.dependencies]`
entry). The native Axum server path compiles automatically.
Integration tests in `tests/` start the server by calling a `spawn_test_server()` helper that:
1. Opens an in-memory or temp-file rusqlite DB (via `NativeRepository`)
2. Calls `router::build_router(repo)` to get the Axum `Router`
3. Binds to a random port with `tokio::net::TcpListener::bind("127.0.0.1:0")`
4. Spawns the server with `tokio::spawn(axum::serve(listener, app))`
5. Returns `(base_url, shutdown_handle)`
No wrangler dev, no separate binary, no feature flags. Standard `cargo test` workflow.
Resolved as part of TRIAGE e8a330 and a91260 (cfg-split architecture decision).
See implementation ticket 00aff0 for the DB abstraction details and ticket 9b581f for the
test harness implementation.
`chore(quotesdb): resolve triage — test-harness-how-to-import-and-start-quotesdbapi-in-tests-wo`