Reproducer test for #335 ModuleGraphParser stderr-pollution#340
Closed
tinder-maxwellelliott wants to merge 1 commit into
Closed
Reproducer test for #335 ModuleGraphParser stderr-pollution#340tinder-maxwellelliott wants to merge 1 commit into
tinder-maxwellelliott wants to merge 1 commit into
Conversation
bazel-diff 18.0.x captured stderr alongside stdout when fetching the bzlmod
graph (BazelModService used Redirect.CAPTURE for both streams, which
internally calls redirectErrorStream(true)). That meant getModuleGraphJson()
could return a payload shaped like:
"INFO: Checking for file changes...\n{...real JSON...}\n"
18.1.0 fixed the redirect (#330), but CI workflows that reuse a base graph
file produced by an older deployment now feed this stderr-prefixed string
back into parseModuleGraph(). The current parser calls
JsonParser.parseString() on the whole input and silently returns
emptyMap() when parsing fails. Downstream, findChangedModules(emptyMap,
fullMap) treats every module in the new graph as "added" and
CalculateImpactedTargetsInteractor.queryTargetsDependingOnModules() spawns
a serial `bazel query rdeps(//..., @@<repo>//...)` subprocess per match --
thousands of them on a real workspace, taking hours.
This adds a @ignore'd reproducer test that asserts parseModuleGraph
tolerates a leading stderr line. Drop the @ignore once the parser strips
non-JSON noise / locates the first '{' to parse from.
Refs #335
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
tinder-maxwellelliott
added a commit
that referenced
this pull request
May 13, 2026
…endingOnModules Issue #335 lists multiple potential fixes; my first PR (#340) covered fix #1 (parser robustness). This PR adds a reproducer for fix #3: the loose substring match in CalculateImpactedTargetsInteractor.queryTargetsDependingOnModules. The current code is: val moduleRepos = allTargets.keys .filter { it.startsWith("@@") && it.contains(moduleName) } .map { it.substring(2).substringBefore("//") } .toSet() `it.contains(moduleName)` is a very loose match. A single changed module like `aspect_bazel_lib` matches every canonical repo whose name starts with that string -- e.g. `@@aspect_bazel_lib+`, `@@aspect_bazel_lib++toolchains+bats_toolchains`, etc. Each match becomes its own serial `bazel query rdeps(//..., @@<repo>//...)` subprocess. On the workspace in #335 that fan-out produced ~5,000 subprocesses and took multiple hours. New test class CalculateImpactedTargetsInteractorIssue335Test: - Wires its own koin module with a mock BazelQueryService that captures every query expression. - Simulates a workspace with one module (aspect_bazel_lib) plus two module-extension repos whose canonical names begin with the same apparent name. - Asserts that resolving the changed module yields exactly ONE rdeps query, scoped to the actual changed repo. @ignore'd until the match is tightened (match canonical repo key exactly, or look up via `bazel mod dump_repo_mapping`). cli/BUILD wires up the new kt_jvm_test target. Refs #335 Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Summary
@Ignored reproducer test for #335 onModuleGraphParser.parseModuleGraph.INFO: Checking for file changes...\n{json}payload (the exact shape an 18.0.x base graph could produce because of the oldRedirect.CAPTURE+redirectErrorStream(true)combo inBazelModService) and asserts that the parser still extracts both modules.JsonParser.parseString()on the whole input, fails, and returnsemptyMap(). Downstream,findChangedModules(emptyMap, fullMap)treats every module in the new graph as "added" andCalculateImpactedTargetsInteractor.queryTargetsDependingOnModules()spawns a serialbazel query rdeps(//..., @@<repo>//...)subprocess per match — thousands of them on a real workspace, taking hours.parseModuleGraphtolerant of leading non-JSON noise (strip stderr prefixes or locate the first{to parse from). Once that lands, remove@Ignorefrom the test.This is a test-only change. The reproducer is marked
@org.junit.Ignoreso CI stays green; the annotation also documents the issue it tracks.Test plan
bazel build //cli:cli-test-libsucceeds.bazel test //cli:ModuleGraphParserTestpasses (the new test is@Ignored and skipped; existing tests still pass).@Ignoreand re-runbazel test //cli:ModuleGraphParserTest— the reproducer should pass.🤖 Generated with Claude Code