Turn a bug report into precise reproduction cases with input, expected result and actual result.
Reproduce a defect with an automated test that fails for the reported reason.
Narrow the cause by varying one input at a time and predicting which cases fail before running them.
Fix the cause rather than the symptom, and show that the regression test fails without the fix.
Use an AI coding agent while debugging without letting it skip reproduction or patch the test instead.
Prerequisites
Reading and writing TypeScript, including async and await.
Writing a test with node:test and assert, or a comparable test framework.
Calling an HTTP API with curl and reading status codes and JSON error bodies.
Knowing that an ISO 8601 timestamp such as 2027-01-15T08:00:00+02:00 names an instant with an offset.
Concepts
Reproduce before you reason
Debugging goes wrong most often at the start, when someone reads a bug report, forms a theory and starts editing code. The theory may be right, but without a reproduction there is no way to know whether the edit fixed the problem, fixed a different one, or only moved it. The discipline is simple to state: make the failure happen on demand, in a test, before you look for the cause.
A bug report is not a reproduction. It mixes observations ("08:00–09:00 fails with OUTSIDE_OPENING_HOURS") with interpretations ("since the deploy") and workarounds that may themselves be wrong. Turn each observation into a case with three parts: the exact request, the result the documented rules say it should get, and the result it actually gets. Cases that work are as useful as cases that fail; the boundary between them is where the cause lives.
Make the test fail for the right reason
A test that fails proves only that something is wrong. Before trusting it as a reproduction, check that it fails the way the report describes. In this service many mistakes in a test produce a 400 of their own: a date that has already passed (STARTS_IN_PAST), a time off the resource's slot grid (INVALID_SLOT), or a malformed body (VALIDATION_FAILED). Assert the error code as well as the status. Write times with an explicit offset, such as 08:00:00+02:00, so the test states which instant you mean rather than relying on whatever the machine's time zone happens to be.
Narrow the cause
With a reliable failing case, change one thing at a time and watch the result: a different resource, a different time of day, a different date, a booking one slot shorter. Each variation splits the possibilities. Look for the pattern across all the cases, not only the first one: a single explanation should predict every failing case and every passing one. If one symptom is left unexplained, there may be a second cause.
Worked example
This walk-through debugs a different defect in a different part of the booking service: pricing. The defect is invented for the example and is not in your workspace, but the code it starts from is, so you can recreate it and follow along.
The ticket
SUP-2140: New projector charges the wrong amount. Operations added a projector resource at 1,000 cents per hour with 15-minute slots. A 90-minute booking was charged 1,530 cents; it should be 1,500. A 45-minute booking was charged 765. The meeting room, the focus booth and the build server lab all look right. Started after the agent change "simplify price calculation". Tests are green.
1. Turn the report into cases
Resource rate (cents per hour)
Duration
Expected
Reported
1,000
90 min
1,500
1,530
1,000
45 min
750
765
30,000 (meeting room)
any
correct
correct
12,000 (focus booth)
Concept questions
Sign in and enrol to answer and save your progress.
Exercise
The situation
Your workspace holds the booking service described in README.md, as it was after last Thursday's deploy. That deploy included a coding agent's cleanup of the booking validation. The tests were green. Since then support has received the ticket in docs/bug-report.md: customers in Johannesburg and New York are being turned away from slots that should be free, and some bookings go through that should not.
Your job is to reproduce the problem with a failing test, find its cause, fix it, and keep the test so the defect cannot come back unnoticed.
The workspace's git history starts with the code as you received it, so there is no earlier version to compare with. Use the booking rules in README.md and the comments in the code as the statement of intended behaviour.
Steps
Read the ticket and write down the cases. For each symptom in docs/bug-report.md, note the resource, the local times, the result the README's rules say it should get, and the result reported. Include the cases the ticket says still work.
Reproduce with a failing test. Create a test file under test/, for example test/opening-hours.test.ts, using the helpers in test/helpers.ts (useTestApp, , , , , ). Book through as does. A few practical points:
Reflection
Recorded for you to look back on. It is not graded and does not by itself show understanding.
Prompt: How did you reproduce the problem, and how did you confirm the cause rather than only a symptom? Describe the first failing test you wrote, any hypothesis you had to abandon along the way, and how you checked that your fix accounts for every symptom in the support ticket.
Two further sources of evidence are cheap. The documentation states intended behaviour; README.md lists the booking rules, and a comment above a function often says what it was meant to do. Version history shows what changed: comparing the current code with the last version known to be good, with git diff or git bisect across several commits, often points straight at the lines involved.
You have found the cause when you can predict, before running them, which new inputs will fail and which will pass, and the predictions hold.
Fix the cause, then prove it
A fix that special-cases the reported example (a particular resource, time or date) makes the test pass and leaves the defect in place for every other input. Fix the rule itself, then verify in four steps:
The regression test passes.
With the fix temporarily undone, the regression test fails again with the reported symptom. This proves the test detects the defect.
The neighbouring cases behave: just inside and just outside each boundary.
The full suite passes: npm run verify.
Keep the regression test, named for the behaviour it protects rather than the ticket number, so the next person who "simplifies" this code finds out immediately.
What agent-generated defects look like
Defects introduced by coding agents tend to share a shape. They arrive in a change described as harmless: "simplify", "clean up", "remove duplication", "avoid repeated work". The new code is shorter and reads well, so a reviewer skimming the diff sees an improvement. The mistake sits in an assumption the old code handled and the new code dropped: what a value means, which side of a boundary is inclusive, which context a calculation runs in. And the tests stay green, either because the behaviour that changed was never tested, or because a test that would have caught it was modified or removed in the same change. When a defect follows an agent's refactoring, look at what happened to the tests in that change as well as to the code.
None of this is unique to agents; people make the same mistakes. Agents simply make them faster, with confident commit messages, and in larger diffs.
Working with an agent while debugging
Agents are useful for reproduction and search, and risky when they jump straight to a fix. Common failure modes are proposing a patch before any reproduction exists, making the reported example pass with a special case, rewriting the whole area so the cause is never identified, and "fixing" a failing test by changing its expectation.
Keep the agent in the order that works:
"Write a failing test for the first symptom in docs/bug-report.md. Do not change anything in src/."
"Explain why this test fails, citing the lines responsible. Predict two other inputs that will fail and two that will pass."
Run those predictions yourself. Only when they hold, ask for the smallest fix of the cause.
"Undo the fix temporarily and show me the regression test failing."
The agent that wrote the defect is a poor reviewer of its own reasoning. A fresh session, given only the bug report and the code, is more likely to question the assumption that went wrong.
any
correct
correct
6,000 (build server lab)
any
correct
correct
The expected values come from the documented rule in README.md: "Price is the hourly rate pro rata, in cents." 1,000 × 90 / 60 = 1,500.
2. Reproduce with a failing test
priceCents in src/rules.ts is a pure function, so the fastest reproduction is a unit test that needs no database or HTTP. A new file, test/pricing.test.ts:
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { priceCents, type Resource } from "../src/rules.ts";
// A resource whose hourly rate is not a whole number of cents per minute (1,000 / 60 = 16.67).
const projector: Resource = {
id: 99,
name: "Projector",
timezone: "UTC",
open_minute: 0,
close_minute: 1440,
slot_minutes: 15,
price_cents_per_hour: 1000,
};
const at = (time: string) => new Date(`2027-03-01T${time}:00Z`);
describe("priceCents", () => {
it("prices 90 minutes at 1,000 cents per hour as 1,500 cents", () => {
assert.equal(priceCents(projector, at("09:00"), at("10:30")), 1500);
});
it("prices 45 minutes at 1,000 cents per hour as 750 cents", () => {
assert.equal(priceCents(projector, at("09:00"), at("09:45")), 750);
});
});
node --test test/pricing.test.ts runs just this file. Against the defective code both tests fail, and the output matches the ticket exactly:
✖ prices 90 minutes at 1,000 cents per hour as 1,500 cents
actual: 1530,
expected: 1500,
✖ prices 45 minutes at 1,000 cents per hour as 750 cents
actual: 765,
expected: 750,
Matching numbers matter: they show the test reproduces the reported failure, not some other problem.
3. Narrow the cause
The seeded rates all work. What do 30,000, 12,000 and 6,000 have in common that 1,000 does not? Each is divisible by 60: 500, 200 and 100 cents per minute. That suggests a hypothesis: the new code works per minute, and something goes wrong when the per-minute rate is not a whole number.
The hypothesis makes predictions that can be checked before reading the code:
1,200 cents per hour (20 per minute) should be priced correctly.
1,000 cents per hour should be off by about 0.33 cents per minute: 30 cents over 90 minutes, 15 over 45. Both match the ticket.
The error should grow with duration, up to 0.5 cents per minute: as much as 360 cents on a 12-hour booking.
A quick extra test with 1,200 cents per hour passes. The predictions hold.
4. Find it in the code
Now the code is read with a specific question: where is the per-minute rate rounded? The agent's version of priceCents:
It rounds 16.67 to 17 cents per minute and then multiplies, so the rounding error is multiplied by the duration. The original rounded once, at the end:
The agent's version reads as tidier, and every existing test used a rate divisible by 60, which is why the suite stayed green.
5. Fix the cause and prove it
Restoring the round-once calculation fixes every rate, not just 1,000. A special case such as if (resource.price_cents_per_hour === 1000) would have passed the new tests and left every other awkward rate wrong.
Verification:
node --test test/pricing.test.ts passes.
Putting the defective line back makes both tests fail again with 1,530 and 765, so the tests detect this defect.
The 1,200 cents per hour case and a 12-hour booking both price correctly.
npm run verify passes.
The new tests stay in test/pricing.test.ts, named for the behaviour they protect.
6. Where an agent helps, and where it does not
An agent given this ticket and asked to "fix it" might well have found the line quickly. The useful prompts, though, were the ones that kept the order: "write a failing test for the 90-minute case without changing src/", then "which rates will this affect, and why?". The second question is the one that confirms the cause, because its answer can be checked.
In the exercise you face a different defect in the booking rules, with a different cause. The method is the same.
auth
ADA
JOHANNESBURG_ROOM
NEW_YORK_BOOTH
LAB
app().inject()
test/bookings.test.ts
Write instants with an explicit offset so the test says exactly which local time it means: Johannesburg is UTC+02:00 all year; New York is UTC−05:00 in January and UTC−04:00 in July.
Bookings must start in the future. To test a particular season, compute the next suitable date:
/** The next given day of a month, at least two days ahead, as YYYY-MM-DD. */
function nextDate(month: number, day = 15): string {
const now = new Date();
let year = now.getUTCFullYear();
if (Date.UTC(year, month - 1, day) < now.getTime() + 2 * 86_400_000) year += 1;
return `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
}
// 07:00 in New York in winter:
const start = `${nextDate(1)}T07:00:00-05:00`;
Assert the error code as well as the status, and check that the test fails with the error the ticket reports.
Run it with npm test, or just your file with node --test test/opening-hours.test.ts.
Find the cause. Vary one thing at a time until you can explain every symptom in the ticket, including the ones that look unrelated, and can predict which new inputs fail before you run them.
Fix the cause in src/. Do not special-case resources, times or dates.
Verify. Your regression test passes; with the fix temporarily undone it fails again; npm run verify passes. Then check by hand:
Replace the date with one in the future if this one has passed. Try the other cases from the ticket the same way: resource 2 is the Hudson focus booth and resource 3 the Build server lab.
Constraints
Do not change package.json or package-lock.json, and do not add dependencies. The assessment runs your code with the project's original dependencies and does not start a submission whose lockfile differs.
Do not edit db/migrations/001_init.sql or any other applied migration; start-up fails if one changes.
Keep every existing endpoint and response working as documented. Keep the service startable with node src/server.ts, keep GET /health, and keep reading DATABASE_URL and PORT.
Keep your regression test in the workspace after the fix.
What Check work assesses
Check work takes a snapshot of your workspace's source files and assesses it outside the lab. For AC1 to AC3, the platform starts your service with node src/server.ts against its own fresh database and its own data, then makes bookings over HTTP: at opening time and at closing time, and just before opening and just after closing, for Johannesburg and New York, on a winter and a summer date. Only the responses count, so printing PASS or editing tests does not change the result.
AC4 is a structural check: it looks for a file under test/ that is new or changed compared with the starting point and is about opening or closing hours. It confirms the test is there; it does not run it or judge whether it is correct. Making it a good test is up to you.
Not assessed: your code style, the quality of your test, and how you found the cause. Your reflection is recorded but not graded.
Tools
You can do this exercise with Claude Code, OpenCode or OpenHands in the lab. If you use an agent, ask it for a failing test first and an explanation second, and do not let it change the test's expectation to make it pass.
Acceptance criteria
AC1Opening time is applied in the resource's time zone, in winter and in summerVerified behaviour
AC2A booking may end exactly at closing timeVerified behaviour
AC3Bookings outside opening hours are still refused with 400 OUTSIDE_OPENING_HOURSVerified behaviour
AC4A regression test for the defect was added under test/Structure check
Verified behaviour is checked by running your submitted work from outside the lab. A structure check confirms that something is present and in the expected format; it does not prove it is correct.
Not assessed
Whether your regression test is correct or passes: the check confirms a relevant test file is there but does not run it.
The readability, structure and style of your fix.
How you found the cause, and whether you used an agent to do it.
Your reflection: it is recorded, not graded.
Hints
Try the exercise first. Each hint gives away a little more than the one before.
Check your work
Submit your work from the lab's Check work panel. Hidden checks run your submitted code from outside the lab; your own test output is never taken as a result. You can revise and resubmit.