Files

28 lines
2.1 KiB
Python

import pathlib,subprocess,sys,json,os,signal
root=pathlib.Path.cwd();out=pathlib.Path(sys.argv[1]);out.mkdir(parents=True,exist_ok=True)
assert root != pathlib.Path('/mnt/storage/src/mosaic-stack')
assert os.environ.get('DOCKER_HOST')=='unix:///nonexistent.sock'
bus='scripts/bus-service.sh';stack='scripts/stack-copy.sh';test='packages/cli/tests/stack-copy.test.mjs'
muts=[
('miss-prefix',bus,' "$directory"/mosaic-.service.d','', 'inherited mosaic'),
('miss-all-services',bus,' "$directory"/service.d','', 'inherited service'),
('ignore-unreadable-directory',bus,'[ -d "$dropdir" ] && [ -r "$dropdir" ] && [ -x "$dropdir" ] || die',': || die','inherited drop-in unreadable'),
('ignore-unreadable-file',bus,'content="$(cat "$file" 2>/dev/null)" || die "refusing: cannot read drop-in $file; nothing was changed"','content="$(cat "$file" 2>/dev/null)" || content=""','inherited drop-in unreadable'),
('omit-copy-comment',stack,'# CLI runs from pinned copy: %s','# CLI copy unspecified: %s','wrapper preserves'),
('omit-lease-comment',stack,'# The Q81 lease probe still answers at mosaic-old.','# Lease explanation omitted.','wrapper preserves'),
('accept-foreign-check-wrapper',stack,'[ "$(sed -n \'2p\' "$BIN/mosaic")" = "$MARKER" ]; then','[ 1 = 1 ]; then','wrapper preserves'),
]
results=[]
for name,file,old,new,pattern in muts:
p=root/file;original=p.read_text();assert original.count(old)==1,(name,original.count(old))
try:
p.write_text(original.replace(old,new,1))
with (out/(name+'.txt')).open('w') as log:
child=subprocess.Popen(['node','--test','--test-name-pattern='+pattern,test],stdout=log,stderr=subprocess.STDOUT,start_new_session=True)
try:code=child.wait(timeout=60);status='killed' if code else 'survived'
except subprocess.TimeoutExpired:os.killpg(child.pid,signal.SIGKILL);child.wait();code=124;status='timeout'
row={'name':name,'exit':code,'status':status};results.append(row);print(json.dumps(row),flush=True)
(out/'summary.json').write_text(json.dumps(results,indent=2)+'\n')
finally:p.write_text(original)
sys.exit(any(r['status']!='killed' for r in results))