Tests become directory modules named after what they test, with a shared fixtures/harness module:
control-plane/src/{responses,ggml_bridge,gguf_f32_stream,prepare_preview}/tests/, desktop-core/src/runtime_rpc/tests/;
integration targets become tests/<name>/main.rs plus topic modules and a harness (backend_worker_http, vision_http,
memory_gate_http, tool_corpus, mcp_hub, api_over_runtime, runtime_gateway_sdet, native_tools_sdet,
native_tools_retry_sdet, managed_worker, gateway); target names are unchanged. Sources: leleka-inference.rs becomes
src/bin/leleka-inference/ (main.rs plus one module per operator option group), the cp_replay example becomes
examples/cp_replay/, and the tonic service impl of runtime_rpc delegates to session_rpc, model_rpc and generate_rpc
(bodies unchanged). impl_* modules are renamed after what they hold (base_provenance, count_tokens, manifest_fetch,
fetcher, record, capture, in_flight, tool_policy, tool_plan, server). The self-spawning tests that name themselves
(credential_child, the managed worker fixture) use the new module path or stay at the target root.
Test ids: 543 before and after in both crates (strata-control, strata-desktop-core, --all-targets), 0 missing, 0 new,
0 outcome changes; 241 ids differ only in the module path. Warnings in the two crates: 0 before and after.
Counts (strata-control / strata-desktop-core): oversize files 19 -> 0 (13 + 6). Functions over 30 lines, complexity 10,
nesting 4, wide lines, prod: 187/135/17/199 -> 187/135/17/196 and 81/59/6/54 -> 81/59/6/54; test: 214/17/30/133 ->
214/17/30/133 and 65/3/3/30 -> 65/3/3/27. The 211 functions that moved verbatim are in limits-allowlist.json (owner
STRA-338) because the diff gate treats a moved function as added; the entries fall as the functions are shortened.
117 lines
3.8 KiB
Rust
117 lines
3.8 KiB
Rust
//! The control-plane stack the replay drives, started over the instant backend.
|
|
|
|
use super::*;
|
|
|
|
pub(super) struct Stack {
|
|
pub(super) addr: std::net::SocketAddr,
|
|
pub(super) marks: Arc<EngineMarks>,
|
|
pub(super) stop: watch::Sender<bool>,
|
|
pub(super) worker: tokio::task::JoinHandle<()>,
|
|
pub(super) server: tokio::task::JoinHandle<()>,
|
|
}
|
|
|
|
pub(super) async fn start_stack<F>(tokenizer_dir: &Path, make: &F) -> Stack
|
|
where
|
|
F: AsyncFn(Arc<EngineMarks>) -> Box<dyn Backend>,
|
|
{
|
|
let tokenizer = Arc::new(Tokenizer::from_assets(tokenizer_dir).expect("tokenizer assets"));
|
|
let marks = Arc::new(EngineMarks::default());
|
|
let backend = make(marks.clone()).await;
|
|
let config = BackendWorkerConfig {
|
|
tokenizer: tokenizer.clone(),
|
|
model: leleka_backend_api::scripted::ScriptedEngine::fixture_descriptor(),
|
|
runtime: RuntimeConfig {
|
|
load_config_version: leleka_backend_api::LOAD_CONFIG_VERSION,
|
|
inference_mode: InferenceMode::Native,
|
|
gpu_memory_limit_bytes: None,
|
|
allow_experimental: false,
|
|
},
|
|
max_context: 262_144,
|
|
max_output_tokens: 32768,
|
|
health_interval: Duration::from_secs(3600),
|
|
generation_timeout: None,
|
|
stall_timeout: None,
|
|
attach_retry: Duration::from_millis(20),
|
|
cancel_drain_timeout: Duration::from_secs(5),
|
|
prefix_view: None,
|
|
memory_view: None,
|
|
};
|
|
let status = Arc::new(RwLock::new(WorkerStatus::default()));
|
|
let (stop, stop_rx) = watch::channel(false);
|
|
let (requests, requests_rx) = mpsc::channel(8);
|
|
let (control, control_rx) = mpsc::channel(8);
|
|
let worker = tokio::spawn(run_backend_worker(
|
|
backend,
|
|
config,
|
|
status.clone(),
|
|
stop_rx,
|
|
requests_rx,
|
|
control_rx,
|
|
));
|
|
let state = AppState {
|
|
engine: EngineLink {
|
|
worker: status.clone(),
|
|
client: Some(strata_control::adapters::ChannelEngine::shared(requests)),
|
|
control: Some(control),
|
|
..Default::default()
|
|
},
|
|
model: ModelView {
|
|
name: Some("fixture".into()),
|
|
tokenizer: Some(Arc::new(strata_control::codec::qwen_codec_shared(
|
|
tokenizer.clone(),
|
|
))),
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
};
|
|
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
|
|
let addr = listener.local_addr().unwrap();
|
|
let app = router(state);
|
|
let server = tokio::spawn(async move {
|
|
use axum::serve::ListenerExt as _;
|
|
let listener = listener.tap_io(|tcp| {
|
|
let _ = tcp.set_nodelay(true);
|
|
});
|
|
let _ = axum::serve(listener, app).await;
|
|
});
|
|
tokio::time::timeout(Duration::from_secs(10), async {
|
|
while status.read().await.state != WorkerState::Ready {
|
|
tokio::time::sleep(Duration::from_millis(5)).await;
|
|
}
|
|
})
|
|
.await
|
|
.expect("worker ready");
|
|
Stack {
|
|
addr,
|
|
marks,
|
|
stop,
|
|
worker,
|
|
server,
|
|
}
|
|
}
|
|
|
|
impl Stack {
|
|
pub(super) async fn stop(self) {
|
|
let _ = self.stop.send(true);
|
|
let _ = tokio::time::timeout(Duration::from_secs(5), self.worker).await;
|
|
self.server.abort();
|
|
}
|
|
}
|
|
|
|
pub(super) struct Reply {
|
|
pub(super) status: u16,
|
|
pub(super) body_len: usize,
|
|
pub(super) t_sent: u64,
|
|
pub(super) t_first_byte: u64,
|
|
pub(super) t_created: u64,
|
|
pub(super) t_first_delta: u64,
|
|
pub(super) t_completed: u64,
|
|
pub(super) saw_function_call: bool,
|
|
pub(super) saw_completed: bool,
|
|
pub(super) sent_unix_ms: u128,
|
|
pub(super) done_unix_ms: u128,
|
|
/// `input_tokens` / `cached_tokens` of the terminal event's usage, when present.
|
|
pub(super) usage: (u64, u64),
|
|
pub(super) terminal: String,
|
|
}
|