Add tests for OpenAI helpers and retry logic#1547
Add tests for OpenAI helpers and retry logic#1547aibrahim-oai wants to merge 16 commits intomainfrom
Conversation
PR SummaryAdds a suite of unit tests (≈ 437 LoC) for Rust core:
ReviewNice boost to test coverage and confidence in critical request paths!
Overall, looks solid—just the small cleanup above and good to merge. |
bolinfest
left a comment
There was a problem hiding this comment.
I have a lot of comments, but I think none of these is review blocking, so please address before submitting.
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
| async fn assembles_messages_correctly() { | ||
| let server = MockServer::start().await; |
There was a problem hiding this comment.
Does this also need to check CODEX_SANDBOX_NETWORK_DISABLED_ENV_VAR?
|
|
||
| let body = capture.lock().unwrap().take().unwrap(); | ||
| let messages = body.get("messages").unwrap().as_array().unwrap(); | ||
| assert_eq!(messages[1]["role"], "user"); |
There was a problem hiding this comment.
Can we just do one assert_eq! on messages in its entirety? Or maybe &messages[1..]?
| } | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
There was a problem hiding this comment.
Please add a docstring explaining what is being tested.
| tokio::spawn(process_sse(stream, tx_event)); | ||
| Ok(ResponseStream { rx_event }) | ||
| } | ||
| #[cfg(test)] |
There was a problem hiding this comment.
Looks like you need just fmt.
| .unwrap(); | ||
| cfg.model_provider = provider.clone(); | ||
| cfg.model = "gpt-test".into(); | ||
| Arc::new(cfg) |
There was a problem hiding this comment.
Just FYI, codex_home will be deleted when this function exits, but that seems fine in this case.
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
| async fn retries_once_on_server_error() { |
There was a problem hiding this comment.
I think all of these tests would benefit from docstrings.
| let provider = ModelProviderInfo { | ||
| name: "openai".into(), | ||
| base_url: format!("{}/v1", server.uri()), | ||
| env_key: Some("PATH".into()), | ||
| env_key_instructions: None, | ||
| wire_api: WireApi::Responses, | ||
| query_params: None, | ||
| http_headers: None, | ||
| env_http_headers: None, | ||
| }; | ||
| let config = default_config(provider.clone()); | ||
| let client = ModelClient::new( | ||
| config, | ||
| provider, | ||
| ReasoningEffortConfig::None, | ||
| ReasoningSummaryConfig::None, | ||
| ); |
There was a problem hiding this comment.
Maybe use a helper function to dedupe common logic in tests?
|
|
||
| let tools = create_tools_json_for_responses_api(&prompt, "gpt-4").unwrap(); | ||
| assert_eq!(tools.len(), 2); | ||
| assert_eq!(tools[0]["type"], "function"); |
There was a problem hiding this comment.
Just one assert_eq! for all of tools[0]?
| assert!( | ||
| tools | ||
| .iter() | ||
| .any(|t| t.get("name") == Some(&name.clone().into())) |
There was a problem hiding this comment.
Maybe use find(|t| t.get("name").as_ref() == Some("srv.dummy") on tools.iter() or something like that and then do an assert_eq!() on the value returned from find()?
| ); | ||
| } | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
For both of these tests, can we just assert the entire string/serde_json::Value that we get back? I realize this means that we will have to update this test if we change the default tools, but I think having a test that verifies everything (and effectively documents what we send on the wire) is worth that maintenance cost.
…b/actions/codex (#1507) [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> chore(deps-dev): bump @types/bun from 1.2.13 to 1.2.18 in /.github/actions/codex (#1509) [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Add paste summarization to Codex TUI (#1549) - introduce `Paste` event to avoid per-character paste handling - collapse large pasted blocks to `[Pasted Content X lines]` - store the real text so submission still includes it - wire paste handling through `App`, `ChatWidget`, `BottomPane`, and `ChatComposer` - `cargo test -p codex-tui` ------ https://chatgpt.com/codex/tasks/task_i_6871e24abf80832184d1f3ca0c61a5ee https://github.com/user-attachments/assets/eda7412f-da30-4474-9f7c-96b49d48fbf8 addressing review addressing review addressing review Fix clippy docstring
61f28bc to
3d85eab
Compare
This reverts commit 75a1e4b.
Summary
ModelClientTesting
cargo clippy --workspace --all-targets -- -D warningscargo test --workspace --exclude codex-linux-sandboxhttps://chatgpt.com/codex/tasks/task_i_68717e8603a48321b875080ed3b70d63