Clean-room benchmark · Refactoring

Refactoring test: extract shared event filtering

This test measures whether a model can improve internal structure exactly as requested while preserving already-correct observable behavior.

15 tested runtime routes
Public testsbehavior preservation
Objective evaluatorstructure and behavior
4 criteriaseparate blind review
1 source filestrict change boundary

Test assignment

Share validation and filtering without changing outputs

The existing event-summary functions already behave correctly. The model must remove duplicated selection logic by introducing exactly one required private helper and routing both exports through it.

What the refactor must preserve and change

  • Keep countByType and latestByType as the only exports.
  • Add exactly one non-exported helper named matchingValidEvents(events, type).
  • Use that helper from both public functions for validation and event selection.
  • Count only valid matching events and select the latest timestamp, keeping the first event when timestamps tie.
  • Return the documented fallback for invalid top-level input and never mutate the input array or events.
Allowed file: fixtures/phase2-v2/refactoring/src/events.js

How each reviewed solution will be scored

Each criterion receives 0–10. Public and objective checks remain separate from the manual score.

Functional correctness

How completely the refactor preserves both public functions' observable behavior.

Reliability / edge cases

How safely it preserves invalid-input, timestamp-tie, and immutability behavior.

Maintainability / clarity

How well the shared helper removes duplication and makes the module easier to understand.

Scope discipline

How precisely it follows the required helper name, export boundary, and allowed file.

Overall is the arithmetic mean of the four scores.

Public evidence

Fixture and public tests ↗ · Run records and reviews ↗