Skip to content

test: add parseSSE coverage (src/client/stream.ts)#110

Merged
MiniMax-AI-Dev merged 1 commit intoMiniMax-AI:mainfrom
hell0gunawan:test/parse-sse-coverage
Apr 20, 2026
Merged

test: add parseSSE coverage (src/client/stream.ts)#110
MiniMax-AI-Dev merged 1 commit intoMiniMax-AI:mainfrom
hell0gunawan:test/parse-sse-coverage

Conversation

@hell0gunawan
Copy link
Copy Markdown

抱歉,这使用的是中文和英文混合版本。

简介 / Summary

本 PR 为 src/client/stream.ts 中的 parseSSE 函数添加了完整的测试覆盖。

测试用例 / Test Cases

用例 描述
单个事件解析 解析包含 data 字段的单个 SSE 事件
多事件解析 顺序解析多个 SSE 事件
事件类型字段 解析 event: 字段
ID 字段 解析 id: 字段
全字段事件 解析同时包含 id、event、data 的事件
注释行跳过 : 开头的注释行被正确跳过
多行数据连接 多行 data 字段使用 \n 正确连接
无冒号行处理 格式错误的行(无冒号)被正确跳过
空数据字段 data: (无值)被正确处理
空响应体 null body 响应(204)不抛出错误
Reader Lock 释放 迭代完成后正确释放 reader lock

覆盖率 / Coverage

指标 之前 之后
Line Coverage 0% 100%
Branch Coverage 0% 100%

说明 / Notes

  • 仅添加测试文件,不修改任何生产代码
  • 所有 126 个现有测试保持通过
  • 测试采用行为驱动方式,验证代码现有行为
  • 无破坏性变更

Summary

Adds 11 tests for parseSSE in src/client/stream.ts, bringing it from 0% to 100% line and branch coverage.

Why This Matters

parseSSE is core infrastructure used by all streaming commands (text chat, speech synthesize, video generation, etc.). Despite being a critical path, it had zero test coverage.

Test Cases

Case Description
Single event parsing Parses a single SSE event with data field
Multiple sequential events Parses sequential SSE events correctly
Event type field Parses event: field
ID field Parses id: field
All-fields event Parses event with id + event + data
Comment line skipping Lines starting with : are skipped
Multi-line data concatenation Multi-line data fields joined with \n
Missing-colon line handling Malformed lines (no colon) are skipped
Empty data field data: with no value handled correctly
Null body response 204 with null body does not throw
Reader lock release Reader lock released after iteration

Coverage

Metric Before After
Line 0% 100%
Branch 0% 100%

Notes

  • Only adds a test file — zero production code changes
  • All 126 existing tests continue to pass
  • Behavioral testing approach — validates existing behavior, no logic changes
  • No breaking changes

Note: This PR uses a Chinese + English bilingual description. If this causes inconvenience, please let me know and I will adjust.

Adds 11 tests covering the SSE parsing function used by all
streaming commands (text chat, speech synthesize, etc.).

Coverage: 0% -> 100% line, 0% -> 100% branch

Test cases:
- Single and multiple sequential SSE events
- event:, id:, data: field parsing
- Comment lines (": ...") are skipped
- Multi-line data concatenation
- Lines without colon (malformed) are skipped
- Empty data field handling
- Null body response
- Reader lock release after iteration
@hell0gunawan hell0gunawan force-pushed the test/parse-sse-coverage branch from 4d4faef to d9a1e6b Compare April 20, 2026 00:29
@MiniMax-AI-Dev MiniMax-AI-Dev merged commit 5f83544 into MiniMax-AI:main Apr 20, 2026
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.

2 participants