74 lines
1.9 KiB
Markdown
74 lines
1.9 KiB
Markdown
# Task 0 — Backend injection seam + tempfile dev-dep
|
|
|
|
> **Index:** [README](README.md). **Spec:** [design](../../specs/2026-04-29-quantum-tutor-design.md).
|
|
|
|
## Goal
|
|
|
|
Make `QuantumBridgeServer` hold `Arc<dyn Backend>` so the upcoming tutor tools depend on `&dyn Backend` (spec §3, CLAUDE.md §3). Existing v1 tools (`list_backends`, `validate_circuit`, `run_circuit`) are **not** refactored — they continue to construct their own `LocalSimulator`. Only the new path complies with DIP. Also add `tempfile` for sandboxed tests in later tasks.
|
|
|
|
## Prerequisites
|
|
|
|
None. This is the starting point.
|
|
|
|
## Files
|
|
|
|
- Modify: `Cargo.toml`
|
|
- Modify: `src/tools/mod.rs`
|
|
- Modify: `src/main.rs`
|
|
|
|
## Steps
|
|
|
|
- [ ] **Step 1: Add `tempfile` to `[dev-dependencies]` in `Cargo.toml`**
|
|
|
|
```toml
|
|
tempfile = "3"
|
|
```
|
|
|
|
- [ ] **Step 2: Replace the unit struct in `src/tools/mod.rs`**
|
|
|
|
```rust
|
|
use std::sync::Arc;
|
|
use crate::executor::{Backend, LocalSimulator};
|
|
|
|
#[derive(Clone)]
|
|
pub struct QuantumBridgeServer {
|
|
pub backend: Arc<dyn Backend>,
|
|
}
|
|
|
|
impl QuantumBridgeServer {
|
|
pub fn new(backend: Arc<dyn Backend>) -> Self {
|
|
Self { backend }
|
|
}
|
|
|
|
pub fn with_local_simulator() -> Self {
|
|
Self::new(Arc::new(LocalSimulator::new()))
|
|
}
|
|
}
|
|
```
|
|
|
|
The existing tool methods inside `#[tool_router(server_handler)] impl QuantumBridgeServer { ... }` are not modified.
|
|
|
|
- [ ] **Step 3: Update the construction in `src/main.rs`**
|
|
|
|
```rust
|
|
let service = QuantumBridgeServer::with_local_simulator()
|
|
.serve(stdio())
|
|
.await
|
|
.inspect_err(|e| tracing::error!("serving error: {:?}", e))?;
|
|
```
|
|
|
|
- [ ] **Step 4: Verify the existing test suite still passes**
|
|
|
|
```bash
|
|
cargo build && cargo test --lib 2>&1 | grep -E "test result|FAILED"
|
|
```
|
|
|
|
Expected: every existing suite green; the change is purely additive.
|
|
|
|
- [ ] **Step 5: Commit**
|
|
|
|
```bash
|
|
git add Cargo.toml src/tools/mod.rs src/main.rs
|
|
git commit -m "refactor: QuantumBridgeServer holds Arc<dyn Backend>; add tempfile dev-dep"
|
|
```
|