From 475f7da6453c31e6f2b2ea3c76c4e1d72b02ea86 Mon Sep 17 00:00:00 2001 From: worldmozara Date: Sat, 24 Oct 2026 02:19:39 +0800 Subject: [PATCH] test: keep the one-shot test off the host's chat.db MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `test_chat_oneshot_success` proved that an explicit `[database].url` wins over the durable default by stat'ing the *real* `~/.local/share/plyngent/chat.db` and comparing its mtime. So a test read the user's own session database, and it went red whenever a live chat happened to write it — which is what a run does while another plyngent session is open. The default path is now pointed into `tmp_path`, the way `test_app.py` already does it, and the assertion is that no `chat.db` shows up there. Nothing outside tmp_path is read, and a regression — the explicit url ignored — still fails, because the default branch would create that file. --- tests/test_cli/test_oneshot.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_cli/test_oneshot.py b/tests/test_cli/test_oneshot.py index 0cf6fe8..0d3be4c 100644 --- a/tests/test_cli/test_oneshot.py +++ b/tests/test_cli/test_oneshot.py @@ -135,10 +135,12 @@ access_key_or_token = "sk" lambda _p, **_kw: 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 + # The durable default must stay untouched, and the test must not read the + # host's own chat.db to prove it: point that default into tmp_path and check + # nothing was created there. + unused_data_dir = tmp_path / "user-data" + _ = unused_data_dir.mkdir() + monkeypatch.setattr("plyngent.cli.app.user_data_path", lambda *_args, **_kwargs: unused_data_dir) runner = CliRunner() result = runner.invoke( @@ -162,8 +164,7 @@ access_key_or_token = "sk" assert result.exit_code == EXIT_OK assert "pong" in result.output assert db_path.is_file() - if global_mtime is not None: - assert global_db.stat().st_mtime == global_mtime + assert not (unused_data_dir / "chat.db").exists() def test_chat_help_mentions_prompt() -> None: