Skip to content

fix(lint): actually shellcheck the root workspace's shell (#853) - #856

Merged
bpalermo merged 2 commits into
mainfrom
fix/853-shellcheck-root-workspace
Sep 20, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/853-shellcheck-root-workspace

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Closes #853.

The defect

.bazelrc has run the shellcheck aspect on every --config=lint build since it was added, and it has never read a line of this repository's own shell.

The issue diagnosed it as "the root workspace declared no sh_* target". That is one step off, and the real shape is worth recording because it is what made this invisible for so long. The repo has always had an sh_binary — //:gazelle, from the gazelle macro — so bazel query 'kind("sh_(binary|library|test)", //...)' was never empty. But filter_srcs (lint/private/lint_aspect.bzl) keeps only srcs that are source files in the main repo:

return [s for s in rule.files.srcs if s.is_source and s.owner.workspace_name == ""]

//:gazelle's only src is the generated //:gazelle-runner, which that discards. So the aspect was handed zero files. make lint was green because it had no input — indistinguishable from green because the shell is clean.

What changed

Five sh_library targets, one per shell-bearing package: //scripts, //bazel, //e2e, //e2e/pressure, //e2e/soak, each glob(["*.sh"]). No symlink bridge — unlike #848 these files are not behind .bazelignore, so the targets sit in their own packages directly.

Per-directory rather than one target, for two reasons. A glob cannot cross a package boundary, so a single glob(["**/*.sh"]) under //e2e would stop dead at //e2e/udsecho's BUILD.bazel and cover less than it appeared to — the same class of silent under-coverage this PR exists to end. And a per-directory target keeps the lint failure label pointing at the directory the script lives in. //scripts:check_proxy_shell_lint (#848, one file) becomes //scripts:scripts_shell (all seven); only //scripts:all was ever referenced, so nothing depended on the old name.

The three findings, fixed. Two SC2155 and one SC2034, no suppressions.

The SC2034 was a real gap, not noise

e2e/multicluster_replicator.sh:41 sets TUNNEL_PORT="18009" and never reads it.

That suite is a fork of the 019 waypoint harness (e2e/multicluster_waypoint.sh), and the fork took TUNNEL_PORT and dump_mesh_dns with it but not dump_echo_eds — the only place the waypoint harness ever uses the constant. The variable is the fossil of a diagnostic that was never ported.

That matters because the replicator suite's step 2 asserts a data path over mirror AND waypoint (it does set agent.eastWestWaypoint=true), and its failure branch dumped mesh-DNS state and died. Once DNS is cleared there are still two distinct causes behind the same curl 000:

  • a never turned the mirrored keys into an endpoint — step 1 already proved the keys are in etcd-a, so this is a replication-side failure;
  • a has the endpoint at a pod IP instead of b-node-ip:18009 — the east/west waypoint rewrite did not happen, a 019 failure and nothing to do with this suite.

The EDS host separates them in one line. So: ported dump_echo_eds, wired it into the step-2 failure path, and made the die message say how to read it. The harness's own step-3 dump (dump_failover_state) already reads /clusters for the opposite purpose, so the access shape and the one-shot-on-failure discipline are unchanged.

Deleting the variable would also have made the gate green. It would have thrown away the evidence that a diagnostic was missing.

Proof the gate fails

The whole point is that a vacuous gate looks exactly like a passing one, so both new gates were run red on purpose.

1. The lint gate. Appended an unquoted expansion to bazel/workspace_status.sh — the stamping script every bazel build runs, and until this PR one of the never-linted ones:

$ bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //...

ERROR: .../bazel/BUILD.bazel:22:11: Linting //bazel:bazel_shell with ShellCheck failed:
(Exit 1): bash failed: error executing AspectRulesLintShellCheck command
(from aspects [//bazel/lint:linters.bzl%shellcheck] on sh_library rule target //bazel:bazel_shell)

In bazel/workspace_status.sh line 20:
echo SHORT_SHA $ref
               ^--^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
echo SHORT_SHA "$ref"

ERROR: Build did NOT complete successfully

Reverted. The same command on the branch as it stands: INFO: Found 398 targets... Build completed successfully.

The gate also caught its own guard on the first run — scripts/check-shell-lint.sh line 4 began # shellcheck aspect (#853)., which shellcheck parses as a malformed directive (SC1072/SC1073). Reworded; the file is in //scripts:scripts_shell and lints itself.

And before the three fixes, the gate reported exactly the three findings the issue listed and nothing else — the other 13 scripts were already clean.

2. The completeness guard. Added e2e/newthing/setup.sh with no target:

$ scripts/check-shell-lint.sh
uncovered: e2e/newthing/setup.sh is in no sh_* target, so the shellcheck aspect never sees it
           fix: add it to the sh_library in e2e/newthing/BUILD.bazel,
                or create that package's sh_library if it has none

srcs are per-package globs and a glob cannot cross a package boundary, so a
script in a directory with no sh_* target is silently unlinted (#853).
$ echo $?
1

Reverted. Clean: OK: all 17 root-workspace shell script(s) are covered by an sh_* target.

The completeness guard

scripts/check-shell-lint.sh (make check-shell-lint) is the root-workspace sibling of #848's check-proxy-shell-lint.sh, which caught a real gap within minutes of existing. The srcs are globs, so a script added to a covered directory needs no edit — but a script added to a directory with no sh_* target is silently outside the gate, and nothing about a green make lint would say so.

It diffs git ls-files --cached --others --exclude-standard against

kind("source file", labels(srcs, kind("sh_(binary|library|test)", //...)))

Asking Bazel rather than re-deriving the globs means it fails when the targets stop covering a file, not when a second copy of the glob list goes stale. The kind("source file", ...) wrapper reproduces filter_srcs exactly — it is the difference between "a target lists it" and "shellcheck reads it", which is the distinction this whole issue turned on. Without it the set would include //:gazelle-runner.

Like its sibling it deliberately does not run shellcheck; that is the second step of the job below.

CI placement

ci, not proxy — the mirror image of #848's reasoning.

#854 put the proxy gate in proxy.yml because ci's changes filter excludes proxy/**/!(*.md), so a proxy-only PR skips the whole ci workflow. The root-workspace gate has the opposite exposure: control_plane is '**' minus the proxy tree and the two proxy workflow files, so scripts/, e2e/ and bazel/ are all inside it, and a PR touching nothing but a root shell script sets control_plane == 'true' and skips proxy entirely. A gate that skips in the case it exists for is the same bug again, so it goes where the change actually lands.

Its own job, not steps inside test, for three reasons:

  • test runs --config=ci, which pulls in --config=remote and needs the BuildBuddy key. This has no compile to offload — it is --config=lint plus fail_on_violation, no RBE, no key, seconds.
  • test is needs: [changes, diff] and skips when bazel-diff finds nothing impacted. The shell gate would inherit a scoping decision it has no reason to trust.
  • scripts/check-shell-lint.sh is not a Bazel target at all and needs a home regardless.

test does still lint any bazel-diff-impacted sh_library as a side effect of --config=ci (kind(rule, //...) includes sh_library). That is a second net, not this one.

The job's target list comes from a query rather than being written into the YAML, so a new package's sh_library is linted the moment the guard starts demanding one; an empty query result fails loudly rather than passing by linting nothing.

Added shell to the ci fan-in gate's needs. proxy.yml's shell job keeps //scripts:all — on a proxy-only PR that is the only thing linting the guard script it runs — with its stale "four source files" note corrected.

Verification

bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //... green, 398 targets
lint gate red on an injected SC2086 above
scripts/check-shell-lint.sh OK: all 17 ... covered
guard red on an uncovered script above
scripts/check-proxy-shell-lint.sh (#848, unchanged) OK: all 4 ... mirrored
make format / make format-check clean, no shfmt symlink failure (no symlinks in these targets)
make gazelle no-op; Gazelle does not touch sh_library
bash -n on all modified scripts parse

Not verified: the ported dump_echo_eds is failure-path-only in a harness that needs two kind clusters plus SPIRE, so it has been shellchecked, shfmt'd and syntax-checked but not executed. Every command in it is || true-guarded and it is a copy of the sibling harness's working function. The new ci shell job's own YAML/runner behaviour is likewise unproven until this PR runs it.

Not touched: the talos-main cluster. charts/ is unchanged, so no Chart.yaml bump.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-Authored-By: Claude Opus 5 [email protected]
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits September 20, 2026 10:54
`--config=lint` has run the shellcheck aspect on every lint build since it
was added, and it has never read a line of this repository's own shell.

`lint_shellcheck_aspect` visits sh_binary/sh_library/sh_test, and then
`filter_srcs` keeps only srcs that are SOURCE files in the main repo. The
one sh_binary this repo has always had, //:gazelle, has exactly one src —
the GENERATED //:gazelle-runner — which filter_srcs discards. So the aspect
received zero files. `make lint` was green because it had no input, which
is indistinguishable from green because the shell is clean.

Declare an sh_library per shell-bearing package (//scripts, //bazel, //e2e,
//e2e/pressure, //e2e/soak), each `glob(["*.sh"])`. Per-directory rather
than one target because a glob cannot cross a package boundary: a single
recursive glob would stop dead at //e2e/udsecho's BUILD.bazel and cover
less than it appeared to. No symlink bridge is needed — unlike #848 these
files are not behind .bazelignore.

That turns the gate on over 16 scripts, 3 of which had findings:

  * e2e/multicluster_config.sh:133   SC2155
  * e2e/multicluster_waypoint.sh:257 SC2155
    `local x="$(cmd)"` is one `local` builtin whose exit status is the
    builtin's, so `set -e` cannot see the substitution fail and the install
    proceeds with "http://:2379" and blames the chart. Split in two.

  * e2e/multicluster_replicator.sh:41 SC2034 — a real gap, not noise.
    That suite is a fork of the 019 waypoint harness and took TUNNEL_PORT
    and dump_mesh_dns with it, but not dump_echo_eds — the only consumer of
    the constant. Its step-2 failure path was therefore diagnosable one bit
    short of the question it asks: with mesh-DNS cleared, "'a' never
    projected the mirrored keys" and "the waypoint rewrite did not happen"
    both look like curl 000, and the EDS host separates them. Ported the
    function rather than deleting the variable.

scripts/check-shell-lint.sh is the completeness guard, the root-workspace
sibling of #848's check-proxy-shell-lint.sh: globs cannot cross package
boundaries, so a script added under a directory with no sh_* target is
silently outside the gate and nothing about a green `make lint` would say
so. It diffs `git ls-files` against
`kind("source file", labels(srcs, kind("sh_(binary|library|test)", //...)))`
— the "source file" filter reproduces filter_srcs, which is the difference
between "a target lists it" and "shellcheck reads it".

The gate goes in `ci`, not `proxy`, for the mirror image of #848's reason:
`ci`'s `changes` filter is '**' minus the proxy tree, so a PR touching
nothing but a root shell script lands there and skips `proxy` entirely.
Its own job, not steps inside `test`: no compile to offload (so
`--config=lint` + fail_on_violation, never `--config=ci` and a BuildBuddy
key), no dependence on bazel-diff's scoping, and the guard is not a Bazel
target at all. Added to the `ci` fan-in gate's needs.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit 9a45a25 into main Sep 20, 2026
23 checks passed
@bpalermo
bpalermo deleted the fix/853-shellcheck-root-workspace branch September 20, 2026 14:26
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.

No shell script in the root workspace is linted: the shellcheck aspect has no sh_* target to visit

1 participant