From 218409cee3ca5e453920396c74b5378a73186454 Mon Sep 17 00:00:00 2001 From: Wright-Bot Date: Tue, 16 Jun 2026 23:41:40 +0200 Subject: [PATCH] Address a or for the python cli to address the problem where choosing any gro... --- qortium_cli/services.py | 13 ++++++++++++- qortium_cli/tools.py | 2 +- qortium_cli/tools/__init__.py | 2 +- tests/test_chat_commands.py | 3 +++ tests/test_chat_service.py | 36 +++++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 tests/test_chat_service.py diff --git a/qortium_cli/services.py b/qortium_cli/services.py index 7a8af83..dc293c5 100644 --- a/qortium_cli/services.py +++ b/qortium_cli/services.py @@ -726,9 +726,20 @@ def delete_local_arbitrary_resource( return (response.text or "").strip().lower() == "true" -def build_chat(ctx: AppContext, payload: Dict[str, Any], session: requests.Session) -> str: +def build_chat( + ctx: AppContext, + payload: Dict[str, Any], + session: requests.Session, + *, + tx_group_id: int | None = None, +) -> str: + params = None + if tx_group_id is not None: + params = {"txGroupId": int(tx_group_id)} + response = session.post( build_api_url(ctx, "/chat"), + params=params, json=payload, timeout=ctx.endpoint.timeout_seconds, ) diff --git a/qortium_cli/tools.py b/qortium_cli/tools.py index 4fcf98b..0ce28a0 100644 --- a/qortium_cli/tools.py +++ b/qortium_cli/tools.py @@ -1095,7 +1095,7 @@ def _send_chat_message(ctx: AppContext, message: str, *, chat_reference: str = " if chat_reference: payload["chatReference"] = chat_reference - unsigned_tx = build_chat(ctx, payload, session) + unsigned_tx = build_chat(ctx, payload, session, tx_group_id=tx_group_id) print("[2/4] Computing nonce (can take 10s-180s on lower-balance accounts)...", flush=True) try: diff --git a/qortium_cli/tools/__init__.py b/qortium_cli/tools/__init__.py index c7c09b9..25f1a90 100644 --- a/qortium_cli/tools/__init__.py +++ b/qortium_cli/tools/__init__.py @@ -1139,7 +1139,7 @@ def _send_chat_message(ctx: AppContext, message: str, *, chat_reference: str = " if chat_reference: payload["chatReference"] = chat_reference - unsigned_tx = build_chat(ctx, payload, session) + unsigned_tx = build_chat(ctx, payload, session, tx_group_id=tx_group_id) print("[2/4] Computing nonce (can take 10s-180s on lower-balance accounts)...", flush=True) try: diff --git a/tests/test_chat_commands.py b/tests/test_chat_commands.py index d048af6..91e2a12 100644 --- a/tests/test_chat_commands.py +++ b/tests/test_chat_commands.py @@ -365,6 +365,7 @@ def test_run_chat_edit_command_blank_input_cancels(self) -> None: def test_send_chat_message_includes_chat_reference_when_present(self) -> None: ctx = make_context() + ctx.chat.tx_group_id = 2 session = MagicMock() manager = MagicMock() manager.__enter__.return_value = session @@ -388,3 +389,5 @@ def test_send_chat_message_includes_chat_reference_when_present(self) -> None: payload = build_chat.call_args.args[1] self.assertEqual(payload["chatReference"], "sig-own") self.assertEqual(payload["data"], "encoded-message") + self.assertEqual(payload["txGroupId"], 2) + self.assertEqual(build_chat.call_args.kwargs["tx_group_id"], 2) diff --git a/tests/test_chat_service.py b/tests/test_chat_service.py new file mode 100644 index 0000000..eb8d6bf --- /dev/null +++ b/tests/test_chat_service.py @@ -0,0 +1,36 @@ +from pathlib import Path +from unittest import TestCase +from unittest.mock import MagicMock + +from qortium_cli.models import AccountSettings, AppContext, ChatSettings, EndpointSettings +from qortium_cli.services import build_chat + + +def make_context() -> AppContext: + return AppContext( + settings_dir=Path("."), + endpoint=EndpointSettings(base_url="http://127.0.0.1:24891", timeout_seconds=15), + account=AccountSettings(), + chat=ChatSettings(), + debug=False, + ) + + +class ChatServiceTests(TestCase): + def test_build_chat_sends_selected_group_as_request_param(self) -> None: + ctx = make_context() + session = MagicMock() + response = MagicMock() + response.text = "unsigned" + session.post.return_value = response + + result = build_chat(ctx, {"txGroupId": 2, "data": "encoded"}, session, tx_group_id=2) + + self.assertEqual(result, "unsigned") + session.post.assert_called_once_with( + "http://127.0.0.1:24891/chat", + params={"txGroupId": 2}, + json={"txGroupId": 2, "data": "encoded"}, + timeout=15, + ) + response.raise_for_status.assert_called_once_with()