Week 11 Lab — Debug an AI-Generated Codebase
CSIC30216 · Fall 2026
Goal
You are given TeamBoard, a small task tracker for student project teams, about 150 lines of Python. An AI wrote it. It contains five intentional bugs. The test file catches four of them. The fifth has no test: you will have to find it and write the test yourself. You will debug the same code twice:
- Part 1 (20 min), chat window: you use Claude in your web browser (claude.ai), the way most people use an AI chat: you paste code and error text, read the answer, and apply every change by hand. The model sees only what you paste.
- Part 2 (15 min), Claude Code: you start again from the original, unfixed code and let Claude Code read files, run tests and edit code, while you supervise.
- Part 3 (10 min): you take one problem of your own through the whole testing loop: a failing test, a fix, green, the whole suite, and a check that your test would catch a bad fix.
- Part 4 (10 min): you answer three comparison questions.
In every part you use the same testing loop (below), and you record it in a small table.
What You Submit (read this first)
| Who | Individual. Each student submits their own file |
| What | One PDF document with the contents listed below |
| Where | E3, under “Week 11 Lab” |
| When | By the end of Wednesday, November 18 (23:59) |
| File name | Week11_Lab_<your student ID>.pdf |
| Grading | Graded on completion (1%), like the earlier labs. We encourage you to be specific, because the detail is what makes the lab useful to you |
Your PDF should contain, in this order:
- Header: your name, student ID, team number, the chat tool and model used in Part 1, the Claude Code model shown in
/status - Bug report: one row for each of the five bugs (attempted is enough; fixed is better). Template in
week11_lab_submission_template.md, available with the required lab files on E3. Include your loop tables: one row per fix, for Part 1 and for Part 2 (see “The testing loop”) - Chat log, Part 1: at least three exchanges that mattered (your prompt and the key part of the answer, copied from the chat), each with your note: what you asked, whether the answer was right, and how you checked. At least one entry must show a diagnosis you checked before applying a fix (see Part 1)
- Claude Code notes: a short list of what Claude Code did, in order, and which of its requests you approved, changed or declined
- Your own loop (Part 3): the test, the red output, your fix, the green output, the whole-suite result, and the result of undoing the fix; plus one line on whether the problem was a bug or a decision
- Three comparison questions (Part 4), answered in writing
Do not include passwords, keys, or screenshots that show them.
Time Plan
| Part | What | Minutes |
|---|---|---|
| Setup | install Claude Code if you have not yet, check all requirements, copy the code, run the tests | 5 |
| Part 1 | debugging in a chat window | 20 |
| Part 2 | the original code again, with Claude Code | 15 |
| Part 3 | one problem of your own, through the whole loop | 10 |
| Part 4 | three comparison questions | 10 |
That is 60 minutes. Use a timer. When Part 1 ends, stop and move on, even if you did not fix all five.
Before Class
Download the student package from the
required lab files on E3.
Complete week11_claude_code_setup.md, then run python week11_setup_check.py.
If Claude Code does not work, tell a TA before Monday.
Setup (5 minutes)
If you have not installed Claude Code yet, do it now with
week11_claude_code_setup.md (doing it before class is safer: if the installer has a
problem, 5 minutes is not enough to fix it). Then run
python week11_setup_check.py and fix anything marked PROBLEM, or tell a TA.
The student package (from the
required lab files on E3) has
a folder teamboard/. Do not edit it. Make two copies, so each part
starts from the original code:
macOS / Linux / WSL:
cp -r teamboard teamboard_chat
cp -r teamboard teamboard_cc
Windows PowerShell:
Copy-Item -Recurse teamboard teamboard_chat
Copy-Item -Recurse teamboard teamboard_cc
Now look at the failing tests, in the chat copy:
cd teamboard_chat
python -m unittest
You should see 4 problems out of 10 tests (2 failures, 2 errors). Remember there
are five bugs: one has no test. You may also run the demo with
python -m teamboard.cli. Do not read the code closely yet. Write
down your first impression of what you think the five bugs might be, in one line each. This is
your “before” guess.
The Testing Loop (use it in every part)
1. Red a test that fails because of the bug (a given one, or one you write)
2. Fix the smallest change
3. Green that test now passes
4. Suite run ALL the tests: did anything else break?
5. Keep the test stays in the suite, so the bug cannot come back unnoticed
Record it. For every fix, add one row to your loop table (in the template):
| Bug | Test that shows it (given, or mine) | Red before the fix? | Fix (one line) | Whole suite after (passing / total) | Anything else break? |
|---|---|---|---|---|---|
It takes seconds per row. It is the evidence that you ran the loop and did not just fix things.
db.py. To find it, ask for a security review of that file. Then,
before you fix it, write a test that fails because of it (red), and only then
fix it (green). This is the “no trace? write a test first” habit from the lecture.
Part 1 — Debugging in a Chat Window (20 minutes)
This is debugging the way most people do it with AI: in a chat window, copying text back and forth. (The course outline calls this the “raw API” approach: the model gets only the text you send it, and nothing else.)
How You Work in This Part
- Open claude.ai in your browser, signed in with the same account you use for Claude Code, and start a new chat.
- Paste text only. Do not upload or attach files, and if the chat offers to run code for you, do not use it. You are testing what the model can do with only what you choose to paste. It cannot open your files, run your tests or change your code.
- You apply every fix by hand, in
teamboard_chat, and you run the tests yourself in your terminal. - Do not open Claude Code in this part.
-
Keep a log as you go. Open a text file
chat_log.mdand, for each exchange that matters, copy in your prompt (or a short summary of what you pasted), the key part of the answer, and a short note: what you asked, whether the answer was right, how you checked.
A Way to Work
- Run the tests. Pick one failing test.
- Build a prompt with: the failing test, the full error text (the traceback, or the assertion message), the function it points to, and one sentence about what the code should do.
- Ask for a diagnosis before a fix: “What is wrong, and why? Do not write code yet.” You can also ask: “Give me three possible causes, and how I could check each one.”
-
Get a check before you get a fix. Ask:
Then:“Before any fix: give me one command or a short test that would show your diagnosis is wrong if it were wrong. Tell me exactly what output you expect if you are right.”
- Judge the check. Would it come out differently if the diagnosis were wrong? A check that does not touch the code (for example
print(3 < 3)) proves nothing. If it would pass either way, ask for a better one. - Run it yourself, in your terminal, from the project folder.
- Compare the predicted output with what you got. If they differ, the diagnosis is in doubt: tell the model what you saw.
- Judge the check. Would it come out differently if the diagnosis were wrong? A check that does not touch the code (for example
- If the check confirmed the diagnosis, ask for the smallest fix. Apply it yourself. Run the tests.
- Repeat. If the tests are green but you do not understand why, that is not finished.
Two Other Ways to Check (optional; try one if you have time)
- Failing test first: “Write a test that fails now because of this bug and will pass once it is fixed.” Run it and see it fail (red) before the fix, and pass (green) after. This works well for bugs that do not crash.
- Second opinion: open a fresh chat, paste the same evidence (test, error, function) without the first answer, and see whether it reaches the same diagnosis. Quick, but weaker: both answers come from the same kind of model and can be wrong in the same way. Use it alongside a check, not instead of one.
Things to Think About While You Work (write answers in your notes)
- Three of the five problems do not crash the program: the test just reports a wrong answer or a slow run. How do you tell the model about a bug that has no stack trace?
- One bug has no test (see the hint above). Paste
db.pyand ask for a security review. When you know the problem, ask: “Write a unittest test, in the style of the tests I pasted, that fails because of this problem.” Run it and see it fail before you fix anything. Would you have found this bug without the hint? - If the model suggests changing a test to make it pass, stop and think about whether the code or the test is wrong.
At minute 20, stop. Run the tests one last time and write down: bugs attempted / bugs fixed / tests passing (out of 10, plus any you added). Check that your loop table has a row for each fix.
Part 2 — Claude Code (15 minutes)
Start again from the original code. Use the second copy. In your terminal (if
you set ANTHROPIC_API_KEY for an earlier lab, unset it first; see the setup guide):
cd teamboard_cc
git init
git add .
git commit -m "original unfixed code"
claude
(If git asks who you are, run git config user.name "your name" and
git config user.email "you@example.com", then repeat the commit.)
The git commit matters: it lets you see exactly what Claude Code changed
(git diff), and undo it if you want to (git checkout .).
How You Work in This Part
- You do not paste the code. Claude Code can read the files itself and can run
python -m unittest. - Read every permission request before you approve it (editing a file, running a command). Do not choose any option that skips the questions. If a request surprises you, decline it and ask why.
- Do not reuse your Part 1 answers. Ask Claude Code from scratch, as if you had not seen the bugs.
- Keep notes as you go: what you asked, what it did, what you approved or declined.
A Way to Work
- Ask:
Run the tests and tell me what is failing. Do not change anything yet. -
Ask it for a diagnosis of each failure and read it. Do you agree?
Then ask, as in Part 1:
Before changing anything, show me a check that would prove your diagnosis wrong if it were wrong, and run it.Read the check before you approve running it, and compare its output with what it predicted. -
Ask it to work test-first:
For each bug: show me a failing test first (write one if no test catches it), then fix it, then run the whole test suite. Stop after each bug so I can check.Read the diff for each change; after each one, rungit diffand look at what actually changed. Fill in a loop-table row for each fix, as in Part 1. - Ask it to find problems the tests do not show:
Review the code for problems the tests do not cover.Compare its list with your five bugs. - When it says it is done, run the tests yourself and read the final
git diff.
Look for These (write down any you see)
- Did it change a test, or only the code?
- Did it change anything unrelated to the five bugs?
- Did it explain what it did, or just do it?
- Did it find something you did not?
- Did it write a test for the bug that has none, before fixing it?
- Did it run the whole suite after each fix, or only the one test?
At minute 15, stop. Write down: bugs fixed / tests passing / number of changes you declined or edited.
Part 3 — One Problem of Your Own, Through the Whole Loop (10 minutes)
Real bugs usually do not come with a test. In this part you find one, write its test, and take it all the way round the loop.
- Work in
teamboard_cc(it has git). First save Part 2's work:git add .thengit commit -m "Part 2 fixes". - Find a problem that no test covers (not the 10 given tests, and not the one you wrote for the security bug). Look at the code with the four lenses from the lecture, or try odd inputs in the Python shell. Some places to look: what happens with a due date that is not a valid date; whether names match regardless of capital letters or spaces; empty titles; an assignee that is only spaces. You may ask an AI tool for ideas, but you decide which one to test.
- Decide what the right behaviour is. Write one line: is this a bug (the code breaks its own docstring), or a decision (the docstring does not say, so you are choosing)? If it is a decision, say what you chose.
-
Red. Write one test for that behaviour in
tests/test_teamboard.py(copy the style of the existing tests). Run it. It must fail. If it passes, the problem is not real or the test does not check it: change the test or pick another problem. Then commit the test:git add .andgit commit -m "Add failing test". - Fix. Make the smallest change that should make it pass (with the chat, with Claude Code, or by hand).
- Green. Run your test: it passes.
- Suite. Run all the tests:
python -m unittest. Everything passes? If something else broke, that is a finding: write it down, then fix it. - Would your test catch a bad fix? Undo the fix for a moment with
git stash, run your test (it should be red again), then bring the fix back withgit stash pop. (Without git: put the old line back by hand, run, and restore it.)
Paste into your PDF: the test, the red output, your fix (the diff), the green output, the whole-suite result, and the result of step 8.
Part 4 — Three Comparison Questions (10 minutes)
Answer in your own words, 4 to 8 sentences each. Refer to specific moments from your two parts. “It was faster” is not an answer unless you say what was faster and by how much.
- What did Claude Code do that the chat window could not?
- Where did Claude Code make a decision you should have made yourself? (If it made none, say what it did that came closest, and why you were comfortable with it.)
- What context did Claude Code have automatically that you had to provide by hand in the chat window? And what context did you have that Claude Code did not?
- Pick the one bug you are least sure the AI fixed correctly, and write one more test that would catch a wrong fix.
-
Let tools check first. In a fresh copy of the original code,
run
pip install mypy ruff, thenruff check --select S teamboardandmypy --check-untyped-defs teamboard. Which of the five bugs does each tool find? Which does neither find? Then runmypy teamboardwithout the option and compare.
Submission Checklist
- Header: name, student ID, team number, Part 1 chat tool and model, Claude Code model
- Bug report with one row for each of the five bugs (attempted is enough), including the bug that had no test
- Loop tables for Part 1 and Part 2, one row per fix
- At least three chat log entries from Part 1, each with your note, including at least one marked CHECKED DIAGNOSIS
- Your Claude Code notes, including at least one thing you declined, edited or questioned (or a sentence saying you approved everything and why)
- Part 3: your test, red output, fix, green output, whole-suite result, the undo check, and “bug or decision”
- Answers to the three comparison questions
- No passwords or keys anywhere
- Saved as one PDF named
Week11_Lab_<student ID>.pdf
If Things Go Wrong
| Problem | What to do |
|---|---|
python -m unittest says no tests were found, or No module named 'teamboard' | You are not in the project folder. cd into teamboard_chat (or teamboard_cc), the folder that contains the teamboard and tests folders |
| The chat says you have reached a usage limit | Tell a TA and write down when it happened. You can continue Part 1 by reading the code and the test output yourself |
| The chat's answer stops in the middle | Ask it to continue, or ask about one function at a time |
| The model's code does not run, or mixes up the files | You probably pasted too little context. Paste the whole file the error points to, and say which function is wrong |
| The model keeps suggesting the same fix | Tell it what happened when you applied the fix (paste the new output). Do not just say “that did not work” |
| Claude Code asks you to log in | Sign in with the account in the setup guide. If it asks about using an API key, choose not to |
| Claude Code is slow, or says a usage limit was reached | Tell a TA. Write down what happened; it is part of the comparison |
| Claude Code made a mess | git checkout . in teamboard_cc returns the files to the original commit. Say in your notes what you restored |
| Claude Code will not install on your computer | Tell a TA. You can still do Part 1; ask a neighbour if you can watch their Part 2 and write your answers from what you saw, saying so |
Connection to the Course
- Week 7: you gave a model tools and saw it route calls. Claude Code is that idea with a large set of tools (read, edit, run) around a model, and a loop that keeps going until it decides it is done
- Week 10: a test suite is how you judge a prompt. Here the tests are a program that runs the code, and you see how an AI uses them (and whether it tries to change them)
- Today's lecture: specify before generating, the four lenses for evaluating AI code, debugging like a scientist (Part 1's checked diagnosis), “no trace? write a test first” (Part 3), and letting tools check first (the optional extension)
- Your project: merge day and CP2 are this week and next. The habits you practise here (read the diff, run the tests yourself, write down why) are what the collaboration evidence asks for
- Week 12: you will review another team's code. Use the four lenses from today