Skip to content

fix(tests): stop faking timezone coverage on the vitest threads pool - #1970

Merged
h4yfans merged 1 commit into
mainfrom
fix-renderer-tz-test-trap
Sep 2, 2026
Merged

fix(tests): stop faking timezone coverage on the vitest threads pool#1970
h4yfans merged 1 commit into
mainfrom
fix-renderer-tz-test-trap

Conversation

@h4yfans

@h4yfans h4yfans commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Closes #1955

Problem

The renderer vitest project runs on vitest's threads pool, where process.env is a per-worker copy: assigning process.env.TZ at runtime never reaches the C++ tzset, so the process stays pinned to the host's zone regardless of what a test sets. journal-template-resolution.test.ts parameterised a describe('timezone', ...) block over three zones this way and passed tautologically — every case ran in the host zone.

Digging further: even with a working TZ knob, that test's coverage would still have been illusory. resolveJournalTemplateId's only timezone-sensitive step is parseISODate, which builds the Date from the string's Y/M/D parts (not a UTC parse), so the weekday it reads back is identical in every zone by construction — that invariance is the whole point of parseISODate over new Date(isoDate).

Changes

  • apps/desktop/src/renderer/src/lib/journal-template-resolution.test.ts — deleted the illusory in-process TZ matrix. Replaced with a genuine child-node test (the real coverage worth keeping): parseISODate reads 2026-08-17 as Monday in UTC, America/Los_Angeles, and Pacific/Kiritimati, proving the weekday stays correct across zones rather than shifting the way a UTC parse would.
  • apps/desktop/src/renderer/src/lib/test-support/run-in-tz.ts (new) — shared helper extracted from the two existing genuine child-process TZ tests (local-day-range.test.ts, journal-day-panel-day-range.test.tsx), so this pattern has one owner instead of getting re-copied (or re-broken) per file.
  • apps/desktop/src/renderer/src/lib/local-day-range.test.ts, apps/desktop/src/renderer/src/components/journal/journal-day-panel-day-range.test.tsx — switched to the shared helper, no behavior change.
  • apps/desktop/src/renderer/src/lib/renderer-process-env-tz-is-inert.test.ts (new) — proves the trap directly: asserts that flipping process.env.TZ in-process does not change the observed UTC offset across four zones, and cross-checks that the same flip in a real child process does.

apps/desktop/src/renderer/src/hooks/use-today.test.tsx and local-day-range.test.ts already carried the correct comment about this wall (from #1953/#1964); journal-template-resolution.test.ts was the one file silently relying on the broken pattern, now fixed to match.

Verification

  • pnpm --filter @memry/desktop typecheck:test — clean
  • Targeted vitest run on all four touched/added test files — 38/38 passing
  • pnpm exec eslint on the new non-test source file — clean

Docs gate: pushed with MEMRY_DOCS_IMPACT_SKIP=1test-support/run-in-tz.ts is internal test infrastructure only, no user-facing behavior or docs impact.

process.env.TZ never reaches tzset in the renderer vitest project (threads
pool copies process.env per worker), so journal-template-resolution.test.ts's
TZ matrix ran every case in the host zone and passed tautologically. Its real
guard -- that parseISODate reads a weekday from Y/M/D parts, not a UTC parse
-- now runs in a genuine child node process via a shared runInTz helper,
extracted from the two existing genuine child-process TZ tests. Added a test
that proves the trap directly: flipping process.env.TZ in-process leaves the
observed offset unchanged, while the same flip in a child process moves it.
@github-actions github-actions Bot added bug Something isn't working test labels Sep 2, 2026
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 453681a.

@h4yfans
h4yfans marked this pull request as ready for review September 2, 2026 18:00
@h4yfans
h4yfans merged commit ae5ae2d into main Sep 2, 2026
14 checks passed
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: process.env.TZ is inert in the renderer vitest project, so every timezone-parameterised renderer test is a false green

1 participant