mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6524] [MERGED] feat(clients): add calendar weekly renewal and schedule previews #6333
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6333
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6524
Author: @JacktheRanger
Created: 9/14/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @MHSanaei
Base:
main← Head:codex/client-calendar-weekly-renewal📝 Commits (9)
5baf87cfeat(clients): add calendar weekly renewal and schedule previews298f865fix(clients): validate renewal schedules across inbound write paths17a1764docs(clients): clarify depleted-client deletion risks on downgradec9c7277fix(clients): bound weekly renewal date searches21df360fix(tests): isolate weekly renewal preview timezonecf3d493Merge branch 'main' into codex/client-calendar-weekly-renewal39b6616ci: retrigger PR checks56f9707ci: retry PR checks and record deferred download hardening9f2f6d7Merge branch 'main' into codex/client-calendar-weekly-renewal📊 Changes
58 files changed (+2712 additions, -197 deletions)
View changed files
📝
.github/workflows/ci.yml(+5 -5)📝
docs/content/docs/en/config/clients.mdx(+63 -1)📝
docs/content/docs/en/reference/api/clients.mdx(+16 -1)📝
docs/content/docs/zh/config/clients.mdx(+53 -1)📝
docs/public/openapi.json(+210 -2)📝
frontend/public/openapi.json(+210 -2)📝
frontend/src/generated/examples.ts(+25 -0)📝
frontend/src/generated/schemas.ts(+113 -2)📝
frontend/src/generated/types.ts(+25 -0)📝
frontend/src/generated/zod.ts(+27 -0)📝
frontend/src/hooks/useClients.ts(+1 -0)📝
frontend/src/pages/api-docs/endpoints.ts(+46 -0)📝
frontend/src/pages/clients/ClientBulkAddModal.tsx(+10 -26)📝
frontend/src/pages/clients/ClientFormModal.tsx(+16 -29)➕
frontend/src/pages/clients/ClientRenewalFields.tsx(+197 -0)📝
frontend/src/schemas/client.ts(+3 -0)➕
frontend/src/test/client-bulk-calendar-renewal.test.tsx(+113 -0)➕
frontend/src/test/client-calendar-renewal.test.tsx(+109 -0)📝
frontend/src/test/client-toggle-traffic-reset.test.tsx(+20 -2)➕
internal/database/client_weekly_renew_migration_test.go(+90 -0)...and 38 more files
📄 Description
Motivation
#6517 handles month-end subscription-header presentation, but presentation is not an automatic-renewal schedule. Clients also need an explicit calendar-weekly option: a fixed seven-day interval is 168 hours and can move away from local midnight across DST. This follows the calendar/no-drift motivation of #6106 while preserving the billing-alignment behavior from #6457.
User-facing behavior
resetvalue are unchanged. Weekly mode cannot be combined with a positiveresetorresetDay.Implementation
resetWeekday/reset_weekdayto client settings, client records, and traffic records. AutoMigrate plus an idempotent NULL backfill defaults old clients to weekly renewal disabled while retaining existing limits, counters, and dates.POST /panel/api/clients/renewalPreview; reuse the existing job, without a second scheduler.Review follow-up (three separate commits)
Inbound write paths now reject invalid day/weekday combinations consistently with the client API; invalid imports must be corrected rather than silently coerced. Existing
reset+resetDaymonthly precedence remains accepted. No new schema, route, dependency, job, telemetry, or automatic deadline conversion is added by these follow-ups.CI race fix
21df360 fixes the test isolation failure reported by the CI race job on
c9c7277. The new exhaustion test temporarily replacedtime.Local, racing with background timer reads throughtime.Now; restoring the variable in cleanup was also unsafe. The earlier local race run passed but did not eliminate this scheduling-dependent failure.The public service still validates requests and resolves the panel timezone, then delegates its unchanged preview calculation with explicit timezone/current-instant arguments. The regression now passes the synthetic timezone locally, uses fixed dates for both suggestion and catch-up exhaustion, and needs no database setup or global timezone writes. A bounded-lifetime background clock reader reproduced the old race before the fix and remains in the test to catch future global mutations. API contracts, renewal behavior, persistence, and privacy are unchanged. The existing race job is retained without workflow changes.
Validation
Run locally with Go 1.27.1, Node 24.19.0, and a temporary PostgreSQL 17.10 instance; no production services or databases were used.
make verify— passed on the CI-isolation fix21df360: generated-file freshness, Go/frontend lint, formatting, typecheck, shuffled uncached Go tests, MSW-worker consistency, frontend/Chromium Storybook tests (156 files / 1,525 tests), production frontend/Go build, and Storybook build.make race— passed on the CI-isolation fix21df360: the full shuffled, uncached Go suite with the race detector and a 25-minute timeout.GODEBUG=tlsmlkem=0,http2client=0 gh run watch 34854598284 --repo MHSanaei/3x-ui --interval 45 --exit-status— exited successfully after the remote CI run on21df360completed. All eight jobs passed, including the full race suite (15m 3s), Go tests, PostgreSQL 16 durable-first/schema/migration checks, frontend, code generation, lint, fuzz smoke, and vulnerability scanning.GODEBUG=tlsmlkem=0,http2client=0 gh pr checks 6524 --repo MHSanaei/3x-ui— passed on21df360; all non-skipped checks succeeded, including CodeQL, documentation, and multi-platform builds. Rolling dev-release publishing is intentionally skipped for the pull request; no release or merge was performed.frontend/) passed:npx vitest run src/test/client-calendar-renewal.test.tsx --project components— 1 test.npx vitest run src/test/client-bulk-calendar-renewal.test.tsx --project components— 1 test.npx vitest run src/test/client-toggle-traffic-reset.test.tsx --project components— 2 tests.GIN_MODE=release go test ./internal/database/model ./internal/web/service ./internal/web/controller -run '^Test(MergeClientRecordRenewalModes|ClientRenewalWriteValidation|InboundRenewalModesRemainEditable|WeeklyRenewalSearchFailsClosed|NextWeeklyRenewal.*|ClientRenewalPreviewHTTP|ClientWeeklyRenewCRUD)$' -count=1— passed. Covers 27 rejected cases over nine write paths, 10 duplicate-record merge cases, valid inbound clients remaining toggleable, weekly search exhaustion and preview error handling, and the existing weekly/CRUD/HTTP cases. The write/merge regressions were red before their fix; exhaustion and incorrect preview failure reporting were also observed red before their respective guards.GIN_MODE=release go test -race ./internal/web/service -run '^TestWeeklyRenewalSearchFailsClosed$' -count=1— observed failing with concurrent clock reads before removing the global timezone writes; the report identified both assignment and cleanup races.GIN_MODE=release go test -race ./internal/web/service -run '^TestWeeklyRenewalSearchFailsClosed$' -count=100— passed after the fix, with the background clock reader active and explicit local timezone/current-instant arguments.GIN_MODE=release go test -race ./internal/web/service ./internal/web/controller -run '^Test(WeeklyRenewalSearchFailsClosed|NextWeeklyRenewal.*|ClientRenewalPreviewHTTP|ClientWeeklyRenewCRUD)$' -shuffle=1789394141536984216 -count=1— passed on the CI-isolation fix, reusing the failed CI run's shuffle seed for these targeted cases.c9c7277; the subsequent CI-isolation fix only changes the preview calculation boundary and its test, with no database, documentation-source, parser, or dependency changes.XUI_DB_TYPE=postgresandXUI_DB_DSN='host=127.0.0.1 port=55463 user=postgres dbname=xui_weekly_test sslmode=disable':go test ./internal/database -run '^(TestHostAutoMigrateCreatesColumns_Postgres|TestMigrate_Postgres|TestClientWeeklyRenewMigration_Postgres)$' -count=1 -v— all 3 top-level tests passed, including missing and nullable weekday-column upgrades in isolated schemas.go test ./internal/web/service -run 'PostgresCommitFailure' -count=1 -v— 2 tests passed, not skipped.docs/:pnpm gen:api;pnpm typecheck && pnpm lint && pnpm format:check && pnpm test— passed, 12 files / 106 tests. The typecheck/lint/format/test chain was rerun after the downgrade wording change.cmp frontend/public/openapi.json docs/public/openapi.jsonconfirms the published specification matches.go test -run '^$' -fuzz 'FuzzParseLink$' -fuzztime=30s -parallel=2 ./internal/util/link/andgo test -run '^$' -fuzz 'FuzzDecodeCertPin$' -fuzztime=30s -parallel=2 ./internal/web/runtime/— both passed.GODEBUG=tlsmlkem=0 GOPROXY=https://goproxy.io,direct make vulncheck— passed, 0 reachable vulnerabilities. The verbose scan reports the existing, unimportedopenpgpmodule advisory GO-2026-5932; no dependency changes are included. These overrides were only for the local checker after TLS-handshake timeouts, not application settings.Regressions cover real renewal writes/shared inbounds, finite and unlimited catch-up, manual disable, node renewal adoption, CRUD/filter/purge behavior, read-only HTTP preview and invalid requests, DST/skipped dates, monthly clamping/leap February, legacy last-second allowance accounting, form payloads, unset cutoffs, and first-use duration preservation. Weekly renewal, node adoption, and skipped-date tests were observed failing before their respective fixes.
Initial feature-validation attempts running verify/race in parallel collided on the network tests' fixed ports. Final follow-up runs were staggered so their Go network tests did not overlap, without changing those tests.
The first local
make verifyattempt for the CI-isolation fix failed in the unchanged Discord testTestGatewayRequestedHeartbeatDoesNotRaceTickerwith a connection reset during its heartbeat flood; the renewal/service package passed.GIN_MODE=release go test ./internal/web/service/discord -run '^TestGatewayRequestedHeartbeatDoesNotRaceTicker$' -shuffle=1789395109532532000 -count=20then passed, followed by a successful completemake verifyrerun. The CI run onc9c7277passed this package too. No Discord source, assertions, or CI configuration was changed.Compatibility, privacy, and scope
Upgrade the main panel and every participating node before enabling weekly mode. Older binaries ignore
resetWeekday, so weekly-only schedules would not renew and can be deleted by depleted-client cleanup after expiry or quota exhaustion. Back up the database and convert them to a mode supported by every participating version before downgrading; merely disabling weekly renewal does not protect depleted clients. Avoid cleanup while mixed versions or unconverted schedules remain. There is no automatic conversion of existing deadlines or renewal modes.The preview is authenticated and read-only. It sends only expiry/schedule/cap/count numbers to the panel, not client emails or credentials, and does not reserve allowances, mutate traffic, activate clients, or guarantee node availability. No external service, new telemetry, or new runtime dependency is introduced.
Independent periodic traffic-reset scheduling is unchanged and does not move expiry; renewal already resets traffic, so the form explains keeping the independent cycle disabled unless an extra reset is intended. The optional month-end subscription-header setting is unchanged. Quarterly, yearly, every-N-week/month schedules, and a linked quota-reset mode are intentionally left out. No live Xray/node deployment or client-app end-to-end run was performed; node reconciliation is covered with traffic snapshots. PostgreSQL 16 coverage remains for the existing upstream CI job.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.