Skip to content

Commit 95b5c0f

Browse files
authored
Fix test suite from oversyncing appwrite file (#8)
* feat: support not oversyncing appwrite file * ci: fix when publishing * chore: bump version
1 parent fc42d72 commit 95b5c0f

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

.github/workflows/publish.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99

1010
jobs:
1111
build-and-publish:
12+
1213
runs-on: ubuntu-latest
1314

1415
steps:

appwrite_lab/test_suite/fixtures.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from pathlib import Path
22

3-
import pytest
43
from appwrite_lab.labs import Labs
54
from appwrite_lab.models import Lab
65

6+
import hashlib
7+
import pytest
8+
79

810
@pytest.fixture(scope="session")
911
def lab_svc():
@@ -42,19 +44,37 @@ def lab_config():
4244
def lab(lab_svc: Labs, appwrite_file: Path, lab_config: dict) -> Lab:
4345
"""Create or get existing lab with optional appwrite.json sync."""
4446
lab_name = lab_config["name"]
47+
hash_file_path = Path.home() / ".config" / "appwrite-lab" / "json_hashes"
48+
hash_file_path.touch()
4549

4650
if lab := lab_svc.get_lab(lab_name):
51+
# Check if the file has changed before unnecessary sync
4752
if appwrite_file and appwrite_file.exists():
48-
lab_svc.sync_with_appwrite_config(
49-
name=lab_name, appwrite_json=appwrite_file
50-
)
53+
hash = hash_file(appwrite_file)
54+
data = hash_file_path.read_text()
55+
if len(data) > 0 and data.strip() == hash:
56+
print("Skipping sync because the file has not changed")
57+
else:
58+
lab_svc.sync_with_appwrite_config(
59+
name=lab_name, appwrite_json=appwrite_file
60+
)
61+
hash_file_path.write_text(hash)
5162
return lab
5263

5364
res = lab_svc.new(**lab_config)
5465

5566
if appwrite_file and appwrite_file.exists():
67+
hash_file_path.write_text(hash_file(appwrite_file))
5668
lab_svc.sync_with_appwrite_config(name=lab_name, appwrite_json=appwrite_file)
5769

5870
if not res.error:
5971
return lab_svc.get_lab(lab_name)
6072
raise ValueError(res.message)
73+
74+
75+
def hash_file(path, algo="sha256"):
76+
h = hashlib.new(algo)
77+
with open(path, "rb") as f:
78+
for chunk in iter(lambda: f.read(8192), b""):
79+
h.update(chunk)
80+
return h.hexdigest()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "appwrite-lab"
7-
version = "0.1.1"
7+
version = "0.1.2"
88
description = "Zero-click Appwrite test environments."
99
readme = "README.md"
1010
requires-python = ">=3.11"

0 commit comments

Comments
 (0)