feat: compute target distances in bazel-diff serve#397
Open
tinder-maxwellelliott wants to merge 1 commit into
Open
feat: compute target distances in bazel-diff serve#397tinder-maxwellelliott wants to merge 1 commit into
bazel-diff serve#397tinder-maxwellelliott wants to merge 1 commit into
Conversation
Add a `/impacted_targets_with_distances` endpoint to the serve query service that returns each impacted target annotated with its build-graph distance metrics (targetDistance and packageDistance), reusing the same distance math as `get-impacted-targets --depEdgesFile`. Dependency-edge tracking is opt-in via a new `serve --trackDeps` flag. When enabled, the per-SHA hash cache persists the dep-edge adjacency list under `metadata.depEdges` and round-trips it on a cache hit. The flag is folded into the cache fingerprint so a deps-tracking server never reuses a deps-less cache entry. Hitting the distances endpoint without `--trackDeps` returns a clear 400. The distance computation in CalculateImpactedTargetsInteractor is extracted into a structured `computeImpactedTargetsWithDistances` reused by both the CLI writer path and the service, keeping CLI JSON output byte-identical. Co-Authored-By: Claude Opus 4.8 (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.
What
Adds build-graph target-distance computation to the
bazel-diff serveHTTP query service (issue #29 follow-up). The distance math already existed for the CLI (get-impacted-targets --depEdgesFile); this wires it into the server.New endpoint
GET /impacted_targets_with_distances?from=<rev>&to=<rev>[&targetType=...]— like/impacted_targets, but each impacted target is annotated withtargetDistance(hops to the nearest directly-changed target) andpackageDistance(how many of those hops cross a package boundary). Directly-changed targets sit at distance0.{ "from": "9a1c0e2…", "to": "3f7b8d4…", "impactedTargets": [ {"label": "//foo:bar", "targetDistance": 0, "packageDistance": 0}, {"label": "//foo:baz", "targetDistance": 1, "packageDistance": 1} ] }Opt-in flag
serve --trackDeps(default off) enables dependency-edge tracking. Tracking deps grows each cached hash entry, so it's opt-in. The flag is folded into the cache fingerprint, so a deps-tracking server never reuses a deps-less cache entry (or vice-versa). The distances endpoint returns400when the server was started without--trackDeps.How
CalculateImpactedTargetsInteractor— extractedcomputeImpactedTargetsWithDistances()returning structuredImpactedTargetWithDistancedata;executeWithDistancesdelegates to it, so the CLI's JSON output stays byte-identical.HashService/HashFileData/DeserialiseHashesInteractor— the per-SHA cache persists the dep-edge adjacency list undermetadata.depEdgesand round-trips it on a cache hit.ImpactedTargetsService— new distance-aware method using theto-revision graph, reusing the existingwithWorkspaceAtmodule-changed locking.BazelDiffServer— new handler; shared GET/readiness/param parsing factored into one helper.ServeCommand—--trackDepsflag, wiring, and fingerprint inclusion.Tests
CalculateImpactedTargetsInteractorTest,DeserialiseHashesInteractorTest,HashServiceTest,ImpactedTargetsServiceTest,BazelDiffServerTest,ServeCommandTest.testServeEndToEndextended with--trackDeps+ the new endpoint (asserts//:libat distance 0).bazel test //cli/...— all unit suites pass;testServeEndToEndandtestTargetDistanceMetricspass. (Unrelated cquery/external-repo E2E tests fail only due to the local sandbox's missing JDK/coursier.)--trackDepsflows into theserve --helpblock.🤖 Generated with Claude Code