♻️ 大幅重构,拆分模块,增加一些MCP相关限制
Some checks failed
Pyright Lint / Pyright Lint (push) Has been cancelled
Ruff Lint / Ruff Lint (push) Has been cancelled

This commit is contained in:
FuQuan233 2026-07-29 17:00:22 +08:00
parent 41e6aeacb9
commit 0d6771eca6
17 changed files with 1142 additions and 912 deletions

34
tests/test_persistence.py Normal file
View file

@ -0,0 +1,34 @@
# ruff: noqa: I001
import tempfile
from pathlib import Path
import unittest
import tests.bootstrap # noqa: F401
from nonebot_plugin_llmchat.config import PresetConfig, ScopedConfig
from nonebot_plugin_llmchat.persistence import StatePersistence
from nonebot_plugin_llmchat.state import StateStore
class PersistenceTests(unittest.IsolatedAsyncioTestCase):
async def test_private_state_loads_even_when_group_file_is_missing(self):
preset = PresetConfig(name="test", api_base="x", api_key="x", model_name="x")
config = ScopedConfig(
api_presets=[preset],
default_preset="test",
enable_private_chat=True,
private_chat_preset="test",
)
with tempfile.TemporaryDirectory() as directory:
group_file = Path(directory) / "groups.json"
private_file = Path(directory) / "private.json"
source = StateStore(config)
source.private_states[42].prompt = "remember me"
persistence = StatePersistence(config, source, group_file, private_file)
await persistence.save()
group_file.unlink()
restored = StateStore(config)
await StatePersistence(config, restored, group_file, private_file).load()
assert restored.private_states[42].prompt == "remember me"
assert not group_file.exists()