refactor: split token-tracker test file for maintainability#2970
Conversation
|
/copilot review |
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
|
Smoke Test Codex: FAIL 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.
|
🔥 Smoke Test Results — PR #2970
Overall: FAIL — MCP returned 401; HTTP code template variable was not substituted.
|
🔥 Smoke Test: Copilot BYOK (Offline) Mode
Running in BYOK offline mode ( Overall: PASS ✅
|
|
Smoke Test Results: ❌ GitHub MCP Testing (gh CLI auth failed) Status: FAIL (3/4 tests passed)
|
There was a problem hiding this comment.
Pull request overview
Refactors the containers/api-proxy token-tracker Jest suite by splitting a large monolithic test file into smaller, concern-specific suites to improve maintainability and failure localization, without changing production behavior.
Changes:
- Removed
containers/api-proxy/token-tracker.test.js(monolithic 1.3k-line suite). - Added focused test suites for parsing, HTTP tracking, WebSocket tracking, and schema validation.
- Adjusted suite-level token-log temp-dir setup to reduce cross-suite environment interference.
Show a summary per file
| File | Description |
|---|---|
| containers/api-proxy/token-tracker.test.js | Removed the monolithic token-tracker test suite in favor of split suites. |
| containers/api-proxy/token-tracker.parsing.test.js | Adds parsing-focused tests (JSON + SSE parsing/normalization). |
| containers/api-proxy/token-tracker.http.test.js | Adds HTTP tracking tests including compressed response cases. |
| containers/api-proxy/token-tracker.websocket.test.js | Adds WebSocket frame parsing and WS token usage tracking tests. |
| containers/api-proxy/token-tracker.schema.test.js | Adds schema validation + JSONL _schema behavior tests (including exact AWF_VERSION pin). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 5/5 changed files
- Comments generated: 4
| // Redirect token log output to a temp dir to avoid /var/log permission errors | ||
| // Keep a shared directory for the full Jest process to avoid cross-file env races. | ||
| const tokenLogDir = process.env.AWF_TOKEN_LOG_DIR || fs.mkdtempSync(path.join(os.tmpdir(), 'token-tracker-test-')); | ||
| process.env.AWF_TOKEN_LOG_DIR = tokenLogDir; | ||
|
|
| // Redirect token log output to a temp dir to avoid /var/log permission errors | ||
| // Keep a shared directory for the full Jest process to avoid cross-file env races. | ||
| const tokenLogDir = process.env.AWF_TOKEN_LOG_DIR || fs.mkdtempSync(path.join(os.tmpdir(), 'token-tracker-test-')); | ||
| process.env.AWF_TOKEN_LOG_DIR = tokenLogDir; | ||
|
|
| // Redirect token log output to a temp dir to avoid /var/log permission errors | ||
| // Keep a shared directory for the full Jest process to avoid cross-file env races. | ||
| const tokenLogDir = process.env.AWF_TOKEN_LOG_DIR || fs.mkdtempSync(path.join(os.tmpdir(), 'token-tracker-test-')); | ||
| process.env.AWF_TOKEN_LOG_DIR = tokenLogDir; | ||
|
|
| /** | ||
| * Tests for token-tracker.js | ||
| */ | ||
|
|
||
| const { | ||
| extractUsageFromJson, | ||
| extractUsageFromSseLine, | ||
| parseSseDataLines, | ||
| normalizeUsage, | ||
| } = require('./token-tracker'); |
Smoke Test Results — FAIL
Overall: FAIL —
|
🧪 Chroot Version Comparison Results
Overall: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot environments.
|
✨ Enhancement
containers/api-proxy/token-tracker.test.jshad grown to 1,324 lines and mixed four distinct concerns in one place, making failures harder to localize. This change decomposes that suite into concern-specific files without changing production code paths.Test suite decomposition
containers/api-proxy/token-tracker.test.js.containers/api-proxy/token-tracker.parsing.test.jscontainers/api-proxy/token-tracker.http.test.jscontainers/api-proxy/token-tracker.websocket.test.jscontainers/api-proxy/token-tracker.schema.test.jsResponsibility boundaries
extractUsageFromJson,extractUsageFromSseLine,parseSseDataLines,normalizeUsageisStreamingResponse,isCompressedResponse,trackTokenUsage(+ compressed response cases)parseWebSocketFrames,trackWebSocketTokenUsagevalidateTokenUsageRecord, JSONL_schemafield behavior, exact version pin behaviorSuite-level setup normalization