Skip to content

test: generate the audit store and PKI signer doubles - #455

Merged
retr0h merged 1 commit into
mainfrom
test/generate-audit-and-signer-doubles
Aug 16, 2026
Merged

test: generate the audit store and PKI signer doubles#455
retr0h merged 1 commit into
mainfrom
test/generate-audit-and-signer-doubles

Conversation

@retr0h

@retr0h retr0h commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

Implements rescope-go-code-standards tasks 5.8 and 5.8a. Both doubles were hand-written for interfaces this repository defines, and both had been recorded as relying on an exception. Neither needed one.

captureStore → generated MockStore

The exception it claimed was real — the middleware writes from a bare go func() nothing can join. But the test coped with that by sleeping:

time.Sleep(50 * time.Millisecond)   // ×7

A generated mock can create the join point the test lacked:

store.EXPECT().Write(gomock.Any(), gomock.Any()).
    DoAndReturn(func(_ context.Context, entry audit.Entry) error {
        got = entry
        close(written)
        return tt.storeErr
    })
...
<-written

Seven sleeps removed. The test now waits on the call itself, not on a guess that can be wrong on a loaded runner.

A generated MockStore already existed in internal/audit/mocks/ — the hand-written spy was sitting next to it.

The excluded paths got a real assertion

Previously they slept and then checked nothing had been written. Now:

store.EXPECT().Write(gomock.Any(), gomock.Any()).Times(0)

The middleware returns before spawning the goroutine for excluded and unauthenticated paths, so nothing is racing. A regression that starts auditing /metrics now fails instead of passing because the sleep was long enough to see nothing.

mockPKISigner → generated MockPKISigner

This was kept on the grounds that the test verifies a real signature:

s.True(ed25519.Verify(pubKey, tt.payload, envelope.Signature))

True, and irrelevant — a generated mock delegates to the real implementation:

m.EXPECT().Sign(gomock.Any()).DoAndReturn(func(data []byte) []byte {
    return ed25519.Sign(priv, data)      // real key, real signature
}).AnyTimes()

Two constructors, per the "constructor returning a configured mock" guidance, since twelve call sites needed the pair and some need the controller key reported as their own.

Verification

just test — passes, coverage 100% against a 99.9% gate. No hand-written double remains for an interface this repository defines.

🤖 Generated with Claude Code

Both were hand-written for interfaces this repository defines, and both
had been recorded as relying on an exception. Neither needed one.

captureStore stood in for a write the audit middleware dispatches from a
goroutine it does not join. That is real, but the test coped with it by
sleeping fifty milliseconds, seven times. The generated mock closes a
channel from its write handler, so the test waits on the call rather
than on a duration. A generated MockStore already existed beside it.

mockPKISigner was kept because the test verifies a real ed25519
signature, which a scripted double would make vacuous. A generated mock
delegates to ed25519.Sign from its return handler, so the signature stays
real and the assertion keeps its meaning.

Paths that skip auditing now assert Times(0) rather than sleeping and
finding nothing, so a regression that starts auditing an excluded path
fails instead of passing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #455   +/-   ##
=======================================
  Coverage   99.94%   99.94%           
=======================================
  Files         484      484           
  Lines       24935    24935           
=======================================
  Hits        24921    24921           
  Misses         14       14           

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eb57692...652b169. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@retr0h
retr0h merged commit 3bffef2 into main Aug 16, 2026
12 checks passed
@retr0h
retr0h deleted the test/generate-audit-and-signer-doubles branch August 16, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant