test: reproducer for #401 (undeclared workspace reads get stable hashes)#402
Merged
Merged
Conversation
A target that reads files it does not declare as inputs (a non-hermetic / "undeclared workspace read", e.g. a buildifier_test scanning every .bzl in the repo) gets a stable hash from bazel-diff, because hashing is derived purely from the declared graph. Editing an undeclared input therefore leaves the target's hash unchanged and get-impacted-targets skips it, even though the target would behave differently if run. Adds the always_affected_external fixture (an `external`-tagged genrule that reads an undeclared file, plus a hermetic genrule for contrast) and an E2E test pinning the current behaviour: the hermetic target is reported impacted while the external-tagged scanner is not. Co-Authored-By: Claude Opus 4.8 <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.
What
Adds an E2E reproducer for #401 — a feature request for "always-affected" hashing of targets that perform undeclared workspace reads (non-hermetic targets).
cli/src/test/resources/workspaces/always_affected_external/://:scanner— a genrule taggedexternalwhose action readsscanned_data.txtbut does not declare it as asrc(the undeclared / non-hermetic read). Stands in for abuildifier_testthat scans every.bzlin the repo without declaring them.//:hermetic— a normal genrule that declaresdeclared_src.txt, for contrast.testUndeclaredWorkspaceReadIsNotImpacted_reproducerForIssue401inE2ETest.kt.Why
bazel-diff derives a target's hash purely from its declared graph (srcs / deps / attributes). A target that reads files it never declares therefore keeps a stable hash even when one of those files changes, so
get-impacted-targetsskips it — even though the target would behave differently if actually run. This is the gap #401 asks to close.Behaviour pinned
The test edits both the undeclared read (
scanned_data.txt) and the declared src (declared_src.txt) between two checkouts, then asserts the current behaviour://:hermeticis reported as impacted (declared its changed source ✅)//:scanneris not reported as impacted (undeclared read → stable hash ❌)If an
--alwaysAffectedTags-style feature later lands, the scanner should start appearing in the impacted set and the final assertion will flag that the behaviour changed.Notes for reviewers
MODULE.bazel.lock(matches thekeep_going_repo_failurefixture); Bazel regenerates it in the copied temp workspace.🤖 Generated with Claude Code