Skip to main content

Lab 3: Full Developer Workflow

๐ŸŽฏ Learning Objectives
  • Use all four Chat modes (Ask, Edit, Plan, Agent) and understand when each is appropriate
  • Execute a complete scaffold-to-test workflow using Agent Mode
  • Use the modern Copilot CLI for real development tasks
  • Experience Copilot-assisted PR workflow on GitHub.com

Chat Modes Reference

ModeWhat It DoesBest For
๐Ÿ’ฌ AskAnswers questions, explains code, suggests changes as text. Does not modify files.Learning, exploration, code review
โœ๏ธ EditMakes direct file modifications. Shows diffs for approval.Targeted refactoring, specific changes
๐Ÿ“‹ PlanResearches the codebase and proposes an implementation plan without making file edits.Planning complex changes before committing to them
๐Ÿค– AgentAutonomous multi-step execution. Plans, edits files, runs terminal commands, iterates on errors.Feature implementation, scaffolding, complex tasks

Exercises

Step 1

Scaffold a REST API with Agent Mode

Agent Mode is Copilot's most powerful feature โ€” it can plan, create files, run commands, and iterate. You'll use it to scaffold an entire API project.

Instructions

  1. Create a new empty folder for this lab: lab3-api/
  2. Open Copilot Chat and switch to Agent Mode (select "Agent" from the mode dropdown at the top of the Chat panel).
  3. Type this prompt:
    Create a Node.js REST API for a task management app using Express 
    and TypeScript. Include:
    
    1. Project setup: package.json, tsconfig.json, .gitignore
    2. Data model: Task with id, title, description, status (todo/in-progress/done), createdAt, updatedAt
    3. In-memory storage (array-based, no database needed)
    4. CRUD endpoints: GET /tasks, GET /tasks/:id, POST /tasks, PUT /tasks/:id, DELETE /tasks/:id
    5. Input validation middleware
    6. Error handling middleware with consistent JSON error responses
    7. A health check endpoint: GET /health

    Put all code in the lab3-api/ directory.



  4. Watch Agent Mode work:

    • It will plan the file structure

    • It will create multiple files (package.json, tsconfig.json, source files)

    • It may run terminal commands (like npm init or npm install)

    • You’ll see a permission prompt before it runs any command โ€” click Allow



  5. When it finishes, review the generated project structure. You should see something like:

    lab3-api/
    โ”œโ”€โ”€ package.json
    โ”œโ”€โ”€ tsconfig.json
    โ”œโ”€โ”€ .gitignore
    โ””โ”€โ”€ src/
        โ”œโ”€โ”€ index.ts (or app.ts)
        โ”œโ”€โ”€ routes/
        โ”‚   โ””โ”€โ”€ tasks.ts
        โ”œโ”€โ”€ middleware/
        โ”‚   โ”œโ”€โ”€ validation.ts
        โ”‚   โ””โ”€โ”€ errorHandler.ts
        โ””โ”€โ”€ types/
            โ””โ”€โ”€ task.ts
    </li>
    
๐Ÿ’ก Key Concept: Agent Mode follows a Plan โ†’ Code โ†’ Test โ†’ Iterate loop. If something fails (like a TypeScript compilation error), it reads the error and tries to fix it automatically. This is the "agentic loop."
โš ๏ธ Safety: Agent Mode asks permission before running terminal commands. Always read what it wants to execute before clicking Allow. Never auto-approve blindly.
Step 2

Ask Mode โ€” Understand the Generated Code

Switch to Ask Mode to explore and understand what Agent Mode created.

Instructions

  1. Switch the Chat mode to Ask.
  2. Ask about the overall architecture:
    #project Explain the architecture of the lab3-api project. What patterns does it use? How does request flow from route to response?
  3. Ask about a specific file (use the actual path from your generated project):
    #file:lab3-api/src/routes/tasks.ts Walk me through each endpoint. What HTTP methods and status codes does each use?
  4. Ask about error handling:
    #file:lab3-api/src/middleware/errorHandler.ts How does the error handling middleware work? What happens if an unhandled error occurs?
  5. Note that Ask Mode only answers questions โ€” it doesn't modify any files. This is the safe mode for exploration.
Step 3

Plan mode โ€” Add Documentation

Use Plan mode for targeted, in-place file modifications with diff review.

Instructions

  1. Switch the Chat mode to Edit.
  2. Open your main routes file and request documentation:
    #file:lab3-api/src/routes/tasks.ts Add comprehensive JSDoc comments to every route handler. Include @param for request parameters, @returns with expected response shape, and @example with a curl command for each endpoint.
  3. Copilot will show you a diff view โ€” green lines are additions, red lines are removals.
  4. Review the diff carefully. Then click Accept to apply.
  5. Now do the same for the types file:
    #file:lab3-api/src/types/task.ts Add JSDoc to the Task interface and all related types. Include field descriptions and valid value ranges.
  6. Accept the changes.
๐Ÿ’ก Edit vs. Agent: Use Plan mode when you have a specific, targeted change in mind (like adding docs to one file). Use Agent Mode when you need multi-file, multi-step changes where Copilot needs to figure out the plan.
Step 4

Agent Mode โ€” Debug and Fix

Introduce a bug and watch Agent Mode diagnose and fix it.

Instructions

  1. Open your tasks route file. Intentionally introduce a bug โ€” for example, change a status code from 201 to 200 on the POST endpoint, or misspell a variable name.
  2. Switch back to Agent Mode.
  3. Type:
    There's a bug in the task creation endpoint. The POST /tasks endpoint should return 201 Created but it's returning the wrong status code. Find and fix it. Then verify by checking all other endpoints for correct status codes:
    - GET collection: 200
    - GET single: 200 (or 404)
    - POST: 201
    - PUT: 200 (or 404) 
    - DELETE: 204 (or 404)
  4. Watch Agent Mode: it reads the file, identifies the issue, makes the fix, and may even verify by reading related files.
Step 5

Agent Mode โ€” Refactor

Use Agent Mode for a cross-cutting refactor that touches multiple files.

Instructions

  1. In Agent Mode, type:
    Refactor the task API to add request logging middleware that logs:
    - Timestamp
    - HTTP method and URL
    - Response status code
    - Response time in milliseconds
    

    Create it as a new middleware file and wire it into the app. Use it on all routes.



  2. Observe that Agent Mode:

    • Creates a new middleware file

    • Modifies the main app file to import and use it

    • This is a multi-file change that Plan mode couldn’t handle as smoothly


Step 6

Agent Mode โ€” Generate Tests

Complete the workflow by generating tests for your API.

Instructions

  1. In Agent Mode, type:
    Generate comprehensive Jest tests for the task API. Include:
    1. Tests for all CRUD endpoints (happy path)
    2. Validation error tests (missing fields, invalid types)
    3. 404 tests for non-existent task IDs
    4. Edge cases (empty title, very long description)
    5. Set up supertest for HTTP testing
    6. Create a test setup file with helpers
    

    Install any needed dev dependencies (jest, ts-jest, supertest, @types/supertest).



  2. Agent Mode will:

    • Install test dependencies via terminal

    • Create Jest configuration

    • Create test files with multiple test suites

    • Possibly run the tests and fix any failures



  3. After it finishes, run the tests yourself:

    cd lab3-api && npx jest --verbose
    </li>
    <li>If any tests fail, paste the error into Agent Mode and ask it to fix them. This is the <strong>iterate</strong> part of the agentic loop.</li>
    
Step 7

Copilot CLI โ€” Terminal Workflows

Use the modern Copilot CLI to assist with shell tasks, explanations, and local workflow planning.

Instructions

  1. Open the integrated terminal in VS Code.
  2. Navigate to your lab3-api directory.
  3. Try these CLI prompts:
    # Find all TypeScript files with more than 50 lines
    copilot "find TypeScript files with more than 50 lines in current directory"
    
    

    Understand a complex npm script
    #

    copilot “explain: npx ts-node –transpile-only src/index.ts”

    Get help with git
    #

    copilot “create a git branch called feature/add-pagination and switch to it”

    Understand a test command
    #

    copilot “explain: npx jest –coverage –watchAll –verbose”

    Plan before changing files
    #

    copilot “/plan add pagination to the task API without changing tests yet”



  4. Review any proposed shell command before running it. The CLI is conversational and may offer to execute commands, but you remain responsible for approval.
Step 8

Bonus: GitHub.com PR Workflow

If you have a test repo, experience Copilot on GitHub.com.

Instructions

  1. Commit your lab3-api work and push to a branch on GitHub.
  2. Open a Pull Request on GitHub.com.
  3. Observe the Copilot PR Summary โ€” it auto-generates a description of your changes.
  4. In the PR, try the Copilot Code Review feature (if available on your plan) to get AI-powered review comments.
๐Ÿ’ก Exam Tip: The exam tests knowledge of Copilot across all surfaces: IDE, CLI, and GitHub.com. Remember that PR summaries and code review are GitHub.com features, not IDE features.

โœ… Completion Checklist

  • Scaffolded a REST API project using Agent Mode
  • Used Ask Mode to explore and understand the generated code
  • Used Plan mode to add JSDoc documentation with diff review
  • Used Agent Mode to find and fix a bug
  • Used Agent Mode for a multi-file refactor (logging middleware)
  • Generated and ran tests using Agent Mode
  • Used Copilot CLI for shell tasks, command explanations, and planning

๐ŸŽฏ Key Takeaways for the Exam

  • Ask Mode: Read-only, conversational, safe for exploration
  • Plan mode: Direct file changes with diff review, targeted edits
  • Plan Mode: Researches and proposes an implementation plan before file changes
  • Agent Mode: Autonomous multi-step, can run terminal commands, iterates on failures
  • Agent Mode is available on all plans including Free
  • Copilot CLI: use copilot for terminal help, command explanations, local context, and planning
  • PR summaries and code review are GitHub.com features
  • Agent Mode follows the Plan โ†’ Code โ†’ Test โ†’ Iterate loop