test: add deferred phase 8 adversarial matrix

This commit is contained in:
2026-07-23 10:49:48 +00:00
parent 3d09e32ccd
commit 69709c778b
11 changed files with 820 additions and 2 deletions
+30
View File
@@ -32,6 +32,36 @@ class CompleteSyncthing:
class ClientJobHappyPathTests(unittest.TestCase):
def test_capacity_guard_fails_before_data_movement(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
store = ClientStore(root / "client.db")
store.initialize()
executor = ClientJobExecutor(
client_id="archive-1",
qbittorrent=Mock(),
store=store,
qb_root=root,
qb_api_root=Path("/downloads"),
route_path=lambda _: root,
syncthing_transport=Mock(),
sparse_supported=True,
free_space_reserve_bytes=100,
)
before = {path.name for path in root.iterdir()}
with patch(
"archive_clients.jobs.shutil.disk_usage",
return_value=Mock(free=109),
), self.assertRaisesRegex(
JobExecutionError,
"109 bytes available, 110 bytes required including reserve",
):
executor._require_space(root, 10)
self.assertEqual(
{path.name for path in root.iterdir()},
before,
)
def test_archive_and_unarchive_five_step_execution(self):
for operation in (
job_pb2.JOB_OPERATION_ARCHIVE,
+42
View File
@@ -12,6 +12,48 @@ from archive_control.v1 import resource_pb2
class ResourceTests(unittest.TestCase):
def test_pure_v2_identity_and_single_file_tree_normalization(self):
info = {
b"file tree": {
b"": {
b"length": 3,
b"pieces root": b"x" * 32,
},
},
b"meta version": 2,
b"name": b"v2.bin",
b"piece length": 16384,
}
metainfo_bytes = encode({b"info": info})
decoded = decode_metainfo(metainfo_bytes)
self.assertEqual(decoded.info_hash_v1_hex, "")
self.assertEqual(
decoded.info_hash_v2_hex,
hashlib.sha256(encode(info)).hexdigest(),
)
self.assertEqual(decoded.files[0].path, "v2.bin")
normalized = normalize_resource(
{
"hash": decoded.info_hash_v2_hex,
"name": "v2.bin",
"state": "stoppedUP",
},
[{
"index": 0,
"name": "v2.bin",
"size": 3,
"completed": 3,
"priority": 1,
}],
metainfo_bytes,
)
self.assertEqual(
normalized.summary.resource_id.info_hash_v2_hex,
decoded.info_hash_v2_hex,
)
self.assertFalse(normalized.summary.resource_id.info_hash_v1_hex)
def test_hybrid_identity_and_selection_normalization(self):
info = {
b"file tree": {