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
+7 -6
View File
@@ -59,12 +59,13 @@ def publish(package, confirmed=False, request=None):
parent = ref["object"]["sha"] if ref else None parent = ref["object"]["sha"] if ref else None
if parent: if parent:
owned = call("GET", f"contents/FARM-MANIFEST.json?ref={BRANCH}", None) owned = call("GET", f"contents/FARM-MANIFEST.json?ref={BRANCH}", None)
if not owned or owned.get("encoding") != "base64": if owned is not None:
raise ValueError("Existing preview branch is not generated by Farm") if owned.get("encoding") != "base64":
previous = json.loads(base64.b64decode(owned["content"])) raise ValueError("Existing Farm manifest encoding is invalid")
if (previous.get("target") != "zhenxun" previous = json.loads(base64.b64decode(owned["content"]))
or previous.get("plugin") != manifest["plugin"]): if (previous.get("target") != "zhenxun"
raise ValueError("Existing preview branch ownership differs") or previous.get("plugin") != manifest["plugin"]):
raise ValueError("Existing preview branch ownership differs")
tree = [] tree = []
for name, content in sorted(files.items()): for name, content in sorted(files.items()):
blob = call("POST", "git/blobs", { blob = call("POST", "git/blobs", {
+29 -11
View File
@@ -230,20 +230,38 @@ class ZhenxunPackageTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, "not accessible"): with self.assertRaisesRegex(ValueError, "not accessible"):
publish(package, True, lambda *args: None) 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 publish_zhenxun import publish
from zipfile import ZipInfo from verify_zhenxun import read_package
package, _ = self.clean_package() package, _ = self.clean_package()
with patch.dict("os.environ", {"FARM_RELEASE_TOKEN":"unit-test"}): calls = []
def unmanaged(method, path, data):
if path == "":
return {"default_branch": "main"}
if path.startswith("git/ref/"):
return {"object": {"sha": "existing"}}
return None
with self.assertRaisesRegex(ValueError, "not generated by Farm"): def unmanaged(method, path, data):
publish(package, True, unmanaged) 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"): for kind in ("duplicate", "link"):
bad = self.root / (kind + ".zip") bad = self.root / (kind + ".zip")
bad.write_bytes(self.bundle.read_bytes()) bad.write_bytes(self.bundle.read_bytes())