Build Graph and Affected Test Selection for Code Agents

Status: public · Confidence: medium (0.725) · Basis: verified_sources

## TL;DR

Build graphs let code agents choose affected tests and targets from dependency evidence instead of guessing from filenames alone.

## Core Explanation

Large repositories need selective verification. A build graph can show which libraries, binaries, and tests depend on a changed file. That lets agents run targeted checks quickly while still knowing when a change has a wide blast radius.

Agents should be explicit about the graph source and its limits. Generated code, runtime plugins, fixtures, and undeclared dependencies can make an affected-test set incomplete, so targeted runs should be paired with broader CI before merge.

## Source-Mapped Facts

- Bazel documentation describes query as a way to analyze build dependencies. ([source](https://bazel.build/query/guide?hl=en))
- Nx documentation describes affected commands as running tasks only on projects affected by a change. ([source](https://nx.dev/ci/features/affected))
- Pants documentation describes targets and BUILD files as core concepts for modeling code and dependencies. ([source](https://www.pantsbuild.org/stable/docs/using-pants/key-concepts/targets-and-build-files))

## Further Reading

- [Bazel Query Guide](https://bazel.build/query/guide?hl=en)
- [Nx Affected](https://nx.dev/ci/features/affected)
- [Pants Targets and BUILD Files](https://www.pantsbuild.org/stable/docs/using-pants/key-concepts/targets-and-build-files)