Make the tests fast under the race detector (closes #120) #123

Open
clawbot wants to merge 1 commits from issue-120-fast-race-tests into next
Collaborator

Implements #120.

  • Under -race, most test time went to scrypt, which age makes slow on purpose, deriving keys from passphrases. The one change outside test files: internal/secret/crypto.go gains ScryptWorkFactor; when not zero, EncryptWithPassphrase uses it instead of age's 18. Only the TestMain of internal/secret, internal/vault and internal/cli sets it, to 1; the package is internal, so no other module can. Decryption reads the factor from the data. The binary some internal/cli tests run keeps age's factor.
  • TestRemovalAsksWithoutHoldingLock timed out because its secret add queued behind other parallel tests' commands for the in-memory lock all tests in the package share; no race or deadlock. It and TestFailedCommandReleasesLock, which waits for that lock the same way, now run alone, like the other tests that time it.
  • TestConcurrentAddsKeepEveryVersion times nothing, and TestGetCommandOutputsToStdout set an environment variable its commands never read; both now run in parallel.
  • The script/cibuild comment no longer says tests are skipped without its memlock ulimit; none needs more than the default. The flag stays.

Disclosures:

  • Judgement call: TestFailedCommandReleasesLock was not failing.
  • Partly verified: the default locked-memory limit was checked at 8 MiB on the host, not in a plain docker build ..
  • Measured: make test with -race in script/cibuild took 86 s on this commit under heavy host load, 59 s in a quieter run before the two parallel-test changes.
  • Unmet: the 60-second cap holds only on a quiet host; most of the time is go vet and the cold -race compile, which no test change shortens.

Model: opus-5-5

Implements https://git.eeqj.de/sneak/secret/issues/120. - Under `-race`, most test time went to scrypt, which age makes slow on purpose, deriving keys from passphrases. The one change outside test files: `internal/secret/crypto.go` gains `ScryptWorkFactor`; when not zero, `EncryptWithPassphrase` uses it instead of age's 18. Only the `TestMain` of `internal/secret`, `internal/vault` and `internal/cli` sets it, to 1; the package is internal, so no other module can. Decryption reads the factor from the data. The binary some `internal/cli` tests run keeps age's factor. - `TestRemovalAsksWithoutHoldingLock` timed out because its `secret add` queued behind other parallel tests' commands for the in-memory lock all tests in the package share; no race or deadlock. It and `TestFailedCommandReleasesLock`, which waits for that lock the same way, now run alone, like the other tests that time it. - `TestConcurrentAddsKeepEveryVersion` times nothing, and `TestGetCommandOutputsToStdout` set an environment variable its commands never read; both now run in parallel. - The `script/cibuild` comment no longer says tests are skipped without its memlock ulimit; none needs more than the default. The flag stays. Disclosures: - Judgement call: `TestFailedCommandReleasesLock` was not failing. - Partly verified: the default locked-memory limit was checked at 8 MiB on the host, not in a plain `docker build .`. - Measured: `make test` with `-race` in `script/cibuild` took 86 s on this commit under heavy host load, 59 s in a quieter run before the two parallel-test changes. - Unmet: the 60-second cap holds only on a quiet host; most of the time is `go vet` and the cold `-race` compile, which no test change shortens. Model: opus-5-5
clawbot added the needs-review label 2026-10-06 03:45:18 +02:00
clawbot self-assigned this 2026-10-06 03:45:18 +02:00
Author
Collaborator

FAIL: needs rework

  1. internal/secret/crypto.go (ScryptWorkFactor) and internal/cli/integration_test.go (TestMain): no test checks that the program itself still encrypts passphrase unlockers at age's work factor of 18. The TestMain comment says the binary keeps age's work factor, but every test still passes if the program encrypts at 1, for example with var ScryptWorkFactor = 1 or any program code that sets it. This PR adds the first way the program could weaken passphrase encryption, so that should be checked. Acceptable: one assertion in a test that already runs the built binary's secret init with a passphrase (such as TestGetCommandOutputsToStdout) that the passphrase unlocker's priv.age names scrypt work factor 18.

Model: opus-5-5

**FAIL: needs rework** 1. `internal/secret/crypto.go` (`ScryptWorkFactor`) and `internal/cli/integration_test.go` (`TestMain`): no test checks that the program itself still encrypts passphrase unlockers at age's work factor of 18. The `TestMain` comment says the binary keeps age's work factor, but every test still passes if the program encrypts at 1, for example with `var ScryptWorkFactor = 1` or any program code that sets it. This PR adds the first way the program could weaken passphrase encryption, so that should be checked. Acceptable: one assertion in a test that already runs the built binary's `secret init` with a passphrase (such as `TestGetCommandOutputsToStdout`) that the passphrase unlocker's `priv.age` names scrypt work factor 18. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-06 05:11:46 +02:00
clawbot added 1 commit 2026-10-06 05:26:21 +02:00
Deriving keys from passphrases with scrypt, slow on purpose, took most
of the test time under -race. secret.ScryptWorkFactor, when not zero,
replaces age's work factor when a passphrase encrypts; the tests of
internal/secret, internal/vault and internal/cli set it to 1 in
TestMain, and the program never sets it. TestGetCommandOutputsToStdout
checks that the built binary's passphrase unlocker names age's 18.

TestRemovalAsksWithoutHoldingLock and TestFailedCommandReleasesLock
time the in-memory lock all tests share, so they no longer run in
parallel. TestConcurrentAddsKeepEveryVersion and
TestGetCommandOutputsToStdout time nothing and now do.

The script/cibuild comment no longer says tests are skipped without
its memlock ulimit.

Model: opus-5-5
clawbot force-pushed issue-120-fast-race-tests from 666e2438b0 to a3977ce937 2026-10-06 05:26:21 +02:00 Compare
clawbot added needs-review and removed needs-rework labels 2026-10-06 06:04:11 +02:00
Author
Collaborator

Review finding #123 (comment): TestGetCommandOutputsToStdout now checks that the passphrase unlocker's priv.age, written by the built binary's secret init, names scrypt work factor 18 on the scrypt line of its age header. It failed with each planted defect (var ScryptWorkFactor = 1, and separately secret.ScryptWorkFactor = 1 in cmd/secret/main.go), both removed. TODO.md and the commit message mention the check.

Model: opus-5-5

Review finding https://git.eeqj.de/sneak/secret/pulls/123#issuecomment-128075: `TestGetCommandOutputsToStdout` now checks that the passphrase unlocker's `priv.age`, written by the built binary's `secret init`, names scrypt work factor 18 on the scrypt line of its age header. It failed with each planted defect (`var ScryptWorkFactor = 1`, and separately `secret.ScryptWorkFactor = 1` in `cmd/secret/main.go`), both removed. `TODO.md` and the commit message mention the check. Model: opus-5-5
Some checks are pending
check / check (push) Waiting to run
You are not authorized to merge this pull request.
This pull request can be merged automatically.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin issue-120-fast-race-tests:issue-120-fast-race-tests
git checkout issue-120-fast-race-tests
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/secret#123