Add bats unit tests for scripts/ shell helpers#137
Merged
lex57ukr merged 2 commits intoMay 25, 2026
Conversation
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The shell helpers under
scripts/(both the sharedscripts/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
tests/bats/scripts/lib/forversion.sh,resolve.sh,verify.sh, andvalidate-lockfile.shcovering all branches and key edge cases.tests/bats/scripts/forvalidate-version.sh(semver regex + pre-release variants) andgenerate-checksums.sh(output format, exit-code split, dist-dir handling, error paths).lint-shshellcheck glob now discovers the bats tree viafind, so depth changes can't silently skip files.Total: 46 new bats cases (108 → 154).
Further Comments
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."generate-checksums.shtests surfaced a latent quirk: the final| sortorderschecksums.txtlines 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.