Practical Examples

Three tasks, easy to harder, covering this course: comment-driven complete, Chat on an unfamiliar repo, and Issue → agent PR on GitHub. Paste the prompts into Copilot; adjust commands for your repo. Do not run these on production with review turned off.


Example 1: Comment-to-code, then you verify

Goal: Ghost-text a pure function with edge behavior—not “it looks runnable.”

Setup: an empty folder is enough.

Windows:

mkdir $HOME\copilot-lab-1
cd $HOME\copilot-lab-1
code .

macOS:

mkdir -p ~/copilot-lab-1
cd ~/copilot-lab-1
code .

Create slug.js. Type only the comment and header; wait for gray text:

// Convert a string to a URL slug: lowercase, trim, spaces to '-',
// strip characters that are not letters, digits, or '-'.
// Collapse repeated '-'. Empty input → "".
function slugify(input) {

Tab to accept or Esc to dismiss and tighten the comment. Then create slug.test.js (or your usual test file) and ask for assertions in a comment:

// Tiny tests without a framework: throw if slugify("Hello World") !== "hello-world"
// Also cover "", "  a--b  ", and punctuation.

If complete tries to add a test library you did not install, Esc and write Do not add Jest in the comment. On Windows and macOS run node --test slug.test.js; if --test is missing, use a few console.assert lines.

Done when:

CheckPass
The implementation came from Copilot, and you read every lineYes / no
Empty string and repeated hyphens are testedYes / no
Tests are greenYes / no

Chapters: Quick Start, Completions.


Example 2: Chat onboards a strange repo; you merge one change

Goal: In two hours, name the entry points and test command, and merge one small change you understand.

Clone a small-to-medium open-source repo you do not know. Open the repo root in VS Code:

git clone <repo-url> unfamiliar-repo
cd unfamiliar-repo
code .

Ctrl+Alt+I (Windows) or Control+Command+I (macOS), then:

@workspace Explain this codebase. Point me to main entry points and
modules I must read before changing behavior. Cite file paths.
@workspace Quote the exact commands this repo uses for install, test,
lint, and dev server. Prefer package.json / Makefile / pyproject.toml.
Do not invent scripts.

Run what it quoted (example only—prefer the files):

npm ci
npm test
npm ci
npm test

Pick a change with no auth and no migrations (copy, README typo, missing JSDoc). Use Chat Ask or Edit, not a full-repo Agent sweep:

Add JSDoc to the exported function I have selected.
Do not change runtime behavior. Do not touch lockfiles.

Review the diff, rerun the same tests, commit only that hunk.

Done when:

CheckPass
Entry paths come from repo files, not inventionYes / no
Test command comes from configYes / no
One small diff merged; tests still green (or you understand the failure)Yes / no

See Chat. If you would rather do this in Cursor, use Cursor practical examples—do not let two agents write at once.


Example 3: Assign an Issue to Copilot; you review the PR

Goal: Run the official cloud-agent loop—not “it felt done” in the IDE.

You need:

  • A practice repo you can push to (not production)
  • Plan and repo policy that allow Copilot cloud agent (see Coding Agent)
  • A specific Issue

Issue body example:

## Goal
Add GET /health returning JSON {"ok": true} using the existing HTTP stack.
Do not change authentication.

## Success
- One new test in the same style as the repo
- README mentions the endpoint in one sentence

## Out of scope
- New dependencies unless the repo already uses them
- Refactors of unrelated files

On GitHub: Assignees → Copilot. Optionally repeat “do not touch auth” in the optional prompt. When the PR appears:

  1. Ask Summarize this pull request in the Copilot panel (GitHub Integration).
  2. Open Files changed yourself; reject drive-by refactors.
  3. Check out the PR branch locally and run tests (same on Windows / macOS):
git fetch origin
git checkout <pr-branch>

Then run the test command from example 2.

  1. If you need changes, comment on the PR, not only on the already-assigned Issue.
  2. Merge only when tests are green and the diff matches the Issue.

If the org disabled the agent: implement the same /health with the CLI and open the PR yourself—still human-reviewed.

Done when:

CheckPass
The Issue has success criteria and out of scopeYes / no
The PR came from Copilot or your explicit CLI fallbackYes / no
You ran tests on your machine, not only a green check on the webYes / no

After the labs

Put norms in .github/copilot-instructions.md. Whether to run Cursor in parallel: Copilot vs Cursor.


Next

评论