Skip to content

fix(tests): use UTC in get_past_timestamp to fix cooldown tests on non-UTC systems#204

Open
timothy-20 wants to merge 2 commits intofrankbria:mainfrom
timothy-20:fix/test-cooldown-timezone
Open

fix(tests): use UTC in get_past_timestamp to fix cooldown tests on non-UTC systems#204
timothy-20 wants to merge 2 commits intofrankbria:mainfrom
timothy-20:fix/test-cooldown-timezone

Conversation

@timothy-20
Copy link

@timothy-20 timothy-20 commented Feb 27, 2026

Summary

Fix cooldown timer tests that fail on non-UTC systems (e.g., JST, EST) by using UTC in get_past_timestamp.

The get_past_timestamp helper generates ISO timestamps for testing cooldown expiration. Without explicit UTC, the timestamp uses the local timezone, but parse_iso_to_epoch expects UTC. This mismatch causes cooldown tests to incorrectly pass or fail depending on the system timezone.

Changes

  • tests/unit/test_circuit_breaker_recovery.bats — add -u flag to date command in get_past_timestamp

Test plan

  • Cooldown timer tests pass on UTC systems
  • Cooldown timer tests pass on non-UTC systems (e.g., TZ=Asia/Tokyo)

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Ensures timestamps produced by fallback routines are consistently formatted in UTC for both past and future timestamps, preventing inconsistent timezone display when system date behavior varies.

…n-UTC systems

The BSD date fallback in get_past_timestamp() used date -r which outputs
local time, but the format string hardcoded +00:00 (UTC). On non-UTC systems
(e.g. JST+9), parse_iso_to_epoch() interpreted the local time as UTC,
producing a future epoch and negative elapsed minutes, causing 5 cooldown
tests to always fail.

Adding -u flag to date -r ensures UTC output matching the +00:00 suffix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db8b237 and ed5a7c1.

📒 Files selected for processing (1)
  • tests/unit/test_circuit_breaker_recovery.bats
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unit/test_circuit_breaker_recovery.bats

Walkthrough

The test helper get_past_timestamp in tests/unit/test_circuit_breaker_recovery.bats was updated so fallback date calls use the -u flag, ensuring generated ISO timestamps are produced in UTC when GNU date patterns are unavailable. No other logic was changed.

Changes

Cohort / File(s) Summary
UTC Timestamp Formatting
tests/unit/test_circuit_breaker_recovery.bats
Added -u to fallback date -r invocations for both past and future epoch branches to force UTC ISO timestamp output.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I nibbled at time, found a stray hour,
Pushed in a small flag to steady the clock,
Now timestamps wear UTC like a bright flower,
Steady and true — no timezone will mock. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: fixing cooldown tests by ensuring UTC timestamps in get_past_timestamp for non-UTC systems.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/unit/test_circuit_breaker_recovery.bats (1)

226-234: ⚠️ Potential issue | 🟡 Minor

Same timezone bug exists in the clock skew test.

Line 233 uses date -r "$future_epoch" without the -u flag but hardcodes +00:00 in the format string—the same pattern that caused failures in get_past_timestamp. On non-UTC systems, this will output local time with an incorrect UTC suffix.

Proposed fix
-        future_timestamp=$(date -r "$future_epoch" +"%Y-%m-%dT%H:%M:%S+00:00" 2>/dev/null || skip "Cannot create future timestamp")
+        future_timestamp=$(date -u -r "$future_epoch" +"%Y-%m-%dT%H:%M:%S+00:00" 2>/dev/null || skip "Cannot create future timestamp")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/test_circuit_breaker_recovery.bats` around lines 226 - 234, The
test "Clock skew (negative elapsed time) stays OPEN safely" creates a future
timestamp using date -r without forcing UTC which leads to a wrong "+00:00"
suffix on non‑UTC systems; update the fallback command that sets
future_timestamp (the date -r "$future_epoch" +"%Y-%m-%dT%H:%M:%S+00:00" call)
to produce UTC output (e.g., add the -u flag or otherwise format in UTC) so the
timestamp and its "+00:00" suffix are consistent across timezones.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@tests/unit/test_circuit_breaker_recovery.bats`:
- Around line 226-234: The test "Clock skew (negative elapsed time) stays OPEN
safely" creates a future timestamp using date -r without forcing UTC which leads
to a wrong "+00:00" suffix on non‑UTC systems; update the fallback command that
sets future_timestamp (the date -r "$future_epoch" +"%Y-%m-%dT%H:%M:%S+00:00"
call) to produce UTC output (e.g., add the -u flag or otherwise format in UTC)
so the timestamp and its "+00:00" suffix are consistent across timezones.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ff27b4 and db8b237.

📒 Files selected for processing (1)
  • tests/unit/test_circuit_breaker_recovery.bats

Apply the same -u flag fix to the clock skew test's BSD date fallback
at L233, matching the get_past_timestamp fix at L96.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant