Skip to content

Commit c5ca145

Browse files
committed
test(P4.01): strengthen clamp assertions with overflow and precise value checks [codexPreflight]
1 parent 2bba91a commit c5ca145

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

src/lib/components/BarChart/barChartHelpers.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,62 @@ describe('createActiveHoursData', () => {
3636

3737
const result = createActiveHoursData(durations)
3838
const values = result.map((item) => item.value)
39+
expect(values[10]).toBe(0)
3940
expect(values.every((v) => v >= 0)).toBe(true)
4041
})
42+
43+
it('clamps same-hour accumulation at zero when a reversed segment exceeds prior minutes', () => {
44+
const durations: SupabaseDuration = {
45+
id: 'test',
46+
created_at: '2024-01-01',
47+
updated_at: '2024-01-01',
48+
date: '2024-01-01',
49+
data: [
50+
{
51+
time: 1704103200, // 2024-01-01 10:00 AM UTC
52+
duration: 1200, // +20 minutes
53+
color: null,
54+
project: 'test',
55+
language: 'TypeScript',
56+
category: 'coding',
57+
entity: 'test.ts',
58+
branch: 'main',
59+
ai_session: null,
60+
ai_additions: 0,
61+
ai_deletions: 0,
62+
human_additions: 0,
63+
human_deletions: 0,
64+
ai_input_tokens: 0,
65+
ai_output_tokens: 0,
66+
ai_prompt_length_sum: 0,
67+
ai_prompt_events: 0,
68+
},
69+
{
70+
time: 1704105000, // 2024-01-01 10:30 AM UTC
71+
duration: -1800, // -30 minutes, would underflow without clamping acc + delta
72+
color: null,
73+
project: 'test',
74+
language: 'TypeScript',
75+
category: 'coding',
76+
entity: 'test.ts',
77+
branch: 'main',
78+
ai_session: null,
79+
ai_additions: 0,
80+
ai_deletions: 0,
81+
human_additions: 0,
82+
human_deletions: 0,
83+
ai_input_tokens: 0,
84+
ai_output_tokens: 0,
85+
ai_prompt_length_sum: 0,
86+
ai_prompt_events: 0,
87+
},
88+
],
89+
}
90+
91+
const result = createActiveHoursData(durations)
92+
const values = result.map((item) => item.value)
93+
94+
expect(values[10]).toBe(0)
95+
expect(values.every((value, index) => index === 10 || value === 0)).toBe(true)
96+
})
4197
})

0 commit comments

Comments
 (0)