Make stateful regression tests self-contained - #7402
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Improves shell test reliability by resetting captured command logs between calls and tightening monitor-scaling assertions to prevent false positives from accumulated output.
Changes:
- Add a helper to clear the powerprofiles “calls” log and invoke it between test phases.
- Clear Hyprctl eval output before running a scaling action, then assert exactly one command was emitted.
- Replace a loose substring match with a more structured regex for the monitor scaling command output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| test/shell.d/powerprofiles-set-test.sh | Clears the calls log between invocations to make tail -n 1 assertions deterministic. |
| test/shell.d/monitor-scaling-test.sh | Resets eval output and strengthens assertions about emitted monitor commands. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| reset_calls_log | ||
| "$ROOT/bin/omarchy-powerprofiles-set" ac balanced | ||
| [[ $(<"$tmp_dir/state/ac") == "balanced" ]] || fail "power profile stores AC preference" | ||
| [[ $(tail -n 1 "$tmp_dir/calls") == "balanced" ]] || fail "power profile applies selected AC preference" |
|
|
||
| reset_calls_log | ||
| "$ROOT/bin/omarchy-powerprofiles-set" ac | ||
| [[ $(tail -n 1 "$tmp_dir/calls") == "balanced" ]] || fail "power profile restores AC preference" |
|
|
||
| reset_calls_log | ||
| "$ROOT/bin/omarchy-powerprofiles-set" ac | ||
| [[ $(tail -n 1 "$tmp_dir/calls") == "balanced" ]] || fail "battery preference does not replace AC preference" |
|
|
||
| reset_calls_log | ||
| ON_BATTERY=1 "$ROOT/bin/omarchy-powerprofiles-set" | ||
| [[ $(tail -n 1 "$tmp_dir/calls") == "performance" ]] || fail "autodetect restores battery preference" |
| rm "$tmp_dir/state/ac" | ||
| reset_calls_log | ||
| ON_BATTERY=0 "$ROOT/bin/omarchy-powerprofiles-set" | ||
| [[ $(tail -n 1 "$tmp_dir/calls") == "performance" ]] || fail "power profile uses performance as AC default" |
| "$ROOT/bin/omarchy-powerprofiles-set" ac power-saver | ||
| reset_calls_log | ||
| "$ROOT/bin/omarchy-powerprofiles-init" | ||
| [[ $(tail -n 1 "$tmp_dir/calls") == "power-saver" ]] || fail "init restores the autodetected preference" |
| (( $(wc -l <"$eval_out") == 1 )) || fail "monitor scaling down emits exactly one monitor command" | ||
| grep -Eq 'output[[:space:]]*=[[:space:]]*"eDP-1".*scale[[:space:]]*=[[:space:]]*2[[:space:]]*}' "$eval_out" || | ||
| fail "monitor scaling down snaps floating point 3x to 2x" |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
test/shell.d/monitor-scaling-test.sh:64
wc -lcounts newline characters, not logical lines; if the stub writes a single command without a trailing newline, this will return 0 and incorrectly fail. Prefer a line-counting approach based on records (e.g., awk NR/END, or grep-based counting) that counts the last line even without a trailing newline.
(( $(wc -l <"$eval_out") == 1 )) || fail "monitor scaling down emits exactly one monitor command"
test/shell.d/monitor-scaling-test.sh:65
- The regex can match
scaleas a substring of a longer identifier (e.g.,rescale = 2), which can produce false positives. Tighten the pattern to requirescaleas its own token (e.g., start-of-line / delimiter beforescale, or include expected command structure).
grep -Eq 'scale[[:space:]]*=[[:space:]]*2([[:space:],}]|$)' "$eval_out" ||
fail "monitor scaling down snaps floating point 3x to 2x"
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
test/shell.d/monitor-scaling-test.sh:64
wc -lcounts newline characters, not logical lines; if the stub writes a single command without a trailing newline, this will report 0 and fail even though exactly one command was emitted. Consider counting records in a way that treats a non-newline-terminated last line as a line (e.g., usingawk 'END{print NR}'or a non-empty-line counter) to make the test robust.
(( $(wc -l <"$eval_out") == 1 )) || fail "monitor scaling down emits exactly one monitor command"
Fixes #7121.
Two stateful regression checks could pass using output produced by an earlier test case.
The monitor scaling test now clears the previous Hyprland evaluation output, verifies that exactly one command was emitted, and checks the relevant output and scale fields without depending on exact formatting.
The power profile tests now reset their call log through a shared helper before each command under test, ensuring every assertion observes a call produced by that specific scenario.
Tested with:
bash test/shell.d/monitor-scaling-test.shgit diff --checkThe power profile test requires the project's Bash 5/GNU environment and cannot run fully under macOS's system Bash 3.2.