Session M2-04 lab: Code review workflows¶
Duration: 2 hours
Deliverable: A completed fix-evaluation-template.md, a corrected project with passing tests, and a resolved conflict
Lab overview¶
Review a deliberately flawed change. Support each comment with a code reference or test result, apply targeted fixes, and decide whether to accept the change. Compare your own review with Copilot-assisted review. Use only synthetic data.
| Exercise | Topic | Time |
|---|---|---|
| 1 | Human, code, and security review of one diff | 40 min |
| 2 | Validate and correct the starter project | 35 min |
| 3 | Resolve a conflict and check the result | 25 min |
| 4 | Review the results and make a final decision | 20 min |
You need¶
- the standalone Copilot CLI with
/reviewand/security-review(check/help); - Copilot pull-request review;
- an empty private GitHub repository you can push to (create one with
gh repo create --private, or use the one the trainer gives you); - Git, the authenticated GitHub CLI (
gh auth status), Node.js, and npm.
What the review commands do¶
/review and /security-review |
Copilot PR review | |
|---|---|---|
| Where | In your Copilot CLI session, in your working repository | On GitHub, on the pull request |
| What it examines | Your staged and unstaged changes, before you commit | The PR diff, after you push |
| Output | Findings in the terminal. Both commands only read; they don't edit files. | Review comments on the PR, some with a suggested fix to apply |
| Focus | /review: correctness and missing tests. /security-review: high-confidence vulnerabilities in the change. |
General review of the PR. You can also set it to run automatically. |
Committing the patch removes it from /review's scope. Local findings
are private and quick, so use them before you push. PR review is the one your
teammates see. Neither approves anything.
Setup¶
Starter assets:
lab/starter/review-project/: Express API under review, withsrc/api.js,src/utils.js, and Jest/Supertest tests intests/api.test.jslab/starter/code-changes.md: intentionally flawed changes to reviewlab/starter/partner-review-checklist.md: structured review worksheetlab/starter/fix-evaluation-template.md: finding, fix, and test recordlab/starter/conflict-scenario/: manual merge-conflict scenario (README.md,utils-with-conflict.js)
Create a workspace outside the curriculum folder:
mkdir -p ~/copilot-labs/session-m2-04
cp -R lab/starter/review-project ~/copilot-labs/session-m2-04/review-project
cd ~/copilot-labs/session-m2-04/review-project
npm install
npm test
git init
printf 'node_modules/\n' > .gitignore
git add .gitignore package.json package-lock.json src tests
git commit -m "Record review baseline"
git branch -M main
git switch -c feature/add-user-management
Expected:
npm installadds no new dependencies andnpm testreports that the existing API tests pass.If install or tests fail: Fix the environment. Don't change package versions to hide a failure.
Add your private repository as origin and push the baseline:
The baseline must be the same commit locally and remotely, so the PR contains only the intended change. If the remote already has commits, use an empty repository. Never force-push or push the intentional defects to a public repository.
No private repository? Skip step 11 of Exercise 1 and compare
/reviewwith/security-reviewinstead.
Exercise 1: Review one diff through three passes (40 minutes)¶
Steps¶
-
Read the change brief. Open
lab/starter/code-changes.md. It lists changes tosrc/api.jsandsrc/utils.js, each with an intended defect. -
Open
lab/starter/fix-evaluation-template.md. Use its one triage table for human, local, and PR findings. Each row names a file or function and the code or test output that supports it. -
Read the baseline. Open
src/api.js,src/utils.js, andtests/api.test.js. Note the existing behavior so you can separate it from introduced defects. -
Apply the change brief on
feature/add-user-management. Keep the changes uncommitted until both local reviews finish. Comparegit diff -- src/api.js src/utils.jswith the brief. Add no unrelated features. -
Run the existing checks.
Some tests may still pass because the defects aren't fully covered. Note the output and any missing coverage.
-
Review the change yourself first. Write your initial verdict in the template and add your two most important findings to the triage table with
Humanas the source. Usepartner-review-checklist.mdfor prompts if you want them. -
Run the general code review. Start
copilotin the working repository:
/review Review the current changes to src/api.js and src/utils.js for
correctness and missing tests. Cite file and line references. Review only;
do not edit files.
- Run the security review on the same diff:
Both commands review staged and unstaged changes. Committing the patch first
removes it from that scope. (With a clean tree, /security-review reviews
the branch diff instead.)
- Triage both outputs in the template. Leave your human findings unchanged. Accept, reject, or leave each finding unresolved, with a reason. If a review reports no findings, write that in the Review runs table.
The search route builds SQL text but connects to no database, so reject a claim that the lab proves database compromise. Synthetic key-shaped strings aren't a leaked real credential. Keep actual data exposure separate from unsafe patterns and maintainability suggestions.
-
Draft the commit message and PR description with Copilot. Stage the two files, then in
copilot:Write a commit message and a PR description (problem, change, validation, risk) for the staged diff. Use only what the diff shows.Compare every claim with the diff. Delete any test result or benefit the diff doesn't show. Commit with the corrected message.
-
Open the training PR. Push to your private remote and open a PR:
git push -u origin feature/add-user-management gh pr create --base main --title "Review synthetic user management" \ --body "Training-only change. Contains intentional defects; do not merge."Request Copilot review from the PR page. In the template, record one finding that differs from the local results. Don't merge the flawed change.
Checkpoint¶
- Which findings block approval, and which are suggestions only?
- Which defects did the existing tests miss?
- What did
/review,/security-review, and PR review each report, and what did only one of them find? - What changed after the assisted review?
- Which claim rests on actual behavior rather than an assumed backend?
Exercise 2: Validate and correct the starter project (35 minutes)¶
Fix the defects with the smallest safe changes, then show the corrected project meets the review criteria.
Steps¶
-
Prioritize blocking findings. Start with issues that leak sensitive data, allow injection, crash the server, or return incorrect behavior. List each defect, its file, and the check you will run.
-
Fix input handling in
src/api.js. Replace unsafe string interpolation and fragile parsing with validated inputs and safe response shapes. The endpoint should handle empty, missing, malformed, and valid inputs predictably. Show the error responses in tests or manual requests. -
Fix sensitive response data. Remove password-like or token-like fields from responses. The JSON should show only fields the API contract needs.
-
Fix pagination in
src/utils.js. Page 1 starts with the first item, and boundary cases return predictable results. A focused test or Node.js check covers page 1, page 2, and empty collections. -
Add or update focused tests in
tests/api.test.jsfor the behavior the original suite missed. New tests fail before the fix and pass after it. -
Run checks again.
All tests should pass. If one fails, record the failing assertion and correct only the related implementation or test expectation.
-
Update the triage rows in
fix-evaluation-template.md. Add the fix and regression test to each accepted finding. Record residual risk in its Human decision section. -
Review the correction diff before committing. Rerun
/reviewand/security-reviewon it and compare with the initial findings. Rerunnpm test, then commit and push only the reviewed fixes to the same PR (or just commit if you have no remote). A clean automated review doesn't approve the PR.
Checkpoint 2¶
- Every blocking finding maps to a focused fix.
- New tests cover the missed behavior.
-
npm testpasses. - The fix evaluation names residual risk.
Exercise 3: Resolve a conflict (25 minutes)¶
Resolve a merge conflict so both branches' intended behavior survives.
Steps¶
-
Read the scenario. Open
lab/starter/conflict-scenario/README.md. Two branches modifysrc/utils.js: one adds date formatting, the other changes price formatting. -
Open the conflicting source,
lab/starter/conflict-scenario/utils-with-conflict.js. Find the conflicting region and state what each side does. -
Write the merged behavior before editing:
Preserve formatDate for date display and preserve formatPrice with an explicit
currency parameter. Existing callers should continue to work or be updated
intentionally.
-
Resolve the conflict manually. Remove the
<<<<<<<,=======, and>>>>>>>markers, keep both valid behaviors, and avoid unrelated formatting changes. -
Add focused tests for date formatting, default currency, supplied currency, and unchanged helpers.
-
Run the project test command and save the output.
-
Peer review the resolution. Ask a partner to review only the resolution and tests. They should be able to say why both branch goals appear in the result.
Checkpoint 3¶
- No conflict markers remain.
- Both branch goals appear in the resolved behavior.
- Tests cover date and currency formatting.
Exercise 4: Review the code and test results (20 minutes)¶
Use the code and test results to make your final decision. An automated suggestion alone isn't enough.
Steps¶
-
Select one blocking finding from Exercise 1 (security, correctness, or reliability). It needs a file reference, impact, and acceptance criterion.
-
Check its triage row. Add any missing before/after behavior, test names, or command output. A reviewer should reproduce the result from your notes.
-
Classify remaining risk:
| Risk type | Question |
|---|---|
| Data | Did the change expose or process restricted data? |
| Dependency | Did the change add or update packages? |
| Permission | Did the workflow need a new permission? |
| Security | Did validation, error handling, or secrets handling change? |
| Quality | Do the tests and review results support the decision? |
-
Complete Human decision in
fix-evaluation-template.md. Choose approve, request changes, or pause, and explain why. Someone reading it should understand the decision without seeing your lab conversation. -
Compare your initial review with the local and PR results. In the triage table, mark differences, false positives, and any finding that changed your verdict. Keep your original findings.
Checkpoint 4¶
- The decision is approve, request changes, or pause.
- The rationale cites findings, fixes, and check results.
- You accepted automated findings only after reviewing them.
Final deliverable¶
fix-evaluation-template.md, completed. It holds your initial verdict, the review runs, the triage table, test results, remaining risk, and decision.- The corrected project, with
npm testpassing. - The resolved conflict and its test output.
- The PR link, if you opened one.
Don't merge the training PR.