fixed # 修复工作流BUG

This commit is contained in:
2026-10-20 11:06:31 +08:00
parent 6227fd4979
commit 2b0fca8828
2 changed files with 36 additions and 17 deletions
+29 -11
View File
@@ -230,20 +230,38 @@ class ZhenxunPackageTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, "not accessible"):
publish(package, True, lambda *args: None)
def test_symlink_duplicate_and_unmanaged_branch_rejected(self):
def test_publish_replaces_unmanaged_main_and_preserves_history(self):
from publish_zhenxun import publish
from zipfile import ZipInfo
from verify_zhenxun import read_package
package, _ = self.clean_package()
with patch.dict("os.environ", {"FARM_RELEASE_TOKEN":"unit-test"}):
def unmanaged(method, path, data):
if path == "":
return {"default_branch": "main"}
if path.startswith("git/ref/"):
return {"object": {"sha": "existing"}}
return None
calls = []
with self.assertRaisesRegex(ValueError, "not generated by Farm"):
publish(package, True, unmanaged)
def unmanaged(method, path, data):
calls.append((method, path, data))
if path == "":
return {"default_branch": "main"}
if path.startswith("git/ref/"):
return {"object": {"sha": "existing"}}
if path.startswith("contents/"):
return None
return {"sha": "created"}
with patch.dict("os.environ", {"FARM_RELEASE_TOKEN": "unit-test"}):
self.assertTrue(publish(package, True, unmanaged)["published"])
tree = next(data for method, path, data in calls
if method == "POST" and path == "git/trees")
self.assertNotIn("base_tree", tree)
self.assertEqual({entry["path"] for entry in tree["tree"]},
set(read_package(package)))
commit = next(data for method, path, data in calls
if method == "POST" and path == "git/commits")
self.assertEqual(commit["parents"], ["existing"])
self.assertIn(("PATCH", "git/refs/heads/main", {
"sha": "created", "force": False,
}), calls)
def test_symlink_and_duplicate_rejected(self):
from zipfile import ZipInfo
for kind in ("duplicate", "link"):
bad = self.root / (kind + ".zip")
bad.write_bytes(self.bundle.read_bytes())