fix: --api-key flag takes precedence over WORKOS_API_KEY env var#137
fix: --api-key flag takes precedence over WORKOS_API_KEY env var#137
Conversation
Hono's `c.req.param()` returns `string | undefined` but these params are always present because they're defined in the route path pattern.
Previously the env var always won, making `--api-key` and `env switch` silently ineffective when WORKOS_API_KEY was set in the shell. Now the precedence follows standard CLI conventions: flag > env var > stored config. Also warns on `env switch` when WORKOS_API_KEY is set, since the env var will still override the stored environment key for commands that don't pass --api-key.
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughChanges add warning emission for environment variable overrides and restructure API key resolution priority. The output utilities are enhanced to support warnings in both JSON and human-readable formats. API key flag now takes precedence over environment variables. Route handlers include non-null assertions for required URL parameters. Changes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Review rate limit: 0/1 reviews remaining, refill in 29 minutes and 38 seconds.Comment |
Greptile SummaryThis PR fixes API key resolution priority so Confidence Score: 5/5Safe to merge; all changes are correct and well-tested, with only a minor spy-leak style issue in the new test helpers. Only P2 findings present — the vi.spyOn(console, 'error') leak doesn't cause any current test failures and doesn't affect production code. Core logic (priority reorder, warning emission, JSON shape) is correct and covered by tests. src/commands/env.spec.ts — spy teardown in the two new human-mode tests should call mockRestore(). Important Files Changed
|
- Remove unused `outputWarning` export (warnings are embedded in `outputSuccess` response instead) - Add missing `!` assertion on `orgId` in `listFilter` for consistency - Restore `WORKOS_API_KEY` env var in no-warning test to prevent leakage
Reflects the new flag > env var > stored config resolution order.
Summary
--api-keynow beatsWORKOS_API_KEYenv var, matching standard CLI conventions (gh,aws,kubectl). Previously the env var always won, making--api-keyandenv switchsilently ineffective.env switch: WhenWORKOS_API_KEYis set in the shell,env switchwarns that the env var will override the stored key. In JSON mode, warnings are embedded in the response object (not separate JSONL lines).outputSuccessgains optionalwarnings: Centralizes warning delivery so JSON consumers get a single parseable object.Reported via Slack by Fraser Langton --
env switchappeared to work but all API calls still hit the old environment becauseWORKOS_API_KEYwas set in the shell.Test plan
pnpm buildpassespnpm testpasses (1621 tests)pnpm typecheckpassesWORKOS_API_KEY=sk_test_fake workos env switch prod --jsonreturns single JSON withwarningsarray--api-keyflag overrides env varSummary by CodeRabbit
Release Notes
New Features
Bug Fixes
Tests