-
Notifications
You must be signed in to change notification settings - Fork 6.3k
chore(core) Consolidate apply_patch tests #6545
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,29 @@ use tempfile::TempDir; | |
| use wiremock::MockServer; | ||
|
|
||
| use crate::load_default_config_for_test; | ||
| use crate::responses::ev_apply_patch_custom_tool_call; | ||
| use crate::responses::ev_apply_patch_function_call; | ||
| use crate::responses::ev_apply_patch_shell_call; | ||
| use crate::responses::ev_apply_patch_shell_call_via_heredoc; | ||
| use crate::responses::ev_assistant_message; | ||
| use crate::responses::ev_completed; | ||
| use crate::responses::ev_response_created; | ||
| use crate::responses::mount_sse_sequence; | ||
| use crate::responses::sse; | ||
| use crate::responses::start_mock_server; | ||
| use crate::wait_for_event; | ||
|
|
||
| type ConfigMutator = dyn FnOnce(&mut Config) + Send; | ||
|
|
||
| /// A collection of different ways the model can output an apply_patch call | ||
| #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
| pub enum ApplyPatchModelOutput { | ||
| Freeform, | ||
| Function, | ||
| Shell, | ||
| ShellViaHeredoc, | ||
| } | ||
|
|
||
| pub struct TestCodexBuilder { | ||
| config_mutators: Vec<Box<ConfigMutator>>, | ||
| } | ||
|
|
@@ -258,6 +276,48 @@ impl TestCodexHarness { | |
| .expect("output string") | ||
| .to_string() | ||
| } | ||
|
|
||
| pub async fn mount_apply_patch_call( | ||
| &self, | ||
| call_id: &str, | ||
| patch: &str, | ||
| assistant_msg: &str, | ||
| output_type: ApplyPatchModelOutput, | ||
| ) { | ||
| let ev_fn = match output_type { | ||
| ApplyPatchModelOutput::Freeform => ev_apply_patch_custom_tool_call, | ||
| ApplyPatchModelOutput::Function => ev_apply_patch_function_call, | ||
| ApplyPatchModelOutput::Shell => ev_apply_patch_shell_call, | ||
| ApplyPatchModelOutput::ShellViaHeredoc => ev_apply_patch_shell_call_via_heredoc, | ||
| }; | ||
|
|
||
| let responses = vec![ | ||
| sse(vec![ | ||
| ev_response_created("resp-1"), | ||
| ev_fn(call_id, patch), | ||
| ev_completed("resp-1"), | ||
| ]), | ||
| sse(vec![ | ||
| ev_assistant_message("msg-1", assistant_msg), | ||
dylan-hurd-oai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ev_completed("resp-2"), | ||
| ]), | ||
| ]; | ||
|
|
||
| mount_sse_sequence(self.server(), responses).await; | ||
| } | ||
|
|
||
| pub async fn get_patch_output( | ||
dylan-hurd-oai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| &self, | ||
| call_id: &str, | ||
| output_type: ApplyPatchModelOutput, | ||
| ) -> String { | ||
| match output_type { | ||
| ApplyPatchModelOutput::Freeform => self.custom_tool_call_output(call_id).await, | ||
| ApplyPatchModelOutput::Function | ||
| | ApplyPatchModelOutput::Shell | ||
| | ApplyPatchModelOutput::ShellViaHeredoc => self.function_call_stdout(call_id).await, | ||
| } | ||
| } | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it's not ideal to expand the scope of the harness, but this felt significantly simpler than introducing async function type signatures / closures in the |
||
| } | ||
|
|
||
| fn custom_tool_call_output<'a>(bodies: &'a [Value], call_id: &str) -> &'a Value { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.