From 32b8c521d93f54f8a53a4be94f287d714b4bc2b8 Mon Sep 17 00:00:00 2001 From: Atri10 <64589033+Atri10@users.noreply.github.com> Date: Mon, 19 Oct 2026 16:29:08 +0530 Subject: [PATCH] fix(scripts): compare the bundle by bytes, not a timestamp cache filecmp.cmp(shallow=False) keys its cached verdict on int(st_mtime), so a drift check that followed a same-second sync returned the pre-write answer. The Windows runner hit this: test_sync_rewrites_a_stale_bundle _and_drops_orphans saw 'stale in the bundle: a.py' right after sync() had rewritten it. sync_engine.same() now compares read_bytes() directly, and a regression test forces identical mtimes with os.utime to pin the same-second case. --- CHANGELOG.md | 14 +++++++++---- README.md | 2 +- engine/tests/test_engine_ships_with_skill.py | 22 ++++++++++++++++++++ scripts/sync_engine.py | 12 ++++++++--- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e403b3c..42d64b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,11 @@ project is tagged; between releases, entries are dated and `main` moves. ## [2.0.3] — 2026-10-19 Patch release: the Windows suite goes green. The v2.0.2 install path was -correct on POSIX, but Windows exposed two failures the matrix caught after -the release was tagged: `--help` crashed under the cp1252 pipe encoding, and -a test tried to execute the launcher as a native program, which Windows -cannot do. +correct on POSIX, but the matrix — and the main-branch run that followed — +exposed three failures: `--help` crashed under the cp1252 pipe encoding, a +test tried to execute the launcher as a native program, which Windows cannot +do, and the bundle check trusted a whole-second timestamp cache instead of +the bytes. ### Fixed @@ -23,6 +24,11 @@ cannot do. stdout and stderr where the stream supports it, so help text, JSON with `ensure_ascii=False`, and error messages survive a redirect on a non-UTF-8 Windows console. +- **The bundle check compares bytes, not cached metadata.** `filecmp.cmp` + keys its verdict on `int(st_mtime)`, so a drift check that followed a + same-second rewrite could report a file stale that had just been synced. + `scripts/sync_engine.py` now compares contents directly, and a regression + test pins the same-second case with a forced mtime. - **The bare-launcher test is POSIX-only.** Windows has no exec bit and `CreateProcess` cannot run a `.py` file without a registered association. The portable spelling — `python3 /scripts/executor` — diff --git a/README.md b/README.md index d4cc54e..d50dfb2 100644 --- a/README.md +++ b/README.md @@ -572,7 +572,7 @@ flowchart TD | Path | What it is | |---|---| | `engine/executor/` | the engine source: `cli.py`, `engine.py`, `schemas.py`, `paths.py`, `store.py`, `views.py`, `policy.py` | -| `engine/tests/` | the suite (741 tests), including the tree-walking contract tests | +| `engine/tests/` | the suite (742 tests), including the tree-walking contract tests | | `skills/executor/` | the router skill, its prompt templates, the references, and the engine that ships with it | | `skills/executor/scripts/executor` | the launcher; resolves `scripts/lib/executor/` relative to itself | | `skills/executor/scripts/lib/executor/` | the installed engine — a generated mirror of `engine/executor/` | diff --git a/engine/tests/test_engine_ships_with_skill.py b/engine/tests/test_engine_ships_with_skill.py index ba73282..6c59856 100644 --- a/engine/tests/test_engine_ships_with_skill.py +++ b/engine/tests/test_engine_ships_with_skill.py @@ -23,6 +23,7 @@ import subprocess import sys import tempfile +import time import unittest from contextlib import redirect_stderr, redirect_stdout from pathlib import Path @@ -88,6 +89,27 @@ def test_sync_rewrites_a_stale_bundle_and_drops_orphans(self): self.assertEqual((dst / "a.py").read_text(encoding="utf-8"), "A = 1\n") + def test_drift_ignores_cached_file_timestamps(self): + """A same-second rewrite must be seen: a metadata-keyed comparison + once let a fresh write read as stale.""" + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + src, dst = root / "engine", root / "bundle" + for d in (src, dst): + d.mkdir() + (src / "a.py").write_text("A = 1\n", encoding="utf-8") + (dst / "a.py").write_text("A = 2\n", encoding="utf-8") + stamp = int(time.time()) + os.utime(src / "a.py", (stamp, stamp)) + os.utime(dst / "a.py", (stamp, stamp)) + with mock.patch.object(sync_engine, "SOURCE", src), \ + unittest.mock.patch.object(sync_engine, "BUNDLE", dst): + self.assertEqual(sync_engine.drift(), + ["stale in the bundle: a.py"]) + sync_engine.sync() + os.utime(dst / "a.py", (stamp, stamp)) + self.assertEqual(sync_engine.drift(), []) + class SyncEngineCli(unittest.TestCase): """`sync_engine.py` is the only writer of the bundle, so its own exit diff --git a/scripts/sync_engine.py b/scripts/sync_engine.py index 44217cc..b9049db 100755 --- a/scripts/sync_engine.py +++ b/scripts/sync_engine.py @@ -19,7 +19,6 @@ from __future__ import annotations import argparse -import filecmp import sys from pathlib import Path @@ -34,6 +33,13 @@ def modules(directory: Path) -> dict[str, Path]: return {p.name: p for p in sorted(directory.glob("*.py")) if p.is_file()} +def same(a: Path, b: Path) -> bool: + """Content equality, by bytes. `filecmp.cmp(shallow=False)` caches its + verdict on whole-second mtimes, so a check that follows a same-second + rewrite can report the pre-rewrite answer.""" + return a.read_bytes() == b.read_bytes() + + def drift() -> list[str]: """Every way the bundle disagrees with the source, as readable lines.""" src, dst = modules(SOURCE), modules(BUNDLE) @@ -43,7 +49,7 @@ def drift() -> list[str]: for name in sorted(set(dst) - set(src))] problems += [f"stale in the bundle: {name}" for name in sorted(set(src) & set(dst)) - if not filecmp.cmp(src[name], dst[name], shallow=False)] + if not same(src[name], dst[name])] return problems @@ -55,7 +61,7 @@ def sync() -> list[str]: changed = [] for name in sorted(src): target = BUNDLE / name - if name in dst and filecmp.cmp(src[name], target, shallow=False): + if name in dst and same(src[name], target): continue target.write_bytes(src[name].read_bytes()) changed.append(name)