Skip to content

test(pipeline): shellcheck the composed scripts and test the shared helpers - #5

Merged
mahdidarabi merged 2 commits into
mainfrom
test/script-checks
Dec 1, 2026
Merged

mahdidarabi merged 2 commits into
mainfrom
test/script-checks

Conversation

@mahdidarabi

@mahdidarabi mahdidarabi commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Lints every embedded pipeline script the way the operator runs it and adds behaviour tests for the shared helpers. Closes the shellcheck half of the "Tests" item in TODO.md; envtest stays open.

  • TestShellcheck: Stage scripts are linted as common.sh + the stage body under sh, Stream scripts as stream/common.sh + backup.sh/restore.sh under bash, plus runner/install-rclone.sh. Findings are reported at the source file and line; a helper finding is reported once, and unused-variable/function findings in a helper only when no script uses it.
  • CI sets KARKIVE_REQUIRE_SHELLCHECK=1, so the test fails instead of skipping if the runner loses shellcheck.
  • helpers_test.go: runs the helpers under dash/bash with stub tools (step markers, .step-failed, log file, truthy, zstd level, decompression by suffix, s3_latest by modification time, best-effort s3_prune).
  • make test-scripts runs only the pipeline tests.

The first CI run (shellcheck 0.11.0) reported 28 findings; the second commit clears them. One is a real fix (STAGE='compress' read as a command assignment), one a simplification (the Stage EXIT trap tests $? directly), and the rest are intended and annotated where they occur: HOSTNAME in POSIX sh (set by the container runtime), dump-name globs that must expand, MariaDB backtick identifiers in sed filters, a literal $6 in a Redis RESP frame, and rc assigned inside the Stream EXIT trap.

…elpers

TestShellcheck lints every embedded script as the operator runs it, the helper plus the stage body (sh for Stage, bash for Stream), plus runner/install-rclone.sh, and reports each finding at its source file and line. It skips without shellcheck; CI sets KARKIVE_REQUIRE_SHELLCHECK so a missing binary fails the job instead.

New behaviour tests run the shared helpers under dash and bash with stub tools: step markers and .step-failed, the log file, truthy, the zstd level, decompression by suffix, s3_latest by modification time and the best-effort s3_prune. make test-scripts runs only the pipeline tests.
…ripts

common.sh disables SC3028 for every Stage script: HOSTNAME is not POSIX, but the container runtime sets it to the pod name that scopes each pod's scratch directory. The Stage EXIT trap tests $? directly instead of through an unassigned-looking ec, and STAGE='compress' is quoted so it no longer reads as the compress command.

The rest are intended and annotated where they occur: the dump-name globs in compress.sh and encrypt.sh must expand, the MariaDB sed filters use backticks as identifier quotes, the Redis RESP frame has a literal $6, and the Stream EXIT trap assigns rc inside its string.
@mahdidarabi
mahdidarabi marked this pull request as ready for review December 1, 2026 21:18
@mahdidarabi
mahdidarabi merged commit d1a1f86 into main Dec 1, 2026
3 checks passed
@mahdidarabi
mahdidarabi deleted the test/script-checks branch December 1, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant