Files
vscode/scripts/mock-policy-server/public/index.html
T
8fb912f511 Mock policy server: upstream passthrough, per-endpoint mocking, request log (#330711)
* 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>
2026-08-13 23:29:50 +00:00

129 lines
4.6 KiB
HTML

<!--
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. See License.txt in the project root for license information.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Mock Policy Server</title>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<header>
<div class="header-content">
<h1>Mock Policy Server</h1>
<button id="clear-cache" type="button" class="btn-warn">Clear Policy Cache</button>
</div>
</header>
<main>
<section class="editor-panel">
<div class="tabs-header">
<nav id="tabs" class="tabs" aria-label="Policy endpoints"></nav>
</div>
<div class="content-section">
<p id="endpoint-meta" class="endpoint-meta"></p>
<div class="form-group">
<label for="preset">Preset</label>
<select id="preset"></select>
</div>
<div class="form-group">
<label for="response-status">HTTP status code</label>
<input id="response-status" class="status-code-input" type="number" min="200" max="599" step="1"
inputmode="numeric" aria-describedby="response-status-validation">
<p id="response-status-validation" class="status" aria-live="polite"></p>
</div>
<div id="schema-section" class="section-block" hidden>
<h2 class="schema-heading">
<button type="button" class="section-header section-header-toggle" id="schema-toggle"
aria-expanded="false" aria-controls="schema-details">
<span class="chevron" id="schema-chevron" aria-hidden="true">&#9654;</span>
<span>Schema</span>
<span id="schema-badge" class="schema-badge" data-tooltip="">&hellip;</span>
</button>
</h2>
<div id="schema-details" class="schema-details" hidden>
<span class="label-small">Schema source</span>
<code id="schema-source" class="block"></code>
<button id="hydrate-schema" type="button" class="btn-secondary">Generate Example</button>
</div>
</div>
<div class="form-group">
<div class="label-row">
<label for="editor">Response body (JSON)</label>
<span id="save-state" class="save-state" aria-live="polite"></span>
</div>
<textarea id="editor" spellcheck="false" autocomplete="off"
aria-describedby="editor-status"></textarea>
<p id="editor-status" class="status" aria-live="polite"></p>
<div id="validation-results" hidden></div>
</div>
</div>
</section>
<aside class="sidebar-panel">
<div class="section-block">
<div class="section-header">
<h2>Live requests</h2>
<button id="clear-log" type="button" class="btn-link">Clear</button>
</div>
<p id="log-empty" class="helper-text">No requests yet.</p>
<ul id="log" class="log"></ul>
</div>
<div class="section-block">
<div class="section-header">
<h2>Code OSS Overrides</h2>
<button type="button" class="info-button"
aria-label="About Code OSS overrides"
data-tooltip="Code OSS from sources only. Writes product.overrides.json; reload after applying or restoring. Does not redirect the independent Agent Runtime Resolution probe.">&#9432;</button>
</div>
<div class="status-box">
<span class="label-small">Status</span>
<strong id="wired-status">&hellip;</strong>
</div>
<button id="overrides-action" type="button" class="btn-primary btn-full">Apply Overrides</button>
</div>
<div class="section-block">
<div class="section-header">
<h2>System Proxy</h2>
<button type="button" class="info-button"
aria-label="About system proxy setup"
data-tooltip="Redirects policy requests for VS Code, Copilot SDK sessions, and Agent Runtime Resolution. After clearing the policy cache, run Developer: Restart Local Agent Host.">&#9432;</button>
</div>
<div class="kv">
<span class="label-small">Map from</span>
<code id="map-from" class="block"></code>
</div>
<div class="kv">
<span class="label-small">Map to</span>
<code id="map-to" class="block"></code>
</div>
<button id="copy-map" type="button" class="btn-secondary btn-full">Copy Mapping</button>
<div class="kv">
<span class="label-small">VS Code settings.json</span>
<code id="proxy-settings" class="block settings-json"></code>
</div>
<button id="copy-proxy-settings" type="button" class="btn-secondary btn-full">Copy VS Code Setting</button>
</div>
</aside>
</main>
<div id="toast" class="toast" role="status" aria-live="polite" hidden></div>
<script src="./endpoints.js"></script>
<script src="./app.js"></script>
</body>
</html>