Set the time zone in main and run Entry in its own test process (closes #192) #194

Merged
clawbot merged 1 commits from issue-192-entry-out-of-test-process into next 2026-10-15 19:25:11 +02:00
Collaborator

cli.Entry() set time.Local to UTC and ended with memguard.Purge(), and TestEntryWipesBuffersAndReturnsExitCode ran it in the same process as every other test in internal/cli. A timer an earlier test left running, such as the 10-second time.After ones in confirm_test.go, could read time.Local as it changed, which the race detector reported on some runs. The purge could destroy a memguard buffer still in use, the likeliest cause of the crash seen on another run.

  • main() in cmd/secret now sets time.Local before it calls cli.Entry(). memguard starts its goroutines only when first used, so no goroutine of secret is running yet. The test from #169 runs the built binary with TZ=America/New_York, so it still covers this.
  • The Entry test runs cli.Entry() in a copy of the test binary started with SECRET_TEST_RUN_ENTRY set. That copy acts in an init function, not in a test, because TestMain would otherwise build the secret binary again and remove it while the other tests run it.

Disclosures:

  • Deviation: cmd/secret/main.go now does one thing besides calling cli.Entry(), which AGENTS.md Go guideline 7 says it should only do. Policy 6 ("Set the local timezone to UTC on startup") and the plan on the issue put the time zone there.
  • Rule suppressed: gochecknoinits on the test's init function, with a reason, as the repo's two other init functions do.
  • Unverified: that the purge is what crashed the test process. The change takes the purge out of that process either way.

Model: opus-5-5

`cli.Entry()` set `time.Local` to UTC and ended with `memguard.Purge()`, and `TestEntryWipesBuffersAndReturnsExitCode` ran it in the same process as every other test in `internal/cli`. A timer an earlier test left running, such as the 10-second `time.After` ones in `confirm_test.go`, could read `time.Local` as it changed, which the race detector reported on some runs. The purge could destroy a memguard buffer still in use, the likeliest cause of the crash seen on another run. - `main()` in `cmd/secret` now sets `time.Local` before it calls `cli.Entry()`. memguard starts its goroutines only when first used, so no goroutine of `secret` is running yet. The test from https://git.eeqj.de/sneak/secret/issues/169 runs the built binary with `TZ=America/New_York`, so it still covers this. - The Entry test runs `cli.Entry()` in a copy of the test binary started with `SECRET_TEST_RUN_ENTRY` set. That copy acts in an `init` function, not in a test, because `TestMain` would otherwise build the `secret` binary again and remove it while the other tests run it. Disclosures: - Deviation: `cmd/secret/main.go` now does one thing besides calling `cli.Entry()`, which `AGENTS.md` Go guideline 7 says it should only do. Policy 6 ("Set the local timezone to UTC on startup") and the plan on the issue put the time zone there. - Rule suppressed: `gochecknoinits` on the test's `init` function, with a reason, as the repo's two other `init` functions do. - Unverified: that the purge is what crashed the test process. The change takes the purge out of that process either way. Model: opus-5-5
clawbot added 1 commit 2026-10-15 18:30:03 +02:00
cli.Entry() set time.Local to UTC and ended with memguard.Purge(), and
TestEntryWipesBuffersAndReturnsExitCode ran it in the same process as
the other tests. A timer left by an earlier test could read time.Local
as it changed, which the race detector reported on some runs, and the
purge could destroy a buffer still in use, the likeliest cause of a
crash seen on another run.

main() in cmd/secret now sets time.Local before it calls cli.Entry();
the test that runs the built binary with TZ=America/New_York still
covers it. The Entry test runs cli.Entry() in a copy of the test binary
started with SECRET_TEST_RUN_ENTRY set, which init picks up so that
TestMain does not run there.

Model: opus-5-5
clawbot self-assigned this 2026-10-15 18:30:06 +02:00
clawbot added the needs-review label 2026-10-15 18:30:06 +02:00
Author
Collaborator

Review passed: ready to merge into next.

Model: opus-5-5

Review passed: ready to merge into `next`. Model: opus-5-5
clawbot merged commit 8851171877 into next 2026-10-15 19:25:11 +02:00
clawbot deleted branch issue-192-entry-out-of-test-process 2026-10-15 19:25:12 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/secret#194