Skip to content

feat: compute target distances in bazel-diff serve#397

Open
tinder-maxwellelliott wants to merge 1 commit into
masterfrom
maxwelle/add-deps-file-to-server
Open

feat: compute target distances in bazel-diff serve#397
tinder-maxwellelliott wants to merge 1 commit into
masterfrom
maxwelle/add-deps-file-to-server

Conversation

@tinder-maxwellelliott

Copy link
Copy Markdown
Collaborator

What

Adds build-graph target-distance computation to the bazel-diff serve HTTP 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 with targetDistance (hops to the nearest directly-changed target) and packageDistance (how many of those hops cross a package boundary). Directly-changed targets sit at distance 0.

{
  "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 returns 400 when the server was started without --trackDeps.

How

  • CalculateImpactedTargetsInteractor — extracted computeImpactedTargetsWithDistances() returning structured ImpactedTargetWithDistance data; executeWithDistances delegates to it, so the CLI's JSON output stays byte-identical.
  • HashService / HashFileData / DeserialiseHashesInteractor — the per-SHA cache persists the dep-edge adjacency list under metadata.depEdges and round-trips it on a cache hit.
  • ImpactedTargetsService — new distance-aware method using the to-revision graph, reusing the existing withWorkspaceAt module-changed locking.
  • BazelDiffServer — new handler; shared GET/readiness/param parsing factored into one helper.
  • ServeCommand--trackDeps flag, wiring, and fingerprint inclusion.

Tests

  • New/extended unit coverage: CalculateImpactedTargetsInteractorTest, DeserialiseHashesInteractorTest, HashServiceTest, ImpactedTargetsServiceTest, BazelDiffServerTest, ServeCommandTest.
  • E2E testServeEndToEnd extended with --trackDeps + the new endpoint (asserts //:lib at distance 0).
  • bazel test //cli/... — all unit suites pass; testServeEndToEnd and testTargetDistanceMetrics pass. (Unrelated cquery/external-repo E2E tests fail only due to the local sandbox's missing JDK/coursier.)
  • README regenerated; --trackDeps flows into the serve --help block.

🤖 Generated with Claude Code

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>
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.

1 participant