* Mock policy server: upstream passthrough, per-endpoint mocking, request log The mock policy server only worked via product.overrides.json, which limits it to Code OSS running from sources, requires a reload after every change, and cannot exercise a stable/Insiders build or the CLI. Support a system HTTP proxy as a second wiring path, keeping product.overrides.json as the default. - Proxy anything not explicitly mocked to the real API (--upstream, default https://api.github.com) and stream it back, so a blanket proxy rule is safe: only endpoints deliberately switched on are faked. Rewrites Host, strips hop-by-hop headers and accept-encoding, forwards Authorization untouched, and reports upstream failures as 502. - Add a per-endpoint mock/passthrough toggle. Only managed settings is mocked by default; applying a preset implicitly switches mocking on. - Add managed-settings disk cache clearing. A cache entry under an hour old makes the runtime skip the network entirely, so an override is never even requested. Paths verified against managed_settings_cache.rs and path_helpers.rs, including the COPILOT_CACHE_HOME override. - Add a rolling request log (GET/DELETE /api/log) surfaced in the GUI, so it is obvious whether the client actually reached the server. - Add realistic managed-settings presets, each validated against the schema, and branch-point presets for the other endpoints. - Only warn about unknown schema keys on 2xx, and re-validate on status change: a 404/466/500 body is an error payload, not a policy document. - Route GUI assets from an explicit allowlist instead of probing public/ for anything that looks like a file, which would otherwise shadow proxied paths. UX: - Make save semantics consistent: everything auto-saves, with a pill showing whether the editor matches what is being served. - Surface mocked vs proxied via tab dots, a checkbox, and reactive help text. - Add a light palette; the dark-only one declared color-scheme: light dark, so UA form controls rendered light on a dark page. - Make the schema disclosure a real button with aria-expanded, add focus-visible styles, and expose tab state to screen readers. - Build the validation table from DOM nodes rather than innerHTML. - Surface save and wire failures instead of failing silently, and fall back to the shared endpoint definitions when the control API is unreachable. - Answer the GUI's own favicon request so it stops appearing in the log as a proxied 404. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Polish mock policy server workflows Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Route runtime policy diagnostics through proxy Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Minimize runtime proxy integration Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Move runtime proxy fix to separate PR Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address mock policy server review feedback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Mock Copilot policy server
Local Node server and web GUI for the four Copilot policy endpoints used by
DefaultAccountService. Mock selected endpoints while forwarding the rest to
the real API. It has no runtime dependencies and is not shipped with VS Code.
Start
npm run mock-policy-server
Open http://127.0.0.1:3000. Managed settings is mocked by default. Use the
switch beside each endpoint tab to choose mock or passthrough. Presets apply
immediately; status and JSON edits auto-save.
Point a client at the server with either:
- Code OSS from sources: select Apply Overrides, reload, sign in, and run Developer: Sync Account Policy.
- Stable, Insiders, CLI, or another client: configure the system proxy
mapping shown for the selected endpoint and copy the VS Code
http.proxysetting.
If no request appears in Live Requests, use Clear Policy Cache. A fresh managed-settings cache entry can prevent the client from making a request for up to one hour. Then run Developer: Restart Local Agent Host to force a new SDK policy resolution.
Other Copilot clients share that cache. For an isolated run, start both the server and Code OSS with the same temporary cache home:
COPILOT_CACHE_HOME="$PWD/.build/mock-policy-cache" npm run mock-policy-server
COPILOT_CACHE_HOME="$PWD/.build/mock-policy-cache" ./scripts/code.sh
HTTP API
The control API is JSON-only and supports complete configuration without the GUI. Start with its machine-readable index and current state:
BASE=http://127.0.0.1:3000
curl "$BASE/api"
curl "$BASE/api/state"
GET /api/state returns endpoint IDs, presets, current bodies, statuses, and
mock/passthrough state.
Apply a known preset:
curl -X POST "$BASE/api/state" \
-H 'Content-Type: application/json' \
-d '{"endpoint":"managedSettings","preset":"not-configured"}'
Set a custom response:
curl -X POST "$BASE/api/state" \
-H 'Content-Type: application/json' \
-d '{"endpoint":"managedSettings","active":true,"status":200,"body":{}}'
Configure multiple endpoints atomically:
curl -X POST "$BASE/api/state" \
-H 'Content-Type: application/json' \
-d '{"endpoints":[
{"endpoint":"managedSettings","preset":"empty"},
{"endpoint":"entitlements","active":false},
{"endpoint":"token","active":false},
{"endpoint":"mcpRegistry","active":false}
]}'
A preset sets its status and body and enables mocking. Explicit status, body,
or active values in the same update override the preset. Invalid requests are
rejected before any endpoint changes.
| Method | Route | Purpose |
|---|---|---|
GET |
/api |
Discover request shapes and routes |
GET |
/api/state |
Read definitions, presets, and current state |
POST |
/api/state |
Apply one update or an atomic endpoint array |
POST |
/api/reset |
Restore startup endpoint state |
GET |
/api/schema |
Read the managed-settings schema |
GET, DELETE |
/api/log |
Read or clear the request log |
DELETE |
/api/cache |
Clear the managed-settings disk cache |
POST |
/api/wire |
Apply product.overrides.json |
POST |
/api/unwire |
Restore product.overrides.json |
Schema and options
The server auto-detects
copilot-agent-runtime/schema/managed-settings-schema.json beside the primary
VS Code checkout, including from a Git worktree. Override it at startup with
--schema or MANAGED_SETTINGS_SCHEMA.
npm run mock-policy-server -- --upstream https://api.ghe.example.com
npm run mock-policy-server -- --schema /path/to/managed-settings-schema.json
npm run mock-policy-server -- --help
| Flag | Environment variable | Default |
|---|---|---|
--host |
— | 127.0.0.1 |
--upstream |
MOCK_POLICY_UPSTREAM |
https://api.github.com |
--schema |
MANAGED_SETTINGS_SCHEMA |
Auto-detected sibling checkout |