From 6d77e7b43d55de62a5f78f09191f525c0635f704 Mon Sep 17 00:00:00 2001 From: Geno Roupsky <185580+groupsky@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:56:36 +0200 Subject: [PATCH 1/2] test: wait for the missed-window alarm; accept G703 directives that gosec 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 --- .github/workflows/ci.yml | 4 ++++ .golangci.yml | 9 +++++++++ internal/approval/approvaltest/approver.go | 7 +++++++ internal/broker/standinguse_test.go | 20 +++++++++++++++++--- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ae23a1..bb094b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,6 +57,8 @@ jobs: fi - run: go vet ./... - run: go test -race ./... + - name: TEMPORARY (#186) TestStandingOutsideWindowAlarmFails, 50 runs + run: go test -race -count=50 -run 'TestStandingOutsideWindow' ./internal/broker/ lint: runs-on: ubuntu-latest @@ -97,6 +99,8 @@ jobs: # With the tag e2e, the files of the end-to-end test are checked # too. No file needs the tag to be missing, so nothing is left out. args: --build-tags e2e + - name: TEMPORARY (#186) the linter 10 more times, each without a cache + run: for i in $(seq 10); do echo "lint $i"; golangci-lint cache clean; golangci-lint run --build-tags e2e || exit 1; done e2e: name: end-to-end test diff --git a/.golangci.yml b/.golangci.yml index a94231a..d7f5b89 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -56,6 +56,15 @@ linters: exclusions: rules: + # gosec finds G703 (a path from tainted input) with a taint analysis + # whose result changes from run to run, with the same code and the + # same version (#186). So nolintlint sometimes reports a G703 + # directive as unused. Only that report is off, only for a directive + # that names G703 alone; any other unused directive is still + # reported, and gosec still reports a G703 without a directive. + - linters: + - nolintlint + text: '^directive `//nolint:gosec // G703: [^`]+` is unused for linter "gosec"$' # Code in cmd/ may print. Only the rules about printing and logging # (their messages start with "library code must not") are off there. - path: ^cmd/ diff --git a/internal/approval/approvaltest/approver.go b/internal/approval/approvaltest/approver.go index 5f2e9e6..5d99752 100644 --- a/internal/approval/approvaltest/approver.go +++ b/internal/approval/approvaltest/approver.go @@ -300,6 +300,13 @@ func (a *Approver) WaitEnded(n int, timeout time.Duration) ([]Ended, error) { return a.Ended(), err } +// WaitAlarms waits until at least n alarms went out, and returns them. It +// fails after timeout. +func (a *Approver) WaitAlarms(n int, timeout time.Duration) ([]approval.Alarm, error) { + err := a.wait(func() bool { return len(a.alarms) >= n }, timeout) + return a.Alarms(), err +} + // WaitRunning waits until Run runs. It fails after timeout. func (a *Approver) WaitRunning(timeout time.Duration) error { return a.wait(func() bool { return a.answer != nil }, timeout) diff --git a/internal/broker/standinguse_test.go b/internal/broker/standinguse_test.go index f809173..3c2470a 100644 --- a/internal/broker/standinguse_test.go +++ b/internal/broker/standinguse_test.go @@ -188,6 +188,7 @@ func TestStandingOldToken(t *testing.T) { func TestStandingOutsideWindow(t *testing.T) { e, tok0, id := useEnv(t) e.clock.Advance(3 * time.Hour) // 15:00 + e.waitMissedAlarm() for range 2 { res, _ := e.useToken("laptop", tok0) mustStatus(t, res, http.StatusForbidden) @@ -451,22 +452,35 @@ func TestStandingForeignToken(t *testing.T) { func TestStandingOutsideWindowAlarmFails(t *testing.T) { e, tok0, id := useEnv(t) e.clock.Advance(3 * time.Hour) // 15:00 + e.waitMissedAlarm() e.approver.FailAlarm(errors.New("made-up: the alarm cannot be sent")) res, _ := e.useToken("laptop", tok0) mustStatus(t, res, http.StatusForbidden) - if n := len(e.approver.Alarms()); n != 0 { - t.Fatalf("%d alarms went out", n) + if n := len(e.approver.Alarms()); n != 1 { + t.Fatalf("%d alarms went out, want only the missed-window alarm", n) } e.approver.FailAlarm(nil) for range 2 { res, _ = e.useToken("laptop", tok0) mustStatus(t, res, http.StatusForbidden) } - if as := e.approver.Alarms(); len(as) != 1 || as[0].Cause != audit.AlarmOutsideWindow || as[0].GrantID != id { + if as := e.approver.Alarms(); len(as) != 2 || as[1].Cause != audit.AlarmOutsideWindow || as[1].GrantID != id { t.Errorf("the alarms: %+v", as) } } +// waitMissedAlarm waits for the alarm of the window of 11:00-13:00 of +// useEnv, after the clock went past 13:00 with no use in it. The core +// sends it from its own goroutine, at a time that the test does not +// control; a test that counts alarms waits for it first (#186). +func (e *env) waitMissedAlarm() { + e.t.Helper() + as, err := e.approver.WaitAlarms(1, waitLimit) + if err != nil || len(as) != 1 || as[0].Cause != audit.AlarmMissedWindow { + e.t.Fatalf("the missed-window alarm: %+v, %v", as, err) + } +} + // TestStandingBeforeStart: a valid token before the start of the grant is // denied, with an outside_window alarm, and the grant stays. func TestStandingBeforeStart(t *testing.T) { From 53cf1251ee67ae15cd0e086bba9841e19e4950c3 Mon Sep 17 00:00:00 2001 From: Geno Roupsky <185580+groupsky@users.noreply.github.com> Date: Wed, 18 Nov 2026 23:21:23 +0200 Subject: [PATCH 2/2] ci: remove the temporary repeated runs Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb094b6..3ae23a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,8 +57,6 @@ jobs: fi - run: go vet ./... - run: go test -race ./... - - name: TEMPORARY (#186) TestStandingOutsideWindowAlarmFails, 50 runs - run: go test -race -count=50 -run 'TestStandingOutsideWindow' ./internal/broker/ lint: runs-on: ubuntu-latest @@ -99,8 +97,6 @@ jobs: # With the tag e2e, the files of the end-to-end test are checked # too. No file needs the tag to be missing, so nothing is left out. args: --build-tags e2e - - name: TEMPORARY (#186) the linter 10 more times, each without a cache - run: for i in $(seq 10); do echo "lint $i"; golangci-lint cache clean; golangci-lint run --build-tags e2e || exit 1; done e2e: name: end-to-end test