From 4c6cf7c96fc2d75f971db622dbe1f7d6435bdf4b Mon Sep 17 00:00:00 2001 From: Denys Koreiba Date: Wed, 4 Nov 2026 17:06:54 +0100 Subject: [PATCH] fix(sonar): own async work and enforce quality gate results --- .github/workflows/merge-tests-coverage.yml | 4 +- .github/workflows/sonar-pr.yml | 4 +- app/auth/callback/page.tsx | 2 +- db_audit_scripts/security-audit.ts | 2 +- docs/ai/design/feature-sonar-main-green.md | 29 ++++++++++++++ .../feature-sonar-main-green.md | 24 ++++++++++++ docs/ai/planning/feature-sonar-main-green.md | 16 ++++++++ .../requirements/feature-sonar-main-green.md | 18 +++++++++ docs/ai/testing/feature-sonar-main-green.md | 38 +++++++++++++++++++ ui/web/adapters/oauth.ts | 2 +- ui/web/components/ExportSelectionDialog.tsx | 4 +- .../features/notes/SearchResultsPanel.tsx | 4 +- ui/web/hooks/useNotesMutations.ts | 12 +++--- ui/web/tests/unit/adapters/oauth.test.ts | 28 ++++++++++++++ 14 files changed, 172 insertions(+), 15 deletions(-) create mode 100644 docs/ai/design/feature-sonar-main-green.md create mode 100644 docs/ai/implementation/feature-sonar-main-green.md create mode 100644 docs/ai/planning/feature-sonar-main-green.md create mode 100644 docs/ai/requirements/feature-sonar-main-green.md create mode 100644 docs/ai/testing/feature-sonar-main-green.md diff --git a/.github/workflows/merge-tests-coverage.yml b/.github/workflows/merge-tests-coverage.yml index 196e9821f4cd..2709f9219c69 100644 --- a/.github/workflows/merge-tests-coverage.yml +++ b/.github/workflows/merge-tests-coverage.yml @@ -143,6 +143,8 @@ jobs: if: always() uses: SonarSource/sonarqube-scan-action@22918119ff8e1ca75a623e15c8296b6ea4fbe28f # v8.2.1 with: - args: ${{ steps.detect-lcov.outputs.sonar_args }} + args: >- + ${{ steps.detect-lcov.outputs.sonar_args }} + -Dsonar.qualitygate.wait=true env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/sonar-pr.yml b/.github/workflows/sonar-pr.yml index 8a896c86d16b..d8eb659956ca 100644 --- a/.github/workflows/sonar-pr.yml +++ b/.github/workflows/sonar-pr.yml @@ -74,6 +74,8 @@ jobs: if: always() uses: SonarSource/sonarqube-scan-action@22918119ff8e1ca75a623e15c8296b6ea4fbe28f # v8.2.1 with: - args: ${{ steps.detect-lcov.outputs.sonar_args }} + args: >- + ${{ steps.detect-lcov.outputs.sonar_args }} + -Dsonar.qualitygate.wait=true env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/app/auth/callback/page.tsx b/app/auth/callback/page.tsx index 9a69fa64354d..e10906e35191 100644 --- a/app/auth/callback/page.tsx +++ b/app/auth/callback/page.tsx @@ -109,7 +109,7 @@ export default function AuthCallback() { } } - handleCallback() + void handleCallback() }, [router]) return ( diff --git a/db_audit_scripts/security-audit.ts b/db_audit_scripts/security-audit.ts index 904520ec7ca6..40120883a051 100644 --- a/db_audit_scripts/security-audit.ts +++ b/db_audit_scripts/security-audit.ts @@ -67,4 +67,4 @@ async function securityAudit() { } } -securityAudit() +void securityAudit() diff --git a/docs/ai/design/feature-sonar-main-green.md b/docs/ai/design/feature-sonar-main-green.md new file mode 100644 index 000000000000..1acecac1ce94 --- /dev/null +++ b/docs/ai/design/feature-sonar-main-green.md @@ -0,0 +1,29 @@ +--- +phase: design +title: Main Sonar Quality Gate Design +--- + +# Promise ownership and the gate boundary + +```mermaid +flowchart LR + OAuth[OAuth start] --> Await[Await navigation] + Await --> Caller[Caller handles failure] + UI[UI refresh] --> Owned[Handler or Query handles errors] + Owned --> Void[Explicit background intent] + Scan[Upload analysis and both LCOV reports] --> Wait[Wait for remote quality gate] + Wait --> Result[CI succeeds or fails with the gate] +``` + +NavigationAdapter permits Promise or void; OAuthAdapter always returns a +promise, so its start method must await navigation. Export loading, auth +callback and the audit CLI already own their catches. TanStack Query refetches +catch fetch errors when throwOnError is false (the existing default), retain +error state, and intentionally run independently of mutation success callbacks. +Explicit void records that ownership; it does not add catch-and-ignore logic, +change query defaults, or delay saves until refetch completion. + +Keep canonical CommonJS entry detection and the operator-controlled argv-list +runner unless evidence identifies a real defect. Classify confirmed analyzer +errors individually, with comments documenting the trust boundary and runtime +proof; never disable a rule or change severity to satisfy the gate. diff --git a/docs/ai/implementation/feature-sonar-main-green.md b/docs/ai/implementation/feature-sonar-main-green.md new file mode 100644 index 000000000000..3842b9166ec4 --- /dev/null +++ b/docs/ai/implementation/feature-sonar-main-green.md @@ -0,0 +1,24 @@ +--- +phase: implementation +title: Main Sonar Quality Gate Implementation +--- + +# Changes + +Based on main 4c734702412c5b948fc268b37a93043d84a61378. +OAuth now awaits NavigationAdapter. Two new tests first demonstrated premature +success and lost rejection; all five adapter cases pass after the change. + +Explicit void annotations preserve existing background behavior in note/tag +cache invalidations, FTS refetch, export page loading, auth callback startup +and the audit CLI. The installed QueryClient.refetchQueries uses catch(noop) +when throwOnError is absent; invalidateQueries delegates to that method. +Export/auth/audit functions already catch their own errors. The audit script +is not executed against a real database during validation. + +Both Sonar scanner workflows pass sonar.qualitygate.wait=true in addition to +unchanged detected LCOV paths. This makes the job reflect the service gate +instead of only upload success. Rules, thresholds, new-code period, fixtures, +assertions, retries, timeouts and coverage inclusion remain unchanged. + +False-positive review remains pending; no issue is accepted as debt or hidden. diff --git a/docs/ai/planning/feature-sonar-main-green.md b/docs/ai/planning/feature-sonar-main-green.md new file mode 100644 index 000000000000..c73b933a96cb --- /dev/null +++ b/docs/ai/planning/feature-sonar-main-green.md @@ -0,0 +1,16 @@ +--- +phase: planning +title: Main Sonar Quality Gate Plan +--- + +# Work plan + +- [x] Refresh exact main SHA, quality-gate conditions and all 15 bug/security issues. +- [x] Preserve worktrees/preview and create sibling codex/sonar-main-green. +- [x] Reproduce OAuth completion/rejection loss with two failing tests; implement await. +- [x] Make existing handled background promise ownership explicit at the other 12 sites. +- [x] Add PR/main quality-gate waiting without changing criteria or coverage. +- [ ] Review two false-positive candidates with auditable evidence in owner Sonar session. +- [x] Validate 29 unit cases and 32 unchanged browser cases, types/lint/workflows. +- [ ] Publish PR, require fresh full CI, merge with exact-head guard. +- [ ] Confirm actual main Sonar gate OK, external check success, and complete tests. diff --git a/docs/ai/requirements/feature-sonar-main-green.md b/docs/ai/requirements/feature-sonar-main-green.md new file mode 100644 index 000000000000..9f97b07915b3 --- /dev/null +++ b/docs/ai/requirements/feature-sonar-main-green.md @@ -0,0 +1,18 @@ +--- +phase: requirements +title: Main Sonar Quality Gate Requirements +--- + +# Main Sonar quality gate + +Make the actual SonarCloud main quality gate green, preserving its rules, +thresholds, baseline period, source scope and coverage. The previous-version +period starts 2026-03-05. At main 4c734702412 it reports C reliability/C security, +13 floating-promise findings and two findings requiring evidence-based review. + +- Propagate asynchronous OAuth navigation failure and completion to its caller. +- Keep already-handled UI refreshes asynchronous without blocking note saves. +- Review only proven false positives with retained rationale and audit history. +- Make PR/main scanner jobs wait for the remote quality-gate result. +- Merge only after fresh remaining PR checks pass; verify actual main gate OK, + not just successful report upload. Keep all 1,146 component cases. diff --git a/docs/ai/testing/feature-sonar-main-green.md b/docs/ai/testing/feature-sonar-main-green.md new file mode 100644 index 000000000000..9d72b8a14668 --- /dev/null +++ b/docs/ai/testing/feature-sonar-main-green.md @@ -0,0 +1,38 @@ +--- +phase: testing +title: Main Sonar Quality Gate Testing +--- + +# Validation scope + +- OAuth adapter: five cases, including two new completion/rejection regressions. + Before fix: two failed, three passed. After fix: five passed, matched scope, + complete Allure modeling, no findings. +- Adjacent unit scope: 29 cases across OAuth, note mutations and both auth + callback suites (27 baseline cases plus two new regressions). +- Browser scope: 32 unchanged cases: export selection 5, note mutations 10, + search results 17. All use synthetic mocks, without a live database audit. +- Full fresh GitHub CI must retain all 1,146 component identities and all + existing Jest cases, plus the two new OAuth regressions. +- Type-check, ESLint and actionlint for both changed workflows. +- Verify successful remote PR/main quality gates separately from scanner upload. + +# Boundaries + +No test assertions, retries, timeouts, fixtures or coverage are reduced. +The background-ownership annotations preserve existing catches and refetch +error state; they do not implement new swallowing of failures. Audit CLI is +reviewed statically and is not run against real data. Native full Jest totals +remain independent of the existing 60 plain-jsdom cases that do not emit Allure. + +# Results + +All 29 adjacent unit cases and all 32 unchanged browser cases passed. Both +Allure runs matched their expected scope, modeled every result, and reported +zero findings, retries, flaky tests, skips or runner failures. Type-check, +targeted ESLint, actionlint for both workflows, git diff --check and all seven +AI DevKit base documentation checks passed. + +Evidence: sonar-main-green/unit-green/index.md and +sonar-main-green/component-green/index.md under the task evidence directory. +False-positive classification, fresh CI and the merged main gate are pending. diff --git a/ui/web/adapters/oauth.ts b/ui/web/adapters/oauth.ts index 7fbfed6f1712..b4e3b3d0d75e 100644 --- a/ui/web/adapters/oauth.ts +++ b/ui/web/adapters/oauth.ts @@ -8,7 +8,7 @@ export const webOAuthAdapter: OAuthAdapter = { // assign, not replace: this is exactly what supabase-js does when it performs the // redirect itself (GoTrueClient calls window.location.assign), so routing through // the adapter leaves browser history behaving as it did before. - webNavigationAdapter.navigate(authUrl) + await webNavigationAdapter.navigate(authUrl) }, } diff --git a/ui/web/components/ExportSelectionDialog.tsx b/ui/web/components/ExportSelectionDialog.tsx index b774a21a5f2f..8accbe3a9f3c 100644 --- a/ui/web/components/ExportSelectionDialog.tsx +++ b/ui/web/components/ExportSelectionDialog.tsx @@ -142,7 +142,7 @@ export function ExportSelectionDialog({ open, onOpenChange, onExport }: ExportSe setSelectAll(false) setPage(0) setInitialLoading(true) - loadPage(0) + void loadPage(0) } }, [open, loadPage]) @@ -150,7 +150,7 @@ export function ExportSelectionDialog({ open, onOpenChange, onExport }: ExportSe const target = event.currentTarget const nearBottom = target.scrollTop + target.clientHeight >= target.scrollHeight - 200 if (nearBottom && hasMore && !loading) { - loadPage(page) + void loadPage(page) } } diff --git a/ui/web/components/features/notes/SearchResultsPanel.tsx b/ui/web/components/features/notes/SearchResultsPanel.tsx index 59ae1c42f4c3..7cfe648554d7 100644 --- a/ui/web/components/features/notes/SearchResultsPanel.tsx +++ b/ui/web/components/features/notes/SearchResultsPanel.tsx @@ -359,7 +359,7 @@ export const SearchResultsPanel = React.forwardRef { - queryClient.invalidateQueries({ queryKey: ['notes'] }) - queryClient.invalidateQueries({ queryKey: ['tags', 'all-with-counts'] }) + void queryClient.invalidateQueries({ queryKey: ['notes'] }) + void queryClient.invalidateQueries({ queryKey: ['tags', 'all-with-counts'] }) if (!params.silent) callbacks.onSuccess?.() }, }) @@ -204,8 +204,8 @@ export function useUpdateNote(callbacks: MutationCallbacks = defaultUpdateCallba onSuccess: (_data, params) => { if (!params.deferCacheRefresh) { - queryClient.invalidateQueries({ queryKey: ['notes'] }) - queryClient.invalidateQueries({ queryKey: ['tags', 'all-with-counts'] }) + void queryClient.invalidateQueries({ queryKey: ['notes'] }) + void queryClient.invalidateQueries({ queryKey: ['tags', 'all-with-counts'] }) } if (!params.silent) callbacks.onSuccess?.() }, @@ -319,8 +319,8 @@ export function useRemoveTag(callbacks: MutationCallbacks = defaultRemoveTagCall }, onSuccess: () => { - queryClient.invalidateQueries({ queryKey: ['notes'] }) - queryClient.invalidateQueries({ queryKey: ['tags', 'all-with-counts'] }) + void queryClient.invalidateQueries({ queryKey: ['notes'] }) + void queryClient.invalidateQueries({ queryKey: ['tags', 'all-with-counts'] }) callbacks.onSuccess?.() }, }) diff --git a/ui/web/tests/unit/adapters/oauth.test.ts b/ui/web/tests/unit/adapters/oauth.test.ts index 74b07335a2ad..f89e6270974f 100644 --- a/ui/web/tests/unit/adapters/oauth.test.ts +++ b/ui/web/tests/unit/adapters/oauth.test.ts @@ -11,6 +11,34 @@ jest.mock('@ui/shell/runtime/platform', () => ({ jest.mock('@ui/shell/runtime/oauth', () => ({ nativeOAuthAdapter: { startOAuth: jest.fn() } })) describe('web OAuth adapter', () => { + it('waits for asynchronous navigation before reporting that OAuth started', async () => { + let finish!: () => void + const navigation = new Promise(resolve => { finish = resolve }) + jest.mocked(webNavigationAdapter.navigate).mockReturnValueOnce(navigation) + let settled = false + const started = webOAuthAdapter.startOAuth('https://provider.example/authorize').then(() => { settled = true }) + + try { + await Promise.resolve() + await Promise.resolve() + expect(settled).toBe(false) + finish() + await started + expect(settled).toBe(true) + } finally { finish() } + }) + + it('propagates asynchronous navigation failure to the OAuth caller', async () => { + const failure = new Error('Navigation failed') + const navigation = Promise.reject(failure) + // Observe the controlled child rejection even before the adapter is fixed; + // the public adapter promise must independently preserve that rejection. + void navigation.catch(() => undefined) + jest.mocked(webNavigationAdapter.navigate).mockReturnValueOnce(navigation) + + await expect(webOAuthAdapter.startOAuth('https://provider.example/authorize')).rejects.toBe(failure) + }) + it('navigates the page to the provider the same way supabase-js would', async () => { await webOAuthAdapter.startOAuth('https://provider.example/authorize')