Skip to content

refactor(protocols): extract responses tests to crates/protocols/tests/ - #1309

Merged
slin1237 merged 1 commit into
mainfrom
refactor/audit-c1-extract-tests
Apr 22, 2026
Merged

slin1237 merged 1 commit into
mainfrom
refactor/audit-c1-extract-tests

Conversation

@slin1237

@slin1237 slin1237 commented Apr 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Extracts the 1263-line #[cfg(test)] mod tests block from crates/protocols/src/responses.rs into a standalone integration test file at crates/protocols/tests/responses.rs, matching the existing convention used by background_mode_protocol.rs and skills_protocol.rs. Pure relocation; no test logic changed.

History

The first attempt of this PR placed the tests in a sibling source file (crates/protocols/src/responses_tests.rs via #[path]). That was flagged as incorrect in review: protocol tests in this crate live under crates/protocols/tests/ as integration tests, not as sibling source files. This branch has been rewritten (force-pushed) to use the correct location.

Stats

  • crates/protocols/src/responses.rs: 3660 -> 2396 lines (-1264).
  • crates/protocols/tests/responses.rs: new, 1262 lines (1260 dedented test lines + 7 import lines + 1 blank + 1 module doc comment + trailing newline, minus the 2 dropped use super::* / use serde_json::json lines).
  • cargo test -p openai-protocol total pass count is preserved: 53 (lib) + 9 (interactions) + 41 (new tests/responses.rs) + 18 (existing integration) + 1 (doc) = 122, all passing. The 41 extracted tests match the pre-move baseline exactly.

How

Integration tests run as a separate test binary against the public crate API, so they cannot use pub(crate) or pub(super) items. Verified this was safe: every symbol referenced in the test bodies is a pub item exposed through openai_protocol::responses or openai_protocol::common.

use super::*; was replaced with explicit crate-qualified imports at the top of the new file:

use openai_protocol::common::{
    ContextManagementType, Detail, PromptCacheRetention, ToolChoice as ChatToolChoice,
    ToolChoiceValue as ChatToolChoiceValue, ToolReference,
};
use openai_protocol::responses::*;
use serde_json::json;

The ChatToolChoice / ChatToolChoiceValue renames mirror the private aliases that were present in responses.rs, so the test bodies remain byte-for-byte identical to the original inline logic. The single fully-qualified reference inside the tests (crate::common::ContextManagementType::Compaction) was shortened to ContextManagementType::Compaction now that the type is imported at the top of the file.

Beyond those imports, the only mechanical transformation was:

  • Removing the outer #[cfg(test)] mod tests { ... } wrapper.
  • Removing the use super::*; line.
  • Dedenting every remaining line by one level of 4 spaces.

No pub item, field, variant, or serde attribute in responses.rs was modified.

Test plan

  • cargo test -p openai-protocol --test responses -> 41 passed, 0 failed, 0 ignored.
  • cargo test -p openai-protocol -> all suites pass (lib 53, interactions 9, new responses 41, existing integration 18, doc 1).
  • cargo fmt --all -- --check -> clean.
  • cargo clippy -p openai-protocol --tests -- -D warnings -> clean.
Checklist
  • Test relocation only — no logic changes
  • cargo test -p openai-protocol passes with the same test count (122)
  • cargo test -p openai-protocol --test responses runs the extracted 41 tests
  • cargo clippy -p openai-protocol --tests -- -D warnings clean
  • cargo fmt --all -- --check clean
  • No source code / public API changes

Summary by CodeRabbit

  • Tests
    • Reorganized JSON serialization test suite for Responses API protocol types into a dedicated test file, improving code maintainability while maintaining comprehensive coverage.

@github-actions github-actions Bot added the protocols Protocols crate changes label Apr 22, 2026
@coderabbitai

coderabbitai Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@slin1237 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 26 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 2 minutes and 26 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4ca42e5b-2843-448d-ab36-80c1fe494ab0

📥 Commits

Reviewing files that changed from the base of the PR and between a802498 and 0adb924.

📒 Files selected for processing (2)
  • crates/protocols/src/responses.rs
  • crates/protocols/tests/responses.rs
📝 Walkthrough

Walkthrough

This PR moves comprehensive serialization and deserialization tests from an inline #[cfg(test)] module in crates/protocols/src/responses.rs to a dedicated external test file at crates/protocols/tests/responses.rs. The test suite validates Responses API protocol types across JSON round-trips, request field handling, content variants, and tool configurations.

Changes

Cohort / File(s) Summary
Test Extraction
crates/protocols/src/responses.rs
Removed inline test module (1264 lines) to separate tests from production code.
Test File Creation
crates/protocols/tests/responses.rs
Added comprehensive test suite (1262 lines) covering serde round-trips for output items, request fields, tool configurations, content parts, and image-generation handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #1278 — Tests exercise the six new ResponsesRequest fields (prompt, prompt_cache_key, prompt_cache_retention, safety_identifier, stream_options, context_management) that this PR implements.
  • PR #1276 — Tests validate ResponsesToolChoice round-trips and projection behavior to Chat that this PR introduces.
  • PR #1273 — Tests assert Reasoning.summary uses the new SummaryTextContent shape that this PR depends on.

Suggested labels

tests

Suggested reviewers

  • CatherineSue
  • key4ng

Poem

🐰 Tests hopped from source to file so neat,
Where serde dances to JSON's beat,
Round-trips and shapes now verified true,
The protocols shine in tests anew! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'refactor(protocols): extract responses tests to crates/protocols/tests/' accurately describes the main change—relocating tests from an inline module in responses.rs to a separate test file—which aligns with the PR's core objective.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/audit-c1-extract-tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request refactors the codebase by moving the test suite for the responses protocol from crates/protocols/src/responses.rs to a dedicated file, crates/protocols/src/responses_tests.rs. The original file now references the new test file using the #[path] attribute. I have no feedback to provide.

@slin1237
slin1237 force-pushed the refactor/audit-c1-extract-tests branch from 817e020 to a802498 Compare April 22, 2026 14:08
@slin1237 slin1237 changed the title refactor(protocols): extract responses mod tests to sibling file refactor(protocols): extract responses tests to crates/protocols/tests/ Apr 22, 2026
@github-actions github-actions Bot added the tests Test changes label Apr 22, 2026
@slin1237

Copy link
Copy Markdown
Member Author

Branch rewritten per feedback: tests relocated from crates/protocols/src/responses_tests.rs (sibling source file) to crates/protocols/tests/responses.rs (integration test location, matches background_mode_protocol.rs / skills_protocol.rs convention).

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clean mechanical refactoring — all tests preserved identically with correct import path updates. No issues found.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/protocols/tests/responses.rs`:
- Around line 1-9: The tests file was moved to the integration-test location
(crates/protocols/tests/responses.rs) which changes test scope; to restore the
original unit-test visibility, move that file into
crates/protocols/src/responses_tests.rs and add a test-module wiring in
crates/protocols/src/responses.rs using the test-only module inclusion (i.e.,
add the cfg(test) path-based mod tests entry that references
responses_tests.rs), or if you intended integration tests instead, update the PR
description to state the change and confirm this new placement satisfies
visibility and discovery requirements.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9a30bf69-4e4b-48bf-9abb-1df9c9e67692

📥 Commits

Reviewing files that changed from the base of the PR and between 817e020 and a802498.

📒 Files selected for processing (2)
  • crates/protocols/src/responses.rs
  • crates/protocols/tests/responses.rs
💤 Files with no reviewable changes (1)
  • crates/protocols/src/responses.rs

Comment thread crates/protocols/tests/responses.rs
Move the `#[cfg(test)] mod tests` block out of
`crates/protocols/src/responses.rs` into a standalone integration
test file `crates/protocols/tests/responses.rs`, matching the
convention already used by `background_mode_protocol.rs` and
`skills_protocol.rs`.

What changed
- `crates/protocols/src/responses.rs`: 3660 -> 2396 lines. Removed the
  entire `#[cfg(test)] mod tests { ... }` block (previously L2398..EOF)
  plus the single blank separator line above it.
- `crates/protocols/tests/responses.rs`: new 1262-line integration
  test file. Contains all 41 tests from the removed inline module,
  dedented one level. `use super::*;` was replaced with explicit
  crate-qualified imports:
    * `use openai_protocol::responses::*;` covers the majority of
      types the tests reference (e.g., `ResponseOutputItem`,
      `ResponseInputOutputItem`, `ResponseContentPart`, `ResponseTool`,
      `ResponsesRequest`, `ResponsesToolChoice`, `McpTool`,
      `Annotation`, `BuiltInToolChoiceType`,
      `ImageGenerationCallStatus`, `IncludeField`,
      `RequireApproval{,Mode,Rules,Filter}`,
      `SimpleInputMessageTypeTag`, `SummaryTextContent`,
      `FileDetail`, `StringOrContentParts`, the tool-choice tag
      enums, `ResponsesFunctionToolChoice`, `ToolChoiceOptions`).
    * `use openai_protocol::common::{ContextManagementType, Detail,
      PromptCacheRetention, ToolChoice as ChatToolChoice,
      ToolChoiceValue as ChatToolChoiceValue, ToolReference};`
      resolves the aliases that the original inline test block
      inherited via the private `use super::common::{...}` in
      `responses.rs`. The `ChatToolChoice` / `ChatToolChoiceValue`
      renames are preserved so the test bodies remain byte-for-byte
      identical to the pre-move logic.
    * The one fully-qualified path inside the tests
      (`crate::common::ContextManagementType::Compaction`) was
      shortened to `ContextManagementType::Compaction` now that the
      type is imported.

Why
- The inline `mod tests` block had grown to 1264 lines (34% of
  `responses.rs`). Relocating the tests keeps the production file
  focused on protocol types.
- The protocols crate already uses `crates/protocols/tests/` for
  protocol-surface integration tests (see `background_mode_protocol.rs`
  and `skills_protocol.rs`). Placing the new file here matches that
  convention rather than introducing a sibling source file, which the
  user flagged as incorrect in PR review feedback on the earlier
  attempt.

How
- Integration tests run as a separate binary against the public crate
  API, so no test could rely on `pub(crate)` or `pub(super)` items.
  Verified by checking every symbol the tests reference: all the types
  used inside the test bodies are `pub` items exposed through
  `openai_protocol::responses` and `openai_protocol::common`.
- Only the `use super::*;` line and the outer `mod tests { ... }`
  braces were dropped; test logic is unchanged.
- No source code was edited. `responses.rs` keeps every `pub` item,
  field, variant, and serde attribute untouched.

Verification
- `cargo test -p openai-protocol --test responses` -> 41 passed,
  0 failed, 0 ignored. Matches the pre-move baseline of 41 tests.
- `cargo test -p openai-protocol` -> 53 (lib) + 9 + 41 + 18 + 1 doc
  tests pass, 0 fail. The lib count dropped from 94 to 53 because the
  41 relocated tests now run under the `responses` integration target.
- `cargo fmt --all -- --check` -> clean.
- `cargo clippy -p openai-protocol --tests -- -D warnings` -> clean.

No source-code behavior or public API was modified.

Signed-off-by: Simo Lin <linsimo.mark@gmail.com>
@slin1237
slin1237 force-pushed the refactor/audit-c1-extract-tests branch from a802498 to 0adb924 Compare April 22, 2026 14:22
@slin1237
slin1237 merged commit 3f36c80 into main Apr 22, 2026
37 checks passed
@slin1237
slin1237 deleted the refactor/audit-c1-extract-tests branch April 22, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

protocols Protocols crate changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant