Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions containers/api-proxy/guards/effective-token-guard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,7 @@ const {
getEffectiveTokenReflectState,
resetEffectiveTokenGuardForTests,
} = require('./effective-token-guard');

function collectLogOutput() {
const lines = [];
const spy = jest.spyOn(process.stdout, 'write').mockImplementation((data) => {
try {
lines.push(JSON.parse(data.toString()));
} catch {
// ignore non-JSON writes
}
return true;
});
return { lines, spy };
}
const { collectLogOutput } = require('../test-helpers/log-test-helpers');

describe('effective-token-guard reflect state', () => {
beforeEach(() => {
Expand Down
17 changes: 1 addition & 16 deletions containers/api-proxy/server.billing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const https = require('https');
const { EventEmitter } = require('events');

const { validateApiKeys, keyValidationResults, resetKeyValidationState, extractBillingHeaders } = require('./server');
const { collectLogOutput } = require('./test-helpers/log-test-helpers');

// ── Helpers for validateApiKeys tests ──────────────────────────────────────────

Expand All @@ -32,22 +33,6 @@ function mockHttpsRequestWithStatus(statusCode) {
});
}

/**
* Collect structured log lines emitted by logRequest() (written to process.stdout).
*/
function collectLogOutput() {
const lines = [];
const spy = jest.spyOn(process.stdout, 'write').mockImplementation((data) => {
try {
lines.push(JSON.parse(data.toString()));
} catch {
// ignore non-JSON writes
}
return true;
});
return { lines, spy };
}

function createValidationAdapter(name, probe) {
return {
name,
Expand Down
14 changes: 1 addition & 13 deletions containers/api-proxy/server.lifecycle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,7 @@ const { EventEmitter } = require('events');

const { fetchStartupModels, healthResponse, createProviderServer, resetModelCacheState } = require('./server');
const { createCopilotAdapter } = require('./providers/copilot');

function collectLogOutput() {
const lines = [];
const spy = jest.spyOn(process.stdout, 'write').mockImplementation((data) => {
try {
lines.push(JSON.parse(data.toString()));
} catch {
// ignore non-JSON writes
}
return true;
});
return { lines, spy };
}
const { collectLogOutput } = require('./test-helpers/log-test-helpers');

describe('healthResponse', () => {
afterEach(() => {
Expand Down
23 changes: 23 additions & 0 deletions containers/api-proxy/test-helpers/log-test-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

/**
* Spy on process.stdout.write and collect any structured JSON log lines emitted
* during a test. Call spy.mockRestore() (or jest.restoreAllMocks()) in afterEach
* to clean up.
*
* @returns {{ lines: object[], spy: jest.SpyInstance }}
*/
function collectLogOutput() {
const lines = [];
const spy = jest.spyOn(process.stdout, 'write').mockImplementation((data) => {
try {
lines.push(JSON.parse(data.toString()));
} catch {
// ignore non-JSON writes
}
return true;
});
return { lines, spy };
}

module.exports = { collectLogOutput };
Loading