Conghao97's picture tcftrees's picture
ProgramGen release
d086025
Raw History Blame Contribute Delete
3.14 kB
#!/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 SETUPTOOLS_SCM_WRITE_TO_SOURCE=1 python3 -m pip install -e "$PWD" --no-build-isolation --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 python3 -m pytest -vv --continue-on-collection-errors -o addopts= url_parser/tests/test_url_parser.py 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