repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

refactor: compress pass over mutant-killing tests

a5d32a1aa3457d9d476a2e4792f3a188a8252273

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (4)

+32 / −75 text lines

Diff layout

smith-ai/src/mux.rs

Modified

+18 / −52 text lines

185185 .unwrap()
186186 }
188 fn scripted(outcome: std::sync::Arc<std::sync::Mutex<Vec<Result<StreamEvent>>>>) -> StreamFn {
188 fn scripted(script: Vec<Result<StreamEvent>>) -> StreamFn {
189 let outcome = std::sync::Mutex::new(script);
189190 Arc::new(move |_request, _cancel| {
190191 let item = { outcome.lock().unwrap().remove(0) };
191192 futures::stream::iter(vec![item]).boxed()
192193 })
193194 }
196 /// The endpoint `name`, serving model `name` from `script` one item per call.
197 fn endpoint(name: &str, script: Vec<Result<StreamEvent>>) -> (String, Endpoint) {
198 (
199 name.to_string(),
200 Endpoint {
201 model: name.to_string(),
202 stream: scripted(script),
203 },
204 )
205 }
195207 fn request() -> ProviderRequest {
196208 ProviderRequest::new("plan", vec![Message::with_text(Role::User, "hi")])
197209 }
236248 primary_seen.fetch_add(1, Ordering::SeqCst);
237249 futures::stream::iter(vec![Err(rate_limit())]).boxed()
238250 });
239 let backup: StreamFn = {
240 let events = Arc::new(std::sync::Mutex::new(vec![Ok(StreamEvent::text_delta(
241 MessageId::new(),
242 "backup",
243 ))]));
244 scripted(events)
245 };
246251 let endpoints = HashMap::from([
247252 (
248253 "primary".to_string(),
251256 stream: primary,
252257 },
253258 ),
254 (
255 "backup".to_string(),
256 Endpoint {
257 model: "backup".to_string(),
258 stream: backup,
259 },
260 ),
259 endpoint("backup", vec![text("backup")]),
261260 ]);
262261 let router = Router::new(catalog(), endpoints, 2).unwrap();
263262 let stream = router
301300 for (faults, outcome, delays) in cases {
302301 let mut primary: Vec<Result<StreamEvent>> = faults.into_iter().map(Err).collect();
303302 primary.push(text("primary"));
304 let endpoint = |name: &str, script| {
305 (
306 name.to_string(),
307 Endpoint {
308 model: name.to_string(),
309 stream: scripted(Arc::new(std::sync::Mutex::new(script))),
310 },
311 )
312 };
313303 let endpoints = HashMap::from([
314304 endpoint("primary", primary),
315305 endpoint("backup", vec![text("backup")]),
334324 #[test]
335325 fn invalid_requests_fail_without_failover() {
336326 let endpoints = HashMap::from([
337 (
338 "primary".to_string(),
339 Endpoint {
340 model: "primary".to_string(),
341 stream: scripted(Arc::new(std::sync::Mutex::new(ok_stream()))),
342 },
343 ),
344 (
345 "backup".to_string(),
346 Endpoint {
347 model: "backup".to_string(),
348 stream: scripted(Arc::new(std::sync::Mutex::new(ok_stream()))),
349 },
350 ),
327 endpoint("primary", ok_stream()),
328 endpoint("backup", ok_stream()),
351329 ]);
352330 let router = Router::new(catalog(), endpoints, 2).unwrap();
353331 let mut invalid = request();
359337 #[test]
360338 fn exhausting_the_plan_surfaces_the_last_fault() {
361339 let endpoints = HashMap::from([
362 (
363 "primary".to_string(),
364 Endpoint {
365 model: "primary".to_string(),
366 stream: scripted(Arc::new(std::sync::Mutex::new(vec![Err(rate_limit())]))),
367 },
368 ),
369 (
370 "backup".to_string(),
371 Endpoint {
372 model: "backup".to_string(),
373 stream: scripted(Arc::new(std::sync::Mutex::new(vec![Err(rate_limit())]))),
374 },
375 ),
340 endpoint("primary", vec![Err(rate_limit())]),
341 endpoint("backup", vec![Err(rate_limit())]),
376342 ]);
377343 let router = Router::new(catalog(), endpoints, 2).unwrap();
378344 let err = route_err(&router, "plan", &request(), &CancelHandle::new());

smith-core/src/bash.rs

Modified

+10 / −12 text lines

285285 }
287287 #[test]
288 fn cancellation_stops_execution() {
289 let (res, mut socket) = cancel_once_raised(|raise| format!("{raise}; sleep 30"));
290 assert!(res.cancelled && !res.timed_out);
291 assert!(closed(&mut socket), "cancelled command kept running");
292 }
294 #[test]
295 fn cancellation_stops_a_command_that_closed_its_pipes() {
296 let (res, mut socket) =
297 cancel_once_raised(|raise| format!("exec >&- 2>&-; {raise}; sleep 30"));
298 assert!(res.cancelled && !res.timed_out);
299 assert!(closed(&mut socket), "cancelled command kept running");
288 fn cancellation_stops_execution_with_pipes_open_or_closed() {
289 for redirect in ["", "exec >&- 2>&-; "] {
290 let (res, mut socket) =
291 cancel_once_raised(|raise| format!("{redirect}{raise}; sleep 30"));
292 assert!(res.cancelled && !res.timed_out, "{redirect:?}");
293 assert!(
294 closed(&mut socket),
295 "cancelled command kept running: {redirect:?}"
296 );
297 }
300298 }
302300 /// User plus system CPU clock ticks spent by the calling thread.

smith-harness/src/runtime.rs

Modified

+1 / −3 text lines

228228 base_url: "https://example.test/v1".to_string(),
229229 model: "gpt-5.1".to_string(),
230230 },
231 workdir: dir.clone(),
232 session_path: dir.join("s.smh"),
233231 api_key: None,
234 auth_dir: dir.join("auth"),
232 ..RuntimeConfig::mock(&dir, Vec::new())
235233 };
236234 let Err(err) = build_agent(&config) else {
237235 unreachable!("no credential must fail assembly");

smith-harness/tests/http_effect.rs

Modified

+3 / −8 text lines

5555 data: [DONE]\n\n";
5656 let port = spawn_sse_server(sse);
58 let session_path = dir.join("session.smh");
5958 let config = RuntimeConfig {
6059 provider: RuntimeProvider::OpenAiCompatible {
6160 base_url: format!("http://127.0.0.1:{port}/v1"),
6261 model: "gpt-test".to_string(),
6362 },
64 workdir: dir.clone(),
65 session_path: session_path.clone(),
6663 api_key: Some("sk-integration-secret".to_string()),
67 auth_dir: dir.join("auth"),
64 ..RuntimeConfig::mock(&dir, Vec::new())
6865 };
6966 let mut agent = build_agent(&config).unwrap();
7067 let outcome = agent.run_turn("say it").unwrap();
7168 assert_eq!(outcome.text, "hello world");
73 let records = provider_http_records(&session_path);
70 let records = provider_http_records(&config.session_path);
7471 assert_eq!(records.len(), 2, "intent and outcome records");
7673 let intent = &records[0];
118115 base_url: "https://example.test".to_string(),
119116 model: "m".to_string(),
120117 },
121 workdir: dir.clone(),
122 session_path: dir.join("s.smh"),
123118 api_key: Some("sk-explicit".to_string()),
124 auth_dir: dir.join("auth"),
119 ..RuntimeConfig::mock(&dir, Vec::new())
125120 };
126121 let _agent = build_agent(&config).unwrap();
127122 let _ = std::fs::remove_dir_all(&dir);