Chat shows an MCOimg pixel image as a short line instead of Base91 noise

A message whose body is an MCOimg image (im3:, or im: for v1/v2) now reads
"🎨 image · 24×24 · 16 colours" in the transcript and the Messages preview.
The v3 header gives the size and the palette; the pixels are not decoded yet.
The Base91 text no longer makes false mention chips, links, or QR codes.
Checked against all 51 reference vectors. Refs #37.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-11-19 21:58:45 -05:00
1 parent 696ac634b9
commit 017fdcfce7
9 files changed
+334 -10

No files matched your search

+17
View File
@@ -490,6 +490,12 @@ def test_preview_draws_the_author_and_the_mentions_as_the_transcript_does(powerl
assert _preview_text(named, _NO_KEYS, us=us).plain == f"{author} hi {me}"
def test_preview_shows_a_pixel_image_as_a_short_line() -> None:
"""The Base91 text of an MCOimg image is noise, so the preview shows what it is."""
image = ChatMessage(text="Bob: im3:g/5WjAL`NA", is_channel=True, channel_idx=0)
assert _preview_text(image, _NO_KEYS).plain.endswith("image · 4×2 · 4 colours")
def test_preview_keeps_the_whole_message() -> None:
"""The preview is built whole. The cut of the row is the part that the ←→ scroll passes."""
long = ChatMessage(text="x" * 300, is_channel=True, channel_idx=0)
@@ -972,6 +978,17 @@ def test_chat_screen_shows_delivery_glyphs() -> None:
assert "^R" in screen.footer_hint
def test_a_pixel_image_shows_a_short_line_not_its_text() -> None:
"""A body that is an MCOimg image shows its size in place of its Base91 text."""
text = "im3:g/5WjAL`NA"
messages = [ChatMessage(text=text, peer="d4e5f6a7")]
screen = _screen(_StubSession(), send=None, messages=messages)
lines = [_strip_ansi(ln) for ln in screen._body_lines(text, messages[0], 60)]
assert len(lines) == 1
assert lines[0].endswith("image · 4×2 · 4 colours")
assert "g/5W" not in lines[0]
def test_wrapped_body_hangs_under_the_first_line() -> None:
"""A body that is too long for the width wraps with a hanging indent under its first line."""
from datetime import datetime, timezone
+63
View File
@@ -0,0 +1,63 @@
# SPDX-License-Identifier: Apache-2.0
"""Tests for the recognition of a pixel image (MCOimg) in the body of a message.
The cases come from the reference test vectors of the format
(``docs/mcoimg-js/tests/v3-js-*-fixtures.json`` and ``v2-js-fixtures.json`` in the
HDDen/meshcore-open repository, MIT). Each one is the text of an image and the size and
the palette profile that its encoder used.
"""
from __future__ import annotations
import pytest
from meshterm.core.mcoimg import PixelImage, base91_decode, recognize
#: (text, width, height, colours) from the version 3 vectors: one case for each mode of
#: the dimensions and for each palette profile that the vectors use.
_V3_CASES = [
("im3:g/5WjAL`NA", 4, 2, 4), # rawGlobal, master4, mode 1
("im3:g/LAU)", 1, 1, 4), # solidBackground, the shortest image
("im3:g/)FCtB", 2, 2, 4), # implicitWhiteSolid, mode 0
("im3:TAYL>iBNGbA", 9, 7, 2), # mono, from the encoder vectors
]
@pytest.mark.parametrize(("text", "width", "height", "colours"), _V3_CASES)
def test_a_version_3_image_gives_its_size_and_colours(
text: str, width: int, height: int, colours: int
) -> None:
assert recognize(text) == PixelImage(3, width, height, colours)
def test_base91_decodes_to_the_payload_of_the_vector() -> None:
"""``im3:g/5WjAL`NA`` is the app payload ``E3oBjQBCvgE=`` (base64) of the vectors."""
assert base91_decode("g/5WjAL`NA") == bytes.fromhex("137a018d0042be01")
def test_a_version_1_or_2_image_has_no_header_to_read() -> None:
assert recognize("im:CC&tj68MFSB") == PixelImage(None)
def test_spaces_at_the_ends_are_permitted() -> None:
assert recognize(" im3:g/5WjAL`NA \n") == PixelImage(3, 4, 2, 4)
@pytest.mark.parametrize(
"body",
[
"hello",
"im: ok", # a person typed it
"im:abc", # too short to be an image with no header
"im3:g/5WjAL`NA and more", # an image is the whole body
"see im3:g/5WjAL`NA",
"im3:hello", # Base91, but not the version 3 byte
"im:CC&tj68M'SB", # ' is not in the alphabet
],
)
def test_text_that_is_not_an_image(body: str) -> None:
assert recognize(body) is None
def test_an_unknown_version_is_an_image_with_no_header() -> None:
assert recognize("im4:CC&tj68MFSB") == PixelImage(4)