Repository navigation
feat: captcha feature flag - #7591
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis PR adds an ChangesCaptcha Feature Flag Gating
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 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. Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Deploying swap-dev with
|
| Latest commit: |
00f6b65
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://7cb774c9.swap-dev-5u6.pages.dev |
| Branch Preview URL: | https://feat-captcha-feature-flag.swap-dev-5u6.pages.dev |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/cowswap-frontend/src/modules/captcha/containers/CaptchaWidget.container.test.tsx (1)
73-88: ⚡ Quick winCover stale JWT cleanup on initial disabled render.
These cases only assert that Turnstile stays hidden. The new contract is stronger: when the flag is missing or
false, a previously stored captcha JWT should also be cleared on first render. Without seedingcaptchaJwtAtomhere, a startup regression in that cleanup path would slip through.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/cowswap-frontend/src/modules/captcha/containers/CaptchaWidget.container.test.tsx` around lines 73 - 88, The tests for initial disabled/missing captcha flag don't seed captchaJwtAtom so they miss verifying JWT cleanup; update both test cases (the one using renderWithStore() and the one that creates a store and sets featureFlagsAtom) to pre-seed captchaJwtAtom with a non-null token (e.g., set(captchaJwtAtom, 'seeded-token') on the store or via createStore helper) before calling renderWithStore, then assert that the cleanup occurs by expecting setBearerTokenMock toHaveBeenCalledWith(null) (and/or that captchaJwtAtom is cleared) after render; reference captchaJwtAtom, renderWithStore, createStore, featureFlagsAtom, and setBearerTokenMock to locate where to change the tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@apps/cowswap-frontend/src/modules/captcha/containers/CaptchaWidget.container.test.tsx`:
- Around line 73-88: The tests for initial disabled/missing captcha flag don't
seed captchaJwtAtom so they miss verifying JWT cleanup; update both test cases
(the one using renderWithStore() and the one that creates a store and sets
featureFlagsAtom) to pre-seed captchaJwtAtom with a non-null token (e.g.,
set(captchaJwtAtom, 'seeded-token') on the store or via createStore helper)
before calling renderWithStore, then assert that the cleanup occurs by expecting
setBearerTokenMock toHaveBeenCalledWith(null) (and/or that captchaJwtAtom is
cleared) after render; reference captchaJwtAtom, renderWithStore, createStore,
featureFlagsAtom, and setBearerTokenMock to locate where to change the tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c10f35cd-5511-402e-9291-bfe2a5d6c4bc
📒 Files selected for processing (3)
apps/cowswap-frontend/src/modules/captcha/README.mdapps/cowswap-frontend/src/modules/captcha/containers/CaptchaWidget.container.test.tsxapps/cowswap-frontend/src/modules/captcha/containers/CaptchaWidget.container.tsx
Deploying explorer-dev with
|
| Latest commit: |
00f6b65
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://fce7914d.explorer-dev-dxz.pages.dev |
| Branch Preview URL: | https://feat-captcha-feature-flag.explorer-dev-dxz.pages.dev |
| import { useCaptchaDebugControls } from '../hooks/useCaptchaDebugControls' | ||
| import { logCaptcha } from '../logger' | ||
|
|
||
| export function CaptchaWidget(): ReactNode { |
There was a problem hiding this comment.
Maybe it will be simplier:
{isCaptchaEnabled && <CaptchaWidget />}
fairlighteth
left a comment
There was a problem hiding this comment.
⚠️ AI Review (Codex GPT-5, worked 4m28s): gate captcha cleanup on hydrated feature flags
Finding: Gate captcha cleanup on hydrated feature flags
- Location:
apps/cowswap-frontend/src/modules/captcha/containers/CaptchaWidget.container.tsx:47 featureFlagsAtomstarts as{}, andFeatureFlagsUpdatercopies LaunchDarkly flags into it from a layout effect.- On initial app mount, this cleanup effect treats the not-yet-hydrated flag as disabled. If LaunchDarkly already has
isCaptchaEnabled=trueand a valid captcha JWT is persisted, the widget can clear the bearer token/JWT before it observes the real enabled flag. - Impact: users with captcha enabled can lose a valid stored captcha token on reload and be forced through Turnstile again.
Suggested fix
- Distinguish “flags not hydrated yet” from “flag missing/false”. For example, read
featureFlagsHydratedAtomand skip destructive cleanup until hydration is complete; once hydrated, missing/false can still clear as intended. - Add coverage for a startup case where a valid
captchaJwtAtomexists, flags are not hydrated on first render, then hydrate to{ isCaptchaEnabled: true }; the JWT/bearer token should not be cleared.
Review scope and related context
Existing comments already cover:
- CodeRabbit’s nit about adding initial disabled/missing-flag cleanup coverage in the test file.
- @shoom3301’s open suggestion to simplify render gating; this finding is separate because moving the gate outside the widget must still preserve the JWT/bearer cleanup behavior.
I did not run the targeted Jest test because this checkout has no node_modules installed.
🤖 Prompt for AI agents
Verify this finding against current code. Fix only if still valid, keep the change minimal, and validate with targeted tests.
Context:
- CaptchaWidget reads featureFlagsAtom directly at apps/cowswap-frontend/src/modules/captcha/containers/CaptchaWidget.container.tsx:20.
- featureFlagsAtom defaults to {} and featureFlagsHydratedAtom defaults to false in apps/cowswap-frontend/src/common/state/featureFlagsState.ts.
- FeatureFlagsUpdater hydrates the atom in useLayoutEffect.
- The cleanup effect at CaptchaWidget.container.tsx:47 currently treats undefined isCaptchaEnabled as disabled and clears bearer/JWT state.
Expected fix/test:
- Do not clear captchaJwtAtom or bearer token while feature flags are still unhydrated.
- Still clear them once flags are hydrated and isCaptchaEnabled is missing or false.
</details>
</details>
| useEffect(() => { | ||
| if (isCaptchaEnabled) return | ||
|
|
||
| exchangeRequestIdRef.current += 1 |
There was a problem hiding this comment.
What is this tracking exactly?
There was a problem hiding this comment.
The idea is to discard stale requests (for exchanging a turnstile token to a jwt), so we assign an incrementing integer which we compare when the result comes back.
This protects against race conditions, but... if we remove useCaptchaDebugControls we have little reason to keep it.
alfetopito
left a comment
There was a problem hiding this comment.
One question about a ref whose name is confusing. Code and behaviour looks good otherwise.
Fixed in c0cf8e8 |
|
Summary
Adds a frontend feature flag gate for captcha while the backend
/auth/turnstileendpoint is not ready.When
isCaptchaEnabledis missing or false:Also adds focused tests for disabled, enabled, and cleanup behavior.
To Test
isCaptchaEnabledmissing or false, captcha is not rendered in the trade widget/auth/turnstileisCaptchaEnabled=trueandREACT_APP_TURNSTILE_SITE_KEYconfigured, Turnstile rendersBackground
The captcha backend endpoint is not deployed yet, so captcha must default off and only activate after LaunchDarkly enables
isCaptchaEnabled.Summary by CodeRabbit
New Features
Documentation
Tests