Skip to content

Commit 6d9cc40

Browse files
committed
Fix CLI tests: mock logger to prevent analytics errors, normalize paths
- Mock logger module in image-dimensions.test.ts to prevent analytics initialization errors when processImageFile calls logger.debug() - Mock logger module in local-agents.test.ts for same reason - Use realpathSync to normalize paths in filePath assertion, handling macOS /var symlink to /private/var
1 parent 41c91d0 commit 6d9cc40

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

cli/src/__tests__/integration/local-agents.test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mkdtempSync, rmSync, writeFileSync, mkdirSync } from 'fs'
1+
import { mkdtempSync, rmSync, writeFileSync, mkdirSync, realpathSync } from 'fs'
22
import os from 'os'
33
import path from 'path'
44

@@ -13,6 +13,17 @@ import {
1313
spyOn,
1414
} from 'bun:test'
1515

16+
// Mock the logger to prevent analytics initialization errors in tests
17+
mock.module('../../utils/logger', () => ({
18+
logger: {
19+
debug: () => {},
20+
info: () => {},
21+
warn: () => {},
22+
error: () => {},
23+
fatal: () => {},
24+
},
25+
}))
26+
1627
import { setProjectRoot, getProjectRoot } from '../../project-files'
1728
import {
1829
loadAgentDefinitions,
@@ -396,7 +407,8 @@ describe('Local Agent Integration', () => {
396407
expect(uiAgent!.displayName).toBe('UI Display Agent')
397408
expect(uiAgent!.id).toBe('test-ui-agent')
398409
// File path should be populated for "Open file" UI links
399-
expect(uiAgent!.filePath).toBe(path.join(agentsDir, 'ui-agent.ts'))
410+
// Use realpathSync to normalize paths (on macOS, /var is a symlink to /private/var)
411+
expect(realpathSync(uiAgent!.filePath!)).toBe(realpathSync(path.join(agentsDir, 'ui-agent.ts')))
400412
})
401413

402414
test('loadLocalAgents sorts agents alphabetically by displayName', async () => {

cli/src/utils/__tests__/image-dimensions.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import { mkdirSync, rmSync } from 'fs'
22
import path from 'path'
33

4-
import { describe, test, expect, beforeEach, afterEach } from 'bun:test'
4+
import { describe, test, expect, beforeEach, afterEach, mock } from 'bun:test'
55
import { Jimp } from 'jimp'
66

77
import { setProjectRoot } from '../../project-files'
88
import { calculateDisplaySize } from '../image-display'
99
import { processImageFile } from '../image-handler'
1010

11+
// Mock the logger to prevent analytics initialization errors in tests
12+
mock.module('../logger', () => ({
13+
logger: {
14+
debug: () => {},
15+
info: () => {},
16+
warn: () => {},
17+
error: () => {},
18+
fatal: () => {},
19+
},
20+
}))
21+
1122
const TEST_DIR = path.join(__dirname, 'temp-test-images')
1223

1324
beforeEach(async () => {

0 commit comments

Comments
 (0)