Files
Vincent Bourdon 9af114e391 Initial import
2026-06-09 16:14:55 +02:00

1.9 KiB

Task 0 — Backend injection seam + tempfile dev-dep

Index: README. Spec: design.

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
tempfile = "3"
  • Step 2: Replace the unit struct in src/tools/mod.rs
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
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
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
git add Cargo.toml src/tools/mod.rs src/main.rs
git commit -m "refactor: QuantumBridgeServer holds Arc<dyn Backend>; add tempfile dev-dep"