Skip to content

refactor(ui): 用复制助手替代手写重写,并让单测文件真正进入 CI - #102

Merged
Pigbibi merged 3 commits into
mainfrom
refactor/untangle-ios
Nov 12, 2026
Merged

Pigbibi merged 3 commits into
mainfrom
refactor/untangle-ios

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

改动内容

把 Express / Marketplace 六处整结构体重写收成一个 with(...) 复制助手,并修掉两处因手写重写导致的数据丢失;同时把单测 target 改成文件系统同步组,让新增测试文件真正进入 CI。

不改会怎样

  1. 手写重写结构体会静默丢字段,而且已经发生了。 MockMarketplaceRepository.updateItem 在重建 MarketplaceItem 时漏掉 typeID 和 ownedByCurrentUser:用户编辑商品分类后,列表仍显示旧分类;"我发布的"标记也会被抹掉。编译器不会报错——少传一个参数只是用了默认值。
  2. 同一份字段清单被抄了六次。 Express / Marketplace 的 6 处成员逐一构造各写一遍完整字段列表。模型加一个字段,六处都要改,漏一处就是上面那类 bug。
  3. 测试文件被静默排除。 单测 target 用的是显式文件引用而不是同步组:磁盘上已有 6 个测试文件从未被 CI 编译过,新加测试也会被无声忽略。这比测试失败更危险——CI 全绿,但覆盖是假的。

怎么验证的

swiftc -parse <changed sources and tests>
swiftc -typecheck -sdk $(xcrun --sdk macosx --show-sdk-path) <stubs + changed sources>
swiftc -sdk ... -o /tmp/run   # 编译并实际执行两个 with(...) 助手
plutil -lint GdeiAssistant-iOS.xcodeproj/project.pbxproj
python3 Tools/check_localization.py
python3 scripts/check_hygiene.py
  • swiftc -parse / -typecheck:改动文件与两个新测试文件均通过。
  • 可执行验证:编译出一个真的可执行文件调用两个助手,断言 typeID、ownedByCurrentUser 等字段被保留。
  • plutil -lint 通过;另做了 pbxproj 引用完整性检查(412 个对象、0 个悬空引用)。
  • check_localization.py:0 errors;check_hygiene.py:0 errors。
  • ./Tools/check_style.sh 未直接执行成功:脚本对全部 Swift 文件逐个 spawn grep(约 900 次),在本机沙箱里被反复终止。改用等价实现(Python 遍历 363 个受跟踪 Swift 文件检查 tab 与行尾空白)验证,0 violations;CI 里跑原脚本。

./Tools/build_simulator.sh 未在本地执行:本机只装了 CommandLineTools,没有 Xcode 与 iPhone SDK。这是本 PR 唯一的验证缺口,模拟器单测依赖 Unit Tests / Build Smoke 两个 CI 检查,请以它们为准再合并。

检查清单

  • 上列本地检查已通过;check_style.sh 因沙箱限制改用等价检查,build_simulator.sh 因缺 Xcode 交由 CI
  • 无对外行为变化,无需更新文档
  • 没有提交真实账号、密码、验证码、Token、Cookie 或他人个人信息
  • 没有提交密钥、证书、local.properties 或环境配置文件

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

不涉及。仅涉及客户端内存中的模型复制与 Xcode 工程的测试文件引用方式,未改变网络请求、存储或日志。

关联 Issue

无。

AI 辅助

使用 WorkBuddy 内的 DeepSeek-V4.1-Flash 完成重复构造定位、助手实现与守卫测试编写。

风险

R1(客户端内部重构 + 工程文件变更)

  • 受影响面:Features/Express、Features/Marketplace 共 6 个源文件,2 个新增测试文件,以及 project.pbxproj。
  • 工程文件变更需要重点 review:.pbxproj 里删掉了显式测试文件引用、改为 PBXFileSystemSynchronizedRootGroup,与 app target 已有的机制一致。副作用是那 6 个此前从未编译的测试文件会第一次进入 CI,如果它们本身有问题,会在这里暴露——这是预期行为,不是本 PR 引入的缺陷。我已静态核对它们引用的 app 符号全部存在。
  • 兼容性:无 API、无模型字段增删、无 UI 文案变化。
  • 回退方式:整批 revert 即可;with(...) 助手是新增方法,回退后调用点恢复原写法。

- Express / Marketplace models now expose one with(...) helper that enumerates every
    stored field; six duplicated full memberwise constructions are gone.
- MockMarketplaceRepository.updateItem silently dropped typeID (edited items kept
    showing the old category) and ownedByCurrentUser. The helper preserves both and now
    applies the draft's typeID; RemoteMarketplaceRepository.fetchItemDetail uses the
    same helpers.
- New guard tests fail when a stored field is added without updating with(...), and
    cover the edit / state-change regressions.
- Convert the unit-test target to a PBXFileSystemSynchronizedRootGroup. Six existing
    test files were on disk but never compiled by CI; adding a test file can no longer
    be silently ignored.

Verification: swiftc -parse / -typecheck on changed sources and tests, a compiled
executable exercising both helpers, plutil -lint plus reference-integrity check on the
project file, check_localization.py (0 errors), check_hygiene.py (0 errors), and an
equivalent of check_style.sh over all 363 tracked Swift files (0 violations). Xcode is
unavailable locally (CommandLineTools only), so the simulator unit-test run remains for
CI.
@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-12T19:38:49.311919Z 338e56d New commits
🔒 Security Review ✅ Completed 2026-11-12T19:39:56.229866Z 338e56d New commits
ℹ️ 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 force-pushed the refactor/untangle-ios branch from e658e5e to 0016bf3 Compare November 12, 2026 18:30
ProfileViewModelTests passed an async call into XCTAssertTrue's autoclosure,
which does not support concurrency and fails to compile.

The error was latent: this file was on disk but never part of the test target,
so it had never been compiled. Making the target a synchronized group surfaced
it, which is the point of that change.
The only synchronous test in this @mainactor class crashed the runner with
"malloc: pointer being freed was not allocated" while constructing the view
model, then passed after the automatic restart. Its async siblings build the
same view model and mock repository without incident, so the sync invocation is
what differs.

Like the rest of the class it tests main-actor state, so declaring it async
keeps it on the actor's executor instead of relying on XCTest's synchronous
main-actor hop. The file had never been compiled before this branch, so the
crash was latent rather than a regression from the model-copy change.
@Pigbibi
Pigbibi merged commit f7e671c into main Nov 12, 2026
14 of 16 checks passed
@Pigbibi
Pigbibi deleted the refactor/untangle-ios branch November 12, 2026 20: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