66 lines
4.1 KiB
Python
66 lines
4.1 KiB
Python
from pathlib import Path
|
|
import re,json,hashlib,subprocess
|
|
from collections import Counter
|
|
from pypdf import PdfReader
|
|
root=next(p for p in Path(__file__).resolve().parents if (p/'AGENTS.md').is_file())
|
|
task=root/'work/undo-redo-report-0.1.4'
|
|
evidence=root/'documents/assets/undo-redo-report-2026-11-24'
|
|
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
|
|
protected=json.loads((evidence/'protected-before.json').read_text())
|
|
for item in protected:
|
|
p=root/item['path'];assert p.exists() and sha(p)==item['sha256'],p
|
|
latex=root/'documents/latex'
|
|
alltex='\n'.join(p.read_text(encoding='utf-8-sig') for p in latex.glob('*.tex'))
|
|
counts={}
|
|
for macro,prefix,expected in [('RequirementID','REQ-',111),('TestCaseID','TC-',82),('VerificationID','VER-',111),('AIRequirementID','AI-REQ-',17),('UseCaseID','UC-',9),('UserStoryID','US-',11),('ValidationID','VAL-',11)]:
|
|
ids=re.findall(r'\\'+macro+r'\{('+prefix+r'[^}]+)\}',alltex)
|
|
assert len(ids)==expected,(macro,len(ids))
|
|
assert len(ids)==len(set(ids)),macro
|
|
counts[macro]=len(ids)
|
|
def rows(file,macro):
|
|
source=(latex/file).read_text()
|
|
pattern=r'(?ms)^\\'+macro+r'\{([^}]+)\}(.*?)(?=^\\'+macro+r'\{|^\\end\{tabularx\})'
|
|
return dict(re.findall(pattern,source))
|
|
requirements=rows('tkrRequirements.tex','RequirementID')
|
|
tests=rows('tkrTests.tex','TestCaseID')
|
|
verification=rows('tkrVerification.tex','VerificationID')
|
|
usecases=(latex/'tkrUseCases.tex').read_text()
|
|
case=re.search(r'(?s)\\section\{Undo or Redo an Edit\}(.*?)(?=\\clearpage)',usecases)[1]
|
|
case_ids=set(re.findall(r'\\RequirementRef\{([^}]+)\}',case))
|
|
req_ids={k for k,v in requirements.items() if r'\UseCaseRef{UC-004}' in v}
|
|
assert req_ids==case_ids,(req_ids^case_ids)
|
|
for rid in req_ids:
|
|
for tid in re.findall(r'\\TestCaseRef\{([^}]+)\}',requirements[rid]):
|
|
assert r'\RequirementRef{'+rid+'}' in tests[tid],(rid,tid)
|
|
for vid in re.findall(r'\\VerificationRef\{([^}]+)\}',requirements[rid]):
|
|
assert r'\RequirementRef{'+rid+'}' in verification[vid],(rid,vid)
|
|
for tid in re.findall(r'\\TestCaseRef\{([^}]+)\}',verification[vid]):
|
|
assert r'\VerificationRef{'+vid+'}' in tests[tid],(tid,vid)
|
|
# New log/approval guidance cannot change the controlled directive statuses.
|
|
directives=(latex/'tkrAIAgentRequirements.tex').read_text()
|
|
assert directives.count(r'\ReqStatusInProgress')==18 # purpose + 17 rows
|
|
assert not re.search(r'\\ReqStatusDone',directives)
|
|
pdf_checks={}
|
|
for edition in ['TikZRefinerySubmission','TikZRefinery']:
|
|
base=task/'build'/edition;reader=PdfReader(base/(edition+'.pdf'));destinations=reader.named_destinations
|
|
links=0;bad=[]
|
|
for i,page in enumerate(reader.pages):
|
|
for ref in page.get('/Annots',[]):
|
|
item=ref.get_object();dest=item.get('/Dest');action=item.get('/A')
|
|
if action and action.get('/S')=='/GoTo':dest=action.get('/D')
|
|
if dest is None:continue
|
|
links+=1
|
|
if isinstance(dest,str) and dest not in destinations:bad.append((i+1,str(dest)))
|
|
assert not bad,bad
|
|
log=(base/(edition+'.log')).read_text(errors='replace')
|
|
bad_log=re.findall(r'^.*(?:Overfull|Float too large|undefined references|undefined citations|Citation .+ undefined|Reference .+ undefined|destination with the same identifier|LaTeX Error).*$' ,log,re.M)
|
|
assert not bad_log,bad_log
|
|
aux='\n'.join(p.read_text(errors='replace') for p in base.glob('*.aux'))
|
|
labels=dict((m[1],m[3]) for m in re.finditer(r'\\newlabel\{([^}]+)\}\{\{([^}]*)\}\{([^}]*)\}',aux))
|
|
required=['Figure:PlannedTransactionClasses','Figure:TransactionDetails','Figure:TransactionActivity','Figure:TransactionSequence','Figure:UC004Diagram']
|
|
assert all(k in labels for k in required)
|
|
pdf_checks[edition]=dict(pages=len(reader.pages),internalLinks=links,namedDestinations=len(destinations),figurePages={k:labels[k] for k in required},underfullNotices=log.count('Underfull'))
|
|
result=dict(date='2026-11-24',reportVersion='0.1.4-alpha',applicationAndDemoVersion='0.1.3-alpha',protectedFilesUnchanged=len(protected),registers=counts,undoRequirementsReciprocallyChecked=len(req_ids),pdfs=pdf_checks,applicationTestsRun=False,source='Authored TeX; PDF metadata/navigation only, no PDF text extraction')
|
|
(evidence/'checks.json').write_text(json.dumps(result,indent=2)+'\n')
|
|
print(json.dumps(result,indent=2))
|