b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
81 lines
2.7 KiB
Python
81 lines
2.7 KiB
Python
"""Tests for cli._prepend_note_to_message.
|
|
|
|
Regression coverage for the TypeError raised when a queued /model or
|
|
/reload-skills note was prepended to a multimodal (image-attached) message:
|
|
``can only concatenate str (not "list") to str``.
|
|
"""
|
|
|
|
from cli import _prepend_note_to_message
|
|
|
|
|
|
def test_string_message_gets_note_prepended():
|
|
assert _prepend_note_to_message("hello", "NOTE") == "NOTE\n\nhello"
|
|
|
|
|
|
def test_empty_note_returns_message_unchanged():
|
|
assert _prepend_note_to_message("hello", "") == "hello"
|
|
assert _prepend_note_to_message("hello", " ") == "hello"
|
|
parts = [{"type": "text", "text": "hi"}]
|
|
assert _prepend_note_to_message(parts, "") == parts
|
|
|
|
|
|
def test_note_is_stripped():
|
|
assert _prepend_note_to_message("hello", " NOTE ") == "NOTE\n\nhello"
|
|
|
|
|
|
def test_empty_string_message_yields_just_note():
|
|
# No trailing blank lines when the user message is empty.
|
|
assert _prepend_note_to_message("", "NOTE") == "NOTE"
|
|
|
|
|
|
def test_empty_text_part_yields_just_note():
|
|
message = [
|
|
{"type": "text", "text": ""},
|
|
{"type": "image_url", "image_url": {"url": "x"}},
|
|
]
|
|
result = _prepend_note_to_message(message, "NOTE")
|
|
assert result[0]["text"] == "NOTE"
|
|
assert result[1]["type"] == "image_url"
|
|
|
|
|
|
def test_list_message_folds_note_into_first_text_part():
|
|
message = [
|
|
{"type": "text", "text": "describe this"},
|
|
{"type": "image_url", "image_url": {"url": "data:..."}},
|
|
]
|
|
result = _prepend_note_to_message(message, "NOTE")
|
|
|
|
assert result[0]["type"] == "text"
|
|
assert result[0]["text"] == "NOTE\n\ndescribe this"
|
|
# Image part is preserved untouched.
|
|
assert result[1] == {"type": "image_url", "image_url": {"url": "data:..."}}
|
|
# Original message is not mutated.
|
|
assert message[0]["text"] == "describe this"
|
|
|
|
|
|
def test_image_only_list_gets_leading_text_part():
|
|
message = [{"type": "image_url", "image_url": {"url": "data:..."}}]
|
|
result = _prepend_note_to_message(message, "NOTE")
|
|
|
|
assert result[0] == {"type": "text", "text": "NOTE"}
|
|
assert result[1]["type"] == "image_url"
|
|
|
|
|
|
def test_list_message_does_not_raise_typeerror():
|
|
# The exact #repro shape: multimodal list + queued note must not raise
|
|
# "can only concatenate str (not 'list') to str".
|
|
message = [
|
|
{"type": "text", "text": "look"},
|
|
{"type": "image_url", "image_url": {"url": "x"}},
|
|
]
|
|
result = _prepend_note_to_message(
|
|
message, "Model switched to gpt-5.5 (provider: openai-codex)."
|
|
)
|
|
assert isinstance(result, list)
|
|
assert result[0]["text"].startswith("Model switched to gpt-5.5")
|
|
|
|
|
|
def test_unknown_shape_returned_unchanged():
|
|
assert _prepend_note_to_message(123, "NOTE") == 123
|
|
assert _prepend_note_to_message(None, "NOTE") is None
|