Подтвердить запуск чистого экспорта и завершить аудит решения

This commit is contained in:
2026-10-30 18:13:52 +03:00
parent 6c87ed2eba
commit 8f112e092a
8 changed files with 290 additions and 31 deletions
+27
View File
@@ -0,0 +1,27 @@
"""Read-only audit: original materials, authorship, secrets and previous project."""
from pathlib import Path
import json
import subprocess
ROOT=Path(__file__).resolve().parents[1]
def git(*args): return subprocess.check_output(['git',*args],cwd=ROOT)
base='ec540a1'
protected=['README.md','COURSE.md','CONTRIBUTING.md','MAINTAINERS.md','contracts','tests']
assert not git('diff',base,'--',*protected).strip(), 'mandatory materials changed'
identity='Sergey Lyakhonov <lyserg119@gmail.com>'
for line in git('log',base+'..HEAD','--format=%an <%ae>|%cn <%ce>').decode().splitlines():
assert line==identity+'|'+identity, 'unexpected commit identity'
paths=git('ls-files','--cached','--others','--exclude-standard','-z').split(b'\0')
secret_dir=ROOT/'secrets'
values=[f.read_bytes().strip() for f in secret_dir.iterdir() if f.is_file()] if secret_dir.exists() else []
for raw in paths:
if not raw: continue
name=raw.decode('utf-8');file=ROOT/name
assert not name.startswith('secrets/') and name!='.env','private file tracked'
if file.is_file():
assert not any(value and value in file.read_bytes() for value in values), 'secret value in '+name
previous=ROOT.parent/'vysoko-nagr 3'
if previous.exists():
args=['git','-c','safe.directory='+str(previous),'-C',str(previous)]
assert not subprocess.check_output(args+['status','--porcelain']).strip(),'previous project changed'
assert subprocess.check_output(args+['rev-parse','HEAD']).decode().strip().startswith('374c43e'),'previous HEAD changed'
print('PASS: original materials unchanged; specified author/committer; no generated secrets in tracked/nonignored files; lab3 unchanged')
+54
View File
@@ -0,0 +1,54 @@
"""Verify a committed Git export with fresh secrets, isolated images/project/volumes."""
import json
import os
from pathlib import Path
import socket
import subprocess
import tarfile
import tempfile
import time
import uuid
ROOT=Path(__file__).resolve().parents[1]
project='lyakhonov-lab4-repro-'+uuid.uuid4().hex[:8]
with socket.socket() as sock:
sock.bind(('127.0.0.1',0)); port=sock.getsockname()[1]
env=dict(os.environ,LAB4_PORT=str(port),PYTHONUTF8='1')
commit=subprocess.check_output(['git','rev-parse','HEAD'],cwd=ROOT,text=True).strip()
with tempfile.TemporaryDirectory(prefix='lab4-repro-') as folder:
temporary=Path(folder).resolve()
assert temporary.parent==Path(tempfile.gettempdir()).resolve() and temporary.name.startswith('lab4-repro-')
archive=temporary/'source.tar'
subprocess.check_call(['git','archive','--format=tar','-o',str(archive),'HEAD'],cwd=ROOT)
source=temporary/'source';source.mkdir()
with tarfile.open(archive) as tar:
for member in tar.getmembers():
assert (source/member.name).resolve().is_relative_to(source.resolve())
tar.extractall(source,filter='data')
assert not (source/'secrets').exists() and not (source/'.env').exists()
override=source/'repro.override.yaml'
override.write_text('services:\n'+''.join(' '+name+':\n image: '+image+'\n' for name,image in [
('api',project+'-api'),('migrate',project+'-api'),('reconciler',project+'-api'),('s3',project+'-s3'),('bucket-init',project+'-s3')]),encoding='utf-8')
base=['docker','compose','--project-directory',str(source),'-f',str(source/'compose.yaml'),'-f',str(override),'-p',project]
def dc(*args,**kwargs): return subprocess.check_output(base+list(args),env=env,text=True,**kwargs)
existing=subprocess.check_output(['docker','ps','-aq','--filter','label=com.docker.compose.project='+project],text=True).strip()
assert not existing
subprocess.check_call(['python',str(source/'scripts/bootstrap.py')],env=env)
results={'commit':commit,'project':project,'port':port,'fresh_secrets':True,'isolated_images':True}
try:
with (ROOT/'evidence/repro-build.txt').open('w',encoding='utf-8') as buildlog:
subprocess.check_call(base+['build','api','s3'],env=env,stdout=buildlog,stderr=subprocess.STDOUT)
dc('up','-d')
ready=subprocess.check_output(['python',str(source/'scripts/wait_ready.py'),'--base-url','http://localhost:'+str(port),'--replicas','2'],env=env,text=True)
smoke=subprocess.check_output(['python',str(source/'tests/smoke.py'),'--base-url','http://localhost:'+str(port)],env=env,text=True)
results.update(result='PASS',readiness=ready.strip(),smoke=smoke.strip())
# Remove only volumes belonging to this newly created unique scratch project.
volumes=subprocess.check_output(['docker','volume','ls','-q','--filter','label=com.docker.compose.project='+project],text=True).split()
for volume in volumes:
labels=json.loads(subprocess.check_output(['docker','volume','inspect',volume],text=True))[0]['Labels']
assert labels['com.docker.compose.project']==project
results['scratch_volumes']=volumes
finally:
dc('down','--volumes')
results['scratch_cleaned']=True
(ROOT/'evidence/clean-export.json').write_text(json.dumps(results,indent=2),encoding='utf-8')
print('PASS: committed clean export built API/S3, fresh secrets, two API replicas and public smoke; scratch stack cleaned')