Stacks

Debug a single failing test in OCaml with Atlas in 2026

Updated 8 min read

Atlas, the terminal-native AI coding agent, empowers OCaml developers in 2026 to efficiently debug a single failing test by integrating directly with the OCaml toolchain, including `dune runtest`, `opam`, and `ocamlformat`, to identify and fix code issues, not just assertions.

How Atlas isolates and runs a single OCaml test

In 2026, Atlas streamlines debugging OCaml tests by running a single failing test in isolation, leveraging its `bash` tool to execute `dune runtest` with specific filter flags. This approach ensures minimal output, allowing developers to focus on the relevant test case without sifting through an entire test suite.

When an OCaml developer needs to debug a specific failing test, Atlas initiates the process by using its `bash` tool to execute the `dune runtest` command. Instead of running the entire test suite, Atlas passes the framework's filter flag, such as `--only-test 'MyModule.MyFailingTest'`, to `dune runtest`. This command, familiar to any OCaml developer, ensures that only the designated test case runs, producing a focused output that is small enough for Atlas to reason about effectively. This capability is crucial for quickly identifying the root cause of a failure within a large OCaml codebase, as it mirrors the precise control a developer would exercise manually in the terminal. Atlas's ability to interact with `dune runtest` directly through `bash` means that all standard debugging levers, including verbose flags or specific test filters, are fully available and utilized by the agent.

Forming hypotheses and adding temporary OCaml logging

Atlas forms hypotheses about OCaml test failures and checks them by adding temporary logging or re-running tests with verbose flags, a common practice for developers in 2026. Using its `edit` tool, Atlas can insert `Printf.printf` statements into `.ml` files, providing runtime insights without manual file manipulation.

Once Atlas has a clear understanding of the failing OCaml test and its call graph, it forms a hypothesis about the root cause. To validate this hypothesis, Atlas can employ several strategies. One effective method is to add temporary logging statements directly into the OCaml source code. Using its `edit` tool, Atlas can insert `Printf.printf` calls or other debugging output into relevant `.ml` files. For instance, it might add `Printf.printf "Debug: value is %d\n" my_variable;` at a critical point. After adding the logging, Atlas re-runs the single failing test using its `bash` tool, observing the output to confirm or refute its hypothesis. Alternatively, Atlas can re-run the test with verbose flags, if supported by the `dune runtest` configuration, to gather more detailed information. This iterative process of hypothesizing, modifying code, and re-running tests is fundamental to effective debugging in OCaml, and Atlas automates these steps while keeping the developer informed.

Fixing OCaml code and ensuring style with ocamlformat

Atlas fixes OCaml production code using its `edit` or `apply_patch` tools, ensuring that changes are precise and maintain code quality. After applying fixes, Atlas automatically runs `ocamlformat` to ensure the modified `.ml` files adhere to the project's style guidelines, a crucial step for OCaml developers in 2026.

After validating a hypothesis and identifying the precise location of the bug in the OCaml codebase, Atlas proceeds to fix the production code. For minor, localized changes, Atlas uses its `edit` tool to modify specific lines or hunks within a `.ml` file. If the required fix spans multiple hunks or involves more complex structural changes, Atlas can generate and apply a unified diff using its `apply_patch` tool, which is more robust than chaining multiple brittle `edit` operations. This ensures that the code modification is comprehensive and atomic. Crucially, after any code modification, Atlas automatically invokes `ocamlformat`. This OCaml formatter ensures that the newly edited code conforms to the project's established style, preventing style-related diffs and maintaining a clean, consistent codebase. The developer is then presented with a unified diff for approval, which includes both the functional fix and the `ocamlformat` changes, before Atlas writes the changes to disk.

Atlas's safety and review mechanisms for OCaml changes

Atlas incorporates robust safety and review mechanisms for OCaml code changes, ensuring developer control and transparency in 2026. Every Atlas tool call, including `bash` and `edit`, is permission-gated, and all proposed file edits are presented as unified diffs for explicit approval before writing.

Atlas is designed with developer safety and control as paramount concerns. Before any tool call, such as executing `dune runtest` via `bash` or modifying an OCaml `.ml` file with `edit`, Atlas consults permission-gated allow, ask, and deny rules. This ensures that no action is taken without explicit or pre-approved consent. Furthermore, Atlas drafts a comprehensive plan in a read-only plan agent, asking for developer approval before switching to a build agent that can make changes. When Atlas proposes a code fix, it computes a unified diff for every file edit, presenting it clearly to the developer for approval. This diff allows the OCaml developer to review the exact changes Atlas intends to make, including those from `ocamlformat`, before they are written to disk. Atlas also snapshots file changes as git patches, enabling easy diffing and rollback of edits, providing an additional layer of safety and version control integration for OCaml projects.

Step by step

  1. 01Run just the failing OCaml test: Use Atlas's `bash` tool to execute `dune runtest --only-test 'MyModule.MyFailingTest'` to isolate the specific test and minimize output.
  2. 02Read the OCaml test and module: Atlas uses its `read` tool to examine the test and the `.ml` module it exercises, then employs the `lsp` tool's `goToDefinition` and `findReferences` to walk the OCaml call path.
  3. 03Form a hypothesis and check it: Atlas uses its `edit` tool to add temporary `Printf.printf` logging statements to OCaml `.ml` files, or re-runs `dune runtest` with verbose flags via `bash` to gather more data.
  4. 04Fix the OCaml production code: Atlas uses its `edit` tool for small, focused changes in `.ml` files, or `apply_patch` for more extensive OCaml code modifications spanning several hunks.
  5. 05Re-run and clean up: Atlas re-runs the single OCaml test with `dune runtest`, then the full suite, and uses `edit` to remove any temporary `Printf.printf` logging added earlier. Finally, Atlas runs `ocamlformat` to ensure style consistency.

Frequently asked questions

How does Atlas interact with my OCaml project's build system?
Atlas interacts directly with your OCaml project's build system by reading your `dune-project` file at the root and understanding each `dune` stanza. It can execute `dune runtest` commands via its `bash` tool, interpret compiler errors, and even suggest adding an `Alcotest` case to a `test/ dune` stanza, all while respecting your project's configuration.
Can Atlas manage OCaml package dependencies with opam?
Yes, Atlas is aware of your OCaml project's package dependencies. It reads the packages pinned in your `opam` switch and understands the context of your `opam` environment. While its primary role is not package management, this awareness helps Atlas provide accurate code suggestions and understand your project's structure.
How does Atlas ensure OCaml code quality and style?
Atlas ensures OCaml code quality and style by integrating `ocamlformat` into its workflow. After Atlas proposes any code edits to `.ml` files, it automatically runs `ocamlformat` to apply your project's formatting rules. This guarantees that the diff presented for your approval is style-clean and adheres to your OCaml project's conventions.
What OCaml file types does Atlas understand?
Atlas understands key OCaml file types, including `.ml` source files and `.mli` interface files. It builds its code index using AST declarations from Tree-sitter, allowing it to parse and understand the structure of your OCaml code, including module signatures and type definitions, for precise navigation and editing.
How does Atlas handle permissions for OCaml code modifications?
Atlas handles permissions for OCaml code modifications through a robust, permission-gated system. Every tool call, including those that modify `.ml` files or execute `dune runtest`, is checked against allow, ask, and deny rules. Atlas also drafts plans in a read-only agent and presents a unified diff for every proposed change for your explicit approval before writing to disk.
Can Atlas debug OCaml code with local embeddings?
Yes, Atlas can build its code index with local Ollama embeddings, keeping your OCaml code off third-party servers. This means that when Atlas searches your OCaml codebase with hybrid semantic and keyword retrieval, the sensitive details of your project remain entirely within your local environment, enhancing privacy and security.

Try Atlas in your terminal

The terminal-native AI coding agent. Free core, single binary.

Install Atlas

Related guides

Debug a Single Failing Test with Atlas in 2026

How to debug one failing test with Atlas in 2026: run it in isolation with bash, walk the call graph with the lsp tool, and fix the code, not the assertion.

Atlas for OCaml: A Terminal-Native AI Coding Agent for dune and opam Projects in 2026

Atlas is a terminal-native AI coding agent for OCaml in 2026. It reads dune stanzas and .mli signatures, runs dune runtest behind a prompt, and finishes with ocamlformat.

Document an OCaml Module with a README using Atlas in 2026

Generate accurate, up-to-date README documentation for your OCaml modules in 2026 using Atlas. Leverage dune, opam, and ocamlformat for precise, traceable docs.

Trace a runtime bug from a stack trace in OCaml with Atlas in 2026

Pinpoint OCaml runtime bugs from production stack traces using Atlas in 2026. Leverage dune, opam, and ocamlformat to quickly identify and fix issues without a debugger attached.

Self-review Your OCaml Working Diff Before Committing with Atlas in 2026

OCaml developers in 2026 can self-review uncommitted diffs with Atlas, catching mistakes before CI. Leverage dune runtest, ocamlformat, and opam for a clean codebase.

Audit an OCaml Repository with Parallel Subagents in Atlas, 2026

Sweep an OCaml repository for specific problems using Atlas's parallel subagents. Leverage `dune`, `opam`, and `ocamlformat` for efficient, context-window-friendly audits.

Review a pull request in OCaml with Atlas in 2026

In 2026, Atlas helps OCaml developers review pull requests by fetching diffs, reading full files, checking .mli signatures, running dune runtest, and applying ocamlformat.

Write Unit Tests for Untested Code in OCaml with Atlas in 2026

Learn how Atlas helps OCaml developers in 2026 write unit tests for untested modules. Atlas uses dune runtest, opam, and ocamlformat to integrate with your existing OCaml workflow.

Browse this resource hub