Repository navigation
fix(lint): actually shellcheck the root workspace's shell (#853) - #856
Merged
Merged
Conversation
`--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
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.
Closes #853.
The defect
.bazelrchas run the shellcheck aspect on every--config=lintbuild 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 ansh_binary—//:gazelle, from thegazellemacro — sobazel query 'kind("sh_(binary|library|test)", //...)'was never empty. Butfilter_srcs(lint/private/lint_aspect.bzl) keeps only srcs that are source files in the main repo://:gazelle's only src is the generated//:gazelle-runner, which that discards. So the aspect was handed zero files.make lintwas green because it had no input — indistinguishable from green because the shell is clean.What changed
Five
sh_librarytargets, one per shell-bearing package://scripts,//bazel,//e2e,//e2e/pressure,//e2e/soak, eachglob(["*.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//e2ewould stop dead at//e2e/udsecho'sBUILD.bazeland 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:allwas ever referenced, so nothing depended on the old name.The three findings, fixed. Two
SC2155and oneSC2034, no suppressions.The SC2034 was a real gap, not noise
e2e/multicluster_replicator.sh:41setsTUNNEL_PORT="18009"and never reads it.That suite is a fork of the 019 waypoint harness (
e2e/multicluster_waypoint.sh), and the fork tookTUNNEL_PORTanddump_mesh_dnswith it but notdump_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 samecurl 000:anever turned the mirrored keys into an endpoint — step 1 already proved the keys are inetcd-a, so this is a replication-side failure;ahas the endpoint at a pod IP instead ofb-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 thediemessage say how to read it. The harness's own step-3 dump (dump_failover_state) already reads/clustersfor 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 everybazel buildruns, and until this PR one of the never-linted ones: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.shline 4 began# shellcheck aspect (#853)., which shellcheck parses as a malformed directive (SC1072/SC1073). Reworded; the file is in//scripts:scripts_shelland 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.shwith no target: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'scheck-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 nosh_*target is silently outside the gate, and nothing about a greenmake lintwould say so.It diffs
git ls-files --cached --others --exclude-standardagainstAsking 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 reproducesfilter_srcsexactly — 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, notproxy— the mirror image of #848's reasoning.#854 put the proxy gate in
proxy.ymlbecauseci'schangesfilter excludesproxy/**/!(*.md), so a proxy-only PR skips the wholeciworkflow. The root-workspace gate has the opposite exposure:control_planeis'**'minus the proxy tree and the two proxy workflow files, soscripts/,e2e/andbazel/are all inside it, and a PR touching nothing but a root shell script setscontrol_plane == 'true'and skipsproxyentirely. 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:testruns--config=ci, which pulls in--config=remoteand needs the BuildBuddy key. This has no compile to offload — it is--config=lintplusfail_on_violation, no RBE, no key, seconds.testisneeds: [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.shis not a Bazel target at all and needs a home regardless.testdoes still lint any bazel-diff-impactedsh_libraryas a side effect of--config=ci(kind(rule, //...)includessh_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_libraryis linted the moment the guard starts demanding one; an empty query result fails loudly rather than passing by linting nothing.Added
shellto thecifan-in gate'sneeds.proxy.yml'sshelljob 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 //...SC2086scripts/check-shell-lint.shOK: all 17 ... coveredscripts/check-proxy-shell-lint.sh(#848, unchanged)OK: all 4 ... mirroredmake format/make format-checkmake gazellesh_librarybash -non all modified scriptsNot verified: the ported
dump_echo_edsis 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 newcishelljob's own YAML/runner behaviour is likewise unproven until this PR runs it.Not touched: the talos-main cluster.
charts/is unchanged, so noChart.yamlbump.🤖 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