File size: 1,872 Bytes
b67a1e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
import json
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
OUT=ROOT/'archive_plan'
errors=[]
for p in [OUT/'ARCHIVE_PLAN.md',OUT/'archive_manifest.json',OUT/'result.json',OUT/'candidates']:
    if not p.exists(): errors.append(f'missing: {p.relative_to(ROOT)}')
res={}
if (OUT/'result.json').exists():
    try: res=json.loads((OUT/'result.json').read_text(encoding='utf-8'))
    except Exception as e: errors.append(f'invalid result.json: {e}')
docs=list((OUT/'candidates').glob('*.md')) if (OUT/'candidates').exists() else []
if res:
    if res.get('mode')!='READ_ONLY_ARCHIVE_PLAN': errors.append('wrong mode')
    if res.get('candidates')!=len(docs): errors.append('candidate doc count mismatch')
    for m in res.get('manifest',[]):
        if not m.get('human_gate'): errors.append(f'{m.get("path")} missing human gate')
        if not m.get('recommended_action'): errors.append(f'{m.get("path")} missing recommended_action')
for d in docs:
    txt=d.read_text(encoding='utf-8',errors='ignore').lower()
    for must in ['required pre-archive checks','human gate','never delete','status = needs_human']:
        if must not in txt: errors.append(f'{d.relative_to(ROOT)} missing {must}')
for jp in res.get('jobs',[]):
    p=Path(jp)
    if not p.exists(): errors.append(f'missing job {jp}'); continue
    data=json.loads(p.read_text(encoding='utf-8'))
    if data.get('mode')!='review_only': errors.append(f'{p.name} not review_only')
    f=' '.join(data.get('forbidden_actions',[])).lower()
    for word in ['delete files','move files','archive files','commit','push','merge']:
        if word not in f: errors.append(f'{p.name} missing forbid {word}')
if errors:
    print('verify_archive_plan: failed')
    for e in errors: print('-',e)
    raise SystemExit(1)
print(f'verify_archive_plan: passed ({len(docs)} candidates)')