YBX.

Research · · 简体中文

How to test a coding agent’s patch with a mixed-input case

A test for a missing flag can pass even when the patch breaks records with valid flags. One mixed-input case caught two such patches in our local Python check.

Build a case around the required behavior

Our original catalog helper returned enabled records. One record without an enabled flag triggered a KeyError. For the follow-up test we passed three records together. One was enabled, one lacked the flag, and one had the flag set to false. The expected output was just the first record.

Try two deliberately wrong implementations

We ran the original implementation, the verified dict.get repair, and two hand-written alternatives. One always returned an empty list. The other returned every record that had the key, regardless of value. Both wrong implementations passed the empty-input check and the case with only a missing flag. Both failed the mixed case.

The original raised KeyError on the missing-only and mixed cases. The dict.get repair passed all three cases. The new mixed case exercises the missing flag alongside values the old code already handled.

Apply the pattern to another patch

Write down the bad input that prompted the fix. Add a nearby valid input and one that should still be excluded. Put them in the same call if the function processes a batch. Name the assertion by expected behavior so a failure tells the reviewer what the patch broke.

Sources

Related reading