Skip to content

Commit 15e7253

Browse files
committed
update logger tests
1 parent 90aea5f commit 15e7253

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

src/lib/host/logger.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import { LogLevel, type ILogger } from '../types';
22
import { createConsoleLogger } from '../utils';
33
import type * as vscode from 'vscode';
44

5-
export const disallowedLogKeys = ['password', 'secret', 'token', 'apiKey', 'apiSecret', 'content'];
5+
export const disallowedLogKeys: Set<string> = new Set([
6+
'password',
7+
'secret',
8+
'token',
9+
'apikey',
10+
'apisecret',
11+
'content',
12+
]);
613

714
function removePromptsFromData<T>(dictionary: T | undefined | null): T | undefined {
815
if (dictionary === null || dictionary === undefined) {
@@ -19,7 +26,7 @@ function removePromptsFromData<T>(dictionary: T | undefined | null): T | undefin
1926
try {
2027
const clone = structuredClone(dictionary) as Record<string, unknown>;
2128
for (const [key, value] of Object.entries(clone)) {
22-
if (disallowedLogKeys.includes(key.toLowerCase())) {
29+
if (disallowedLogKeys.has(key.toLowerCase())) {
2330
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
2431
delete clone[key];
2532
continue;
@@ -110,6 +117,9 @@ export const Logger: ILogger & {
110117
*/
111118
{
112119
setOutputChannel: (outputChannel: vscode.OutputChannel | undefined) => {
120+
if (LoggerImpl.outputChannel === outputChannel) {
121+
return;
122+
}
113123
LoggerImpl.dispose();
114124
LoggerImpl.outputChannel = outputChannel;
115125
},

tests/lib/host.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ describe('host module exports', () => {
1010

1111
expect(typeof Logger).toBe('object');
1212
expect(typeof getLogger).toBe('function');
13-
expect(Array.isArray(disallowedLogKeys)).toBe(true);
13+
// Recent change: disallowedLogKeys is now a Set
14+
expect(disallowedLogKeys instanceof Set).toBe(true);
1415
});
1516

1617
it('should export WebviewApiProvider', async () => {
@@ -52,13 +53,13 @@ describe('host module exports', () => {
5253
expect(typeof logger.debug).toBe('function');
5354
});
5455

55-
it('should have disallowedLogKeys array with expected values', async () => {
56+
it('should have disallowedLogKeys set with expected values', async () => {
5657
const { disallowedLogKeys } = await import('../../src/lib/host');
5758

58-
expect(disallowedLogKeys.length).toBeGreaterThan(0);
59-
expect(disallowedLogKeys).toContain('password');
60-
expect(disallowedLogKeys).toContain('token');
61-
expect(disallowedLogKeys).toContain('secret');
59+
expect(disallowedLogKeys.size).toBeGreaterThan(0);
60+
expect(disallowedLogKeys.has('password')).toBe(true);
61+
expect(disallowedLogKeys.has('token')).toBe(true);
62+
expect(disallowedLogKeys.has('secret')).toBe(true);
6263
});
6364

6465
it('should have working isViewApiRequest function', async () => {

tests/lib/host/logger.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ describe('host/logger', () => {
1111
mockOutputChannel.appendLine.mockClear();
1212
mockOutputChannel.dispose.mockClear();
1313

14+
// Route Logger output to the mocked VS Code output channel
15+
Logger.setOutputChannel(mockOutputChannel);
16+
1417
// Mock date for consistent timestamps
1518
originalDateNow = Date.prototype.toISOString;
1619
Date.prototype.toISOString = vi.fn(() => '2024-01-01T12:00:00.000Z');
@@ -19,6 +22,8 @@ describe('host/logger', () => {
1922
afterEach(() => {
2023
Date.prototype.toISOString = originalDateNow;
2124
vi.clearAllMocks();
25+
// Reset output channel between tests
26+
Logger.setOutputChannel(undefined);
2227
});
2328

2429
describe('Logger static methods', () => {
@@ -320,14 +325,10 @@ describe('host/logger', () => {
320325

321326
describe('disallowedLogKeys', () => {
322327
it('should export correct disallowed keys', () => {
323-
expect(disallowedLogKeys).toEqual([
324-
'password',
325-
'secret',
326-
'token',
327-
'apiKey',
328-
'apiSecret',
329-
'content',
330-
]);
328+
// Recent change: exported as Set with lowercase API keys
329+
expect(disallowedLogKeys).toEqual(
330+
new Set(['password', 'secret', 'token', 'apikey', 'apisecret', 'content'])
331+
);
331332
});
332333
});
333334

0 commit comments

Comments
 (0)