From a3d65a6b3d82baecfc90ba3925f1bddb8873c4e3 Mon Sep 17 00:00:00 2001 From: goodboy Date: Fri, 14 Aug 2026 09:34:05 -0400 Subject: [PATCH] Add a `pformat_caller_frame()` render guard test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `pformat_boxed_tb()` has never accepted an `indent` kwarg but `pformat_caller_frame(box_tb=True)` has been passing one since `888af602`. Nothing in the suite covered the branch, so the `TypeError` only ever surfaced from `_mk_send_mte()` — i.e. EVERY send-side `MsgTypeError` blew up while formatting itself and masked the real msg-spec violation behind a bogus `TypeError`. Red on purpose per the test-first convention; the 1-line fix lands next. Also pin `pformat_boxed_tb()`s signature so a future typo'd kwarg fails loudly at the call site instead of only when some rare error path runs. (this patch was generated in some part by `claude-code` using `claude-opus-5` (`anthropic`)) --- tests/devx/test_pformat.py | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/devx/test_pformat.py diff --git a/tests/devx/test_pformat.py b/tests/devx/test_pformat.py new file mode 100644 index 00000000..103e2556 --- /dev/null +++ b/tests/devx/test_pformat.py @@ -0,0 +1,52 @@ +''' +Unit tests for the `tractor.devx.pformat` render helpers. + +''' +from __future__ import annotations + +import pytest + +from tractor.devx.pformat import ( + pformat_boxed_tb, + pformat_caller_frame, +) + + +@pytest.mark.parametrize( + 'box_tb', + [True, False], + ids=['boxed', 'bare'], +) +def test_pformat_caller_frame_renders(box_tb: bool): + ''' + `pformat_caller_frame()` must render, not raise. + + XXX the `box_tb=True` branch was passing an `indent=''` kwarg + that `pformat_boxed_tb()` never accepted, so it blew up with + a `TypeError`. Nothing in the test suite covered it, and the + only caller is `_mk_send_mte()` — i.e. EVERY send-side + `MsgTypeError` died while formatting itself, masking the real + msg-spec violation behind a bogus `TypeError`. + + ''' + report: str = pformat_caller_frame( + stack_limit=3, + box_tb=box_tb, + ) + assert isinstance(report, str) + assert 'test_pformat_caller_frame_renders' in report + + +def test_pformat_boxed_tb_rejects_unknown_kwargs(): + ''' + Pin the signature so a future typo'd kwarg fails loudly at the + call site rather than only when some rare error path runs. + + ''' + assert pformat_boxed_tb(tb_str='doggy\n') + + with pytest.raises(TypeError): + pformat_boxed_tb( + tb_str='doggy\n', + indent='', + )