You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
2.2 KiB
Markdown
49 lines
2.2 KiB
Markdown
---
|
|
# quotesdb-aa9s
|
|
title: '[TRIAGE] Test harness: how to import and start quotesdb-api in tests (workers-rs vs native build target)'
|
|
status: completed
|
|
type: task
|
|
priority: critical
|
|
created_at: 2026-03-10T23:32:06Z
|
|
updated_at: 2026-03-10T23:32:06Z
|
|
---
|
|
|
|
<context>
|
|
This is a triage decision ticket. It must be resolved before dependent implementation tickets can proceed.
|
|
</context>
|
|
|
|
<question>
|
|
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?
|
|
</question>
|
|
|
|
<options>
|
|
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.
|
|
</options>
|
|
|
|
<decision>
|
|
**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.
|
|
</decision>
|
|
|
|
<commit>
|
|
`chore(quotesdb): resolve triage — test-harness-how-to-import-and-start-quotesdbapi-in-tests-wo`
|
|
</commit>
|