From 7f4203a64167162d8e37b1e3642853576bcbda95 Mon Sep 17 00:00:00 2001 From: Maxwell Elliott Date: Sat, 7 Mar 2026 19:20:07 -0500 Subject: [PATCH 1/2] Fixes for version command in query service This can lead to errors in some use cases --- MODULE.bazel | 2 +- MODULE.bazel.lock | 2 +- .../com/bazel_diff/bazel/BazelQueryService.kt | 19 +++++--- .../test/kotlin/com/bazel_diff/e2e/E2ETest.kt | 44 +++++++++++++++++++ 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 661ecca..6a228a3 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module( name = "bazel-diff", - version = "17.0.3", + version = "17.1.0", compatibility_level = 0, ) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 359a100..5cab574 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -498,7 +498,7 @@ "//:extensions.bzl%non_module_repositories": { "general": { "bzlTransitiveDigest": "ks6ZQP7BhZgybSu5miBVjOep566JGWK7Lf4pDkWwq4M=", - "usagesDigest": "R+eeQSmnbI2egC1XZAUVLusRFRlA5h9C4dw9POOyEMc=", + "usagesDigest": "MxX6OaeEPcLlUaLHR5ezZpcHxNHxr/2yXWdBNsF5OUE=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, diff --git a/cli/src/main/kotlin/com/bazel_diff/bazel/BazelQueryService.kt b/cli/src/main/kotlin/com/bazel_diff/bazel/BazelQueryService.kt index c74f6be..770a240 100644 --- a/cli/src/main/kotlin/com/bazel_diff/bazel/BazelQueryService.kt +++ b/cli/src/main/kotlin/com/bazel_diff/bazel/BazelQueryService.kt @@ -30,7 +30,7 @@ class BazelQueryService( @OptIn(ExperimentalCoroutinesApi::class) private suspend fun determineBazelVersion(): Triple { - val cmd = arrayOf(bazelPath.toString(), "--version") + val cmd = arrayOf(bazelPath.toString(), "version") logger.i { "Executing Bazel version command: ${cmd.joinToString()}" } val result = process( @@ -45,12 +45,19 @@ class BazelQueryService( throw RuntimeException("Bazel version command failed, exit code ${result.resultCode}") } - if (result.output.size != 1 || !result.output.first().startsWith("bazel ")) { - throw RuntimeException("Bazel version command returned unexpected output: ${result.output}") - } + // "bazel version" outputs "Build label: X.Y.Z" on one of the lines; accept that or legacy "bazel X.Y.Z". + val versionString = + result.output + .firstOrNull { it.startsWith("Build label: ") } + ?.removePrefix("Build label: ")?.trim() + ?: result.output + .firstOrNull { it.startsWith("bazel ") } + ?.removePrefix("bazel ")?.trim() + ?: throw RuntimeException( + "Bazel version command returned unexpected output: ${result.output}") // Trim off any prerelease suffixes (e.g., 8.6.0-rc1 or 8.6.0rc1). - val versionString = result.output.first().removePrefix("bazel ").trim().split('-')[0] - val version = versionString.split('.').map { it.takeWhile { c -> c.isDigit() }.toInt() }.toTypedArray() + val version = + versionString.split('-')[0].split('.').map { it.takeWhile { c -> c.isDigit() }.toInt() }.toTypedArray() return Triple(version[0], version[1], version[2]) } diff --git a/cli/src/test/kotlin/com/bazel_diff/e2e/E2ETest.kt b/cli/src/test/kotlin/com/bazel_diff/e2e/E2ETest.kt index b32fa7c..b480ab3 100644 --- a/cli/src/test/kotlin/com/bazel_diff/e2e/E2ETest.kt +++ b/cli/src/test/kotlin/com/bazel_diff/e2e/E2ETest.kt @@ -136,6 +136,37 @@ class E2ETest { testE2E(emptyList(), emptyList(), "/fixture/impacted_targets-1-2.txt") } + @Test + fun testDetermineBazelVersion() { + // E2E coverage for BazelQueryService.determineBazelVersion(): version is resolved lazily + // when the first query runs. Running generate-hashes to completion validates that + // "bazel version" is executed and parsed successfully (e.g. "Build label: X.Y.Z"). + val projectA = extractFixtureProject("/fixture/integration-test-1.zip") + val workingDirectory = File(projectA, "integration") + val outputDir = temp.newFolder() + val outputPath = File(outputDir, "hashes.json") + + val cli = CommandLine(BazelDiff()) + val exitCode = cli.execute( + "generate-hashes", + "-w", + workingDirectory.absolutePath, + "-b", + "bazel", + outputPath.absolutePath) + + assertThat(exitCode).isEqualTo(0) + assertThat(outputPath.readText().isNotEmpty()).isEqualTo(true) + } + + @Test + fun testE2EWithNoKeepGoing() { + testE2E( + listOf("--no-keep_going"), + emptyList(), + "/fixture/impacted_targets-1-2.txt") + } + @Test fun testE2EIncludingTargetType() { testE2E( @@ -996,6 +1027,19 @@ class E2ETest { // which is designed to fail during analysis assertThat(exitCodeWithCquery).isEqualTo(1) + // Test with --no-keep_going: cquery should fail (no partial results, immediate failure) + val outputNoKeepGoing = File(outputDir, "hashes_no_keep_going.json") + val exitCodeWithNoKeepGoing = cli.execute( + "generate-hashes", + "-w", + workspace.absolutePath, + "-b", + "bazel", + "--useCquery", + "--no-keep_going", + outputNoKeepGoing.absolutePath) + assertThat(exitCodeWithNoKeepGoing).isEqualTo(1) + // Test with --keep_going enabled (default behavior) // With keep_going, cquery returns partial results but still exits with code 1 // The current implementation allows exit codes 0 and 3, but cquery with keep_going From 7bea68ae124e3b861b4caf24720f58d4524681f8 Mon Sep 17 00:00:00 2001 From: Maxwell Elliott Date: Mon, 9 Mar 2026 09:00:49 -0400 Subject: [PATCH 2/2] readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 647245b..7130730 100644 --- a/README.md +++ b/README.md @@ -341,7 +341,7 @@ First, add the following snippet to your project: #### Bzlmod snippet ```bazel -bazel_dep(name = "bazel-diff", version = "15.0.5") +bazel_dep(name = "bazel-diff", version = "17.1.0") ``` You can now run the tool with: