Skip to content

fix(tests): let the installer suites run on a Windows host - #4130

Merged
kovtcharov-amd merged 2 commits into
mainfrom
fix/windows-geteuid-patches
Sep 25, 2026
Merged

kovtcharov-amd merged 2 commits into
mainfrom
fix/windows-geteuid-patches

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Running the unit tests on a Windows box errored out 19 times before reaching a
single assertion, so the installer suites were effectively unrunnable on that
platform. os.geteuid is POSIX-only, and unittest.mock.patch refuses to patch
an attribute that does not exist. Both installer suites now pass on Windows and
are unchanged on Linux and macOS. Closes #4127.

Three things, all in the same lane:

  • The geteuid patches — 19 tests, not the 7 in the issue. One autouse
    fixture in the macOS suite took all twelve of its own tests down with it.
  • One unrelated Windows failure in the same file — macOS install detection
    compared paths as native strings, which a Windows host renders with
    backslashes, so nothing ever matched. Comparing as POSIX keeps the assertion
    equally strict everywhere.
  • Nine pylint errors that only appear on Windows — util/lint.py flagged
    os.killpg / os.getpgid / os.geteuid in daemon/sidecars/ and
    installer/ as missing members. The code is correct and guarded at runtime;
    CI lints on Linux and never saw them.

No production code changed — every call site was already guarded.

🔍 Technical details

patch(target) defaults to create=False, so get_original() raises
AttributeError when the attribute is absent. create=True invents it for the
patch's duration and delattrs it on exit, so nothing leaks between tests — and
the injected euid is exactly what the code under test would have read on POSIX.

Sites: seven decorators in TestInstallViaPpa
(tests/unit/test_init_command.py), plus the _non_root autouse fixture and the
root-case patch in tests/unit/test_lemonade_macos_install.py.

src/gaia/installer/lemonade_installer.py needed nothing — all three call sites
(723, 909, 1196) already sit behind hasattr(os, "geteuid").

The path bug: test_check_installation_finds_macos_install stubs Path.exists
with a set membership test, but str(Path("/usr/local/bin/lemond")) is
\usr\local\bin\lemond on Windows. Both the stub and the info.path assertion
now normalise through as_posix().

pylint: astroid resolves os members against the running interpreter, so these
are false positives that can only fire on Windows. Adding the three names to
generated-members in .pylintrc is a no-op on Linux — the check never fired
there — and the rcfile's own header endorses suppressing rare false positives
rather than dropping a valuable check wholesale. Note line 1197 never tripped:
pylint understands the if hasattr(...) statement form but not the hasattr(...) and ... boolean form used at 723 and 909.

Test plan

  • python -m pytest tests/unit/test_init_command.py tests/unit/test_lemonade_macos_install.py -q on Windows 11 — 144 passed, 9 subtests passed, was 1 failed / 19 errors
  • python util/lint.py --pylint on Windows — PASS, was 9 errors
  • python util/lint.py --black --isort — PASS
  • Linux CI unit lane stays green (the create=True and as_posix() changes are no-ops where os.geteuid exists and / is the separator)

The Windows unit lane errored out 19 times before reaching a single
assertion: every `patch("os.geteuid", ...)` raised AttributeError because
the attribute is POSIX-only and mock refuses to patch what does not exist.
Nineteen, not the seven originally reported — one autouse fixture in the
macOS suite took all twelve of its tests down with it.

`create=True` at each patch site lets mock invent the attribute for the
duration, which is exactly the euid the code under test would have seen.
The production code needed no change: every call site in
lemonade_installer.py already guards with hasattr.

Also fixes the one remaining Windows failure in the same file, which was a
different bug — the macOS detection test compared `str(Path("/usr/..."))`,
which a Windows host renders with backslashes so it matched nothing.
Comparing as POSIX keeps the assertion equally strict everywhere.

Finally, .pylintrc now lists os.killpg/getpgid/geteuid as generated members.
astroid resolves os against the running interpreter, so `util/lint.py`
reported nine E1101s on Windows for guarded, correct code. CI lints on Linux
and never saw them.
@github-actions github-actions Bot added the tests Test changes label Sep 22, 2026
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

Reproduced and verified this end to end on a real Windows box — both the problem and the fix. Worth recording, because every lane in this PR's own CI runs on Linux, so none of them can confirm the thing it claims to fix.

Before: the two installer suites produce 20 failures before a single assertion runs (19 geteuid, plus the macOS path-comparison one), and python util/lint.py --pylint fails with 9 errors. After: 144 passed, 0 failed, and lint passes. The PR body's counts are exact.

🔍 Technical details

Windows 11, Python 3.13, this PR's three files checked out over current main.

# main
8 failed, 124 passed, 12 errors, 9 subtests passed
AttributeError: <module 'os' (frozen)> does not have the attribute 'geteuid'
# + 4130
144 passed, 9 subtests passed

util/lint.py --pylint: 9 × E1101 → 0 (os.killpg/os.getpgid in daemon/sidecars/{ledger,manager}.py, os.geteuid in installer/lemonade_installer.py).

Two things I checked that could have been gaps, and are not:

  • Scope of the generated-members entry. Swept src/gaia for other POSIX-only members that would reopen this on the next file — only signal.SIGKILL and os.chown, one site each, neither raising E1101. The three listed symbols are the complete set today.
  • A residual PIL.Image.LANCZOS E1101. Shows up under a direct python -m pylint but not through util/lint.py, which shells out via uvx into an env without Pillow, so it lands as E0401 (already disabled). Not a gap — an artifact of invoking pylint differently.

Only red is pr-review / run, which is the quota outage (#4120 / #4126), unrelated.

The module docstring said the file was kept separate because the install
suite patches os.geteuid and therefore errors on Windows. That is no longer
true, and leaving it would send the next reader looking for a bug that has
been fixed. The split still has a real reason: these are string assertions
against the pinned .pkg BOMs, not install control flow.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

Independently reproduced on a Windows box, with a number this PR can't see from inside: these two suites go from 8 failed + 12 errors to 0 once it lands, and that's 20 of the 131 failures that survive #4115 — the single largest remaining cause in the local Windows unit suite.

I'd arrived at create=True separately before finding this PR, so the fix is confirmed twice over. Worth noting mine stopped one short of yours: create=True alone still leaves test_check_installation_finds_macos_install red, and the as_posix() comparison here is what actually clears it. Complete fix, not a partial one.

🔍 Technical details

Measured against a full pytest tests/unit/ -q on origin/main (1112 failed+errors) and on #4115's head (131). Attribution within that 131:

file count cause
test_lemonade_macos_install.py 12 all ERROR at setup — AttributeError: <module 'os' (frozen)> does not have the attribute 'geteuid', from the autouse _non_root fixture
test_init_command.py 8 7 × the same in TestInstallViaPpa, plus test_check_installation_finds_macos_install

19 of the 20 are literally the same AttributeError — grep -c on the run log returns exactly 19. The 20th is the path-comparison bug.

Checked with the patch applied locally: 8 failed, 124 passed, 12 errors → 1 failed, 143 passed, with the survivor being precisely the one your Path.as_posix() change targets.

The .pylintrc generated-members addition is worth keeping — astroid resolves os.* against the running interpreter, so E1101 fires on Windows for call sites that are already hasattr-guarded at runtime, and CI lints on Linux and never sees it.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 25, 2026
Merged via the queue into main with commit b85930a Sep 25, 2026
31 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/windows-geteuid-patches branch September 25, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci(tests): unit suite has no Windows lane on a Windows-first product

2 participants