| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- """Refresh local review artifacts and check the instruction-only Doubao revision."""
- from pathlib import Path
- import difflib
- import hashlib
- import json
- import re
- import runpy
- from urllib.parse import unquote
- OUT = Path(__file__).resolve().parent
- ROOT = OUT.parents[1]
- SKILL = ROOT / 'skills/ksf-workshop-runtime'
- def sha(path):
- return hashlib.sha256(path.read_bytes()).hexdigest()
- def main():
- baseline = dict(line.split(' ', 1)[::-1] for line in
- (OUT / 'before/FILES.sha256').read_text(encoding='utf-8').splitlines())
- assert len(baseline) == 41
- actual = {p.relative_to(SKILL).as_posix() for p in SKILL.rglob('*') if p.is_file()}
- assert actual == set(baseline) | {'FILES.sha256'}, actual ^ set(baseline)
- changes = [name for name, digest in baseline.items() if sha(SKILL / name) != digest]
- assert len(changes) == 20 and all(name.endswith('.md') for name in changes)
- runtime = [name for name in baseline if name.startswith('scripts/') or name == 'runtime-lock.json']
- assert len(runtime) == 7 and all(sha(SKILL / name) == baseline[name] for name in runtime)
- assert sha(SKILL / 'references/workshop-commercial-feasibility.md') == baseline['references/workshop-commercial-feasibility.md']
- # Check the recorded transformation against the originals without applying it again.
- update = runpy.run_path(str(OUT / 'update_local_skill.py'))
- for name in changes:
- before = (OUT / 'before' / name).read_text(encoding='utf-8')
- assert sha(OUT / 'before' / name) == baseline[name]
- expected = before
- for old, new in update['GENERAL'] + update['SPECIFIC'].get(name, []):
- expected = expected.replace(old, new)
- if name == 'SKILL.md':
- pos = expected.index('\n## ') + 1
- expected = expected[:pos] + update['ENVIRONMENT'] + expected[pos:]
- after = (SKILL / name).read_text(encoding='utf-8')
- assert after == expected, 'Unrecorded edit: ' + name
- patch = OUT / 'diff' / (name + '.diff')
- patch.write_text(''.join(difflib.unified_diff(
- before.splitlines(True), after.splitlines(True),
- fromfile='r6/' + name, tofile='local-doubao/' + name)), encoding='utf-8', newline='\n')
- refs = list((SKILL / 'references').rglob('*'))
- assert sum(p.suffix == '.md' for p in refs) == 31
- assert sum(p.suffix == '.json' for p in refs) == 2
- links = 0
- for path in SKILL.rglob('*.md'):
- content = path.read_text(encoding='utf-8')
- for target in re.findall(r'\[[^\]]*\]\(([^)\s]+)\)', content):
- if target.startswith(('https:', 'http:', '#')):
- continue
- target_path = unquote(target.split('#', 1)[0])
- if target_path:
- assert (path.parent / target_path).is_file(), (path, target)
- links += 1
- if path.name != 'SKILL.md':
- assert not re.search(r'付费|收费|计费|停费|paidCalls|零费用', content), path
- intake = (SKILL / 'references/workshop-intake.md').read_text(encoding='utf-8')
- assert len(re.findall(r'^\| D[12]-(?:\d+|N) ', intake, re.M)) == 13
- sealed = ROOT / 'docs/workshop-skill-release-20261109-r6/ksf-workshop-skill-update-20261109-r6.zip'
- assert sha(sealed) == 'c329432b9773cfb0a8e5d4a3e5c162b3778eab28d576b79875da6854f33c4dc5'
- manifest = ''.join(sha(SKILL / name) + ' ' + name + '\n' for name in baseline)
- (SKILL / 'FILES.sha256').write_text(manifest, encoding='utf-8', newline='\n')
- report = {
- 'kind': 'local-instruction-draft-not-installed-remotely', 'baseline': 'r6',
- 'changes': [{'path': name, 'beforeSha256': baseline[name],
- 'afterSha256': sha(SKILL / name)} for name in changes],
- 'skillSha256': sha(SKILL / 'SKILL.md'),
- 'manifestSha256': sha(SKILL / 'FILES.sha256'),
- 'publicFilesVerified': 42, 'manifestEntriesVerified': 41,
- 'relativeLinksVerified': links, 'referenceFilesVerified': 33,
- 'intakeStagesPreserved': 13, 'runtimeFilesChanged': 0,
- 'businessCostRulesUnchanged': True, 'sealedR6PackageModified': False,
- 'doubaoExecutionVerified': False, 'remoteInstalled': False,
- }
- (OUT / 'change-receipt.json').write_text(
- json.dumps(report, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
- print(json.dumps({k: v for k, v in report.items() if k != 'changes'}, ensure_ascii=False, indent=2))
- if __name__ == '__main__':
- main()
|