Skip to content

test: shellcheck every generated script; spawn:* tag round-trip contract (#689) - #1249

Merged
scttfrdmn merged 2 commits into
mainfrom
test/689-shellcheck-tags
Oct 20, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
test/689-shellcheck-tags

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #689

This covers parts A and C of #689. Part B (AL2023 container checks) is not done here: it needs a container runtime in CI and is not cheap. A comment on #689 explains why.

(a) shellcheck CI gate (#689 C)

  • internal/shellcheckgate.Check(t, id, script) runs shellcheck -S warning --shell=bash. It also checks every nested script the generated one writes through a quoted-delimiter heredoc (/tmp/spawn-command.sh in the bootstrap, for example), because shellcheck treats a heredoc body as data. It skips when shellcheck isn't installed locally and fails under CI=true. The exception is Windows, where it skips: the windows-latest job doesn't install shellcheck, and the verdict on a Linux script doesn't depend on the GOOS the test runs on.
  • Every generator is rendered in its own package's tests, with inputs carrying spaces and quotes:
    • pkg/launcher BuildLinuxBootstrap, minimal and with every optional block on
    • pkg/userdata MPI (install, and EFA on a peer), storage (EFS+FSx+EBS), container, queue runner
    • pkg/taskproto GenerateWrapper, GeneratePooledJobScript (host and container) and GenerateFlushScript
    • pkg/sporedinstall installer pair
    • cmd/app.go templates (container DCV, DCV command, desktop, web)
    • the pool worker loop (standalone and inside the bootstrap), upgrade-spored, the terminate flush, SSM key injection, burst, and a composed job-array member (bootstrap + storage + MPI)
    • lambda/pipeline-orchestrator stage user data
    • pkg/slurm's three conversions
  • Discovery: TestEveryShellGeneratorIsShellchecked (root) parses every non-test .go file. Any function or var holding a string literal with a shell shebang at the start of a line is a generator, and some shellcheckgate.Check call must name it. It also fails on a Check id that names no declaration, and on an empty discovery.
  • CI: the Test job installs shellcheck v0.11.0 before Test, pinned by version and sha256. The sha256 matches the GitHub release asset digest, and the install follows the same pattern as staticcheck.

Findings from the baseline pass

  • Fixed (real bug): pkg/slurm cd <WorkingDir> was unquoted and unchecked, and export SLURM_JOB_NAME=<name> was unquoted. Both are now shell-quoted, with cd ... || exit 1. TestGeneratedScripts_QuoteJobNameAndWorkingDir runs the scripts and fails against the old code.
  • Fixed: EFA install cd /tmp and cd aws-efa-installer are now checked explicitly. Failure stays fatal, as it already was under the bootstrap's set -e.
  • Removed: the unused TASK_ID= in the task wrapper. Nothing read it, and it wasn't exported.
  • Scoped disables, each with its reason:
    • SC2050 on MPI's if [ "{{.JobArrayIndex}}" -eq 0 ]: the rank is fixed at render time.
    • SC2041 on the bootstrap's for SPAWN_MP in '<one path>': a list of quoted mount points.
    • SC2024 on the wrapper's sudo docker inspect ... > "$PROV_DIR/...": the wrapper user owns $PROV_DIR.

(b) Tag round-trip contract (#689 A)

Gates watched failing against compiling reverts

  • Discovery: I replaced Check(t, "pkg/slurm.generateMPIScript", ...) with _ = generateMPIScript(job) and renamed another id. Result: "not shellchecked" for both generators, plus "not a declaration" for the renamed id.
  • shellcheck: reverting the slurm quoting, or removing the SC2041 disable, makes the respective Check fail. Missing shellcheck under CI=true (clean PATH, through the hermetic wrapper) fails; without CI it skips.
  • Tag contract: renaming spawn:dcv-session-id in buildTags fails both directions. Renaming the completion-delay reader in pkg/provider fails both directions.
  • Round trip: mis-keying the spawn:sweep-size case in listInstancesInRegion fails with "SweepSize is not filled by any tag". Also copying spawn:job-array-id into Tags (the drainJobArray has never terminated anything: it filters on a tag that InstanceInfo.Tags never contains #683 shape) fails with "in both InstanceInfo.JobArrayID and Tags".

Checks

make check passes except check-build-tags, which also fails on unmodified main because of /private/tmp paths. golangci-lint (root, --allow-parallel-runners) reports 0 issues; semgrep is clean. No help text or exported API changed.

Limits

  • The static contract treats "read anywhere in the repo" as read. It does not prove that the right consumer reads each key.
  • The out-of-repo consumers (lagotto, spore-host-mcp) aren't scanned.

Follow-ups filed

@scttfrdmn scttfrdmn added this to the v0.138.0 milestone Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.18182% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/shellcheckgate/shellcheckgate.go 65.00% 26 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

…ract (#689)

shellcheck gate (#689 C): internal/shellcheckgate runs shellcheck -S
warning on each rendered generator (and the scripts it writes through
quoted heredocs). Generators are discovered from source by their shell
shebang; one no test checks fails the build. Skips locally without
shellcheck, fails under CI=true; the Test job installs v0.11.0 pinned by
version and sha256. Baseline findings fixed: slurm conversions quote the
job name and working dir and stop on a failed cd; EFA cds are checked; the
unused TASK_ID in the wrapper is gone. Intentional patterns get scoped,
reasoned disables.

Tag contract (#689 A): every spawn:* key buildTags writes must be read
somewhere and every key read must be written somewhere, both discovered
structurally across the repo, with a named allowlist for keys written
outside spawn's code. A Substrate round trip checks each launch tag lands
in exactly one place on InstanceInfo and every tag-sourced field is filled.
@scttfrdmn
scttfrdmn force-pushed the test/689-shellcheck-tags branch from 67e84c1 to 59a3cce Compare October 20, 2026 20:11
@scttfrdmn
scttfrdmn merged commit aef75d6 into main Oct 20, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the test/689-shellcheck-tags branch October 20, 2026 20:40
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.

Testing: substrate tag round-trip contract, AL2023 container checks, shellcheck on rendered user-data

1 participant