Fix tests and GitHub Actions failures - clippy warnings, formatting, and key rotation logic #17
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.
Overview
This PR fixes all failing tests and GitHub Actions CI checks in the repository. The issue was caused by three categories of problems: code quality violations (clippy warnings), code formatting inconsistencies, and actual bugs in integration tests.
Issues Fixed
1. Code Quality & Formatting
Fixed multiple clippy warnings that were blocking CI with
-D warnings:Defaultimplementation with#[derive(Default)]forConfigstructreqwest::Error::from())std::io::Error::other()API#[allow(dead_code)]for public API functions and removed unused test helpersiter_custominstead of deprecatedto_asyncApplied
cargo fmtacross all 17 modified files to ensure consistent formatting.2. Key Rotation Logic Bug
Problem: The
test_api_key_rotation_on_rate_limittest was failing because the proxy wasn't actually rotating to different API keys when retrying after rate limit errors.Root Cause: When the first key returned a 429 (rate limited) response, the retry loop would call
get_key_for_model()again, which always returned the same key because it was the best match for the requested model (e.g., "gpt-3.5-turbo").Solution: Modified the
ProxyEngineto track retry state and switch to usingget_next_key()after the first failure, ensuring actual key rotation through all available keys:This ensures the proxy properly implements failover by trying different API keys when one becomes rate limited.
3. Wiremock Test Configuration
Problem: The
test_api_streaming_responsetest was failing because the content-type header wasn't being preserved in the response.Root Cause: Wiremock's
set_body_string()method automatically setscontent-type: text/plainand overrides any custom headers set withinsert_header()orappend_header().Solution: Changed to use
set_body_bytes()which doesn't override custom headers:Additional Fix: Added proper mock setup for the
test_api_error_handling_no_available_keystest to handle the "others" fallback key scenario.Test Results
All test suites now pass:
cargo fmt --checkpassescargo clippy -- -D warningspassesImpact
The changes are minimal and surgical, focusing only on fixing identified issues without modifying working code.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
definitely-not-a-real-domain-12345.com/home/REDACTED/work/key-cycle-proxy/key-cycle-proxy/target/debug/deps/enhanced_unit_tests-1efd28ab9ffdee84(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.