fix(audit): require integer phase0 summary row limits
Require non-negative integer maxSessions/maxChannels/maxSkipReasons in summary core and both phase0 summary/capture CLIs to prevent silent flooring of fractional values. Architecture/protocol diagrams reviewed; no flow or API shape changes required.
This commit is contained in:
@@ -222,6 +222,14 @@ describe('summarizePhase0Baseline', () => {
|
||||
expect(() => summarizePhase0Baseline(events, { maxChannels: -1 })).toThrow('maxChannels');
|
||||
expect(() => summarizePhase0Baseline(events, { maxSkipReasons: -1 })).toThrow('maxSkipReasons');
|
||||
});
|
||||
|
||||
it('rejects non-integer max limits', () => {
|
||||
const events: AuditEvent[] = [];
|
||||
|
||||
expect(() => summarizePhase0Baseline(events, { maxSessions: 1.5 })).toThrow('maxSessions');
|
||||
expect(() => summarizePhase0Baseline(events, { maxChannels: 1.5 })).toThrow('maxChannels');
|
||||
expect(() => summarizePhase0Baseline(events, { maxSkipReasons: 1.5 })).toThrow('maxSkipReasons');
|
||||
});
|
||||
});
|
||||
|
||||
describe('renderPhase0BaselineMarkdown', () => {
|
||||
|
||||
@@ -126,10 +126,13 @@ function normalizeLimit(value: number | undefined, optionName: string): number |
|
||||
if (!Number.isFinite(value)) {
|
||||
throw new Error(`${optionName} must be a finite number.`);
|
||||
}
|
||||
if (!Number.isInteger(value)) {
|
||||
throw new Error(`${optionName} must be an integer greater than or equal to 0.`);
|
||||
}
|
||||
if (value < 0) {
|
||||
throw new Error(`${optionName} must be greater than or equal to 0.`);
|
||||
}
|
||||
return Math.floor(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
function percentile(sortedAscending: number[], pct: number): number {
|
||||
@@ -197,7 +200,7 @@ function sortGroups(groups: Map<string, RunCounter>, limit?: number): RunOutcome
|
||||
});
|
||||
|
||||
if (typeof limit === 'number' && Number.isFinite(limit)) {
|
||||
return rows.slice(0, Math.floor(limit));
|
||||
return rows.slice(0, limit);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
@@ -213,7 +216,7 @@ function sortSkipReasons(reasons: Map<string, number>, limit?: number): Reaction
|
||||
}));
|
||||
|
||||
if (typeof limit === 'number' && Number.isFinite(limit)) {
|
||||
return rows.slice(0, Math.floor(limit));
|
||||
return rows.slice(0, limit);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user