Skip to content

test: add unit tests for chat_completions translation module#234

Open
leseb wants to merge 2 commits into
praxis-proxy:mainfrom
leseb:leseb/fix-issue-231
Open

test: add unit tests for chat_completions translation module#234
leseb wants to merge 2 commits into
praxis-proxy:mainfrom
leseb:leseb/fix-issue-231

Conversation

@leseb

@leseb leseb commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds 64 new unit tests (87 total) for apis/src/openai/translation/chat_completions.rs, covering all major code paths
  • Tests span ResponseContext construction, request translation (messages, content parts, tools, tool_choice, text format, reasoning), and response translation (finish reasons, usage, service tier, tool calls, refusals, logprobs, full resource shape)

Test areas covered

Area Tests added
ResponseContext construction & defaults 4
Request: message edge cases 5
Request: content part handling 5
Request: function call serialization 5
Request: tool definitions 3
Request: tool_choice variants 5
Request: text format / reasoning 5
Response: finish reasons & status 3
Response: completed_at behavior 2
Response: empty/no choices 4
Response: content + refusal 5
Response: usage tokens 3
Response: service tier fallbacks 3
Response: tool call output items 2
Response: full resource shape & defaults 6
Response: non-object error 1
Response: message item id & annotations 2

Resolves #231

Test plan

  • All 87 tests pass (cargo test --lib -p praxis-ai-apis -- translation::tests)
  • No clippy warnings

@leseb leseb requested review from a team and aslakknutsen July 2, 2026 07:44
@leseb leseb requested a review from shaneutt as a code owner July 2, 2026 07:44
@praxis-bot-app

praxis-bot-app Bot commented Jul 2, 2026

Copy link
Copy Markdown

Missing Signed-off-by: ddf4e41. All commits require sign-off (via git commit --signoff).

@praxis-bot-app

praxis-bot-app Bot commented Jul 2, 2026

Copy link
Copy Markdown

PR too large: 1211 lines added (limit: 750, excludes Cargo files, tests, docs, examples, and benchmarks). Please split into smaller PRs. Add skip/pr-conventions label to override.

Cover ResponseContext construction/defaults, request translation edge
cases (empty instructions, content part collapse, function call
serialization, tool definitions, tool_choice variants, text format,
reasoning), and response translation edge cases (finish reasons,
completed_at, empty/null content, refusals, array content parts,
logprobs attachment, usage token details, service tier fallbacks,
tool call output items, full response resource shape).

Resolves praxis-proxy#231

Signed-off-by: Sébastien Han <seb@redhat.com>
// -------------------------------------------------------------------------

#[test]
fn empty_instructions_do_not_produce_system_message() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicates simple_inputs_map_or_drop_cleanly

"input": [{"foo": "bar"}]
}));

assert!(error.contains("unknown"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both UnsupportedInputItemType and UnsupportedContentPartType could be caught by "unknown", intentional?

@praxis-bot praxis-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review: test: add unit tests for chat_completions translation module

One-line summary: Thorough, well-structured test suite with two convention adjustments needed.

Overall assessment

This PR adds 64 well-organized unit tests covering ResponseContext construction, request translation edge cases (messages, content parts, function calls, tools, tool_choice, text format, reasoning), and response translation paths (finish reasons, usage, service tier, tool calls, refusals, logprobs, resource shape). The tests correctly verify both happy-path and edge-case behavior, use no doc comments on test functions, avoid inline comments in test bodies, and consistently use to_owned() for &str conversions. Two convention issues should be fixed.

Findings

# Severity Location Finding
1 Medium mod.rs:675 Separator comments use 73 dashes instead of 77
2 Medium mod.rs:1204 Test utility functions placed mid-module instead of at the end

);
}

// -------------------------------------------------------------------------

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Medium] Separator comments inside the test module use 73 dashes (total width 80 including indent), but the convention requires 77 dashes regardless of nesting depth. The implementation file (chat_completions.rs) uses 77-dash separators at the top level. All 19 separator blocks in this PR should be updated. Correct form:

    // ---------------------------------------------------------------------------
    // ResponseContext construction
    // ---------------------------------------------------------------------------

// Response translation: finish reasons
// -------------------------------------------------------------------------

fn make_response_context(request: &Value) -> super::chat_completions::ResponseContext {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Medium] make_response_context and simple_chat_response (line 1209) are test utility functions placed between test sections. The project convention requires test utility functions to go last inside mod tests, after all #[test] functions. Move both to the end of the module, just before the closing }.

@aslakknutsen

Copy link
Copy Markdown
Contributor

As this PR resolves #231, I can't see any test case for;

  • edge case "malformed tool schemas"
  • also the silent drop in function_call_tool_call when call_id or name is missing seems untested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add unit tests for OpenAI Responses-to-ChatCompletions translation

3 participants