Skip to content

Add bats unit tests for scripts/ shell helpers#137

Merged
lex57ukr merged 2 commits into
mainfrom
28-add-shell-unit-tests-for-resolver-and-verify-scripts
May 25, 2026
Merged

Add bats unit tests for scripts/ shell helpers#137
lex57ukr merged 2 commits into
mainfrom
28-add-shell-unit-tests-for-resolver-and-verify-scripts

Conversation

@lex57ukr
Copy link
Copy Markdown
Contributor

@lex57ukr lex57ukr commented May 25, 2026

Summary

The shell helpers under scripts/ (both the shared scripts/lib/ library and the top-level release-time helpers) had no automated coverage, leaving regressions detectable only through manual or release-time runs against live APIs and real artifacts. This adds focused, network-free bats unit tests for every testable function and script in that tree, so CI catches breakage in version parsing, hash validation, version-check formatting, lockfile/Dockerfile drift, semver gating, and checksum generation before it lands.

Related Issues

Fixes #28

Changes

  • Bats unit tests under tests/bats/scripts/lib/ for version.sh, resolve.sh, verify.sh, and validate-lockfile.sh covering all branches and key edge cases.
  • Bats unit tests under tests/bats/scripts/ for validate-version.sh (semver regex + pre-release variants) and generate-checksums.sh (output format, exit-code split, dist-dir handling, error paths).
  • lint-sh shellcheck glob now discovers the bats tree via find, so depth changes can't silently skip files.

Total: 46 new bats cases (108 → 154).

Further Comments

  • Network-touching wrappers (latest_gh_tag, latest_npm_version, latest_luarocks_version, fetch_gh_asset, fetch_gh_digests) are intentionally excluded — issue Add shell unit tests for resolver and verify scripts #28 scopes those out as "integration tests, separate if needed."
  • Writing the generate-checksums.sh tests surfaced a latent quirk: the final | sort orders checksums.txt lines by the sha256 prefix rather than by filename. Output is still deterministic but not human-useful. The test asserts set membership rather than order so the buggy ordering isn't frozen as a contract; worth a follow-up issue.

The shared helpers under scripts/lib/ had no automated coverage —
regressions could only be caught by manual integration runs against
live GitHub/npm/luarocks APIs. Add focused, network-free unit tests
for the testable surface:

- version.sh: normalize_version, validate_strict_version
- resolve.sh: validate_sha256, resolve_local, pick_gh_digest
- verify.sh: check, verify_exit
- validate-lockfile.sh: happy path, mismatch reporting, TARGETARCH
  and default-value filtering, input errors

The validate-lockfile tests pin two invariants the production lint
can never re-fire (Dockerfile and lockfile are always in sync), so a
"simplify the sed" change can no longer silently break sync
validation.

Switch the lint-sh shellcheck glob to find so the bats tree is
discovered depth-agnostically; the previous three-glob pattern
silently skipped any new directory depth.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lex57ukr lex57ukr added the enhancement New feature or request label May 25, 2026
@lex57ukr lex57ukr linked an issue May 25, 2026 that may be closed by this pull request
validate-version.sh and generate-checksums.sh are exercised in
release-time integration paths but only ever see the happy input
in CI. Add focused unit tests so the rejection paths and exit-code
contracts are pinned independently of release runs.

- validate-version.sh: happy semver/pre-release forms, rejection
  paths (leading v, two-segment, malformed pre-release), no-arg
  usage error
- generate-checksums.sh: GNU coreutils output format, default vs
  explicit dist dir, basename-only flattening for nested artifacts,
  release-body.md markdown wrapper, exit-code split (2 for arg
  errors vs 1 for runtime errors), missing/empty dir paths

The set-membership check on checksums.txt is intentional — the
script's trailing `| sort` orders lines by sha256 prefix, not by
filename, which is a latent quirk worth surfacing in a follow-up
rather than freezing as test contract.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lex57ukr lex57ukr changed the title Add bats unit tests for scripts/lib helpers Add bats unit tests for scripts/ shell helpers May 25, 2026
@lex57ukr lex57ukr merged commit fcd8c98 into main May 25, 2026
8 checks passed
@lex57ukr lex57ukr deleted the 28-add-shell-unit-tests-for-resolver-and-verify-scripts branch May 25, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add shell unit tests for resolver and verify scripts

1 participant