test/cli: isolate oneshot chat from user-data database

This commit is contained in:
2026-07-21 22:44:26 +08:00
parent b06bb1d409
commit db7c097466
+17 -2
View File
@@ -69,15 +69,22 @@ access_key_or_token = "sk"
def test_chat_oneshot_success(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: def test_chat_oneshot_success(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
config = tmp_path / "plyngent.toml" config = tmp_path / "plyngent.toml"
# Ephemeral file DB under tmp_path — never the user's durable chat.db.
# (Unset/empty [database].url is rewritten to ~/.local/share/plyngent/chat.db.)
db_path = tmp_path / "test-chat.db"
_ = config.write_text( _ = config.write_text(
""" f"""
[database]
implementation = "sqlite"
url = "{db_path.as_posix()}"
[providers.local] [providers.local]
preset = "openai-compatible" preset = "openai-compatible"
url = "https://example.com/v1" url = "https://example.com/v1"
access_key_or_token = "sk" access_key_or_token = "sk"
[providers.local.models] [providers.local.models]
"tiny" = {} "tiny" = {{}}
""", """,
encoding="utf-8", encoding="utf-8",
) )
@@ -128,6 +135,11 @@ access_key_or_token = "sk"
lambda _p: DummyClient(), lambda _p: DummyClient(),
) )
from platformdirs import user_data_path
global_db = user_data_path("plyngent") / "chat.db"
global_mtime = global_db.stat().st_mtime if global_db.exists() else None
runner = CliRunner() runner = CliRunner()
result = runner.invoke( result = runner.invoke(
main, main,
@@ -149,6 +161,9 @@ access_key_or_token = "sk"
) )
assert result.exit_code == EXIT_OK assert result.exit_code == EXIT_OK
assert "pong" in result.output assert "pong" in result.output
assert db_path.is_file()
if global_mtime is not None:
assert global_db.stat().st_mtime == global_mtime
def test_chat_help_mentions_prompt() -> None: def test_chat_help_mentions_prompt() -> None: