Skip to content
File

Blob: src/pyodide/internal/test_frozen_sdk.py

python55 lines
1"""Test that the in-tree Python SDK (internal/workers-api/) is frozen.
2
3The Python SDK now lives in https://github.com/cloudflare/workers-py and is
4installed from PyPI. The copy in this repository is kept only for backward
5compatibility and MUST NOT be modified.
6
7If this test fails, it means a file under internal/workers-api/ was changed.
8New features should go to cloudflare/workers-py instead. If the change is a
9deliberate backward-compatibility fix, update EXPECTED_HASHES below.
10"""
11 
12import hashlib
13import unittest
14from pathlib import Path
15 
16SDK_DIR = Path(__file__).parent / "workers-api"
17 
18# SHA-256 hashes of every file in the frozen SDK, keyed by path relative to
19# internal/workers-api/.
20# Calculate with: find internal/workers-api -type f -exec sha256sum {} \;
21EXPECTED_HASHES = {
22 "pyproject.toml": "2ba30eeea93f2cf161fce735981b382d2ca1f5aee77e663f447743aabe8575cf",
23 "src/asgi.py": "da171340aa361f733d99d4a1e09c7fe440dd6c79fbca83e4f11d7c42f7622549",
24 "src/workers/__init__.py": "5db8f21adacc3ba625c8763c6e8c47220325109bdc4ec301d76925037844cfd7",
25 "src/workers/_workers.py": "a1e2d9b8199e4bb88c3e89e82dca037772d223bf58bcb1a241d9f03bc54282bd",
26 "src/workers/workflows.py": "9379fdf416da56d2400369165a51b72da83f724aea893ac785285631d09803bf",
27 "uv.lock": "8945fab16bffb1ea1fe5740ca677e40bf8fe28010325e4c389cd11b8a072a9fc",
28}
29 
30 
31def _sha256(path: Path) -> str:
32 return hashlib.sha256(path.read_bytes()).hexdigest()
33 
34 
35class TestFrozenSDK(unittest.TestCase):
36 def test_no_files_modified(self):
37 """Ensure no existing SDK files were modified."""
38 for rel_path, expected_hash in sorted(EXPECTED_HASHES.items()):
39 file_path = SDK_DIR / rel_path
40 if not file_path.exists():
41 continue
42 actual_hash = _sha256(file_path)
43 self.assertEqual(
44 actual_hash,
45 expected_hash,
46 f"Python SDK is frozen — {rel_path} was modified. "
47 f"New features belong in cloudflare/workers-py. "
48 f"If this is a deliberate backward-compat fix, update "
49 f"EXPECTED_HASHES in this test.",
50 )
51 
52 
53if __name__ == "__main__":
54 unittest.main()