Skip to content

test(picker/summary): sleep between writes to avoid mtime tick collision - #2433

Merged
max-sixty merged 1 commit into
mainfrom
fix/issue-2432
Apr 27, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/issue-2432

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Problem

test_cache_roundtrip_and_prune_on_write flaked on PR #2429's code-coverage job (logs) — the assertion that deadbeef was pruned after writing cafebabe failed, then a rerun passed.

Root cause: sweep_lru (src/cache.rs:126) sorts entries by file mtime to pick the eviction victim. The test wrote deadbeef and cafebabe back-to-back with no delay; on filesystems with coarse mtime resolution both files can share a tick, making eviction order nondeterministic and sometimes pruning the newer entry instead.

Solution

Add a 10 ms sleep between the two writes — the same gap test_sweep_lru_trims_oldest_entries (src/cache.rs:319-322) already uses for the same reason.

Testing

Targeted test passes locally; the broader commands::picker::summary::tests and cache::tests modules still pass.


Closes #2432 — automated triage

@worktrunk-bot worktrunk-bot added the automated-fix Automated CI fix label Apr 27, 2026
@max-sixty
max-sixty merged commit e4fa2d8 into main Apr 27, 2026
23 checks passed
@max-sixty
max-sixty deleted the fix/issue-2432 branch April 27, 2026 16:27
max-sixty added a commit that referenced this pull request May 4, 2026
…#2586)

The test wrote `tracked.txt` as `"original"` then `"modified"` — both 8
bytes. `wt step commit --dry-run --stage=tracked` runs `git add -u`
against a copy of the index, so the only signal git has for the
modification is mtime. On Linux/ext4 the recorded entry mtime and the
post-modification mtime can be indistinguishable at the kernel's
resolution; git treats the file as unchanged, the temp index keeps the
old blob hash, and `git diff --staged` returns nothing. The rendered
prompt then has empty `<diffstat>` / `<diff>` blocks and the assertion
on `"tracked.txt"` / `"modified"` fires.

Reproduces 0/200 locally on macOS APFS and passes on `test (linux)`, but
flaked on the `affected (linux, advisory)` job for PR #2581
([logs](https://github.com/max-sixty/worktrunk/actions/runs/25306727293/job/74184225239))
— that PR only touched PowerShell shell config and has no plausible
effect on this code path.

Switching the modification to `"modified content"` makes the new size
differ from the committed blob, so git's DATA_CHANGED check fires
unconditionally and the test no longer depends on mtime resolution. This
mirrors the adjacent `test_step_commit_with_stage_tracked_flag`
(`merge.rs:2113`) which uses `"initial"` → `"modified"` (different
sizes) for the same reason. PR #2433 fixed an analogous mtime-tick
collision in the picker/summary tests.

The `stdout.contains("modified")` assertion still passes since
`"modified"` is a prefix of the new content.

> _This was written by Claude Code on behalf of @max-sixty_

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flake: test_cache_roundtrip_and_prune_on_write fails when writes share an mtime tick

2 participants