forked from mtusi2026/mtusi2026lab3
74 lines
4.7 KiB
Plaintext
74 lines
4.7 KiB
Plaintext
date: 2026-11-05T22:15:19.343707+00:00 commit: 55b99a24a493faec8e61bf2c6a98e14e0229fe60
|
|
$ python3 <<'PY'
|
|
import csv
|
|
import json
|
|
import re
|
|
import statistics
|
|
import struct
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
root = Path('evidence/track1-sqlalchemy')
|
|
protected = subprocess.check_output(['git','diff','5c8f605cd3bd40245109348463d3e7111379b2d3','--name-only','--','contracts','tests','README.md','COURSE.md','.pipeline'],text=True)
|
|
assert not protected, protected
|
|
subprocess.run(['git','diff','--exit-code','57744c532c58d3e2bd248b4368ecba0a42402ed8','HEAD','--','src','alembic','Dockerfile','compose.yaml','pyproject.toml','uv.lock'],check=True)
|
|
tracked = subprocess.check_output(['git','ls-files','-z'],text=True).split('\0')
|
|
assert not [p for p in tracked if p == '.env' or p.startswith(('secrets/','volumes/'))]
|
|
headers=[]
|
|
secret_files=[]
|
|
patterns=[r'Bearer\s+[A-Za-z0-9._-]{20,}',r'(?:postgres(?:ql)?|rediss?)://[^\s:]+:[^\s@]+@',r'-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----']
|
|
for p in root.rglob('*'):
|
|
if not p.is_file(): continue
|
|
if p.suffix=='.png':
|
|
data=p.read_bytes(); pos=8; description=''
|
|
while pos<len(data):
|
|
length=struct.unpack('>I',data[pos:pos+4])[0]; kind=data[pos+4:pos+8]; payload=data[pos+8:pos+8+length]; pos+=length+12
|
|
if kind==b'tEXt' and payload.startswith(b'Description\0'): description=payload.split(b'\0',1)[1].decode()
|
|
assert description.startswith('date:') and 'commit:' in description,p
|
|
continue
|
|
text=p.read_text()
|
|
if p.suffix=='.json':
|
|
data=json.loads(text)
|
|
values=[data] if isinstance(data,dict) else data
|
|
assert all('date' in value and 'commit' in value for value in values),p
|
|
if p.name=='summary.json' and p.parent.name=='k6': assert 'setup_data' not in data,p
|
|
elif not text.startswith(('date:','# date:')):
|
|
headers.append(str(p))
|
|
if any(re.search(pattern,text,re.I) for pattern in patterns): secret_files.append(str(p))
|
|
assert not headers,headers
|
|
assert not secret_files,secret_files
|
|
revalidation=root/'revalidation'
|
|
for p in list((revalidation/'detection').glob('*/*.json'))+list((revalidation/'failover-each').glob('*/result.json'))+[revalidation/'rolling/result.json',revalidation/'lb-check.json',revalidation/'retry.json']:
|
|
assert json.loads(p.read_text())['pass'],p
|
|
for p in list((revalidation/'failover-each').glob('*/result.json'))+[revalidation/'rolling/result.json']:
|
|
data=json.loads(p.read_text())
|
|
assert data['history']['exact_match'] and data['history']['unique']
|
|
assert data['history']['confirmed']==data['history']['stored']
|
|
assert data['k6']['failed_ratio']==0 and data['k6']['dropped_iterations']==0
|
|
raw=json.loads((p.parent/'k6/summary.json').read_text())['metrics']
|
|
assert data['k6']['requests']==raw['http_reqs{scenario:measure}']['values']['count']
|
|
assert (revalidation/'rolling/action.txt').read_text().count('migrate once before the first replacement')==1
|
|
commands=(revalidation/'commands.txt').read_text()
|
|
assert '290 passed, 12 deselected' in commands and '12 passed in' in commands
|
|
assert all(code=='0' for code in re.findall(r'^exit: (\d+)$',commands,re.M))
|
|
rows=list(csv.DictReader(line for line in (root/'compare/summary.csv').open() if not line.startswith('#')))
|
|
report=Path('REPORT.md').read_text()
|
|
for variant,expected in [('before',14.28),('after',4.63)]:
|
|
values=[float(r['p95_ms']) for r in rows if r['variant']==variant and r['rate']=='2400']
|
|
assert statistics.median(values)==expected and str(expected) in report
|
|
assert len(list((root/'plots').glob('*.png')))==12
|
|
assert not subprocess.check_output(['docker','ps','-aq','--filter','label=com.docker.compose.project=mtusi2026lab3-track5-20261105'],text=True).strip()
|
|
volumes=subprocess.check_output(['docker','volume','ls','-q','--filter','label=com.docker.compose.project=mtusi2026lab3-track5-20261105'],text=True).splitlines()
|
|
assert len(volumes)==2,volumes
|
|
print('PASS: protected paths unchanged; final API source matches measured image source; secrets not tracked/exposed by selected patterns')
|
|
print('PASS: provenance headers, 12 PNG descriptions, k6 without setup_data, public/own-test logs, 12 detection and 3 load results')
|
|
print('PASS: request counts match raw k6, exact unique histories, one migrate, report p95 matches CSV')
|
|
print('PASS: own project stopped, both persistent volumes retained')
|
|
PY
|
|
|
|
PASS: protected paths unchanged; final API source matches measured image source; secrets not tracked/exposed by selected patterns
|
|
PASS: provenance headers, 12 PNG descriptions, k6 without setup_data, public/own-test logs, 12 detection and 3 load results
|
|
PASS: request counts match raw k6, exact unique histories, one migrate, report p95 matches CSV
|
|
PASS: own project stopped, both persistent volumes retained
|
|
exit: 0
|