CI/CD GatesLong read
Diff-Aware Structural Regression Testing
Functional tests stay green while diffs quietly break architecture, so start from the diff.
Sponsored by Graphide

Why re-running a broad test suite cannot answer the structural question a diff raises
- Role: Opens the argument by establishing the fundamental mismatch between what traditional regression testing measures and what a diff actually demands — sets up every section that follows by naming the question the article will answer.
- Traditional regression testing answers the wrong question: it asks whether any existing test broke, not whether the change violated the architecture.
- The two questions have entirely different blast radii: a large documentation change may need no product tests at all, while a small change to a shared helper can silently invalidate assumptions held by dozens of downstream modules.
- Functional tests stay green through structural violations — a change that places a utility in the wrong architectural layer, crosses a forbidden module boundary, or introduces a hidden circular dependency produces no failing assertion and no red CI badge.
- The implication: answering the structural question requires a different starting point — not the full test suite, but the diff itself, used as the root of a dependency traversal.
- Note: Open on the VS Code example to make the gap visceral before naming it abstractly. Keep the section tight — its only job is to establish that the right question is different, not to survey everything that can go wrong.
How test-impact analysis traverses a dependency graph from a diff — and where the traversal breaks down
- Role: Explains the mechanism that makes diff-aware selection possible, then immediately exposes its known failure modes — building the ground the next section needs to argue why structural regression requires going further than TIA.
- Test-impact analysis makes the traversal mechanically: diff → dependency graph → ranked test set, selecting only the tests that exercise code reachable from the changed files.
- The dependency graph can be constructed from instrumentation, static import analysis, or historical failure data — each source captures a different slice of the true dependency structure.
- The traversal's limits are structural, not incidental:
- One hop of the import graph misses a fault two hops away; the full transitive graph misses dependencies that are not imports at all.
- Coverage-based selection is one run stale: a test file the diff adds appears in no existing coverage map and is therefore invisible to the selector.
- A change to a feature-flag default or environment variable touches no application code, so a diff-based rule selects nothing — configuration files must be mapped explicitly to a high-blast-radius tier or they escape selection entirely.
- The deeper problem: TIA finds tests that exercise changed code; it does not find tests that verify architectural constraints on that code — those constraints may not be encoded in any test at all.
- Note: Keep the failure-mode list concrete and short. The point is not to exhaustively catalog TIA weaknesses but to show that even a well-implemented traversal stops short of the structural question — which is what the next section addresses.
Why agent-generated diffs make the traversal's failure modes urgent rather than theoretical
- Role: Raises the stakes by showing that the failure modes just described are not edge cases under agentic coding — they are the norm — transitioning the argument from mechanism to real-world consequence.
- Agents make locally sensible decisions that are globally inconsistent: each file touched in a multi-file diff may be individually correct while the composition violates an architectural invariant that no single-file review would surface.
- The research record on agent-generated code structure is damning: a 2026 study (arXiv:2605.02741, cited in research brief) found that as models become more capable they generate increasingly coupled code, with code volume acting as a near-perfect predictor of architectural decay — and neither functional correctness nor detailed prompting mitigates the decay.
- The coupling pattern is not random: agents show a systematic preference for high-coupling strategies — monolithic methods in simple tasks, tight module coupling in complex ones — because coupling is the fastest path to functional correctness, which is what every test suite rewards.
- A large-scale empirical study (arXiv:2603.28592, cited in research brief) found that in AI-contributed repositories, the overwhelming majority of issues are code smells, structural problems, compared to correctness and security issues — confirming that functional test suites systematically miss the dominant failure mode of agentic output.
- Agent repair compounds the problem: SmellBench (arXiv:2605.07001, cited in research brief) found that the most aggressive repair agent introduces more new smells than it removes, exposing a gap between localized transformation capability and the cross-module architectural understanding that real repair requires.
- The practical consequence: the diff that lands in CI after an agent session is likely larger, more coupled, and more architecturally consequential than any human-authored diff of equivalent functional scope — exactly the conditions under which TIA's failure modes become critical.
- Note: Do not dwell on agent failure statistics as a catalog. Use the research to build a single point: the structural risk is not occasional, it is the default output shape of agentic coding, which is why the mechanism in the previous section needs to be extended rather than trusted as-is.
What structural regression testing actually requires: a dependency traversal rooted at the diff, not a test selector
- Role: Pivots from diagnosis to prescription — defines what diff-aware structural regression testing actually is mechanically, distinguishing it from ordinary TIA and from after-the-fact smell detection.
- Structural regression testing reframes the question: not "which tests need to run?" but "which architectural constraints does the diff's reachable subgraph touch, and do any of them now fail?"
- The traversal starts at the diff and walks the dependency graph transitively — not to find tests, but to identify every module, boundary, and relationship that the change reaches or perturbs.
- DiffTestGen (arXiv:2607.16024) demonstrates the mechanism in practice:
- Given a PR, it uses static call-graph analysis to identify valid entry points for reaching the changed code — including private functions not directly accessible from public APIs.
- It introduces a union coverage metric that combines coverage of the modified code in both the old and new version, iteratively improving until the behavioral difference between versions is exposed.
- Evaluated on a large set of PRs, DiffTestGen exposes behavioral differences in the overwhelming majority of cases and, integrated with the Testora regression detector, surfaces regression bugs missed by the best prior approaches.
- The call-graph traversal is what makes this structural rather than merely test-selective: reaching a private function two hops from the diff's entry point is exactly the case that one-hop import analysis misses.
- The union coverage metric matters architecturally: a test that covers only the new version may miss a behavioral regression in code the old version exercised; covering both versions' modified paths is the minimum required to catch violations of invariants that held before the change.
- Note: This is the technical heart of the piece. Ground it in DiffTestGen's actual mechanism rather than describing the ideal abstractly. The goal is for the reader to understand concretely what "rooted at the diff" means in implementation terms.
Making architectural constraints machine-evaluable so the traversal has something to check against
- Role: Advances the argument by showing that a dependency traversal is only as useful as the constraints it is checking — and that constraints must be encoded in executable form, not documentation, to be checkable at all.
- A traversal without a constraint set produces a subgraph but no verdict: knowing which modules the diff reaches says nothing about whether reaching them is a violation unless the permitted and forbidden relationships are stated precisely.
- The class of constraints that matter structurally are those that are topological: layer boundaries that prohibit upward or cross-layer imports, module isolation rules that forbid certain dependency edges, cycle-freedom invariants that break when mutual imports appear.
- The causal Java repository study (arXiv:2606.13298, cited in research brief) makes this concrete in the other direction: architectural smells such as cyclic dependencies and hub-like dependencies are topological — they are detectable as graph properties (mutual package imports, excessive fan-in and fan-out) — which is precisely why they are mechanically checkable rather than requiring human judgment.
- The design principle for executable constraints: each constraint connects a recorded architectural decision to an objective check — a dependency edge that must not exist, a module that must not import from a given namespace, a file that must live in a specific directory — evaluable without inference.
- A useful gate must emit more than pass/fail: the governing decision, the affected files, the detected violation, the approved alternatives, and an exception path — so that a blocked merge carries enough context for the developer to act without opening a separate document.
- The VS Code file-placement case (from DiffTestGen research) illustrates the payoff: a constraint that encodes "utilities must reside in src/vs/base/, not in workbench subdirectories" is evaluable mechanically against the diff's file list — no test execution required, no human review of forty changed files.
- Note: Keep the section focused on the constraint-encoding problem, not on tooling ecosystems. The point is that constraints must be stated in a form the traversal can evaluate — the next section handles enforcement in CI.
Enforcing structural constraints in CI without making the pipeline too slow to matter
- Role: Addresses the practical objection that makes teams skip structural checks — latency — and shows that diff-scoping is the answer, connecting the mechanism from earlier sections to the CI enforcement context.
- The CI latency trap is the main reason structural analysis gets disabled: pipeline stages that exceed a certain time threshold face developer resistance and are frequently scheduled only nightly, which means they catch violations after the damage is already merged.
- The solution is the same diff-scoping the earlier sections describe: instead of analyzing the entire codebase for every push, the structural check traverses only the subgraph reachable from the diff — a bounded computation whose cost scales with change size, not codebase size — consistent with a 2026 analysis of test impact analysis tools on pull requests, which found a 60 to 80% reduction in test suite execution time compared to running the full suite.
- The confidence-widening behavior is important: a structural gate that narrows scope when it is uncertain is worse than no gate, because it produces a false sense of coverage; the right failure mode is to widen to smoke and critical-path checks, not to silently skip.
- Configuration and environment files that touch no application code require explicit mapping to a high-blast-radius tier — a change to a feature-flag default must trigger a broader structural check even though the diff-to-import-graph traversal finds nothing.
- The false-positive problem in smell detection (SmellBench, cited in research brief) is a separate CI concern: a gate that blocks on raw smell counts will generate high noise because overall false-positive rates are high and vary dramatically by smell type; filtering by smell type — blocking on Unstable Dependencies, not on Potential Redundant Abstractions — is required before a smell-based gate becomes usable.
- Note: The latency argument and the false-positive argument are the two objections most likely to get structural CI gates disabled in practice. Address both concretely. Do not turn this into a survey of CI tools — keep it on the structural enforcement logic.
What `gr check` enforces and why the graph should live in the repo, not in a diagram
- Role: Brings the argument to its practical conclusion by showing that the graph-as-source-of-truth model — where the architectural map versions with the code and is enforceable in CI — is the necessary infrastructure for everything the earlier sections describe.
- Every mechanism described so far — traversal rooted at the diff, executable constraints, confidence-aware widening — requires a stable, machine-readable representation of the architecture that exists in the repo and updates as the code changes.
- A diagram someone drew once and stored outside the repo cannot serve this function: it goes stale at the first merge it does not witness, and it cannot be queried by a CI check or a traversal algorithm.
- The graph that lives in the repo and versions with the code can do what a diagram cannot: it is the ground truth the traversal walks, the structure the constraint checker evaluates, and the map developers steer agents on — all from the same artifact.
- gr init maps every module, file, class, function, and call relationship into this live graph instantly; gr check runs the structural constraint evaluation against it in CI, exits non-zero on a violation, and blocks the merge with enough context — the governing constraint, the affected files, the approved alternatives — for the developer to act without a separate review conversation.
- A CI check that exits non-zero and blocks a merge is more valuable than any amount of post-hoc architectural review: it catches the violation at the moment of lowest remediation cost, before the change is integrated and before downstream modules have been written to depend on the new structure.
- The causal Java study's finding (cited in research brief) that structural smell counts held essentially flat even as agentic code volume grew (+12.8%), though the authors characterize this as a denominator effect rather than evidence of architectural enforcement, is the strongest evidence that enforcement works: modules integrating without creating new topological violations is not an accident — it is the outcome of constraints that make violation impossible to merge.
- Note: Close on the enforcement-as-prevention framing, not on product features. The argument the whole piece has been building is that structural regression is a question you can only answer if you have an enforceable, versioned architectural model — this section names that model and shows why it is the necessary conclusion of the earlier reasoning.
Sources
Filed underCI/CD Gates
More in CI/CD Gates
Shift-Left Architecture Review for Agent-Generated PRs
Shipped by Agents Editors
Graph-Level Architecture Policy as a Non-Negotiable CI Merge Gate
Shipped by Agents Editors
Why Graph-Native PR Blocking Catches Layered Architecture Violations Static Analysis Misses
Shipped by Agents Editors


