mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 18:07:06 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
128 lines
6.5 KiB
Bash
Executable File
128 lines
6.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Tests for aw_autostart.sh — ActivityWatch's autostart wiring and self-checks.
|
|
#
|
|
# The subject writes an XDG .desktop entry, appends an `exec` line to the i3
|
|
# config, and generates an i3blocks status script. All of it lands under
|
|
# $USER_HOME, which the suite points at a throwaway dir -- so unlike its
|
|
# siblings this one does not need root paths. It still runs under the jail
|
|
# with the rest of the directory's suites; see jail_args beside this file.
|
|
#
|
|
# The generated i3blocks script is asserted by EXECUTING it against stubbed
|
|
# pacman/pgrep, not by grepping its text: "AW on" vs "AW off" is the thing
|
|
# that reaches the status bar, and a heredoc that emits syntactically broken
|
|
# bash would pass a text check and fail in front of the user.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
# shellcheck source=./features_harness.sh
|
|
. "$SCRIPT_DIR/features_harness.sh"
|
|
|
|
_t_setup_env
|
|
trap _t_teardown EXIT
|
|
|
|
# The globals aw_autostart.sh inherits from setup_activitywatch.sh.
|
|
USER_HOME="$TEST_TMPDIR/home"
|
|
ACTUAL_USER="$(id -un)"
|
|
mkdir -p "$USER_HOME/.config/i3"
|
|
|
|
# test_setup calls these two; they live in the entry script, above the source
|
|
# line. Redefinable per-assertion, so each definition goes in a subshell -- a
|
|
# top-level redefinition would shadow the subject's own view for every later
|
|
# assertion.
|
|
check_activitywatch_installed() { return 1; }
|
|
check_activitywatch_running() { return 1; }
|
|
|
|
# shellcheck source=../aw_autostart.sh
|
|
. "$FEATURES_LIB_DIR/aw_autostart.sh"
|
|
|
|
# --- setup_autostart: no i3 config present ----------------------------------
|
|
rm -f "$USER_HOME/.config/i3/config"
|
|
no_i3_out="$(setup_autostart)"
|
|
desktop="$USER_HOME/.config/autostart/activitywatch.desktop"
|
|
_t_file_has "$desktop" 'Exec=aw-qt' "the XDG autostart entry execs aw-qt"
|
|
_t_file_has "$desktop" 'X-GNOME-Autostart-enabled=true' "the XDG entry enables GNOME autostart"
|
|
_t_has "$no_i3_out" 'i3 config not found' "setup_autostart reports a missing i3 config"
|
|
|
|
# --- setup_autostart: appends to an existing i3 config ----------------------
|
|
printf '# my i3 config\n' >"$USER_HOME/.config/i3/config"
|
|
added_out="$(setup_autostart)"
|
|
_t_file_has "$USER_HOME/.config/i3/config" 'exec --no-startup-id aw-qt' "setup_autostart appends the i3 exec line"
|
|
_t_has "$added_out" 'Added ActivityWatch to i3 config' "setup_autostart reports the i3 entry was added"
|
|
|
|
# --- setup_autostart: idempotent -- a second run must not duplicate ---------
|
|
again_out="$(setup_autostart)"
|
|
_t_eq "1" "$(grep -c 'exec --no-startup-id aw-qt' "$USER_HOME/.config/i3/config")" \
|
|
"a second run does not duplicate the i3 exec line"
|
|
_t_has "$again_out" 'already exists in i3 config' "setup_autostart reports the entry already exists"
|
|
|
|
# --- create_i3blocks_status -------------------------------------------------
|
|
status_out="$(create_i3blocks_status)"
|
|
status_script="$USER_HOME/.config/i3blocks/activitywatch_status.sh"
|
|
_t_eq "0" "$([[ -x $status_script ]] && echo 0 || echo 1)" "the i3blocks status script is executable"
|
|
_t_has "$status_out" 'interval=10' "the printed i3blocks block sets interval=10"
|
|
|
|
# --- the GENERATED script actually works ------------------------------------
|
|
# Not installed: pacman -Qi fails and aw-qt is absent from PATH.
|
|
# PATH is REPLACED, not prepended, for this one case: aw-qt is genuinely
|
|
# installed at /usr/bin/aw-qt on the dev host, so a prepended stub dir cannot
|
|
# hide it -- `command -v aw-qt` would find the real one and the case would
|
|
# silently assert nothing. The generated script needs only coreutils here.
|
|
_t_stub pgrep
|
|
printf '#!/usr/bin/env bash\nexit 1\n' >"$TEST_TMPDIR/bin/pacman"
|
|
chmod +x "$TEST_TMPDIR/bin/pacman"
|
|
uninstalled="$(PATH="$TEST_TMPDIR/bin:/usr/bin/coreutils-only" "$status_script")"
|
|
_t_has "$uninstalled" 'AW uninstalled' "the status script reports 'AW uninstalled' with no package and no binary"
|
|
|
|
# Installed via the aw-qt binary, but no process running: pgrep must FAIL.
|
|
printf '#!/usr/bin/env bash\nexit 0\n' >"$TEST_TMPDIR/bin/aw-qt"
|
|
chmod +x "$TEST_TMPDIR/bin/aw-qt"
|
|
printf '#!/usr/bin/env bash\nexit 1\n' >"$TEST_TMPDIR/bin/pgrep"
|
|
chmod +x "$TEST_TMPDIR/bin/pgrep"
|
|
off_out="$("$status_script")"
|
|
_t_has "$off_out" 'AW off' "the status script reports 'AW off' when installed but not running"
|
|
|
|
# Installed and running.
|
|
printf '#!/usr/bin/env bash\nexit 0\n' >"$TEST_TMPDIR/bin/pgrep"
|
|
chmod +x "$TEST_TMPDIR/bin/pgrep"
|
|
on_out="$("$status_script")"
|
|
_t_has "$on_out" 'AW on' "the status script reports 'AW on' when the process is found"
|
|
|
|
# Installed via the pacman package rather than the binary.
|
|
rm -f "$TEST_TMPDIR/bin/aw-qt"
|
|
printf '#!/usr/bin/env bash\nexit 0\n' >"$TEST_TMPDIR/bin/pacman"
|
|
chmod +x "$TEST_TMPDIR/bin/pacman"
|
|
pkg_out="$("$status_script")"
|
|
_t_has "$pkg_out" 'AW on' "the status script accepts the pacman package as proof of install"
|
|
|
|
# --- test_setup: everything present -----------------------------------------
|
|
present_out="$(
|
|
check_activitywatch_installed() { return 0; }
|
|
check_activitywatch_running() { return 0; }
|
|
test_setup
|
|
)"
|
|
_t_has "$present_out" '✓ ActivityWatch is installed' "test_setup reports an installed ActivityWatch"
|
|
_t_has "$present_out" '✓ ActivityWatch is running' "test_setup reports a running ActivityWatch"
|
|
_t_has "$present_out" '✓ XDG autostart file exists' "test_setup finds the XDG autostart file"
|
|
_t_has "$present_out" '✓ i3 autostart configured' "test_setup finds the i3 autostart line"
|
|
_t_has "$present_out" '✓ i3blocks status script created' "test_setup finds the i3blocks script"
|
|
|
|
# --- test_setup: nothing present --------------------------------------------
|
|
rm -f "$desktop" "$status_script" "$USER_HOME/.config/i3/config"
|
|
absent_out="$(
|
|
check_activitywatch_installed() { return 1; }
|
|
check_activitywatch_running() { return 1; }
|
|
test_setup
|
|
)"
|
|
_t_has "$absent_out" '✗ ActivityWatch is not installed' "test_setup reports a missing ActivityWatch"
|
|
_t_has "$absent_out" '✗ ActivityWatch is not running' "test_setup reports a stopped ActivityWatch"
|
|
_t_has "$absent_out" '✗ XDG autostart file missing' "test_setup reports the missing XDG file"
|
|
_t_has "$absent_out" '! i3 autostart may not be configured' "test_setup reports the missing i3 line"
|
|
_t_has "$absent_out" '✗ i3blocks status script missing' "test_setup reports the missing i3blocks script"
|
|
|
|
# --- show_instructions ------------------------------------------------------
|
|
instructions="$(show_instructions)"
|
|
_t_has "$instructions" 'http://localhost:5600' "show_instructions gives the web interface URL"
|
|
_t_has "$instructions" 'Super+Shift+R' "show_instructions gives the i3 reload shortcut"
|
|
|
|
_t_report "test_aw_autostart.sh"
|