test: finish 1.11 archive and source package validation

This commit is contained in:
Agent Workbench Dev
2026-10-30 14:17:33 +08:00
parent 20691139f0
commit 4516f66ab6
6 changed files with 68 additions and 10 deletions
+24 -3
View File
@@ -1,5 +1,7 @@
import hashlib
import json
import os
import shutil
from datetime import datetime, timezone
from pathlib import Path, PurePosixPath
import sys
@@ -9,10 +11,29 @@ import zipfile
workspace = Path(__file__).resolve().parent.parent
release_dir = (workspace / 'releases').resolve()
release = json.loads((release_dir / 'latest.json').read_text(encoding='utf-8'))
archive_qa_root = Path(os.environ.get('AGENT_WORKBENCH_ARCHIVE_QA_ROOT', workspace / '.qa')).resolve()
archive_qa_root.mkdir(parents=True, exist_ok=True)
records = []
extraction_root = None
version = None
def filesystem_path(path):
"""Use the Windows extended path form for source archives with deep dependency trees."""
value = str(path)
if os.name == 'nt' and not value.startswith('\\\\?\\'):
return '\\\\?\\' + value
return value
def extract_archive(bundle, root):
for entry in bundle.infolist():
target = (root / entry.filename.replace('\\\\', '/')).resolve()
if entry.is_dir():
os.makedirs(filesystem_path(target), exist_ok=True)
continue
os.makedirs(filesystem_path(target.parent), exist_ok=True)
with bundle.open(entry, 'r') as source, open(filesystem_path(target), 'wb') as destination:
shutil.copyfileobj(source, destination)
for kind, root_key in [('portable', 'portableRoot'), ('source', 'sourceRoot')]:
root = Path(release[root_key]).resolve()
archive = Path(release[kind]['path']).resolve()
@@ -45,13 +66,13 @@ for kind, root_key in [('portable', 'portableRoot'), ('source', 'sourceRoot')]:
assert len(contents) == expected[relative]['bytes']
assert hashlib.sha256(contents).hexdigest() == expected[relative]['sha256']
if kind == 'source' and '--extract-source' in sys.argv:
isolated = (workspace / '.qa' / ('source-check-' + uuid.uuid4().hex)).resolve()
assert isolated.is_relative_to((workspace / '.qa').resolve())
isolated = (archive_qa_root / ('source-check-' + uuid.uuid4().hex)).resolve()
assert isolated.is_relative_to(archive_qa_root)
isolated.mkdir(parents=True, exist_ok=False)
for entry in bundle.infolist():
target = (isolated / entry.filename.replace('\\', '/')).resolve()
assert target.is_relative_to(isolated)
bundle.extractall(isolated)
extract_archive(bundle, isolated)
extraction_root = str(isolated / root.name)
records.append({'kind': kind, 'path': str(archive), 'files': len(expected), 'crcPassed': True,
'manifestAndDirectoryMatch': True, 'sha256': release[kind]['sha256']})