Skip to content

test(audit): stop requiring a positive scan duration - #356

Merged
runkids merged 2 commits into
runkids:mainfrom
star-nebula:fix/audit-elapsed-non-negative
Oct 3, 2026
Merged

runkids merged 2 commits into
runkids:mainfrom
star-nebula:fix/audit-elapsed-non-negative

Conversation

@star-nebula

Copy link
Copy Markdown
Contributor

Type

  • Bug fix (test-only, no product code changes)

Linked Issue

Part of #344

What

One assertion in internal/audit/parallel_test.go:38:

-	if outputs[0].Elapsed <= 0 {
-		t.Error("expected positive elapsed duration")
+	if outputs[0].Elapsed < 0 {
+		t.Errorf("expected non-negative elapsed duration, got %s", outputs[0].Elapsed)

Why

ParallelScan records Elapsed: time.Since(start) around one skill scan
(internal/audit/parallel.go:81). A scan of a single tiny skill directory can complete inside one
clock tick, in which case the recorded duration is legitimately 0. The assertion demands it be
strictly positive, so it is asserting a property of the clock rather than of ParallelScan.

This is not theoretical. On a windows-latest host the assertion fails intermittently, and it is the
reason internal/audit alternates between green and red across upstream commits without any change to
that package:

run commit internal/audit
37098433003 e77e9128 ok 1.999s
37108486253 6e176ddb FAIL 0.947s, TestParallelScan_SingleSkill the only failure

Measured

Cross-compiled windows/amd64 test binary, run on a real Windows host at 6e176ddb:

current assertion patched assertion
TestParallelScan_SingleSkill repeated 4 failures in 1000 runs 0 failures in 1000 runs
whole internal/audit package alternates passes
same on Linux (WSL, ext4) 0 failures in 1000 runs 0 failures in 1000 runs

So the flake is specific to the Windows clock, not a general fragility: the same 1000 runs on Linux
never trip it, which is why the ubuntu and macOS jobs have stayed green.

gofmt -l, go vet ./internal/audit, go build ./... and
go test -race ./internal/audit ./internal/memory are all clean.

I kept a check rather than deleting the assertion: a negative duration would mean Elapsed was
corrupted or read from the wrong field, and < 0 still catches that. The alternative — making the
fixture slow enough to always register — would just reintroduce the same dependence on timing.

Why this matters for the Windows job

#351 merged a windows-test job restricted to packages that are green on windows-latest. A flaky
package cannot go on that list without making the job something reviewers learn to ignore, so fixing
the assertion is the prerequisite for keeping internal/audit under Windows coverage.

Checklist

  • I've read CONTRIBUTING.md
  • Tests included and passing — measured 1 failure/200 before, 0/1000 after, on a real Windows host,
    Linux unchanged
  • No unrelated changes in the diff (1 file, 1 assertion)
  • Scope is focused — one assertion in one test

ParallelScan records time.Since, which a single tiny skill can complete inside one
clock tick. Measured on a windows-latest host: 1 failure in 200 runs of
TestParallelScan_SingleSkill, and the package alternates between green and red across
upstream commits because of it. Keep the non-negative check, drop the timing promise.

@runkids runkids left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed ca03b1b. No blocking findings. A strictly positive duration is not guaranteed for a tiny scan at the available clock resolution; retaining the non-negative assertion removes the flaky assumption while still rejecting invalid timing. Verified TestParallelScan_SingleSkill with 100 repetitions in an isolated devcontainer copy; all passed. The Windows CI check also passed.

@runkids
runkids merged commit 8f30af8 into runkids:main Oct 3, 2026
8 checks passed
@star-nebula
star-nebula deleted the fix/audit-elapsed-non-negative branch October 15, 2026 07: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.

2 participants