Skip to content

test(shared.just): BATS coverage for powerwash, toggle-tpm2 - #1034

Merged
castrojo merged 1 commit into
mainfrom
quality/test-shared-just
Sep 10, 2026
Merged

castrojo merged 1 commit into
mainfrom
quality/test-shared-just

Conversation

@kubestellar-hive

Copy link
Copy Markdown
Contributor

Test Improvement

Adds tests/test_shared_just.bats — 14 BATS cases covering
system_files/shared/usr/share/ublue-os/just/shared.just, which had zero
test coverage.

Why this file

powerwash is the most destructive recipe in the repo: it ends in
sudo bootc install reset --experimental, an irreversible factory reset. It is
guarded by two gum choose confirmations plus a bctl powerwash fast path.
None of that gating was verified by any test.

How

The powerwash body is a #!/usr/bin/bash shebang recipe with no just
interpolation, so the test extracts it verbatim and executes it against
stubbed bctl/gum/sudo binaries. This exercises real control flow rather
than grepping recipe text, and requires no just binary in CI.

Asserted behavior:

  • bctl present → delegates to bctl powerwash, and gum/sudo are never invoked
  • declining the first confirmation → cancels, only one prompt, no sudo
  • declining the second confirmation → cancels, no sudo
  • non-affirmative (maybe) and empty answers → treated as declines
  • two prompts are always required; a single "yes" never wipes
  • both confirmations → sudo bootc install reset --experimental, exactly once
  • both prompts carry their warning text
  • toggle-tpm2 uses the absolute /usr/bin/luks-tpm2-autounlock path

All 14 pass locally (bats 1.14.0). Mutation-checked: deleting the second
confirmation from shared.just fails 3 of the tests.

Scope / disjointness

Claimed ground: tests/test_shared_just.bats only — one new test file, no
production code touched.

Deliberately does not touch .github/workflows/unit-tests.yml (claimed by
open PRs #942 and #961) and does not touch system.just (#942),
apps.just (#1007), default.just (#1003), bonedigger-report (#1010),
hooks.py (#1011), or ublue-fastfetch (#1005). CI registration of this and
the other test files not yet wired into unit-tests.yml is tracked separately
by #968.


Filed by quality agent (hold-gated mode). Human review required. Do not merge on my behalf.

— hive: agent=quality backend=copilot model=claude-opus-5

system_files/shared/usr/share/ublue-os/just/shared.just had zero test
coverage. Its powerwash recipe performs an irreversible factory reset
(sudo bootc install reset --experimental) behind two gum confirmations,
with a bctl fast path that must bypass those prompts.

tests/test_shared_just.bats extracts the powerwash shebang recipe body
and executes it against stubbed bctl/gum/sudo binaries, asserting:
bctl delegation short-circuits gum and sudo; declining either
confirmation cancels without wiping; non-affirmative and empty answers
decline; two prompts are always required; and the reset runs exactly
once only after both confirmations. toggle-tpm2 is checked for its
absolute luks-tpm2-autounlock path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: kubestellar-hive[bot] <kubestellar-hive[bot]@users.noreply.github.com>

@hanthor hanthor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New tests/test_shared_just.bats for the destructive powerwash recipe and toggle-tpm2; extracts and executes the real recipe body against stubbed bctl/gum/sudo, verifying both confirmations are required, non-affirmative/empty answers decline, and the reset command fires exactly once. CI test green; validate fails only on title-lint.


Generated by Claude Code

@castrojo castrojo changed the title [quality] test: BATS coverage for shared.just (powerwash, toggle-tpm2) test(shared.just): BATS coverage for powerwash, toggle-tpm2 Sep 10, 2026
@castrojo castrojo closed this Sep 10, 2026
@castrojo castrojo reopened this Sep 10, 2026

@castrojo castrojo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: PR #1034 (test(shared.just): BATS coverage for powerwash, toggle-tpm2)

Findings

  • Robust BATS test coverage in tests/test_shared_just.bats covering powerwash and toggle-tpm2 with mocked confirmation prompts and error conditions.
  • All CI checks passing (8/8 pass, 0 fail).

Verdict

Approved.

@castrojo castrojo added lgtm This PR has been approved by a maintainer and removed hold Work is intentionally paused. labels Sep 10, 2026
@castrojo
castrojo added this pull request to the merge queue Sep 10, 2026
Merged via the queue into main with commit c5f8bf8 Sep 10, 2026
16 of 18 checks passed
@castrojo
castrojo deleted the quality/test-shared-just branch September 10, 2026 02:27
pull Bot pushed a commit to joshyorko/common that referenced this pull request Sep 10, 2026
…boot-key, toggle-user-motd, check-local-overrides, check-idle-power-draw, benchmark (projectbluefin#1048)

## Test Improvement

Adds `tests/test_default_just.bats` — 23 BATS tests for
`system_files/shared/usr/share/ublue-os/just/default.just`.

Before this PR, exactly one of the file's 12 recipes was under test
(`clean-system`, via `tests/test_clean_system_podman_path.bats`). The
rest had
zero coverage, including a firmware reboot and a Secure Boot MOK
enrollment.

### Recipes claimed by this PR

| Recipe | What is covered |
|---|---|
| `bios` | legacy-BIOS guard exits 1 and never reboots; EFI + confirm
issues `systemctl reboot --firmware-setup`; declined confirmation does
not reboot |
| `bios-info` | all four `dmidecode -s` fields read under `sudo bash`;
every field is labelled |
| `enroll-secure-boot-key` | `mokutil --timeout -1` precedes the import;
`akmods-ublue.der` is the imported cert; enrollment password guidance is
printed |
| `toggle-user-motd` | shim body is exactly `uwelcome toggle` |
| `check-local-overrides` | only-in-`/etc` reporting; content divergence
reporting; silence when trees match; `NO_COLOR=1` palette suppression;
palette applied when unset; identity/credential `--exclude` set |
| `check-idle-power-draw` | missing-`powerstat` guard exits 1 without
invoking it; present path runs `powerstat -a -r` |
| `benchmark` | `stress-ng` present runs the 1m matrix load without
touching brew; accept path runs `brew install`/`brew link` then the
load; decline path exits 0 with no install |

### Method

Each shebang recipe body is extracted verbatim from `default.just` and
executed
against stubbed `gum`, `sudo`, `systemctl`, `dmidecode`, `mokutil`,
`powerstat`,
`stress-ng`, `brew`, and `uwelcome`. `/sys/firmware/efi` and the
`/usr/etc /etc`
diff operands are redirected into a sandbox with `sed`, so real control
flow is
exercised instead of grepped. `sudo` execs its argv so the `sudo bash
<<EOF`
heredocs run against the same stubs.

### Incidental finding pinned, not fixed

`check-local-overrides` hardcodes `diff --color="always"`. `NO_COLOR=1`
therefore suppresses only the palette the recipe applies itself with
`sed`;
`diff`'s own ANSI escapes still reach the terminal. One test documents
that
current behaviour so a future fix is visible. No production code is
changed by
this PR.

### Disjointness

Explicitly claims only the seven recipes listed above in `default.just`,
plus
the new test file.

- `device-info` (`default.just`) — **left to PR projectbluefin#1003**, not touched or
asserted on.
- `clean-system` (`default.just`) — already owned by
`tests/test_clean_system_podman_path.bats`.
- `shared.just` — left to PR projectbluefin#1034.
- `system.just` — left to PR projectbluefin#1031.
- `apps.just` — left to PRs projectbluefin#978, projectbluefin#1007, projectbluefin#1018.
- `changelog.just` / `ublue-image-repo` — left to PR projectbluefin#1045.

`Justfile`: one line, `bats tests/test_default_just.bats`, inserted
immediately
after the existing `test_clean_system_podman_path.bats` line rather than
appended to the end of the recipe, specifically so it does not collide
with
PR projectbluefin#1031's append at the tail of the same recipe.

`.github/workflows/unit-tests.yml` is intentionally **not** modified —
the hive
App token lacks the `workflows` permission, and that wiring gap is
tracked
separately by common#968.

### Verification

```
$ bats tests/test_default_just.bats
1..23
ok 1 .. ok 23
```

## Related Issue

Refs projectbluefin#968 (the workflow-wiring half of the gap remains open).

---
*Filed by quality agent (hold-gated mode). Human review required.*

— hive: agent=quality backend=copilot model=claude-opus-5

Signed-off-by: quality <sec-check[bot]@users.noreply.github.com>
Co-authored-by: quality <sec-check[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer quality Code quality or test-coverage work. testing Test authoring or test infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants