Skip to content

Commit 0983f67

Browse files
CodeWhale Botclaude
andcommitted
fix(test): derive the prune cut from recorded timestamps, not a fixed 6s
`prune_older_than_keeps_the_newest_and_drops_only_the_old_tail` fails intermittently on windows-latest with assertion `left == right` failed: only the old tail should be removed left: 3 right: 2 The fixture builds two old snapshots, sleeps 8s, then two new ones 1.1s apart, and cuts at a hardcoded 6s. That assumes `repo.snapshot()` is fast: `new:0` is only ~1.2s plus one git subprocess older than prune time, so on a loaded Windows runner that subprocess alone carries it past the 6s line and it is pruned with the old pair. The existing fixture guard could not catch it — it asserts on `before[0]` and `before[2]`, and `before[1]` is the entry that drifts. The cut is now computed from the timestamps the repo actually recorded: aim at the midpoint of the gap between the oldest survivor and the newest victim, which leaves ~4s of slack in both directions instead of depending on wall-clock luck. The gap itself is asserted first, so a fixture that collapsed says so plainly rather than failing later as a count mismatch. Behaviour under test is unchanged: two removed, `new:1` and `new:0` survive. No production code is touched. cargo clippy -p codewhale-tui --lib -> 0 errors cargo test -p codewhale-tui --lib -- prune_older_than -> test result: ok. 3 passed; 0 failed Found when it failed the windows leg of Hmbown#5987, a PR containing zero Rust files (TypeScript, CI config and .gitignore only), so it cannot have been caused there. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D4rk4NXwyy6wmvii9Lp84P Signed-off-by: CodeWhale Bot <bot@codewhale.net>
1 parent 3f3aa9e commit 0983f67

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

crates/tui/src/snapshot/repo.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,22 +1411,32 @@ mod tests {
14111411
}
14121412
let before = repo.list(usize::MAX).unwrap();
14131413
assert_eq!(before.len(), 4);
1414-
// Guard the fixture itself: if load skewed the timestamps so the cut
1415-
// would not fall between the pairs, say so instead of failing later
1416-
// with a confusing count mismatch.
1414+
// Derive the cut from the timestamps actually recorded rather than a
1415+
// fixed 6s. A fixed cut assumes `repo.snapshot()` is fast: `new:0` is
1416+
// only ~1.2s plus one git subprocess older than prune time, so on a
1417+
// loaded Windows runner that subprocess alone pushed it past 6s and
1418+
// three snapshots were pruned instead of two. (The old fixture guard
1419+
// could not catch it either — it checked `before[0]` and `before[2]`,
1420+
// and `before[1]` is the entry that drifts.)
14171421
let now = std::time::SystemTime::now()
14181422
.duration_since(std::time::UNIX_EPOCH)
14191423
.unwrap()
14201424
.as_secs() as i64;
1425+
// Newest-first: [new:1, new:0, old:1, old:0]. The cut must land
1426+
// strictly between the pairs, so aim at the midpoint of the 8s gap —
1427+
// that leaves ~4s of slack against clock drift and a slow runner in
1428+
// both directions.
1429+
let survivor = before[1].timestamp;
1430+
let victim = before[2].timestamp;
14211431
assert!(
1422-
now - before[0].timestamp < 6 && now - before[2].timestamp > 6,
1423-
"fixture ages unusable for a 6s cut (newest {}s, oldest-surviving-pair {}s)",
1424-
now - before[0].timestamp,
1425-
now - before[2].timestamp
1432+
survivor - victim >= 2,
1433+
"fixture needs a real gap between the pairs (survivor {survivor}, victim {victim})"
14261434
);
1435+
let midpoint = victim + (survivor - victim) / 2;
1436+
let max_age = Duration::from_secs((now - midpoint).max(0) as u64);
14271437

1428-
// Cut 6s back: the two old snapshots drop, the two new ones survive.
1429-
let removed = repo.prune_older_than(Duration::from_secs(6)).unwrap();
1438+
// The two old snapshots drop, the two new ones survive.
1439+
let removed = repo.prune_older_than(max_age).unwrap();
14301440
assert_eq!(removed, 2, "only the old tail should be removed");
14311441

14321442
let remaining = repo.list(usize::MAX).unwrap();

0 commit comments

Comments
 (0)