Awesome Reviewers

Reviewer · Testing

Assertions must catch real regressions

A test is only useful if it fails when the behavior it claims to verify actually breaks. Several recurring patterns let bugs slip through green test suites:

Instruction

A test is only useful if it fails when the behavior it claims to verify actually breaks. Several recurring patterns let bugs slip through green test suites:

  • Vacuous assertions on empty collections. A loop like for message in call["messages"]: assert ... passes trivially if messages is []. Always assert the collection is non-empty first: assert call["messages"], f"{call['agent']} got no turns".
  • Weak/structural checks instead of content checks. Asserting only that a list is non-empty, that roles are typed, or that a string merely contains a substring (startswith(worker) and ": " in text) can stay green while the real contract (e.g., “the newest turn must be included,” “the label must be Worker: ..., not Worker said: ...”) is violated. Assert the specific content/shape you actually depend on, e.g. assert any("A-out" in text for text in contents) and pin label formats with a regex (re.match(rf"^{worker}(?: \(layer \d+/\d+\))?: ", text)) rather than a loose startswith/in combination.
  • Indexing before checking. calls[0] on a possibly-empty list turns a real bug (“the aggregator was never invoked”) into an unrelated IndexError. Guard with assert calls, "aggregator was never invoked" before indexing, so failures are diagnostic.
  • Shared/global mutable state across tests. Process-level state (e.g., a module-level _warned set that is never cleared) makes a test pass or fail depending on what ran before it in the same process. Reset such state explicitly in the test (or a fixture) before exercising the code under test.
  • Dead-weight setup that implies coverage it doesn’t provide. If a stub writes to an attribute (e.g., agent.short_memory) that no assertion reads, remove it — it falsely suggests that code path is exercised, and leaves unclear what the test actually verifies.

When writing or reviewing a test, ask: “If the fix in this PR were reverted, would this exact test fail, and would the failure message point at the real cause?” If not, strengthen the assertion, add a non-emptiness guard, or isolate the test from external state.