Complex Agents, Shallow Tests: Demystifying and Enhancing Test Adequacy of Agent Harness in the Wild

Yifan Xiong, Jingyi Ge, Zhenpeng Chen, Yiling LouarXiv 2026

TL;DR

While LLM-based agents are exploding in popularity, their "harness"—the critical infrastructure code that manages tools, memory, and environment—is dangerously undertested. This paper introduces HarnessTester, a novel test generation tool that uses "agent-harness contracts" to achieve significantly higher code coverage and has already uncovered 122 real-world bugs in major agentic systems like OpenClaw and OpenHands.

What Problem Does This Paper Address?

Modern AI agents aren't just LLMs; they are complex software systems composed of a probabilistic backbone (the LLM) and a deterministic harness. The harness is the "body" that allows the LLM "brain" to interact with the world—it handles tool calls, manages long-term memory, and enforces guardrails.

As these harnesses grow to hundreds of thousands of lines of code, they become prone to traditional software bugs. However, the community has primarily focused on "black-box" benchmarks (like SWE-bench) that measure if an agent finishes a task, rather than "white-box" testing that ensures the harness code itself is reliable. The authors identify a specific, critical category of code called LLM-Dependent Harness (LDH): the parts of the harness that directly process or react to non-deterministic LLM outputs. Their study reveals that LDH is severely undertested, with less than half of its lines and branches covered by existing test suites.

Methods

The researchers tackled this problem in two phases: an empirical study and the development of a new testing tool.

  1. LDH Extraction: They developed an interprocedural analysis tool to identify LDH code by tracing data and control dependencies from LLM invocation points (like OpenAI or LiteLLM calls) throughout the codebase.
  2. HarnessTester: They built a coverage-driven, LLM-powered test generator specifically for agent harnesses. Its core innovation is Agent-Harness Contract Support, which consists of two parts:
  3. Contract Guidance: A set of prompt-level principles that instruct the LLM to respect "contracts"—the expected data structures, execution preconditions, and interaction protocols required for different harness components to work together.
  4. Contract Context Retriever: A tool that allows the test generator to fetch relevant code definitions (classes, functions, fixtures) on demand, helping it construct "contract-faithful" mocks and test setups.

Datasets

The study and evaluation utilized several key resources:

  • 10 Real-World Agentic Systems: A diverse set of popular open-source agents including OpenHands, Aider, OpenClaw, and Kimi Code, spanning domains like coding, research, and general-purpose automation.
  • H-Bench: A new, manually curated benchmark created by the authors containing 250 historical harness bugs mined from the commit histories of the studied agents. This serves as a ground-truth set for evaluating bug-detection capabilities.
Table 1. Statistics of studied agentic systems.

Key Insights and Ideas

  • The "Brain-Body" Interface is the Weakest Link: LDH code contains a high concentration of decision logic (parsing responses, dispatching actions) but receives less testing attention than general utility code.
  • Testing Requires "Contract Fidelity": You can't just mock a random LLM response to test an agent. Reaching deep harness logic requires a test setup that satisfies complex, multi-component "contracts"—for example, a tool-call response must match a specific schema and be preceded by a valid history state.
  • Semantic Gaps in Testing: The authors found that while "Tool Action Handling" is relatively well-tested (due to explicit schemas), "Agent Orchestration" and "Error Recovery" are largely ignored because they depend on dynamic, hard-to-enumerate execution contexts.
  • White-Box vs. Black-Box: High task-level performance doesn't guarantee reliability. Even "successful" agents can have harness bugs (like sensitive data leakage) that end-to-end benchmarks miss.

Key Results

The evaluation showed that HarnessTester is a significant step forward for agent reliability:

  • Superior Coverage: HarnessTester achieved 75.95% larger line coverage gains and 84.76% larger branch coverage gains compared to state-of-the-art general-purpose test generators like CoverUp and Qodo Cover.
  • Better Bug Detection: In the H-Bench historical bug test, HarnessTester detected 43 bugs, while the best baseline detected only 2.
  • Real-World Impact: When applied to the latest versions of these agents, HarnessTester identified 122 true bugs. 88 of these were previously unknown, and 69 have already been confirmed by developers.
  • Cost-Effectiveness: Despite being more complex, HarnessTester found bugs at an average cost of $1.80 per bug (in LLM API fees), significantly more efficient than baselines.
Table 2. Overall test adequacy.

Limitations and Future Work

  • Scope of Study: The empirical findings are based on 10 specific systems. While diverse, they may not represent every possible agent architecture.
  • Manual Labeling: The semantic analysis of predicates relied on manual annotation, which, while showing high agreement (Cohen’s κ = 0.96), is subject to human judgment.
  • Cost: While cost-effective per bug, the iterative generation process is more expensive in terms of raw API tokens than simpler methods.
  • Future Directions: The authors suggest extending this work to explore how harness testing can be integrated into CI/CD pipelines for agents and developing more automated ways to infer "contracts" directly from code.

Summary updated

BibTeX
@misc{xiong2026complex,
  author = {Yifan Xiong and Jingyi Ge and Zhenpeng Chen and Yiling Lou},
  title = {{Complex Agents, Shallow Tests: Demystifying and Enhancing Test Adequacy of Agent Harness in the Wild}},
  year = {2026},
  eprint = {2610.04921},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.04921},
}
Figure