From 359eae93de55fa8dcf75ebee99f0283d8461aa2c Mon Sep 17 00:00:00 2001 From: nesquena-hermes Date: Mon, 29 Jun 2026 01:59:22 +0000 Subject: [PATCH] test: de-flake test_skills_stats_cache mtime race test_skills_stats_cache asserted that adding a skill bumps the skills-dir mtime so the cheap per-call probe recomputes counts on the next call. Two _write_skill() calls inside the same coarse filesystem mtime tick could leave the skills-dir mtime byte-identical to the cached probe value, so the probe saw no change and served the stale count of 1 (assert enabled==2 failed). This is an order-dependent flake: passes in isolation, fails intermittently under full-suite ordering (observed across multiple unrelated PRs). Force the skills-dir mtime strictly forward after the second write so the probe is guaranteed to detect a genuine mtime change. The assertion stays honest (it still proves recompute-on-mtime-change); only the race is removed. --- tests/test_profile_skills_stats.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_profile_skills_stats.py b/tests/test_profile_skills_stats.py index 6e3f46b05..bf7276d36 100644 --- a/tests/test_profile_skills_stats.py +++ b/tests/test_profile_skills_stats.py @@ -144,6 +144,17 @@ def test_skills_stats_cache(tmp_path): # Adding a skill bumps the skills-dir mtime; the cheap probe detects it on # the very next call and the counts update immediately (no stale TTL window). _write_skill(tmp_path, "beta") + # Guarantee the skills-dir mtime is STRICTLY newer than the cached probe value. + # A real FS-backed skill-add always advances the dir mtime, but two writes inside + # the same coarse mtime tick can leave it byte-identical under full-suite timing — + # the source of this test's intermittent flake (order-dependent: passes in + # isolation, fails ~intermittently under full-suite ordering). Forcing it forward + # keeps the assertion honest (the probe must recompute on a genuine mtime change) + # without racing the filesystem's mtime granularity. + import os as _os, time as _time + _skills_dir = tmp_path / "skills" + _future = _time.time() + 5 + _os.utime(_skills_dir, (_future, _future)) enabled, compat = profiles._get_profile_skills_stats(tmp_path) assert enabled == 2 and compat == 2