apm icon indicating copy to clipboard operation
apm copied to clipboard

[BUG] Windows CI fails due to CRLF baseline output, missing ratchet baseline authority detection, and WebSocket shutdown warning

Open fabuchimk2 opened this issue 4 months ago • 1 comments

Describe the bug

Commit 5b20a65f219a1b68212c44cc872f72c2163e5764 causes the test suite to fail on the Windows GitHub Actions runner.

The test run reports three failures:

  1. The canonical JSON baseline is written with Windows-style CRLF line endings (\r\n), while the test expects platform-independent LF line endings (\n).
  2. The contract authority checker does not detect a missing import from the shared ratchet_baseline owner in scripts/check_test_assertions.py.
  3. The contract authority checker does not detect a missing import from the shared ratchet_baseline owner in scripts/check_exact_test_duplicates.py.

The same test run also produces a PytestUnhandledThreadExceptionWarning during WebSocket test server shutdown on Windows:

OSError: [WinError 10038] An operation was attempted on something that is not a socket

The WebSocket warning does not appear to be the direct cause of the current non-zero exit code, but it could cause a failure when warnings are treated as errors.

To Reproduce

Steps to reproduce the behavior:

  1. Check out the affected commit:

    git checkout 5b20a65f219a1b68212c44cc872f72c2163e5764
    
  2. Install the project dependencies.

  3. Run the full test suite on Windows:

    uv run --frozen pytest
    
  4. Alternatively, run the failing tests individually:

    uv run --frozen pytest tests/unit/scripts/test_check_test_assertions.py::test_update_writes_reduced_canonical_baseline -q
    
    uv run --frozen pytest tests/unit/scripts/test_check_test_contract_authorities.py::test_ratchet_consumers_must_import_baseline_owner -q
    
    uv run --frozen pytest tests/unit/integration/test_copilot_app_ws.py::TestHandshake::test_app_not_running_raises_app_not_running -q
    
  5. Observe that:

    • The generated baseline uses \r\n instead of \n.
    • The authority checker does not report the removed ratchet_baseline imports.
    • The WebSocket server thread raises WinError 10038 during shutdown.

Expected behavior

The test suite should pass consistently on Windows and Unix-like systems.

Specifically:

  • Canonical JSON baseline files should always be written with LF line endings, regardless of the operating system.
  • The contract authority checker should report a violation when either ratchet consumer does not import the shared ratchet_baseline owner.
  • The WebSocket test server should shut down cleanly without producing an unhandled thread exception warning.

Environment (please complete the following information):

  • OS: Windows, GitHub Actions hosted runner
  • Python Version: 3.12.10
  • APM Version: Commit 5b20a65f219a1b68212c44cc872f72c2163e5764
  • VSCode Version (if relevant): Not applicable

Logs

tests/unit/integration/test_copilot_app_ws.py::TestHandshake::test_app_not_running_raises_app_not_running
  D:\a\apm\apm\.venv\Lib\site-packages\_pytest\threadexception.py:58:
  PytestUnhandledThreadExceptionWarning:
  Exception in thread Thread-291 (serve_forever)

  Traceback (most recent call last):
    File "C:\hostedtoolcache\windows\Python\3.12.10\x64\Lib\threading.py", line 1075, in _bootstrap_inner
      self.run()
    File "C:\hostedtoolcache\windows\Python\3.12.10\x64\Lib\threading.py", line 1012, in run
      self._target(*self._args, **self._kwargs)
    File "D:\a\apm\apm\.venv\Lib\site-packages\websockets\sync\server.py", line 275, in serve_forever
      poller.select()
    File "C:\hostedtoolcache\windows\Python\3.12.10\x64\Lib\selectors.py", line 323, in select
      r, w, _ = self._select(self._readers, self._writers, [], timeout)
    File "C:\hostedtoolcache\windows\Python\3.12.10\x64\Lib\selectors.py", line 314, in _select
      r, w, x = select.select(r, w, w, timeout)
  OSError: [WinError 10038] An operation was attempted on something that is not a socket
FAILED tests/unit/scripts/test_check_test_assertions.py::test_update_writes_reduced_canonical_baseline

assert b'{\r\n  "rules"...\r\n}\r\n' == b'{\n  "rules"...\n}\n'

At index 1 diff: b'\r' != b'\n'
FAILED tests/unit/scripts/test_check_test_contract_authorities.py::test_ratchet_consumers_must_import_baseline_owner[scripts/check_test_assertions.py]

assert False
FAILED tests/unit/scripts/test_check_test_contract_authorities.py::test_ratchet_consumers_must_import_baseline_owner[scripts/check_exact_test_duplicates.py]

assert False
=========================== short test summary info ===========================
FAILED tests/unit/scripts/test_check_test_assertions.py::test_update_writes_reduced_canonical_baseline
FAILED tests/unit/scripts/test_check_test_contract_authorities.py::test_ratchet_consumers_must_import_baseline_owner[scripts/check_test_assertions.py]
FAILED tests/unit/scripts/test_check_test_contract_authorities.py::test_ratchet_consumers_must_import_baseline_owner[scripts/check_exact_test_duplicates.py]
= 3 failed, 18699 passed, 77 skipped, 21 xfailed, 22 warnings in 134.02s (0:02:14) =
Error: Process completed with exit code 1.

Additional context

The affected commit is:

5b20a65f219a1b68212c44cc872f72c2163e5764

Commit title:

test: add finite taxonomy and quality ratchets (#2198)

The line-ending failure appears to be Windows-specific. Writing the canonical JSON through a normal text-mode API converts \n to \r\n on Windows. Writing the serialized JSON as UTF-8 bytes, or explicitly opening the output file with newline="\n", should make the output platform-independent.

The two authority contract failures may indicate that the shared ratchet_baseline owner and its tests were introduced without fully updating the authority checker. Both of the following consumers should be required to import the shared baseline owner:

scripts/check_test_assertions.py
scripts/check_exact_test_duplicates.py

The WebSocket warning is likely caused by the server socket being closed while the background server thread is still blocked in select(). The test helper may need to wait for the server thread to terminate and handle only the expected Windows socket-shutdown error.

fabuchimk2 avatar Jul 15 '26 19:07 fabuchimk2

Status update

PR #2237 has been driven to a merge-ready state. This turned out to be a broader systemic defect than the original report: current main (as of b44bc29edf12fd7bdf7f2c2b437bedb4224be405) had accumulated 2 additional Windows-only failure signatures beyond the two originally reported here, all sharing the same root cause -- Windows CI only runs post-merge, so Windows regressions are invisible at PR time.

All 4 failure signatures fixed, each at its canonical owner

  1. CRLF baseline drift (ratchet_baseline.py, run_mutation_pilot.py) -- both scripts had hand-rolled write-then-replace logic instead of using the existing atomic writer. Fixed by delegating to apm_cli.utils.atomic_io.atomic_write_text.
  2. Authority-check regression (check_test_contract_authorities.py) -- raw Path objects interpolated into f-strings emitted backslash paths on Windows, breaking authority-detection string matching. Fixed via .as_posix() at every interpolation site.
  3. Shepherd owner-touch-gate FileNotFoundError: [WinError 2] (test_shepherd_owner_touch_gate.py, owner_touch_gate.py) -- bare ["git", ...] argv is not PATH-searched by Windows CreateProcess when shell=False. Fixed by routing through the existing canonical owner apm_cli.utils.git_env.get_git_executable() (test helper) and a self-contained shutil.which-based cache (the standalone shepherd-driver skill script, which cannot depend on apm_cli).
  4. WebSocket shutdown warning (this issue's original report) -- websockets.sync.server skips its self-pipe shutdown signal on win32, causing OSError: [WinError 10038] during a concurrent shutdown. Fixed with a narrow per-thread wrapper that catches only that exact platform+winerror combination.

CI hardened so this class cannot recur unnoticed

Added a new Windows Compatibility Gate CI job that runs a focused, contract-pinned cross-platform test subset (225 tests, 15-minute timeout) at PR time -- not just post-merge on main. A dedicated test suite pins the job's scope and timeout so it cannot silently balloon into a full-suite duplicate.

Verification

Full canonical lint mirror clean; 19253+ tests passing across all CI-matching scopes; thread-sensitive files re-run 5x with zero flakiness; apm-review-panel (9 specialist personas + CEO synthesis) and docs-sync advisory reviews both completed with no blocking findings.

See PR #2237 for full details, root-cause table, and test evidence. Not yet merged.

danielmeppiel avatar Jul 16 '26 10:07 danielmeppiel