| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- """Check real installation behavior and data invariants for the two local self-runs."""
- import hashlib
- import importlib.util
- import json
- import re
- import shutil
- from decimal import Decimal
- from pathlib import Path
- ROOT=Path(__file__).resolve().parents[1]
- FINAL=ROOT/'docs/workshop-validated-final-20261110'
- BASE=ROOT/'docs/workshop-self-run-20261110'
- WORK=ROOT/'work/workshop-r12-rerun-20261110'
- sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
- dump=lambda p,x:p.write_text(json.dumps(x,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
- def run():
- meta=json.loads((FINAL/'installation/release.json').read_bytes())
- skill=WORK/'isolated-skills/ksf-workshop-runtime'
- checked=[]
- for n,h in meta['workshop']['files'].items():
- assert sha(skill/n)==h,n
- checked.append(n)
- assert len(checked)==44
- previous=ROOT/'work/workshop-self-run-20261110/baseline-source-skill'
- protected=[n for n in checked if n.startswith('scripts/') or n=='runtime-lock.json']
- assert len(protected)==7
- assert all(sha(skill/n)==sha(previous/n) for n in protected)
- assert (skill/'references/workshop-output-navigation.md').is_file()
- local_links=[]
- for p in skill.rglob('*.md'):
- for label,link in re.findall(r'\[([^\]]+)\]\(([^)]+)\)',p.read_text('utf-8')):
- if '://' in link or link.startswith('#'):continue
- name=link.split('#',1)[0]
- assert (p.parent/name).is_file(),(p,link)
- local_links.append([p.relative_to(skill).as_posix(),link])
- # Reuse the unmodified, actually installed installer for exact-baseline and rejection checks.
- spec=importlib.util.spec_from_file_location('local_installer',FINAL/'installation/install.py')
- installer=importlib.util.module_from_spec(spec);spec.loader.exec_module(installer)
- payload={'ksf-workshop-runtime':{n:(skill/n).read_bytes() for n in checked}}
- fixture=WORK/'upgrade-fixture'
- assert not fixture.exists(),'Use a fresh verification result location'
- shutil.copytree(previous,fixture/'ksf-workshop-runtime')
- target=fixture/'ksf-workshop-runtime'
- private=target/'credential-binding.json';private.write_text('{"syntheticTest":true,"preserve":"unchanged"}\n',encoding='utf-8')
- note=target/'local-note.txt';note.write_text('synthetic local file\n',encoding='utf-8')
- preserved={p.name:sha(p) for p in [private,note]}
- actions=installer.plan(fixture,payload,meta['upgradeFrom'])
- assert actions[0]['action']=='upgrade'
- installer.install_files(fixture,payload,actions,WORK/'upgrade-fixture-backup')
- installer.verify_component(target,payload['ksf-workshop-runtime'])
- assert all(sha(target/n)==h for n,h in preserved.items())
- assert installer.plan(fixture,payload,meta['upgradeFrom'])[0]['action']=='verify-only'
- modified=WORK/'unknown-fixture';shutil.copytree(previous,modified/'ksf-workshop-runtime')
- p=modified/'ksf-workshop-runtime/references/workshop-feedback.md';p.write_text(p.read_text('utf-8')+'\nlocal unknown change\n',encoding='utf-8')
- before={p.relative_to(modified).as_posix():sha(p) for p in modified.rglob('*') if p.is_file()}
- try:installer.plan(modified,payload,meta['upgradeFrom']);raise AssertionError('unknown baseline was accepted')
- except installer.InstallError as e:assert str(e)=='UPGRADE_BASELINE_CHANGED'
- assert before=={p.relative_to(modified).as_posix():sha(p) for p in modified.rglob('*') if p.is_file()}
- r10=ROOT/'work/workshop-self-run-20261110/isolated-skills'
- try:installer.plan(r10,payload,meta['upgradeFrom']);raise AssertionError('unsupported r10 was accepted')
- except installer.InstallError as e:assert str(e)=='UPGRADE_BASELINE_CHANGED'
- ledger=json.loads((BASE/'证据与编码.json').read_bytes())
- for row in ledger['reviews']:
- raw=json.loads((BASE/row['responseFile']).read_bytes())['record']
- assert raw['id']==row['recordId'] and raw['content']==row['quote']
- usable=[r for r in ledger['reviews'] if r['status']=='usable']
- assert len(usable)==45 and len({r['quote'].strip() for r in usable})==43
- for s in ledger['statistics']:
- group=[r for r in usable if r['productId']==s['productId'] and r['platform']==s['platform']]
- assert s['denominatorMembers']==[r['key'] for r in group]
- assert s['members']==[r['key'] for r in group if s['theme'] in r['tags']]
- assert s['N']==len(group) and s['n']==len(s['members'])
- assert s['percent']==round(s['n']/s['N']*100,1)
- for s in json.loads((BASE/'商业情景复算.json').read_bytes())['scenarios']:
- R,C=Decimal(s['R']),Decimal(s['C'])
- assert Decimal(s['difference'])==R-C
- assert Decimal(s['marginPercent'])==(R-C)/R*100
- for folder in [BASE,FINAL/'rerun']:
- pool=json.loads((folder/'候选机会全池.json').read_bytes())
- assert all([r['localKey'] for r in rows]==['O1','O2','O3'] for rows in pool['snapshots'].values())
- assert all(not r['artifactId'] and not r['opportunityId'] for rows in pool['snapshots'].values() for r in rows)
- for p in (folder/'evidence').glob('*.request.json'):
- r=json.loads(p.read_bytes()); assert sha(folder/'evidence'/(r['name']+'.json'))==r['responseSha256']
- assert r['databaseWrites']==0 and r['readOnly'] is True
- # No changes to the exact user-specified original manual.
- original=ROOT/'docs/workshop-final-local-20261110/康师傅工作坊操作手册-本地定稿.html'
- assert sha(original)=='8c8942c3d1331693570928b8f54300f13f635387cfa3dcf1422bde3cec1740ab'
- result={'ok':True,'skillPublicFilesVerified':len(checked),'protectedFilesUnchanged':protected,
- 'skillReferenceLinksVerified':len(local_links),'freshInstall':'actual CLI plan/apply + VOC runtime receipt',
- 'exactR11Upgrade':True,'localFilesPreserved':'synthetic credential-binding.json and local-note.txt',
- 'sameVersionVerifyOnly':True,'unknownBaselineRejectedWithoutWrites':True,'r10SafelyRejected':True,
- 'reviewBodiesChecked':49,'usableReviews':45,'distinctTexts':43,'statisticsRecomputed':len(ledger['statistics']),
- 'financeScenariosRecomputed':5,'candidatePoolV1V2V3KeysRetained':True,'originalManualUnchanged':True,
- 'productionWrites':0,'independentModelReview':False,'realEmployeeTest':False}
- dump(FINAL/'内容与安装核验.json',result)
- print(json.dumps(result,ensure_ascii=False))
- if __name__=='__main__':run()
|