Skip to content

fix(tests): resolve test collection and execution failures on Windows - #2028

Open
prasad2512 wants to merge 1 commit into
anthropics:mainfrom
prasad2512:fix-windows-test-suite-2027
Open

prasad2512 wants to merge 1 commit into
anthropics:mainfrom
prasad2512:fix-windows-test-suite-2027

Conversation

@prasad2512

Copy link
Copy Markdown

Fixes #2027

Summary

Resolves multiple test collection and test execution errors encountered when running the test suite on Windows / non-POSIX platforms:

  1. Guard os.geteuid() against AttributeError during pytest collection:
    In tests/lib/tools/test_file_store.py (lines 207 & 317) and tests/lib/tools/memory_sync/test_delete_discipline.py (line 168), @pytest.mark.skipif(os.geteuid() == 0, ...) crashed test collection on Windows with AttributeError: module 'os' has no attribute 'geteuid' because os.geteuid is POSIX-only. Added os.name != "posix" or getattr(os, "geteuid", lambda: -1)() == 0 guards. Also guarded the runtime check in tests/lib/tools/memory_sync/test_memory_sync.py:372 to match test_credentials.py and test_agent_toolset.py.

  2. Skip non-POSIX platforms on memory sync suites:
    FileStore requires O_NOFOLLOW support and explicitly refuses non-POSIX platforms (_platform_supported() raising RuntimeError: FileStore requires O_NOFOLLOW support on this platform). While test_file_store.py already carried pytestmark = pytest.mark.skipif(os.name != "posix", reason="FileStore refuses non-POSIX platforms"), test_memory_sync.py and test_delete_discipline.py were missing this file-level skip marker. Added the marker so these suites skip cleanly on Windows.

  3. Resolve NamedTemporaryFile lock contention in Bedrock tests:
    In tests/lib/test_bedrock.py, mock_aws_config opened tempfile.NamedTemporaryFile(mode="w+", delete=True) in a context manager. On Windows, an open temporary file cannot be opened by a second process/handle, causing boto3.Session to raise botocore.exceptions.ProfileNotFound and fail 4 tests (test_region_infer_from_profile, test_region_infer_from_specified_profile, and test_region_infer_from_aws_profile_argument). Replaced with pytest's built-in tmp_path fixture.

  4. Mark remaining symlink tests in test_agent_toolset.py:
    Added @needs_symlinks marker to test_read_through_symlink_escape_is_rejected, test_glob_post_filters_symlink_escape, and test_grep_skips_symlinked_files to avoid WinError 1314 privilege failures on Windows.

Tests Verified

  • uv run pytest -n 0 tests/lib/test_bedrock.py tests/lib/tools/test_file_store.py tests/lib/tools/memory_sync/test_delete_discipline.py tests/lib/tools/memory_sync/test_memory_sync.py tests/lib/tools/test_agent_toolset.py (103 passed, 105 skipped, 0 failures)
  • uv run ruff check tests/lib/test_bedrock.py tests/lib/tools/ (All checks passed)
  • uv run ruff format --check tests/lib/test_bedrock.py tests/lib/tools/ (All formatted)
  • uv run pyright tests/lib/test_bedrock.py tests/lib/tools/ (0 errors, 0 warnings)

@prasad2512
prasad2512 requested a review from a team as a code owner October 19, 2026 17:24
@prasad2512
prasad2512 force-pushed the fix-windows-test-suite-2027 branch from fe59a53 to 8e68840 Compare October 19, 2026 17:52

@chrikrah chrikrah left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prasad2512 I'd merge 8e68840. I have no Windows machine, so I removed os.geteuid before pytest imports the modules. At bcd55fe two modules fail to collect and at your head none do. The tests you touched pass on Linux as before.

$ python nogeteuid.py tests/lib/tools/test_file_store.py tests/lib/tools/memory_sync   # del os.geteuid, then pytest --collect-only
bcd55fe:  99 tests collected, 2 errors   (AttributeError: module 'os' has no attribute 'geteuid')
8e68840:  145 tests collected

$ python -m pytest tests/lib/test_bedrock.py tests/lib/tools/memory_sync tests/lib/tools/test_agent_toolset.py tests/lib/tools/test_file_store.py -q -n 4
bcd55fe: 271 passed     8e68840: 271 passed

$ python -m pytest tests/lib -q -n 4   # 8e68840, env -i, CPython 3.10
2209 passed, 10 skipped, 1 xfailed

$ pyright --pythonplatform Windows <the five touched files>   # pyright 1.1.399
0 errors, 0 warnings, 0 informations
# not run: Windows itself, so the NamedTemporaryFile lock and the FileStore skips rest on reading

non-blocking: every job in .github/workflows/ci.yml runs on ubuntu-latest, so nothing stops the next os.geteuid() in a decorator from breaking collection again. The two runtime calls left, test_credentials.py:3946 and test_agent_toolset.py:861, already sit behind an os.name check.

The fixture you replaced came in with 46e4b98 (#974) and its delete=True handle carries no reason tied to the platform, so tmp_path loses nothing.

The three @needs_symlinks lines in item 4 are also in #1917 (okxint), open since 09-07.

@dtmeadows-ant the change is tests only. I'd add a windows-latest collect-only step, which costs one runner and would have caught all three decorators. Is Windows a platform you mean to support for contributors?

@prasad2512

Copy link
Copy Markdown
Author

Thank you so much @chrikrah for the thorough verification and testing on Linux! Really appreciate your confirmation on test collection and regression safety.

Happy to make any further adjustments if needed by @dtmeadows-ant. Looking forward to having Windows contributor support enabled cleanly!

@prasad2512

Copy link
Copy Markdown
Author

Hi @dtmeadows-ant, just gently following up on this PR.

All CI checks and Windows test collection fixes have been verified and approved by @chrikrah (and duplicate PR #2035 was closed). Please let me know if anything else is needed from my end to get this merged. Thank you!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix test collection and execution errors on Windows (geteuid, FileStore skip, bedrock tempfile lock)

2 participants