| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- """Exercise the complete handoff at isolated local paths, never production."""
- import hashlib
- import importlib.util
- import json
- import os
- from pathlib import Path
- import shutil
- import subprocess
- import sys
- ROOT=Path(__file__).resolve().parents[1]
- WORK=ROOT/'work/voc-structure-20261105'
- PACKAGE=ROOT/'artifacts/康师傅VOC结构化入库-20261105/ksf-voc-library-20261105-r2'
- TARGET=WORK/'r2-install-acceptance-final'
- def digest(p):return hashlib.sha256(p.read_bytes()).hexdigest()
- def run(args,env=None):
- result=subprocess.run(args,capture_output=True,text=True,encoding='utf-8',env=env)
- assert result.returncode==0,(args,result.returncode,result.stdout,result.stderr)
- return json.loads(result.stdout)
- def write(p,x):
- p.parent.mkdir(parents=True,exist_ok=True)
- p.write_text(json.dumps(x,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
- def main():
- assert not TARGET.exists(),'Do not overwrite previous acceptance evidence'
- spec=importlib.util.spec_from_file_location('install_voc',PACKAGE/'ops/install_voc.py')
- module=importlib.util.module_from_spec(spec);spec.loader.exec_module(module)
- lib=TARGET/'library';skill=TARGET/'skills/ksf-voc-library'
- plan=module.install(PACKAGE,lib,skill)
- assert plan['readOnly'] and len(plan['newDirectories'])==2 and not TARGET.exists()
- applied=module.install(PACKAGE,lib,skill,True)
- assert applied['applied'] and applied['filesystemVerified']
- before=digest(lib/'library.sqlite')
- entry=skill/'scripts/query_voc.py'
- base=[sys.executable,'-X','utf8',str(entry)]
- env=dict(os.environ,KSF_VOC_DB=str(lib/'library.sqlite'))
- contract=run(base+['contract'],env)
- assert contract['schema']=='ksf.voc-library.v2'
- examples=[]
- for p in sorted((PACKAGE/'examples').glob('*.json')):
- command='facets' if p.name.startswith('14-') else 'aggregate' if p.name.startswith('15-') else 'search'
- result=run(base+[command,'--input',str(p)],env)
- assert result['ok'] and result['readOnly'] and result['databaseWrites']==0
- if command=='search':
- assert result['totalMatched']>0
- row=result['records'][0]
- detail=run(base+['get','--entity',row['entity'],'--id',row['record_id']],env)
- assert detail['record']['source_record_id']==row['source_record_id']
- source=run(base+['source','--id',row['source_record_id']],env)
- assert source['citation']['archiveSha256']==row['citation']['archiveSha256']
- examples.append(dict(file=p.name,command=command,ok=result['ok'],totalMatched=result.get('totalMatched')))
- assert digest(lib/'library.sqlite')==before
- assert not list(skill.rglob('__pycache__')),'Queries must not modify installed skill'
- repeated=module.install(PACKAGE,lib,skill,True)
- assert not repeated['applied'] and repeated['newDirectories']==[]
- rejected=run([sys.executable,'-B','-X','utf8',str(PACKAGE/'ops/install_voc.py'),'--package',str(PACKAGE),'--library-dir',str(lib),'--skill-dir',str(skill),'--check'])
- assert rejected['ok']
- write(PACKAGE/'receipts/install-validation.json',dict(ok=True,plan=plan,apply=applied,contractGeneration=contract['generation'],
- installedCliExamples=examples,installedGetAndSourceVerified=True,databaseShaBeforeAfter=before,
- queryCreatedBytecode=False,reinstallNoOp=True,productionInstalled=False))
- # Both permitted workshop documentation baselines, with isolated fake state.
- for label,baseline in [
- ('20261104-db-first',WORK/'workshop-baseline'),
- ('20261105-prepared-r1',PACKAGE.parent/'ksf-voc-library-20261105-r1/materials/skills/ksf-workshop-runtime')]:
- dest=TARGET/'workshop'/label/'skills/ksf-workshop-runtime'
- shutil.copytree(baseline,dest)
- (dest/'credential-binding.json').write_text('{"fixture":true}',encoding='utf-8')
- state=TARGET/'workshop'/label/'ksf-workshop-state/sessions'
- state.mkdir(parents=True)
- (state/'test.json').write_text('{"fixture":true,"sessionId":"local-only"}',encoding='utf-8')
- node_script=TARGET/'workshop-test.mjs'
- node_script.write_text('''import fs from 'node:fs';
- import path from 'node:path';
- import crypto from 'node:crypto';
- import {pathToFileURL} from 'node:url';
- const [packageRoot,workspace,targetRoot]=process.argv.slice(2);
- const {installWorkshopSkill}=await import(pathToFileURL(path.join(packageRoot,'materials/scripts/install-workshop-skill.mjs')));
- const hash=p=>crypto.createHash('sha256').update(fs.readFileSync(p)).digest('hex');
- const snapshots=[['20261104-db-first',path.join(workspace,'work/voc-structure-20261105/workshop-baseline')],
- ['20261105-prepared-r1',path.join(workspace,'artifacts/康师傅VOC结构化入库-20261105/ksf-voc-library-20261105-r1/materials/skills/ksf-workshop-runtime')]];
- const results=[];
- for(const [label,baseline] of snapshots){
- const dest=path.join(targetRoot,label,'skills/ksf-workshop-runtime');
- const binding=path.join(dest,'credential-binding.json');
- const session=path.join(targetRoot,label,'ksf-workshop-state/sessions/test.json');
- const a=hash(binding),b=hash(session),source=path.join(packageRoot,'materials/skills/ksf-workshop-runtime');
- const plan=installWorkshopSkill(source,dest,{apply:false});
- if(JSON.stringify(plan.changed.sort())!==JSON.stringify(['FILES.sha256','SKILL.md','references/workshop-tasks.md']))throw Error('UNEXPECTED_CHANGES');
- const apply=installWorkshopSkill(source,dest);
- if(hash(binding)!==a||hash(session)!==b)throw Error('FIXTURE_STATE_CHANGED');
- const noOp=installWorkshopSkill(source,dest,{apply:false});if(noOp.changed.length)throw Error('REINSTALL_NOT_NOOP');
- results.push({baseline:label,plan,apply,reinstallNoOp:true,credentialAndStateFixturePreserved:true});
- }
- console.log(JSON.stringify({ok:true,baselines:results,productionInstalled:false}));
- ''',encoding='utf-8')
- workshop=run(['node',str(node_script),str(PACKAGE),str(ROOT),str(TARGET/'workshop')])
- write(PACKAGE/'receipts/workshop-install-validation.json',workshop)
- validator=Path('C:/Users/JSHY/.codex/skills/.system/skill-creator/scripts/quick_validate.py')
- results=[]
- for folder in [ROOT/'skills/ksf-voc-library',PACKAGE/'skill',ROOT/'work/five-views-delivery-20261103/skills/ksf-workshop-runtime',PACKAGE/'materials/skills/ksf-workshop-runtime']:
- proc=subprocess.run([sys.executable,'-B','-X','utf8',str(validator),str(folder)],capture_output=True,text=True,encoding='utf-8')
- assert proc.returncode==0,proc.stdout+proc.stderr
- results.append(dict(path=str(folder),ok=True,output=proc.stdout.strip()))
- write(PACKAGE/'receipts/skill-validation.json',dict(ok=True,results=results))
- print(json.dumps(dict(ok=True,installedExamples=len(examples),getSourceVerified=True,workshopBaselines=2,skillValidations=4,productionInstalled=False),ensure_ascii=False,indent=2))
- if __name__=='__main__':main()
|