diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/loop.rs | 60 | ||||
| -rw-r--r-- | tests/tools.rs | 13 |
2 files changed, 71 insertions, 2 deletions
diff --git a/tests/loop.rs b/tests/loop.rs index 7e6086f..73592f0 100644 --- a/tests/loop.rs +++ b/tests/loop.rs | |||
| @@ -483,7 +483,7 @@ fn a_wrong_argument_key_names_both_keys() { | |||
| 483 | "delta": { "tool_calls": [{ | 483 | "delta": { "tool_calls": [{ |
| 484 | "index": 0, | 484 | "index": 0, |
| 485 | "id": "call_wrong", | 485 | "id": "call_wrong", |
| 486 | "function": { "name": "bash", "arguments": "{\"command\":\"ls\"}" } | 486 | "function": { "name": "bash", "arguments": "{\"shell\":\"ls\"}" } |
| 487 | }]}, | 487 | }]}, |
| 488 | "finish_reason": "tool_calls" | 488 | "finish_reason": "tool_calls" |
| 489 | }] | 489 | }] |
| @@ -525,7 +525,63 @@ fn a_wrong_argument_key_names_both_keys() { | |||
| 525 | .expect("the turn should survive a wrong key"); | 525 | .expect("the turn should survive a wrong key"); |
| 526 | 526 | ||
| 527 | let result = history[3]["content"].as_str().unwrap(); | 527 | let result = history[3]["content"].as_str().unwrap(); |
| 528 | assert!(result.contains("`command`"), "should name what arrived: {result}"); | 528 | assert!(result.contains("`shell`"), "should name what arrived: {result}"); |
| 529 | assert!(result.contains("`cmd`"), "should name what was expected: {result}"); | 529 | assert!(result.contains("`cmd`"), "should name what was expected: {result}"); |
| 530 | assert!(!result.contains("denied"), "{result}"); | 530 | assert!(!result.contains("denied"), "{result}"); |
| 531 | } | 531 | } |
| 532 | |||
| 533 | #[test] | ||
| 534 | fn a_command_key_alias_runs_the_call() { | ||
| 535 | let dir = temp_dir("alias"); | ||
| 536 | let call = sse(&format!( | ||
| 537 | "data: {}\n\ndata: [DONE]\n\n", | ||
| 538 | json!({ | ||
| 539 | "choices": [{ | ||
| 540 | "delta": { "tool_calls": [{ | ||
| 541 | "index": 0, | ||
| 542 | "id": "call_alias", | ||
| 543 | "function": { "name": "bash", "arguments": "{\"command\":\"echo alias-ok\"}" } | ||
| 544 | }]}, | ||
| 545 | "finish_reason": "tool_calls" | ||
| 546 | }] | ||
| 547 | }) | ||
| 548 | )); | ||
| 549 | let final_round = sse( | ||
| 550 | "data: {\"choices\":[{\"delta\":{\"content\":\"done\"},\"finish_reason\":\"stop\"}]}\n\n\ | ||
| 551 | data: [DONE]\n\n", | ||
| 552 | ); | ||
| 553 | |||
| 554 | let base = serve_sequence(vec![call, final_round]); | ||
| 555 | std::env::set_var("AGENT686_DATA", dir.join("data")); | ||
| 556 | |||
| 557 | let system = agent::system_prompt(); | ||
| 558 | let mut session = Session::create("test-model", &system).unwrap(); | ||
| 559 | let cfg = Config { | ||
| 560 | base_url: base, | ||
| 561 | api_key: "test-key".into(), | ||
| 562 | model: "test-model".into(), | ||
| 563 | session: session.id.clone(), | ||
| 564 | yolo: true, | ||
| 565 | lenient: false, | ||
| 566 | system_ca: false, | ||
| 567 | provider: agent686::config::Provider::OpenCode, | ||
| 568 | allow_home: false, | ||
| 569 | allow_nogit: false, | ||
| 570 | }; | ||
| 571 | let mut history = agent::new_history(system); | ||
| 572 | let mut approver = Approver::new(true); | ||
| 573 | |||
| 574 | agent::run_turn( | ||
| 575 | &cfg, | ||
| 576 | &mut session, | ||
| 577 | &mut history, | ||
| 578 | "run it", | ||
| 579 | &AtomicBool::new(false), | ||
| 580 | &mut approver, | ||
| 581 | ) | ||
| 582 | .expect("the turn should succeed"); | ||
| 583 | |||
| 584 | let result = history[3]["content"].as_str().unwrap(); | ||
| 585 | assert!(result.contains("alias-ok"), "{result}"); | ||
| 586 | assert!(result.contains("[exit 0]"), "{result}"); | ||
| 587 | } | ||
diff --git a/tests/tools.rs b/tests/tools.rs index 4a8176e..0321bf8 100644 --- a/tests/tools.rs +++ b/tests/tools.rs | |||
| @@ -517,3 +517,16 @@ fn a_pipeline_that_exceeds_the_file_limit_is_reported() { | |||
| 517 | "should report the file limit: {text}" | 517 | "should report the file limit: {text}" |
| 518 | ); | 518 | ); |
| 519 | } | 519 | } |
| 520 | |||
| 521 | #[test] | ||
| 522 | fn bash_accepts_command_as_an_alias_for_cmd() { | ||
| 523 | use agent686::tools::validate; | ||
| 524 | |||
| 525 | assert!(validate("bash", &json!({ "command": "ls" })).is_ok()); | ||
| 526 | assert!(validate("bash", &json!({ "command": " " })).is_err()); | ||
| 527 | assert!(validate("bash", &json!({})).is_err()); | ||
| 528 | |||
| 529 | let text = run("bash", &json!({ "command": "echo alias-works" })).unwrap(); | ||
| 530 | assert!(text.contains("alias-works"), "{text}"); | ||
| 531 | assert!(text.contains("[exit 0]"), "{text}"); | ||
| 532 | } | ||
