Skip to content

test(network): cover MemoRelationAdapter for v0.24/v0.25/v0.26 parsing#9

Draft
whtis wants to merge 1 commit into
mainfrom
night-shift/20260604-network-tests
Draft

test(network): cover MemoRelationAdapter for v0.24/v0.25/v0.26 parsing#9
whtis wants to merge 1 commit into
mainfrom
night-shift/20260604-network-tests

Conversation

@whtis

@whtis whtis commented Jun 3, 2026

Copy link
Copy Markdown
Owner

改动概述

  • Adds 10 JUnit tests for MemoRelationAdapter — the custom Moshi adapter that handles the three on-the-wire shapes Memos servers ship for memo relations across v0.24 / v0.25 / v0.26.
  • Wires up JUnit 4 as a testImplementation on :core:network (first test-implementation dependency in the repo, so also adds the junit entry to gradle/libs.versions.toml).
  • No production code touched.

为什么

Regressions in MemoRelationAdapter are silent and version-specific: comment threads or reference chips just stop rendering on one server build. Pinning every branch (string memo / object memo / numeric memo / null; string type / numeric 1+2 / numeric unknown / null; related_memo snake_case alias; unknown-field skip; round-trip toJson) makes any future refactor cheap to verify.

测试

  • ⚠️ 未本地验证 — 本机没装 Android SDK (ANDROID_HOME 未设置, ~/Library/Android/sdk 不存在),gradle 任务在 SDK location 检查阶段就 fail 了。
  • 测试代码逻辑与 MemoRelationAdapter.readMemoField / readTypeField 的每个 when 分支一一对应,目测可读。
  • 请在有 SDK 的机器上跑一次:
    ./gradlew :core:network:testDebugUnitTest
    预期 10 个用例全部通过。

Next step for reviewer

  1. Run ./gradlew :core:network:testDebugUnitTest locally — confirm 10 green.
  2. If green, gh pr ready → merge.
  3. If anything fails, the failure mode is informative (the test inputs are the exact JSON shapes the adapter is supposed to accept) — file a follow-up rather than reverting; the gap matters.

🌙 night-shift 自动生成;draft 状态等待人工 review。

`MemoRelationAdapter` is the seam between the Memos server's three
different on-the-wire shapes for memo relations:

  - v0.24 sometimes ships `memo` / `relatedMemo` as bare strings
  - v0.24/v0.25 ship `type` as a numeric proto enum (1 = REFERENCE,
    2 = COMMENT)
  - v0.26 ships `memo` / `relatedMemo` as objects with name/uid/snippet
    and `type` as a string

A regression in this adapter silently breaks comment threads, reference
chips, and the memo detail page across every supported server version,
but until now it had zero test coverage.

Adds 10 unit tests pinning every parsing branch (string / object /
numeric / null memo fields; string / numeric / unknown / null type
fields; snake_case alias; unknown-field skip; round-trip toJson),
plus the JUnit test-implementation wiring needed for `:core:network`
to host them. No production code changes.
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