test(secrets): cover compileAll and ScanBytes compile-error paths #3053
Reference in New Issue
Block a user
Delete Branch "fix/1269-secrets-compile-error-tests"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #1269.
PR #1255 left two unreachable code paths uncovered in
workspace-server/internal/secrets:compileAllerror when a pattern regex is invalid.ScanBytesreturning the compile error instead of aMatch.Changes
TestCompileErrorandTestScanBytes_CompileErr.Patternsslice, resetcompiledOnce/compileErr/compiledPatterns, and restore the original state after the test so later tests see the canonical pattern set.Test plan
go test ./workspace-server/internal/secrets/...passes locally.Fixes #1269
🤖 Generated with Claude Code
c462fd811eto4139fa1fa95-axis review on head
d6a1423e:APPROVED.
Correctness: the new tests exercise real compile-error paths by injecting invalid regex sources into
Patterns, resettingcompiledOnce,compileErr, andcompiledPatterns, then assertingcompileAll,ScanBytes, andScanStringsurface the pattern-specific compile error with noMatch. The cleanup restores the canonical pattern slice and clears the once state so later tests recompile cleanly.Robustness: no
t.Paralleluse, so the package-global mutation is not racing within this test file. Cleanup is deferred in each mutating test. Security: test fixtures do not introduce real secrets and preserve the no-roundtrip match contract. Performance: test-only, negligible. Readability: helper and scenario names make the otherwise-global-state manipulation clear.I could not run
go testlocally because this container does not havegoinstalled, but Gitea shows CI / Platform (Go), secret scan, and the relevant core code checks successful on this head.