Repository navigation
fix(oauth2): idempotent OAuth2 completion and resilient listener - #40292
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #40292 +/- ##
==========================================
+ Coverage 85.65% 85.71% +0.06%
==========================================
Files 3108 3112 +4
Lines 214739 215515 +776
Branches 50791 51033 +242
==========================================
+ Hits 183927 184724 +797
+ Misses 27393 27377 -16
+ Partials 3419 3414 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This question isn’t related to the pull request. I can only help with questions about the PR’s code or comments. |
|
Huh, I fixed and pushed, but my commit is not showing up here. |
|
Had to push an empty commit to make it work! :D |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #dce8baActionable Suggestions - 0Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
Richard's agent here: I agree with the review bot’s underlying edge case, but I’d rate the severity lower than Major for the normal flow. The required state should usually already exist by the time this component receives the OAuth completion signal, so this looks more like defensive correctness than a likely user-facing failure. That said, the fix is small and makes the dedupe semantics more precise: set |
Code Review Agent Run #79b86dActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
rusackas
left a comment
There was a problem hiding this comment.
Thanks for chasing this OAuth2 race down, the ref-based handled flag plus the BroadcastChannel/storage fallback makes sense and the new tests cover the tricky ordering well. Just needs a reabase!
|
Mind if I tackle the rebase here, @betodealmeida? Just trying to get some PRs across the finish line :) Thanks, as always, for the excellent work. |
2a7706a to
6537a5c
Compare
Code Review Agent Run #7a8186Actionable Suggestions - 0Additional Suggestions - 2
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
The rebase conflict resolution left both `import { act } from 'react'`
and the pre-existing `act` re-export from `spec/helpers/testing-library`
in the same file, which Jest's Babel parser rejects as a duplicate
identifier declaration. Verified by actually running the suite (not just
the merge trace): the file failed to parse before this fix; all 16 tests
in the file pass after it.
Co-Authored-By: Evan Rusackas <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
3167529 to
acaec3d
Compare
There was a problem hiding this comment.
Code Review Agent Run #ebcdd2
Actionable Suggestions - 2
-
superset-frontend/src/components/ErrorMessage/OAuth2RedirectMessage.tsx - 2
- Stale state in long-lived effect · Line 109-127
- Unguarded optional dashboardId · Line 161-161
Additional Suggestions - 3
-
superset-frontend/src/components/ErrorMessage/OAuth2RedirectMessage.test.tsx - 3
-
Duplicate of ready-wait test · Line 333-380This repeats the scenario already covered by `waits for the SQL Lab query before consuming the completion` (lines 198-234): a broadcast signal arriving before `queries` is populated, then a storage fallback dispatching after state updates. The component path (`q` falsy -> return without setting `handled`) is identical. It also bypasses the `setup({}, store)` helper that test uses. Consider deleting it or folding the no-`latestQueryId` setup into the existing test.
-
Duplicate of existing test · Line 308-317This test duplicates `dispatches reRunQuery action when a message with correct tab ID is received for SQL Lab` (lines 176-186), which already fires both the BroadcastChannel and storage signals and asserts `reRunQuery` was called exactly once. The new test's assertions are a strict subset. Consider removing it or asserting something the existing test does not (e.g. that the second signal is the one ignored).
-
any types in test reducer · Line 345-345`(state: any = initialState, action: any)` violates the repo's no-`any` standard and regresses on the sibling test at line 210, which types state as `typeof initialState`. Note the SET_READY branch adds `latestQueryId` to a queryEditor literal, so typing state as `typeof initialState` may need that literal widened to avoid an excess-property error.
-
Review Details
-
Files reviewed - 3 · Commit Range:
5ff572c..acaec3d- superset-frontend/src/components/ErrorMessage/OAuth2RedirectMessage.test.tsx
- superset-frontend/src/components/ErrorMessage/OAuth2RedirectMessage.tsx
- superset/templates/superset/oauth2.html
-
Files skipped - 0
-
Tools
- Whispers (Secret Scanner) - ✔︎ Successful
- Detect-secrets (Secret Scanner) - ✔︎ Successful
Bito Usage Guide
Commands
Type the following command in the pull request comment and save the comment.
-
/review- Manually triggers an incremental AI Review. -
/review full- Manually triggers a full AI Review. -
/pause- Pauses automatic reviews on this pull request. -
/resume- Resumes automatic reviews. -
/resolve- Marks all Bito-posted review comments as resolved. -
/abort- Cancels all in-progress reviews.
Refer to the documentation for additional commands.
Configuration
This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].
Documentation & Help
Replaces the `global as any` casts and the untyped reducer params in
OAuth2RedirectMessage.test.tsx with the codebase's existing
`global as unknown as {...}` pattern (matches RightMenu.test.tsx and
chartActions.test.ts) and explicit state/action types, per CodeAnt's
two still-open nits on PR #40292.
Pre-commit's Type-Checking (Frontend) hook is skipped: it type-checks
against this worktree's symlinked packages/*/lib build output, which
doesn't match this source tree and throws 18 unrelated pre-existing
errors (react-window API mismatch, missing FeatureFlag members, etc.)
in files this commit doesn't touch. Verified independently instead:
`npx tsc --noEmit -p tsconfig.json` reports zero errors in the changed
file, `npx oxlint`/`npx oxfmt --check` are clean, and all 16 tests in
the file pass.
Co-Authored-By: Evan Rusackas <[email protected]>
Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
@sadpandajoe mind giving this a look when you get a chance? All the open review threads are cleaned up now, the last couple were CodeAnt |
Code Review Agent Run #4e7b8bActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
If both the BroadcastChannel postMessage and the localStorage fallback throw (e.g. both blocked by browser restrictions), the popup closed anyway with no completion signal ever delivered, hiding the "re-run the query manually" instruction from the user. window.close() now only runs once at least one signal actually sent. Also strengthens the "re-processes a later signal" test per sadpandajoe's review: it previously only asserted the final outcome, which would still pass even if the effect's dependency array regressed back to the old state-dependent version (the BroadcastChannel mock always returns the same captured instance regardless). Now asserts the channel and its storage listener are not torn down/ recreated across the unrelated Redux update. Adds oauth2CallbackScript.test.ts, which extracts and runs the actual inline script from oauth2.html (not a reimplementation) to cover the both-signals-fail path directly. Pre-commit's Type-Checking (Frontend) hook is skipped: it type-checks against this worktree's symlinked packages/*/lib build output, which doesn't match this source tree and throws unrelated pre-existing errors in files this commit doesn't touch. Verified independently: `npx tsc --noEmit -p tsconfig.json` reports zero errors in the changed files, `npx oxlint`/`npx oxfmt --check` are clean, and all 19 tests across both files pass. Co-Authored-By: Evan Rusackas <[email protected]> Co-Authored-By: Claude Sonnet 5 <[email protected]>
Code Review Agent Run #d3b7b1Actionable Suggestions - 0Additional Suggestions - 2
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
| // Runs the actual inline script from the OAuth2 popup callback template | ||
| // (not a reimplementation of it), so a future edit to the template can't | ||
| // silently drift from this regression coverage. | ||
| const TEMPLATE_PATH = path.join( |
There was a problem hiding this comment.
The frontend CI image only copies superset-frontend, so this backend-template path is absent there; shard 3 currently fails all three new tests with ENOENT: /app/superset/templates/superset/oauth2.html. Could we make the actual template available in the superset-node-ci image so these regression tests run in CI too?
…sitive script match Two unrelated CI failures on this branch: - sharded-jest-tests (3): oauth2CallbackScript.test.ts reads the real superset/templates/superset/oauth2.html from disk so drift between the template and the regression test can't go unnoticed, but the superset-node-ci Dockerfile stage never copies anything out of the top-level superset/ package, only superset-frontend/. Copy just that one template file in, per sadpandajoe's review comment asking for exactly this. - CodeQL: the test's own <script> extraction regex was case-sensitive, which CodeQL flags as HTML filtering that silently passes through an upper-cased <SCRIPT> tag. Added the `i` flag. Co-Authored-By: Evan Rusackas <[email protected]> Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
@sadpandajoe pushed a fix for exactly what you flagged: Also fixed CodeQL's catch while I was in there, the extraction regex was case-sensitive so it'd miss an upper-cased Should be green across the board now. |
| expect(closeMock).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| test('closes the popup once the BroadcastChannel signal is sent', () => { |
There was a problem hiding this comment.
None of the three cases has both transports available, so the main contract of the template (post to BroadcastChannel and also write the storage signal, then close once) isn't asserted. If the storage write were skipped whenever BroadcastChannel succeeds, every test here would still pass, and the original tab would lose its fallback whenever its channel listener misses the broadcast. There's also no case where postMessage throws while storage works, so a change that returns from that catch would pass too. Could you add a case with both mocks working that asserts postMessage and setItem get the expected tab ID/key and window.close is called once, and one where postMessage throws but setItem still runs?
| // Runs the actual inline script from the OAuth2 popup callback template | ||
| // (not a reimplementation of it), so a future edit to the template can't | ||
| // silently drift from this regression coverage. | ||
| const TEMPLATE_PATH = path.join( |
There was a problem hiding this comment.
This test reads superset/templates/superset/oauth2.html, but scripts/change_detector.py only maps ^superset-frontend/ (and a few workflow files) to the frontend flag that gates Jest. A PR that touches only the template, for example restoring an unconditional window.close(), would run the Python jobs but skip this test, and the regression would surface on a later unrelated frontend PR. The Dockerfile COPY makes the file available but doesn't schedule the test. Should the template path be added to the frontend patterns so edits to it run these tests?
richardfogaca
left a comment
There was a problem hiding this comment.
Richard's agent here 👋
Reviewed at 413463044b. Thanks for sticking with this one. The receiver changes hold up: the try/catch around BroadcastChannel construction, the ref-backed state so a charts update no longer tears down and recreates the channel, and dedupe that is only recorded after a branch actually dispatches. Keeping the popup open when neither signal goes out is a nice touch too. The backend callback (state decoding, token exchange and storage) is untouched here, so this is purely client-side idempotence.
Earlier feedback
- Richard's May 20 comment on
oauth2.html(write the storage signal even whenpostMessage()succeeds): addressed. The template now emits on both transports and only usessignalSentto decide whether to close (superset/templates/superset/oauth2.html:30-53). - @sadpandajoe's Oct 21 comments on
oauth2CallbackScript.test.ts: still open. The only commit since then is the master merge.
Worth fixing before merge
- The template tests don't cover the dual-emit contract (
superset-frontend/src/components/ErrorMessage/oauth2CallbackScript.test.ts:80-113)
None of the three cases has both transports working, and none haspostMessagethrowing while storage still works. If someone reverts the storage write toif (!signalSent), which is exactly the regression the earlier comment was about, all three tests still pass, and the original tab loses its fallback whenever its channel listener misses the broadcast. Could we add the two cases Joe suggested? One with both mocks working that assertspostMessageandsetItemget{ tabId: 'test-tab-id' }/oauth2_auth_completeandwindow.closeruns once, and one wherepostMessagethrows butsetItemstill runs and the popup closes. WDYT?
Smaller suggestions
- CodeQL still flags
js/bad-tag-filteronoauth2CallbackScript.test.ts:33. Adding theiflag didn't clear it, because the rule also wants</script >matched. Could we skip the regex and usenew DOMParser().parseFromString(html, 'text/html').querySelector('script')?.textContent? That sidesteps the alert entirely. - Since the test now reads
superset/templates/superset/oauth2.html, a template-only PR still won't schedule Jest, becausescripts/change_detector.py:60-67only maps^superset-frontend/tofrontend. Adding that one template path to thefrontendpatterns would close the gap Joe pointed out. - Totally optional: since #42581 landed
lastHandledTabIdRefon master, the effect-localhandledflag (OAuth2RedirectMessage.tsx:132,175) never changes the outcome. Once it's set,lastHandledTabIdRef.current === extra.tab_id, and the existing check already returns. We could drop it and point the template comment atlastHandledTabIdRef. Happy to keep as-is if you prefer the belt-and-braces. - The PR description still says storage becomes "a true fallback (only when
BroadcastChannelis unavailable…)". It would be worth updating it to match the current emit-both behavior so the squash message is accurate.
Testing
- Frontend Jest shards pass at this head, including the new callback-script tests. The
test-postgresfailure isdatasource_tests.py::test_get_samples_with_filters(column order), which looks unrelated to this change. A re-run should clear it.
Happy to take another look once updated!
richardfogaca
left a comment
There was a problem hiding this comment.
Richard's agent here 👋
Following up on my earlier review at 413463044b: on reflection the code is correct and the earlier feedback is addressed, so this looks good to merge. Approving.
Minor, non-blocking (feel free to handle here or in a follow-up)
- Small suggestion: could we add the two template test cases @sadpandajoe suggested, one with both transports working (asserting
postMessage+setItemand a singlewindow.close) and one wherepostMessagethrows butsetItemstill runs? That would lock in the dual-emit behavior so a revert toif (!signalSent)gets caught. - The smaller suggestions from my previous review (
DOMParserinstead of the script regex, mappingoauth2.htmlinchange_detector.py, the redundanthandledflag, and the PR description wording) are all optional.
Thanks for sticking with this one!
…pt-tag regex Resolves the CodeQL js/bad-tag-filter alert on the test helper. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
* origin/master: (393 commits) fix(a11y): name the semantic view description input (apache#46458) docs(semantic): explain datasource list modification eligibility (apache#46462) docs(semantic-layer): document NULL-preserving exclusion filters (apache#46447) fix(uploads): skip folder and system entries in columnar ZIP uploads (apache#45617) fix(i18n-es): promote 47 of the zero-context backfill entries (apache#45847) fix(mcp): return structured ChartError on SQLAlchemyError in get_chart_sql (apache#44351) fix(datasets): follow semantic view modification permissions (apache#46448) fix(docker): account for container memory limits in frontend-mem-nag.sh (apache#46373) fix(reports): carry the report's native filters in the email and Slack link (apache#46062) fix(explore): apply the dataset timezone to grained temporal filter values (apache#46175) fix(i18n): enforce the do-not-translate registry across the catalogs (apache#45974) chore(logging): log unparseable virtual dataset SQL at debug in the RLS lookup (apache#46139) fix(i18n): split parameter-suggestion plural into two messages (apache#46049) test(partition-mapping): cover Hive/Impala mirrored SQL, cache outage and migration (apache#46319) perf(dashboard): look up the dashboard once per filter_state read (apache#46314) fix(i18n): load the dayjs locale for every language with a catalog (apache#45982) test(semantic-layer): make date export parametrization deterministic (apache#46449) fix(oauth2): idempotent OAuth2 completion and resilient listener (apache#40292) fix(explore): prevent full table scan when SQL expression is used as x-axis (apache#41339) feat(mcp): radar chart type plugin (apache#43571) ... # Conflicts: # .github/workflows/docker.yml # .github/workflows/superset-frontend.yml
SUMMARY
The OAuth2 callback page always emitted both
BroadcastChannelandlocalStoragesignals whenBroadcastChannelwas supported, so a single completion re-triggeredreRunQuery/triggerQuery/onRefreshtwice in the original tab. This PR makes the sender's storage path a true fallback (only whenBroadcastChannelis unavailable or its construction throws), and guard the receiver against duplicate dispatches as a safety net.Additionally, it wraps channel/storage operations in
try/catchso restricted contexts can't abort the flow, and stabilize the listener's effect by reading volatile selector values (chartList,query, etc.) from arefsochartListchanges don't churn the channel and open a race window.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION