mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-11 19:34:03 +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
117 lines
3.7 KiB
Bash
Executable File
117 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# lib/tests/mtk_harness.sh — shared fixture for linux_configuration/lib.
|
|
#
|
|
# Sourced, not executed.
|
|
#
|
|
# The name is historical: this fixture was written for the mtk_* libraries,
|
|
# which have since moved to github.com/kuhyx/mtk-root along with their suites.
|
|
# It stays because test_common_datetime.sh sources it, and renaming it would
|
|
# churn that file for no behavioural gain.
|
|
#
|
|
# WHAT IS EXERCISED
|
|
# The pure decision logic in the libraries that remain here — currently the
|
|
# string and clock helpers in common_datetime.sh.
|
|
#
|
|
# WHAT IS DELIBERATELY NOT EXERCISED, AND WHY
|
|
# The coverage gate only checks that this directory HAS a run_all.sh, so it
|
|
# cannot tell a real suite from an empty one. Naming the gaps is therefore
|
|
# the only honest record of them:
|
|
# - require_hosts_readable / init_android_script — `exec sudo -E bash "$0"`
|
|
# would replace the test process with a sudo re-exec of the suite.
|
|
# - check_adb_device / check_adb_root — call die(), which exits 1 and
|
|
# would take the whole run down; both also need real hardware.
|
|
# - collapse_mounts — calls `umount -l` on a live path.
|
|
# - install_missing_pacman_packages / require_imagemagick / notify —
|
|
# effecting code (pacman, desktop notifications).
|
|
# The measured pattern holds: decision logic reaches ~90%, effecting code 0%.
|
|
#
|
|
# TIME AND HOST DEPENDENCE
|
|
# This suite runs in shell-tests.yml and again on every pre-push via
|
|
# ci-mirror, so a wall-clock assertion would pass locally and fail at some
|
|
# other hour on some other machine. get_hour and get_day_of_week are
|
|
# therefore shimmed where a specific value is needed, and the readers of
|
|
# /proc/uptime are asserted on SHAPE, never on value.
|
|
set -euo pipefail
|
|
|
|
PASS=0
|
|
FAIL=0
|
|
|
|
_t_ok() {
|
|
PASS=$((PASS + 1))
|
|
printf ' OK: %s\n' "$1"
|
|
}
|
|
|
|
_t_bad() {
|
|
FAIL=$((FAIL + 1))
|
|
printf ' FAIL: %s\n' "$1"
|
|
}
|
|
|
|
# Assert equality. Every check in this suite funnels through here or _t_rc so
|
|
# there is exactly one place that counts a result.
|
|
_t_is() {
|
|
if [[ $2 == "$1" ]]; then
|
|
_t_ok "$3"
|
|
else
|
|
_t_bad "$3 (want '${1}', got '${2}')"
|
|
fi
|
|
}
|
|
|
|
# Assert a command's exit status. Run under `if` so a non-zero return is data
|
|
# rather than a `set -e` abort.
|
|
_t_rc() {
|
|
local want="$1" what="$2"
|
|
shift 2
|
|
local got=0
|
|
"$@" >/dev/null 2>&1 || got=$?
|
|
_t_is "$want" "$got" "$what"
|
|
}
|
|
|
|
# Assert a substring, for messages whose exact wording is not the contract.
|
|
_t_in() {
|
|
if [[ $2 == *"$1"* ]]; then
|
|
_t_ok "$3"
|
|
else
|
|
_t_bad "$3 (want substring '${1}')"
|
|
fi
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Isolation
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# android.sh runs `ensure_dir "$ANDROID_WORK_DIR"` at SOURCE time, and that
|
|
# path is under $HOME. Redirect HOME before sourcing anything or merely
|
|
# loading the library writes to the real ~/.cache. MTK_ROOT_CACHE moves the
|
|
# mtk toolkit's artifacts for the same reason.
|
|
_t_sandbox() {
|
|
T_TMP="$(mktemp -d)"
|
|
export T_TMP
|
|
HOME="$T_TMP/home"
|
|
mkdir -p "$HOME"
|
|
export HOME
|
|
export MTK_ROOT_CACHE="$T_TMP/cache"
|
|
}
|
|
|
|
_t_cleanup() {
|
|
[[ -n ${T_TMP:-} && -d ${T_TMP:-} ]] && rm -rf "$T_TMP"
|
|
return 0
|
|
}
|
|
|
|
# Build a device fixture. mtk_common.sh reads props.txt as `key=value` lines
|
|
# and by-name.txt as one partition per line; those two files ARE the seam.
|
|
# Usage: _t_fixture <name> <props-text> <by-name-text>
|
|
_t_fixture() {
|
|
local dir="$T_TMP/fixtures/$1"
|
|
mkdir -p "$dir"
|
|
printf '%s\n' "$2" >"$dir/props.txt"
|
|
printf '%s\n' "$3" >"$dir/by-name.txt"
|
|
printf '%s' "$dir"
|
|
}
|
|
|
|
# Report and set the process exit status. Called at the end of every suite.
|
|
_t_done() {
|
|
printf '\n %s: %d passed, %d failed\n' "$1" "$PASS" "$FAIL"
|
|
_t_cleanup
|
|
[[ $FAIL -eq 0 ]]
|
|
}
|