from __future__ import annotations import sys import unittest from pathlib import Path BACKEND_DIR = Path(__file__).resolve().parents[1] if str(BACKEND_DIR) not in sys.path: sys.path.insert(0, str(BACKEND_DIR)) from rpa_engine.douyin_im.pb_decode import analyze_send_response class AnalyzeSendResponseTests(unittest.TestCase): def test_standalone_kick_json_is_not_decoded_as_protobuf(self): result = analyze_send_response(b'{"decision": "KICK"}') self.assertFalse(result["ok"]) self.assertEqual(result["decision"], "KICK") self.assertEqual(result["summary"], "JSON响应 decision=KICK") self.assertNotIn("unsupported wire type", result["summary"]) def test_malformed_json_still_returns_controlled_decode_summary(self): result = analyze_send_response(b'{"decision":') self.assertFalse(result["ok"]) self.assertIn("解码失败", result["summary"]) if __name__ == "__main__": unittest.main()