newsfilter
← Interviews
AI Engineer13 min

225,000 Lines of Tests, Written and Merged by Agents - Kush Agrawal, Duolingo

Kush Agrawal

Conference Presentation, Keynote
  • Duolingo's iOS engineering team, led by staff engineer Kush, successfully deployed an AI agent-driven pipeline to generate and ship 225,000 lines of unit tests, moving repository coverage from 11% to 24% and MVVM-specific coverage from 9% to 59% over an eight-month period.
  • The initiative addressed a scaling bottleneck where verifying code became more critical than writing it, driven by a 10-year mature codebase growing from 200,000 to nearly 2 million executable lines and a contributor base expanding from 200 to over 250 engineers, including non-iOS roles like backend engineers and product managers.
  • The system architecture relies on Temporal for durable workflow orchestration, Cloud Code for the AI coding agent, S3 for shared state management, GitHub Actions for PR lifecycle management, and Datadog for observability.
  • The workflow follows a five-step loop: identifying testable files, writing tests via AI agents, verifying quality and CI pass, resolving PRs through human review, and iterating on feedback to improve future agent performance.
  • The project was executed in four distinct milestones: local validation to prove viability, a scheduled backfill workflow for existing code, a PR lifecycle workflow for merging generated tests, and a label-trigger system for testing new code added by engineers.
  • During local validation, the team achieved a 50% merge rate across two batches (17 PRs yielding 8 merges, 40 PRs yielding 19 merges) to identify and fix "paper cuts" before production deployment.
  • Key technical failures identified during validation included agents mixing XCTest and SwiftTesting frameworks, difficulties mocking concrete singletons, and CI flakiness from timing-based tests, all resolved through updated testing rules, codebase protocolization, and improved prompting.
  • The production backfill workflow utilizes a scoring script to prioritize files, granting a 2.5x boost to ViewModels, Repositories, and Data Sources while penalizing large legacy files and excluding UI code, which is better suited for snapshot testing.
  • The PR lifecycle workflow operates as a state machine that closes stale PRs after three weeks, auto-fixes pre-commit issues, retries CI failures up to five times, and assigns reviewers based on the top contributor of the source file.
  • To ensure code quality, the team implemented a three-layer defense: a deterministic rule rejecting production code edits outside of test/mock files, an agent resolving P0 comments from Claude/Codex reviews, and an "LLM as a judge" that rejected 73 out of 1,200 reviewed PRs for issues like silencing tests or adding long waits.
  • Infrastructure challenges regarding lint failures (initially 13.6% of PRs, with 62% caused by two specific rules) were solved by moving agents from Linux to Mac runners, enabling local linting and building before PR creation, alongside a GitHub action for autofixing.
  • As of the presentation, the pipeline accounted for 34% of new test files, 44% of new test cases, and 10% of all Swift lines added, though this share has recently declined as human engineers increasingly write their own tests.
  • The team anticipates applying this same "identify-write-verify-resolve-iterate" pattern to other modernization tasks, including migrating legacy screens to MVVM/Swift UI and Android code to Coroutines.
  • Future plans include replacing the current handwritten decision tree in the PR lifecycle workflow with fast, general-purpose AI classifiers to execute PR state-to-action decisions in milliseconds.