Skip to content

test: add unit tests for resolveApiKey precedence in config.zig#59

Open
javimosch wants to merge 1 commit into
masterfrom
mago/task-56
Open

test: add unit tests for resolveApiKey precedence in config.zig#59
javimosch wants to merge 1 commit into
masterfrom
mago/task-56

Conversation

@javimosch

Copy link
Copy Markdown
Owner

What changed

Added 8 unit tests to src/config.zig for the resolveApiKey function, which implements the 6-level API key precedence chain used across every provider invocation.

Previously this function had zero test coverage despite being a critical path — a regression in any precedence level would silently break auth without any failing test.

Test cases

Test Precedence level covered
explicit --api-key wins all lower sources Level 1
config keys[provider] map beats provider env var Level 2
provider primary env var is used when above absent Level 3
second env key tried when first absent (xiaomi: PIZIG_API_KEY) Level 3b
config_api_key beats TAU_API_KEY Level 4
TAU_API_KEY used as last resort before null Level 5
returns null when no key available anywhere Fall-through
empty-string env values are skipped in precedence Guard check

Verification

zig build test --summary all
# Build Summary: 3/3 steps succeeded; 141/141 tests passed (was 133)

Closes #56 (mago task #56)

Cover all 6 precedence levels:
1. explicit --api-key wins
2. config keys map beats provider env var
3. provider env var (primary + secondary for multi-key providers)
4. config_api_key beats TAU_API_KEY
5. TAU_API_KEY as last resort before null
6. returns null when no key available
7. empty-string env values are skipped

zig build test: 141/141 pass (was 133).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@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.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@javimosch, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 256f0403-874a-4bbd-a031-0b0fceb76bfb

📥 Commits

Reviewing files that changed from the base of the PR and between 3e3b3b7 and d6df262.

📒 Files selected for processing (1)
  • src/config.zig
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mago/task-56

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

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

@javimosch

Copy link
Copy Markdown
Owner Author

Review — Head of Org Engineering: The diff adds only test cases for the existing resolveApiKey function in src/config.zig, covering all documented priority levels (explicit key, keys map, provider env var, config_api_key, TAU_API_KEY, null). The tests are syntactically valid Zig, scoped to the correct file, and introduce no correctness bugs, security issues, or secrets.

(approved — review-only mode; merge when ready.)

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.

Without repo access, I'll reason from the shipped work pattern and the focus area.

1 participant