Skip to content

test: explicitly use UTC timezone in tests - #1343

Merged
ryoppippi merged 1 commit into
ccusage:mainfrom
jonahsnider:test/explicit-utc
Jun 21, 2026
Merged

ryoppippi merged 1 commit into
ccusage:mainfrom
jonahsnider:test/explicit-utc

Conversation

@jonahsnider

@jonahsnider jonahsnider commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

I was running tests locally (PDT) and they failed since they didn't explicitly use UTC. This fixes the tests that failed for me.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Make tests explicitly use UTC to prevent timezone-dependent failures on local runs. Pass UTC to the parser and report generation tests so results are deterministic across environments.

Written for commit d3449fe. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Tests
    • Updated test cases to use explicit UTC timezone specifications for parsing and report generation operations to ensure consistent and deterministic test behavior.

@pullfrog

pullfrog Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

no API key found — this repo is configured to use deepseek/deepseek-v4-pro, which needs DEEPSEEK_API_KEY, but the runner has no key for it.

To fix: add the key as a GitHub Actions secret (referenced from your workflow's env: block) or as a Pullfrog secret in the console — or switch this repo to a different model (free models need no key).

Open repo secrets → · Configure model → · Setup docs → · Ask in Discord →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3cb1c4f6-823a-462d-86ca-da3fcfe1efda

📥 Commits

Reviewing files that changed from the base of the PR and between 02843ad and d3449fe.

📒 Files selected for processing (2)
  • rust/crates/ccusage/src/adapter/opencode/parser.rs
  • rust/crates/ccusage/src/main.rs

📝 Walkthrough

Walkthrough

Two unit tests are updated to supply an explicit UTC timezone instead of None when calling message_value_to_entry and adapter::codex::report_json, making snapshot and JSON report output deterministic.

Changes

Deterministic timezone in tests

Layer / File(s) Summary
opencode parser snapshot test: None → UTC timezone
rust/crates/ccusage/src/adapter/opencode/parser.rs
Parses a UTC timezone once and passes it as tz.as_ref() to both the "calculated" and "displayCost" message_value_to_entry calls, replacing None.
codex daily JSON report test: None → Some("UTC")
rust/crates/ccusage/src/main.rs
Changes the timezone argument in builds_codex_daily_json_report from None to Some("UTC") in the adapter::codex::report_json call.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 No more None to rule the clock,
UTC ticks tick-tock by tick-tock.
The snapshots now know where they stand,
A timezone held in each small hand.
Deterministic hops — how grand! 🕐

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@github-actions

Copy link
Copy Markdown
Contributor

This PR was auto-closed. Only contributors approved with lgtm can open PRs. Open an issue first.

Maintainers review auto-closed issues and reopen worthwhile ones. Issues that do not meet the quality bar in CONTRIBUTING.md may not be reopened or receive a reply.

If a maintainer replies lgtmi, your future issues will stay open. If a maintainer replies lgtm, your future issues and PRs will stay open.

See CONTRIBUTING.md.

@github-actions github-actions Bot closed this Jun 20, 2026
@ryoppippi ryoppippi reopened this Jun 21, 2026
@ryoppippi

Copy link
Copy Markdown
Member

@coderabbitai review it

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get the PR diff
gh pr view 1343 --repo ccusage/ccusage --json title,body,files,additions,deletions,commits
echo "---DIFF---"
gh pr diff 1343 --repo ccusage/ccusage

Length of output: 5160


🏁 Script executed:

#!/bin/bash
# Check if snapshot files exist and whether they were changed in this PR
fd -e snap . rust/ | head -30
echo "---"
# Check git diff for snapshot files
gh pr diff 1343 --repo ccusage/ccusage -- "*.snap" 2>/dev/null | head -100

Length of output: 3092


🏁 Script executed:

#!/bin/bash
# Check the relevant snapshot files
cat rust/crates/ccusage/src/adapter/opencode/snapshots/ccusage__adapter__opencode__parser__tests__snapshots_message_to_entry_variants_and_model_candidates.snap

echo "=== main.rs codex snapshot ==="
# Find snapshot for builds_codex_daily_json_report
fd -e snap . rust/crates/ccusage/src/ | xargs grep -l "builds_codex" 2>/dev/null
# Check the parse_tz function
rg -n "fn parse_tz" rust/

Length of output: 3003


🏁 Script executed:

#!/bin/bash
# Check parse_tz implementation
sed -n '215,240p' rust/crates/ccusage/src/date_utils.rs

echo "==="
# Check the builds_codex_daily_json_report test in main.rs
rg -n "builds_codex_daily_json_report" rust/ -A 50 | head -60

Length of output: 5144



@ryoppippi: The fix is correct and well-implemented. Here's a detailed review:


Review Summary ✅

The root cause is clear: format_date_tz falls back to JiffTimeZone::system() when no timezone is provided. In PDT (UTC−7), the test timestamp "2026-01-02T00:00:01.000Z" maps to the previous day (2026-01-01), causing assertions like report["daily"][0]["date"] == "2026-01-02" to fail.

rust/crates/ccusage/src/adapter/opencode/parser.rs

let tz = crate::parse_tz(Some("UTC"));

✅ Parsing the timezone once and reusing tz.as_ref() for both message_value_to_entry calls is clean and efficient.
✅ tz.as_ref() is the correct pattern to convert Option<JiffTimeZone> → Option<&JiffTimeZone> without moving.

rust/crates/ccusage/src/main.rs

Some("UTC"),  // was: None

✅ Passing Some("UTC") directly matches the Option<&str> parameter type of report_json.
✅ The test snapshot for this is assertion-based (not file-based), so no snapshot update is needed.


Minor observation (out of scope for this PR)

The prices_codex_versioned_models_like_typescript_adapter test immediately below (line 568) also uses a midnight-UTC timestamp ("2026-01-02T00:00:01.000Z"). If it asserts on a date field and passes None for timezone, it may have the same latent issue. Worth checking in a follow-up.


Overall: the fix is minimal, correct, and directly addresses the stated problem. The changes are well-scoped with no unnecessary modifications.

[approve]

@ryoppippi ryoppippi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@ryoppippi
ryoppippi merged commit 88246e6 into ccusage:main Jun 21, 2026
15 checks passed
@jonahsnider
jonahsnider deleted the test/explicit-utc branch June 21, 2026 18:25
@github-actions github-actions Bot mentioned this pull request Jul 9, 2026
@ryoppippi ryoppippi added the triage:resolved Resolved by a later change or current implementation. label Aug 31, 2026
@ryoppippi

Copy link
Copy Markdown
Member

Historical audit: this pull request was auto-closed by the legacy contributor gate. That closure did not assess technical importance.

Audit result: resolved. A later merged change or the current main implementation covers this request. This PR is kept for history and does not need to be revived.

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

Labels

triage:resolved Resolved by a later change or current implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants