Skip to content

fix(tests): keep same-size edits out of the stamp time tick - #508

Merged
16bit-ykiko merged 1 commit into
mainfrom
fix/stamp-test-tick
Jul 13, 2026
Merged

16bit-ykiko merged 1 commit into
mainfrom
fix/stamp-test-tick

Conversation

@16bit-ykiko

@16bit-ykiko 16bit-ykiko commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Both Windows CI jobs are red on main since #507 (its own merge run 29258064794 failed): MergedIndex.NeedUpdateChecksAllContexts and MergedIndex.SerializedStampsValidate fail deterministically with need_update() expected true, got false.

Root cause

Windows file times advance in ~16ms clock ticks. The failing assertions perform same-size rewrites (int b2(); → int b3();, int f(); → int g();) moments after the stamp was recorded; when the rewrite lands in the same tick, the file reproduces the stamp's size and mtime exactly, so the stat fast path — equality-based by design — rightly reports fresh, and the hash layer the assertions meant to exercise is never consulted. On Linux/macOS nanosecond timestamps always move, which is why only Windows fails.

Production is immune: merge only records a stamp for files untouched since two seconds before the build (stat_baseline_before_ns), so a stamped file's later edit can never share its tick. The tests defeat that guard deliberately (generous_build_at() = now + 10s) to earn the fast path, which is what exposes them to the tick.

Fix

After each same-size rewrite, bump the file's mtime explicitly (set_file_mtime, +5s) — modelling the reality that a genuine edit arrives long after the stamp, and pinning those verdicts on the hash layer as intended. Test-only change; no product code touched.

Windows file times advance in ~16ms ticks, so a same-size rewrite
landing in the tick that produced the recorded stamp reproduces size
and mtime exactly — the stat fast path rightly calls that fresh, and
NeedUpdateChecksAllContexts / SerializedStampsValidate failed
deterministically on both Windows runners (main is red since #507).
Production stamps are immune: merge only stamps files untouched since
two seconds before the build, so a later edit can never share their
tick. The tests defeat that guard on purpose via generous_build_at;
bump the mtime explicitly after same-size edits so the verdict rests
on the hash layer, which is what these assertions exercise.
@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Merged-index tests now explicitly adjust dependency file modification times after rewrites and edits, ensuring update decisions consistently exercise the intended mtime and content-hash validation layers across platforms.

Changes

Merged-index freshness validation

Layer / File(s) Summary
Timestamp-controlled update assertions
tests/unit/index/merged_index_tests.cpp
Dependency rewrites and serialized-stamp edits now explicitly bump file mtimes before asserting MergedIndex::need_update() results.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • clice-io/clice#507: Updates the merged-index freshness model and related staleness tests.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the test-only fix for same-size edits and filesystem timestamp tick flakiness.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/stamp-test-tick

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/unit/index/merged_index_tests.cpp (1)

740-740: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider asserting set_file_mtime return values.

set_file_mtime returns false on failure (e.g., file doesn't exist, permission error). If it silently fails, the mtime isn't bumped and the test may pass or flake for the wrong reason. An ASSERT_TRUE(set_file_mtime(...)) would catch this. This is a pre-existing pattern (lines 769 and 794 also ignore the return), so it's not blocking — just noting for future hardening.

Also applies to: 748-748, 801-801

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/index/merged_index_tests.cpp` at line 740, Assert that every
set_file_mtime call in the affected test cases succeeds, including the calls
near the existing updates at lines 740, 748, and 801. Wrap each invocation with
ASSERT_TRUE so failures are reported immediately instead of allowing the test to
continue with an unchanged modification time.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/unit/index/merged_index_tests.cpp`:
- Line 740: Assert that every set_file_mtime call in the affected test cases
succeeds, including the calls near the existing updates at lines 740, 748, and
801. Wrap each invocation with ASSERT_TRUE so failures are reported immediately
instead of allowing the test to continue with an unchanged modification time.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cca6267f-4bf7-48b1-bd85-ff8a3bc25d93

📥 Commits

Reviewing files that changed from the base of the PR and between 77a53b8 and 6ec1b3d.

📒 Files selected for processing (1)
  • tests/unit/index/merged_index_tests.cpp

@16bit-ykiko
16bit-ykiko merged commit 7c81744 into main Jul 13, 2026
22 checks passed
@16bit-ykiko
16bit-ykiko deleted the fix/stamp-test-tick branch July 13, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant