Skip to content

fix: ignore whitespace around the API key - #189

Merged
lumpinif merged 2 commits into
mainfrom
fix/api-key-whitespace
Nov 27, 2026
Merged

lumpinif merged 2 commits into
mainfrom
fix/api-key-whitespace

Conversation

@lumpinif

@lumpinif lumpinif commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What

The API key is stripped of surrounding whitespace where it is read (argument or FISH_API_KEY).

Why

A key read from a file or an environment variable often ends with a newline. httpx then refuses the Authorization header with a LocalProtocolError whose message prints the header, key included. With this change such a key simply works.

A key that is empty after stripping raises the existing "API key must be provided" error. A key with whitespace in the middle is not touched and still fails as before.

Verification

poe check passes. Three new tests in tests/unit/test_core.py cover a key from the argument, a key from the environment, and a whitespace-only key.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes
    • API keys supplied directly or through the environment are now trimmed of leading and trailing whitespace before use, so both input methods handle accidental surrounding spaces consistently. Keys made up entirely of whitespace continue to be rejected as missing, preserving existing validation behavior. No other changes to API-key requirements are included.

A key read from a file or an environment variable often ends with a newline.
httpx refused the resulting Authorization header with an error that printed
it, key included. The key is now stripped where it is read, so such a key
simply works.
@lumpinif
lumpinif requested review from abersheeran and a lite review from Copilot November 26, 2026 12:21
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T12:21:08.558392Z
We couldn’t complete this review. Comment @codex review to try again.
f585803 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The client removes leading and trailing whitespace from API keys supplied as arguments or through FISH_API_KEY. Tests verify the trimmed authorization value and the error for whitespace-only input.

Changes: API Key Handling

Layer / File(s) Summary
Trim and validate API keys
src/fishaudio/core/client_wrapper.py, tests/unit/test_core.py
BaseClientWrapper trims the selected API key. Tests check argument and environment values and confirm that a whitespace-only key raises the existing ValueError.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: Minimal · up to 867f4

The client now trims whitespace around API keys, so keys with trailing newlines no longer cause header errors. The change is small and tested, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: ignore whitespace around the API key" matches the main change. The wrapper now strips leading and trailing whitespace from the API key taken from the argument or FISH_API_KEY. The new …
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.
Full details: Title check

Explanation

The title "fix: ignore whitespace around the API key" matches the main change. The wrapper now strips leading and trailing whitespace from the API key taken from the argument or FISH_API_KEY. The new tests cover that behavior, and whitespace-only keys still raise the existing missing-key error.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 76d93797-4456-47dc-a0f1-ccad9493194b
Commits

Reviewing files that changed from the base of the PR and between f585803 and 867f4d9.

Files selected for processing: 2

  • src/fishaudio/core/client_wrapper.py
  • tests/unit/test_core.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/fishaudio/core/client_wrapper.py 92.81% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI 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.

🟢 Approval recommended

No active review issues are identified for the narrowly scoped API-key whitespace normalization change.

No open issues 🎉

What changed in this PR

This pull request trims surrounding whitespace from API keys read from arguments or FISH_API_KEY, allowing keys with trailing newlines to authenticate while preserving existing missing-key validation.

Changes:

  • Strip leading and trailing whitespace from API keys before validation and authorization.
  • Preserve the existing error for empty or whitespace-only keys.
  • Add tests covering argument input, environment input, and whitespace-only keys.
File Description
tests/​unit/​test_core.py Adds tests verifying whitespace normalization for argument- and environment-sourced API keys, including whitespace-only values.
src/​fishaudio/​core/​client_wrapper.py Trims surrounding whitespace from the API key before validation and request authentication.

Review effort: Lite

@lumpinif
lumpinif merged commit afb406a into main Nov 27, 2026
25 of 27 checks passed
@lumpinif
lumpinif deleted the fix/api-key-whitespace branch November 27, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants