feat: add CH5 cube renewal presentation, trade level UI, audit manifests, and test fixtures
This commit is contained in:
@@ -41,6 +41,8 @@ python3 tools/server/ava2-items/make_quiver.py \
|
||||
|
||||
测试:
|
||||
|
||||
可追加 `--with-motion-assets` 解析46条动作/特效闭包,仅补入当前包缺失的两份AVA2特殊MSA。使用 `stage_quiver_client.py` 生成私有测试客户端,不手改正式Index。步骤、当前验证及限制见[状态与动作记录](../../../docs/XXF-CH5-QUIVER-SYNC-20261022.md)。
|
||||
|
||||
```sh
|
||||
python3 -m unittest discover -s tools/server/ava2-items/tests
|
||||
```
|
||||
|
||||
@@ -13,6 +13,8 @@ def dependencies(path,raw):
|
||||
out=[]
|
||||
for value in REFERENCE.findall(raw):
|
||||
name=value.decode('ascii').lower().replace('\\','/')
|
||||
if name.startswith('/') or (':' in name and not name.startswith('d:/ymir work/')):
|
||||
raise ValueError('invalid quiver dependency: '+name)
|
||||
if not name.startswith(('d:/','sound/','icon/')):
|
||||
name=posixpath.dirname(path)+'/'+name
|
||||
name=posixpath.normpath(name)
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Create a private quiver test client, leaving the registered production assets untouched."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
def digest(path):
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def stage(base, candidate, output, packer):
|
||||
base, candidate, output, packer = [Path(p).resolve() for p in (base, candidate, output, packer)]
|
||||
if output.exists():
|
||||
raise ValueError('private output must not exist')
|
||||
if output == base or base in output.parents or output == candidate or candidate in output.parents:
|
||||
raise ValueError('output must be separate from base and candidate')
|
||||
report = json.loads((candidate / 'manifest.json').read_text())
|
||||
if not report.get('motion_assets'):
|
||||
raise ValueError('candidate requires --with-motion-assets')
|
||||
if not {'quiver.eix', 'quiver.epk'} <= set(report['files']):
|
||||
raise ValueError('candidate manifest must bind both pack files')
|
||||
if digest(base / 'pack/Index') != report['effective_client_base']['index_sha256']:
|
||||
raise ValueError('base Index changed; regenerate/review candidate')
|
||||
for name, expected in report['files'].items():
|
||||
path = (candidate / name).resolve()
|
||||
if candidate not in path.parents or not path.is_file() or digest(path) != expected:
|
||||
raise ValueError('candidate integrity error: ' + name)
|
||||
with tempfile.TemporaryDirectory(prefix='quiver-stage-check-') as folder:
|
||||
for i, (name, record) in enumerate(report['motion_assets'].items()):
|
||||
if record['origin'] == 'ava2_reference':
|
||||
source = (candidate / 'assets' / name).resolve()
|
||||
if candidate not in source.parents or digest(source) != record['sha256']:
|
||||
raise ValueError('candidate motion changed: ' + name)
|
||||
elif record['origin'] == 'registered_client':
|
||||
probe = Path(folder) / str(i)
|
||||
subprocess.run([str(packer), '--read-client', str(base), name, str(probe)],
|
||||
check=True, capture_output=True)
|
||||
if digest(probe) != record['sha256']:
|
||||
raise ValueError('base dependency changed: ' + name)
|
||||
else:
|
||||
raise ValueError('unknown motion origin')
|
||||
# Separate writable configs/Index; pack content and large loose resources are read-only links.
|
||||
output.mkdir(parents=True, exist_ok=False)
|
||||
(output / 'pack').mkdir()
|
||||
for source in (base / 'pack').iterdir():
|
||||
if source.is_file() and source.suffix.lower() in ('.eix', '.epk'):
|
||||
(output / 'pack' / source.name).symlink_to(source.resolve())
|
||||
stem = 'ch5_quiver_candidate'
|
||||
for suffix in ('.eix', '.epk'):
|
||||
target = output / 'pack' / (stem + suffix)
|
||||
if target.exists():
|
||||
raise ValueError('candidate pack name conflicts with base')
|
||||
shutil.copy2(candidate / ('quiver' + suffix), target)
|
||||
lines = (base / 'pack/Index').read_bytes().splitlines()
|
||||
if not lines or lines[0] not in (b'PACK', b'FILE'):
|
||||
raise ValueError('unsupported base Index')
|
||||
(output / 'pack/Index').write_bytes(b'\n'.join([b'PACK', b'*', stem.encode(), *lines[1:]]) + b'\n')
|
||||
for source in base.iterdir():
|
||||
if source.is_file() and (source.suffix == '.cfg' or source.name == 'channel.inf'):
|
||||
shutil.copy2(source, output / source.name)
|
||||
elif source.is_dir() and source.name in ('sound', 'BGM', 'bgm', 'ymir work'):
|
||||
(output / source.name).symlink_to(source.resolve(), target_is_directory=True)
|
||||
result = dict(base=str(base), candidate=str(candidate), candidate_manifest_sha256=digest(candidate / 'manifest.json'),
|
||||
index_sha256=digest(output / 'pack/Index'), production_modified=False,
|
||||
warning='Local test checkout with links to base assets; not a distributable bundle or live acceptance')
|
||||
(output / 'quiver-test-staging.json').write_text(json.dumps(result, indent=2) + '\n')
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
for key in ('base', 'candidate', 'output', 'packer'):
|
||||
parser.add_argument('--' + key, type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
print(json.dumps(stage(args.base, args.candidate, args.output, args.packer)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,45 @@
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
import quiver_assets as q
|
||||
|
||||
|
||||
class QuiverAssetTests(unittest.TestCase):
|
||||
def test_relative_windows_paths_and_cycles(self):
|
||||
files = {'d:/ymir work/pc/assassin/bow/' + n: b'' for n in q.MOTIONS}
|
||||
files.update({'d:/ymir work/pc2/assassin/bow/' + n: b'' for n in q.MOTIONS})
|
||||
special = 'd:/ymir work/pc/assassin/bow/attack_special.msa'
|
||||
raw = b'MotionFileName "attack.gr2"\nEffect "d:\\ymir work\\pc\\assassin\\effect\\arrow_02.msf"'
|
||||
files['d:/ymir work/pc/assassin/bow/attack.gr2'] = b'existing-model'
|
||||
files['d:/ymir work/pc/assassin/effect/arrow_02.msf'] = b'Effect "../bow/attack_special.msa"'
|
||||
del files[special]
|
||||
missing, records = q.collect(files.get, lambda p: raw if p == special else None)
|
||||
self.assertEqual(missing, {special: raw})
|
||||
self.assertEqual(len(records), 20)
|
||||
self.assertEqual(records[special]['origin'], 'ava2_reference')
|
||||
|
||||
def test_current_artwork_is_never_overridden(self):
|
||||
def reference(p):
|
||||
raise AssertionError('should not consult reference')
|
||||
missing, records = q.collect(lambda p: b'current', reference)
|
||||
self.assertEqual(missing, {})
|
||||
self.assertEqual(len(records), 18)
|
||||
|
||||
def test_missing_dependency_rejects(self):
|
||||
with self.assertRaisesRegex(ValueError, 'missing quiver dependency'):
|
||||
q.collect(lambda p: None, lambda p: None)
|
||||
|
||||
def test_path_escape_rejects(self):
|
||||
for raw in [b'"../../../../../private.tga"', b'"e:/private.tga"']:
|
||||
with self.assertRaises(ValueError):
|
||||
q.dependencies('d:/ymir work/pc/assassin/bow/attack_special.msa', raw)
|
||||
|
||||
def test_closure_limit(self):
|
||||
with self.assertRaisesRegex(ValueError, 'exceeds limit'):
|
||||
q.collect(lambda p: b'', lambda p: None, maximum=1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,52 @@
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import json
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
import stage_quiver_client as q
|
||||
|
||||
|
||||
class StagingTests(unittest.TestCase):
|
||||
def setup_tree(self, root):
|
||||
base=root/'base';candidate=root/'candidate'
|
||||
(base/'pack').mkdir(parents=True);candidate.mkdir()
|
||||
(base/'pack/Index').write_bytes(b'PACK\n*\nroot\n')
|
||||
(base/'pack/root.eix').write_bytes(b'base index')
|
||||
(base/'pack/root.epk').write_bytes(b'base data')
|
||||
(base/'locale.cfg').write_bytes(b'1 936 zh')
|
||||
for name in ('quiver.eix','quiver.epk'):(candidate/name).write_bytes(name.encode())
|
||||
path='d:/ymir work/pc/assassin/bow/attack_special.msa'
|
||||
asset=candidate/'assets'/path;asset.parent.mkdir(parents=True);asset.write_bytes(b'motion')
|
||||
report=dict(files={p.relative_to(candidate).as_posix():q.digest(p)
|
||||
for p in candidate.rglob('*') if p.is_file()},
|
||||
effective_client_base=dict(index_sha256=q.digest(base/'pack/Index')),
|
||||
motion_assets={path:dict(origin='ava2_reference',sha256=q.digest(asset))})
|
||||
(candidate/'manifest.json').write_text(json.dumps(report))
|
||||
return base,candidate
|
||||
|
||||
def test_private_overlay_does_not_modify_base(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
root=Path(folder);base,candidate=self.setup_tree(root)
|
||||
original=(base/'pack/Index').read_bytes()
|
||||
q.stage(base,candidate,root/'test',root/'unused-packer')
|
||||
self.assertEqual((base/'pack/Index').read_bytes(),original)
|
||||
self.assertEqual((root/'test/pack/Index').read_bytes(),b'PACK\n*\nch5_quiver_candidate\n*\nroot\n')
|
||||
self.assertTrue((root/'test/pack/root.epk').is_symlink())
|
||||
self.assertFalse((root/'test/locale.cfg').is_symlink())
|
||||
with self.assertRaisesRegex(ValueError,'must not exist'):
|
||||
q.stage(base,candidate,root/'test',root/'unused-packer')
|
||||
|
||||
def test_stale_index_or_corrupt_pack_rejects_before_output(self):
|
||||
for corrupt in ('base','candidate'):
|
||||
with self.subTest(corrupt=corrupt),tempfile.TemporaryDirectory() as folder:
|
||||
root=Path(folder);base,candidate=self.setup_tree(root)
|
||||
path=base/'pack/Index' if corrupt=='base' else candidate/'quiver.epk'
|
||||
path.write_bytes(b'changed')
|
||||
with self.assertRaises(ValueError):q.stage(base,candidate,root/'test',root/'unused-packer')
|
||||
self.assertFalse((root/'test').exists())
|
||||
|
||||
|
||||
if __name__ == '__main__':unittest.main()
|
||||
Reference in New Issue
Block a user