Skip to content

feat(model): add scripted chat model for tests - #1161

Open
March-77 wants to merge 1 commit into
cloudwego:mainfrom
March-77:agent/issue-1029-scripted-chat-model
Open

feat(model): add scripted chat model for tests#1161
March-77 wants to merge 1 commit into
cloudwego:mainfrom
March-77:agent/issue-1029-scripted-chat-model

Conversation

@March-77

Copy link
Copy Markdown

What type of PR is this?

feat

Check the PR title.

  • This PR title matches the format: <type>(optional scope): <description>.
  • The description is user-oriented and clear enough for others to understand.
  • The new testing API is documented inline and includes a runnable example.

(Optional) Translate the PR title into Chinese.

feat(model): 添加面向单元测试的可脚本化 ChatModel

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:

Eino users currently need to implement BaseChatModel manually or depend on gomock to test multi-turn agents and graphs. The generated mock under internal/ is intentionally unavailable to downstream applications.

This PR adds a dependency-free components/model/modeltest package with:

  • fluent turn-based scripts through OnTurn;
  • content-aware scripts through OnPrompt matchers;
  • complete messages, tool calls, errors, and scripted stream chunks;
  • matching Generate and Stream behavior, including concatenating stream chunks for Generate;
  • concurrency-safe call history with defensive message, tool, and common-option snapshots;
  • helper assertions such as LastUserMessage and LastToolMessageName;
  • immutable WithTools derivation implementing model.ToolCallingChatModel;
  • a runnable package example.

User impact: applications can unit-test ChatModelAgent, ReAct, and graph behavior without provider credentials, network calls, gomock setup, or handwritten model stubs.

Compatibility/risk: this is an additive package with no changes to existing interfaces or implementations. Each scripted expectation is consumed once, making missing or unexpected calls fail deterministically.

Validation:

  • go test ./components/model/modeltest -count=1 (pass)
  • go test -race ./components/model/modeltest -count=1 (pass)
  • go test ./... -count=1 (pass)
  • go vet ./... (pass)
  • gofmt -s and git diff --check (pass)
  • golangci-lint could not start because its first-time v2.12.2 download repeatedly stalled on github.com/MirrexOne/unqueryvet; both attempts were stopped after no progress.

zh(optional):

新增无外部依赖的可脚本化 ChatModel,支持按轮次或 Prompt 匹配响应、流式分片、工具调用、错误响应、调用历史及不可变工具绑定,供下游 Agent 和 Graph 单元测试直接使用。

(Optional) Which issue(s) this PR fixes:

Fixes #1029

(optional) The PR that updates user documentation:

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 提供面向用户层单元测试的可脚本化 MockChatModel

1 participant