Repository navigation
test: wait for the missed-window alarm; accept G703 directives that gosec skips - #221
Merged
Merged
Conversation
groupsky
force-pushed
the
fix/186-flaky-alarm-and-g703
branch
from
November 18, 2026 21:06
16959d6 to
ba59ced
Compare
…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
force-pushed
the
fix/186-flaky-alarm-and-g703
branch
from
November 18, 2026 21:17
ba59ced to
6d77e7b
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Fixes #186
TestStandingOutsideWindowAlarmFails("1 alarms went out")The cause is the test.
useEnvmakes 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.goandmissed.go). The test setFailAlarmright 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), likeWaitAskedandWaitEnded.TestStandingOutsideWindowAlarmFailsandTestStandingOutsideWindow(same race, other side) wait for the missed-window alarm first. Then the failedoutside_windowalarm sends nothing, and the next request sends exactly oneoutside_windowalarm (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 unusedG304` 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.go test -race -count=50 -run TestStandingOutsideWindow ./internal/broker/with the Go ofgo.modand Go stable, and the linter 10 more times, each without a cache.Progress
go test -race -count=50 -run TestStandingOutsideWindow ./internal/broker/passed with the Go ofgo.mod(job 135139975313) and Go stable (job 135139975268); the lint job ran golangci-lint 11 times, 10 of them aftergolangci-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).Second low note of the review:
internal/approval/approvaltestis test-only by habit, not by a check. Only_test.gofiles import it. This PR adds only a read helper.Checklist
🤖 Generated with Claude Code