Run the WSL tests wherever a distribution answers - #40
Merged
Conversation
Calling the windows install of keycmd from a shell inside WSL is the half of the WSL setup that needs both sides of the boundary to be real, and it was opt in through KEYCMD_TEST_WSL, on the grounds that installing WSL takes a CI job of its own. That reasoning holds for CI and nowhere else: a developer machine with WSL2 on it can run those tests today, and the only thing standing in the way was a variable nobody remembers to set. The suite works it out for itself now. find_wsl in tests/conftest.py asks whether this is a windows machine, whether a distribution answers -- which is a different question from whether one is registered, since wsl.exe is on PATH on any windows install and docker's distributions run no shell -- and whether there is a keycmd on PATH for it to reach. The `wsl` fixture hands the tests the distribution or skips them with the reason there is none, the way `os_keyring` does for the keyring, and KEYCMD_REQUIRE_WSL turns that skip into a failure for the one CI job that provisions a distro. The answer goes in the pytest header next to the shells, since a run that silently skipped these looks exactly like a run on a machine without WSL. What the tests needed of wsl.exe moves to the fixture with it, so a test reads wsl.sh(script) and wsl.path(p) rather than reaching for helpers of its own, and decode now sniffs the utf-16 that wsl.exe writes its own errors in. A machine with no distribution registered says so in utf-16, and that sentence is the skip reason, which is not the place to hand someone W\x00i\x00n\x00d\x00o\x00w\x00s. Which turned up a bug that would have made most of this moot. Subclassing a keyring backend registers it, for the session and with no way to take it back out, so FakeChainer in test_backend.py was a candidate in every search that ran after that module was imported -- and a chainer of two backends outranks the credential manager, so the keyring probe settled on a chainer of null and fail and reported that this machine has no keyring. Every credential test then skipped itself, which is what a machine without a keyring is supposed to look like. It passed in CI only because -v prints the report header, which initializes keyring before collection; -q does not, so a local run covered twenty tests fewer without saying anything. The double sets viable = False and stays out of the search. Locally that is 196 passed where it was 175 passed and 21 skipped. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calling the Windows install of keycmd from a shell inside WSL was opt in through
KEYCMD_TEST_WSL, on the grounds that installing WSL takes a CI job of its own. That holds for CI and nowhere else: a developer machine with WSL2 on it can run those tests today, and the only thing in the way was a variable nobody remembers to set.The suite works it out for itself now.
find_wslintests/conftest.pyasks whether this is a Windows machine, whether a distribution answers — a different question from whether one is registered, sincewsl.exeis onPATHon any Windows install and Docker's distributions run no shell — and whether there is akeycmdonPATHfor it to reach. Thewslfixture then hands the tests the distribution, or skips them with the reason there is none, the wayos_keyringdoes for the keyring.KEYCMD_REQUIRE_WSL=1turns that skip into a failure, and the one CI job that provisions a distro sets it. The answer goes in the pytest header next to the shells, since a run that silently skipped these looks exactly like a run on a machine without WSL:What the tests needed of
wsl.exemoves to the fixture with it, so a test readswsl.sh(script)andwsl.path(p)rather than reaching for helpers of its own, anddecodesniffs the utf-16 thatwsl.exewrites its own errors in — a machine with no distribution registered says so in utf-16, and that sentence is now a skip reason.A bug that would have made most of this moot
Subclassing a keyring backend registers it, for the session and with no way to take it back out, so
FakeChainerintest_backend.pywas a candidate in every search that ran after that module was imported. A chainer of two backends outranks the credential manager, so the keyring probe settled on a chainer of null and fail and concluded the machine has no keyring — and every credential test skipped itself, which is exactly what a machine without a keyring is supposed to look like.It passed in CI only because
-vprints the report header, which initializes keyring before collection.-qdoes not, so a local run quietly covered twenty tests fewer. The double setsviable = Falseand stays out of the search.Verified
On Windows 11 with WSL2 (Ubuntu),
KEYCMD_REQUIRE_OS_KEYRING=1 KEYCMD_REQUIRE_WSL=1:ruff check,ruff format --check,ty check --error-on-warningandmkdocs build --strictare cleanCI is the other half of the verification: the WSL job proves the require flag still fails loudly on a provisioned distro, and the three Windows/macOS/Linux jobs prove the new tests skip quietly where there is no WSL.
🤖 Generated with Claude Code