From afe813769ab107e4792f9892359013807f2f816d Mon Sep 17 00:00:00 2001 From: adamXbot <111877622+adamXbot@users.noreply.github.com> Date: Fri, 16 Oct 2026 14:50:13 +1100 Subject: [PATCH] Vendor the archive digest fix digest() hashed an .xcarchive's whole Info.plist. A real `just upload` runs xcodebuild -exportArchive with destination=upload, and Xcode records the distribution in that file (a Distributions key), so the digest changed and projectctl exited 1 with "Upload modified the archive" after a successful upload. The reviewed runtime from AdamXweb/dev#19 now hashes the archive's Info.plist by its archive keys and the app's identity keys, and every other file byte for byte. Vendored with dev's install.py; only projectctl.py, its vendored test and the runtime lock change, and the justfile regenerates unchanged. Co-Authored-By: Claude Opus 5.5 --- .project/projectctl.py | 20 +++++++++++++++++++- .project/runtime.lock.json | 4 ++-- .project/tests/test_projectctl.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/.project/projectctl.py b/.project/projectctl.py index a8a7826..199552e 100644 --- a/.project/projectctl.py +++ b/.project/projectctl.py @@ -49,12 +49,30 @@ def source(root): "event": os.environ.get("GITHUB_EVENT_NAME", "local"), "ref": os.environ.get("GITHUB_REF", "")} +# Xcode records each distribution in an archive's top-level Info.plist, so +# uploading changes that file. An archive's identity is every other file, +# byte for byte, plus what that Info.plist says about the archive and the app +# inside it. +ARCHIVE_KEYS = ("ArchiveVersion", "CreationDate", "Name", "SchemeName") +ARCHIVE_APPLICATION_KEYS = ("ApplicationPath", "Architectures", "CFBundleIdentifier", "CFBundleShortVersionString", + "CFBundleVersion", "SigningIdentity", "Team") + +def archive_identity(path): + info = plistlib.loads((path / "Info.plist").read_bytes()) + application = info.get("ApplicationProperties", {}) + identity = {key: info[key] for key in ARCHIVE_KEYS if key in info} + identity["ApplicationProperties"] = {key: application[key] for key in ARCHIVE_APPLICATION_KEYS if key in application} + return json.dumps(identity, sort_keys=True, default=str).encode() + def digest(path): path = Path(path) files = sorted(path.rglob("*")) if path.is_dir() else [path] + archive = path.is_dir() and path.suffix == ".xcarchive" and (path / "Info.plist").is_file() value = hashlib.sha256() for item in files: - if item.is_symlink(): + if archive and item == path / "Info.plist": + value.update(b"Info.plist\0" + archive_identity(path)) + elif item.is_symlink(): value.update(str(item.relative_to(path)).encode() + b"\0" + os.readlink(item).encode()) elif item.is_file(): value.update((str(item.relative_to(path)) if path.is_dir() else path.name).encode() + b"\0") diff --git a/.project/runtime.lock.json b/.project/runtime.lock.json index f43b2a9..3120b21 100644 --- a/.project/runtime.lock.json +++ b/.project/runtime.lock.json @@ -1,8 +1,8 @@ { "schema": "project-runtime/v1", "files": { - "projectctl.py": "904c215b4decc03e4bd97de694d105b93dfda65288fdb3634f14bca770a3779a", + "projectctl.py": "de877635fafa33085a7ed416ef47661dbce5d0fe46c63e33f0269c8006b005f6", "install.py": "68d74f7bfb6fbd9b2b65c9001e26307f3c7051cbea0f525461a37074b2db0bd6", - "tests/test_projectctl.py": "24da05795b6ab89c33de1603f6afb278b07b4d0e8ab35c895f812bc5985e30d1" + "tests/test_projectctl.py": "485d1e5cc7e32bf502c2bce5a9ffb8634bdef82ca86bca470c0dfa9d51d889fd" } } diff --git a/.project/tests/test_projectctl.py b/.project/tests/test_projectctl.py index 67f76a5..8c60e64 100644 --- a/.project/tests/test_projectctl.py +++ b/.project/tests/test_projectctl.py @@ -189,6 +189,35 @@ def test_wrong_source_manifest_rejected(self): def test_dirty_artifact_rejected(self): artifact,_=self.artifact(dirty='YES') with self.assertRaisesRegex(ctl.ContractError,'Source changed'):self.project.record(artifact,ctl.source(self.root)) + def test_xcode_upload_bookkeeping_is_not_an_archive_change(self): + artifact,_=self.artifact(channel='testflight',tagged='NO') + self.project.record(artifact,ctl.source(self.root)) + info=plistlib.loads((artifact/'Info.plist').read_bytes()) + def upload(archive, environment): + # What Xcode does when it distributes an archive: it records the upload. + recorded=dict(info, Distributions=[{'destination':'upload','date':datetime(2026,10,9)}]) + (archive/'Info.plist').write_bytes(plistlib.dumps(recorded)) + stub=SimpleNamespace(upload_archive=upload, load_environment=lambda: {}) + with patch.object(self.project,'apple_module',return_value=stub): + self.project.run(self.opts('upload',value=str(artifact),channel='testflight')) + # A retry of the same archive still verifies. + self.project.verify(artifact,'testflight') + def test_upload_that_changes_the_app_or_its_identity_fails(self): + for change in ('product','identity'): + artifact,_=self.artifact(channel='testflight',tagged='NO') + self.project.record(artifact,ctl.source(self.root)) + def upload(archive, environment, change=change): + if change=='product': + (archive/'Products/Applications/Example.app/Contents/Extra').write_text('tampered') + else: + info=plistlib.loads((archive/'Info.plist').read_bytes()) + info['ApplicationProperties']['CFBundleIdentifier']='com.example.other' + (archive/'Info.plist').write_bytes(plistlib.dumps(info)) + stub=SimpleNamespace(upload_archive=upload, load_environment=lambda: {}) + with patch.object(self.project,'apple_module',return_value=stub): + with self.assertRaisesRegex(ctl.ContractError,'Upload modified the archive'): + self.project.run(self.opts('upload',value=str(artifact),channel='testflight')) + shutil.rmtree(artifact); (self.root/'build/Example.xcarchive.project.json').unlink() def test_valid_beta_archive_identity_preserved(self): artifact,_=self.artifact();manifest=self.project.record(artifact,ctl.source(self.root)); before=ctl.digest(artifact) self.project.verify(artifact,'testflight');self.assertEqual(before,ctl.digest(artifact));self.assertEqual(manifest['build'],'2026.1001.0900')