Skip to content

fix: re-upload previous day's usage to catch mid-day updates#41

Merged
ohong merged 1 commit intoohong:mainfrom
jbyoung12:include-previous-date-in-npx-straude
Mar 12, 2026
Merged

fix: re-upload previous day's usage to catch mid-day updates#41
ohong merged 1 commit intoohong:mainfrom
jbyoung12:include-previous-date-in-npx-straude

Conversation

@jbyoung12
Copy link
Contributor

@jbyoung12 jbyoung12 commented Mar 11, 2026

Summary

  • Fixes issue where mid-day uploads miss end-of-day usage - e.g. I uploaded at noon yesterday. I continued working throughout the day. I didn't upload at the end of the day. Today I upload again but it only includes today's usage, missing the 2nd half of yesterday.
  • CLI now re-uploads the previous day's data when syncing to catch any updates
  • When last_push_date is yesterday, syncs yesterday + today (not just today)

Changes

  • Modified smart sync logic in packages/cli/src/commands/push.ts
  • When gap < MAX_BACKFILL_DAYS, includes last_push_date in sync range
  • Added test case for the 1-day gap scenario

Test plan

  • All 31 unit tests pass
  • Manually tested with straude --dry-run
  • Verified it syncs yesterday + today when gap = 1 day
  • Confirmed backward compatibility for other gap values

🤖 Generated with Claude Code

@vercel
Copy link

vercel bot commented Mar 11, 2026

@jbyoung12 is attempting to deploy a commit to the Pacific Systems Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2026

📝 Walkthrough

Walkthrough

The PR modifies the push command's backfill date calculation logic to conditionally include last_push_date when it falls within the maximum backfill window, and adds a test case covering the edge case where the date gap is exactly one day.

Changes

Cohort / File(s) Summary
Push Command Logic
packages/cli/src/commands/push.ts, packages/cli/__tests__/commands/push.test.ts
Modified backfill sinceDate calculation to use last_push_date directly when the gap is smaller than MAX_BACKFILL_DAYS, instead of always using a window-based calculation. Added test case validating the one-day gap scenario where since equals yesterday and until equals today.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit's push grows smart and keen,
Last date remembered, in-between,
One day gap caught with careful eyes,
Backfill windows, perfectly sized!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: re-upload previous day's usage to catch mid-day updates' directly addresses the main change: modifying sync logic to include the previous day's data when the gap is small, which catches mid-day updates.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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

@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.

🧹 Nitpick comments (1)
packages/cli/__tests__/commands/push.test.ts (1)

685-703: Consider adding a boundary test for gap = MAX_BACKFILL_DAYS - 1.

The critical boundary is at gap = 6 (should include last_push_date) vs gap = 7 (should cap and exclude it). Adding tests for both would strengthen confidence in the boundary condition.

🧪 Optional: boundary tests
it("includes last_push_date when gap is MAX_BACKFILL_DAYS - 1 (6 days)", async () => {
  const sixDaysAgo = daysAgoStr(6);
  mockLoadConfig.mockReturnValue({ ...fakeConfig, last_push_date: sixDaysAgo });
  mockRunCcusageRawAsync.mockResolvedValue("[]");
  mockParseCcusageOutput.mockReturnValue({ data: [] });

  await pushCommand({});

  const [sinceArg] = mockRunCcusageRawAsync.mock.calls[0]!;
  const expectedSince = sixDaysAgo.replace(/-/g, "");
  expect(sinceArg).toBe(expectedSince); // Should include last_push_date
});

it("excludes last_push_date when gap equals MAX_BACKFILL_DAYS (7 days)", async () => {
  const sevenDaysAgo = daysAgoStr(7);
  mockLoadConfig.mockReturnValue({ ...fakeConfig, last_push_date: sevenDaysAgo });
  mockRunCcusageRawAsync.mockResolvedValue("[]");
  mockParseCcusageOutput.mockReturnValue({ data: [] });

  await pushCommand({});

  const [sinceArg] = mockRunCcusageRawAsync.mock.calls[0]!;
  const expectedSince = daysAgoStr(6).replace(/-/g, ""); // Should be 6 days ago, not 7
  expect(sinceArg).toBe(expectedSince);
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cli/__tests__/commands/push.test.ts` around lines 685 - 703, Add two
boundary tests around MAX_BACKFILL_DAYS for the push flow: create one test that
sets last_push_date to daysAgoStr(MAX_BACKFILL_DAYS - 1) (6 days) and asserts
pushCommand calls mockRunCcusageRawAsync with sinceArg equal to that date
(formatted without dashes), and a second test that sets last_push_date to
daysAgoStr(MAX_BACKFILL_DAYS) (7 days) and asserts sinceArg is capped to
daysAgoStr(MAX_BACKFILL_DAYS - 1) instead of the 7-day date; reuse the existing
helpers and mocks (pushCommand, mockLoadConfig, mockRunCcusageRawAsync,
mockParseCcusageOutput, daysAgoStr) and the same pattern used in the existing
test to set up mocks and assert the first argument passed to
mockRunCcusageRawAsync.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/cli/__tests__/commands/push.test.ts`:
- Around line 685-703: Add two boundary tests around MAX_BACKFILL_DAYS for the
push flow: create one test that sets last_push_date to
daysAgoStr(MAX_BACKFILL_DAYS - 1) (6 days) and asserts pushCommand calls
mockRunCcusageRawAsync with sinceArg equal to that date (formatted without
dashes), and a second test that sets last_push_date to
daysAgoStr(MAX_BACKFILL_DAYS) (7 days) and asserts sinceArg is capped to
daysAgoStr(MAX_BACKFILL_DAYS - 1) instead of the 7-day date; reuse the existing
helpers and mocks (pushCommand, mockLoadConfig, mockRunCcusageRawAsync,
mockParseCcusageOutput, daysAgoStr) and the same pattern used in the existing
test to set up mocks and assert the first argument passed to
mockRunCcusageRawAsync.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7a42ad60-5154-4b3f-a8bb-eb749a243b4e

📥 Commits

Reviewing files that changed from the base of the PR and between 8fb42e8 and cc997c9.

📒 Files selected for processing (2)
  • packages/cli/__tests__/commands/push.test.ts
  • packages/cli/src/commands/push.ts

@ohong ohong merged commit 8b2fce7 into ohong:main Mar 12, 2026
1 of 2 checks passed
@ohong
Copy link
Owner

ohong commented Mar 12, 2026

Thanks for catching this @jbyoung12! Great find — the smart sync was silently dropping same-day usage because it never re-fetched last_push_date.

Your fix is merged. I applied one additional tweak on main: changed the boundary check from gap >= MAX_BACKFILL_DAYS to gap > MAX_BACKFILL_DAYS (single character). The >= comparison was excluding last_push_date when the gap was exactly 7 days, even though the server accepts a 7-day window. With >, gaps of 1–7 all include the last push date; only gaps exceeding 7 get capped.

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.

2 participants