Skip to content

test: wait for the missed-window alarm; accept G703 directives that gosec skips - #221

Merged
groupsky merged 2 commits into
mainfrom
fix/186-flaky-alarm-and-g703
Nov 18, 2026
Merged

groupsky merged 2 commits into
mainfrom
fix/186-flaky-alarm-and-g703

Conversation

@groupsky

@groupsky groupsky commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Fixes #186

TestStandingOutsideWindowAlarmFails ("1 alarms went out")

The cause is the test. useEnv makes a standing grant at 12:00 with a daily window 11:00-13:00. The test moves the fake clock to 15:00, so the window ends with no use. The core then sends a missed-window alarm from its own goroutine (watchGrants → deliverAlarms, internal/approval/grants.go and missed.go). The test set FailAlarm right after the clock jump. Most often the core was slower, and the missed-window alarm failed. Sometimes the core was faster, and the alarm went out: "1 alarms went out". With a pause of 100 ms after the clock jump, the old test fails every time.

The broker is right: the missed-window alarm is expected. The fix:

  • approvaltest.Approver.WaitAlarms(n, timeout), like WaitAsked and WaitEnded.
  • TestStandingOutsideWindowAlarmFails and TestStandingOutsideWindow (same race, other side) wait for the missed-window alarm first. Then the failed outside_window alarm sends nothing, and the next request sends exactly one outside_window alarm (the mark was given back). The deny path is the same as before.

The G703 directives of nolintlint

gosec finds G703 (a path from tainted input) with a taint analysis. Its result changes from run to run with the same code and the same golangci-lint v2.14.0. When gosec does not report G703 on a line, nolintlint calls the //nolint:gosec // G703: ... directive there unused, and the lint step fails.

The fix is one exclusion in .golangci.yml, for nolintlint only, with an anchored text: ^directive //nolint:gosec // G703: [^]+ is unused for linter "gosec"$. I checked it with a scratch file: an unused G703 directive is accepted; an unused G304` directive is still reported. A missing reason, a missing linter name, a directive for more than one linter, and any G703 finding without a directive are still reported.

Trade-off (security review, low): if one of the 32 G703 directives stops being needed after a later change, nolintlint no longer says so, and the directive keeps gosec off on that line. This is accepted while the analysis is not stable.

Behavior for callers

Changes behavior for existing callers: no

Tests

  • go test -race ./..., go vet ./..., golangci-lint run --build-tags e2e.
  • Temporary CI steps (removed before the merge): go test -race -count=50 -run TestStandingOutsideWindow ./internal/broker/ with the Go of go.mod and Go stable, and the linter 10 more times, each without a cache.

Progress

  • Cause of the alarm count found and fixed in the test.
  • Lint: unused-G703 report of nolintlint accepted, nothing else.
  • Security review: no open finding (two low notes, explained above and below).
  • Repeated runs on CI, in run 44399960806: go test -race -count=50 -run TestStandingOutsideWindow ./internal/broker/ passed with the Go of go.mod (job 135139975313) and Go stable (job 135139975268); the lint job ran golangci-lint 11 times, 10 of them after golangci-lint cache clean, with 0 issues each time (job 135139975472). Earlier, before the rebase, the same steps passed in run 44396305192 (lint and stable). Without this change, the lint step of fix(broker): clear the login of a pre-approval before the answer #219 failed on the four G703 directives of this issue (run 44397050885, first attempt).
  • Temporary CI steps removed.

Second low note of the review: internal/approval/approvaltest is test-only by habit, not by a check. Only _test.go files import it. This PR adds only a read helper.

Checklist

  • The title follows Conventional Commits.
  • Tests cover the deny paths, not only the happy path.
  • The docs are updated: no doc shows these tests or the lint config.
  • The security review is done.
  • No private data.

🤖 Generated with Claude Code

@groupsky
groupsky force-pushed the fix/186-flaky-alarm-and-g703 branch from 16959d6 to ba59ced Compare November 18, 2026 21:06
…osec skips

TestStandingOutsideWindowAlarmFails moved the clock past the end of an
unused window. The core sends the missed-window alarm from its own
goroutine, and it sometimes went out before the test made alarms fail.
The test now waits for that alarm first, as does
TestStandingOutsideWindow.

gosec finds G703 with a taint analysis whose result changes from run to
run, so nolintlint sometimes called a G703 directive unused. Only that
one report of nolintlint is now off.

Fixes #186

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@groupsky
groupsky force-pushed the fix/186-flaky-alarm-and-g703 branch from ba59ced to 6d77e7b Compare November 18, 2026 21:17
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@groupsky
groupsky marked this pull request as ready for review November 18, 2026 21:21
@groupsky
groupsky merged commit b1d1da9 into main Nov 18, 2026
8 of 9 checks passed
@groupsky
groupsky deleted the fix/186-flaky-alarm-and-g703 branch November 18, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: flaky CI: TestStandingOutsideWindowAlarmFails and unused gosec G703 nolint directives

1 participant