Skip to content

refactor(tests): deduplicate WebSocket frame builder across token-tracker schema tests#5026

Merged
lpcox merged 3 commits into
mainfrom
copilot/fix-duplicate-code-schema-tests
Jun 15, 2026
Merged

refactor(tests): deduplicate WebSocket frame builder across token-tracker schema tests#5026
lpcox merged 3 commits into
mainfrom
copilot/fix-duplicate-code-schema-tests

Conversation

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Three trackWebSocketTokenUsage schema tests each duplicated the same ~15-line buildFrame helper 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.js

Exports three helpers:

  • buildFrame(text) — encodes a string as an unmasked WebSocket text frame
  • buildHttpUpgradeHeader() — returns the HTTP 101 Switching Protocols buffer
  • buildAnthropicUsageFrames() — composes the full canonical test payload (upgrade header + message_start + message_delta)

Modified: token-tracker.schema.test.js

Each of the three trackWebSocketTokenUsage tests now replaces its inline frame setup with a single call:

// Before (×3, ~15 lines each):
function buildFrame(text) { ... }
const httpHeader = Buffer.from('HTTP/1.1 101 ...');
const frame1 = buildFrame(JSON.stringify({ type: 'message_start', ... }));
const frame2 = buildFrame(JSON.stringify({ type: 'message_delta', ... }));
socket.emit('data', Buffer.concat([httpHeader, frame1, frame2]));

// After:
socket.emit('data', buildAnthropicUsageFrames());

Tests now vary only on requestId and onUsage — the meaningful dimensions — rather than re-implementing low-level frame encoding.

Copilot AI changed the title [WIP] Refactor websocket token-tracker schema tests to eliminate duplication refactor(tests): deduplicate WebSocket frame builder across token-tracker schema tests Jun 15, 2026
Copilot finished work on behalf of lpcox June 15, 2026 13:48
Copilot AI requested a review from lpcox June 15, 2026 13:48
@lpcox lpcox marked this pull request as ready for review June 15, 2026 14:37
Copilot AI review requested due to automatic review settings June 15, 2026 14:37
@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 96.86% 96.90% 📈 +0.04%
Statements 96.73% 96.77% 📈 +0.04%
Functions 98.81% 98.81% ➡️ +0.00%
Branches 91.24% 91.27% 📈 +0.03%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/workdir-setup.ts 92.6% → 94.4% (+1.85%) 92.6% → 94.4% (+1.85%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 trackWebSocketTokenUsage schema tests to emit the canonical payload via buildAnthropicUsageFrames() 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

Comment on lines +10 to +16
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]);
}
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions github-actions Bot mentioned this pull request Jun 15, 2026
@github-actions

This comment has been minimized.

@github-actions

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>
@github-actions

Copy link
Copy Markdown
Contributor

🔬 Smoke Test: Copilot PAT Auth — PASS

Test Result
GitHub MCP connectivity
GitHub.com HTTP ✅ 200
File write/read

Auth mode: PAT (COPILOT_GITHUB_TOKEN)
PR: refactor(tests): deduplicate WebSocket frame builder across token-tracker schema tests
Author: @Copilot | Assignees: @lpcox @Copilot

Overall: PASS

🔑 PAT report filed by Smoke Copilot PAT

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct Mode)

✅ Test 1: GitHub MCP connectivity — verified
✅ Test 2: GitHub.com connectivity — verified
✅ Test 3: File write/read — verified
✅ Test 4: BYOK inference — working

Status: PASS — Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY) via api-proxy → api.githubcopilot.com

cc/ @lpcox @Copilot

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results

PR: refactor(tests): deduplicate WebSocket frame builder across token-tracker schema tests
Author: @Copilot | Assignees: @lpcox @Copilot

Test Result
GitHub MCP connectivity
GitHub.com HTTP connectivity ❌ (pre-step template variable not expanded)
File write/read ❌ (pre-step template variable not expanded)

Overall: FAIL — pre-computed step outputs were not substituted (workflow expression issue).

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

Copy link
Copy Markdown
Contributor
  • Deduplicate Copilot bearer-prefix stripping in api-proxy
  • refactor(api-proxy): deduplicate guard enforcement between HTTP and WebSocket paths, fix 3 missing WebSocket guards
  • refactor(tests): deduplicate WebSocket frame builder across token-tracker schema tests
  • GitHub: ✅
  • Playwright: ✅
  • File write: ✅
  • Build: ✅
  • Overall: PASS

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions

Copy link
Copy Markdown
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3 ❌ NO
Node.js v24.16.0 v22.22.3 ❌ NO
Go go1.22.12 go1.22.12 ✅ YES

Overall: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot.

Tested by Smoke Chroot

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results

  • Redis PING: ❌ (connection timed out to host.docker.internal:6379)
  • PostgreSQL pg_isready: ❌ (no response on port 5432)
  • PostgreSQL SELECT 1: ❌ (connection timed out)

host.docker.internal resolves to 172.17.0.1 but TCP connections to ports 6379 and 5432 both time out — services appear unreachable from this runner.

Overall: FAIL

🔌 Service connectivity validated by Smoke Services

@github-actions

Copy link
Copy Markdown
Contributor

🔭 Smoke Test: API Proxy OpenTelemetry Tracing

Scenario Result Notes
1. Module Loading ✅ Pass otel.js loaded; isEnabled()=true (endpoint configured); exports 12 functions incl. startRequestSpan, setTokenAttributes, endSpan
2. Test Suite ✅ Pass 59/59 tests passed across otel.test.js + otel-fanout.test.js
3. Env Var Forwarding ⚠️ Expected-pending Grep targets api-proxy-service.ts but OTEL vars live in api-proxy-service-config.ts (6 refs); functionally forwarded, step reports "expected during development"
4. Token Tracker Integration ✅ Pass onUsage callback present in token-tracker-http.js (lines 176, 251, 320)
5. OTEL Diagnostics i️ No spans No api-proxy span file at expected path — api-proxy not running during this run

Summary: Core OTEL implementation is healthy. Scenario 3 reports pending due to a path mismatch in the validation grep (checks api-proxy-service.ts; vars are in api-proxy-service-config.ts) — not a real gap.

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx 1/1 passed ✅ PASS
Node.js execa 1/1 passed ✅ PASS
Node.js p-limit 1/1 passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #5026 ·

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results: Gemini

Overall Status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • localhost

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini

@github-actions

Copy link
Copy Markdown
Contributor

@Copilot @lpcox refactor(tests): deduplicate WebSocket frame builder across token-tracker schema tests

  1. GitHub MCP: ✅
  2. github.com: ✅
  3. File I/O: ✅
  4. BYOK inference: ✅

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

🪪 BYOK (AOAI Entra) report filed by Smoke Copilot BYOK AOAI (Entra)

@github-actions

Copy link
Copy Markdown
Contributor

@Copilot @lpcox
Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw)

GitHub MCP API connectivity: ✅
github.com HTTP connectivity: ✅
File write/read: ✅
BYOK inference: ✅

Overall: PASS

🔑 BYOK (AOAI api-key) report filed by Smoke Copilot BYOK AOAI (api-key)

@lpcox lpcox merged commit a71f4b8 into main Jun 15, 2026
80 of 84 checks passed
@lpcox lpcox deleted the copilot/fix-duplicate-code-schema-tests branch June 15, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants