38 lines
1.8 KiB
Bash
Executable File
38 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
|
exec "$ROOT/scripts/agent_jail.sh" "$1" "${2:-e2e}" -- python3 - <<'PY'
|
|
import os, subprocess
|
|
from pathlib import Path
|
|
rd=Path(os.environ['BENCH_ROLLOUT_DIR']); bench=Path(os.environ['BENCH_ROOT'])
|
|
jd=rd.parent.parent
|
|
fails=[]
|
|
def check(label, ok):
|
|
print(('PASS ' if ok else 'FAIL ')+label, flush=True)
|
|
if not ok: fails.append(label)
|
|
def unreadable(p):
|
|
try: p.read_bytes(); return False
|
|
except OSError: return True
|
|
def unwritable(p):
|
|
# Never truncate a real existing file, even on a broken jail.
|
|
try:
|
|
fd=os.open(p, os.O_WRONLY | os.O_APPEND); os.close(fd); return False
|
|
except OSError: return True
|
|
other=jd.parent/'cls--resnet18--nash-m--ptq--int8'/'oracle'/'result.json'
|
|
check('other job oracle hidden', unreadable(other))
|
|
check('state sqlite hidden', unreadable(bench/'state/jobs.sqlite'))
|
|
check('real state sqlite hidden', unreadable(Path.home()/'bench-state/jobs.sqlite'))
|
|
for p in [bench/'registry/gates.yaml', bench/'harness/gates.py', other, bench/'state/x', Path.home()/'bench-state/x',rd/'rollout.json']:
|
|
check('write denied '+str(p), unwritable(p))
|
|
# Only create a NEW workspace artifact.
|
|
p=rd/'workspace'/('probe-'+str(os.getpid()))
|
|
try: p.write_text('probe'); check('workspace writable', True)
|
|
except OSError: check('workspace writable', False)
|
|
r=subprocess.run([str(bench/'bin/bench'),'stage','status','nonexistent'],capture_output=True,text=True)
|
|
check('stdlib stage status executes',r.returncode==1 and 'handle 不存在' in r.stderr and 'harness' not in r.stderr)
|
|
r=subprocess.run(['mount','-o','remount,bind,rw',str(rd)],capture_output=True)
|
|
check('cannot undo read-only mounts',r.returncode!=0)
|
|
check('host processes hidden',len(list(Path('/proc').glob('[0-9]*')))<15)
|
|
raise SystemExit(bool(fails))
|
|
PY
|