summaryrefslogtreecommitdiffstats
path: root/tests/tools.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tools.rs')
-rw-r--r--tests/tools.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/tools.rs b/tests/tools.rs
index a400df0..e54b5ff 100644
--- a/tests/tools.rs
+++ b/tests/tools.rs
@@ -434,3 +434,59 @@ fn validate_rejects_calls_that_cannot_run() {
434 // Empty content is how you create an empty file. 434 // Empty content is how you create an empty file.
435 assert!(validate("write", &json!({ "path": "a", "content": "" })).is_ok()); 435 assert!(validate("write", &json!({ "path": "a", "content": "" })).is_ok());
436} 436}
437
438#[test]
439fn bash_keeps_stderr_separate_from_stdout() {
440 let text = run(
441 "bash",
442 &json!({ "cmd": "printf 'out\\n'; printf 'err\\n' >&2; exit 2" }),
443 )
444 .unwrap();
445
446 assert!(text.contains("[stdout]"), "{text}");
447 assert!(text.contains("[stderr]"), "{text}");
448 assert!(text.contains("[exit 2]"), "{text}");
449 let stdout_at = text.find("[stdout]").unwrap();
450 let stderr_at = text.find("[stderr]").unwrap();
451 assert!(stdout_at < stderr_at, "{text}");
452 assert!(text.contains("out"), "{text}");
453 assert!(text.contains("err"), "{text}");
454}
455
456#[test]
457fn bash_stdout_alone_is_not_labelled() {
458 let text = run("bash", &json!({ "cmd": "echo hello" })).unwrap();
459 assert!(!text.contains("[stdout]"), "no label needed: {text}");
460 assert!(text.contains("hello"), "{text}");
461}
462
463#[test]
464fn bash_stderr_alone_is_labelled() {
465 let text = run("bash", &json!({ "cmd": "echo problem >&2" })).unwrap();
466 assert!(text.contains("[stderr]"), "{text}");
467 assert!(text.contains("problem"), "{text}");
468}
469
470#[test]
471fn bash_honours_a_per_call_timeout() {
472 let started = std::time::Instant::now();
473 let text = run(
474 "bash",
475 &json!({ "cmd": "sleep 5", "timeout_seconds": 1 }),
476 )
477 .unwrap();
478 assert!(text.contains("timed out after 1.0s"), "{text}");
479 assert!(started.elapsed() < std::time::Duration::from_secs(4));
480}
481
482#[test]
483fn bash_honours_a_per_call_output_budget() {
484 let text = run(
485 "bash",
486 &json!({ "cmd": "yes | head -c 200000", "max_bytes": 4096 }),
487 )
488 .unwrap();
489 assert!(text.contains("bytes omitted"), "{text}");
490 assert!(text.contains("output truncated"), "{text}");
491 assert!(text.len() < 10_000, "output was {} bytes", text.len());
492}