forked from longtao.wu/droboticflow
🐛 Verify installed upload receipts against real BOS checkpoint heads
The device items endpoint intentionally omits expectedBase/committedVersion, so the scenario rejected every real item. Take formal identities from the fixture checkpoint, which HEADs each head object on BOS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
97a108fa3d
commit
ee8ff920bb
@ -403,6 +403,8 @@ class InstalledAcceptance:
|
||||
rows = self.items(session_id)
|
||||
by_path = {row.get("relativePath"): row for row in rows}
|
||||
require(len(rows) == len(by_path) and set(by_path) == set(expected), "session contains unexpected paths")
|
||||
# Device item metadata omits receipts; take formal identities from the fixture's real BOS HEAD checkpoint.
|
||||
heads = None
|
||||
for path, wanted in expected.items():
|
||||
row = by_path[path]
|
||||
require(row.get("status") == wanted and row.get("md5sum") == digests[path]["md5sum"]
|
||||
@ -410,13 +412,16 @@ class InstalledAcceptance:
|
||||
if wanted == "denied":
|
||||
require(row.get("action") == "deny_archived_hash_change", "conflict was not denied as an archived hash change")
|
||||
else:
|
||||
remote = row.get("committedVersion") if wanted == "committed" else row.get("expectedBase")
|
||||
require(isinstance(remote, dict) and remote.get("exists") is True and remote.get("etag")
|
||||
and remote.get("sizeBytes", 0) == digests[path]["sizeBytes"], "item has no complete formal cloud receipt")
|
||||
target = row.get("targetKey", "")
|
||||
require(isinstance(target, str) and target.endswith("/" + path)
|
||||
and self.settings["runId"] in target.split("/"), "item target escaped the acceptance run")
|
||||
self.cloud_objects[target] = {"eTag": remote["etag"], "sizeBytes": digests[path]["sizeBytes"]}
|
||||
if heads is None:
|
||||
heads = self.checkpoint("items-" + session_id[:64])["objects"]
|
||||
remote = heads.get(target)
|
||||
require(isinstance(remote, dict) and remote.get("eTag")
|
||||
and remote.get("sizeBytes") == digests[path]["sizeBytes"],
|
||||
"item has no complete formal cloud receipt: path=%s status=%s" % (path, wanted))
|
||||
self.cloud_objects[target] = {"eTag": remote["eTag"], "sizeBytes": digests[path]["sizeBytes"]}
|
||||
return by_path
|
||||
|
||||
def source(self, name, prefix, specifications):
|
||||
|
||||
@ -344,24 +344,28 @@ class InstalledAcceptanceSyncTests(unittest.TestCase):
|
||||
runner = DRIVER.InstalledAcceptance(settings())
|
||||
row = {"id": "item", "sessionId": "new-session", "relativePath": "completed/small.bin",
|
||||
"targetKey": PREFIX + "completed/small.bin", "status": "unchanged", "md5sum": "a" * 32,
|
||||
"sizeBytes": 4, "expectedBase": {"exists": True, "etag": "etag", "sizeBytes": 4}}
|
||||
"sizeBytes": 4}
|
||||
runner.items = Mock(return_value=[row])
|
||||
value = checkpoint()
|
||||
runner.request = Mock(side_effect=lambda *args, **kwargs: json.loads(json.dumps(value)))
|
||||
actual = runner.assert_items("new-session", {"completed/small.bin": "unchanged"},
|
||||
{"completed/small.bin": {"sizeBytes": 4, "md5sum": "a" * 32}})
|
||||
self.assertEqual(actual["completed/small.bin"]["status"], "unchanged")
|
||||
self.assertIn(row["targetKey"], runner.cloud_objects)
|
||||
row["expectedBase"].pop("etag")
|
||||
with self.assertRaises(DRIVER.AcceptanceError):
|
||||
self.assertEqual(runner.cloud_objects[row["targetKey"]], {"eTag": "etag", "sizeBytes": 4})
|
||||
runner.cloud_objects.clear()
|
||||
value["objects"].clear()
|
||||
with self.assertRaisesRegex(DRIVER.AcceptanceError, "formal cloud receipt"):
|
||||
runner.assert_items("new-session", {"completed/small.bin": "unchanged"},
|
||||
{"completed/small.bin": {"sizeBytes": 4, "md5sum": "a" * 32}})
|
||||
|
||||
def test_zero_length_cloud_receipt_can_omit_zero_size_field(self):
|
||||
def test_cloud_receipt_size_must_match_source(self):
|
||||
runner = DRIVER.InstalledAcceptance(settings())
|
||||
runner.items = Mock(return_value=[{"relativePath": "mixed/zero.bin", "targetKey": PREFIX + "mixed/zero.bin",
|
||||
"status": "committed", "md5sum": "d41d8cd98f00b204e9800998ecf8427e", "sizeBytes": 0,
|
||||
"committedVersion": {"exists": True, "etag": "empty-etag"}}])
|
||||
runner.assert_items("initial", {"mixed/zero.bin": "committed"},
|
||||
{"mixed/zero.bin": {"sizeBytes": 0, "md5sum": "d41d8cd98f00b204e9800998ecf8427e"}})
|
||||
runner.items = Mock(return_value=[{"relativePath": "completed/small.bin", "targetKey": PREFIX + "completed/small.bin",
|
||||
"status": "committed", "md5sum": "a" * 32, "sizeBytes": 5}])
|
||||
runner.request = Mock(return_value=checkpoint())
|
||||
with self.assertRaisesRegex(DRIVER.AcceptanceError, "formal cloud receipt"):
|
||||
runner.assert_items("initial", {"completed/small.bin": "committed"},
|
||||
{"completed/small.bin": {"sizeBytes": 5, "md5sum": "a" * 32}})
|
||||
|
||||
|
||||
class InstalledAcceptanceCleanupTests(unittest.TestCase):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user