Add idle_keepawake: idle detection + keep machine awake#427
Merged
Conversation
Long unattended runs derail two ways: the screensaver/power policy sleeps the box mid-run, or the run should hold while a human is using the machine. The framework had neither signal. idle_seconds/is_idle read time since the last input (GetLastInputInfo on Windows) through an injectable probe; keep_awake (scoped CM) and keep_awake_on/allow_sleep (process-global on/off for JSON flows) stop the system and display sleeping through an injectable driver (SetThreadExecutionState/caffeinate/systemd-inhibit by default), restored on release. plan_keep_awake is the pure planner. All logic is unit-testable without touching the OS via the injected probe/driver.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 55 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
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.



Why
Long unattended automation runs get derailed two ways: the screensaver / power policy sleeps the box mid-run, or the run should hold while a human is actively using the machine. The framework had neither signal. Second feature of the ROUND-15 cross-app OS lane (after
shell_open).What
A headless
utils/idle_keepawake/module behind injectable seams so all logic is testable without touching the OS:idle_seconds/is_idle— seconds since the last user keyboard/mouse input (GetLastInputInfoon Windows) through an injectableprobe.plan_keep_awake— pure planner describing which wake flags a request maps to.keep_awake— scoped context manager keeping the machine awake for awithblock, restoring prior state on exit.keep_awake_on/allow_sleep— process-global on/off pair for JSON action flows (lock-guarded; a secondkeep_awake_onreplaces and releases the prior request).All keep-awake entry points apply the plan through an injectable
driver—SetThreadExecutionState(Windows),caffeinate(macOS),systemd-inhibit(Linux) by default. The live OS paths are platform-specific (untested in Linux CI, likeshell_open's opener); the headless tests drive the logic through fake probe/driver.Five-layer coverage
je_auto_control/utils/idle_keepawake/(noPySide6).je_auto_control/__init__.py+__all__.AC_idle_seconds,AC_is_idle,AC_plan_keep_awake,AC_keep_awake_on,AC_allow_sleep.ac_*tools (reads read-only; keep-awake on/off side-effect-only).Docs: EN/Zh
v204_features_doc.rst+ WHATS_NEW. Headless testtest_idle_keepawake_batch.py(14 tests, fake probe/driver). Full headless suite green (3793 passed). Verified the real Win32 probe +SetThreadExecutionStatekeep-awake path end-to-end on Windows.