mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-24 06:26:22 +01:00
Compare commits
No commits in common. "d42d8ff20d42fde906185da76e3898b0e1ecc74a" and "0048293a2ba30f7f1cb5b4d1a58c3677bec3dd37" have entirely different histories.
d42d8ff20d
...
0048293a2b
@ -12,124 +12,45 @@ it was non-interactive — a grilling round would have ended the turn with
|
||||
nothing delivered. **The user can still veto any of these cheaply**, since the
|
||||
gate is not yet in the hook chain:
|
||||
|
||||
- **Q1 Scope → ratchet.** 115 pre-existing libraries are exempt via
|
||||
`meta/shell-coverage-allowlist.txt`; any library not on that list must be
|
||||
covered, so a new one cannot enter untested. Unrelated commits are never
|
||||
blocked (verified). **Exemption is static** — editing an allowlisted library
|
||||
is allowed and does not demand tests. An entry leaves the list only when its
|
||||
directory gains a suite.
|
||||
- **Q2 Bar → presence, not a percentage — but NOT because a percentage is
|
||||
impossible.** An earlier session on 2026-08-21 reached **100% (38/38) on
|
||||
`setup_night_lockdown.sh` with no source changes and no suppressions**, using
|
||||
a user-namespace jail, with containment verified by canary. The generic
|
||||
runner then got **75% (57/76) on `pacman_wrapper.sh`**, because each subject
|
||||
needs its own mount analysis. So a numeric bar is reachable but costs bespoke
|
||||
per-file work — presence is the floor that can land today, and a percentage
|
||||
can layer on top later. See
|
||||
`docs/superpowers/evidence/phase3-namespace-jail-feasibility-2026-08-21.json`
|
||||
and `meta/scripts/shell_coverage.sh`. **Both jail subjects were entry
|
||||
scripts, which Q3 puts out of scope**, so nothing is yet measured for the 198
|
||||
`lib/` files.
|
||||
- **Q1 Scope → ratchet.** 125 pre-existing libraries are exempt via
|
||||
`meta/shell-coverage-allowlist.txt`; only new or modified libraries must be
|
||||
covered. Unrelated commits are never blocked (verified).
|
||||
- **Q2 Bar → presence, not a percentage.** A numeric bar is unreachable here:
|
||||
Phase 1 measured the effecting code at 0% because it sudos, pkills and
|
||||
installs, so hitting a number needs either mass shimming or the suppressions
|
||||
this repo forbids. The gate asserts a `tests/run_all.sh` exists beside the lib.
|
||||
- **Q3 Which files → `.sh` under a `lib/` dir**, excluding `lib/tests/` and
|
||||
`lib/payloads/`. Entry scripts are orchestration whose bodies are untestable.
|
||||
|
||||
## The one thing left to do
|
||||
|
||||
`meta/scripts/check_shell_coverage.sh` works standalone but is **not in
|
||||
`.pre-commit-config.yaml`**. That edit has now been **denied twice** as a
|
||||
sensitive file (2026-08-21, two separate sessions), so it is not an oversight
|
||||
and not worth a third agent attempt — **the user must paste it**. Do not try
|
||||
to route around the denial with `sed`/heredoc/`python`; the restriction is
|
||||
deliberate.
|
||||
|
||||
Paste this block **directly after the `file-length-cap` hook** (which ends at
|
||||
`always_run: true`, immediately before `- id: ci-baseline-green`).
|
||||
|
||||
**Indent every line below by 6 spaces** so `- id:` lines up with the
|
||||
neighbouring `- id: file-length-cap` and `- id: ci-baseline-green`. The block
|
||||
is shown unindented because prettier reformats fenced code and strips the
|
||||
leading whitespace; it is a `repo: local` hook list, so the indentation is
|
||||
load-bearing and YAML will reject a flush-left paste.
|
||||
`.pre-commit-config.yaml`** — that edit was denied as a sensitive file. Add
|
||||
this block after the `file-length-cap` hook (note `files:`, **not** `--all`;
|
||||
per-file is what makes it a ratchet):
|
||||
|
||||
```yaml
|
||||
- id: shell-coverage-ratchet
|
||||
name: Shell libraries must have a test suite
|
||||
# Per-file (files:, NOT --all) is what makes this a ratchet rather than
|
||||
# a repo-wide gate: the 115 libraries that predate it stay exempt via
|
||||
# meta/shell-coverage-allowlist.txt, so unrelated commits never block,
|
||||
# but a NEW library cannot enter without a tests/run_all.sh beside it.
|
||||
# Filenames must be passed — with pass_filenames: false the script
|
||||
# would receive no arguments, iterate nothing, and pass forever.
|
||||
entry: bash meta/scripts/check_shell_coverage.sh
|
||||
language: system
|
||||
files: \.sh$
|
||||
```
|
||||
|
||||
Or let `sed` do the indenting — copy the block above into `/tmp/hook.yaml`,
|
||||
then `sed 's/^/ /' /tmp/hook.yaml` and paste that output.
|
||||
|
||||
**Do NOT copy `pass_filenames: false` from the neighbouring `file-length-cap`
|
||||
hook.** That hook uses it because it runs `--all`; this one is driven by
|
||||
`files:`. With `pass_filenames: false` the script gets zero arguments,
|
||||
`report_uncovered "$@"` iterates nothing, and the gate exits 0 forever — a
|
||||
dead gate that looks green in every test you would naturally run.
|
||||
|
||||
### Verification already done (2026-08-21) — do not redo
|
||||
|
||||
The script's own behaviour is measured; only the YAML wiring is outstanding.
|
||||
|
||||
| Case | Command | Result |
|
||||
| ------------------------------------- | --------------------------------------------------------------- | ----------------------------------------------- |
|
||||
| Unrelated entry script must not block | `check_shell_coverage.sh meta/scripts/check_file_length.sh` | exit **0** |
|
||||
| New untested lib must block | canary `linux_configuration/scripts/lib/_ratchet_canary_tmp.sh` | exit **1**, names the needed `tests/run_all.sh` |
|
||||
| Batch, all covered | 3 covered files in one call | exit **0** |
|
||||
| Batch, 3rd of 4 uncovered | canary in the middle of a batch | exit **1** |
|
||||
| A `lib/tests/` harness must not block | `check_shell_coverage.sh <a lib/tests/*.sh>` | exit **0** — script self-filters |
|
||||
|
||||
That last row is why the block needs **no `exclude:`**. `files: \.sh$` does
|
||||
match `lib/tests/` and `lib/payloads/` files, but the script filters them
|
||||
itself, so the gate cannot block its own test suites.
|
||||
|
||||
The batch cases matter because pre-commit passes many filenames per
|
||||
invocation; a loop that only inspected `$1` would have passed silently.
|
||||
|
||||
After pasting, confirm the wiring end-to-end:
|
||||
|
||||
```bash
|
||||
pre-commit run shell-coverage-ratchet --all-files # expect pass (115 exempt)
|
||||
grep -n "shell-coverage-ratchet" .pre-commit-config.yaml
|
||||
```
|
||||
|
||||
The `grep` is not redundant — an autoformat pass silently stripped
|
||||
load-bearing lines three times during Phase 1. Check after the commit lands,
|
||||
not before.
|
||||
Then re-verify the negative case before trusting it:
|
||||
`bash meta/scripts/check_shell_coverage.sh meta/scripts/check_file_length.sh`
|
||||
must exit 0 (an unrelated entry script must never block a commit).
|
||||
|
||||
**Do not run `--seed` after adding an untested library** — it would rewrite the
|
||||
allowlist and silently exempt it. The list is shrink-only, and `--seed` now
|
||||
enforces that by exiting 1 rather than adding an entry.
|
||||
allowlist and silently exempt it. The list is shrink-only; nothing mechanically
|
||||
enforces that yet.
|
||||
|
||||
## Chipping away at the 115
|
||||
## Chipping away at the 125
|
||||
|
||||
198 in-scope libraries: 115 exempt, 83 already covered. The allowlist is
|
||||
concentrated: `single_use/features/lib` (45), `single_use/fixes/lib` (22),
|
||||
`phone_focus_mode/lib` (9), `scripts/lib` (9). Adding one `tests/run_all.sh`
|
||||
to a directory enforces every file in it at once, so expect the work to arrive
|
||||
in batches rather than one file at a time.
|
||||
|
||||
**`--seed` is shrink-only and now enforces it** — it exits 1 rather than adding
|
||||
an entry, so you cannot exempt a new library by reseeding. It reads tracked
|
||||
files only, so stage before trusting its output.
|
||||
|
||||
## Phase 4 (later): a percentage bar on top of the ratchet
|
||||
|
||||
The namespace-jail evidence above is the load-bearing input. The technique
|
||||
works and is contained; what is unmeasured is whether it generalises to `lib/`
|
||||
files rather than entry scripts, and what per-file mount analysis costs at
|
||||
scale. The `pacman_wrapper.sh` result names the dominant failure mode: masking
|
||||
`/usr/local/bin` makes the wrapper take its "libraries missing → exec pacman
|
||||
unwrapped" escape hatch at lines 44-45 and exit before doing any real work, so
|
||||
coverage collapses from 75% to 29%. Measure a handful of `lib/` files through
|
||||
`jail_run.sh` before proposing any number.
|
||||
The allowlist is concentrated: `single_use/features/lib` (45),
|
||||
`single_use/fixes/lib` (22), `phone_focus_mode/lib` (9), `scripts/lib` (9).
|
||||
Adding one `tests/run_all.sh` to a directory enforces every file in it at once,
|
||||
so expect the work to arrive in batches rather than one file at a time.
|
||||
|
||||
## What is already true (verify, do not redo)
|
||||
|
||||
@ -155,8 +76,9 @@ gh run list --limit 5
|
||||
|
||||
```bash
|
||||
git ls-files '*.sh' | wc -l # 560 tracked
|
||||
git ls-files '*/lib/*.sh' | grep -v '/lib/tests/' | wc -l # 208 libraries
|
||||
git ls-files '*/lib/tests/run_all.sh' # 4 suites
|
||||
bash meta/scripts/check_shell_coverage.sh --all # 115 uncovered, 115 exempt
|
||||
bash meta/scripts/check_shell_coverage.sh --all # 125 uncovered, 125 exempt
|
||||
```
|
||||
|
||||
A bare `find` reports 565 `.sh` files because it walks `.venv/`,
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
{
|
||||
"title": "Shrink the shell-coverage allowlist: a real test suite for linux_configuration/scripts/lib",
|
||||
"objective": "Start chipping at the 115-entry shell-coverage allowlist with the smallest concentrated batch, so the ratchet narrows rather than merely holding. One tests/run_all.sh covers all nine libraries in that directory at once, which is what makes this the highest-ratio first batch. The nine entries come off the allowlist as a result — the deliverable is the allowlist shrinking, not the suite existing.",
|
||||
"acceptance_criteria": [
|
||||
"run_all.sh runs every test_*.sh in the directory and exits 0, with all four suites reporting zero failures.",
|
||||
"The suite is proven NON-VACUOUS by mutation: the coverage gate only checks that tests/run_all.sh exists, so an empty file would mark all nine libraries covered while testing nothing. Each of the four load-bearing rules must be mutated and the suite must go red for each.",
|
||||
"meta/shell-coverage-allowlist.txt drops from 115 entries to 106, with zero entries remaining for linux_configuration/scripts/lib/ — the measured delta, not a rounded one.",
|
||||
"No assertion depends on wall-clock time, this host's udev rules, or a real device: the suite runs in shell-tests.yml and again on every pre-push via ci-mirror, so a host-dependent assertion becomes a push-blocking flake.",
|
||||
"Sourcing a library must not write outside the test tmpdir — android.sh calls ensure_dir on a $HOME path at source time.",
|
||||
"shellcheck and shfmt pass with no suppression added."
|
||||
],
|
||||
"out_of_scope": [
|
||||
"Wiring shell-coverage-ratchet into .pre-commit-config.yaml. That edit is denied as a sensitive file and belongs to the user; NEXT_SESSION_PROMPT.md carries the block.",
|
||||
"The effecting half of these libraries: require_hosts_readable (exec sudo), check_adb_device/check_adb_root (die -> exit), collapse_mounts (umount -l), install_missing_pacman_packages, require_imagemagick, notify. Phase 1 measured this pattern already — decision logic reaches ~90%, effecting code reaches 0%.",
|
||||
"mtk_udev_catchall_files, which globs /etc/udev/rules.d with no seam and would read this host's real rules.",
|
||||
"The other 106 allowlist entries; the next concentrated batches are single_use/features/lib (45) and single_use/fixes/lib (22).",
|
||||
"A percentage coverage bar. The bar remains presence, as settled in Phase 3."
|
||||
],
|
||||
"verifier": "bash linux_configuration/scripts/lib/tests/run_all.sh (exit 0; 139 assertions across 4 suites). Four mutations applied to throwaway copies, each required to turn the suite red: classify_device's `&&` -> `||` (would classify a stranger's MediaTek phone as the target device), discover_partitions' `init_boot boot` -> `boot init_boot` (would dump the wrong partition on Android 13+ hardware), mtk_select_device's `-gt 1` -> `-gt 99` (would silently pick one of two attached phones), and is_hour_in_range's `10#$` removal (the 08/09 octal trap). Allowlist delta measured with `grep -vc '^#\\|^$' meta/shell-coverage-allowlist.txt` before and after --seed."
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
{
|
||||
"intent": "Establish empirically, before writing tests for 565 .sh files, whether Phase 3's constraints are jointly satisfiable: a repo-wide gate at 100% line coverage over ALL shell files, with no suppressions. Phase 1 measured effecting code at 0% under PATH shims; if that were the ceiling, 100% would require either forbidden suppressions or source seams in 17+46 files.",
|
||||
"scope": [
|
||||
"Measurement only - no production file was modified",
|
||||
"Subjects: setup_night_lockdown.sh (entry script, 127 lines) and pacman_wrapper.sh (215 lines)",
|
||||
"Non-goal: writing the test suites themselves; this answers the feasibility question that gates them"
|
||||
],
|
||||
"changes": [
|
||||
"Added this evidence artifact recording the feasibility result",
|
||||
"No source, script, or configuration file was changed; probe scripts live only in the session scratchpad"
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "bash meta/scripts/shell_coverage.sh <digital_wellbeing run_all.sh> <lib> 0",
|
||||
"result": "pass - baseline reproduces NEXT_SESSION_PROMPT.md exactly",
|
||||
"evidence": "leechblock_fetch.sh 38.57%, leechblock_browsers.sh 36.47%, cco_state.sh 93.94% (uncovered 125-128 = kill_app's pkill lines)"
|
||||
},
|
||||
{
|
||||
"command": "kcov 'help' alone into a fresh dir, vs 4 subcommands accumulated into one dir",
|
||||
"result": "pass - kcov unions across runs, so the union number is real",
|
||||
"evidence": "help alone = 26/38 (68.42%); four cases accumulated = 31/38 (81.58%). Different numbers prove merging works rather than overwriting."
|
||||
},
|
||||
{
|
||||
"command": "scratchpad/probe2.sh - PATH shims for sudo/systemctl/modprobe/pkill plus HOME and XDG redirected into the jail",
|
||||
"result": "pass - establishes the PATH-shim-only ceiling at 81.58%",
|
||||
"evidence": "31/38 = 81.58%. Uncovered 86,87,93,95,96 (install_i2c_modules: a bare `cat >` to /etc with no sudo to intercept) and 115,117 (dispatch arms behind require_root's EUID branch)."
|
||||
},
|
||||
{
|
||||
"command": "unshare --user --map-root-user --mount --fork, with /etc bind-mounted to a jail copy",
|
||||
"result": "pass - the namespace closes the require_root residue with zero source changes",
|
||||
"evidence": "EUID becomes 0 so require_root falls through naturally and lines 115/117 execute. Coverage rose 81.58% -> 86.84% (33/38)."
|
||||
},
|
||||
{
|
||||
"command": "unshare --user --map-root-user --mount, binding /etc, /usr/local/bin and /var/lib, plus a jail passwd/group/nsswitch in which the invoking user resolves",
|
||||
"result": "pass - 100% reached with no source changes and no suppressions",
|
||||
"evidence": "38/38 = 100.00%. Installer artifacts night-lockdown-enter.sh, night-lockdown-unlock.sh and night-lockdown-i2c.conf all landed INSIDE the jail."
|
||||
},
|
||||
{
|
||||
"command": "canary write to /etc/modules-load.d/CANARY_TEST.conf inside the namespace, then ls the real dir; plus ls -la /etc/modules-load.d/night-lockdown-i2c.conf after every probe",
|
||||
"result": "pass - containment holds; the real system was never touched",
|
||||
"evidence": "The canary appeared only in the jail copy. The real night-lockdown-i2c.conf kept its original Jul 23 11:56 mtime across all probes, and git status stayed clean."
|
||||
},
|
||||
{
|
||||
"command": "scratchpad/jail_run.sh <subject> <arg-sets> - a generalised runner rebuilt from the proven mounts",
|
||||
"result": "pass - the jail is reusable, not hand-tuned to one subject",
|
||||
"evidence": "Reproduced 38/38 = 100.00% on setup_night_lockdown.sh through the generic runner."
|
||||
},
|
||||
{
|
||||
"command": "jail_run.sh on pacman_wrapper.sh with /usr/local/bin bind-mounted, vs the same cases without that mount",
|
||||
"result": "pass - generalises, and exposes the dominant failure mode",
|
||||
"evidence": "28.95% (22/76) with /usr/local/bin masked vs 75.00% (57/76) without it. The wrapper sources sibling libs from /usr/local/bin and takes its 'libraries missing -> exec pacman unwrapped' escape hatch at lines 44-45 when they vanish, exiting before any real work."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"DECISIVE FINDING: 100% line coverage on an entry script is achievable with NO source changes and NO suppressions, so the earlier estimate that 17 files need path seams and 46 need require_root seams is superseded.",
|
||||
"--map-root-user ALONE is insufficient for /etc writes: CAP_DAC_OVERRIDE inside a userns only covers files whose owner uid is mapped in. The bind-mount over the write target is what makes the write land.",
|
||||
"The jail must supply its own /etc/passwd, /etc/group and /etc/nsswitch.conf. Inside the userns the invoking user does not resolve, so `id -u <user>` fails and aborts any script using it under set -e. This cost three iterations to find.",
|
||||
"Entry scripts cannot be staged into a temp dir the way libs can: they resolve libs via BASH_SOURCE and common.sh via `readlink -f \"$0\"`, so they must be executed in place as $0.",
|
||||
"The jail must be PER-SCRIPT: mount only what a script WRITES and preserve what it READS. A blanket jail masking /usr/local/bin cut pacman_wrapper.sh from 75.00% to 28.95%. An over-aggressive mount looks exactly like unreachable code, which is the same misdiagnosis class that produced the false 81.58% ceiling.",
|
||||
"Arbitrary argument sets do not drive coverage; cases must be designed from each script's own dispatch logic. This, not the jail, is the dominant per-file cost across 565 files.",
|
||||
"Running installers for real as uid 0 inside a namespace is safe only while every write target is mounted; a missing mount plus a writable real path would modify the live system.",
|
||||
"An uncommitted file meta/scripts/check_shell_coverage.sh appeared in the working tree during this session. It was never committed (git log across all refs is empty for it) and this session's probes never reference that path, so its origin is unknown. Its content implements the lib-only presence-ratchet design that was overruled, so it must not be wired in. Left untouched deliberately."
|
||||
],
|
||||
"rollback": [
|
||||
"Nothing to revert: no production file was changed. Deleting this evidence file restores the prior tree state.",
|
||||
"After rollback, confirm with `git status` that the tree is clean and `bash meta/scripts/check_file_length.sh --all` still passes."
|
||||
]
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
{
|
||||
"intent": "Fix two defects in the shell-coverage ratchet found in review, before the gate is wired into pre-commit: a path classifier that treated test helpers as production libraries, and a shrink-only rule that was documented but not enforced.",
|
||||
"scope": [
|
||||
"meta/scripts/check_shell_coverage.sh — is_shell_lib classifier, seed_allowlist guard",
|
||||
"meta/shell-coverage-allowlist.txt — reseeded 125 -> 115 as a legitimate shrink",
|
||||
"NON-GOAL: wiring the pre-commit hook. That edit is still denied as a sensitive file; the YAML block to add is recorded in NEXT_SESSION_PROMPT.md."
|
||||
],
|
||||
"changes": [
|
||||
"is_shell_lib now excludes */tests/lib/* as well as */lib/tests/*. Both nestings are test code; only the first was excluded, so helpers under tests/lib/ were classified as production libraries and the gate demanded 'tests/lib/tests/run_all.sh' — an incoherent path. Confirmed by probe before fixing: un-exempting linux_configuration/tests/lib/ made the gate emit exactly that demand for 7 files.",
|
||||
"The bug's timing was the reason to fix it now, not its size: Phase 3's follow-up work is writing test suites, which means editing test helpers — precisely the files that would have been blocked.",
|
||||
"--seed now diffs the proposed set against the existing allowlist and exits 1 if it would ADD any entry, rather than relying on a header comment saying not to. Per workflow-rules.md, a remedy that only works if a human remembers something is hygiene, not a fix.",
|
||||
"Corrected a docs-vs-code mismatch: the parent commit's script header, commit message and handoff all said an exempt file loses its exemption 'when next modified', but check_files never consults modification — it exempts allowlisted paths unconditionally. Verified by staging an edit to phone_focus_mode/lib/adb_common.sh and running the gate: exit 0. Fixed the TEXT rather than the code, because making an edit trip the gate would block routine work across 115 of the repo's 198 shell libraries, which is the repo-wide gate this ratchet exists to avoid.",
|
||||
"Corrected the parent commit's rationale, which claimed a coverage percentage was unreachable without forbidden suppressions. It is reachable: an earlier session the same day hit 100% (38/38) on setup_night_lockdown.sh via a user-namespace jail with no source changes and no suppressions. Presence remains the right bar because the generic runner scored 75% (57/76) on the next subject, so a percentage needs bespoke per-file mount analysis — a cost, not an impossibility.",
|
||||
"Reseeded the allowlist from 125 to 115; the 10 removed entries are the misclassified test helpers under linux_configuration/tests/lib, scripts/mtk_root/tests/lib and scripts/boot_recovery/tests/lib."
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "bash meta/scripts/check_shell_coverage.sh --seed",
|
||||
"result": "pass",
|
||||
"evidence": "'seeded allowlist with 115 uncovered librar(ies)', down from 125. `grep -c '/tests/lib/'` on the allowlist is now 0."
|
||||
},
|
||||
{
|
||||
"command": "bash meta/scripts/check_shell_coverage.sh linux_configuration/tests/lib/i3blocks_claude_usage.sh",
|
||||
"result": "pass",
|
||||
"evidence": "exit=0. Before the fix the same file was reported as needing linux_configuration/tests/lib/tests/run_all.sh."
|
||||
},
|
||||
{
|
||||
"command": "git add -N <a new untested lib>; bash meta/scripts/check_shell_coverage.sh --seed",
|
||||
"result": "pass",
|
||||
"evidence": "exit=1, 'refusing to seed — that would ADD 1 entr(ies)', and `diff -q` confirms the allowlist file was left byte-identical. Note the guard only sees tracked files: an unstaged probe was invisible to `git ls-files` and seeded normally, so the first run of this probe was a false negative until the file was staged."
|
||||
},
|
||||
{
|
||||
"command": "full case matrix: covered lib / unrelated entry script / exempt lib / test helper / new untested lib",
|
||||
"result": "pass",
|
||||
"evidence": "exits 0,0,0,0,1 — all five as intended. The unrelated-entry-script case (exit 0) is the one that distinguishes a ratchet from a repo-wide gate."
|
||||
},
|
||||
{
|
||||
"command": "git add <edit to phone_focus_mode/lib/adb_common.sh>; bash meta/scripts/check_shell_coverage.sh phone_focus_mode/lib/adb_common.sh",
|
||||
"result": "pass",
|
||||
"evidence": "exit=0 — a modified allowlisted library is NOT blocked, disproving the 'until modified' wording in the parent commit. File restored from backup and `git status` confirmed clean afterwards. A first attempt used the path phone_focus_mode/lib/adb.sh, which does not exist; that created a stray 22-byte untracked file whose exit=1 was a false positive. It was deleted and the test rerun against the real allowlisted path."
|
||||
},
|
||||
{
|
||||
"command": "shellcheck meta/scripts/check_shell_coverage.sh; shfmt -d meta/scripts/check_shell_coverage.sh",
|
||||
"result": "pass",
|
||||
"evidence": "shellcheck clean, shfmt reports no diff. No suppressions added."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"The gate still proves a suite EXISTS beside a library, not that it exercises that specific file. A directory that already has a run_all.sh can gain an untested library silently — the shrink-only guard does not close this, because such a file is never a candidate for the allowlist in the first place.",
|
||||
"The --seed guard reads tracked files only. A library that exists on disk but has never been git-added is invisible to both the guard and the gate until staged; pre-commit stages before running hooks, so this is not a hole in the hook path.",
|
||||
"Counts in this session drifted twice and are worth stating precisely once: an earlier per-directory map was inflated because the git pathspec '*' crosses '/', and the 208 figure in the parent commit's evidence predates this fix, since it still counted the 10 test helpers as libraries. Verified independently after the fix: 198 in-scope libraries = 115 exempt + 83 covered."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert this commit. That restores the 125-entry allowlist and the classifier that misreads tests/lib, so it should be paired with reverting the parent commit 3278bebd rather than done alone.",
|
||||
"After rollback confirm `bash meta/scripts/check_shell_coverage.sh --all` still runs and that no pre-commit hook references the script, since the hook entry was never landed."
|
||||
]
|
||||
}
|
||||
@ -1,72 +0,0 @@
|
||||
{
|
||||
"intent": "Shrink the shell-coverage allowlist from 115 entries to 106 by giving linux_configuration/scripts/lib a real test suite, so the ratchet narrows instead of merely holding the line. Nine libraries lose their exemption at once, because coverage is per-directory.",
|
||||
"scope": [
|
||||
"New: linux_configuration/scripts/lib/tests/ — run_all.sh, mtk_harness.sh, and four test_*.sh suites",
|
||||
"Modified: meta/shell-coverage-allowlist.txt — reseeded, 115 -> 106 entries, all nine linux_configuration/scripts/lib/ entries removed",
|
||||
"No change to any library under test. This commit adds tests and removes exemptions; it does not touch the code being tested.",
|
||||
"Non-goal: wiring shell-coverage-ratchet into .pre-commit-config.yaml — denied as a sensitive file, so it stays with the user (see NEXT_SESSION_PROMPT.md)",
|
||||
"Non-goal: the effecting half of these libraries (sudo re-exec, umount -l, pacman, adb against real hardware) and mtk_udev_catchall_files, which has no seam"
|
||||
],
|
||||
"changes": [
|
||||
"Covered the mtk toolkit through its existing MTK_ROOT_FIXTURE seam, which mtk_common.sh documents as the only boundary with real hardware — props.txt and by-name.txt fixtures make the whole suite offline and hermetic",
|
||||
"Asserted the three safety rules that a plausible refactor would break: classify_device requires a MediaTek signal AND a vendor match (never either, so a third phone lands in UNKNOWN); discover_partitions prefers init_boot over boot; mtk_select_device refuses to guess between two attached devices",
|
||||
"Shimmed adb onto a narrowed PATH for the device-selection suite, with the shim exiting 97 on any unexpected subcommand rather than returning an empty string that would read as 'no devices'",
|
||||
"Kept every assertion independent of wall-clock time: get_hour and get_day_of_week are shimmed where a specific value is needed, and the real /proc/uptime readers are asserted on shape only. This suite runs in shell-tests.yml and again on every pre-push via ci-mirror, so a time-dependent assertion would be a push-blocking flake.",
|
||||
"Redirected HOME to a tmpdir before sourcing, because android.sh runs ensure_dir on a $HOME path at source time — merely loading the library writes to ~/.cache otherwise",
|
||||
"Named the deliberately-untested functions and the reason for each in mtk_harness.sh's header, since the gate checks only that run_all.sh exists and cannot tell a real suite from an empty one"
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "bash linux_configuration/scripts/lib/tests/run_all.sh",
|
||||
"result": "pass",
|
||||
"evidence": "exit 0; 139 assertions across 4 suites, 0 failed (common_datetime 55, mtk_partitions 36, mtk_device 26, mtk_classify 22)."
|
||||
},
|
||||
{
|
||||
"command": "mutation: classify_device's `$mtk_match -eq 1 && $ulefone_match -eq 1` -> `||`, on a throwaway copy",
|
||||
"result": "pass",
|
||||
"evidence": "Suite exits 1. This is the regression that would classify a stranger's MediaTek phone as the target device; the ULEFONE and PIXEL cases still pass under the mutation, so only the third-phone case catches it."
|
||||
},
|
||||
{
|
||||
"command": "mutation: discover_partitions' `for candidate in init_boot boot` -> `boot init_boot`",
|
||||
"result": "pass",
|
||||
"evidence": "Suite exits 1. Checking boot first picks the wrong ramdisk carrier on Android 13+ hardware, silently, because both partitions exist and both reads succeed."
|
||||
},
|
||||
{
|
||||
"command": "mutation: mtk_select_device's `${#serials[@]} -gt 1` -> `-gt 99`",
|
||||
"result": "pass",
|
||||
"evidence": "Suite exits 1. A version that took serials[0] with two phones attached passes every other assertion in that file."
|
||||
},
|
||||
{
|
||||
"command": "mutation: is_hour_in_range's `$((10#$current_hour))` -> `$((current_hour))`",
|
||||
"result": "pass",
|
||||
"evidence": "Suite exits 1 — but only after the assertion was strengthened. The first version checked exit status alone and the mutation SURVIVED: bash aborts with 'value too great for base (error token is \"09\")', a non-zero exit indistinguishable from an honest out-of-range result. The assertion now checks stderr is empty."
|
||||
},
|
||||
{
|
||||
"command": "grep -vc '^#\\|^$' meta/shell-coverage-allowlist.txt (before, after)",
|
||||
"result": "pass",
|
||||
"evidence": "115 -> 106. `grep -c 'linux_configuration/scripts/lib/'` goes 9 -> 0, matching the predicted delta exactly."
|
||||
},
|
||||
{
|
||||
"command": "bash meta/scripts/check_shell_coverage.sh linux_configuration/scripts/lib/mtk_classify.sh linux_configuration/scripts/lib/common_datetime.sh",
|
||||
"result": "pass",
|
||||
"evidence": "exit 0 — the nine libraries are now covered on their merits rather than exempt."
|
||||
},
|
||||
{
|
||||
"command": "git ls-files -s linux_configuration/scripts/lib/tests/",
|
||||
"result": "pass",
|
||||
"evidence": "All six files staged 100755. Staged with `git add --chmod=+x`; a plain `git add` afterwards would reset the bit and the shebang hook rejects 100644."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"Coverage is presence, not a percentage. The gate cannot distinguish these 139 assertions from an empty run_all.sh, and the nine libraries are now permanently off the allowlist — if a later commit guts the suite, nothing detects it. The harness header naming what is and is not exercised is the only durable record.",
|
||||
"The effecting halves of android.sh, common_packages.sh and common_services.sh remain at 0%, so the exemption has been traded for partial coverage rather than full coverage. This is Phase 1's measured pattern, not a regression, but the allowlist no longer records it.",
|
||||
"The adb shim narrows PATH to a shim dir plus /usr/bin and /bin. If mtk_device.sh later reaches for an external not seeded there, the suite aborts under `set -e` with no stderr — the exact failure that cost twenty minutes in Phase 1.",
|
||||
"mtk_check_venv is asserted only on its 'missing' branch, reached by pointing MTK_ROOT_CACHE at an empty tmpdir. The 'broken' branch (a venv that exists but fails `import usb`) is unexercised.",
|
||||
"This suite now runs on every pre-push via ci-mirror, so it is on the critical path for pushing any change to this repo, not just shell changes."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert this commit. It restores the nine allowlist entries and deletes the tests directory; no library under test changes, so nothing executable is affected.",
|
||||
"After rollback, confirm `bash meta/scripts/check_shell_coverage.sh --all` reports 115 exempt entries and exits 0.",
|
||||
"To keep the suite but restore the exemptions, delete linux_configuration/scripts/lib/tests/run_all.sh only — is_covered() checks for that one file, so the other suites can stay in place while the directory reverts to exempt."
|
||||
]
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
{
|
||||
"intent": "Record the measured behaviour of the shell-coverage ratchet gate and hand off the one remaining step -- pasting its hook block into .pre-commit-config.yaml -- which an agent cannot perform because that path is permission-denied as a sensitive file.",
|
||||
"scope": [
|
||||
"NEXT_SESSION_PROMPT.md -- rewrote 'The one thing left to do' with the exact block, its indentation, its anchor point, and the completed verification table",
|
||||
"Non-goal: editing .pre-commit-config.yaml. The edit was denied in two separate sessions; routing around the denial via sed/heredoc/python is explicitly ruled out",
|
||||
"Non-goal: chipping at the 115 allowlist entries. Mixing that in would blur the signal on whether the gate wired correctly",
|
||||
"No behaviour change to meta/scripts/check_shell_coverage.sh -- this commit only measures and documents it"
|
||||
],
|
||||
"changes": [
|
||||
"Documented that the .pre-commit-config.yaml edit has now been denied twice, so a third agent attempt is not worth making and the paste belongs to the user",
|
||||
"Added an explicit warning against copying pass_filenames: false from the adjacent file-length-cap hook -- that hook needs it because it runs --all, whereas this one is driven by files:. With it, the script receives zero arguments, report_uncovered iterates nothing, and the gate exits 0 forever while appearing green",
|
||||
"Gave the pasted block the same 6-space indentation as its neighbours and named its anchor (after file-length-cap's always_run: true, before ci-baseline-green)",
|
||||
"Recorded the four measured gate cases as a table so the next session does not re-derive them",
|
||||
"Added the post-commit grep for shell-coverage-ratchet, because a Phase 1 autoformat pass silently stripped load-bearing lines three times"
|
||||
],
|
||||
"verification": [
|
||||
{
|
||||
"command": "bash meta/scripts/check_shell_coverage.sh meta/scripts/check_file_length.sh",
|
||||
"result": "pass",
|
||||
"evidence": "exit 0; 'every checked shell library has a test suite'. An unrelated entry script must never block an unrelated commit."
|
||||
},
|
||||
{
|
||||
"command": "bash meta/scripts/check_shell_coverage.sh linux_configuration/scripts/lib/_ratchet_canary_tmp.sh (temporary canary, removed after the run)",
|
||||
"result": "pass",
|
||||
"evidence": "exit 1; named the offending file and the exact path it needs: linux_configuration/scripts/lib/tests/run_all.sh. Confirms a new untested library cannot enter."
|
||||
},
|
||||
{
|
||||
"command": "bash meta/scripts/check_shell_coverage.sh <3 covered files in one invocation>",
|
||||
"result": "pass",
|
||||
"evidence": "exit 0. pre-commit passes many filenames per invocation, so the multi-file path is the one that actually runs in production."
|
||||
},
|
||||
{
|
||||
"command": "bash meta/scripts/check_shell_coverage.sh <4 files, canary 3rd> >/dev/null 2>&1; echo $?",
|
||||
"result": "pass",
|
||||
"evidence": "exit 1. A loop that only inspected $1, or one whose exit code was overwritten by a later passing file, would have returned 0 here."
|
||||
},
|
||||
{
|
||||
"command": "git status --short",
|
||||
"result": "pass",
|
||||
"evidence": "Clean after both canary runs -- the temporary library was removed, so no canary leaked into the tree or the allowlist."
|
||||
}
|
||||
],
|
||||
"risks": [
|
||||
"The gate stays inert until a human pastes the YAML. Until then a new untested shell library can still land, exactly as before this commit -- the ratchet is documented, not active.",
|
||||
"The highest-consequence paste error is silent: pass_filenames: false yields a permanently green dead gate. This is called out in the handoff, but nothing mechanically prevents it, and no test the next session would naturally run would reveal it.",
|
||||
"The 115-entry allowlist is unchanged, so the pre-existing uncovered libraries stay exempt; this commit narrows nothing.",
|
||||
"check_shell_coverage.sh --seed remains capable of rewriting the allowlist. It is shrink-only and exits 1 rather than adding an entry, so the documented failure mode is guarded."
|
||||
],
|
||||
"rollback": [
|
||||
"git revert this commit -- it touches only NEXT_SESSION_PROMPT.md and this evidence file, so nothing executable changes.",
|
||||
"If the hook was already pasted and misbehaves, delete the shell-coverage-ratchet block from .pre-commit-config.yaml; the gate is self-contained and no other hook depends on it.",
|
||||
"After rollback, confirm the ratchet script itself still behaves: bash meta/scripts/check_shell_coverage.sh --all should list 115 exempt entries and exit 0."
|
||||
]
|
||||
}
|
||||
@ -1,119 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# lib/tests/mtk_harness.sh — shared fixture for linux_configuration/scripts/lib.
|
||||
#
|
||||
# Sourced, not executed.
|
||||
#
|
||||
# WHAT IS EXERCISED
|
||||
# The pure decision logic and everything reachable through the
|
||||
# MTK_ROOT_FIXTURE seam that mtk_common.sh documents as its only boundary
|
||||
# with real hardware: classify_device, discover_partitions,
|
||||
# mtk_ramdisk_carrier, mtk_check_layout_expectation, mtk_assert_mediatek,
|
||||
# mtk_sanitize, mtk_sane_ramdisk_size, mtk_select_device/require_authorized
|
||||
# under a fixture, plus the string 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).
|
||||
# - mtk_udev_catchall_files — globs /etc/udev/rules.d with no seam, so it
|
||||
# reads this host's real rules; the result differs between here and CI.
|
||||
# - mtk_sha256 / mtk_file_size — one-line wrappers over sha256sum/stat.
|
||||
# This matches Phase 1's measured pattern: decision logic reaches ~90%, the
|
||||
# effecting code reaches 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 ]]
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Runs every linux_configuration/scripts/lib test.
|
||||
#
|
||||
# The glob is test_*.sh, NOT one prefix per subject: this directory holds
|
||||
# suites for several libraries (mtk_*, common_datetime, ...), and a prefix
|
||||
# glob silently skips every suite added after it — including in the CI
|
||||
# discovery step in shell-tests.yml, which runs this file.
|
||||
#
|
||||
# This file's existence is what meta/scripts/check_shell_coverage.sh checks:
|
||||
# is_covered() tests for tests/run_all.sh and nothing more, so an empty one
|
||||
# here would mark all nine libraries in the parent directory covered while
|
||||
# testing nothing. The suites it runs, and the gaps they leave, are named in
|
||||
# mtk_harness.sh's header.
|
||||
set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
rc=0
|
||||
for t in "$HERE"/test_*.sh; do
|
||||
printf '\n=== %s ===\n' "$(basename "$t")"
|
||||
# Each suite exits non-zero on failure; keep going so one red suite does not
|
||||
# hide the state of the others, then fail the run as a whole.
|
||||
# Invoked directly, NOT as `bash "$t"`: under kcov the latter instruments
|
||||
# bash itself and reports zero lines for every lib. A fresh process per
|
||||
# suite also matters here, because mtk_common.sh declares readonly
|
||||
# patterns and sourcing it twice in one shell aborts under set -e.
|
||||
"$t" || rc=1
|
||||
done
|
||||
|
||||
exit "$rc"
|
||||
@ -1,160 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Covers the pure helpers in common_datetime.sh: validate_resolution,
|
||||
# generate_output_filename, has_cmd, ask_yes_no, mount_layers_count, the
|
||||
# zero-fork time readers, and the two predicates built on them.
|
||||
#
|
||||
# NO ASSERTION HERE DEPENDS ON THE WALL CLOCK. This suite runs in
|
||||
# shell-tests.yml and again on every pre-push via ci-mirror, so
|
||||
# `is_hour_in_range 9 17` would pass during the working day and fail at
|
||||
# night — a flake that blocks a push for reasons unrelated to the change.
|
||||
# The predicates are tested by shimming get_hour/get_day_of_week to fixed
|
||||
# values; the real readers are asserted on SHAPE only.
|
||||
set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=mtk_harness.sh
|
||||
source "$HERE/mtk_harness.sh"
|
||||
|
||||
_t_sandbox
|
||||
# shellcheck source=../common_datetime.sh
|
||||
source "$HERE/../common_datetime.sh"
|
||||
|
||||
# --- validate_resolution ---------------------------------------------------
|
||||
|
||||
_t_rc 0 "a WIDTHxHEIGHT resolution is valid" validate_resolution "1920x1080"
|
||||
_t_rc 0 "a single-digit resolution is valid" validate_resolution "1x1"
|
||||
_t_rc 1 "a capital X is not the separator" validate_resolution "1920X1080"
|
||||
_t_rc 1 "a missing dimension is invalid" validate_resolution "1920x"
|
||||
_t_rc 1 "a bare number is not a resolution" validate_resolution "1920"
|
||||
_t_rc 1 "trailing text is rejected" validate_resolution "1920x1080p"
|
||||
_t_rc 1 "an empty string is not a resolution" validate_resolution ""
|
||||
# Anchoring matters: an unanchored regex would accept this and the caller
|
||||
# would go on to pass it to a scaler.
|
||||
_t_rc 1 "an embedded match is rejected, not extracted" validate_resolution "a1920x1080b"
|
||||
|
||||
# --- generate_output_filename ----------------------------------------------
|
||||
|
||||
_t_is "./photo_resized.jpg" "$(generate_output_filename "photo.jpg" "_resized")" \
|
||||
"suffix goes before the extension, not after"
|
||||
_t_is "/tmp/photo_small.png" "$(generate_output_filename "/tmp/photo.png" "_small")" \
|
||||
"the directory is preserved"
|
||||
# A file with no extension: the caller's fallback is used, defaulting to jpg.
|
||||
_t_is "./photo_x.jpg" "$(generate_output_filename "photo" "_x")" \
|
||||
"an extensionless input defaults to jpg"
|
||||
_t_is "./photo_x.png" "$(generate_output_filename "photo" "_x" "png")" \
|
||||
"an explicit fallback extension is honoured"
|
||||
# Only the LAST dot separates the extension.
|
||||
_t_is "./archive.tar_x.gz" "$(generate_output_filename "archive.tar.gz" "_x")" \
|
||||
"only the final extension is split off"
|
||||
_t_is "/a/b/c_out.jpg" "$(generate_output_filename "/a/b/c.jpg" "_out")" \
|
||||
"a nested path is preserved"
|
||||
|
||||
# --- has_cmd ---------------------------------------------------------------
|
||||
|
||||
_t_rc 0 "has_cmd finds a command that exists" has_cmd bash
|
||||
_t_rc 1 "has_cmd rejects a command that does not" has_cmd definitely-not-a-real-binary-xyz
|
||||
|
||||
# --- ask_yes_no ------------------------------------------------------------
|
||||
|
||||
# Reads stdin, so it is drivable without a tty.
|
||||
_t_yn() {
|
||||
printf '%s\n' "$1" | ask_yes_no "prompt?" >/dev/null 2>&1
|
||||
}
|
||||
_t_rc 0 "'y' is yes" _t_yn "y"
|
||||
_t_rc 0 "'Y' is yes" _t_yn "Y"
|
||||
_t_rc 0 "'yes' is yes" _t_yn "yes"
|
||||
_t_rc 1 "'n' is no" _t_yn "n"
|
||||
# Default-no is the safety property: an empty answer must never mean yes.
|
||||
_t_rc 1 "an empty answer defaults to no" _t_yn ""
|
||||
_t_rc 1 "unrecognised input is no, not a reprompt" _t_yn "maybe"
|
||||
|
||||
# --- mount_layers_count ----------------------------------------------------
|
||||
|
||||
# A path with no bind mount over it has zero layers. `/` always appears in
|
||||
# mountinfo, so it is the one value that is stable on any host.
|
||||
_t_is "0" "$(mount_layers_count "/definitely/not/a/mount/point")" \
|
||||
"an unmounted path counts zero layers"
|
||||
_t_rc 0 "a mounted path counts without failing" mount_layers_count "/"
|
||||
root_layers="$(mount_layers_count "/")"
|
||||
_t_rc 0 "the root mount count is numeric" grep -qE '^[0-9]+$' <<<"$root_layers"
|
||||
|
||||
# --- time readers: shape, never value --------------------------------------
|
||||
|
||||
_t_rc 0 "get_timestamp returns digits" grep -qE '^[0-9]+$' <<<"$(get_timestamp)"
|
||||
_t_rc 0 "get_date is YYYY-MM-DD" grep -qE '^[0-9]{4}-[0-9]{2}-[0-9]{2}$' <<<"$(get_date)"
|
||||
_t_rc 0 "get_time is HH:MM:SS" grep -qE '^[0-9]{2}:[0-9]{2}:[0-9]{2}$' <<<"$(get_time)"
|
||||
_t_rc 0 "get_datetime joins both" \
|
||||
grep -qE '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' <<<"$(get_datetime)"
|
||||
_t_rc 0 "get_day_of_week is 1-7" grep -qE '^[1-7]$' <<<"$(get_day_of_week)"
|
||||
_t_rc 0 "get_day_name is alphabetic" grep -qE '^[A-Za-z]+$' <<<"$(get_day_name)"
|
||||
_t_rc 0 "get_hour is 00-23" grep -qE '^([01][0-9]|2[0-3])$' <<<"$(get_hour)"
|
||||
_t_rc 0 "get_minute is 00-59" grep -qE '^[0-5][0-9]$' <<<"$(get_minute)"
|
||||
_t_rc 0 "get_second is 00-60" grep -qE '^([0-5][0-9]|60)$' <<<"$(get_second)"
|
||||
_t_rc 0 "get_uptime_seconds is a whole number" grep -qE '^[0-9]+$' <<<"$(get_uptime_seconds)"
|
||||
_t_rc 0 "get_boot_datetime is a datetime" \
|
||||
grep -qE '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$' <<<"$(get_boot_datetime)"
|
||||
_t_rc 0 "get_boot_date is a date" grep -qE '^[0-9]{4}-[0-9]{2}-[0-9]{2}$' <<<"$(get_boot_date)"
|
||||
_t_rc 0 "get_boot_hour is 00-23" grep -qE '^([01][0-9]|2[0-3])$' <<<"$(get_boot_hour)"
|
||||
|
||||
# Boot time is in the past, and by the same margin /proc/uptime reports. This
|
||||
# is a relation between two readings, so it holds at any wall-clock time.
|
||||
now_ts="$(get_timestamp)"
|
||||
up_s="$(get_uptime_seconds)"
|
||||
_t_rc 0 "boot precedes now by the uptime" test "$((now_ts - up_s))" -le "$now_ts"
|
||||
|
||||
# --- predicates, with the clock shimmed ------------------------------------
|
||||
|
||||
# is_hour_in_range is half-open: start inclusive, end exclusive. Overriding
|
||||
# get_hour is what makes these assertions true at 3am and at 3pm alike.
|
||||
get_hour() { printf '%s' "$T_FAKE_HOUR"; }
|
||||
|
||||
T_FAKE_HOUR=06
|
||||
_t_rc 0 "06 is inside 5..8" is_hour_in_range 5 8
|
||||
T_FAKE_HOUR=05
|
||||
_t_rc 0 "the start hour is inside the range" is_hour_in_range 5 8
|
||||
T_FAKE_HOUR=08
|
||||
_t_rc 1 "the end hour is outside the range" is_hour_in_range 5 8
|
||||
T_FAKE_HOUR=04
|
||||
_t_rc 1 "an hour before the range is outside" is_hour_in_range 5 8
|
||||
T_FAKE_HOUR=23
|
||||
_t_rc 1 "an hour after the range is outside" is_hour_in_range 5 8
|
||||
# A leading zero must not be read as octal — 08 and 09 are the classic trap,
|
||||
# and the implementation uses 10#$ precisely to avoid it.
|
||||
#
|
||||
# Assert on STDERR, not only on the status. Dropping the 10# prefix makes
|
||||
# bash abort with "value too great for base", which is a non-zero exit that
|
||||
# an exit-status-only check reads as an ordinary "hour is out of range" —
|
||||
# so the mutation survives. Mutation-tested: removing 10#$ fails this.
|
||||
_t_hour_err() {
|
||||
T_FAKE_HOUR="$1"
|
||||
# Capture stderr ONLY: stdout is discarded first, then stderr is pointed at
|
||||
# it. Braces make the order explicit rather than relying on a bare
|
||||
# `2>&1 >/dev/null`, which reads backwards.
|
||||
{ is_hour_in_range "$2" "$3" >/dev/null; } 2>&1 || true
|
||||
}
|
||||
for _t_h in 08 09; do
|
||||
_t_is "" "$(_t_hour_err "$_t_h" 9 17)" "${_t_h} raises no arithmetic error"
|
||||
done
|
||||
T_FAKE_HOUR=09
|
||||
_t_rc 0 "09 is parsed as decimal nine, not invalid octal" is_hour_in_range 9 17
|
||||
T_FAKE_HOUR=08
|
||||
_t_rc 1 "08 is decimal eight, so it is below the 9..17 range" is_hour_in_range 9 17
|
||||
T_FAKE_HOUR=00
|
||||
_t_rc 0 "midnight is parsed as zero" is_hour_in_range 0 1
|
||||
_t_is "" "$(_t_hour_err 00 0 1)" "00 raises no arithmetic error"
|
||||
|
||||
# is_day_of_week takes a list and matches any of them.
|
||||
get_day_of_week() { printf '%s' "$T_FAKE_DOW"; }
|
||||
|
||||
T_FAKE_DOW=1
|
||||
_t_rc 0 "Monday matches a list containing it" is_day_of_week 1 5 6 7
|
||||
T_FAKE_DOW=3
|
||||
_t_rc 1 "Wednesday does not match that list" is_day_of_week 1 5 6 7
|
||||
T_FAKE_DOW=7
|
||||
_t_rc 0 "Sunday matches at the end of the list" is_day_of_week 1 5 6 7
|
||||
T_FAKE_DOW=4
|
||||
_t_rc 0 "a single-element list matches" is_day_of_week 4
|
||||
T_FAKE_DOW=4
|
||||
_t_rc 1 "an empty list matches nothing" is_day_of_week
|
||||
|
||||
_t_done "test_common_datetime.sh"
|
||||
@ -1,120 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Covers classify_device, mtk_assert_mediatek, mtk_explain_classification
|
||||
# and mtk_sanitize, all through the MTK_ROOT_FIXTURE seam.
|
||||
#
|
||||
# The load-bearing assertion here is the THIRD PHONE case. classify_device's
|
||||
# contract is that ULEFONE requires a MediaTek signal AND a vendor/model
|
||||
# match — both, never either — so an unrelated MediaTek handset must land in
|
||||
# UNKNOWN rather than being treated as the Ulefone. Every caller refuses to
|
||||
# act on UNKNOWN, and that is what stops this toolkit flashing a stranger's
|
||||
# phone. A rule rewritten to `||` would still pass the ULEFONE and PIXEL
|
||||
# cases below; only this one catches it.
|
||||
set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=mtk_harness.sh
|
||||
source "$HERE/mtk_harness.sh"
|
||||
|
||||
_t_sandbox
|
||||
# shellcheck source=../mtk_common.sh
|
||||
source "$HERE/../mtk_common.sh"
|
||||
|
||||
# --- classify_device -------------------------------------------------------
|
||||
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture ulefone \
|
||||
'ro.product.manufacturer=Ulefone
|
||||
ro.product.model=Armor 26 Ultra
|
||||
ro.board.platform=mt6989
|
||||
ro.hardware=mt6989
|
||||
ro.product.device=Armor26Ultra' 'boot_a')"
|
||||
export MTK_ROOT_FIXTURE
|
||||
classify_device
|
||||
_t_is "ULEFONE" "$MTK_DEVICE_CLASS" "MediaTek platform + Ulefone vendor -> ULEFONE"
|
||||
_t_in "MediaTek platform" "$MTK_CLASS_REASON" "ULEFONE reason names the platform signal"
|
||||
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture pixel \
|
||||
'ro.product.manufacturer=Google
|
||||
ro.product.model=Pixel 6a
|
||||
ro.board.platform=gs101
|
||||
ro.hardware=oriole
|
||||
ro.product.device=bluejay' 'boot_a')"
|
||||
classify_device
|
||||
_t_is "PIXEL" "$MTK_DEVICE_CLASS" "Google + Pixel identity -> PIXEL"
|
||||
|
||||
# A MediaTek phone that is NOT the Ulefone. The single most important case:
|
||||
# "not a Pixel, so presumably the Ulefone" is exactly the reasoning the
|
||||
# implementation refuses, and it is what would target the wrong hardware.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture third_party \
|
||||
'ro.product.manufacturer=Xiaomi
|
||||
ro.product.model=Redmi Note 12
|
||||
ro.board.platform=mt6833
|
||||
ro.hardware=mt6833
|
||||
ro.product.device=tapas' 'boot_a')"
|
||||
classify_device
|
||||
_t_is "UNKNOWN" "$MTK_DEVICE_CLASS" "MediaTek but wrong vendor -> UNKNOWN, not ULEFONE"
|
||||
|
||||
# Ulefone identity with no MediaTek signal is equally not enough.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture ulefone_no_mtk \
|
||||
'ro.product.manufacturer=Ulefone
|
||||
ro.product.model=Armor 26 Ultra
|
||||
ro.board.platform=sm8650
|
||||
ro.hardware=qcom
|
||||
ro.product.device=Armor26Ultra' 'boot_a')"
|
||||
classify_device
|
||||
_t_is "UNKNOWN" "$MTK_DEVICE_CLASS" "Ulefone identity without MediaTek -> UNKNOWN"
|
||||
|
||||
# An unauthorized device answers every getprop with an empty string. That must
|
||||
# not resolve to a class.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture empty '' 'boot_a')"
|
||||
classify_device
|
||||
_t_is "UNKNOWN" "$MTK_DEVICE_CLASS" "no properties at all -> UNKNOWN"
|
||||
_t_in "no rule matched" "$MTK_CLASS_REASON" "UNKNOWN reason explains which reads were empty"
|
||||
|
||||
# --- mtk_assert_mediatek ---------------------------------------------------
|
||||
|
||||
# A positive assertion, deliberately not "is not a Pixel". It gates the only
|
||||
# script that touches partitions, so both directions are asserted.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture assert_mtk \
|
||||
'ro.board.platform=mt6989
|
||||
ro.hardware=mt6989' 'boot_a')"
|
||||
classify_device
|
||||
_t_rc 0 "mtk_assert_mediatek accepts an mt#### platform" mtk_assert_mediatek
|
||||
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture assert_qcom \
|
||||
'ro.board.platform=sm8650
|
||||
ro.hardware=qcom' 'boot_a')"
|
||||
classify_device
|
||||
_t_rc 1 "mtk_assert_mediatek rejects a non-MediaTek platform" mtk_assert_mediatek
|
||||
|
||||
# hardware alone is enough — some devices report the SoC there and leave
|
||||
# ro.board.platform unset.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture assert_hw_only 'ro.hardware=mt8183' 'boot_a')"
|
||||
classify_device
|
||||
_t_rc 0 "mtk_assert_mediatek accepts a MediaTek ro.hardware alone" mtk_assert_mediatek
|
||||
|
||||
# --- mtk_explain_classification --------------------------------------------
|
||||
|
||||
explain_out="$(mtk_explain_classification 2>&1)"
|
||||
_t_in "Verdict:" "$explain_out" "explain output states a verdict"
|
||||
_t_in "mt8183" "$explain_out" "explain output echoes the property it read"
|
||||
|
||||
# --- mtk_sanitize ----------------------------------------------------------
|
||||
|
||||
# adb shell returns CRLF, which silently breaks string comparisons — the
|
||||
# reason this function exists at all.
|
||||
_t_is "mt6989" "$(mtk_sanitize "$(printf 'mt6989\r')")" "sanitize strips a trailing CR"
|
||||
_t_is "Armor 26 Ultra" "$(mtk_sanitize 'Armor 26 Ultra')" "sanitize keeps spaces and digits"
|
||||
# tr -cd DELETES disallowed bytes rather than truncating at the first one, so
|
||||
# the alphanumerics inside a substitution survive as inert text. What matters
|
||||
# is that $ ( ) ` ; & | cannot come back out.
|
||||
# The metacharacters are assembled from \-escapes rather than written inside
|
||||
# single quotes, so that "these must not expand" is stated in the code rather
|
||||
# than left to the reader (and to shellcheck) to infer.
|
||||
hostile="rm -rf \$(whoami)\`id\`; reboot & echo|x"
|
||||
sanitized="$(mtk_sanitize "$hostile")"
|
||||
_t_is "rm -rf whoamiid reboot echox" "$sanitized" "sanitize deletes shell metacharacters"
|
||||
for meta in '$' '(' ')' '`' ';' '&' '|'; do
|
||||
_t_is "" "${sanitized//[^"$meta"]/}" "sanitize leaves no '${meta}' behind"
|
||||
done
|
||||
|
||||
_t_done "test_mtk_classify.sh"
|
||||
@ -1,152 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Covers mtk_list_devices, mtk_device_state, mtk_select_device and
|
||||
# mtk_require_authorized.
|
||||
#
|
||||
# The load-bearing case is REFUSING TO GUESS. With two phones attached and no
|
||||
# --serial, mtk_select_device must fail rather than pick one: a wrong choice
|
||||
# here points a partition-flashing toolkit at the wrong device. A version
|
||||
# that took serials[0] would pass every other assertion in this file.
|
||||
#
|
||||
# adb is shimmed onto PATH rather than mocked in-process, because
|
||||
# mtk_list_devices calls the binary directly. _t_adb_says writes the shim's
|
||||
# canned `adb devices` output; nothing here talks to real hardware, and the
|
||||
# shim refuses any subcommand the tests do not expect.
|
||||
set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=mtk_harness.sh
|
||||
source "$HERE/mtk_harness.sh"
|
||||
|
||||
_t_sandbox
|
||||
# shellcheck source=../mtk_common.sh
|
||||
source "$HERE/../mtk_common.sh"
|
||||
|
||||
# --- adb shim --------------------------------------------------------------
|
||||
|
||||
# Narrow PATH to a shim dir. Every external these functions reach for must be
|
||||
# seeded here: a missing one aborts the suite under `set -e` with no stderr.
|
||||
_t_shim_dir="$T_TMP/bin"
|
||||
mkdir -p "$_t_shim_dir"
|
||||
cat >"$_t_shim_dir/adb" <<'SHIM'
|
||||
#!/usr/bin/env bash
|
||||
# Test double. Prints the canned `adb devices` table and nothing else; any
|
||||
# other subcommand is a bug in the test, so say so loudly rather than
|
||||
# returning an empty string that would read as "no devices".
|
||||
if [[ ${1:-} == "devices" ]]; then
|
||||
cat "${T_ADB_DEVICES:?}"
|
||||
exit 0
|
||||
fi
|
||||
printf 'adb shim: unexpected invocation: %s\n' "$*" >&2
|
||||
exit 97
|
||||
SHIM
|
||||
chmod +x "$_t_shim_dir/adb"
|
||||
for _t_ext in awk mapfile cat printf; do
|
||||
_t_bin="$(command -v "$_t_ext" 2>/dev/null || true)"
|
||||
[[ -n $_t_bin ]] && ln -sf "$_t_bin" "$_t_shim_dir/$_t_ext"
|
||||
done
|
||||
PATH="$_t_shim_dir:/usr/bin:/bin"
|
||||
export PATH
|
||||
|
||||
T_ADB_DEVICES="$T_TMP/adb_devices.txt"
|
||||
export T_ADB_DEVICES
|
||||
|
||||
_t_adb_says() {
|
||||
printf 'List of devices attached\n%s\n' "$1" >"$T_ADB_DEVICES"
|
||||
}
|
||||
|
||||
# --- mtk_list_devices ------------------------------------------------------
|
||||
|
||||
_t_adb_says 'ABC123 device'
|
||||
_t_is "ABC123 device" "$(mtk_list_devices)" "one attached device is listed with its state"
|
||||
|
||||
_t_adb_says 'ABC123 device
|
||||
DEF456 unauthorized'
|
||||
_t_is "2" "$(mtk_list_devices | wc -l)" "both attached devices are listed"
|
||||
|
||||
# A blank table is what an empty `adb devices` looks like.
|
||||
_t_adb_says ''
|
||||
_t_is "" "$(mtk_list_devices)" "no attached devices lists nothing"
|
||||
|
||||
# --- mtk_device_state ------------------------------------------------------
|
||||
|
||||
_t_adb_says 'ABC123 device
|
||||
DEF456 unauthorized
|
||||
GHI789 offline'
|
||||
_t_is "device" "$(mtk_device_state ABC123)" "an authorized device reports 'device'"
|
||||
_t_is "unauthorized" "$(mtk_device_state DEF456)" "an unauthorized device reports so"
|
||||
_t_is "offline" "$(mtk_device_state GHI789)" "an offline device reports so"
|
||||
_t_is "absent" "$(mtk_device_state NOPE000)" "an unattached serial reports 'absent'"
|
||||
|
||||
# --- mtk_select_device -----------------------------------------------------
|
||||
|
||||
_t_adb_says 'ABC123 device'
|
||||
unset MTK_SERIAL
|
||||
_t_rc 0 "a single attached device is selected" mtk_select_device
|
||||
unset MTK_SERIAL
|
||||
mtk_select_device
|
||||
_t_is "ABC123" "$MTK_SERIAL" "the selected serial is the attached one"
|
||||
|
||||
# Two devices, no request: must refuse.
|
||||
_t_adb_says 'ABC123 device
|
||||
DEF456 device'
|
||||
unset MTK_SERIAL
|
||||
_t_rc 1 "two devices with no --serial refuses to guess" mtk_select_device
|
||||
unset MTK_SERIAL
|
||||
refuse_out="$(mtk_select_device 2>&1 || true)"
|
||||
_t_in "refusing to guess" "$refuse_out" "the refusal says why"
|
||||
_t_in "--serial" "$refuse_out" "the refusal names the way out"
|
||||
|
||||
# Two devices WITH a request: the named one is honoured.
|
||||
unset MTK_SERIAL
|
||||
mtk_select_device DEF456
|
||||
_t_is "DEF456" "$MTK_SERIAL" "an explicit serial disambiguates"
|
||||
|
||||
# A requested serial that is not attached must fail, not fall back.
|
||||
unset MTK_SERIAL
|
||||
_t_rc 1 "a requested serial that is absent fails" mtk_select_device ZZZ999
|
||||
unset MTK_SERIAL
|
||||
_t_in "is not attached" "$(mtk_select_device ZZZ999 2>&1 || true)" \
|
||||
"the absent-serial error names the problem"
|
||||
|
||||
# No devices at all.
|
||||
_t_adb_says ''
|
||||
unset MTK_SERIAL
|
||||
_t_rc 1 "no attached devices fails" mtk_select_device
|
||||
unset MTK_SERIAL
|
||||
_t_in "No device visible" "$(mtk_select_device 2>&1 || true)" "the no-device error is actionable"
|
||||
|
||||
# --- mtk_require_authorized ------------------------------------------------
|
||||
|
||||
_t_adb_says 'ABC123 device
|
||||
DEF456 unauthorized
|
||||
GHI789 offline'
|
||||
|
||||
MTK_SERIAL=ABC123
|
||||
_t_rc 0 "an authorized device passes the gate" mtk_require_authorized
|
||||
|
||||
# The case this function exists for: an unauthorized device answers every
|
||||
# getprop with an empty string, which reads exactly like "no properties".
|
||||
MTK_SERIAL=DEF456
|
||||
_t_rc 1 "an unauthorized device is caught up front" mtk_require_authorized
|
||||
_t_in "UNAUTHORIZED" "$(mtk_require_authorized 2>&1 || true)" \
|
||||
"the unauthorized error blames the prompt, not the device"
|
||||
|
||||
MTK_SERIAL=GHI789
|
||||
_t_rc 1 "an offline device is caught" mtk_require_authorized
|
||||
_t_in "OFFLINE" "$(mtk_require_authorized 2>&1 || true)" "the offline error is actionable"
|
||||
|
||||
MTK_SERIAL=NOPE000
|
||||
_t_rc 1 "an absent device is caught" mtk_require_authorized
|
||||
|
||||
# Under a fixture both selection and authorization are bypassed entirely,
|
||||
# which is what keeps the rest of this directory's suites offline.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture selectable '' 'boot')"
|
||||
export MTK_ROOT_FIXTURE
|
||||
unset MTK_SERIAL
|
||||
_t_rc 0 "a fixture selects without adb" mtk_select_device
|
||||
unset MTK_SERIAL
|
||||
mtk_select_device
|
||||
_t_is "fixture" "$MTK_SERIAL" "the fixture serial is a placeholder"
|
||||
_t_rc 0 "a fixture is always authorized" mtk_require_authorized
|
||||
|
||||
_t_done "test_mtk_device.sh"
|
||||
@ -1,142 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Covers discover_partitions, mtk_ramdisk_carrier,
|
||||
# mtk_check_layout_expectation, mtk_sane_ramdisk_size and mtk_check_venv.
|
||||
#
|
||||
# The load-bearing case is INIT_BOOT WINS OVER BOOT. A device launched on
|
||||
# Android 13+ carries the ramdisk in init_boot even though boot also exists,
|
||||
# so a loop that checked boot first would pick the wrong partition on exactly
|
||||
# the hardware this toolkit targets — and would do it silently, because both
|
||||
# names are present and both reads succeed.
|
||||
#
|
||||
# The second is that discover_partitions consults the FILESYSTEM, never the
|
||||
# API level. mtk_check_layout_expectation may disagree and warn, but it must
|
||||
# not change the answer.
|
||||
set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=mtk_harness.sh
|
||||
source "$HERE/mtk_harness.sh"
|
||||
|
||||
_t_sandbox
|
||||
# shellcheck source=../mtk_common.sh
|
||||
source "$HERE/../mtk_common.sh"
|
||||
|
||||
# --- discover_partitions ---------------------------------------------------
|
||||
|
||||
# A/B device with init_boot: the ramdisk lives in init_boot, not boot.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture ab_initboot 'ro.boot.slot_suffix=_a' \
|
||||
'boot_a
|
||||
boot_b
|
||||
init_boot_a
|
||||
init_boot_b
|
||||
vbmeta_a
|
||||
vbmeta_b
|
||||
userdata')"
|
||||
export MTK_ROOT_FIXTURE
|
||||
_t_rc 0 "discover_partitions succeeds when a ramdisk carrier exists" discover_partitions
|
||||
discover_partitions
|
||||
_t_is "A/B" "$MTK_AB_SCHEME" "an _a suffix in the listing means A/B"
|
||||
_t_is "_a" "$MTK_SLOT_SUFFIX" "slot suffix comes from ro.boot.slot_suffix"
|
||||
_t_is "init_boot_a" "$MTK_RAMDISK_PART" "init_boot wins over boot when both exist"
|
||||
_t_is "vbmeta_a" "$MTK_VBMETA_PART" "vbmeta picks up the active slot suffix"
|
||||
_t_is "init_boot" "$(mtk_ramdisk_carrier)" "carrier strips the slot suffix"
|
||||
_t_is "0" "$MTK_SLOT_ASSUMED" "a reported slot suffix is not an assumption"
|
||||
|
||||
# A-only device with no init_boot: must fall through to boot.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture aonly_boot '' \
|
||||
'boot
|
||||
recovery
|
||||
vbmeta
|
||||
userdata')"
|
||||
discover_partitions
|
||||
_t_is "A-only" "$MTK_AB_SCHEME" "no _a suffix means A-only"
|
||||
_t_is "" "$MTK_SLOT_SUFFIX" "A-only has no slot suffix"
|
||||
_t_is "boot" "$MTK_RAMDISK_PART" "falls through to boot when init_boot is absent"
|
||||
_t_is "boot" "$(mtk_ramdisk_carrier)" "carrier of an unsuffixed boot is boot"
|
||||
|
||||
# A/B device whose slot_suffix is unreadable. The code falls back to _a
|
||||
# because a dump has to start somewhere, but must FLAG that it guessed.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture ab_no_suffix '' \
|
||||
'boot_a
|
||||
boot_b
|
||||
vbmeta_a
|
||||
vbmeta_b')"
|
||||
discover_partitions
|
||||
_t_is "_a" "$MTK_SLOT_SUFFIX" "A/B with no reported suffix falls back to _a"
|
||||
_t_is "1" "$MTK_SLOT_ASSUMED" "the _a fallback is recorded as an assumption"
|
||||
_t_is "boot_a" "$MTK_RAMDISK_PART" "assumed suffix still resolves a carrier"
|
||||
|
||||
# An empty listing is what an unauthorized or absent device produces. It must
|
||||
# fail rather than reporting a plausible-looking empty layout.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture no_partitions '' '')"
|
||||
_t_rc 1 "discover_partitions fails on an empty by-name listing" discover_partitions
|
||||
discover_partitions || true
|
||||
_t_is "unknown" "$MTK_AB_SCHEME" "an empty listing yields an unknown scheme"
|
||||
_t_is "" "$MTK_RAMDISK_PART" "an empty listing names no ramdisk partition"
|
||||
|
||||
# A listing with neither boot nor init_boot: non-empty, but no carrier.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture no_carrier '' \
|
||||
'system
|
||||
vendor
|
||||
userdata')"
|
||||
_t_rc 1 "discover_partitions fails when no carrier is present" discover_partitions
|
||||
|
||||
# --- mtk_check_layout_expectation ------------------------------------------
|
||||
|
||||
# first_api_level >= 33 predicts init_boot. Agreement is quiet.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture api34_initboot \
|
||||
'ro.boot.slot_suffix=_a
|
||||
ro.product.first_api_level=34' \
|
||||
'boot_a
|
||||
init_boot_a')"
|
||||
discover_partitions
|
||||
_t_rc 0 "api 34 + init_boot carrier agrees" mtk_check_layout_expectation
|
||||
|
||||
# Disagreement warns and returns 1 — but the device still wins.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture api34_boot_only \
|
||||
'ro.boot.slot_suffix=_a
|
||||
ro.product.first_api_level=34' \
|
||||
'boot_a
|
||||
vbmeta_a')"
|
||||
discover_partitions
|
||||
_t_rc 1 "api 34 + boot carrier disagrees and says so" mtk_check_layout_expectation
|
||||
_t_is "boot_a" "$MTK_RAMDISK_PART" "a disagreeing expectation does NOT change the answer"
|
||||
warn_out="$(mtk_check_layout_expectation 2>&1 || true)"
|
||||
_t_in "Trusting the device" "$warn_out" "the warning states the filesystem wins"
|
||||
|
||||
# Below 33 predicts boot.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture api30_boot 'ro.product.first_api_level=30' 'boot')"
|
||||
discover_partitions
|
||||
_t_rc 0 "api 30 + boot carrier agrees" mtk_check_layout_expectation
|
||||
|
||||
# An unreadable or non-numeric api level is not an error — it is simply no
|
||||
# cross-check. This must not be mistaken for a disagreement.
|
||||
MTK_ROOT_FIXTURE="$(_t_fixture api_missing '' 'boot')"
|
||||
discover_partitions
|
||||
_t_rc 0 "an absent api level skips the cross-check" mtk_check_layout_expectation
|
||||
|
||||
# --- mtk_sane_ramdisk_size -------------------------------------------------
|
||||
|
||||
# Both an empty read and a whole-disk grab look like success to mtkclient's
|
||||
# exit code, which is the entire reason this band exists.
|
||||
_t_rc 1 "zero bytes is implausible" mtk_sane_ramdisk_size 0
|
||||
_t_in "implausibly small" "$(mtk_sane_ramdisk_size 0 || true)" "small failure says which way"
|
||||
_t_rc 1 "a truncated read is implausible" mtk_sane_ramdisk_size 1024
|
||||
_t_rc 0 "8 MiB is a plausible ramdisk" mtk_sane_ramdisk_size $((8 * 1024 * 1024))
|
||||
_t_rc 0 "the lower bound itself is accepted" mtk_sane_ramdisk_size $((1024 * 1024))
|
||||
_t_rc 0 "the upper bound itself is accepted" mtk_sane_ramdisk_size $((128 * 1024 * 1024))
|
||||
_t_rc 1 "a whole-disk grab is implausible" mtk_sane_ramdisk_size $((4 * 1024 * 1024 * 1024))
|
||||
_t_in "implausibly large" "$(mtk_sane_ramdisk_size $((4 * 1024 * 1024 * 1024)) || true)" \
|
||||
"large failure says which way"
|
||||
# `stat` failing yields an empty string, not a number.
|
||||
_t_rc 1 "a non-numeric size is rejected" mtk_sane_ramdisk_size "not-a-number"
|
||||
_t_rc 1 "an empty size is rejected" mtk_sane_ramdisk_size ""
|
||||
|
||||
# --- mtk_check_venv --------------------------------------------------------
|
||||
|
||||
# MTK_ROOT_CACHE points at an empty tmpdir, so this takes the deterministic
|
||||
# "missing" branch on any host, CI included.
|
||||
_t_rc 1 "an absent venv is reported as missing" mtk_check_venv
|
||||
_t_in "missing:" "$(mtk_check_venv || true)" "the missing branch names the interpreter path"
|
||||
|
||||
_t_done "test_mtk_partitions.sh"
|
||||
@ -15,14 +15,8 @@
|
||||
# whose bodies are the untestable part, so capping them would buy nothing.
|
||||
#
|
||||
# The ratchet: files listed in the allowlist predate the gate and are exempt.
|
||||
# Any library NOT on it must be covered, so a new library cannot enter without
|
||||
# a suite. The list only ever shrinks, and --seed enforces that.
|
||||
#
|
||||
# Exemption is static, NOT "until the file is next modified": editing an
|
||||
# allowlisted library is allowed and does not demand tests. Making a mere edit
|
||||
# trip the gate would block routine work across most of the repo's shell
|
||||
# surface, which is the repo-wide gate this ratchet exists to avoid. An entry
|
||||
# leaves the list when someone gives its directory a suite.
|
||||
# A file that is NEW or MODIFIED must be covered, and a covered file can never
|
||||
# go back on the allowlist. The list only ever shrinks.
|
||||
#
|
||||
# check_shell_coverage.sh <file>... # gate the named files (hook mode)
|
||||
# check_shell_coverage.sh --all # report every uncovered lib
|
||||
@ -54,18 +48,11 @@ usage() {
|
||||
# True for a shell library: a .sh under a lib/ dir, excluding the tests
|
||||
# themselves and vendored trees. Payloads are data emitted onto other
|
||||
# machines, not logic this repo's suites can source.
|
||||
#
|
||||
# Both nestings of "library" and "tests" are test code and are out of scope:
|
||||
# lib/tests/ (a suite beside its libs) and tests/lib/ (helpers beside their
|
||||
# tests). Missing the second made the gate demand tests/lib/tests/run_all.sh,
|
||||
# which is incoherent — and it would have fired precisely while editing test
|
||||
# helpers to add the suites this ratchet asks for.
|
||||
is_shell_lib() {
|
||||
local path="$1"
|
||||
[[ "$path" == *.sh ]] || return 1
|
||||
[[ "$path" == */lib/* ]] || return 1
|
||||
[[ "$path" == */lib/tests/* ]] && return 1
|
||||
[[ "$path" == */tests/lib/* ]] && return 1
|
||||
[[ "$path" == */lib/payloads/* ]] && return 1
|
||||
[[ "$path" == third_party/* ]] && return 1
|
||||
return 0
|
||||
@ -95,37 +82,12 @@ seed_allowlist() {
|
||||
local -a libs=()
|
||||
mapfile -t libs < <(collect_libs)
|
||||
|
||||
# Shrink-only, enforced rather than merely documented: a reseed may drop
|
||||
# entries that gained a suite, never add one. Without this, running --seed
|
||||
# after writing an untested library would silently exempt it and quietly
|
||||
# widen the hole the gate exists to close.
|
||||
if [[ -f "$ALLOWLIST" ]]; then
|
||||
local -a added=()
|
||||
mapfile -t added < <(comm -13 \
|
||||
<(exempt_paths | sort) \
|
||||
<(report_uncovered "${libs[@]}" | sort))
|
||||
|
||||
if ((${#added[@]} > 0)); then
|
||||
echo "$SCRIPT_NAME: refusing to seed — that would ADD ${#added[@]} entr(ies):" >&2
|
||||
local entry
|
||||
for entry in "${added[@]}"; do
|
||||
printf ' %s\n' "$entry" >&2
|
||||
done
|
||||
echo >&2
|
||||
echo " The allowlist only ever shrinks. Give these libraries a" >&2
|
||||
echo " tests/run_all.sh instead of exempting them." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
{
|
||||
echo "# Shell libraries that predate the coverage ratchet."
|
||||
echo "#"
|
||||
echo "# Each line is a file exempt from check_shell_coverage.sh. The exemption"
|
||||
echo "# is static: editing one of these files is fine and does not require"
|
||||
echo "# tests. An entry goes away when its lib/ directory gains a"
|
||||
echo "# tests/run_all.sh, at which point every file in that directory is"
|
||||
echo "# enforced."
|
||||
echo "# Each line is a file exempt from check_shell_coverage.sh until it is"
|
||||
echo "# next modified. Modifying an exempt file requires giving its lib/"
|
||||
echo "# directory a tests/run_all.sh suite and deleting the line."
|
||||
echo "#"
|
||||
echo "# This list only ever shrinks. Never add a path to it by hand -- a new"
|
||||
echo "# library must ship with its tests."
|
||||
@ -175,9 +137,9 @@ check_files() {
|
||||
printf ' needs: %s/tests/run_all.sh\n' "$(dirname "$path")" >&2
|
||||
done
|
||||
echo >&2
|
||||
echo " A shell library must ship with a suite that sources it. Extend" >&2
|
||||
echo " the nearest existing tests/ directory rather than cloning a" >&2
|
||||
echo " harness -- jscpd fails above 2% duplication." >&2
|
||||
echo " A new or modified shell library must ship with a suite that" >&2
|
||||
echo " sources it. Extend the nearest existing tests/ directory rather" >&2
|
||||
echo " than cloning a harness -- jscpd fails above 2% duplication." >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
# Shell libraries that predate the coverage ratchet.
|
||||
#
|
||||
# Each line is a file exempt from check_shell_coverage.sh. The exemption
|
||||
# is static: editing one of these files is fine and does not require
|
||||
# tests. An entry goes away when its lib/ directory gains a
|
||||
# tests/run_all.sh, at which point every file in that directory is
|
||||
# enforced.
|
||||
# Each line is a file exempt from check_shell_coverage.sh until it is
|
||||
# next modified. Modifying an exempt file requires giving its lib/
|
||||
# directory a tests/run_all.sh suite and deleting the line.
|
||||
#
|
||||
# This list only ever shrinks. Never add a path to it by hand -- a new
|
||||
# library must ship with its tests.
|
||||
@ -12,6 +10,16 @@
|
||||
# Regenerate (only ever to REMOVE now-covered entries):
|
||||
# bash meta/scripts/check_shell_coverage.sh --seed
|
||||
linux_configuration/.githooks/lib/common.sh
|
||||
linux_configuration/scripts/boot_recovery/tests/lib/boot_repair_cases.sh
|
||||
linux_configuration/scripts/lib/android.sh
|
||||
linux_configuration/scripts/lib/common_datetime.sh
|
||||
linux_configuration/scripts/lib/common_packages.sh
|
||||
linux_configuration/scripts/lib/common_services.sh
|
||||
linux_configuration/scripts/lib/common.sh
|
||||
linux_configuration/scripts/lib/mtk_classify.sh
|
||||
linux_configuration/scripts/lib/mtk_common.sh
|
||||
linux_configuration/scripts/lib/mtk_device.sh
|
||||
linux_configuration/scripts/lib/mtk_partitions.sh
|
||||
linux_configuration/scripts/meta/lib/shell_check_discover.sh
|
||||
linux_configuration/scripts/meta/lib/shell_check_install.sh
|
||||
linux_configuration/scripts/meta/lib/shell_check_lint.sh
|
||||
@ -19,6 +27,8 @@ linux_configuration/scripts/mtk_root/lib/dump_partitions.sh
|
||||
linux_configuration/scripts/mtk_root/lib/dump_verify.sh
|
||||
linux_configuration/scripts/mtk_root/lib/mtk_udev.sh
|
||||
linux_configuration/scripts/mtk_root/lib/recon_report.sh
|
||||
linux_configuration/scripts/mtk_root/tests/lib/assertions.sh
|
||||
linux_configuration/scripts/mtk_root/tests/lib/dump_tests.sh
|
||||
linux_configuration/scripts/periodic_background/digital_wellbeing/pacman/lib/install_files.sh
|
||||
linux_configuration/scripts/periodic_background/digital_wellbeing/pacman/lib/integrity.sh
|
||||
linux_configuration/scripts/periodic_background/digital_wellbeing/pacman/lib/managed_copy.sh
|
||||
@ -103,6 +113,13 @@ linux_configuration/scripts/single_use/misc/testsAndMisc-bash/lib/transcribe_dep
|
||||
linux_configuration/scripts/single_use/misc/testsAndMisc-bash/lib/transcribe_pkgmgr.sh
|
||||
linux_configuration/scripts/single_use/misc/testsAndMisc-bash/lib/transcribe_venv.sh
|
||||
linux_configuration/scripts/single_use/misc/testsAndMisc-bash/lib/unity_handler.sh
|
||||
linux_configuration/tests/lib/i3blocks_claude_usage.sh
|
||||
linux_configuration/tests/lib/i3blocks_config_checks.sh
|
||||
linux_configuration/tests/lib/pacman_wrapper_makepkg.sh
|
||||
linux_configuration/tests/lib/pacman_wrapper_syntax.sh
|
||||
linux_configuration/tests/lib/security_apps.sh
|
||||
linux_configuration/tests/lib/security_hosts_shutdown.sh
|
||||
linux_configuration/tests/lib/security_pacman.sh
|
||||
meta/lib/lint_full_tools.sh
|
||||
meta/lib/lint_output.sh
|
||||
meta/scripts/lib/disk_cleanup_common.sh
|
||||
|
||||
Loading…
Reference in New Issue
Block a user