refactor(tests): deduplicate WebSocket frame builder across token-tracker schema tests#5026
Conversation
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
There was a problem hiding this comment.
Pull request overview
Refactors the api-proxy token tracker schema tests by extracting duplicated WebSocket upgrade + frame-building fixtures into a shared helper, reducing repetition and making future fixture updates centralized.
Changes:
- Added a shared WebSocket frame/fixture helper for Anthropic streaming test payloads.
- Updated the three
trackWebSocketTokenUsageschema tests to emit the canonical payload viabuildAnthropicUsageFrames()instead of duplicating frame setup inline.
Show a summary per file
| File | Description |
|---|---|
| containers/api-proxy/token-tracker.schema.test.js | Replaces duplicated inline WebSocket frame/handshake setup with a shared helper call in three tests. |
| containers/api-proxy/test-helpers/websocket-frame-helpers.js | Introduces reusable helpers to build an HTTP upgrade header and minimal unmasked WS text frames, plus a canonical Anthropic usage payload builder. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
| function buildFrame(text) { | ||
| const payload = Buffer.from(text, 'utf8'); | ||
| const header = Buffer.alloc(2); | ||
| header[0] = 0x81; // FIN + opcode 1 (text) | ||
| header[1] = payload.length; | ||
| return Buffer.concat([header, payload]); | ||
| } |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Throws a clear error if payload exceeds 125 bytes (the single-byte length limit), preventing silent production of invalid WebSocket frames. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🔬 Smoke Test: Copilot PAT Auth — PASS
Auth mode: PAT (COPILOT_GITHUB_TOKEN) Overall: PASS ✅
|
|
Smoke Test: Copilot BYOK (Direct Mode) ✅ Test 1: GitHub MCP connectivity — verified Status: PASS — Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY) via api-proxy → api.githubcopilot.com cc/
|
🔬 Smoke Test ResultsPR: refactor(tests): deduplicate WebSocket frame builder across token-tracker schema tests
Overall: FAIL — pre-computed step outputs were not substituted (workflow expression issue).
|
Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
Chroot Version Comparison Results
Overall: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot.
|
Smoke Test Results
Overall: FAIL
|
🔭 Smoke Test: API Proxy OpenTelemetry Tracing
Summary: Core OTEL implementation is healthy. Scenario 3 reports pending due to a path mismatch in the validation grep (checks
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Smoke Test Results: Gemini
Overall Status: FAIL Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "localhost"See Network Configuration for more information.
|
|
Running in direct BYOK mode (AWF_AUTH_TYPE=github-oidc + AWF_AUTH_AZURE_* + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) authenticated via Microsoft Entra Overall: PASS
|
|
GitHub MCP API connectivity: ✅ Overall: PASS
|
Three
trackWebSocketTokenUsageschema tests each duplicated the same ~15-linebuildFramehelper and identical Anthropic WebSocket handshake fixture, meaning any change to frame encoding or the canonical usage payload required three parallel edits.Changes
New:
test-helpers/websocket-frame-helpers.jsExports three helpers:
buildFrame(text)— encodes a string as an unmasked WebSocket text framebuildHttpUpgradeHeader()— returns the HTTP 101 Switching Protocols bufferbuildAnthropicUsageFrames()— composes the full canonical test payload (upgrade header +message_start+message_delta)Modified:
token-tracker.schema.test.jsEach of the three
trackWebSocketTokenUsagetests now replaces its inline frame setup with a single call:Tests now vary only on
requestIdandonUsage— the meaningful dimensions — rather than re-implementing low-level frame encoding.