intermediate · 23 minute study
Make one hypothesis face a counterexample
Changing several things until a bug disappears can leave you unable to explain the fix or prevent the failure from returning.
Useful preparation · 1 prerequisite
Use this as a map, not a lock. If these ideas are familiar, continue.
- Turn a complaint into a reproducible defect — A vague bug report invites a vague fix. The fastest useful first step is to make expected behavior, actual behavior and reproduction steps precise.
First, build a mental model
A hypothesis earns confidence by making a prediction that could be wrong. A regression test preserves the smallest counterexample after the fix.
- Write competing explanations and choose a cheap experiment whose outcomes distinguish them. Repeating the same successful case adds little evidence.
- Change the mechanism responsible for the contract failure. Avoid masking the symptom with broad catches, disabled validation or ignored errors.
- Keep the original failing case and a nearby valid case. A fix that rejects every input can pass a rejection test while breaking the feature.
- A regression test should fail against the defective behavior and pass against the corrected behavior for the intended reason.
function parseCount(raw) {
const count = Number(raw);
if (!Number.isSafeInteger(count) || count < 0) {
throw new Error('Count must be a nonnegative integer');
}
return count;
}
// Critic's question: should '' really mean zero?- Hypothesis
Numeric conversion alone may accept inputs the product considers missing.
- Counterexample
Number('') is 0. The shown function accepts a blank string.
- Repair contract
Decide whether blank input is invalid, then reject it explicitly before conversion and retain valid numeric input.
Production thinking
Take this beyond the example.
Stop widening the patch once the actual invariant is restored and its regression is covered. If the contract itself is ambiguous, resolve that decision rather than inventing an expected value.
Sources and further reading
Your evidence
unseen is a local learning signal, not a credential or proof of production competence.
Explain the mental model, then explicitly acknowledge it. Opening a page is not evidence.
Supported retries can complete this lesson. Independent evidence and delayed review determine the skill stage.
Next lesson · Choose the test that can actually prove the claim →