Download tests/plugins/test_plugin_storage.py from SaylorTwift/hermes-agent: direct link, hf CLI and curl.
- Browser
- Download file 2.39 kB
-
https://huggingface.co/SaylorTwift/hermes-agent/resolve/main/tests/plugins/test_plugin_storage.py
- Command line
-
hf download hf://SaylorTwift/hermes-agent/tests/plugins/test_plugin_storage.py
-
curl -L -o test_plugin_storage.py https://huggingface.co/SaylorTwift/hermes-agent/resolve/main/tests/plugins/test_plugin_storage.py
2.39 kB
| """Tests for the per-plugin durable storage convention (plugins/plugin_storage). | |
| The contract under test: data lives under ``<hermes home>/plugin-data/<name>/`` | |
| (NOT the ``plugins/<name>/`` install tree), names that could escape the root | |
| are rejected, and the sqlite helper opens a WAL-mode connection inside the | |
| data dir. | |
| """ | |
| from __future__ import annotations | |
| import pytest | |
| from hermes_constants import reset_hermes_home_override, set_hermes_home_override | |
| from plugins.plugin_storage import plugin_data_dir, plugin_db | |
| def hermes_home(tmp_path): | |
| token = set_hermes_home_override(str(tmp_path)) | |
| try: | |
| yield tmp_path | |
| finally: | |
| reset_hermes_home_override(token) | |
| def test_data_dir_lives_outside_the_install_tree(hermes_home): | |
| root = plugin_data_dir("my-plugin") | |
| assert root == hermes_home / "plugin-data" / "my-plugin" | |
| assert root.is_dir() | |
| # The invariant that motivated the module: data must not live under the | |
| # install tree that `hermes plugins remove` deletes. | |
| assert (hermes_home / "plugins") not in root.parents | |
| def test_data_dir_is_stable_across_calls(hermes_home): | |
| assert plugin_data_dir("p") == plugin_data_dir("p") | |
| def test_hostile_names_are_rejected(hermes_home, bad): | |
| with pytest.raises(ValueError): | |
| plugin_data_dir(bad) | |
| def test_plugin_db_journal_mode_is_the_shared_fallback_verdict(hermes_home): | |
| """Plugin DBs take the journal mode the core WAL helper decides for this SQLite build and | |
| filesystem (WAL normally; DELETE on WAL-reset-bug builds or network FS) — never a raw PRAGMA.""" | |
| from hermes_state_wal import is_sqlite_wal_reset_vulnerable | |
| conn = plugin_db("board") | |
| try: | |
| conn.execute("CREATE TABLE t (x)") | |
| conn.execute("INSERT INTO t VALUES (1)") | |
| conn.commit() | |
| mode = conn.execute("PRAGMA journal_mode").fetchone()[0] | |
| assert mode == ("delete" if is_sqlite_wal_reset_vulnerable() else "wal") | |
| finally: | |
| conn.close() | |
| assert (hermes_home / "plugin-data" / "board" / "data.db").exists() | |
| def test_plugin_db_rejects_path_shaped_filenames(hermes_home): | |
| with pytest.raises(ValueError): | |
| plugin_db("board", filename="../outside.db") | |
| with pytest.raises(ValueError): | |
| plugin_db("board", filename="") | |