[PR #6211] [MERGED] refactor(tgbot): share numeric keypad transitions #6173

Closed
opened 2026-11-02 04:06:53 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6211
Author: @n0ctal
Created: 8/12/2026
Status: ✅ Merged
Merged: 8/13/2026
Merged by: @MHSanaei

Base: main ← Head: codex/upstream-tgbot-keypad-transition


📝 Commits (2)

  • f959420 refactor(tgbot): share numeric keypad transitions
  • 1a06376 Merge branch 'main' into codex/upstream-tgbot-keypad-transition

📊 Changes

3 files changed (+62 additions, -60 deletions)

View changed files

➕ internal/web/service/tgbot/numeric_input.go (+18 -0)
➕ internal/web/service/tgbot/numeric_input_test.go (+38 -0)
📝 internal/web/service/tgbot/tgbot_router.go (+6 -60)

📄 Description

Summary

The inline number pad's state transition is copy-pasted into six callback branches in tgbot_router.go. This extracts it into one unexported helper.

Why

The six copies are byte-for-byte identical: -2 clears, -1 drops the last digit, anything else appends. That is fine until one of them needs a change — a new clear key, a maximum length, a guard against overflow — at which point the change has to be made six times and reviewed six times, and missing one produces a keypad that behaves differently from its five siblings for reasons no one can see at the call site.

This is a pure extraction: no behaviour changes, no caller-specific validation is touched, and the button labels and callback payloads are untouched.

Scope

  • internal/web/service/tgbot/numeric_input.go: new updateNumericInput(value, key int) int, which reproduces the existing switch exactly.
  • internal/web/service/tgbot/tgbot_router.go: six branches call it.

Net effect on the router is 36 fewer lines.

Validation

  • TestUpdateNumericInput is a table test over reset, backspace, append and the zero case.
  • TestNumericInputTransitionIsUsedByEveryKeypad asserts there are six call sites, so a future keypad that open-codes the switch again is caught.
  • Mutation-checked: with tgbot_router.go reverted, that test fails with numeric keypad transition call sites = 0, want 6.
  • go build ./internal/..., go vet, internal/web/service/tgbot tests, golangci-lint, staticcheck -checks=U1000 (host and GOOS=linux), make gen-check: all clean.

Risk

Lowest of the set in behaviour and highest in review cost, since a reviewer has to satisfy themselves that all six copies really were identical. The helper is a verbatim copy of the block it replaces, and the transitions are covered by the table test. No Telegram or browser interaction was exercised.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6211 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 8/12/2026 **Status:** ✅ Merged **Merged:** 8/13/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `codex/upstream-tgbot-keypad-transition` --- ### 📝 Commits (2) - [`f959420`](https://github.com/MHSanaei/3x-ui/commit/f959420fff84e5083cf08ce2a7e572f9830e8b68) refactor(tgbot): share numeric keypad transitions - [`1a06376`](https://github.com/MHSanaei/3x-ui/commit/1a0637666abdefb0a9ba2d94ab38c2a456674357) Merge branch 'main' into codex/upstream-tgbot-keypad-transition ### 📊 Changes **3 files changed** (+62 additions, -60 deletions) <details> <summary>View changed files</summary> ➕ `internal/web/service/tgbot/numeric_input.go` (+18 -0) ➕ `internal/web/service/tgbot/numeric_input_test.go` (+38 -0) 📝 `internal/web/service/tgbot/tgbot_router.go` (+6 -60) </details> ### 📄 Description ## Summary The inline number pad's state transition is copy-pasted into six callback branches in `tgbot_router.go`. This extracts it into one unexported helper. ## Why The six copies are byte-for-byte identical: `-2` clears, `-1` drops the last digit, anything else appends. That is fine until one of them needs a change — a new clear key, a maximum length, a guard against overflow — at which point the change has to be made six times and reviewed six times, and missing one produces a keypad that behaves differently from its five siblings for reasons no one can see at the call site. This is a pure extraction: no behaviour changes, no caller-specific validation is touched, and the button labels and callback payloads are untouched. ## Scope - `internal/web/service/tgbot/numeric_input.go`: new `updateNumericInput(value, key int) int`, which reproduces the existing `switch` exactly. - `internal/web/service/tgbot/tgbot_router.go`: six branches call it. Net effect on the router is 36 fewer lines. ## Validation - `TestUpdateNumericInput` is a table test over reset, backspace, append and the zero case. - `TestNumericInputTransitionIsUsedByEveryKeypad` asserts there are six call sites, so a future keypad that open-codes the switch again is caught. - Mutation-checked: with `tgbot_router.go` reverted, that test fails with `numeric keypad transition call sites = 0, want 6`. - `go build ./internal/...`, `go vet`, `internal/web/service/tgbot` tests, `golangci-lint`, `staticcheck -checks=U1000` (host and `GOOS=linux`), `make gen-check`: all clean. ## Risk Lowest of the set in behaviour and highest in review cost, since a reviewer has to satisfy themselves that all six copies really were identical. The helper is a verbatim copy of the block it replaces, and the transitions are covered by the table test. No Telegram or browser interaction was exercised. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:53 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6173
No description provided.