Repository navigation
Conversation
乘客端「撥打司機電話」按鈕(O7)讀 drivers.phone,但這個欄位在此之前 沒有任何寫入路徑——註冊不收 phone、沒有更新端點,只有測試碼直接寫 DB。 結果是正式流程下號碼恆為空字串,撥號按鈕永遠不顯示,功能形同不存在。 刻意不把電話併進既有的 PUT /driver/vehicle:那條路徑的 UpdateVehicle 會把 vehicle_review_status 原子地重置為 pending(O5),司機每改一次 電話就會被審核 gate 踢出接單池。 - constants: NormalizePhone/IsValidPhone,寬鬆驗證(8–15 碼、允許開頭 +), 比照車牌的取捨不綁「09 開頭」樣式,以免誤擋市話與國際號碼 - repository: UpdatePhone 只寫 phone 與 updated_at - service: SetPhone,空字串=清除號碼(司機可收回不公開) - handler + route: PUT /api/driver/profile,driver_id 取自 token 測試:TestDriverSetPhone(含「改電話不影響車輛審核狀態」,已反向確認 注入迴歸後會 FAIL)、TestNormalizePhone/TestIsValidPhone。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jul 21, 2026
thothawei
added a commit
that referenced
this pull request
Jul 27, 2026
PR #42 的產品程式碼後來由別的 PR 進了 main,但它帶的兩個測試檔從未落地。 比對後只救這一個:internal/constants/phone_test.go。 main 目前對 NormalizePhone/IsValidPhone 的覆蓋只在 handler 層的 driver_profile_test.go,且只驗「4 碼失敗、正常手機通過」兩點。 本檔補上真正的邊界: - 有效:8 碼市話(下界)、市話含區碼、手機、+886 國際格式 - 無效:7 碼(短於下界)、16 碼(超過 E.164 上界)、全形數字、 夾雜英文字母、`+` 出現在開頭以外的位置、空字串 **刻意沒救 PR #42 的 internal/service/driver_phone_test.go**:它編碼的是當時的 行為假設,與 main 後來的決策衝突,跑起來會 FAIL—— - 它斷言 SetPhone("") 可清除電話,但 main 後來拍板「電話必填」而刻意擋空字串; - 它斷言 "0912-345-678a" 會被擋,但 main 是「先正規化再驗證」,字母會被 NormalizePhone 濾掉——這是 TODO 記載的刻意寬鬆(只驗位數不驗樣式, 硬綁格式會誤擋市話與境外號碼)。 把它救回來等於用過時的測試去推翻現行決策,所以丟棄。 Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Owner
Author
|
2026-07-27 逐一比對後關閉:本 PR 的產品程式碼已全數在 main(由後續 PR 帶入)。
不救 service 測試的理由:它編碼的是當時的行為假設,與 main 後來的決策衝突,實測 FAIL—— 分支 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題
乘客端「撥打司機電話」按鈕(O7)2026-07-17 就上線了,資料讀
driver_phone。但drivers.phone沒有任何寫入路徑——註冊不收、沒有更新端點,只有測試碼直接寫 DB。結果正式流程下號碼恆為空字串,App 端hasPhone永遠 false,這顆按鈕從來沒有真正出現過。做法
新開
PUT /api/driver/profile(driver JWT,driver_id取自 token)。刻意不把電話併進既有的
PUT /driver/vehicle:那條路徑的UpdateVehicle會把vehicle_review_status原子地重置為 pending(O5),司機每改一次電話就會被審核 gate 踢出接單池。constants:NormalizePhone/IsValidPhone——8–15 碼、允許開頭+。比照車牌的取捨不綁「09 開頭」樣式,否則市話與國際號碼會被誤擋repository.UpdatePhone: 只寫phone與updated_atservice.SetPhone: 空字串=清除號碼(司機可收回不公開)handler.UpdateProfile+ 路由驗證
go build ./...OKTestDriverSetPhone(正規化/清除/格式錯誤/改電話不影響車輛審核狀態)、TestNormalizePhone、TestIsValidPhone全綠UpdatePhone也重置審核 → 「改電話不影響車輛審核狀態」如預期 FAIL,已還原0912-345-678→ 回0912345678;存完再查車輛 →review_status:"approved"、can_accept:true;存12345→ 400「電話格式錯誤」;存""→ 清除成功GET /customer/rides/active首次真的帶出"driver_phone":"0912345678"相依
App 端對應 PR:thothawei/fleet-app(司機端填寫入口)。後端可先合,App 端沒有這支端點只會存不了電話,不影響既有功能。
🤖 Generated with Claude Code