test: finish 1.11 archive and source package validation
This commit is contained in:
@@ -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']})
|
||||
|
||||
@@ -9,15 +9,19 @@ const evidence = JSON.parse(fs.readFileSync('.qa/archives-validation.json', 'utf
|
||||
assert.equal(evidence.success, true);
|
||||
assert.ok(evidence.extractionRoot, 'Run python scripts/verify-archives.py --extract-source first.');
|
||||
const sourceRoot = fs.realpathSync.native(evidence.extractionRoot);
|
||||
assert.ok(sourceRoot.startsWith(path.resolve('.qa') + path.sep));
|
||||
const archiveQaRoot = path.resolve(process.env.AGENT_WORKBENCH_ARCHIVE_QA_ROOT || '.qa');
|
||||
assert.ok(sourceRoot.startsWith(archiveQaRoot + path.sep));
|
||||
const npmCli = path.join(path.dirname(process.execPath), 'node_modules/npm/bin/npm-cli.js');
|
||||
assert.ok(fs.existsSync(npmCli), 'Use Node with its bundled npm.');
|
||||
const files = (root, relative = '') => fs.readdirSync(path.join(root, relative), { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))
|
||||
.flatMap(entry => entry.isDirectory() ? files(root, path.join(relative, entry.name)) : [path.join(relative, entry.name)]);
|
||||
const digest = file => createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
||||
const expected = Object.fromEntries(['dist-client', 'dist-server'].flatMap(folder => files(path.join(workspace, folder)).map(relative => [path.join(folder, relative), digest(path.join(workspace, folder, relative))])));
|
||||
const allowedEnv = /^(path|pathext|systemroot|systemdrive|windir|comspec|temp|tmp|userprofile|homedrive|homepath|home|appdata|localappdata|programfiles(?:\(x86\))?|commonprogramfiles(?:\(x86\))?|lang|lc_all|AGENT_WORKBENCH_TEST_PYTHON)$/i;
|
||||
const allowedEnv = /^(path|pathext|systemroot|systemdrive|windir|comspec|temp|tmp|userprofile|homedrive|homepath|home|appdata|localappdata|programfiles(?:\(x86\))?|commonprogramfiles(?:\(x86\))?|lang|lc_all|AGENT_WORKBENCH_TEST_PYTHON|AGENT_WORKBENCH_DEEPSEEK_ROOT)$/i;
|
||||
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => allowedEnv.test(key)));
|
||||
const inheritedPath = Object.entries(env).find(([key]) => key.toLowerCase() === 'path')?.[1] || '';
|
||||
for (const key of Object.keys(env)) if (key.toLowerCase() === 'path') delete env[key];
|
||||
env.PATH = [path.dirname(process.execPath), inheritedPath].filter(Boolean).join(path.delimiter);
|
||||
let stage = 'install';
|
||||
const resultFile = path.join(workspace, '.qa/source-package-validation.json');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user