@@ -78,6 +78,42 @@ def append(path: Path, data: bytes) -> None:
7878 stream .write (data )
7979
8080
81+ @pytest .mark .parametrize ("kind" , ["stable" , "changed-ctime" , "wrong-inode" ])
82+ def test_snapshot_windows_stat_difference (
83+ tmp_path : Path , monkeypatch : pytest .MonkeyPatch , kind : str
84+ ) -> None :
85+ path = tmp_path / "sample.txt"
86+ path .write_bytes (b"Current content" )
87+ original = path .lstat ()
88+ real_fstat = os .fstat
89+ calls = 0
90+
91+ def descriptor_stat (fd : int ) -> os .stat_result :
92+ nonlocal calls
93+ calls += 1
94+ info = real_fstat (fd )
95+ fields = list (info )
96+ if kind == "wrong-inode" :
97+ fields [1 ] += 1
98+ ctime = original .st_ctime_ns + 1_000_000_000
99+ if kind == "changed-ctime" and calls > 1 :
100+ ctime += 1
101+ return os .stat_result (
102+ fields , {"st_mtime_ns" : info .st_mtime_ns , "st_ctime_ns" : ctime }
103+ )
104+
105+ with monkeypatch .context () as patch :
106+ patch .setattr (sys , "platform" , "win32" )
107+ patch .setattr (os , "fstat" , descriptor_stat )
108+ if kind == "stable" :
109+ first = initialize .snapshot (path )
110+ assert first .data == b"Current content"
111+ assert first == initialize .snapshot (path )
112+ else :
113+ with pytest .raises (initialize .InitializationError , match = "input changed" ):
114+ initialize .snapshot (path )
115+
116+
81117def test_help_and_preview (project : Path ) -> None :
82118 original = files (project )
83119 help_result = run (project , "--help" )
@@ -181,7 +217,8 @@ def test_edited_readmes_preserve_current_content(project: Path, eol: bytes) -> N
181217 cover .write_bytes (b"synthetic cover bytes" )
182218 originals = {}
183219 for path in READMES :
184- relative = COVER .as_posix () if path .parent == Path ("." ) else f"../../../{ COVER } "
220+ prefix = "" if path .parent == Path ("." ) else "../../../"
221+ relative = f"{ prefix } { COVER .as_posix ()} "
185222 custom = (
186223 (
187224 "# A maintained heading \n \n "
0 commit comments