fix(experiments): freeze clock in metricQueryUtils getQuery tests - #70244
Conversation
getQuery builds date_from/date_to from dayjs() at call time formatted to the minute (YYYY-MM-DDTHH:mm). The getQuery tests recompute the same dayjs() expressions independently in their expected values, so when a minute rollover falls between getQuery's internal read and the test's read, the two minute strings differ and toEqual fails. Seven tests share this pattern; it is why the file is auto-quarantined as flaky. Freeze the system clock file-wide (fake timers without advanceTimers, so it cannot move) at a fixed midday instant, making both reads resolve to the same time. Verified the mechanism deterministically (two dayjs reads straddling :59.999 -> :00.001 produce different minute strings) and ran the full file 10x green with the freeze. Generated-By: PostHog Code Task-Id: 579aeefd-dccd-4225-9813-79f735ee0c3f
🦔 Hogbox preview · ✅ ready▶ Open the preview
commit |
🤖 CI report✅ Bundle size — no changeUncompressed size of every built Total: 68.08 MiB · no change No file changed by more than 1000 B. Posted automatically by build-bundle-size-report · uncompressed bytes from dist-report ✅ Eager graph — within budgetHow much code each root ships on the eager path — downloaded and parsed before the surface is interactive. Measured from the esbuild output chunks (post-tree-shake, static imports only); lazy
🟢 Largest files eagerly shipped from
|
| Size | File |
|---|---|
| 126.8 KiB | ../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom.production.min.js |
| 24.6 KiB | ../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js |
| 6.3 KiB | ../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js |
| 4.5 KiB | ../node_modules/.pnpm/@jspm+core@2.1.0/node_modules/@jspm/core/nodelibs/browser/process.js |
| 3.9 KiB | ../node_modules/.pnpm/scheduler@0.23.2/node_modules/scheduler/cjs/scheduler.production.min.js |
| 1.4 KiB | ../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js |
| 1.3 KiB | src/RootErrorBoundary.tsx |
| 912 B | ../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js |
| 789 B | src/scenes/ChunkLoadErrorBoundary.tsx |
| 668 B | src/index.tsx |
Largest files eagerly shipped from src/scenes/AuthenticatedShell.tsx
| Size | File |
|---|---|
| 278.2 KiB | ../node_modules/.pnpm/posthog-js@1.399.2/node_modules/posthog-js/dist/rrweb.js |
| 266.9 KiB | ../node_modules/.pnpm/@posthog+icons@0.37.4_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@posthog/icons/dist/posthog-icons.es.js |
| 234.9 KiB | src/taxonomy/core-filter-definitions-by-group.json |
| 221.5 KiB | ../node_modules/.pnpm/posthog-js@1.399.2/node_modules/posthog-js/dist/module.js |
| 164.0 KiB | src/queries/validators.js |
| 154.2 KiB | ../node_modules/.pnpm/re2js@0.4.1/node_modules/re2js/build/index.esm.js |
| 126.8 KiB | ../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom.production.min.js |
| 105.9 KiB | src/lib/api.ts |
| 93.3 KiB | ../node_modules/.pnpm/prosemirror-view@1.40.1/node_modules/prosemirror-view/dist/index.js |
| 90.6 KiB | ../node_modules/.pnpm/@tiptap+core@3.20.6_@tiptap+pm@3.20.6/node_modules/@tiptap/core/dist/index.js |
Posted automatically by check-eager-graph · sizes are eager output bytes (shipped, post-tree-shake) from the esbuild metafile · part of #32479
✅ Dist folder size — no change
Total size of the built frontend/dist folder (all assets), compared against the base branch.
Total: 1283.90 MiB · no change
⚠️ Playwright — 1 failed
🎭 Playwright report · View test results →
❌ 1 failed test:
- Retention calculations, period, breakdown, and chart (chromium)
These issues are not necessarily caused by your changes.
Annoyed by this section? Help fix flakies and failures and it will go green!
There was a problem hiding this comment.
Test-only change freezing fake timers to fix a flaky date-comparison test; diff matches the description exactly, no risky territory touched, no outstanding concerns.
- 👍 on the PR from chatgpt-codex-connector[bot], hex-security-app[bot].
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| size | ✓ | 0L, 0F substantive, 12L/1F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T0 auto-approve: T0-deterministic (12L, 1F, single-area, fix) |
| stamphog 2.0.0b3 | .stamphog/policy.yml @ b7847a3 · reviewed head 05104b8 |
Problem
metricQueryUtils.test.tsis auto-quarantined as flaky by Trunk (e.g.getQuery returns the correct query for a mean metric with sum math type). ThegetQuerytests compare a query object whosedate_from/date_toare built fromdayjs().Changes
getQuery(inmetricQueryUtils.ts) computes the default date range at call time:Each
getQuerytest recomputes the identicaldayjs()expressions independently in its expected value. Both are formatted to the minute. When a minute rollover falls betweengetQuery's internaldayjs()read and the test's read, the two minute strings differ (e.g.12:34vs12:35) andtoEqualfails. Seven tests in the file share this pattern — a rare (~ms-per-minute) timing race, exactly the profile of an auto-quarantined flake.Freeze the system clock file-wide with fake timers at a fixed midday instant so both reads resolve to the same time. Deliberately not using
advanceTimers— the clock must not move, or the race persists. The freeze is harmless to the file's other (pure, date-independent) describe blocks.How did you test this code?
:59.999, read thedate_fromexpression (asgetQuerydoes), advanced ~2ms across the minute boundary, and read it again (as the test's expected value does) — the two minute strings differed, which is precisely what makestoEqualfail. (Scratch test removed; not part of this PR.)metricQueryUtils.test.tsfile 10x with the freeze: 10/10 green, no impact on the non-date describe blocks.The natural flake rate is far too low to catch in a practical repro loop, so validation is the deterministic mechanism demonstration above plus the frozen-clock fix that removes the nondeterminism at its source.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Authored by PostHog Code (Opus) working a flaky-test backlog. Pulled the quarantined-test list from Trunk's
list-quarantined-testsREST API (998 auto-quarantined tests), filtered to frontend, and picked this one because a pure-function test flaking points to a definite nondeterminism (here: unfrozendayjs()) rather than an environment race. Invoked the repo/fixing-flaky-testsskill. Fix follows the existingLemonCalendarSelect.test.tsxfake-timers idiom, adjusted to a frozen (non-advancing) clock so the minute-precision reads can't diverge.Created with PostHog Code