Skip to content

Commit ceac013

Browse files
authored
fix: exclude test-utils from build, add shouldLog behavior tests
Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/ecadd9eb-35b3-4054-9be8-afffc1aa5c90
1 parent f182970 commit ceac013

4 files changed

Lines changed: 75 additions & 3 deletions

File tree

src/commands/logs-stats.test.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
*/
44

55
import { statsCommand, StatsCommandOptions } from './logs-stats';
6+
import { logger } from '../logger';
67
import { LogSource } from '../types';
7-
import { createLogCommandTestHarness } from './test-helpers';
8+
import { createLogCommandTestHarness } from './test-helpers.test-utils';
89

910
// Mock dependencies
1011
jest.mock('../logs/log-discovery');
@@ -161,4 +162,39 @@ describe('logs-stats command', () => {
161162
await expect(statsCommand(options)).rejects.toThrow('process.exit called');
162163
expect(harness.mockExit).toHaveBeenCalledWith(1);
163164
});
165+
166+
it('should emit source-selection info logs for non-JSON formats but suppress them for JSON', async () => {
167+
const mockSource: LogSource = {
168+
type: 'preserved',
169+
path: '/tmp/squid-logs-123',
170+
dateStr: 'Mon Jan 01 2024',
171+
};
172+
const emptyStats = {
173+
totalRequests: 0,
174+
allowedRequests: 0,
175+
deniedRequests: 0,
176+
uniqueDomains: 0,
177+
byDomain: new Map(),
178+
timeRange: null,
179+
};
180+
181+
harness.mockedDiscovery.discoverLogSources.mockResolvedValue([mockSource]);
182+
harness.mockedDiscovery.selectMostRecent.mockReturnValue(mockSource);
183+
harness.mockedAggregator.loadAndAggregate.mockResolvedValue(emptyStats);
184+
harness.mockedFormatter.formatStats.mockReturnValue('');
185+
186+
// pretty: shouldLog returns true → logger.info should be called
187+
await statsCommand({ format: 'pretty' });
188+
expect((logger.info as jest.Mock)).toHaveBeenCalled();
189+
(logger.info as jest.Mock).mockClear();
190+
191+
// markdown: shouldLog returns true → logger.info should be called
192+
await statsCommand({ format: 'markdown' });
193+
expect((logger.info as jest.Mock)).toHaveBeenCalled();
194+
(logger.info as jest.Mock).mockClear();
195+
196+
// json: shouldLog returns false → logger.info should NOT be called
197+
await statsCommand({ format: 'json' });
198+
expect((logger.info as jest.Mock)).not.toHaveBeenCalled();
199+
});
164200
});

src/commands/logs-summary.test.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
*/
44

55
import { summaryCommand, SummaryCommandOptions } from './logs-summary';
6+
import { logger } from '../logger';
67
import { LogSource } from '../types';
7-
import { createLogCommandTestHarness } from './test-helpers';
8+
import { createLogCommandTestHarness } from './test-helpers.test-utils';
89

910
// Mock dependencies
1011
jest.mock('../logs/log-discovery');
@@ -189,4 +190,39 @@ describe('logs-summary command', () => {
189190
await expect(summaryCommand(options)).rejects.toThrow('process.exit called');
190191
expect(harness.mockExit).toHaveBeenCalledWith(1);
191192
});
193+
194+
it('should emit source-selection info logs only for pretty format, suppress them for markdown and json', async () => {
195+
const mockSource: LogSource = {
196+
type: 'preserved',
197+
path: '/tmp/squid-logs-123',
198+
dateStr: 'Mon Jan 01 2024',
199+
};
200+
const emptyStats = {
201+
totalRequests: 0,
202+
allowedRequests: 0,
203+
deniedRequests: 0,
204+
uniqueDomains: 0,
205+
byDomain: new Map(),
206+
timeRange: null,
207+
};
208+
209+
harness.mockedDiscovery.discoverLogSources.mockResolvedValue([mockSource]);
210+
harness.mockedDiscovery.selectMostRecent.mockReturnValue(mockSource);
211+
harness.mockedAggregator.loadAndAggregate.mockResolvedValue(emptyStats);
212+
harness.mockedFormatter.formatStats.mockReturnValue('');
213+
214+
// pretty: shouldLog returns true → logger.info should be called
215+
await summaryCommand({ format: 'pretty' });
216+
expect((logger.info as jest.Mock)).toHaveBeenCalled();
217+
(logger.info as jest.Mock).mockClear();
218+
219+
// markdown: shouldLog returns false → logger.info should NOT be called
220+
await summaryCommand({ format: 'markdown' });
221+
expect((logger.info as jest.Mock)).not.toHaveBeenCalled();
222+
(logger.info as jest.Mock).mockClear();
223+
224+
// json: shouldLog returns false → logger.info should NOT be called
225+
await summaryCommand({ format: 'json' });
226+
expect((logger.info as jest.Mock)).not.toHaveBeenCalled();
227+
});
192228
});

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
"types": ["node", "jest"]
1818
},
1919
"include": ["src/**/*"],
20-
"exclude": ["node_modules", "dist", "**/*.test.ts"]
20+
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.test-utils.ts"]
2121
}

0 commit comments

Comments
 (0)