All posts

5 min readPost 10

Tests our machines could not run: two tiers

You cannot prove a file-deletion tool is safe using only mocks, yet real filesystems, real Git repos, and real PowerShell stalled local runs past 1,500 seconds under parallel workers. Here is how we split testing into a 60-second local tier and sharded CI, solved Go's testlog stall and a Git Bash ACL bug, and guaranteed zero host contamination.

On this page
  1. The bottleneck was disk sync and process spawning, not CPU
  2. Two tiers: fast feedback locally, full shards in CI
  3. CI billing reality—and a Git Bash privilege trap
  4. Isolation guardrails: real tests must never touch the host

Most of Obituary's test suite consists of real integration tests: real NTFS filesystems, real Git repositories, real PowerShell processes, and real registry keys under isolated roots. Because the entire purpose of the suite is proving that Obituary never deletes the wrong file, replacing OS and Git behavior with mocks would undermine what we are testing.

On 10 November that realism hit a wall. With a dozen workers running concurrently on one dev machine, the doctor package—which finished in 63 seconds on an idle GitHub runner—timed out past 1,500 seconds locally while CPU utilization sat around 26%.

The bottleneck was disk sync and process spawning, not CPU ​

Idle CPU alongside 25-minute timeouts pointed straight at I/O and OS process contention:

  • Almost every test ran git init to build a fresh temporary repository.
  • Every ledger commit ran real disk fsync.
  • Each Windows PowerShell invocation cost roughly 0.4 s of startup overhead.
  • Every doctor test audited all 30 integrated agents.

Adding t.Parallel() to 425 top-level tests and 97 subtests helped CPU-bound code yet did nothing for disk syncs or process creation—under heavy concurrency, a dozen workers fighting over one SSD only made wall time worse.

Two tiers: fast feedback locally, full shards in CI ​

We split the test pyramid cleanly into two explicit tiers:

  • Local fast tier (go test -short ./...): developers and workers run affected packages and -short locally, targeting under 60 seconds across the tree on an idle machine while skipping the heaviest end-to-end integration tests.
  • CI full and mutation tiers: every full suite and all compile-time mutations run sharded in GitHub Actions, printing the 30 slowest tests on every run so latency regressions show up immediately.

Four targeted changes brought -short under a minute without weakening coverage:

  • Disabled default ledger fsync inside test binaries (mirroring SQLite's synchronous=OFF in tests); durability-order tests keep fsync enabled, while crash-recovery tests inject explicit fault points rather than simulating power cuts.
  • Built one template Git repo per package and copied it instead of invoking git init repeatedly.
  • Scoped doctor unit tests to only the agents each case exercises.
  • Stubbed repetitive Git and PowerShell calls in upper-layer tests while preserving real invocations in contract suites.

Measured wall time across the full tree:

Scenariogo test -short ./... wall time
Idle dev machine (initial split)~61 s
11 parallel workers contending on the same host~81 s
Cold-cache run after growing to 74 packages110 s (0 failures)

An unexpected stall: Go's multi-hundred-MB testlog ​

Even after tests printed ok, one worker hung for nearly ten minutes before exiting. Go's test driver rewrites its testlog file on shutdown, and integration-heavy runs ballooned that file to hundreds of megabytes.

Our shared testenv wrapper now compacts testlog only on stable Go 1.26.x when the file format matches verbatim; if a future Go release changes the format, testenv leaves every byte untouched and logs one notice.

Terminal output from gotestsum listing the 12 slowest tests in the fast tier: slowest is 6.12 seconds across core/lifecycle, cli/purge, and integrate
Slowest tests from a cold-cache -short run across 74 packages via gotestsum: 36 tests over 2 seconds, slowest at 6.12 seconds. CI prints the top 30 on every run.

CI billing reality—and a Git Bash privilege trap ​

While the repository was still private, Windows runners billed at 2×. Running the full suite on every push burned roughly 1,284 billable minutes in a single day. That evening we trimmed push/PR runs to single-runner -short, moving the four full shards to nightly runs and mutations to weekly runs—explicitly accepting that slow-tier regressions could take until the next morning to surface.

Once the repo went public on 11 November, standard runners became free and we restored four parallel full Windows shards alongside Linux -race and macOS POSIX runs (~10 minutes wall time), with mutations sharded 8 ways via OBIT_MUTATION_SHARD=k/n.

Why Windows CI must run from pwsh, never Git Bash ​

Early Windows CI runs kept failing our deny-ACL test fixtures: directories marked access-denied were still readable by the code under test.

We initially blamed long TEMP paths and wrote a workaround before discovering the actual cause: MSYS (Git Bash) enables SeBackupPrivilege and SeRestorePrivilege on elevated tokens, and every child process inherits them—completely defeating NTFS deny ACLs. Removing the wrong workaround and running tests directly from pwsh fixed every ACL test on the first run.

Isolation guardrails: real tests must never touch the host ​

Because our tests exercise real system primitives, every test package invokes testenv.Main(m) from TestMain:

  • Redirects data, config, home, and temp directories to disposable per-run folders.
  • Strips inherited GIT_* environment variables and supplies an isolated gitconfig.
  • Redirects registry writes through OBIT_TEST_REGISTRY_ROOT, rejecting any key outside HKCU\Software\obituary-test-* before opening a handle.
  • Snapshots real Explorer menus, login Run keys, Start Menu/Desktop shortcuts, and top-level entries under <drive>\.obituary\graveyard before and after execution—any unexpected diff fails the run immediately.

All posts