Key idea
A test proves something only if it could have failed. Write it before the fix, run it, and watch it fail for the reason you expect. Then fix the code and watch the same test pass. A test you've never seen fail might not be checking anything.
Module 1 asked whether a task due today counts as overdue. In the starter it does, and that's a bug. None of the tests look at overdue dates, so they all pass: exactly the gap an agent's "all tests pass" can hide.
Fail first, then fix
true !== false: the bug, for the reason you expect
<= becomes <, nothing else
The same test, unchanged
Commit it with the fix. It fails again if the bug comes back.
Find the rule
Open lib/dates.js. The last line of isOverdue decides:
return startOfDay(task.due + "T00:00:00Z") <= startOfDay(now);
Both sides are the start of a day. When the due day is today, they're equal, and <= says overdue. The rule should be "due before today".
Don't fix it yet.
Write the test first
Open test/dates.test.js. Add isOverdue to the require line at the top, so it reads const { isValidDueDate, daysUntil, isOverdue } = require("../lib/dates");. Then add two tests at the end:
test("a task due today is not overdue", () => {
const now = new Date("2026-10-01T15:30:00Z");
assert.equal(isOverdue({ due: "2026-10-01", done: false }, now), false);
});
test("a task due yesterday is overdue", () => {
const now = new Date("2026-10-01T15:30:00Z");
assert.equal(isOverdue({ due: "2026-09-30", done: false }, now), true);
});
Each test fixes now to one moment, so it gives the same answer on any day you run it. The second test guards the other side of the line, so a "fix" that never marks anything overdue can't pass.
Watch it fail
npm test
✖ a task due today is not overdue
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
true !== false
Read the failure before moving on. It says the function returned true where you expected false: exactly the bug, and not a typo in the test. A test that fails for a different reason, such as a missing import, proves nothing yet.
Fix it and watch it pass
Change <= to < in isOverdue, run npm test again, and all nine tests pass. Commit the test and the fix together, so the history shows the proof next to the change:
git commit -am "fix: a task due today is not overdue"
Why a fixed 'now' instead of the real clock?
A test that uses today's date passes or fails depending on when it runs, and tests near midnight or across time zones flip without any code changing. That's a flaky test, and people learn to ignore flaky tests. isOverdue takes now as an argument for exactly this reason. When your own code reads the clock deep inside, ask your agent to make the time an argument first, as a separate small change.
Ask for the failing test, not the fix
When you hand a bug to an agent, ask for the test first: "Write a test that fails because a task due today counts as overdue. Run it and show me the failure. Don't change lib/dates.js yet." You check one small thing, the failure message, before any fix exists to distract you.
Check yourself