"""platform/objectstore — local-disk adapter round-trip (SD-0002 §6.2/§6.3.1).""" import pytest from app.platform import objectstore def test_local_put_get_round_trip(tmp_path): store = objectstore.LocalObjectStore(str(tmp_path)) key = "storefronts/1/product-images/9/original" store.put(key, b"\x89PNG-bytes", "image/png") assert store.get(key) == b"\x89PNG-bytes" def test_local_get_missing_raises_not_found(tmp_path): store = objectstore.LocalObjectStore(str(tmp_path)) with pytest.raises(objectstore.ObjectNotFound): store.get("nope/missing") def test_local_delete_is_idempotent(tmp_path): store = objectstore.LocalObjectStore(str(tmp_path)) store.put("a/b", b"x", "text/plain") store.delete("a/b") store.delete("a/b") # no error second time with pytest.raises(objectstore.ObjectNotFound): store.get("a/b") def test_local_keys_cannot_escape_base_dir(tmp_path): store = objectstore.LocalObjectStore(str(tmp_path)) with pytest.raises(ValueError): store.put("../escape", b"x", "text/plain") def test_build_objectstore_local(tmp_path, monkeypatch): monkeypatch.setenv("ECOMM_OBJECTSTORE_KIND", "local") monkeypatch.setenv("ECOMM_OBJECTSTORE_DIR", str(tmp_path)) store = objectstore.build_objectstore("local") assert isinstance(store, objectstore.LocalObjectStore) def test_build_objectstore_unknown_kind_raises(): with pytest.raises(ValueError): objectstore.build_objectstore("s3")