test(browser-use): keep the capture-month rollover test ahead of the database clock (#23363)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents can use Browser Use Cloud. Paperclip records its usage cost
in the cost ledger and the monthly budget.
> - A server test checks that a usage change after a UTC month rollover
goes into the correct month. The test uses a fixed fake clock:
2026-11-30T23:59:59.900Z, then 2026-12-01T00:00:00.100Z.
> - Browser Use sessions get `next_poll_at` from the database `now()`.
The poll compares that value with the fake JavaScript clock.
> - After the real time passed 2026-11-30T23:59:59.900Z, the fake clock
was behind the database clock. The poll did not select the session, so
the test failed.
> - The test fails on every `master` commit since 2026-12-01. The
post-merge Cloud readiness check fails, the Core Docker image build
stops, and staging cannot get new Core commits.
> - This pull request calculates the rollover from the next UTC month
boundary after the real time. The fake clock is always ahead of the
database clock again.
> - The benefit is that `master` image builds and staging deploys can
continue. The test still checks the same month rollover.

## Linked Issues or Issue Description

**What happened?**
`server/src/__tests__/browser-use-connection.test.ts` > "dates a new
cumulative delta in its capture month and keeps that receipt's retry
time stable" fails on current `master`. The error is `expected { …(15) }
to match object { eventsDrained: +0, result: { …(1) } }`. The budget
hold shows `amountCents: "0.0000000"` and has no `accountedCentsExact`
or `receipt`, so the first usage report (0.15 USD) was not accounted.

**Expected behavior**
The test passes on any date. A test with a fake clock must not depend on
the real date.

**Steps to reproduce**
1. Check out `master` (for example 743c18f3b2) on or after 2026-12-01.
2. Run `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/browser-use-connection.test.ts -t "capture month"`.
3. See the test fail.

**Paperclip version or commit**
`master` at 743c18f3b2. The last green Core image build was fb6632530d
(2026-11-30T23:13Z).

## What Changed

- `server/src/__tests__/browser-use-connection.test.ts`: calculate
`before`, `after` and the later retry time from the next UTC month
boundary after the real time plus one day. Do not use fixed 2026 dates.
The test still crosses a UTC month boundary, and the assertions do not
change.

## Verification

- Red: on `master` (743c18f3b2), `pnpm --filter @paperclipai/server exec
vitest run src/__tests__/browser-use-connection.test.ts -t "capture
month"` fails with the error above.
- Green: with this change, `pnpm --filter @paperclipai/server exec
vitest run src/__tests__/browser-use-connection.test.ts` passes, 65/65.
- No product code changes.

## Risks

- Low risk. The change is in one test only. The test checks the same
rollover behavior at a later month boundary.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`) through Claude Code, with tool use
(shell, git, GitHub CLI).

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: devinfoley <139239+devinfoley@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-12-01 09:54:48 +00:00
1 parent 743c18f3b2
commit b3fd921cfb
1 file changed
+4 -2
@@ -1749,7 +1749,9 @@ const actor = { actorType: "user" as const, actorId: "browser-reviewer" };
});
it("dates a new cumulative delta in its capture month and keeps that receipt's retry time stable", async () => {
const f = await fixture();
const before = new Date("2026-11-30T23:59:59.900Z"), after = new Date("2026-12-01T00:00:00.100Z");
const ahead = new Date(Date.now() + 86_400_000);
const rollover = Date.UTC(ahead.getUTCFullYear(), ahead.getUTCMonth() + 1, 1);
const before = new Date(rollover - 100), after = new Date(rollover + 100);
vi.useFakeTimers({ toFake: ["Date"] });
try {
vi.setSystemTime(before);
@@ -1766,7 +1768,7 @@ const actor = { actorType: "user" as const, actorId: "browser-reviewer" };
expect(captured).toMatchObject({ eventsDrained: 0, result: { paperclipBudgetHold: {
accountedCentsExact: "15.0000000", receipt: { totalCentsExact: "20.0000000", occurredAt: after.toISOString() },
} } });
vi.setSystemTime(new Date("2026-12-01T00:00:05.100Z"));
vi.setSystemTime(new Date(rollover + 5_100));
f.usage("0.99");
await f.tick(); await f.tick();
const events = await db.select({ cents: sql<string>`${costEvents.costCents}::text`, occurredAt: costEvents.occurredAt })