Harden package paths and storage writes

This commit is contained in:
RayPals
2026-08-25 20:36:43 +00:00
parent 7d4d683a8f
commit 9e2ab7f28a
4 changed files with 105 additions and 2 deletions
+33
View File
@@ -0,0 +1,33 @@
import json
import tempfile
import unittest
from pathlib import Path
from beeos.core.runtime_api import BeeStorageAPI
class BeeStorageAPITests(unittest.TestCase):
def test_set_persists_json_and_leaves_no_temporary_file(self):
with tempfile.TemporaryDirectory() as temp_dir:
storage_file = Path(temp_dir) / "storage.json"
storage = BeeStorageAPI(storage_file)
storage.set("launches", 3)
self.assertEqual(storage.get("launches"), 3)
self.assertEqual(json.loads(storage_file.read_text(encoding="utf-8")), {"launches": 3})
self.assertFalse(storage_file.with_name("storage.json.tmp").exists())
def test_delete_removes_key_without_corrupting_other_values(self):
with tempfile.TemporaryDirectory() as temp_dir:
storage = BeeStorageAPI(Path(temp_dir) / "storage.json")
storage.set("launches", 3)
storage.set("theme", "yellow")
storage.delete("launches")
self.assertEqual(storage.all(), {"theme": "yellow"})
if __name__ == "__main__":
unittest.main()