Skip to content

Commit 67fff3c

Browse files
committed
Numeric cli arguments should treat 0 as a real value
1 parent 0dbdfeb commit 67fff3c

2 files changed

Lines changed: 62 additions & 11 deletions

File tree

profile-query-cli/src/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,13 @@ async function main(): Promise<void> {
335335
let functionFilters: FunctionFilterOptions | undefined;
336336

337337
if (subcommand === 'markers') {
338-
const hasSearch = !!argv.search;
339-
const hasMinDuration = !!argv['min-duration'];
340-
const hasMaxDuration = !!argv['max-duration'];
341-
const hasCategory = !!argv.category;
338+
const hasSearch = argv.search !== undefined;
339+
const hasMinDuration = argv['min-duration'] !== undefined;
340+
const hasMaxDuration = argv['max-duration'] !== undefined;
341+
const hasCategory = argv.category !== undefined;
342342
const hasStack = argv['has-stack'];
343-
const hasLimit = !!argv.limit;
344-
const hasGroupBy = !!argv['group-by'];
343+
const hasLimit = argv.limit !== undefined;
344+
const hasGroupBy = argv['group-by'] !== undefined;
345345
const hasAutoGroup = argv['auto-group'];
346346

347347
if (
@@ -403,9 +403,9 @@ async function main(): Promise<void> {
403403

404404
// Parse function filter options if this is a functions command
405405
if (subcommand === 'functions') {
406-
const hasSearch = !!argv.search;
407-
const hasMinSelf = !!argv['min-self'];
408-
const hasLimit = !!argv.limit;
406+
const hasSearch = argv.search !== undefined;
407+
const hasMinSelf = argv['min-self'] !== undefined;
408+
const hasLimit = argv.limit !== undefined;
409409

410410
if (hasSearch || hasMinSelf || hasLimit) {
411411
functionFilters = {};
@@ -439,8 +439,8 @@ async function main(): Promise<void> {
439439
subcommand === 'samples-top-down' ||
440440
subcommand === 'samples-bottom-up'
441441
) {
442-
const hasMaxLines = !!argv['max-lines'];
443-
const hasScoring = !!argv.scoring;
442+
const hasMaxLines = argv['max-lines'] !== undefined;
443+
const hasScoring = argv.scoring !== undefined;
444444

445445
if (hasMaxLines || hasScoring) {
446446
callTreeOptions = {};

profile-query-cli/src/test/integration/basic.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,57 @@ describe('pq basic functionality', () => {
9494
expect(result2.stdout).toEqual(result1.stdout);
9595
});
9696

97+
test('numeric zero marker filters are preserved instead of being ignored', async () => {
98+
await pq(ctx, ['load', 'src/test/fixtures/upgrades/processed-1.json']);
99+
100+
const minDurationResult = await pq(ctx, [
101+
'thread',
102+
'markers',
103+
'--json',
104+
'--min-duration',
105+
'0',
106+
]);
107+
expect(minDurationResult.stdout).toContain('"minDuration": 0');
108+
109+
const maxDurationResult = await pq(ctx, [
110+
'thread',
111+
'markers',
112+
'--json',
113+
'--max-duration',
114+
'0',
115+
]);
116+
expect(maxDurationResult.stdout).toContain('"maxDuration": 0');
117+
});
118+
119+
test('numeric zero function filters are preserved instead of being ignored', async () => {
120+
await pq(ctx, ['load', 'src/test/fixtures/upgrades/processed-1.json']);
121+
122+
const result = await pq(ctx, [
123+
'thread',
124+
'functions',
125+
'--json',
126+
'--min-self',
127+
'0',
128+
]);
129+
130+
expect(result.stdout).toContain('"minSelf": 0');
131+
});
132+
133+
test('max-lines=0 is rejected instead of silently falling back to the default', async () => {
134+
await pq(ctx, ['load', 'src/test/fixtures/upgrades/processed-1.json']);
135+
136+
const result = await pqFail(ctx, [
137+
'thread',
138+
'samples-top-down',
139+
'--max-lines',
140+
'0',
141+
]);
142+
143+
expect(result.exitCode).not.toBe(0);
144+
const output = String(result.stdout || '') + String(result.stderr || '');
145+
expect(output).toContain('--max-lines must be a positive integer');
146+
});
147+
97148
test('build hash mismatch stops the daemon before cleaning up the session', async () => {
98149
const loadResult = await pq(ctx, [
99150
'load',

0 commit comments

Comments
 (0)