mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-26 04:27:21 +01:00
Compare commits
3 Commits
1b43ba093c
...
f1590cbb64
| Author | SHA1 | Date | |
|---|---|---|---|
| f1590cbb64 | |||
| 23fdfcf867 | |||
| 9dd9aeb50e |
78
.github/workflows/pre-commit.yml
vendored
78
.github/workflows/pre-commit.yml
vendored
@ -16,8 +16,84 @@ jobs:
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
# zsh backs the zsh-syntax hook. apt does not let a patch release be
|
||||
# selected, so this is pinned only to what the runner image provides;
|
||||
# the version is echoed so a jump shows up in the log rather than as a
|
||||
# mystery parse difference. Local machines compare on major.minor only.
|
||||
- name: Install system dependencies
|
||||
run: sudo apt-get update && sudo apt-get install -y zsh
|
||||
run: |
|
||||
set -euo pipefail
|
||||
sudo apt-get update && sudo apt-get install -y zsh
|
||||
zsh --version
|
||||
|
||||
# Pin shellcheck instead of inheriting whatever ubuntu-latest ships.
|
||||
#
|
||||
# The runner image carried 0.9.0 while developer machines have 0.11.0
|
||||
# from pacman, and the shellcheck hook is `language: system` -- so it
|
||||
# used whichever binary happened to be on PATH. The two versions
|
||||
# disagree (0.11.0 demoted SC2002 and several SC2015/SC2119 cases as
|
||||
# noise), which meant a commit could pass every local check and still
|
||||
# fail CI on findings the developer could not reproduce. That is exactly
|
||||
# what kept this workflow red from b83ce5d onward.
|
||||
#
|
||||
# Keep SHELLCHECK_VERSION in step with the version developers install;
|
||||
# the verification below fails loudly rather than silently drifting.
|
||||
- name: Install shellcheck (pinned)
|
||||
env:
|
||||
SHELLCHECK_VERSION: v0.11.0
|
||||
SHELLCHECK_SHA256: 8c3be12b05d5c177a04c29e3c78ce89ac86f1595681cab149b65b97c4e227198
|
||||
run: |
|
||||
set -euo pipefail
|
||||
tarball="shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz"
|
||||
curl -fsSL -o "$tarball" \
|
||||
"https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/${tarball}"
|
||||
echo "${SHELLCHECK_SHA256} ${tarball}" | sha256sum --check --strict
|
||||
tar -xJf "$tarball"
|
||||
sudo install -m 0755 "shellcheck-${SHELLCHECK_VERSION}/shellcheck" /usr/local/bin/shellcheck
|
||||
# Fail here, not 40 hooks later, if PATH still resolves to another copy.
|
||||
installed="$(shellcheck --version | awk '/^version:/ { print $2 }')"
|
||||
expected="${SHELLCHECK_VERSION#v}"
|
||||
if [ "$installed" != "$expected" ]; then
|
||||
echo "::error::shellcheck on PATH is ${installed}, expected ${expected}" >&2
|
||||
command -v -a shellcheck >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "shellcheck ${installed} pinned and on PATH"
|
||||
|
||||
# prettier and shfmt do NOT run in this job -- prettier is a pre-push
|
||||
# hook and shfmt runs from the local pre-commit git hook. They are
|
||||
# pinned here anyway so this file stays the single place that records
|
||||
# the expected version of every `language: system` tool, and so a future
|
||||
# workflow that does run them inherits the pin instead of re-deriving
|
||||
# it. Their real divergence risk is between developers: both REWRITE
|
||||
# files, so two versions reformat the repo back and forth.
|
||||
- name: Install prettier and shfmt (pinned)
|
||||
env:
|
||||
PRETTIER_VERSION: 3.9.5
|
||||
SHFMT_VERSION: v3.13.1
|
||||
SHFMT_SHA256: fb096c5d1ac6beabbdbaa2874d025badb03ee07929f0c9ff67563ce8c75398b1
|
||||
run: |
|
||||
set -euo pipefail
|
||||
npm install --global --no-fund --no-audit "prettier@${PRETTIER_VERSION}"
|
||||
|
||||
curl -fsSL -o shfmt \
|
||||
"https://github.com/mvdan/sh/releases/download/${SHFMT_VERSION}/shfmt_${SHFMT_VERSION}_linux_amd64"
|
||||
echo "${SHFMT_SHA256} shfmt" | sha256sum --check --strict
|
||||
sudo install -m 0755 shfmt /usr/local/bin/shfmt
|
||||
|
||||
# Assert what PATH actually resolves to, not what was just written:
|
||||
# a copy earlier on PATH would otherwise win silently.
|
||||
prettier_installed="$(prettier --version)"
|
||||
shfmt_installed="$(shfmt --version)"
|
||||
if [ "$prettier_installed" != "$PRETTIER_VERSION" ]; then
|
||||
echo "::error::prettier on PATH is ${prettier_installed}, expected ${PRETTIER_VERSION}" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ "$shfmt_installed" != "$SHFMT_VERSION" ]; then
|
||||
echo "::error::shfmt on PATH is ${shfmt_installed}, expected ${SHFMT_VERSION}" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "prettier ${prettier_installed} and shfmt ${shfmt_installed} pinned and on PATH"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
{
|
||||
"title": "Fix the 11 shellcheck findings keeping CI red",
|
||||
"objective": "Restore the 'Pre-commit checks' GitHub Actions workflow to green. It has failed on every push since b83ce5d (2026-08-03), which removed shellcheck's --severity filter; CI runs an older shellcheck than the developer machine and reports 11 info/style findings that shellcheck 0.11.0 no longer emits. Fix each finding properly, with no behavioural change and no suppressions.",
|
||||
"acceptance_criteria": [
|
||||
"shellcheck 0.9.0, version-matched to CI, reports zero findings on all 9 edited files",
|
||||
"shellcheck 0.11.0, the developer machine version, also reports zero findings on those files",
|
||||
"pre-commit run shellcheck --all-files passes over the whole repository",
|
||||
"Every rewritten conditional keeps the trailing '|| true' the original had, so no guarded side effect can newly abort a caller under set -e",
|
||||
"require_imagemagick and adb_select_device behave identically to the bare calls they replace, confirmed by running both forms",
|
||||
"phone_focus_mode/lib/tests/test_adb_common.sh passes 13/13 and boot_recovery/tests/test_boot_repair.sh passes 31/31",
|
||||
"No shellcheck disable directive, no --severity filter, and no per-file exclusion is added"
|
||||
],
|
||||
"out_of_scope": [
|
||||
"Changing the behaviour of any edited script: every fix is semantics-preserving",
|
||||
"third_party/agent-skills/, which the shellcheck hook already excludes as vendored upstream code that would be lost on the next sync",
|
||||
"Pinning the shellcheck version in the CI workflow to remove the local/CI divergence at its root: considered, deferred as a separate change",
|
||||
"The mtk_root toolkit from commit 1b43ba0, which was already clean and is untouched here",
|
||||
"Device-level verification of curfew_enforcer.sh and hosts_enforcer.sh, which run on the phone under Magisk"
|
||||
],
|
||||
"verifier": "shellcheck 0.9.0 (CI-matched) and 0.11.0 over the edited files; pre-commit run shellcheck --all-files; phone_focus_mode/lib/tests/test_adb_common.sh; linux_configuration/scripts/boot_recovery/tests/test_boot_repair.sh; and the GitHub Actions 'Pre-commit checks' run on the pushed commit"
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
{
|
||||
"intent": "Extend the shellcheck version pin from 23fdfcf to every `language: system` tool the gates depend on -- prettier, shfmt and zsh -- so no hook can silently run a different binary on CI than on a developer machine, and so drift is reported at commit time rather than discovered as an unreproducible failure.",
|
||||
"scope": [
|
||||
".github/workflows/pre-commit.yml (pin prettier + shfmt, echo zsh version)",
|
||||
"linux_configuration/.githooks/lib/common.sh (generalise the drift check to a table)",
|
||||
"Non-goal: changing what any hook reports or how any file is formatted",
|
||||
"Non-goal: pinning local tool versions, which come from pacman on a rolling distro",
|
||||
"Non-goal: adding prettier or shfmt to the CI job's hook run; they remain pre-push and local-git-hook respectively"
|
||||
],
|
||||
"changes": [
|
||||
"Replaced the single-purpose check_shellcheck_version() with a table-driven check_pinned_tool_versions() over PINNED_TOOL_VERSIONS, covering shellcheck 0.11.0, prettier 3.9.5, shfmt 3.13.1 and zsh 5.9. Each entry names the file pinning the other side, so the warning tells the developer exactly what to update.",
|
||||
"Added _tool_version() to normalise the four different version formats: shellcheck's 'version:' line, shfmt's and node's leading 'v', and zsh's second field. Normalising at the source keeps the comparison a plain string match.",
|
||||
"zsh is compared on major.minor only, because apt does not allow selecting a patch release on the runner image -- 5.9.2 locally versus 5.9 in CI is not a meaningful divergence and should not produce a permanent warning.",
|
||||
"Added a workflow step installing prettier at an exact npm version and shfmt from a checksum-verified release binary, each followed by an assertion that PATH actually resolves to the pinned version rather than to a copy found earlier on PATH.",
|
||||
"The zsh install step now echoes 'zsh --version' so a runner image bump appears in the log instead of surfacing as an unexplained parse difference.",
|
||||
"Documented in both files WHY prettier and shfmt are pinned despite not running in CI: they rewrite files, so version drift between two developers reformats the repo back and forth."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "python3 -c \"import yaml; yaml.safe_load(open('.github/workflows/pre-commit.yml'))\"",
|
||||
"result": "pass",
|
||||
"evidence": "Parses cleanly. Step order: checkout, setup-python, Install system dependencies, Install shellcheck (pinned), Install prettier and shfmt (pinned), Install dependencies, Run pre-commit hooks -- every pin lands before the hooks run."
|
||||
},
|
||||
{
|
||||
"command": "the shfmt install steps, executed verbatim in a scratch directory",
|
||||
"result": "pass",
|
||||
"evidence": "curl fetched shfmt_v3.13.1_linux_amd64; 'sha256sum --check --strict' reported 'shfmt: OK'; the binary reports v3.13.1, so the version gate passes. 'npm view prettier@3.9.5' confirms that exact version resolves from the registry."
|
||||
},
|
||||
{
|
||||
"command": "check_pinned_tool_versions with stubbed prettier 3.0.0 and shfmt v3.0.0 on PATH",
|
||||
"result": "pass",
|
||||
"evidence": "Emitted a separate warning per tool naming the installed and pinned versions plus both files to update, then the shared 'Results may differ' line. Confirms the 'v' prefix is normalised (v3.0.0 compared as 3.0.0) and that the check reports every drifted tool rather than stopping at the first."
|
||||
},
|
||||
{
|
||||
"command": "check_pinned_tool_versions against the real local toolchain",
|
||||
"result": "pass",
|
||||
"evidence": "Silent. Local shellcheck 0.11.0, prettier 3.9.5, shfmt v3.13.1 and zsh 5.9.2 all match their pins (zsh on major.minor)."
|
||||
},
|
||||
{
|
||||
"command": "shellcheck linux_configuration/.githooks/lib/common.sh",
|
||||
"result": "pass",
|
||||
"evidence": "Zero findings. An earlier revision failed with SC1073/SC1072 because a comment line began with '# shellcheck, zsh --', which shellcheck parsed as a malformed directive; the comment was reworded as prose."
|
||||
},
|
||||
{
|
||||
"command": "source the hook library and inspect verify_toolchain",
|
||||
"result": "pass",
|
||||
"evidence": "check_pinned_tool_versions is defined and is called from verify_toolchain, so the check runs on every hook invocation."
|
||||
},
|
||||
{
|
||||
"command": "bash ~/.claude/scripts/finish.sh gate ~/testsAndMisc <2 files>",
|
||||
"result": "pass",
|
||||
"evidence": "FINISH_GATE {\"risk\":\"review\",\"changed_files\":2,\"phase\":\"ok\"} with 1193 Python tests at 100% coverage."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"Four pinned versions now live in two files each and must be bumped together. The local warning exists to surface exactly that, but a developer who ignores it can still drift.",
|
||||
"zsh cannot be pinned precisely on the runner image, so it is only compared on major.minor. A patch-level parse difference in zsh would still go unnoticed; the echoed version in the CI log is the mitigation.",
|
||||
"CI now depends on the npm registry and a GitHub release asset being reachable. A transient outage fails the workflow rather than silently falling back, which is the intended direction but is a new external dependency.",
|
||||
"prettier and shfmt are pinned in a job that does not currently run them, so the pin is unexercised by CI. It protects a future workflow that does run them, and documents the expected version in one place; the real enforcement for these two remains the local drift warning."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert the commit; the workflow steps are additive and the hook-library change swaps one function for a superset of it.",
|
||||
"After reverting, CI returns to the runner image's prettier/shfmt (or none at all) and the local drift warning covers only shellcheck.",
|
||||
"Confirm with: pre-commit run --all-files locally, sourcing the hook library to check verify_toolchain still resolves, and the next 'Pre-commit checks' CI run."
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
{
|
||||
"intent": "Close the root cause behind the CI outage fixed in 9dd9aeb: CI and developer machines ran different shellcheck versions, so a commit could pass every local gate and still fail CI on findings the developer could not reproduce. Pin CI to the version developers actually run, and make any future divergence visible locally at commit time instead of as an unreproducible CI failure.",
|
||||
"scope": [
|
||||
".github/workflows/pre-commit.yml (pin + verify shellcheck)",
|
||||
"linux_configuration/.githooks/lib/common.sh (local drift warning)",
|
||||
"Non-goal: changing which findings shellcheck reports, or any hook's behaviour",
|
||||
"Non-goal: pinning the local shellcheck itself, which comes from pacman on a rolling distro where version bumps are routine",
|
||||
"Non-goal: pinning the other language:system tools (prettier, shfmt, zsh, node); only shellcheck has demonstrated this failure"
|
||||
],
|
||||
"changes": [
|
||||
"Added an 'Install shellcheck (pinned)' step to the pre-commit workflow that downloads shellcheck v0.11.0 from the official GitHub release, verifies it against a recorded sha256 with 'sha256sum --check --strict', installs it to /usr/local/bin, and then asserts the version resolved on PATH matches. Previously the workflow never installed shellcheck at all and silently inherited whatever ubuntu-latest shipped, which was 0.9.0.",
|
||||
"The version assertion fails the step immediately, with 'command -v -a shellcheck' output, rather than letting a wrong binary surface as confusing findings 40 hooks later.",
|
||||
"Added EXPECTED_SHELLCHECK_VERSION and check_shellcheck_version() to the git hook library, called from verify_toolchain(), so a local shellcheck that disagrees with the CI pin prints a warning naming both files to update.",
|
||||
"The local check warns rather than aborts on purpose: shellcheck arrives via pacman on a rolling distro, so a bump is routine and must not block a commit. What must not happen silently is local and CI disagreeing about what counts as a finding."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "python3 -c \"import yaml; yaml.safe_load(open('.github/workflows/pre-commit.yml'))\"",
|
||||
"result": "pass",
|
||||
"evidence": "Parses cleanly; steps are checkout, setup-python, Install system dependencies, Install shellcheck (pinned), Install dependencies, Run pre-commit hooks -- the pin lands before the hooks run."
|
||||
},
|
||||
{
|
||||
"command": "the workflow's install steps, executed verbatim in a scratch directory",
|
||||
"result": "pass",
|
||||
"evidence": "curl fetched shellcheck-v0.11.0.linux.x86_64.tar.xz (HTTP 200); 'sha256sum --check --strict' reported OK; the extracted binary reports version 0.11.0, so the version gate would pass in CI."
|
||||
},
|
||||
{
|
||||
"command": "check_shellcheck_version with a stub shellcheck reporting 0.9.0 on PATH",
|
||||
"result": "pass",
|
||||
"evidence": "Emitted: '⚠ shellcheck 0.9.0 locally, CI pins 0.11.0.' followed by both file paths to update. The drift warning was observed firing, not merely assumed to work."
|
||||
},
|
||||
{
|
||||
"command": "check_shellcheck_version against the real local shellcheck 0.11.0",
|
||||
"result": "pass",
|
||||
"evidence": "No output, as intended -- the warning stays silent when the versions agree."
|
||||
},
|
||||
{
|
||||
"command": "shellcheck linux_configuration/.githooks/lib/common.sh",
|
||||
"result": "pass",
|
||||
"evidence": "Zero findings."
|
||||
},
|
||||
{
|
||||
"command": "bash ~/.claude/scripts/finish.sh gate ~/testsAndMisc <2 files>",
|
||||
"result": "pass",
|
||||
"evidence": "FINISH_GATE {\"risk\":\"review\",\"changed_files\":2,\"phase\":\"ok\"} with 1193 Python tests at 100% coverage."
|
||||
},
|
||||
{
|
||||
"command": "gh run view 30940953208 # Pre-commit checks on 9dd9aeb",
|
||||
"result": "pass",
|
||||
"evidence": "Pre-commit checks = success -- the first green run of that workflow since it broke at b83ce5d on 2026-08-03. This change protects that result rather than producing it."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"The pinned version now has to be maintained in two places. The local warning exists precisely to surface that, but a developer who ignores it can still drift.",
|
||||
"The recorded sha256 must be updated alongside SHELLCHECK_VERSION; a bump without it fails the checksum step, which is the intended direction of failure.",
|
||||
"CI now depends on the GitHub release asset being reachable at build time. A transient outage fails the workflow rather than silently falling back to the runner's copy, which is deliberate but is a new external dependency.",
|
||||
"The other language:system tools (prettier, shfmt, zsh, node) remain unpinned and could develop the same class of divergence; only shellcheck has demonstrated it so far."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert the commit; both changes are purely additive and no existing step or function was modified.",
|
||||
"After reverting, CI returns to using the runner image's shellcheck, so expect findings to reappear that local 0.11.0 does not report.",
|
||||
"Confirm with: pre-commit run shellcheck --all-files locally, and check the next CI 'Pre-commit checks' run still passes."
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
{
|
||||
"intent": "Turn the 'Pre-commit checks' CI workflow green again. It has failed on every push since b83ce5d (2026-08-03), the commit that removed shellcheck's --severity filter, because CI runs an older shellcheck than the developer machine and reports 11 findings that shellcheck 0.11.0 no longer emits.",
|
||||
"scope": [
|
||||
"linux_configuration/scripts/boot_recovery/boot-repair",
|
||||
"linux_configuration/scripts/diagnostics/line-speed-probe.sh",
|
||||
"linux_configuration/scripts/single_use/features/keepass_sync.sh",
|
||||
"linux_configuration/scripts/single_use/utils/{gif_to_square,txt_to_image}.sh",
|
||||
"phone_focus_mode/{curfew_enforcer,hosts_enforcer,run_phone}.sh",
|
||||
"phone_focus_mode/lib/tests/test_adb_common.sh",
|
||||
"Non-goal: changing any script's behaviour -- every fix is semantics-preserving",
|
||||
"Non-goal: suppressing findings via directives or a --severity filter",
|
||||
"Non-goal: third_party/, which the shellcheck hook already excludes as vendored code"
|
||||
],
|
||||
"changes": [
|
||||
"SC2015 x6: rewrote 'A && B || C' as an explicit if-statement in boot-repair, line-speed-probe.sh, keepass_sync.sh, curfew_enforcer.sh (x2) and run_phone.sh. Each retains its trailing '|| true' so a failing side effect still cannot abort the caller under set -e.",
|
||||
"SC2119 x3: require_imagemagick and adb_select_device both take an OPTIONAL first argument, so the bare calls were correct. Passing \"$@\" as shellcheck suggests would forward the script's own arguments as a tool preference, which would be a defect; passing an explicit \"\" states the same intent without changing behaviour.",
|
||||
"SC2002 x2: replaced 'cat FILE | tr ...' with 'tr ... < FILE' in hosts_enforcer.sh, keeping 2>/dev/null so a missing file still yields an empty string.",
|
||||
"Kept '|| true' on the _info call in run_phone.sh: it is the last statement of a function under set -e, so dropping it (as the first draft of this change did) would let a failed write to stderr abort the caller."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "shellcheck-v0.9.0 -- <each of the 9 files> # version-matched to CI",
|
||||
"result": "pass",
|
||||
"evidence": "All 9 report OK. Before the change the same binary reproduced CI exactly: 6x SC2015, 3x SC2119, 2x SC2002. A full-repo scan under 0.9.0 leaves findings only in third_party/agent-skills/, which the hook excludes via '^third_party/'."
|
||||
},
|
||||
{
|
||||
"command": "pre-commit run shellcheck --all-files",
|
||||
"result": "pass",
|
||||
"evidence": "shellcheck...Passed over the whole repository."
|
||||
},
|
||||
{
|
||||
"command": "bash phone_focus_mode/lib/tests/test_adb_common.sh",
|
||||
"result": "pass",
|
||||
"evidence": "Results: 13 passed, 0 failed."
|
||||
},
|
||||
{
|
||||
"command": "bash linux_configuration/scripts/boot_recovery/tests/test_boot_repair.sh",
|
||||
"result": "pass",
|
||||
"evidence": "31 passed, 0 failed."
|
||||
},
|
||||
{
|
||||
"command": "behavioural equivalence check for require_imagemagick",
|
||||
"result": "pass",
|
||||
"evidence": "Sourcing lib/common.sh and calling both forms: require_imagemagick \"\" -> OK, MAGICK_CMD=magick; bare require_imagemagick -> OK, MAGICK_CMD=magick. Identical result."
|
||||
},
|
||||
{
|
||||
"command": "behavioural equivalence check for the useless-cat rewrite",
|
||||
"result": "pass",
|
||||
"evidence": "Against a file containing ' 1 ': old 'cat F | tr -d [:space:]' -> [1]; new 'tr -d [:space:] < F' -> [1]. Against a nonexistent path the new form still yields [] with the error suppressed."
|
||||
},
|
||||
{
|
||||
"command": "bash -n on all 8 edited executable scripts",
|
||||
"result": "pass",
|
||||
"evidence": "All report syntax OK."
|
||||
},
|
||||
{
|
||||
"command": "bash ~/.claude/scripts/finish.sh gate ~/testsAndMisc <9 files>",
|
||||
"result": "pass",
|
||||
"evidence": "FINISH_GATE {\"risk\":\"review\",\"changed_files\":9,\"phase\":\"ok\"} with 1193 Python tests passing at 100% coverage. The review pass flagged the dropped '|| true' in run_phone.sh, which was then restored."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"The underlying local/CI divergence remains: CI installs a different shellcheck version than the developer machine, so a future finding can again pass locally and fail in CI. Pinning the version in the workflow would remove the class of problem; that was considered and deferred as a separate change.",
|
||||
"These files were not otherwise exercised end-to-end. curfew_enforcer.sh and hosts_enforcer.sh run on the phone under Magisk and were verified by static analysis, syntax check and unit tests rather than a device run.",
|
||||
"keepass_sync.sh's case arm is now a single-line if-then-fi, which is denser to read than the original; behaviour is unchanged."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert the commit; each change is confined to one or two lines per file and no interfaces changed.",
|
||||
"After reverting, expect 'Pre-commit checks' CI to go red again on the same 11 findings while local shellcheck 0.11.0 continues to report none.",
|
||||
"Re-run pre-commit run shellcheck --all-files plus the phone_focus_mode and boot_recovery test suites to confirm the revert left both in their prior state."
|
||||
]
|
||||
}
|
||||
@ -89,6 +89,83 @@ Run this yourself, then retry:
|
||||
! sudo pacman -S ${pkg}"
|
||||
}
|
||||
|
||||
# Versions of the `language: system` tools that the gates depend on. Every
|
||||
# entry is `command:expected:where`, where `where` names the file that pins
|
||||
# the other side so a mismatch report can point at it.
|
||||
#
|
||||
# Why this table exists: these hooks run whatever binary happens to be on
|
||||
# PATH. When the local copy and the pinned copy disagree about what counts as
|
||||
# a finding -- or, for the formatters, about how a file should be formatted --
|
||||
# a commit passes every local gate and then fails elsewhere on output the
|
||||
# developer cannot reproduce. That is precisely what kept the pre-commit
|
||||
# workflow red from b83ce5d onward, and it cost a full session to diagnose
|
||||
# because the failure was invisible on the developer's machine.
|
||||
#
|
||||
# Two distinct risks are covered here. The linters (shellcheck and zsh) run
|
||||
# in CI, so drift there shows up as an unreproducible CI failure. The
|
||||
# formatters (prettier and shfmt) never run in CI -- they are pre-push and
|
||||
# local-git-hook only -- but they REWRITE files, so drift between two
|
||||
# developers silently reformats the repo back and forth, producing diff churn
|
||||
# nobody intended.
|
||||
readonly PINNED_TOOL_VERSIONS=(
|
||||
"shellcheck:0.11.0:.github/workflows/pre-commit.yml (SHELLCHECK_VERSION)"
|
||||
"prettier:3.9.5:.github/workflows/pre-commit.yml (PRETTIER_VERSION)"
|
||||
"shfmt:3.13.1:.github/workflows/pre-commit.yml (SHFMT_VERSION)"
|
||||
"zsh:5.9:.github/workflows/pre-commit.yml (zsh comes from apt; major.minor only)"
|
||||
)
|
||||
|
||||
# Print the version of a pinned tool, normalised to bare digits.
|
||||
#
|
||||
# Each tool reports differently: shellcheck uses a `version:` line, shfmt and
|
||||
# node prefix a `v`, zsh puts it in field 2. Normalising here keeps the
|
||||
# comparison below a plain string match.
|
||||
_tool_version() {
|
||||
local cmd="$1" raw=""
|
||||
|
||||
case "$cmd" in
|
||||
shellcheck) raw="$(shellcheck --version 2>/dev/null | awk '/^version:/ { print $2 }')" ;;
|
||||
prettier) raw="$(prettier --version 2>/dev/null)" ;;
|
||||
shfmt) raw="$(shfmt --version 2>/dev/null)" ;;
|
||||
# zsh patch releases are not selectable via apt, so compare major.minor
|
||||
# only -- 5.9.2 locally and 5.9 in CI are not a meaningful divergence.
|
||||
zsh) raw="$(zsh --version 2>/dev/null | awk '{ print $2 }' | cut -d. -f1,2)" ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
|
||||
printf '%s' "${raw#v}"
|
||||
}
|
||||
|
||||
# Warn when a local tool disagrees with the version pinned for CI.
|
||||
#
|
||||
# Deliberately warnings, not aborts: these arrive via pacman on a rolling
|
||||
# distro, so bumps are routine and must not block a commit. What must not
|
||||
# happen silently is the disagreement itself.
|
||||
check_pinned_tool_versions() {
|
||||
local entry cmd expected where installed drifted=0
|
||||
|
||||
for entry in "${PINNED_TOOL_VERSIONS[@]}"; do
|
||||
cmd="${entry%%:*}"
|
||||
where="${entry##*:}"
|
||||
expected="${entry#*:}"
|
||||
expected="${expected%%:*}"
|
||||
|
||||
command -v "$cmd" >/dev/null 2>&1 || continue
|
||||
|
||||
installed="$(_tool_version "$cmd")" || continue
|
||||
[[ -n $installed ]] || continue
|
||||
[[ $installed == "$expected" ]] && continue
|
||||
|
||||
hook_log "⚠ ${cmd} ${installed} locally, pinned ${expected}"
|
||||
hook_log " update: ${where}"
|
||||
hook_log " update: linux_configuration/.githooks/lib/common.sh (PINNED_TOOL_VERSIONS)"
|
||||
drifted=1
|
||||
done
|
||||
|
||||
if [[ $drifted -eq 1 ]]; then
|
||||
hook_log " Results may differ between this machine and CI/other developers."
|
||||
fi
|
||||
}
|
||||
|
||||
# Ensure every tool in REQUIRED_TOOLS is present. Fails closed on the first
|
||||
# one that cannot be provided.
|
||||
verify_toolchain() {
|
||||
@ -98,4 +175,6 @@ verify_toolchain() {
|
||||
pkg="${entry##*:}"
|
||||
require_tool "$cmd" "$pkg"
|
||||
done
|
||||
|
||||
check_pinned_tool_versions
|
||||
}
|
||||
|
||||
@ -363,7 +363,9 @@ check_fstab_options() {
|
||||
' OFS='\t' "$fstab" > "${fstab}.new"
|
||||
mv "${fstab}.new" "$fstab"
|
||||
repaired "fstab /boot options reset to 'defaults'"
|
||||
is_live && systemctl daemon-reload 2> /dev/null || true
|
||||
if is_live; then
|
||||
systemctl daemon-reload 2> /dev/null || true
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@ -80,7 +80,9 @@ verdict_for() {
|
||||
cleanup() {
|
||||
local p
|
||||
for p in "${PIDS[@]:-}"; do
|
||||
[[ -n "$p" ]] && kill "$p" 2>/dev/null || true
|
||||
if [[ -n "$p" ]]; then
|
||||
kill "$p" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
wait 2>/dev/null || true
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ remote_get() {
|
||||
}
|
||||
remote_hash() {
|
||||
case "$REMOTE_MODE" in
|
||||
file) [[ -f "$REMOTE_FILE" ]] && sha "$REMOTE_FILE" || true ;;
|
||||
file) if [[ -f "$REMOTE_FILE" ]]; then sha "$REMOTE_FILE" || true; fi ;;
|
||||
webdav) curl -fsS -u "$DUFS_USER:$DUFS_PASS" "${REMOTE_URL}?hash" 2>/dev/null || true ;;
|
||||
esac
|
||||
}
|
||||
|
||||
@ -49,7 +49,9 @@ if ! command -v magick &> /dev/null && ! command -v convert &> /dev/null; then
|
||||
fi
|
||||
fi
|
||||
|
||||
require_imagemagick || exit 1
|
||||
# Empty arg = no preference between magick/convert. Passing "$@" here would
|
||||
# forward this script's own arguments as a tool preference, which is wrong.
|
||||
require_imagemagick "" || exit 1
|
||||
|
||||
# Set up identify command (IM7: magick identify, IM6: identify)
|
||||
if [[ ${MAGICK_CMD} == "magick" ]]; then
|
||||
|
||||
@ -35,7 +35,9 @@ EOF
|
||||
}
|
||||
|
||||
# Check if ImageMagick is installed and determine which command to use
|
||||
require_imagemagick || exit 1
|
||||
# Empty arg = no preference between magick/convert. Passing "$@" here would
|
||||
# forward this script's own arguments as a tool preference, which is wrong.
|
||||
require_imagemagick "" || exit 1
|
||||
|
||||
# Parse arguments
|
||||
if [[ $# -lt 1 ]]; then
|
||||
|
||||
@ -137,7 +137,9 @@ restore_grayscale() {
|
||||
case "$en" in ''|null) en=0 ;; esac
|
||||
case "$lv" in ''|null) lv=-1 ;; esac
|
||||
settings put secure accessibility_display_daltonizer_enabled "$en" 2>/dev/null || true
|
||||
[ "$lv" != "-1" ] && settings put secure accessibility_display_daltonizer "$lv" 2>/dev/null || true
|
||||
if [ "$lv" != "-1" ]; then
|
||||
settings put secure accessibility_display_daltonizer "$lv" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
# ---- Layer 2: Do-Not-Disturb (alarms only) ----
|
||||
@ -232,8 +234,9 @@ NET_BUILT=""
|
||||
# Refresh the cached UID list (one `pm list packages -U` fork). Called once per
|
||||
# main tick so the fast watchdog can rebuild from the cache without forking.
|
||||
refresh_uid_cache() {
|
||||
night_uids > "$CURFEW_NET_UID_CACHE.tmp" 2>/dev/null \
|
||||
&& mv "$CURFEW_NET_UID_CACHE.tmp" "$CURFEW_NET_UID_CACHE" 2>/dev/null || true
|
||||
if night_uids > "$CURFEW_NET_UID_CACHE.tmp" 2>/dev/null; then
|
||||
mv "$CURFEW_NET_UID_CACHE.tmp" "$CURFEW_NET_UID_CACHE" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
# Rebuild the chain from cache for whichever iptables variants exist. No pm fork.
|
||||
|
||||
@ -55,7 +55,7 @@ acquire_lock() {
|
||||
old_pid="$(cat "$PIDFILE")"
|
||||
if kill -0 "$old_pid" 2>/dev/null; then
|
||||
local cmdline
|
||||
cmdline="$(cat "/proc/$old_pid/cmdline" 2>/dev/null | tr '\0' ' ')"
|
||||
cmdline="$(tr '\0' ' ' < "/proc/$old_pid/cmdline" 2>/dev/null)"
|
||||
if echo "$cmdline" | grep -q "hosts_enforcer"; then
|
||||
echo "hosts_enforcer already running (PID $old_pid)"
|
||||
exit 0
|
||||
@ -82,7 +82,7 @@ sha256_of() {
|
||||
workout_active() {
|
||||
[ -f "$WORKOUT_ACTIVE_FILE" ] || return 1
|
||||
local v
|
||||
v="$(cat "$WORKOUT_ACTIVE_FILE" 2>/dev/null | tr -d '[:space:]')"
|
||||
v="$(tr -d '[:space:]' < "$WORKOUT_ACTIVE_FILE" 2>/dev/null)"
|
||||
[ "$v" = "1" ]
|
||||
}
|
||||
|
||||
|
||||
@ -172,7 +172,8 @@ TRUSTED_MODEL='Pixel 7rm -rf /dangerline2'
|
||||
TRUSTED_FINGERPRINT='google/pixel:14/UP1A.231005.007/evilcmd'
|
||||
EOF
|
||||
|
||||
if (adb_select_device >/dev/null 2>&1); then
|
||||
# Empty arg = no requested serial, which is what this case exercises.
|
||||
if (adb_select_device "" >/dev/null 2>&1); then
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
||||
@ -68,7 +68,12 @@ _auto_repair_minor_drift() {
|
||||
fi
|
||||
fi
|
||||
|
||||
[[ ${repaired} -gt 0 ]] && _info "Minor repairs applied: ${repaired}" || true
|
||||
# `|| true` retained from the original `&& ... || true`: this is the last
|
||||
# statement of the function under `set -e`, so a failed write to stderr
|
||||
# would otherwise abort the caller.
|
||||
if [[ ${repaired} -gt 0 ]]; then
|
||||
_info "Minor repairs applied: ${repaired}" || true
|
||||
fi
|
||||
}
|
||||
|
||||
cmd_auto() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user