Skip to content

[Repo Assist] fix: fix flaky test infrastructure - empty diagnostics buffer and directory cleanup failures#1521

Draft
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-flaky-diagnostics-test-20260405-ebc63397a93dba3a
Draft

[Repo Assist] fix: fix flaky test infrastructure - empty diagnostics buffer and directory cleanup failures#1521
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-flaky-diagnostics-test-20260405-ebc63397a93dba3a

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 5, 2026

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Fixes two distinct flaky test infrastructure issues that cause intermittent test failures.

Fix 1: Empty diagnostics buffer in waitForLatestDiagnostics

Root cause: waitForLatestDiagnostics in Server.fs uses Observable.bufferSpan to collect diagnostic notifications. For error-free code, the LSP server sends no publishDiagnostics notifications, so the buffer emits an empty IList<Diagnostic[]>. Calling Seq.last on this empty list throws System.InvalidOperationException: The input sequence was empty.

Observed failure:

InlayHint.voption.show: for custom function
System.InvalidOperationException: The input sequence was empty
   at Microsoft.FSharp.Collections.SeqModule.Last[T](IEnumerable`1 source)
   at ... waitForLatestDiagnostics@301

Fix: Replace Seq.last with Seq.tryLast |> Option.defaultValue [||] — an empty buffer returns [||] (no diagnostics), which is the correct result for error-free code.

Fix 2: Directory cleanup failures in dotnetCleanup

Root cause: On macOS + .NET 10, Directory.Delete(path, true) fails with IOException: Directory not empty because background .NET SDK processes (hot reload daemon, file watchers) may hold locks on files in obj/Debug during test cleanup. This causes ~15 test failures on the macos-15 / net10.0 / TransparentCompiler CI matrix.

Fix: Wrap Directory.Delete in a try/catch with a 200ms retry. If both attempts fail, silently ignore the error — the test result is valid even if the temp directory persists.

Files Changed

  • test/FsAutoComplete.Tests.Lsp/Utils/Server.fsSeq.lastSeq.tryLast |> Option.defaultValue [||]
  • test/FsAutoComplete.Tests.Lsp/Helpers.fs — retry/fallback in dotnetCleanup

Test Status

  • ✅ Build: dotnet build -f net8.0 passes
  • ✅ Format: dotnet fantomas --check passes
  • ℹ️ Full test suite not run locally (would take 20+ min), but the fixes are targeted to the exact failure signatures observed in CI

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@7ee2b60744abf71b985bead4599640f165edcd93

github-actions bot and others added 2 commits April 5, 2026 04:46
When the language server does not publish any diagnostics (e.g. for
error-free code), the Observable.bufferSpan window completes with an
empty IList. The previous Seq.last call threw 'The input sequence was
empty', causing intermittent test failures in tests like the InlayHint
voption 'show: for custom function' test.

Change Seq.last to Seq.tryLast |> Option.defaultValue [||] to return
an empty diagnostics array instead of throwing when no diagnostic
notifications are received.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
On some platforms (notably macOS with .NET 10), Directory.Delete with
recursive=true can fail with 'Directory not empty' when background SDK
processes (e.g., hot reload daemon) still hold file locks. This caused
15 test failures in Go-to-definition tests on macOS+net10.0 CI matrix.

Change dotnetCleanup to retry once after 200ms and then silently ignore
cleanup failures. Stale build artifacts from a previous run are not
critical -- tests still produce correct results.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants