Repository navigation
refactor(ui): 表单校验与模块名映射各归一处 - #139
Merged
Merged
Conversation
A cross-file duplicate-block scan found three places where the same knowledge was copied into two files: - LostFoundEditViewModel / LostFoundPublishViewModel each carried the same eleven-branch validation chain (title/description/location/contact limits). - MarketplaceEditViewModel / MarketplaceViewModel did the same for price and contact rules. The two copies could drift when a limit changes. - InteractionListScreen / MessagesScreen each defined an identical interactionModuleLabel() mapping of module ids to string resources. Extract LostFoundFormValidator, MarketplaceFormValidator and a shared InteractionModuleLabels composable; all six call sites now use them. The publish-only image check stays in the publish view model, and the marketplace validator exposes a non-null price only after validation succeeds (the old code relied on a Kotlin smart cast that no longer applies across the call). Add unit tests for both validators (rule order, trimming, invalid prices). ANDROID_HOME=~/Library/Android/sdk ./gradlew --offline :app:testDebugUnitTest -> 233 tests, 0 failures.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
改动内容
把两组重复的表单校验规则和一个重复的模块名映射抽成单一实现,并补上校验器单测。
不改会怎样
跨文件重复块扫描发现三处「同一份知识抄了两份」:
LostFoundEditViewModel与LostFoundPublishViewModel各自维护同一条十一分支的校验链(标题/描述/地点/联系方式上限)。上限一改,两份就会漂移——编辑页能过、发布页不能过,而用户看到的是同一个表单。MarketplaceEditViewModel与MarketplaceViewModel同样复制了价格与联系方式规则。InteractionListScreen与MessagesScreen各写了一份完全相同的interactionModuleLabel(),把 module id 映射到字符串资源。新增一个模块时漏改一处,其中一个页面就会显示原始 id。怎么验证的
ANDROID_HOME=~/Library/Android/sdk ./gradlew --offline :app:testDebugUnitTest结果:
233 tests, 0 failures(新增LostFoundFormValidatorTest、MarketplaceFormValidatorTest共 2 个测试类,覆盖规则顺序、首尾空白裁剪、非法价格)。./gradlew :app:lintDebug未在本地执行:本机 Android SDK 处于离线模式,lint 依赖的构件无法拉取。该检查由android-ci.yml覆盖。检查清单
:app:testDebugUnitTest已通过;:app:lintDebug未跑,原因见上,交由android-ci.yml验证local.properties或环境配置文件涉及隐私、权限或数据流的改动
不涉及。仅调整表单校验的代码归属与模块名映射位置,未改变字段、请求参数、存储位置或日志内容。
关联 Issue
无。
AI 辅助
使用 WorkBuddy 内的 DeepSeek-V4.1-Flash 完成重复块扫描、抽取与测试编写。
风险
R1(纯 UI 层重构,无契约变化)
ui/lostfound、ui/marketplace、ui/messages共 11 个文件。LostFoundPublishViewModel;MarketplaceFormValidator改为在校验成功后返回非空价格,因为跨函数调用后原来的 Kotlin smart cast 不再成立——这处如果不改会编译失败,不是可选优化。