headroom/tests/test_install
Parideboy 1edaeb8b76
fix(install/windows): register persistent-task from S4U hidden XML (#2453) (#2459)
## Description

Windows `persistent-task` created its startup and 5-minute health tasks
via `schtasks` command-line flags, which register the task with an
**interactive-token** principal. Every task run spawned a visible
console window that briefly grabbed keyboard focus before vanishing —
every 5 minutes, indefinitely (and at boot / proxy restart). Fixes
#2453.

This registers the tasks from Task Scheduler **XML** instead: user-scope
tasks use an **S4U** principal (run whether the user is logged on or
not, no stored password) with `<Hidden>true</Hidden>`, so runs execute
in a non-interactive session and never draw a window. System-scope tasks
keep the LocalSystem service account (which already has no desktop).

## Type of Change

- [x] Bug fix (non-breaking change which fixes an issue)

## Changes Made

- `headroom/install/supervisors.py`: add `_windows_task_xml()`
(S4U/hidden for user scope, LocalSystem for system scope),
`_windows_boot_trigger()`, `_windows_health_trigger()` (PT5M
repetition), and `_register_windows_task()` (writes UTF-16 XML to a temp
file and calls `schtasks /Create /TN <n> /XML <file> /F`). Rewrite the
Windows TASK branch of `install_supervisor` to register both tasks from
XML.
- `tests/test_install/test_supervisors.py`: unit tests asserting the XML
carries `S4U` + `Hidden` + `PT5M` for user scope and `S-1-5-18` /
`ServiceAccount` for system scope; updated the install-flow assertion to
expect `schtasks /XML` registration for the startup and health tasks.

## Testing

- [x] Unit tests pass

```
$ python -m pytest tests/test_install/test_supervisors.py -q
collected 29 items
tests\test_install\test_supervisors.py .............................     [100%]
============================= 29 passed in 1.48s ==============================
```

## Real Behavior Proof

- Environment: Windows 11 Pro 10.0.26200, Python 3.13.11
- Exact command / steps: python -m pytest
tests/test_install/test_supervisors.py -q; ruff check + ruff format
--check; mypy headroom/install/supervisors.py --ignore-missing-imports
- Observed result: 29 passed; ruff clean; mypy exit 0. Generated XML
contains <LogonType>S4U</LogonType> and <Hidden>true</Hidden> for user
scope.
- Not tested: live end-to-end `headroom install apply --preset
persistent-task` on a physical desktop confirming zero console flash
over a >5-minute window (no interactive Windows session in CI).

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-12 00:10:23 -05:00
..
test_codex_install.py fix(codex): detect keyring-backed ChatGPT auth (#2478) 2026-07-22 06:09:31 -07:00
test_health.py test: expand persistent install coverage 2026-04-11 18:24:15 -05:00
test_native_installers.py fix(install): trust Docker bridge for dashboard metadata 2026-08-11 14:25:29 -07:00
test_paths.py ci: restore green lint (reformat for ruff 0.15.17, fix mypy no-any-return, pin linters) (#1295) 2026-06-22 15:14:40 -05:00
test_planner.py fix(install): stop baking the host memory DB path into a container deployment (#2845) 2026-08-08 01:15:41 -05:00
test_providers.py fix(codex): rewrite config.toml properly so Codex will route through … (#2102) 2026-07-14 11:53:24 -04:00
test_proxy_mode_default.py fix(install): default to cache mode, matching headroom proxy (#1893 follow-up) (#2563) 2026-07-25 19:26:15 -07:00
test_runtime.py fix(install): use --userns=keep-id under Podman so bind-mount writes don't fail (#2846) 2026-08-08 01:30:48 -05:00
test_state.py fix(install): migrate deployments off the retired chopratejas image repo (#2427) 2026-07-19 22:15:01 -07:00
test_supervisors.py fix(install/windows): register persistent-task from S4U hidden XML (#2453) (#2459) 2026-08-12 00:10:23 -05:00