fix defects D1-D12 batch 1, structured envelope, saf gates + ops kill-switches

This commit is contained in:
Oleksandr Kozachuk
2026-07-13 12:56:32 +02:00
parent f1578cbd99
commit 6e5abf3d2c
14 changed files with 770 additions and 214 deletions
+5 -29
View File
@@ -6,7 +6,7 @@ import toml
from discord import Message, TextChannel, User
from fjerkroa_bot import FjerkroaBot
from fjerkroa_bot.ai_responder import AIMessage, AIResponse, parse_maybe_json
from fjerkroa_bot.ai_responder import AIMessage, AIResponse
class TestBotBase(unittest.IsolatedAsyncioTestCase):
@@ -26,9 +26,10 @@ class TestBotBase(unittest.IsolatedAsyncioTestCase):
"additional-responders": [],
}
self.history_data = []
with patch.object(FjerkroaBot, "load_config", new=lambda s, c: self.config_data), patch.object(
FjerkroaBot, "user", new_callable=PropertyMock
) as mock_user:
with (
patch.object(FjerkroaBot, "load_config", new=lambda s, c: self.config_data),
patch.object(FjerkroaBot, "user", new_callable=PropertyMock) as mock_user,
):
mock_user.return_value = MagicMock(spec=User)
mock_user.return_value.id = 12
self.bot = FjerkroaBot("config.toml")
@@ -56,31 +57,6 @@ class TestFunctionality(TestBotBase):
result = FjerkroaBot.load_config("config.toml")
self.assertEqual(result, self.config_data)
def test_json_strings(self) -> None:
json_string = '{"key1": "value1", "key2": "value2"}'
expected_output = "value1\nvalue2"
self.assertEqual(parse_maybe_json(json_string), expected_output)
non_json_string = "This is not a JSON string."
self.assertEqual(parse_maybe_json(non_json_string), non_json_string)
json_array = '["value1", "value2", "value3"]'
expected_output = "value1\nvalue2\nvalue3"
self.assertEqual(parse_maybe_json(json_array), expected_output)
json_string = '"value1"'
expected_output = "value1"
self.assertEqual(parse_maybe_json(json_string), expected_output)
json_struct = '{"This is a string."}'
expected_output = "This is a string."
self.assertEqual(parse_maybe_json(json_struct), expected_output)
json_struct = '["This is a string."]'
expected_output = "This is a string."
self.assertEqual(parse_maybe_json(json_struct), expected_output)
json_struct = "{This is a string.}"
expected_output = "This is a string."
self.assertEqual(parse_maybe_json(json_struct), expected_output)
json_struct = "[This is a string.]"
expected_output = "This is a string."
self.assertEqual(parse_maybe_json(json_struct), expected_output)
async def test_message_lings(self) -> None:
request = AIMessage(
"Lala",