mirror of
https://github.com/beshu-tech/deltaglider.git
synced 2026-04-17 22:19:43 +02:00
refactor: Rename Leaf to DeltaSpace for semantic clarity
- Renamed Leaf class to DeltaSpace throughout the codebase - Updated all imports, method signatures, and variable names - Updated documentation and comments to reflect the new naming - DeltaSpace better represents a container for delta-compressed files The term "DeltaSpace" is more semantically accurate than "Leaf" as it represents a space/container for managing related files with delta compression, not a terminal node in a tree structure. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import io
|
||||
from pathlib import Path
|
||||
|
||||
from deltaglider.core import Leaf, ObjectKey
|
||||
from deltaglider.core import DeltaSpace, ObjectKey
|
||||
|
||||
|
||||
def test_full_put_get_workflow(service, temp_dir, mock_storage, mock_diff):
|
||||
@@ -25,7 +25,7 @@ def test_full_put_get_workflow(service, temp_dir, mock_storage, mock_diff):
|
||||
|
||||
mock_diff.decode.side_effect = decode_side_effect
|
||||
|
||||
leaf = Leaf(bucket="test-bucket", prefix="test/data")
|
||||
delta_space = DeltaSpace(bucket="test-bucket", prefix="test/data")
|
||||
|
||||
# Storage state tracking
|
||||
storage_data = {}
|
||||
@@ -76,28 +76,28 @@ def test_full_put_get_workflow(service, temp_dir, mock_storage, mock_diff):
|
||||
mock_storage.get.side_effect = mock_get
|
||||
|
||||
# Step 1: Put the first file (creates reference)
|
||||
summary1 = service.put(file1, leaf)
|
||||
summary1 = service.put(file1, delta_space)
|
||||
assert summary1.operation == "create_reference"
|
||||
assert summary1.key == "test/data/reference.bin"
|
||||
|
||||
# Verify reference was stored
|
||||
ref_key = f"{leaf.bucket}/{leaf.reference_key()}"
|
||||
ref_key = f"{delta_space.bucket}/{delta_space.reference_key()}"
|
||||
assert ref_key in storage_data
|
||||
assert storage_data[ref_key]["content"] == file1_content
|
||||
|
||||
# Step 2: Put the second file (creates delta)
|
||||
summary2 = service.put(file2, leaf)
|
||||
summary2 = service.put(file2, delta_space)
|
||||
assert summary2.operation == "create_delta"
|
||||
assert summary2.key == "test/data/version2.zip.delta"
|
||||
assert summary2.delta_size is not None
|
||||
assert summary2.ref_key == "test/data/reference.bin"
|
||||
|
||||
# Verify delta was stored
|
||||
delta_key = f"{leaf.bucket}/{summary2.key}"
|
||||
delta_key = f"{delta_space.bucket}/{summary2.key}"
|
||||
assert delta_key in storage_data
|
||||
|
||||
# Step 3: Get the delta file back
|
||||
obj_key = ObjectKey(bucket=leaf.bucket, key=summary2.key)
|
||||
obj_key = ObjectKey(bucket=delta_space.bucket, key=summary2.key)
|
||||
service.get(obj_key, output_file)
|
||||
|
||||
# Step 4: Verify the recovered file matches the original
|
||||
@@ -118,7 +118,7 @@ def test_get_with_auto_delta_suffix(service, temp_dir, mock_storage, mock_diff):
|
||||
|
||||
mock_diff.decode.side_effect = decode_side_effect
|
||||
|
||||
leaf = Leaf(bucket="test-bucket", prefix="archive")
|
||||
delta_space = DeltaSpace(bucket="test-bucket", prefix="archive")
|
||||
|
||||
# Storage state tracking
|
||||
storage_data = {}
|
||||
@@ -169,7 +169,7 @@ def test_get_with_auto_delta_suffix(service, temp_dir, mock_storage, mock_diff):
|
||||
mock_storage.get.side_effect = mock_get
|
||||
|
||||
# Put the file
|
||||
summary = service.put(test_file, leaf)
|
||||
summary = service.put(test_file, delta_space)
|
||||
|
||||
# Get it back using original name (without .delta)
|
||||
# The service should internally look for "mydata.zip.delta"
|
||||
@@ -178,9 +178,9 @@ def test_get_with_auto_delta_suffix(service, temp_dir, mock_storage, mock_diff):
|
||||
# Use the key without .delta suffix
|
||||
if summary.operation == "create_reference":
|
||||
# If it's a reference, the zero-diff delta was created
|
||||
obj_key = ObjectKey(bucket=leaf.bucket, key="archive/mydata.zip.delta")
|
||||
obj_key = ObjectKey(bucket=delta_space.bucket, key="archive/mydata.zip.delta")
|
||||
else:
|
||||
obj_key = ObjectKey(bucket=leaf.bucket, key=summary.key)
|
||||
obj_key = ObjectKey(bucket=delta_space.bucket, key=summary.key)
|
||||
|
||||
service.get(obj_key, output_file)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import warnings
|
||||
import pytest
|
||||
|
||||
from deltaglider.core import (
|
||||
Leaf,
|
||||
DeltaSpace,
|
||||
NotFoundError,
|
||||
ObjectKey,
|
||||
PolicyViolationWarning,
|
||||
@@ -19,12 +19,12 @@ class TestDeltaServicePut:
|
||||
def test_create_reference_first_file(self, service, sample_file, mock_storage):
|
||||
"""Test creating reference for first file."""
|
||||
# Setup
|
||||
leaf = Leaf(bucket="test-bucket", prefix="test/prefix")
|
||||
delta_space = DeltaSpace(bucket="test-bucket", prefix="test/prefix")
|
||||
mock_storage.head.return_value = None # No reference exists
|
||||
mock_storage.put.return_value = PutResult(etag="abc123")
|
||||
|
||||
# Execute
|
||||
summary = service.put(sample_file, leaf)
|
||||
summary = service.put(sample_file, delta_space)
|
||||
|
||||
# Verify
|
||||
assert summary.operation == "create_reference"
|
||||
@@ -41,7 +41,7 @@ class TestDeltaServicePut:
|
||||
def test_create_delta_subsequent_file(self, service, sample_file, mock_storage, mock_diff):
|
||||
"""Test creating delta for subsequent file."""
|
||||
# Setup
|
||||
leaf = Leaf(bucket="test-bucket", prefix="test/prefix")
|
||||
delta_space = DeltaSpace(bucket="test-bucket", prefix="test/prefix")
|
||||
|
||||
# Create reference content and compute its SHA
|
||||
import io
|
||||
@@ -68,12 +68,12 @@ class TestDeltaServicePut:
|
||||
mock_storage.get.return_value = io.BytesIO(ref_content)
|
||||
|
||||
# Create cached reference with matching content
|
||||
ref_path = service.cache.ref_path(leaf.bucket, leaf.prefix)
|
||||
ref_path = service.cache.ref_path(delta_space.bucket, delta_space.prefix)
|
||||
ref_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
ref_path.write_bytes(ref_content)
|
||||
|
||||
# Execute
|
||||
summary = service.put(sample_file, leaf)
|
||||
summary = service.put(sample_file, delta_space)
|
||||
|
||||
# Verify
|
||||
assert summary.operation == "create_delta"
|
||||
@@ -89,7 +89,7 @@ class TestDeltaServicePut:
|
||||
def test_delta_ratio_warning(self, service, sample_file, mock_storage, mock_diff):
|
||||
"""Test warning when delta ratio exceeds threshold."""
|
||||
# Setup
|
||||
leaf = Leaf(bucket="test-bucket", prefix="test/prefix")
|
||||
delta_space = DeltaSpace(bucket="test-bucket", prefix="test/prefix")
|
||||
|
||||
# Create reference content and compute its SHA
|
||||
import io
|
||||
@@ -119,14 +119,14 @@ class TestDeltaServicePut:
|
||||
mock_diff.encode.side_effect = large_encode
|
||||
|
||||
# Create cached reference with matching content
|
||||
ref_path = service.cache.ref_path(leaf.bucket, leaf.prefix)
|
||||
ref_path = service.cache.ref_path(delta_space.bucket, delta_space.prefix)
|
||||
ref_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
ref_path.write_bytes(ref_content)
|
||||
|
||||
# Execute and check warning
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
service.put(sample_file, leaf, max_ratio=0.1)
|
||||
service.put(sample_file, delta_space, max_ratio=0.1)
|
||||
|
||||
assert len(w) == 1
|
||||
assert issubclass(w[0].category, PolicyViolationWarning)
|
||||
|
||||
Reference in New Issue
Block a user