Skip to content

refactor(ui): 表单校验与模块名映射各归一处 - #139

Merged
Pigbibi merged 1 commit into
masterfrom
refactor/untangle-android
Nov 12, 2026
Merged

Pigbibi merged 1 commit into
masterfrom
refactor/untangle-android

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

改动内容

把两组重复的表单校验规则和一个重复的模块名映射抽成单一实现,并补上校验器单测。

不改会怎样

跨文件重复块扫描发现三处「同一份知识抄了两份」:

  1. LostFoundEditViewModel 与 LostFoundPublishViewModel 各自维护同一条十一分支的校验链(标题/描述/地点/联系方式上限)。上限一改,两份就会漂移——编辑页能过、发布页不能过,而用户看到的是同一个表单。
  2. MarketplaceEditViewModel 与 MarketplaceViewModel 同样复制了价格与联系方式规则。
  3. 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 验证
  • 无行为变化,无需更新文档
  • 没有提交真实账号、密码、验证码、Token、Cookie 或他人个人信息
  • 没有提交密钥、证书、local.properties 或环境配置文件

涉及隐私、权限或数据流的改动

不涉及。仅调整表单校验的代码归属与模块名映射位置,未改变字段、请求参数、存储位置或日志内容。

关联 Issue

无。

AI 辅助

使用 WorkBuddy 内的 DeepSeek-V4.1-Flash 完成重复块扫描、抽取与测试编写。

风险

R1(纯 UI 层重构,无契约变化)

  • 受影响面:ui/lostfound、ui/marketplace、ui/messages 共 11 个文件。
  • 行为差异(有意保留):发布页独有的图片必填检查仍留在 LostFoundPublishViewModel;MarketplaceFormValidator 改为在校验成功后返回非空价格,因为跨函数调用后原来的 Kotlin smart cast 不再成立——这处如果不改会编译失败,不是可选优化。
  • 兼容性:无对外接口、无导航参数、无字符串资源增删。

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 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-12T18:23:35.596924Z edc9de5 PR opened
🔒 Security Review ✅ Completed 2026-11-12T18:25:35.140227Z edc9de5 PR opened
ℹ️ 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.

@Pigbibi
Pigbibi merged commit 03d5de5 into master Nov 12, 2026
14 of 15 checks passed
@Pigbibi
Pigbibi deleted the refactor/untangle-android branch November 12, 2026 19:04
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