Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
In this step, you’ll work with GitHub Copilot to fix three intentionally failing unit tests in the debug-1 branch. Your goal is to have Copilot identify each failure, explain what went wrong, fix the underlying issue, and re-run the tests until everything passes. This exercise teaches you how to collaborate with Copilot in a clear, transparent debugging loop.
Your task is to use GitHub Copilot to identify and fix the failing unit tests in the debug-1 branch. Copilot should walk you through each failure one at a time, showing you what broke, why it broke, what code needs to change, and how the fix resolves the issue. Transparency is key: you should always understand what Copilot is doing and why.
What You Need to Know
The Debugging Loop
Copilot’s debugging workflow follows a predictable pattern:
Run the test suite
Observe which tests fail
Inspect the corresponding code
Apply a fix
Re-run the affected tests
Repeat until all tests pass
This loop mirrors real-world debugging and helps keep the process controlled, understandable, and predictable.
Copilot as an Autonomous Debugger
Copilot can run commands, read test output, explore your codebase, and apply fixes. More capable models tend to perform better at this process, while smaller models may require more guidance. Regardless of the model, the goal is to keep the workflow transparent and iterative.
Your Custom Fixing Prompt
This workshop includes a pre-built debugging prompt in:
.github/prompts/fix-tests.prompt.md
This prompt structures how Copilot works through failing tests, forcing it to:
Explain failures in plain English
Identify the buggy file and function
Describe the planned fix
Apply changes
Re-run tests in isolation
Move to the next failure one-by-one
This ensures a controlled and understandable debugging flow.
You are a senior developer tasked with fixing failing tests in a codebase. Your job is to run the unit tests for this project npm test, identify any failures, and fix them one by one.
It's important that everything you do is transparent so the user has an opportunity to see which tests failed, why they failed, and what the fix was. For each failing test you encounter, you will:
Point out the test that failed and code where the bug occurred (filename, function name, etc).
Provide a high level description of what went wrong using plain english, and in a way that's easy to understand.
Look through the broken code and try to identify where the failure occurred. Once you've found the bug, explain what the problem is and how you plan to fix it.
Fix the bug
Re-run the test in isolation. If it passes, move on to fix the next failing test. If it fails, repeat this process until it passes.
If there are multiple failing tests, fix them by following the above process ONE AT A TIME. Do not attempt to solve them all in parallel.
Sample Output (do this for each failing test one at a time):
1) Fail/Where it failed
Test file: string-utils.test.ts
Failing assertion: expected sanitizeInput("Hi!!") to return "Hi!" but received "Hi!!".
Observed failure message: "Expected: Hi! Received: Hi!!"
2) High-level description (plain English)
The test expects sanitizeInput to collapse repeated punctuation so user input like "Hi!!" becomes "Hi!" for consistency. The implementation was returning the original string unchanged, so duplicate punctuation wasn’t being reduced.
3) Root cause & plan
Where the bug is: string-utils.ts, function sanitizeInput.
What went wrong: the code simply returned the input string without removing repeated punctuation characters.
Why that fails tests: tests assert that all consecutive identical punctuation marks should be collapsed to a single character.
Planned fix: update sanitizeInput to replace sequences of repeated punctuation with a single instance.
4) The fix I applied
File changed: string-utils.ts
Before: return input;
After: return input.replace(/([!?.])\1+/g, "$1");
(I applied that edit to string-utils.ts.)
5) Re-run test and result
Command run: npx jest string-utils.test.ts -i --silent
Result: PASS — all 4 tests in string-utils.test.ts passed.
Output: "PASS string-utils.test.ts — Tests: 4 passed"
Current status and next steps
Status: The sanitizeInput failure is fixed and verified.
While running the initial full suite earlier, there were additional failures I observed (I will handle them one at a time next):
task-runner.test.ts — TypeScript error where a function expects a Config object but receives undefined. Needs investigation.
form-renderer.test.tsx — test couldn’t find the primary action button; likely a markup or mocking change.
✏️ Hands-On Exploration
In this section, you’ll work with Copilot to fix the bugs in the debug-1 branch. Follow the steps below to work through the failing tests with Copilot.
Checkout out the bug-1 branch in TaskFlow
Commit or reset any changes made by Copilot;
Commit git add . && git commit -m “changes“
Reset git reset --hard HEAD && git clean -fd
Check out the new branch
git switch bug-1
Run the unit tests and observe the failures
npm run test
Ask Copilot to run the tests and explain the failures
"Run the unit tests and explain any failures.”
Look over the bug fixing prompt .github/prompts/fix-tests.prompt.md
You are a senior developer tasked with fixing failing tests in a codebase. Your job is to run the unit tests for this project npm test, identify any failures, and fix them one by one.
It's important that everything you do is transparent so the user has an opportunity to see which tests failed, why they failed, and what the fix was. For each failing test you encounter, you will:
Point out the test that failed and code where the bug occurred (filename, function name, etc).
Provide a high level description of what went wrong using plain english, and in a way that's easy to understand.
Look through the broken code and try to identify where the failure occurred. Once you've found the bug, explain what the problem is and how you plan to fix it.
Fix the bug
Re-run the test in isolation. If it passes, move on to fix the next failing test. If it fails, repeat this process until it passes.
If there are multiple failing tests, fix them by following the above process ONE AT A TIME. Do not attempt to solve them all in parallel.
Sample Output (do this for each failing test one at a time):
1) Fail/Where it failed
Test file: string-utils.test.ts
Failing assertion: expected sanitizeInput("Hi!!") to return "Hi!" but received "Hi!!".
Observed failure message: "Expected: Hi! Received: Hi!!"
2) High-level description (plain English)
The test expects sanitizeInput to collapse repeated punctuation so user input like "Hi!!" becomes "Hi!" for consistency. The implementation was returning the original string unchanged, so duplicate punctuation wasn’t being reduced.
3) Root cause & plan
Where the bug is: string-utils.ts, function sanitizeInput.
What went wrong: the code simply returned the input string without removing repeated punctuation characters.
Why that fails tests: tests assert that all consecutive identical punctuation marks should be collapsed to a single character.
Planned fix: update sanitizeInput to replace sequences of repeated punctuation with a single instance.
4) The fix I applied
File changed: string-utils.ts
Before: return input;
After: return input.replace(/([!?.])\1+/g, "$1");
(I applied that edit to string-utils.ts.)
5) Re-run test and result
Command run: npx jest string-utils.test.ts -i --silent
Result: PASS — all 4 tests in string-utils.test.ts passed.
Output: "PASS string-utils.test.ts — Tests: 4 passed"
Current status and next steps
Status: The sanitizeInput failure is fixed and verified.
While running the initial full suite earlier, there were additional failures I observed (I will handle them one at a time next):
task-runner.test.ts — TypeScript error where a function expects a Config object but receives undefined. Needs investigation.
form-renderer.test.tsx — test couldn’t find the primary action button; likely a markup or mocking change.
Run the prompt
”/fix-tests"
Observe the output and how Copilot goes about fixing the bugs
Pro Tip: Use a more advanced model to get better results
Verify the tests are fixed
npm run test
Next Steps
With your unit tests now passing, you’re ready to move into more advanced debugging scenarios.
In the next step, you’ll investigate a bug that spans both the frontend and backend — requiring Copilot to work with multiple processes, logs, and environments at the same time.