File size: 4,637 Bytes
d086025 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | #!/bin/bash
# Harbor verifier: inject the hidden suite, run it, and score against the
# generation-time measured test count. Every path emits reward + metrics.
set -uo pipefail
mkdir -p /logs/verifier
cd "${WORKDIR:-/workspace/repo}"
OUT_FILE=/logs/verifier/test-output.log
: > "$OUT_FILE"
EXPECTED=$(python3 -c 'import json; d=json.load(open("/tests/tests.json")); print(int(d.get("expected_test_count") or d.get("measured_test_count") or 0))' 2>/dev/null || echo 0)
grade_and_exit() {
local phase="$1" reason="$2" rc="$3"
python3 /tests/grader.py --output "$OUT_FILE" --return-code "$rc" --expected-count "$EXPECTED" --phase "$phase" --reason "$reason" >/dev/null
cat /logs/verifier/reward.txt
exit 0
}
python3 - /tests/test_patch.diff <<'PY' 2>/dev/null || true
import os, sys
try:
lines = open(sys.argv[1], encoding='utf-8', errors='replace').read().splitlines()
except OSError:
lines = []
i = 0
while i < len(lines):
line = lines[i]
if line.startswith('diff --git a/'):
rest = line[len('diff --git a/'):]
split = rest.find(' b/')
path = rest[:split] if split != -1 else None
is_new = False
j = i + 1
while j < len(lines) and not lines[j].startswith('diff --git '):
is_new = is_new or lines[j].startswith('new file mode')
j += 1
if is_new and path and os.path.isfile(path):
try:
os.remove(path)
except OSError:
pass
i = j
continue
i += 1
PY
PATCH_APPLIED=0
if git apply --check /tests/test_patch.diff 2>/dev/null; then
git apply /tests/test_patch.diff 2>/dev/null && PATCH_APPLIED=1
elif git apply --reverse --check /tests/test_patch.diff 2>/dev/null; then
PATCH_APPLIED=1
elif patch --dry-run -p1 < /tests/test_patch.diff >/dev/null 2>&1; then
patch -p1 < /tests/test_patch.diff >/dev/null 2>&1 && PATCH_APPLIED=1
fi
if [ "$PATCH_APPLIED" -ne 1 ]; then
echo 'hidden test patch could not be applied' > "$OUT_FILE"
grade_and_exit patch hidden-test-patch-failed 1
fi
if ! {
[ -e "$PWD"/README.md ] || { mkdir -p "$(dirname "$PWD"/README.md)"; : > "$PWD"/README.md; };
SETUPTOOLS_SCM_PRETEND_VERSION=0.0.0 PDM_BUILD_SCM_VERSION=0.0.0 POETRY_DYNAMIC_VERSIONING_BYPASS=0.0.0 UV_DYNAMIC_VERSIONING_BYPASS=0.0.0 PIP_NO_INDEX=1 PIP_FIND_LINKS=/usr/local/lib/programgen-build-wheels SETUPTOOLS_SCM_WRITE_TO_SOURCE=1 python3 -m pip install -e "$PWD" --no-deps;
} >/logs/verifier/pip-install.log 2>&1; then
cat /logs/verifier/pip-install.log > "$OUT_FILE"
grade_and_exit install python-install-contract-failed 86
fi
if [ -d /tests/test_assets ]; then
find /tests/test_assets -mindepth 1 -maxdepth 1 -exec cp -a -t "$PWD" -- {} +
fi
timeout --signal=TERM --kill-after=30s 3300s bash -lc 'set -uo pipefail
run=(python3 -m pytest -vv --continue-on-collection-errors -o addopts= tests/test_bench_handler.py tests/test_cli_handler.py tests/test_log_handler.py tests/test_meta_handler.py tests/test_sutools.py)
if [ -n "${COVERAGE_FILE:-}" ]; then run=(python3 -m coverage run --source=. -m pytest -vv --continue-on-collection-errors -o addopts= tests/test_bench_handler.py tests/test_cli_handler.py tests/test_log_handler.py tests/test_meta_handler.py tests/test_sutools.py); fi
collect=(python3 -m pytest -q -o addopts= tests/test_bench_handler.py tests/test_cli_handler.py tests/test_log_handler.py tests/test_meta_handler.py tests/test_sutools.py)
collected_output=$("${collect[@]}" --collect-only)
collect_rc=$?
if [ "$collect_rc" -ne 0 ] && [ "$collect_rc" -ne 5 ]; then
printf "%s\n" "$collected_output" >&2
printf "[programgen] test collection failed with exit code %s\n" "$collect_rc" >&2
exit "$collect_rc"
fi
mapfile -t collected < <(printf "%s\n" "$collected_output" | sed -n '"'"'/::/p'"'"' | sed '"'"'s/[[:space:]]*$//'"'"')
if [ "${#collected[@]}" -gt 500 ]; then
while IFS= read -r id; do run+=("--deselect=$id"); done < <(printf "%s\n" "${collected[@]}" | awk -F'"'"'::'"'"' -v limit=500 '"'"'{f=$1; n[f]++; idx[f,n[f]]=NR; all[NR]=$0; if(!(f in seen)){seen[f]=1; order[++m]=f}} END{d=1; c=0; while(c<limit){a=0; for(i=1;i<=m;i++){f=order[i]; if(d<=n[f]){keep[idx[f,d]]=1; c++; a=1; if(c>=limit) break}} if(!a) break; d++} for(r=1;r<=NR;r++) if(!(r in keep)) print all[r]}'"'"')
fi
"${run[@]}"; exit $?' 2>&1 | tail -c 1500000 > "$OUT_FILE"
RC=${PIPESTATUS[0]}
cat "$OUT_FILE"
if [ "$RC" -eq 124 ] || [ "$RC" -eq 137 ]; then
grade_and_exit tests verifier-timeout "$RC"
fi
python3 /tests/grader.py --output "$OUT_FILE" --return-code "$RC" --expected-count "$EXPECTED" --phase tests >/dev/null
cat /logs/verifier/reward.txt
|