Session 02 Lab — Copilot Chat & Inline Suggestions¶
Duration: 2 hours
Difficulty: Beginner
Prerequisites: Session 01 completed (Copilot installed and configured)
Deliverable: A debugged and tested module, plus documented model comparison observations
Lab Overview¶
Use Copilot Chat to explain unfamiliar code, debug broken functions, generate tests, explore workspace-aware features, and compare approved model options.
| Exercise | Topic | Time |
|---|---|---|
| 1 | Code Explanation & Debugging | 40 min |
| 2 | Test Generation | 30 min |
| 3 | Workspace & Terminal Chat | 30 min |
| 4 | Model Comparison | 20 min |
Before you start¶
Read the course safety baseline. Confirm that Copilot Chat and model selection are available in your IDE.
If access is unavailable¶
Complete the debugging, testing, and context exercises against the supplied files. Record the prompt you would have used and peer-review the proposed change.
Exercise 1: Code Explanation & Debugging (40 min)¶
Objective¶
Use Copilot Chat to inspect unfamiliar code, then debug three deliberately broken functions.
Part A: Code Explanation (15 min)¶
-
Open
lab/starter/mystery-code.pyin VS Code. This file contains working but complex code that may be unfamiliar to you. -
Select all the code in the file (
Ctrl+A/Cmd+A). -
Open Copilot Chat using one of these methods:
- Click the Copilot Chat icon in the sidebar
- Press
Ctrl+Alt+I/Cmd+Alt+I -
Use inline chat:
Ctrl+I/Cmd+I -
Ask Copilot to explain the code. Type in the Chat panel:
Expected: A detailed explanation of each function, the data structures used, and the overall purpose of the module.
- Ask follow-up questions to understand the code better:
What algorithm is the find_shortest_path function using?What is the time complexity of each function?-
Are there any edge cases this code doesn't handle? -
Try inline chat for a single function. Select just the
memoizefunction, pressCtrl+I, and type:
Checkpoint: You should now understand what each function does. Write a one-sentence summary of the module's purpose in your own words.
Part B: Debugging (25 min)¶
-
Open
lab/starter/buggy-functions.py. This file has 3 functions with intentional bugs. -
Try to run the file first to see the errors:
Expected: Errors or incorrect output for one or more functions.
- Debug each function using Copilot Chat. For each broken function:
Method 1: /fix command
- Select the function
- Type /fix in Chat
- Review the suggested fix
Method 2: Conversational debugging
- Paste the error message into Chat
- Ask: This function is supposed to [expected behavior], but it's [actual behavior]. What's wrong?
Method 3: Inline fix
- Select the broken function
- Press Ctrl+I and type: Fix the bug in this function
-
Fix all 3 bugs. The bugs are:
binary_search: Logic error — returns wrong resultremove_duplicates: Mutation error — modifies data unexpectedlyparse_csv_line: Edge case — fails with quoted commas
-
Verify your fixes:
Expected output:
-
Compare with
lab/solution/buggy-functions.pyto see the reference fixes.
Troubleshooting¶
| Problem | Solution |
|---|---|
| Chat doesn't see my code | Make sure the file is open and active. Use #file:buggy-functions.py to reference it explicitly. |
| /fix doesn't work | Select the function first, then type /fix. The selection provides context. |
| Chat gives a wrong fix | Give more context: describe the expected vs. actual behavior. Paste the error message. |
Exercise 2: Test Generation (30 min)¶
Objective¶
Use Copilot Chat to draft unit tests for an existing module, then review and improve them.
Steps¶
-
Open
lab/starter/calculator.pyin VS Code. This is a fully working calculator module with no tests. -
Generate tests using the /tests command. Select the entire file, then in Chat:
Expected: Copilot generating a test file with multiple test functions covering the calculator's operations.
-
Save the generated tests. Create a new file called
starter/test_calculator.pyand paste the generated tests. -
Review the generated tests. Check:
- Are edge cases covered (division by zero, empty history)?
- Are there both positive and negative test cases?
- Do the test names clearly describe what they test?
-
Is there a test for the
historyfeature? -
Ask Chat to add missing tests. If you see gaps:
These tests are missing coverage for:
- Division by zero
- The history() method
- Chaining operations
Add those test cases.
- Run the tests (if pytest is installed):
Expected: All tests passing with verbose output showing each test name.
- Compare with
lab/solution/test_calculator.pyto see the reference test suite.
Troubleshooting¶
| Problem | Solution |
|---|---|
| pytest not installed | Run pip install pytest first. Or use python -m pytest. |
| Tests import fails | Make sure test_calculator.py is in the same directory as calculator.py. |
| Generated tests are wrong | Fix them and record what Chat missed. Trainers need to see those limits. |
Exercise 3: Workspace & Terminal Chat (30 min)¶
Objective¶
Use @workspace to answer questions about a multi-file project, and @terminal to troubleshoot a failing build.
Part A: @workspace (15 min)¶
-
Open the mini-project folder. In VS Code, open the folder
lab/starter/mini-project/(or open the files within it). -
Ask @workspace about the project. In Copilot Chat, try these queries:
Expected: Chat analyzing all files in the project and describing the Express.js server, its routes, and overall structure.
- Ask specific questions:
- Notice how @workspace differs from regular Chat. Without
@workspace, Chat sees the active file. With it, Chat searches the project.
Checkpoint: You should be able to describe what the mini-project does, its routes, and dependencies without reading every file manually.
Part B: @terminal (15 min)¶
- Try to start the mini-project. Open a terminal and run:
Expected: An error. The project has an intentional build issue.
- Use @terminal to diagnose. In Copilot Chat:
Expected: Chat reading the terminal output and identifying the issue.
-
Apply the fix suggested by Chat. Then try
npm startagain. -
Test the running server (if the fix works):
Expected output:
{"status":"ok","timestamp":"..."}
- Compare with
lab/solution/mini-project/to see the fixed version.
Troubleshooting¶
| Problem | Solution |
|---|---|
| @workspace doesn't find files | Make sure the mini-project files are inside your VS Code workspace (not just a single file open). |
| @terminal not available | Ensure you have a terminal open with recent output. @terminal reads from the active terminal. |
| Node.js not installed | Install Node.js from https://nodejs.org/. Or focus on Part A only. |
Exercise 4: Model Comparison (20 min)¶
Objective¶
Where customer policy permits a comparison choice, compare responses to the same synthetic question; otherwise compare an assisted response with a manual solution.
Steps¶
-
Open
lab/starter/model-comparison-template.mdto record your observations. -
Check the customer-approved options. Ask the customer administrator which comparison choices, if any, are approved for this exercise. Use current official documentation and customer policy rather than assuming a catalog.
-
Ask a coding question with Model A. Use this prompt:
Write a Python function that finds the longest common subsequence of two strings. Include comments explaining the approach.
Copy the response into the template under "Model A".
-
Use a second approved comparison choice. If none is approved or shown, use a manual implementation as the comparison baseline.
-
Ask the exact same question with Model B. Copy the response into the template under "Model B".
-
Compare the responses. Fill in the comparison table in the template:
- Which was more concise?
- Which had better comments/explanations?
- Which code is more readable?
-
Did they use different algorithms?
-
Try a non-coding question. Ask both models:
Note differences in explanation style.
- Document your recommendation. In the template, write which model you'd recommend for different tasks.
By the end: A filled-in template comparing two models across multiple dimensions, with a recommendation for which to use when.
Troubleshooting¶
| Problem | Solution |
|---|---|
| No comparison choice is shown | Do not infer why. Use the manual baseline and record that the customer policy did not authorize a second comparison. |
| Can't find the model selector | Look for a dropdown near the chat input. In some versions it's a settings icon. |
| Responses look identical | Try a more specific question: ask for architecture advice or code review feedback. |
Wrap-up¶
Deliverables Checklist¶
-
mystery-code.py— Explained (notes in Chat or journal) -
buggy-functions.py— All 3 bugs fixed and verified -
test_calculator.py— Generated test suite (saved and reviewed) -
mini-project/— Build issue diagnosed and fixed -
model-comparison-template.md— Completed model comparison
Trainer notes¶
- Chat helps with debugging. Use
/fixor a focused question, then verify the result. - Use
@workspacefor unfamiliar codebases. It is useful for cross-file questions and onboarding. - Review generated tests. They are a draft, not proof of coverage.
- Compare approved model options. Record the differences you can observe.
- Give Chat relevant context. A selected function, error message, or workspace search can improve the answer.
Next session¶
In Session 03, you will practice prompts that state the task, context, and constraints clearly.