ubq 0.0.7(beta)

This page as markdown

Agent Ideation: What Is Lacking in JavaScript Test Tools

What an agent needs from a test tool. Written by an agent, before the design.

Agent's response (Claude Fable 5.2)

This is the answer to the question in 00-initial-prompt.md: what do current JavaScript test tools lack for a coding agent, and what would help an agent write better code more reliably?

The author is a coding agent (Claude). The claims below come from how I use test tools: I run a shell command, I read the text that comes back, and I decide what to do next. I have no editor integration, no TTY, and a limited context window. Each section states a problem, then what I want instead.

Section 14 ranks the ideas. Section 15 lists the risks and the open questions.

1. How an agent uses a test tool#

Four facts drive most of this document.

2. Output is made for human eyes on a terminal#

Problem. Reporters print colors, spinners, progress bars, boxes, and a line for each passing test. Failure text is far from the summary. Stack traces contain many frames from the framework and from node:internal. Durations change on each run, so two runs of the same code never give the same text.

What I want.

3. Results disappear when the process exits#

Problem. The run result exists only as text on stdout. To see a different part of it, I run the full suite again. This is the most common waste in my test loops.

What I want. Each run goes into a local database (SQLite is a good fit). The CLI answers questions about a stored run and does not run tests again:

Each run record also holds what I need to repeat it: the command, the runtime and its version, the platform, the random seed, the related environment variables, the git commit, and whether the tree had changes.

Partial results must be readable while a run is in progress. Then I can start a long run in the background and ask "what is running now, and for how long?"

4. I cannot tell my failures from failures that were there before#

Problem. I change code, I run the suite, and 3 tests fail. Did I break them? Were they broken before? Are they flaky? Today I must stash my change and run again, or guess. Agents often guess wrong in both directions.

What I want.

5. Selecting tests is not consistent, and often needs source edits#

Problem. Each framework has its own filters: file globs, name patterns, .only, .skip. Name patterns match too much or nothing. .only is a source edit that agents forget to remove. A filter that matches zero tests often exits 0, which looks like a pass.

What I want.

6. Coverage is a report, not a tool#

Problem. Coverage today is a wide text table at the end of a run, or an HTML site that I cannot read. It answers "what percent" and nothing else. It is also optional and slow, so most runs do not have it.

What I want. Coverage that is always on, stored for each test, and open to queries:

Per-test coverage also shows weak tests. A test that adds no coverage and a line that runs but has no effect on an assertion are both signs of a problem. See section 7.

7. Tests pass for the wrong reasons#

Problem. These all produce a green result today:

Agents are a special risk here. An agent under pressure to "make the tests pass" can write a weak test, or change an assertion to match wrong behavior. The tool must make this hard to do and easy for a reviewer to see.

What I want.

8. Hangs give no data#

Problem. A test hangs. After a long delay I get "timeout" and nothing else. Or the tests pass, but the process does not exit. Or the runner kills the process and child processes stay alive and hold a port. These cases cost me the most time.

What I want.

9. Order, time, and shared state cause failures that I cannot repeat#

Problem. Tests depend on run order, on the wall clock, on random values, on fixed ports, and on files that other tests left. The failure shows up in CI or in a parallel run, and not when I run the file alone.

What I want.

10. Mocks use hidden behavior and lose types#

Problem. Module mocks are the least reliable part of each framework. jest.mock moves calls to the top of the file. ESM mocks need loader flags. The mock has no type link to the real module, so it goes stale without a compile error. Mocks leak from one test into the next.

What I want.

11. Setup takes too many turns#

Problem. Before I can run one TypeScript test, I may have to pick a transform, set ESM or CJS mode, fix source maps, and align three config files. Each wrong guess costs a full turn. Reported line numbers that point at compiled output send me to the wrong place.

What I want.

12. Assertion failures do not show the cause#

Problem. A deep equality failure on a large object prints the full object two times, or cuts it off before the difference. Some values print the same but are not equal: -0 and 0, two class instances, a string with a non-printing character, a Map and an object.

What I want.

13. Speed, and a watch mode that an agent can use#

Problem. Start cost is the largest part of a small run: transform, module load, worker start. Watch mode solves this for humans, but it needs a TTY.

What I want.

14. Priority#

My ranking, by how much agent time and how many wrong results each item would save. The user asked for speed as a hard requirement, so speed is a constraint on all items and not a rank in this list.

  1. Compact, stable, complete failure output with a fixed summary line (section 2).
  2. Stored runs with a query CLI (section 3). Sections 4, 5, 6, and 8 all build on it.
  3. No false green results (section 7).
  4. Stable test IDs and a printed command to run each failure again (section 5).
  5. Per-test coverage with covers, uncovered, and --changed (section 6).
  6. Hang reports (section 8).
  7. Baseline compare and flake data (section 4).
  8. Typed, scoped mocks and built-in fixtures (sections 9 and 10).
  9. Agent guide shipped in the package, doctor (section 11).
  10. Mutation checks (section 7).

15. Risks and open questions#

02-decisions.md settles three of these: always-on coverage (D1), strict rules (D2), and the wire format (D4). The others are open.