Skip to content

test: add unit tests for openai_llm2_python ThinkParser#2150

Open
nuthalapativarun wants to merge 1 commit into
TEN-framework:mainfrom
nuthalapativarun:test/openai-llm2-python
Open

test: add unit tests for openai_llm2_python ThinkParser#2150
nuthalapativarun wants to merge 1 commit into
TEN-framework:mainfrom
nuthalapativarun:test/openai-llm2-python

Conversation

@nuthalapativarun
Copy link
Copy Markdown

Summary

  • Add 16 unit tests for ThinkParser in openai_llm2_python, covering the <think>...</think> reasoning-block parser used to handle streaming LLM responses from reasoning models (e.g. o1, DeepSeek-R1 style)
  • Add conftest.py that stubs ten_runtime and ten_ai_base so pure-Python helper tests run without a full TEN runtime installation
  • No changes to production code

What is tested

Test Coverage
test_plain_text_produces_message_delta Normal text emits message_delta
test_think_block_produces_reasoning_events Full block emits reasoning_delta + reasoning_done + message_delta
test_think_block_reasoning_content Correct content in delta/done events
test_message_after_think_block Text after </think> emitted as message_delta
test_empty_input_returns_no_events Empty string → no events
test_partial_open_tag_buffered Trailing <th is held in _pending
test_partial_open_tag_resolved_on_next_chunk Pending prefix flushed when next chunk rules out <think>
test_split_think_tag_across_chunks <thi / nk> split across calls still detected
test_state_returns_to_normal_after_think State machine resets after </think>
test_finalize_flushes_pending_normal finalize() drains _pending in NORMAL state
test_finalize_closes_open_think_block finalize() closes unclosed THINK block
test_multiple_think_blocks Two back-to-back blocks both produce reasoning_done
test_process_reasoning_content_emits_delta process_reasoning_content() path
test_process_reasoning_content_empty_closes_block Empty string closes THINK state
test_process_returns_false_for_plain_text Legacy process() bool return
test_process_returns_true_on_state_change process() returns True on state transition

Test plan

  • python3 -m pytest ai_agents/agents/ten_packages/extension/openai_llm2_python/tests/ -v16/16 passed
  • task format — clean (no production code changes)

ThinkParser handles <think>...</think> reasoning blocks in streaming
LLM responses but had no test coverage. Add 16 tests covering:
- Plain text message_delta events
- Full <think>...</think> block parsing (delta + done events)
- Partial open/close tag buffering across chunks
- Split tags across multiple chunks
- finalize() flushing pending buffer and open blocks
- Multiple think blocks in a single stream
- process_reasoning_content() API
- Legacy process() bool interface
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