Skip to content

refactor(sonar): replace sequential loop waits with pollUntil helper (typescript:S9382) - #224

Merged
setchy merged 5 commits into
mainfrom
fix/sonar/typescript-S9382
Oct 7, 2026
Merged

setchy merged 5 commits into
mainfrom
fix/sonar/typescript-S9382

Conversation

@setchy

@setchy setchy commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Summary

typescript:S9382 flags awaits used sequentially inside loops, on the assumption the iterations are independent and could run concurrently. The two waits in tests/visual/run.mts are genuinely sequential, so instead of suppressing the findings we restructured the code so no await sits inside a loop:

  1. the READY poll waits 100 ms between ticks so each check observes the fixture's latest stdout,
  2. the capture/retry loop waits 2 s between attempts so each retry checks a fresh screenshot.

Changes

  • tests/visual/run.mts: add a pollUntil(deadline, work, intervalMs) helper that runs work immediately, then re-runs it every intervalMs via a promise chain until work returns false or deadline passes — the awaits live inside the helper, never in a loop.
  • tests/visual/run.mts: replace the READY while loop with await pollUntil(deadline, () => !ready && child.exitCode === null, 100).
  • tests/visual/run.mts: move the capture/pixel-check retry loop body into the pollUntil callback (returning result.status !== 'pass'), preserving the attempts counter, the per-attempt console.log, and screenshot-failure propagation.
  • tests/visual/run.mts: remove the // NOSONAR:typescript:S9382 markers.

Verification

  • pnpm lint (oxlint + oxfmt) — clean
  • pnpm typecheck — clean
  • pnpm test — 129/129 passing
  • SonarCloud PR analysis — 0 open issues, quality gate OK

Findings

SonarQube rule typescript:S9382 flags the awaits inside the RUN_READY poll
loop and the capture/retry loop. Both are intentionally sequential - the
fixture must be observed tick-by-tick, and each retry needs a fresh
screenshot before the next pixel check - so NOSONAR markers explain why.
@setchy setchy changed the title fix(visual): address SonarQube typescript:S9382 findings refactor(sonar): justify sequential polling waits in loops (typescript:S9382) Oct 3, 2026
@setchy setchy closed this Oct 3, 2026
@setchy setchy reopened this Oct 3, 2026
@setchy setchy changed the title refactor(sonar): justify sequential polling waits in loops (typescript:S9382) refactor(sonar): replace sequential loop waits with pollUntil helper (typescript:S9382) Oct 4, 2026
The visual fixture left hideOnBlur at its default of true, so any focus
change after showWindow() hid the popup ~100ms later. On Windows the
VISUAL_PREPARE_CMD restarts Explorer, which reliably steals focus, so the
popup was gone by capture time and the check saw only the desktop behind
it (window=false, windowBlack=0) on all 26 retries. Set hideOnBlur:false
so the rendering fixture stays painted; it exercises rendering, not focus.
@sonarqubecloud

sonarqubecloud Bot commented Oct 7, 2026

Copy link
Copy Markdown

@setchy
setchy marked this pull request as ready for review October 7, 2026 12:06
@setchy
setchy requested a review from afonsojramos as a code owner October 7, 2026 12:06
@setchy
setchy merged commit 2fb2b8a into main Oct 7, 2026
29 checks passed
@setchy
setchy deleted the fix/sonar/typescript-S9382 branch October 7, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant