Skip to content

test: add unit tests for helpers (#815)#847

Merged
planetf1 merged 2 commits intogenerative-computing:mainfrom
planetf1:cs/issue-815
Apr 14, 2026
Merged

test: add unit tests for helpers (#815)#847
planetf1 merged 2 commits intogenerative-computing:mainfrom
planetf1:cs/issue-815

Conversation

@planetf1
Copy link
Copy Markdown
Contributor

@planetf1 planetf1 commented Apr 13, 2026

Misc PR

Type of PR

  • Bug Fix
  • New Feature
  • Documentation
  • Other

Description

41 new unit tests across async_helpers, openai_compatible_helpers, and server_type. Uses real objects throughout (no mocks). Follows project conventions (auto unit marker, asyncio_mode="auto").

Coverage

Module Before After
openai_compatible_helpers 8% 100%
async_helpers 28% 90%
server_type 95% 95%
Module Tests
openai_compatible_helpers extract_model_tool_requests (9), chat_completion_delta_merge (7), message_to_openai_message (4), messages_to_docs (4)
async_helpers send_to_queue (5), get_current_event_loop (2), ClientCache (3)
server_type _server_type (7 parametrised)

Remaining async_helpers gap (10%): wait_for_all_mots and _run_async_in_thread are one-liners that can't be meaningfully unit-tested without over-engineering. Both are implicitly exercised by e2e tests (parallel inference, sync-to-async bridging).

Testing

  • Tests added to the respective file if code was changed
  • New code has 100% coverage if code as added
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

Add 63 tests across openai_compatible_helpers, async_helpers, and
server_type covering critical gaps in pure functions used by every
OpenAI-compatible backend.

- extract_model_tool_requests: 9 tests (single/multi/unknown/null
  args/malformed JSON/mixed known+unknown)
- chat_completion_delta_merge: 7 tests (text/reasoning/tool assembly
  with index merging/force-separate/stop_reason)
- message_to_openai_message: 5 tests (text/images/empty images
  list/roles)
- messages_to_docs: 4 tests (empty/single/optional fields/across
  messages)
- send_to_queue: 5 tests (coroutine/async-iter/direct-iter/exception
  propagation)
- wait_for_all_mots: 2 tests (resolve all/empty list)
- get_current_event_loop: 2 tests (running/no-loop)
- ClientCache: 6 tests (put/get/evict-LRU/refresh/overwrite/size)
- _server_type: 7 parametrized tests (localhost variants/openai/
  unknown/malformed URL)

Fixes generative-computing#815
@github-actions
Copy link
Copy Markdown
Contributor

The PR description has been updated. Please fill out the template for your PR to be reviewed.

Remove tests that either test language builtins (OrderedDict.get,
len()), duplicate existing coverage (assistant_role vs text_only),
or can't meaningfully exercise the function under test without a
real pending thunk (wait_for_all_mots).
@planetf1 planetf1 marked this pull request as ready for review April 13, 2026 17:54
@planetf1 planetf1 requested a review from a team as a code owner April 13, 2026 17:54
Copy link
Copy Markdown
Contributor

@ajbozarth ajbozarth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a small nit from Claude

ran uv run pytest test/helpers/:

62 passed, 1 warning in 7.47s

result = message_to_openai_message(msg)
assert len(result["content"]) == 3 # 1 text + 2 images

def test_with_empty_images_list(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit from Claude:


No real caller passes images=[] — all production code uses None for "no images". This test covers a reachable-but-unreachable-in-practice code path caused by message_to_openai_message using is not None instead of a truthiness check. Fine to keep for coverage, but worth noting: if images=[] should ever be treated the same as images=None, the fix is a one-liner in the source (if msg.images: instead of if msg.images is not None:).


Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for pointer. I've not made a code change though currently.

@planetf1 planetf1 added this pull request to the merge queue Apr 14, 2026
Merged via the queue into generative-computing:main with commit f1d5cf4 Apr 14, 2026
13 of 14 checks passed
@planetf1 planetf1 deleted the cs/issue-815 branch April 14, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: unit tests for helpers (openai_compatible_helpers, async_helpers)

3 participants