Cover directory storage migrations

这个提交存在于:
YokiiroBW 2026-07-05 21:49:02 +08:00
父节点 eb70493a00
当前提交 2c8ee1989d

查看文件

@ -859,6 +859,44 @@ database:
self.assertFalse(missing["ok"])
self.assertEqual(missing["error_code"], "MEDIA_NOT_FOUND")
def test_storage_migration_copies_directories_safely(self):
source_dir = self.root / "images" / "batch"
source_dir.mkdir(parents=True, exist_ok=True)
(source_dir / "a.bin").write_bytes(b"a")
nested = source_dir / "nested"
nested.mkdir(parents=True, exist_ok=True)
(nested / "b.bin").write_bytes(b"bb")
execution = migrate_storage(
self.ctx,
{
"source_uri": "storage://images/batch",
"target_uri": "storage://archives/batch-copy",
"dry_run": False,
},
self.media_service,
)
self.assertTrue(execution["ok"])
self.assertEqual(execution["data"]["files"], 2)
self.assertEqual(execution["data"]["bytes"], 3)
self.assertEqual((self.root / "archives" / "batch-copy" / "a.bin").read_bytes(), b"a")
self.assertEqual((self.root / "archives" / "batch-copy" / "nested" / "b.bin").read_bytes(), b"bb")
self.assertTrue((source_dir / "a.bin").exists())
self.assertNotIn(str(self.root), str(execution["data"]))
unsafe_target = migrate_storage(
self.ctx,
{
"source_uri": "storage://images/batch",
"target_uri": "storage://images/batch/nested-copy",
"dry_run": False,
},
self.media_service,
)
self.assertFalse(unsafe_target["ok"])
self.assertEqual(unsafe_target["error_code"], "FORBIDDEN")
def test_web_manifest_returns_public_mounts_without_local_paths(self):
response = get_web_manifest(self.ctx, self.web_hosting_service)