Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(mcp-analytics): pin the clock in the timeBuckets interval tests (#92557)

Rafael Audibert0a207f8d6561
diff --git a/products/mcp_analytics/frontend/timeBuckets.test.ts b/products/mcp_analytics/frontend/timeBuckets.test.ts
index 9b95310a07f7..508e02a36bba 100644
--- a/products/mcp_analytics/frontend/timeBuckets.test.ts
+++ b/products/mcp_analytics/frontend/timeBuckets.test.ts
@@ -144,6 +144,18 @@ describe('timeBuckets', () => {
})
describe('resolveInterval', () => {
+ // Relative windows resolve against the clock, so a -7d window that sits inside one calendar
+ // month on most days straddles two at a month boundary. Pin the clock mid-month, or those
+ // cases invert on the 1st of every month.
+ beforeEach(() => {
+ jest.useFakeTimers()
+ jest.setSystemTime(new Date('2026-06-15T12:00:00.000Z'))
+ })
+
+ afterEach(() => {
+ jest.useRealTimers()
+ })
+
// A pin outlives the window it was set on, so it has to give way once the window outgrows it:
// charting a year hour by hour also runs past the query's row limit, which drops the newest
// buckets. A pin that still fits has to beat the auto-choice — that's the point of pinning.
@@ -159,6 +171,15 @@ describe('timeBuckets', () => {
})
describe('intervalOptionsForWindow', () => {
+ beforeEach(() => {
+ jest.useFakeTimers()
+ jest.setSystemTime(new Date('2026-06-15T12:00:00.000Z'))
+ })
+
+ afterEach(() => {
+ jest.useRealTimers()
+ })
+
it('disables the intervals that would smear or collapse the window', () => {
expect(intervalOptionsForWindow('-1y', null, 'UTC')).toEqual([
{ value: 'hour', label: 'Hour', disabledReason: 'Range too long' },