Skip to content

Commit cbd64ac

Browse files
authored
test: cover Linear env key logging (#30)
Co-authored-by: Sober <zerone0x@users.noreply.github.com>
1 parent d097a06 commit cbd64ac

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

src/__tests__/config.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { getLinearApiToken } from '../utils/config.js';
2+
3+
describe('getLinearApiToken', () => {
4+
const originalArgv = process.argv;
5+
const originalEnv = process.env;
6+
let consoleErrorSpy: jest.SpyInstance;
7+
8+
beforeEach(() => {
9+
process.argv = ['node', 'mcp-linear'];
10+
process.env = { ...originalEnv };
11+
delete process.env.LINEAR_API_TOKEN;
12+
delete process.env.LINEAR_API_KEY;
13+
delete process.env.LINEAR_WEBHOOK_SECRET;
14+
delete process.env.MCP_LINEAR_DEBUG;
15+
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
16+
});
17+
18+
afterEach(() => {
19+
consoleErrorSpy.mockRestore();
20+
process.argv = originalArgv;
21+
process.env = originalEnv;
22+
});
23+
24+
it('does not log LINEAR environment variable keys when debug logging is disabled', () => {
25+
process.env.LINEAR_WEBHOOK_SECRET = 'present-but-not-a-token';
26+
27+
const token = getLinearApiToken();
28+
29+
expect(token).toBeUndefined();
30+
expect(consoleErrorSpy).toHaveBeenCalledWith('API token not found in command line args or environment variables');
31+
expect(consoleErrorSpy).not.toHaveBeenCalledWith(
32+
'Environment variables:',
33+
expect.arrayContaining(['LINEAR_WEBHOOK_SECRET']),
34+
);
35+
});
36+
37+
it('only logs LINEAR environment variable keys when explicit debug logging is enabled', () => {
38+
process.env.LINEAR_WEBHOOK_SECRET = 'present-but-not-a-token';
39+
process.env.MCP_LINEAR_DEBUG = 'true';
40+
41+
const token = getLinearApiToken();
42+
43+
expect(token).toBeUndefined();
44+
expect(consoleErrorSpy).toHaveBeenCalledWith(
45+
'Environment variables:',
46+
expect.arrayContaining(['LINEAR_WEBHOOK_SECRET']),
47+
);
48+
});
49+
});

0 commit comments

Comments
 (0)