Skip to content

feat: add unit tests for model client (_parse_response, MessageBuilder, ModelConfig)#411

Open
nankingjing wants to merge 2 commits into
zai-org:mainfrom
nankingjing:test/add-model-client-tests
Open

feat: add unit tests for model client (_parse_response, MessageBuilder, ModelConfig)#411
nankingjing wants to merge 2 commits into
zai-org:mainfrom
nankingjing:test/add-model-client-tests

Conversation

@nankingjing

@nankingjing nankingjing commented Jul 10, 2026

Copy link
Copy Markdown

Summary

Adds 24 unit tests for the phone_agent/model/client.py module. This is the second pure-logic test suite for the repository (following PR #410 which covered parse_action).

Module tested

phone_agent/model/client.py — the AI model client responsible for parsing raw model output and building OpenAI-format message dictionaries. _parse_response and MessageBuilder are fully deterministic, data-in/data-out functions — no network or device access needed, making them ideal for fast, hermetic unit tests.

Test classes (11 classes, 24 test cases)

Class Tests Covers
TestParseResponseFinish 3 Rule 1: content with finish(message=...)
TestParseResponseDo 3 Rule 2: do(action=...) parsing, incl. finish-takes-precedence
TestParseResponseLegacyXml 2 Rule 3: XML <think>/<answer> fallback (strip tags)
TestParseResponseFallback 2 Rule 4: no markers / empty string fallback
TestMessageBuilderSystem 1 create_system_message shape
TestMessageBuilderUser 2 create_user_message (text-only + with base64 image)
TestMessageBuilderAssistant 1 create_assistant_message shape
TestMessageBuilderRemoveImages 3 Image stripping from messages
TestMessageBuilderScreenInfo 3 build_screen_info JSON (incl. non-ASCII preservation)
TestModelConfigDefaults 3 Default values, mutable-field isolation, overrides
TestModelResponseDefaults 1 Dataclass defaults for performance metrics

Design

  • Pure and deterministic — no network, no device, no mocking required.
  • Follows the exact patterns established in PR #410 (tests/test_handler.py): pytest, one test class per rule/method, docstrings.
  • Documents the parsing precedence order (finish > do > XML <answer> > raw fallback).
  • Documents that build_screen_info preserves non-ASCII (Chinese) app names via ensure_ascii=False.

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