Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Take the Linux subdirectory-watch race out of the compiler watcher test (#11362)

Daniel Han675b61ac151e
diff --git a/tests/studio/test_installer_av_shapes.py b/tests/studio/test_installer_av_shapes.py
index 471213ed0a3..a38fdd4aa13 100644
--- a/tests/studio/test_installer_av_shapes.py
+++ b/tests/studio/test_installer_av_shapes.py
@@ -927,8 +927,16 @@ function Get-WinEvent {
"""
-def _run_watch(tmp_path, action: str) -> tuple[str, list[str]]:
- """Drive the real Invoke-WithCompilerWatch over $Action, with TEMP pointed at tmp_path."""
+def _run_watch(
+ tmp_path,
+ action: str,
+ setup: str = "",
+) -> tuple[str, list[str]]:
+ """Drive the real Invoke-WithCompilerWatch over $Action, with TEMP pointed at tmp_path.
+
+ ``setup`` runs BEFORE the watch starts, for the one case that needs a directory to
+ already exist and already be watched when the action writes into it.
+ """
temp_root = tmp_path / "temp"
temp_root.mkdir()
evidence = tmp_path / "evidence"
@@ -941,6 +949,7 @@ def _run_watch(tmp_path, action: str) -> tuple[str, list[str]]:
f'$env:TMP = "{temp_root.as_posix()}"',
_FAKE_WINEVENT,
f'. "{_WATCHER}"',
+ setup,
f"$action = {{ {action} }}",
"$seen = Invoke-WithCompilerWatch -Name 'probe' -Action $action "
f'-EvidenceRoot "{evidence.as_posix()}"',
@@ -968,20 +977,46 @@ def test_the_watcher_sees_intermediates_the_compiler_cleaned_up(tmp_path) -> Non
directory once the assembly is loaded. Comparing a listing taken before against one
taken after cannot see a file that no longer exists, so the job failed as a broken
detector on every run since it was added.
+
+ The directory is staged BEFORE the watch starts, and that is the whole reason this
+ test is reliable. It used to be created inside the action, which is what CodeDom
+ does, and which is unobservable here: `IncludeSubdirectories` is recursive in the
+ kernel on Windows, but off Windows .NET emulates it by adding an inotify watch per
+ directory, and it adds the one for a new subdirectory after the fact. A file written
+ into a brand-new subdirectory microseconds later can land before its watch does and
+ never be raised at all. Measured driving the same shape in a loop, idle: 1 miss in
+ 60. On a two-core hosted runner it landed as COUNT:0 on a pull request that touches
+ none of this (Backend CI job 105986532571, `Repo tests (CPU, studio)`).
+
+ There is nothing to synchronise on either, so a wait is the only alternative and a
+ wait is just a wider race. The watcher's NotifyFilter is FileName, which does not
+ raise a directory's own creation: measured, 0 of 1 under FileName and 1 of 1 once
+ DirectoryName is added, so the event that would say "the subdirectory is watched
+ now" is deliberately not in the stream, and widening the production filter to put it
+ there would change what the detector records.
+
+ What is under test does not need a new directory. The claim is that a file which no
+ longer exists when the action returns is still reported, and the only detector that
+ can make it is the live stream: the before-listing is taken while the directory is
+ empty, the after-listing sees a directory that is gone. Staging the directory removes
+ the platform's timing from the measurement without touching the claim.
"""
+ setup = (
+ '$staged = Join-Path $env:TEMP "vpmyd5eq"; '
+ "New-Item -ItemType Directory -Force -Path $staged | Out-Null"
+ )
action = (
- '$dir = Join-Path $env:TEMP "abcd1234"; '
- "New-Item -ItemType Directory -Force -Path $dir | Out-Null; "
- 'Set-Content -LiteralPath (Join-Path $dir "abcd1234.cmdline") -Value "/noconfig"; '
- 'Set-Content -LiteralPath (Join-Path $dir "abcd1234.dll") -Value "MZ"; '
+ '$dir = Join-Path $env:TEMP "vpmyd5eq"; '
+ 'Set-Content -LiteralPath (Join-Path $dir "vpmyd5eq.cmdline") -Value "/noconfig"; '
+ 'Set-Content -LiteralPath (Join-Path $dir "vpmyd5eq.dll") -Value "MZ"; '
"Start-Sleep -Milliseconds 400; "
# The whole point: gone before the action returns, exactly as CodeDom leaves it.
"Remove-Item -LiteralPath $dir -Recurse -Force"
)
- stdout, libraries = _run_watch(tmp_path, action)
+ stdout, libraries = _run_watch(tmp_path, action, setup = setup)
assert libraries, f"a compile that cleaned up after itself was missed again: {stdout}"
- assert any(lib.endswith(".cmdline") for lib in libraries), libraries
- assert any(lib.endswith(".dll") for lib in libraries), libraries
+ assert any(lib.endswith("vpmyd5eq.cmdline") for lib in libraries), libraries
+ assert any(lib.endswith("vpmyd5eq.dll") for lib in libraries), libraries
@pytest.mark.skipif(shutil.which("pwsh") is None, reason = "needs PowerShell")