Skip to content

feat(bazel): SOCKET_BAZEL_FORCE_QUERY_FALLBACK env-var gate for deterministic fallback-parser coverage#1317

Merged
Simon (simonhj) merged 2 commits into
v1.xfrom
simon/bazel-force-query-fallback-env
May 19, 2026
Merged

feat(bazel): SOCKET_BAZEL_FORCE_QUERY_FALLBACK env-var gate for deterministic fallback-parser coverage#1317
Simon (simonhj) merged 2 commits into
v1.xfrom
simon/bazel-force-query-fallback-env

Conversation

@simonhj
Copy link
Copy Markdown

@simonhj Simon (simonhj) commented May 19, 2026

Summary

Add a SOCKET_BAZEL_FORCE_QUERY_FALLBACK env variable that, when truthy (1 / true / yes, case-insensitive), makes socket manifest bazel skip the unsorted_deps.json fast path and parse extraction output through the bazel query --output=build regex fallback instead.

Why

The Bazel extractor has two parser paths inside extractFromOneRepo:

  1. Fast pathJSON.parse over <externalDir>/<repo>/unsorted_deps.json (~50 lines)
  2. Fallback path — six regex patterns over the cached bazel query --output=build stdout, in bazel-build-parser.mts

Today the choice is decided purely by existsSync(unsorted_deps.json). Whichever path Bazel happens to materialize on disk runs. The fast path is also the path that runs in 90%+ of real corpus repos, because rules_jvm_external materializes unsorted_deps.json by default.

What changed

  • New isForceQueryFallbackEnabled() helper in extract_bazel_to_maven.mts — reads process.env['SOCKET_BAZEL_FORCE_QUERY_FALLBACK'], normalizes case, treats 1 / true / yes as on.
  • extractFromOneRepo now early-returns from the unsorted_deps.json candidates loop when the gate fires, falling through to parseBazelBuildOutput(cachedProbeStdout).
  • A logger.verbose line is emitted when the gate fires (only when queryOpts.verbose is set).
  • Eight new test cases in extract_bazel_to_maven.test.mts covering:
    • Env unset → fast path used (existing behavior preserved)
    • 1 / true / YES (case-insensitive) → fallback used
    • '' / 0 / false → fast path used (falsy)
    • Two parsers pitted against each other (each produces a coordinate the other doesn't) to assert which one ran by inspecting the manifest output.

Note

Low Risk
Default behavior is unchanged unless SOCKET_BAZEL_FORCE_QUERY_FALLBACK is set; the main risk is altering artifact extraction results when the env var is enabled and bypasses unsorted_deps.json.

Overview
Adds SOCKET_BAZEL_FORCE_QUERY_FALLBACK (truthy: 1/true/yes) to make extractFromOneRepo skip the unsorted_deps.json fast path and always fall through to parsing cached probe stdout via the regex fallback, with a verbose diagnostic when enabled.

Extends unit tests to assert fast-path vs fallback selection across truthy/falsy env values by seeding both sources with distinct coordinates and verifying which lands in the generated maven_install.json.

Reviewed by Cursor Bugbot for commit a8d0322. Configure here.

When truthy (1/true/yes, case-insensitive), skip the unsorted_deps.json
fast path and parse via the bazel-query regex fallback. Internal
diagnostic toggle; not a user-facing CLI flag.
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Tests read manifest from non-existent _whole_repo subdirectory
    • Removed the incorrect '_whole_repo' path segment from all four readFileSync calls in the SOCKET_BAZEL_FORCE_QUERY_FALLBACK tests so they read from the correct output location (path.join(tmp, 'maven_install.json')).

Create PR

Or push these changes by commenting:

@cursor push f15aaf1792
Preview (f15aaf1792)
diff --git a/src/commands/manifest/bazel/extract_bazel_to_maven.test.mts b/src/commands/manifest/bazel/extract_bazel_to_maven.test.mts
--- a/src/commands/manifest/bazel/extract_bazel_to_maven.test.mts
+++ b/src/commands/manifest/bazel/extract_bazel_to_maven.test.mts
@@ -517,7 +517,7 @@
 
     expect(result.ok).toBe(true)
     const manifest = JSON.parse(
-      readFileSync(path.join(tmp, '_whole_repo', 'maven_install.json'), 'utf8'),
+      readFileSync(path.join(tmp, 'maven_install.json'), 'utf8'),
     )
     // The JSON parser ran: from-json coord is present, from-regex is absent.
     expect(manifest.artifacts['com.example:from-json']).toBeDefined()
@@ -539,7 +539,7 @@
 
     expect(result.ok).toBe(true)
     const manifest = JSON.parse(
-      readFileSync(path.join(tmp, '_whole_repo', 'maven_install.json'), 'utf8'),
+      readFileSync(path.join(tmp, 'maven_install.json'), 'utf8'),
     )
     // The regex parser ran: from-regex coord is present, from-json is absent.
     expect(manifest.artifacts['com.example:from-regex']).toBeDefined()
@@ -573,7 +573,7 @@
       expect(result.ok).toBe(true)
       const manifest = JSON.parse(
         readFileSync(
-          path.join(tmp, '_whole_repo', 'maven_install.json'),
+          path.join(tmp, 'maven_install.json'),
           'utf8',
         ),
       )
@@ -600,7 +600,7 @@
       expect(result.ok).toBe(true)
       const manifest = JSON.parse(
         readFileSync(
-          path.join(tmp, '_whole_repo', 'maven_install.json'),
+          path.join(tmp, 'maven_install.json'),
           'utf8',
         ),
       )

You can send follow-ups to the cloud agent here.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a8d0322. Configure here.

Comment thread src/commands/manifest/bazel/extract_bazel_to_maven.test.mts Outdated
The new SOCKET_BAZEL_FORCE_QUERY_FALLBACK test cases read the generated
manifest at <out>/_whole_repo/maven_install.json, which is correct on
the local Phase 02 branch but wrong on v1.x — the _whole_repo/ wrapper
was removed in the Phase 01.1 cleanup batch and standalone output now
writes directly to <out>/maven_install.json. Drop the _whole_repo
segment from the four read sites in the new describe block. The two
pre-existing assertions that _whole_repo must NOT exist are preserved.

Committed with --no-verify per documented project precedent: pnpm test
(run by husky) is known-failing on output-analytics, cdxgen, and
optimize tests unrelated to this work; lint and tsc are green.
@simonhj Simon (simonhj) merged commit bb561fa into v1.x May 19, 2026
12 checks passed
@simonhj Simon (simonhj) deleted the simon/bazel-force-query-fallback-env branch May 19, 2026 11:29
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.

2 participants