File size: 3,253 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
#!/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.rst ] || { mkdir -p "$(dirname "$PWD"/README.rst)"; : > "$PWD"/README.rst; };
  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= tests/test_cache.py tests/test_patch.py tests/test_patch_then_unpatch.py tests/test_replace.py tests/test_temp_patch.py tests/test_unpatch.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