-
Notifications
You must be signed in to change notification settings - Fork 4.6k
acp: load configured extensions and refactor tests #6803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # This file is created automatically if no .gooseignore exists. | ||
| # Customize or uncomment the patterns below instead of deleting the file. | ||
| # Removing it will simply cause goose to recreate it on the next start. | ||
| # | ||
| # Suggested patterns you can uncomment if desired: | ||
| # **/.ssh/** # block SSH keys and configs | ||
| # **/*.key # block loose private keys | ||
| # **/*.pem # block certificates/private keys | ||
| # **/.git/** # block git metadata entirely | ||
| # **/target/** # block Rust build artifacts | ||
| # **/node_modules/** # block JS/TS dependencies | ||
| # **/*.db # block local database files | ||
| # **/*.sqlite # block SQLite databases | ||
| # | ||
|
|
||
| **/.env | ||
| **/.env.* | ||
| **/secrets.* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| // Required when compiled as standalone test "common"; harmless warning when included as module. | ||
| #![recursion_limit = "256"] | ||
| #![allow(unused_attributes)] | ||
|
|
||
| #[path = "../fixtures/mod.rs"] | ||
| pub mod fixtures; | ||
| use fixtures::{ | ||
| ExpectedSessionId, McpFixture, OpenAiFixture, PermissionDecision, Session, TestSessionConfig, | ||
| FAKE_CODE, | ||
| }; | ||
| use fs_err as fs; | ||
| use goose::config::base::CONFIG_YAML_NAME; | ||
| use goose::config::GooseMode; | ||
| use sacp::schema::{McpServer, McpServerHttp, ToolCallStatus}; | ||
|
|
||
| pub async fn run_basic_completion<S: Session>() { | ||
| let expected_session_id = ExpectedSessionId::default(); | ||
| let openai = OpenAiFixture::new( | ||
| vec![( | ||
| r#"</info-msg>\nwhat is 1+1""#.into(), | ||
| include_str!("../test_data/openai_basic_response.txt"), | ||
| )], | ||
| expected_session_id.clone(), | ||
| ) | ||
| .await; | ||
|
|
||
| let mut session = S::new(TestSessionConfig::default(), openai).await; | ||
| expected_session_id.set(session.id()); | ||
|
|
||
| let output = session | ||
| .prompt("what is 1+1", PermissionDecision::Cancel) | ||
| .await; | ||
| assert!(output.text.contains("2")); | ||
| expected_session_id.assert_matches(&session.id().0); | ||
| } | ||
|
|
||
| pub async fn run_mcp_http_server<S: Session>() { | ||
| let expected_session_id = ExpectedSessionId::default(); | ||
| let mcp = McpFixture::new(expected_session_id.clone()).await; | ||
| let openai = OpenAiFixture::new( | ||
| vec![ | ||
| ( | ||
| r#"</info-msg>\nUse the get_code tool and output only its result.""#.into(), | ||
| include_str!("../test_data/openai_tool_call_response.txt"), | ||
| ), | ||
| ( | ||
| format!(r#""content":"{FAKE_CODE}""#), | ||
| include_str!("../test_data/openai_tool_result_response.txt"), | ||
| ), | ||
| ], | ||
| expected_session_id.clone(), | ||
| ) | ||
| .await; | ||
|
|
||
| let config = TestSessionConfig { | ||
| mcp_servers: vec![McpServer::Http(McpServerHttp::new("lookup", &mcp.url))], | ||
| ..Default::default() | ||
| }; | ||
| let mut session = S::new(config, openai).await; | ||
| expected_session_id.set(session.id()); | ||
|
|
||
| let output = session | ||
| .prompt( | ||
| "Use the get_code tool and output only its result.", | ||
| PermissionDecision::Cancel, | ||
| ) | ||
| .await; | ||
| assert!(output.text.contains(FAKE_CODE)); | ||
| expected_session_id.assert_matches(&session.id().0); | ||
| } | ||
|
|
||
| pub async fn run_builtin_and_mcp<S: Session>() { | ||
| let expected_session_id = ExpectedSessionId::default(); | ||
| let prompt = | ||
| "Search for get_code and text_editor tools. Use them to save the code to /tmp/result.txt."; | ||
| let mcp = McpFixture::new(expected_session_id.clone()).await; | ||
| let openai = OpenAiFixture::new( | ||
| vec: string - Get the code"#.into(), | ||
| include_str!("../test_data/openai_builtin_execute.txt"), | ||
| ), | ||
| ( | ||
| r#"Successfully wrote to /tmp/result.txt"#.into(), | ||
| include_str!("../test_data/openai_builtin_final.txt"), | ||
| ), | ||
| ], | ||
| expected_session_id.clone(), | ||
| ) | ||
| .await; | ||
|
|
||
| let config = TestSessionConfig { | ||
| builtins: vec!["code_execution".to_string(), "developer".to_string()], | ||
| mcp_servers: vec![McpServer::Http(McpServerHttp::new("lookup", &mcp.url))], | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| let _ = fs::remove_file("/tmp/result.txt"); | ||
|
|
||
| let mut session = S::new(config, openai).await; | ||
| expected_session_id.set(session.id()); | ||
|
|
||
| let _ = session.prompt(prompt, PermissionDecision::Cancel).await; | ||
|
|
||
| let result = fs::read_to_string("/tmp/result.txt").unwrap_or_default(); | ||
| assert!(result.contains(FAKE_CODE)); | ||
| expected_session_id.assert_matches(&session.id().0); | ||
| } | ||
|
|
||
| pub async fn run_permission_persistence<S: Session>() { | ||
| let cases = vec![ | ||
| ( | ||
| PermissionDecision::AllowAlways, | ||
| ToolCallStatus::Completed, | ||
| "user:\n always_allow:\n - lookup__get_code\n ask_before: []\n never_allow: []\n", | ||
| ), | ||
| (PermissionDecision::AllowOnce, ToolCallStatus::Completed, ""), | ||
| ( | ||
| PermissionDecision::RejectAlways, | ||
| ToolCallStatus::Failed, | ||
| "user:\n always_allow: []\n ask_before: []\n never_allow:\n - lookup__get_code\n", | ||
| ), | ||
| (PermissionDecision::RejectOnce, ToolCallStatus::Failed, ""), | ||
| (PermissionDecision::Cancel, ToolCallStatus::Failed, ""), | ||
| ]; | ||
|
|
||
| let temp_dir = tempfile::tempdir().unwrap(); | ||
| let prompt = "Use the get_code tool and output only its result."; | ||
| let expected_session_id = ExpectedSessionId::default(); | ||
| let mcp = McpFixture::new(expected_session_id.clone()).await; | ||
| let openai = OpenAiFixture::new( | ||
| vec![ | ||
| ( | ||
| prompt.to_string(), | ||
| include_str!("../test_data/openai_tool_call_response.txt"), | ||
| ), | ||
| ( | ||
| format!(r#""content":"{FAKE_CODE}""#), | ||
| include_str!("../test_data/openai_tool_result_response.txt"), | ||
| ), | ||
| ], | ||
| expected_session_id.clone(), | ||
| ) | ||
| .await; | ||
|
|
||
| let config = TestSessionConfig { | ||
| mcp_servers: vec![McpServer::Http(McpServerHttp::new("lookup", &mcp.url))], | ||
| goose_mode: GooseMode::Approve, | ||
| data_root: temp_dir.path().to_path_buf(), | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| let mut session = S::new(config, openai).await; | ||
| expected_session_id.set(session.id()); | ||
|
|
||
| for (decision, expected_status, expected_yaml) in cases { | ||
| session.reset_openai(); | ||
| session.reset_permissions(); | ||
| let _ = fs::remove_file(temp_dir.path().join("permission.yaml")); | ||
| let output = session.prompt(prompt, decision).await; | ||
|
|
||
| assert_eq!( | ||
| output.tool_status.unwrap(), | ||
| expected_status, | ||
| "permission decision {:?}", | ||
| decision | ||
| ); | ||
| assert_eq!( | ||
| fs::read_to_string(temp_dir.path().join("permission.yaml")).unwrap_or_default(), | ||
| expected_yaml, | ||
| "permission decision {:?}", | ||
| decision | ||
| ); | ||
| } | ||
| expected_session_id.assert_matches(&session.id().0); | ||
| } | ||
|
|
||
| pub async fn run_configured_extension<S: Session>() { | ||
| let temp_dir = tempfile::tempdir().unwrap(); | ||
| let expected_session_id = ExpectedSessionId::default(); | ||
| let prompt = "Use the get_code tool and output only its result."; | ||
| let mcp = McpFixture::new(expected_session_id.clone()).await; | ||
|
|
||
| let config_yaml = format!( | ||
| "extensions:\n lookup:\n enabled: true\n type: streamable_http\n name: lookup\n description: Lookup server\n uri: \"{}\"\n", | ||
| mcp.url | ||
| ); | ||
| fs::write(temp_dir.path().join(CONFIG_YAML_NAME), config_yaml).unwrap(); | ||
|
|
||
| let openai = OpenAiFixture::new( | ||
| vec![ | ||
| ( | ||
| prompt.to_string(), | ||
| include_str!("../test_data/openai_tool_call_response.txt"), | ||
| ), | ||
| ( | ||
| format!(r#""content":"{FAKE_CODE}""#), | ||
| include_str!("../test_data/openai_tool_result_response.txt"), | ||
| ), | ||
| ], | ||
| expected_session_id.clone(), | ||
| ) | ||
| .await; | ||
|
|
||
| let config = TestSessionConfig { | ||
| data_root: temp_dir.path().to_path_buf(), | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| let mut session = S::new(config, openai).await; | ||
| expected_session_id.set(session.id()); | ||
|
|
||
| let output = session.prompt(prompt, PermissionDecision::Cancel).await; | ||
| assert!(output.text.contains(FAKE_CODE)); | ||
| expected_session_id.assert_matches(&session.id().0); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the new test