testsAndMisc/linux_configuration/fixes/lib/tests/arch_perf_harness.sh
Krzysztof kuhy Rudnicki 4f2b0ccdf7 Dissolve linux_configuration/scripts/ and single_use/
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
2026-08-23 18:53:30 +02:00

107 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# lib/tests/arch_perf_harness.sh — shared setup for the arch performance lib
# tests (arch_perf_report.sh, arch_perf_probes.sh).
#
# Sourced, not executed. Builds on lib_test_core.sh and adds the pieces these
# libs read from their entry script, diagnose_arch_performance.sh:
#
# * REPORT_FILE, FINDINGS, ACTIONS and the APPLY_SAFE_FIXES flag;
# * add_finding, add_action and run_and_log, redefined verbatim from the
# entry script -- they live there rather than in any lib, the same
# arrangement pacman_hook_stall_harness.sh handles with log_size;
# * the real log_*/has_cmd helpers, via lib/common.sh.
#
# REPORT_FILE points into the throwaway tmpdir, so the probes' report writes
# never leave the sandbox.
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FIXES_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd)"
REPO_ROOT="$(cd "${FIXES_DIR}/../.." && pwd)"
# shellcheck source=lib_test_core.sh
. "${SCRIPT_DIR}/lib_test_core.sh"
# shellcheck source=../../../lib/common.sh
. "${REPO_ROOT}/linux_configuration/lib/common.sh"
# --- globals and helpers owned by diagnose_arch_performance.sh --------------
# These four are read by the libs under test, never by this harness, so
# static analysis cannot see the use; export makes the intent explicit.
export REPORT_FILE="${TEST_TMPDIR}/report.log"
# arch_perf_fixes.sh writes a journald drop-in and a systemd unit, and probes
# two absolute home paths for organize_downloads.sh. All three are behind
# overrides defaulting to the real locations, because run_all.sh runs UN-jailed
# in ci_mirror.sh and in CI, where a bind mount would protect nothing.
export JOURNALD_CONF_DIR="${TEST_TMPDIR}/journald.conf.d"
export SYSTEMD_UNIT_DIR="${TEST_TMPDIR}/systemd_units"
export ORGANIZE_SCRIPT_CANDIDATES="${TEST_TMPDIR}/organize_downloads.sh"
export APPLY_SAFE_FIXES="false"
export INSTALL_TOOLS="false"
declare -a FINDINGS=()
declare -a ACTIONS=()
# Verbatim from diagnose_arch_performance.sh.
add_finding() {
FINDINGS+=("$1")
log_warn "$1"
}
add_action() {
ACTIONS+=("$1")
log_info "$1"
}
run_and_log() {
local header="$1"
shift
{
echo
echo "=== $header ==="
"$@" 2>&1 || true
} >>"$REPORT_FILE"
}
# --- external tool stubs ----------------------------------------------------
_arch_default_stubs() {
local tool
for tool in nvidia-smi lspci journalctl systemctl sysctl lsblk sensors \
free uptime ps top swapon findmnt pacman systemd-analyze; do
_t_stub "$tool" 'exit 0'
done
}
# arch_reset — start a test group from "nothing has happened yet".
arch_reset() {
_t_reset_calls
FINDINGS=()
ACTIONS=()
APPLY_SAFE_FIXES="false"
INSTALL_TOOLS="false"
export APPLY_SAFE_FIXES INSTALL_TOOLS
: >"$REPORT_FILE"
rm -rf "${JOURNALD_CONF_DIR}" "${SYSTEMD_UNIT_DIR}"
mkdir -p "${JOURNALD_CONF_DIR}" "${SYSTEMD_UNIT_DIR}"
rm -f "${ORGANIZE_SCRIPT_CANDIDATES}"
_t_full_path
_arch_default_stubs
}
# _t_report — the report file's contents this round.
_t_report() {
cat "$REPORT_FILE" 2>/dev/null || true
}
# _t_findings / _t_actions — the recorded findings and actions, one per line.
_t_findings() {
printf '%s\n' "${FINDINGS[@]:-}"
}
_t_actions() {
printf '%s\n' "${ACTIONS[@]:-}"
}
arch_reset