AI Regression Selection Agent: Intelligent Test Impact Analysis on Every Pull Request
Using Git diff AST analysis and dependency graphs to execute only the tests affected by a code change.
01. The Problem
02. The Concrete Engineering Scenario
A developer modifies wallet balance calculation logic in backend/src/modules/wallets/wallets.service.ts. Do we need to run all 608 tests, or only the subset affected by wallet balance changes?
Acts as a CI Test Selector agent that computes code coverage dependency graphs between modified source files and Playwright/Jest test files, dynamically assembling an optimal test execution list.
03. Context & Inputs Provided to Agent
- •Git commit diff (git diff origin/main...HEAD).
- •TypeScript import dependency tree generated via madge or ts-morph.
- •Historical test execution results and defect density records.
04. Agent Reasoning & Planning Steps
Playwright Interaction
Passes filtered grep patterns or specific file path arguments to npx playwright test, executing 28 targeted tests instead of 608.
Evidence Collection
Outputs a CI summary comment on the GitHub PR showing: 'Impact Analysis: 2 files modified -> 28 tests selected (4.6% of suite). Execution time: 4.2s (vs 34s baseline).'
05. Concrete Code Excerpt
Selective CI Execution Script# Generated dynamic execution command based on PR git diff
npx jest src/modules/wallets/wallets.service.spec.ts \
&& npx playwright test \
tests/api/wallets.spec.ts \
tests/defects/wp-qa-001-settlement-refund.spec.ts \
tests/ui/transfer-flow.spec.tsFailure & Edge Case Handling
If a change touches shared root infrastructure (e.g., main.ts, database migration, or global env config), the agent automatically escalates to a full regression run.
Measurable Result
Reduces PR check turnaround time from 35 seconds to under 5 seconds while ensuring zero missed regressions.
Human Review & Approval Gate
Developers appreciate immediate PR feedback; nightly builds still run the 100% full regression baseline for comprehensive safety.
Key Engineering Lessons Learned
Test impact analysis is essential for scaling test automation beyond 1,000 tests.
Always maintain a full nightly regression sweep to catch indirect side-effects that static analysis misses.
Clear visual indicators showing WHY a test was selected build developer trust in selective CI.