| #!/bin/bash |
| set -uo pipefail |
| mkdir -p /logs/verifier |
| patch_applied=1 |
| fail_to_pass=0 |
| pass_to_pass=0 |
| deterministic=0 |
| setup_completed=0 |
| fail_to_pass_exit_code=-1 |
| fail_to_pass_repeat_exit_code=-1 |
| pass_to_pass_exit_code=-1 |
| verifier_cache="" |
|
|
| kill_verifier_processes() { pkill -KILL -u "$(id -u verifier)" 2>/dev/null || true; } |
| |
| |
| |
| run_verifier_command() { |
| local logfile |
| logfile="$(mktemp /tmp/selfbench-verifier-command-XXXXXX.log)" |
| local attempt=1 |
| local status=1 |
| while [ "$attempt" -le 3 ]; do |
| : > "$logfile" |
| runuser -u verifier -- env PATH="/usr/local/go/bin:/usr/local/cargo/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin" UV_CACHE_DIR="$verifier_cache" UV_NO_BUILD_ISOLATION=1 bash -lc "$1" >"$logfile" 2>&1 |
| status=$? |
| if [ "$status" -eq 0 ]; then |
| break |
| fi |
| if [ "$attempt" -lt 3 ] && grep -qE 'ECONNRESET|ETIMEDOUT|ESOCKETTIMEDOUT|ENOTFOUND|EAI_AGAIN|META_FETCH_FAIL|FetchError|EPIPE|EPERM|registry\.npmjs' "$logfile"; then |
| sleep "$((10 * attempt))" |
| attempt=$((attempt + 1)) |
| continue |
| fi |
| break |
| done |
| cat "$logfile" |
| rm -f "$logfile" |
| kill_verifier_processes |
| return "$status" |
| } |
| protect_held_out_path() { |
| local path="$1" |
| chown -R root:root -- "$path" |
| chmod -R a-w,go+rX -- "$path" |
| } |
|
|
| if [ ! -f /opt/selfbench/agent.patch ]; then |
| patch_applied=0 |
| elif [ -s /opt/selfbench/agent.patch ]; then |
| git -C /app apply --binary --whitespace=nowarn --exclude='test/production/app-dir/browser-chunks/browser-chunks.test.ts' --exclude='test/production/app-dir/browser-chunks/browser-chunks.test.ts/*' --exclude='test/production/app-dir/browser-chunks/browser-runtime.test.ts' --exclude='test/production/app-dir/browser-chunks/browser-runtime.test.ts/*' /opt/selfbench/agent.patch || patch_applied=0 |
| fi |
|
|
| if [ "$patch_applied" -eq 1 ]; then setup_completed=1; fi |
|
|
| if [ "$patch_applied" -eq 1 ] && [ "$setup_completed" -eq 1 ]; then |
| kill_verifier_processes |
| git -C /app restore --source=HEAD --staged --worktree -- 'test/production/app-dir/browser-chunks/browser-chunks.test.ts' 'test/production/app-dir/browser-chunks/browser-runtime.test.ts' 2>/dev/null || true |
| git -C /app clean -fd -- 'test/production/app-dir/browser-chunks/browser-chunks.test.ts' 'test/production/app-dir/browser-chunks/browser-runtime.test.ts' >/dev/null 2>&1 || true |
| git -C /app apply --binary --whitespace=nowarn /tests/test.patch || patch_applied=0 |
| if [ "$patch_applied" -eq 1 ]; then |
| for protected_path in '/app/test/production/app-dir/browser-chunks/browser-chunks.test.ts' '/app/test/production/app-dir/browser-chunks/browser-runtime.test.ts'; do protect_held_out_path "$protected_path"; done |
| fi |
| rm -f /tests/test.patch |
| fi |
|
|
| if [ "$patch_applied" -eq 1 ] && [ "$setup_completed" -eq 1 ]; then |
| cd '/app/.' |
| verifier_cache="$(mktemp -d /tmp/selfbench-verifier-uv-XXXXXX)" |
| cp -a /opt/uv-cache/. "$verifier_cache"/ |
| chown -R verifier:verifier "$verifier_cache" |
| if run_verifier_command 'pnpm swc-build-native && pnpm build && pnpm test-start-experimental-turbo '"'"'test/production/app-dir/browser-chunks/browser-chunks.test.ts'"'"''; then |
| fail_to_pass_exit_code=0 |
| fail_to_pass=1 |
| if run_verifier_command 'pnpm swc-build-native && pnpm build && pnpm test-start-experimental-turbo '"'"'test/production/app-dir/browser-chunks/browser-chunks.test.ts'"'"''; then |
| fail_to_pass_repeat_exit_code=0 |
| deterministic=1 |
| else |
| fail_to_pass_repeat_exit_code=$? |
| fi |
| else |
| fail_to_pass_exit_code=$? |
| fi |
| if run_verifier_command 'pnpm swc-build-native && pnpm build && pnpm test-start-experimental-turbo '"'"'test/production/app-dir/browser-chunks/browser-runtime.test.ts'"'"''; then |
| pass_to_pass_exit_code=0 |
| pass_to_pass=1 |
| else |
| pass_to_pass_exit_code=$? |
| fi |
| rm -rf "$verifier_cache" |
| fi |
|
|
| reward=0 |
| if [ "$patch_applied" -eq 1 ] && [ "$fail_to_pass" -eq 1 ] && [ "$pass_to_pass" -eq 1 ] && [ "$deterministic" -eq 1 ]; then reward=1; fi |
| cat > /logs/verifier/reward.json <<EOF |
| {"reward": $reward, "patch_applied": $patch_applied, "fail_to_pass": $fail_to_pass, "pass_to_pass": $pass_to_pass, "deterministic": $deterministic, "setup_completed": $setup_completed, "fail_to_pass_exit_code": $fail_to_pass_exit_code, "fail_to_pass_repeat_exit_code": $fail_to_pass_repeat_exit_code, "pass_to_pass_exit_code": $pass_to_pass_exit_code} |
| EOF |
| exit 0 |
|
|