Skip to content

fix(portal): judge a card end's renewal on the card clock, in UTC - #631

Merged
devantler merged 2 commits into
mainfrom
claude/portal-month-edge
Nov 16, 2026
Merged

devantler merged 2 commits into
mainfrom
claude/portal-month-edge

Conversation

@devantler

Copy link
Copy Markdown
Contributor

🤖 Generated by the Agentic Engineer

Summary

TestPrivateCardRetriesAnEndAfterItsMonthPassed failed whenever it ran in the first hour or two of a month in Copenhagen: 00:00–01:00 in winter, 00:00–02:00 in summer. The product was right in that window; the test was not.

  • Why it failed. Copenhagen's month begins an hour or two before Stripe's renewal, which runs at 00:00 UTC on the 1st. The test took the month before the current Copenhagen month as one whose renewal has already passed. In the window that renewal is still ahead. scheduleCardEnd then correctly ends the subscription at the renewal, which charges nothing, rather than at once, which is what the test expected.
  • The test now uses the month before the current UTC month, whose renewal has always passed.
  • New test. TestPrivateCardEndWaitsForARenewalStillAhead pins the window at 2026-10-31 23:30 UTC, which is 00:30 on 1 November in Copenhagen. An end whose last month is October is scheduled at 2026-11-01 00:00 UTC, not at once.
  • The one code change. scheduleCardEnd reads the card configuration's clock (CardBilling.Now) instead of time.Now(). That is the clock the first-charge anchor and the webhook signature check already use. In production both are time.Now, so behaviour is unchanged; the test can now set the time. If time.Now() is put back, the new test fails because the cancel becomes immediate.

Audit of the other month decisions

Each one either follows Stripe's UTC 1st or dates invoices in Copenhagen, and none picks the wrong month in the window:

Decision Clock Window behaviour
First billed month (firstOfNextMonth) Copenhagen at order time An order at 00:30 on 1 December starts in January, and its anchor is 1 January 00:00 UTC
Subscription anchor (firstAnchor) UTC; once the month has begun, the next 1st (documented in BILLING.md) Copenhagen's month has begun but UTC's has not, so the anchor stays this month's 1st, about an hour later
Renewal period (applySubscriptionInvoicePaid) Stripe's renewal invoice created, read in Copenhagen 00:00 UTC on the 1st is 01:00 or 02:00 on the same 1st in Copenhagen, so both clocks give the same month
Client or operator end of a whole order Copenhagen month; Stripe cancels at 00:00 UTC on the next 1st An end at 00:30 on 1 December ends after December; December's renewal an hour later charges it, as recorded
End of one card add-on (#627) UTC month, because Stripe removes the item at once An end at 00:30 on 1 December ends after November, before December's renewal
Subscription ended by Stripe UTC month of ended_at less one second An end at the 1st's renewal records the month before
Numina invoices Copenhagen month and date Unaffected by UTC

The two end rules differ in the window, but each matches what Stripe charges. A whole-order end can wait for the renewal. An add-on item is removed at once, so the add-on cannot be billed for a month whose renewal comes after its removal.

Test plan

  • Both tests pass, and putting time.Now() back in scheduleCardEnd makes the new one fail
  • Full Go suite (-race, all cohorts) passes against the local fixture database
  • Spelling and Go lint checks pass locally

🤖 Generated with Claude Code

TestPrivateCardRetriesAnEndAfterItsMonthPassed failed in the first hour
or two of a Copenhagen month. It took the previous Copenhagen month as
one whose renewal had passed, but Stripe renews at 00:00 UTC, so in
that window the renewal is still ahead and the end is rightly scheduled
at it. The test now uses the previous UTC month.

scheduleCardEnd reads the card configuration's clock, like the
first-charge anchor, and a new test pins the window: an end whose last
month just ended in Copenhagen waits for Stripe's renewal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@devantler

Copy link
Copy Markdown
Contributor Author

🤖 Generated by the Agentic Engineer

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T03:37:53.486633Z 73e00f3 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: fbc0c3574f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

✅MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Max errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 1.58s
✅ CSS stylelint 1 0 0 0 2.25s
✅ GO golangci-lint yes yes no no 135.27s
✅ GO revive 191 0 0 0.97s
✅ HTML djlint 5 0 0 1.73s
✅ HTML htmlhint 5 0 0 0.6s
✅ JSON jsonlint 2 0 0 0.1s
✅ JSON prettier 2 0 0 0 0.5s
✅ JSON v8r 2 0 0 1.12s
✅ MARKDOWN markdownlint 17 0 0 0 2.02s
✅ MARKDOWN markdown-table-formatter 17 0 0 0 0.41s
✅ REPOSITORY betterleaks yes no no 0.84s
✅ REPOSITORY checkov yes no no 16.02s
✅ REPOSITORY git_diff yes no no 0.08s
✅ REPOSITORY grype yes no no 190.14s
✅ REPOSITORY osv-scanner yes no no 166.76s
✅ REPOSITORY secretlint yes no no 1.34s
✅ REPOSITORY syft yes no no 2.72s
✅ REPOSITORY trivy yes no no 17.5s
✅ REPOSITORY trivy-sbom yes no no 0.19s
✅ REPOSITORY trufflehog yes no no 2.4s
✅ SPELL cspell 218 0 0 6.02s
✅ SPELL lychee 24 0 0 143.91s

See detailed reports in MegaLinter artifacts

Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@10.2.0 --custom-flavor-setup --custom-flavor-linters COPYPASTE_JSCPD,CSS_STYLELINT,GO_GOLANGCI_LINT,GO_REVIVE,HTML_DJLINT,HTML_HTMLHINT,JSON_JSONLINT,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_BETTERLEAKS,REPOSITORY_GRYPE,REPOSITORY_OSV_SCANNER,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,SPELL_CSPELL,SPELL_LYCHEE

MegaLinter is provided by OX Security
Show us your support by starring ⭐ the repository

@github-code-quality

github-code-quality Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Go

Go / code-coverage/go

main claude/portal-month-... 73e00f3 +/-
— 77% —

Line coverage data for the main branch is not yet available.

View coverage of the 10 most covered files.
File main claude/portal-month-... 73e00f3 +/-
internal/identity/browser.go — 90% —
internal/webapp/app.go — 89% —
internal/identity/contact.go — 89% —
internal/custom...ity/material.go — 85% —
internal/identity/request.go — 82% —
internal/identi...ork_approval.go — 79% —
internal/identi...l_acceptance.go — 77% —
internal/identity/order.go — 77% —
internal/identity/card.go — 76% —
internal/identity/billing.go — 69% —

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 16, 2026 03:42 UTC

jscpd on #631: the two card end tests repeated the order and its
subscription's completion. subscribedCardOrderWith takes the one-time
amount; subscribedCardOrder keeps its callers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@devantler

Copy link
Copy Markdown
Contributor Author

🤖 Generated by the Agentic Engineer

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 73e00f3178

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@devantler
devantler marked this pull request as ready for review November 16, 2026 04:09
@devantler
devantler requested a review from a team as a code owner November 16, 2026 04:09
@devantler
devantler merged commit 0153e13 into main Nov 16, 2026
40 checks passed
@devantler
devantler deleted the claude/portal-month-edge branch November 16, 2026 04:09
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