Skip to content

Commit b024af9

Browse files
geevensinghCopilot
andcommitted
DiffViewer: fix flaky Start_IgnoredPath_DoesNotFire watcher test
Writing a file inside a directory updates the parent directory's LastWrite timestamp on Windows, which the FileSystemWatcher reports as a separate Changed event on the directory itself - no trailing slash, so the test's ignore predicate (StartsWith(\\ignored/\\)) didn't match it. Whether that event arrived inside the 800 ms wait window was timing-dependent, causing intermittent failures. Production callers don't have this gap: RepositoryService.IsPathIgnored delegates to LibGit2Sharp.Ignore.IsPathIgnored, which (per git semantics for \\ignored/\\) returns true for both the directory and its descendants. The hand-rolled test predicate was an over-narrow stand-in. Broaden the predicate to match both \\ignored\\ exactly and \\ignored/\*\\ descendants. Added a comment explaining why both clauses are required so a future cleanup pass doesn't collapse them back. Verified by running the watcher tests 20x in a row with zero failures. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b21fad2 commit b024af9

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

DiffViewer.Tests/Services/RepositoryWatcherTests.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,19 @@ public void Start_FileCreatedInWorkingTree_FiresChanged()
8787
[Fact]
8888
public void Start_IgnoredPath_DoesNotFire()
8989
{
90-
// Mark every path under "ignored/" as ignored.
91-
Func<string, bool> ignore = rel => rel.StartsWith("ignored/", StringComparison.Ordinal);
90+
// Mark "ignored" itself AND every path under it as ignored.
91+
// Matching both is required because writing a file inside a
92+
// directory updates the parent directory's LastWrite timestamp on
93+
// Windows, which the FSW reports as a separate event on "ignored"
94+
// (no trailing slash). Production callers route through
95+
// LibGit2Sharp.Ignore.IsPathIgnored, which treats `ignored/` as a
96+
// directory-ignore that matches the directory itself too - so a
97+
// predicate that only matches children was an over-narrow stand-in
98+
// and let the parent-directory event leak through, causing flakes
99+
// when Windows happened to deliver that event inside WaitForFire.
100+
Func<string, bool> ignore = rel =>
101+
string.Equals(rel, "ignored", StringComparison.Ordinal) ||
102+
rel.StartsWith("ignored/", StringComparison.Ordinal);
92103
Directory.CreateDirectory(Path.Combine(_workingDir, "ignored"));
93104

94105
using var watcher = new RepositoryWatcher(_workingDir, _gitDir, ignore, FastDebounce);

0 commit comments

Comments
 (0)