Datasets:

Modalities:
Text
Languages:
English
Size:
< 1K
ArXiv:
Libraries:
Datasets
Harbor
License:
lewtun HF Staff commited on
Commit
69ae06b
·
verified ·
1 Parent(s): cd6751c

grader: isolated Python (-I -S), no PATH tools (#120 review #5); check.py: import and PATH cheats (part 5)

Browse files
tasks/agg-p31-n01/tests/test.sh CHANGED
@@ -7,15 +7,18 @@
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
- # of the check also scores 0. A copy of the answer stays with the trial's results. ANSWER,
11
- # EXPECTED and VERIFIER_DIR override the paths (no links in them), to test the grader locally.
12
- answer=${ANSWER:-/app/answer.json}
13
- expected=${EXPECTED:-$(dirname "$0")/expected.json}
14
- verifier=${VERIFIER_DIR:-/logs/verifier}
15
- mkdir -p "$verifier"
16
- rm -f "$verifier/reward.txt" "$verifier/reward.json" "$verifier/answer.json"
17
- echo 0 > "$verifier/reward.txt"
18
- ANSWER="$answer" EXPECTED="$expected" VERIFIER_DIR="$verifier" python3 - <<'PY' || true
 
 
 
19
  import json
20
  import os
21
  import stat
@@ -61,6 +64,13 @@ def parse(data):
61
 
62
 
63
  verifier = os.environ["VERIFIER_DIR"]
 
 
 
 
 
 
 
64
  valid = False
65
  try:
66
  data = read_own(os.environ["ANSWER"])
 
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
+ # of the check also scores 0. A copy of the answer stays with the trial's results.
11
+ # Python runs isolated (-I -S): no module from the working directory, PYTHON* variables, the
12
+ # user's site or site-packages hooks (sitecustomize, usercustomize, .pth files) can replace what
13
+ # it imports. Besides bash, python3 is the only command this script runs (no dirname, mkdir or
14
+ # rm an agent could shadow on the PATH). ANSWER, EXPECTED and VERIFIER_DIR override the paths
15
+ # (no links in them), to test the grader locally.
16
+ case $0 in */*) here=${0%/*} ;; *) here=. ;; esac
17
+ export ANSWER=${ANSWER:-/app/answer.json}
18
+ export EXPECTED=${EXPECTED:-$here/expected.json}
19
+ export VERIFIER_DIR=${VERIFIER_DIR:-/logs/verifier}
20
+ [ -d "$VERIFIER_DIR" ] && echo 0 > "$VERIFIER_DIR/reward.txt"
21
+ python3 -I -S - <<'PY' || true
22
  import json
23
  import os
24
  import stat
 
64
 
65
 
66
  verifier = os.environ["VERIFIER_DIR"]
67
+ os.makedirs(verifier, exist_ok=True)
68
+ for name in ("reward.txt", "reward.json", "answer.json"): # never written through a link
69
+ try:
70
+ os.unlink(os.path.join(verifier, name))
71
+ except FileNotFoundError:
72
+ pass
73
+ write_new(os.path.join(verifier, "reward.txt"), "0")
74
  valid = False
75
  try:
76
  data = read_own(os.environ["ANSWER"])
tasks/agg-p31-n02/tests/test.sh CHANGED
@@ -7,15 +7,18 @@
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
- # of the check also scores 0. A copy of the answer stays with the trial's results. ANSWER,
11
- # EXPECTED and VERIFIER_DIR override the paths (no links in them), to test the grader locally.
12
- answer=${ANSWER:-/app/answer.json}
13
- expected=${EXPECTED:-$(dirname "$0")/expected.json}
14
- verifier=${VERIFIER_DIR:-/logs/verifier}
15
- mkdir -p "$verifier"
16
- rm -f "$verifier/reward.txt" "$verifier/reward.json" "$verifier/answer.json"
17
- echo 0 > "$verifier/reward.txt"
18
- ANSWER="$answer" EXPECTED="$expected" VERIFIER_DIR="$verifier" python3 - <<'PY' || true
 
 
 
19
  import json
20
  import os
21
  import stat
@@ -61,6 +64,13 @@ def parse(data):
61
 
62
 
63
  verifier = os.environ["VERIFIER_DIR"]
 
 
 
 
 
 
 
64
  valid = False
65
  try:
66
  data = read_own(os.environ["ANSWER"])
 
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
+ # of the check also scores 0. A copy of the answer stays with the trial's results.
11
+ # Python runs isolated (-I -S): no module from the working directory, PYTHON* variables, the
12
+ # user's site or site-packages hooks (sitecustomize, usercustomize, .pth files) can replace what
13
+ # it imports. Besides bash, python3 is the only command this script runs (no dirname, mkdir or
14
+ # rm an agent could shadow on the PATH). ANSWER, EXPECTED and VERIFIER_DIR override the paths
15
+ # (no links in them), to test the grader locally.
16
+ case $0 in */*) here=${0%/*} ;; *) here=. ;; esac
17
+ export ANSWER=${ANSWER:-/app/answer.json}
18
+ export EXPECTED=${EXPECTED:-$here/expected.json}
19
+ export VERIFIER_DIR=${VERIFIER_DIR:-/logs/verifier}
20
+ [ -d "$VERIFIER_DIR" ] && echo 0 > "$VERIFIER_DIR/reward.txt"
21
+ python3 -I -S - <<'PY' || true
22
  import json
23
  import os
24
  import stat
 
64
 
65
 
66
  verifier = os.environ["VERIFIER_DIR"]
67
+ os.makedirs(verifier, exist_ok=True)
68
+ for name in ("reward.txt", "reward.json", "answer.json"): # never written through a link
69
+ try:
70
+ os.unlink(os.path.join(verifier, name))
71
+ except FileNotFoundError:
72
+ pass
73
+ write_new(os.path.join(verifier, "reward.txt"), "0")
74
  valid = False
75
  try:
76
  data = read_own(os.environ["ANSWER"])
tasks/agg-p31-n04/tests/test.sh CHANGED
@@ -7,15 +7,18 @@
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
- # of the check also scores 0. A copy of the answer stays with the trial's results. ANSWER,
11
- # EXPECTED and VERIFIER_DIR override the paths (no links in them), to test the grader locally.
12
- answer=${ANSWER:-/app/answer.json}
13
- expected=${EXPECTED:-$(dirname "$0")/expected.json}
14
- verifier=${VERIFIER_DIR:-/logs/verifier}
15
- mkdir -p "$verifier"
16
- rm -f "$verifier/reward.txt" "$verifier/reward.json" "$verifier/answer.json"
17
- echo 0 > "$verifier/reward.txt"
18
- ANSWER="$answer" EXPECTED="$expected" VERIFIER_DIR="$verifier" python3 - <<'PY' || true
 
 
 
19
  import json
20
  import os
21
  import stat
@@ -61,6 +64,13 @@ def parse(data):
61
 
62
 
63
  verifier = os.environ["VERIFIER_DIR"]
 
 
 
 
 
 
 
64
  valid = False
65
  try:
66
  data = read_own(os.environ["ANSWER"])
 
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
+ # of the check also scores 0. A copy of the answer stays with the trial's results.
11
+ # Python runs isolated (-I -S): no module from the working directory, PYTHON* variables, the
12
+ # user's site or site-packages hooks (sitecustomize, usercustomize, .pth files) can replace what
13
+ # it imports. Besides bash, python3 is the only command this script runs (no dirname, mkdir or
14
+ # rm an agent could shadow on the PATH). ANSWER, EXPECTED and VERIFIER_DIR override the paths
15
+ # (no links in them), to test the grader locally.
16
+ case $0 in */*) here=${0%/*} ;; *) here=. ;; esac
17
+ export ANSWER=${ANSWER:-/app/answer.json}
18
+ export EXPECTED=${EXPECTED:-$here/expected.json}
19
+ export VERIFIER_DIR=${VERIFIER_DIR:-/logs/verifier}
20
+ [ -d "$VERIFIER_DIR" ] && echo 0 > "$VERIFIER_DIR/reward.txt"
21
+ python3 -I -S - <<'PY' || true
22
  import json
23
  import os
24
  import stat
 
64
 
65
 
66
  verifier = os.environ["VERIFIER_DIR"]
67
+ os.makedirs(verifier, exist_ok=True)
68
+ for name in ("reward.txt", "reward.json", "answer.json"): # never written through a link
69
+ try:
70
+ os.unlink(os.path.join(verifier, name))
71
+ except FileNotFoundError:
72
+ pass
73
+ write_new(os.path.join(verifier, "reward.txt"), "0")
74
  valid = False
75
  try:
76
  data = read_own(os.environ["ANSWER"])
tasks/agg-p31-n08/tests/test.sh CHANGED
@@ -7,15 +7,18 @@
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
- # of the check also scores 0. A copy of the answer stays with the trial's results. ANSWER,
11
- # EXPECTED and VERIFIER_DIR override the paths (no links in them), to test the grader locally.
12
- answer=${ANSWER:-/app/answer.json}
13
- expected=${EXPECTED:-$(dirname "$0")/expected.json}
14
- verifier=${VERIFIER_DIR:-/logs/verifier}
15
- mkdir -p "$verifier"
16
- rm -f "$verifier/reward.txt" "$verifier/reward.json" "$verifier/answer.json"
17
- echo 0 > "$verifier/reward.txt"
18
- ANSWER="$answer" EXPECTED="$expected" VERIFIER_DIR="$verifier" python3 - <<'PY' || true
 
 
 
19
  import json
20
  import os
21
  import stat
@@ -61,6 +64,13 @@ def parse(data):
61
 
62
 
63
  verifier = os.environ["VERIFIER_DIR"]
 
 
 
 
 
 
 
64
  valid = False
65
  try:
66
  data = read_own(os.environ["ANSWER"])
 
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
+ # of the check also scores 0. A copy of the answer stays with the trial's results.
11
+ # Python runs isolated (-I -S): no module from the working directory, PYTHON* variables, the
12
+ # user's site or site-packages hooks (sitecustomize, usercustomize, .pth files) can replace what
13
+ # it imports. Besides bash, python3 is the only command this script runs (no dirname, mkdir or
14
+ # rm an agent could shadow on the PATH). ANSWER, EXPECTED and VERIFIER_DIR override the paths
15
+ # (no links in them), to test the grader locally.
16
+ case $0 in */*) here=${0%/*} ;; *) here=. ;; esac
17
+ export ANSWER=${ANSWER:-/app/answer.json}
18
+ export EXPECTED=${EXPECTED:-$here/expected.json}
19
+ export VERIFIER_DIR=${VERIFIER_DIR:-/logs/verifier}
20
+ [ -d "$VERIFIER_DIR" ] && echo 0 > "$VERIFIER_DIR/reward.txt"
21
+ python3 -I -S - <<'PY' || true
22
  import json
23
  import os
24
  import stat
 
64
 
65
 
66
  verifier = os.environ["VERIFIER_DIR"]
67
+ os.makedirs(verifier, exist_ok=True)
68
+ for name in ("reward.txt", "reward.json", "answer.json"): # never written through a link
69
+ try:
70
+ os.unlink(os.path.join(verifier, name))
71
+ except FileNotFoundError:
72
+ pass
73
+ write_new(os.path.join(verifier, "reward.txt"), "0")
74
  valid = False
75
  try:
76
  data = read_own(os.environ["ANSWER"])
tasks/agg-p31-n16/tests/test.sh CHANGED
@@ -7,15 +7,18 @@
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
- # of the check also scores 0. A copy of the answer stays with the trial's results. ANSWER,
11
- # EXPECTED and VERIFIER_DIR override the paths (no links in them), to test the grader locally.
12
- answer=${ANSWER:-/app/answer.json}
13
- expected=${EXPECTED:-$(dirname "$0")/expected.json}
14
- verifier=${VERIFIER_DIR:-/logs/verifier}
15
- mkdir -p "$verifier"
16
- rm -f "$verifier/reward.txt" "$verifier/reward.json" "$verifier/answer.json"
17
- echo 0 > "$verifier/reward.txt"
18
- ANSWER="$answer" EXPECTED="$expected" VERIFIER_DIR="$verifier" python3 - <<'PY' || true
 
 
 
19
  import json
20
  import os
21
  import stat
@@ -61,6 +64,13 @@ def parse(data):
61
 
62
 
63
  verifier = os.environ["VERIFIER_DIR"]
 
 
 
 
 
 
 
64
  valid = False
65
  try:
66
  data = read_own(os.environ["ANSWER"])
 
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
+ # of the check also scores 0. A copy of the answer stays with the trial's results.
11
+ # Python runs isolated (-I -S): no module from the working directory, PYTHON* variables, the
12
+ # user's site or site-packages hooks (sitecustomize, usercustomize, .pth files) can replace what
13
+ # it imports. Besides bash, python3 is the only command this script runs (no dirname, mkdir or
14
+ # rm an agent could shadow on the PATH). ANSWER, EXPECTED and VERIFIER_DIR override the paths
15
+ # (no links in them), to test the grader locally.
16
+ case $0 in */*) here=${0%/*} ;; *) here=. ;; esac
17
+ export ANSWER=${ANSWER:-/app/answer.json}
18
+ export EXPECTED=${EXPECTED:-$here/expected.json}
19
+ export VERIFIER_DIR=${VERIFIER_DIR:-/logs/verifier}
20
+ [ -d "$VERIFIER_DIR" ] && echo 0 > "$VERIFIER_DIR/reward.txt"
21
+ python3 -I -S - <<'PY' || true
22
  import json
23
  import os
24
  import stat
 
64
 
65
 
66
  verifier = os.environ["VERIFIER_DIR"]
67
+ os.makedirs(verifier, exist_ok=True)
68
+ for name in ("reward.txt", "reward.json", "answer.json"): # never written through a link
69
+ try:
70
+ os.unlink(os.path.join(verifier, name))
71
+ except FileNotFoundError:
72
+ pass
73
+ write_new(os.path.join(verifier, "reward.txt"), "0")
74
  valid = False
75
  try:
76
  data = read_own(os.environ["ANSWER"])
tasks/agg-p32-n01/tests/test.sh CHANGED
@@ -7,15 +7,18 @@
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
- # of the check also scores 0. A copy of the answer stays with the trial's results. ANSWER,
11
- # EXPECTED and VERIFIER_DIR override the paths (no links in them), to test the grader locally.
12
- answer=${ANSWER:-/app/answer.json}
13
- expected=${EXPECTED:-$(dirname "$0")/expected.json}
14
- verifier=${VERIFIER_DIR:-/logs/verifier}
15
- mkdir -p "$verifier"
16
- rm -f "$verifier/reward.txt" "$verifier/reward.json" "$verifier/answer.json"
17
- echo 0 > "$verifier/reward.txt"
18
- ANSWER="$answer" EXPECTED="$expected" VERIFIER_DIR="$verifier" python3 - <<'PY' || true
 
 
 
19
  import json
20
  import os
21
  import stat
@@ -61,6 +64,13 @@ def parse(data):
61
 
62
 
63
  verifier = os.environ["VERIFIER_DIR"]
 
 
 
 
 
 
 
64
  valid = False
65
  try:
66
  data = read_own(os.environ["ANSWER"])
 
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
+ # of the check also scores 0. A copy of the answer stays with the trial's results.
11
+ # Python runs isolated (-I -S): no module from the working directory, PYTHON* variables, the
12
+ # user's site or site-packages hooks (sitecustomize, usercustomize, .pth files) can replace what
13
+ # it imports. Besides bash, python3 is the only command this script runs (no dirname, mkdir or
14
+ # rm an agent could shadow on the PATH). ANSWER, EXPECTED and VERIFIER_DIR override the paths
15
+ # (no links in them), to test the grader locally.
16
+ case $0 in */*) here=${0%/*} ;; *) here=. ;; esac
17
+ export ANSWER=${ANSWER:-/app/answer.json}
18
+ export EXPECTED=${EXPECTED:-$here/expected.json}
19
+ export VERIFIER_DIR=${VERIFIER_DIR:-/logs/verifier}
20
+ [ -d "$VERIFIER_DIR" ] && echo 0 > "$VERIFIER_DIR/reward.txt"
21
+ python3 -I -S - <<'PY' || true
22
  import json
23
  import os
24
  import stat
 
64
 
65
 
66
  verifier = os.environ["VERIFIER_DIR"]
67
+ os.makedirs(verifier, exist_ok=True)
68
+ for name in ("reward.txt", "reward.json", "answer.json"): # never written through a link
69
+ try:
70
+ os.unlink(os.path.join(verifier, name))
71
+ except FileNotFoundError:
72
+ pass
73
+ write_new(os.path.join(verifier, "reward.txt"), "0")
74
  valid = False
75
  try:
76
  data = read_own(os.environ["ANSWER"])
tasks/agg-p32-n02/tests/test.sh CHANGED
@@ -7,15 +7,18 @@
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
- # of the check also scores 0. A copy of the answer stays with the trial's results. ANSWER,
11
- # EXPECTED and VERIFIER_DIR override the paths (no links in them), to test the grader locally.
12
- answer=${ANSWER:-/app/answer.json}
13
- expected=${EXPECTED:-$(dirname "$0")/expected.json}
14
- verifier=${VERIFIER_DIR:-/logs/verifier}
15
- mkdir -p "$verifier"
16
- rm -f "$verifier/reward.txt" "$verifier/reward.json" "$verifier/answer.json"
17
- echo 0 > "$verifier/reward.txt"
18
- ANSWER="$answer" EXPECTED="$expected" VERIFIER_DIR="$verifier" python3 - <<'PY' || true
 
 
 
19
  import json
20
  import os
21
  import stat
@@ -61,6 +64,13 @@ def parse(data):
61
 
62
 
63
  verifier = os.environ["VERIFIER_DIR"]
 
 
 
 
 
 
 
64
  valid = False
65
  try:
66
  data = read_own(os.environ["ANSWER"])
 
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
+ # of the check also scores 0. A copy of the answer stays with the trial's results.
11
+ # Python runs isolated (-I -S): no module from the working directory, PYTHON* variables, the
12
+ # user's site or site-packages hooks (sitecustomize, usercustomize, .pth files) can replace what
13
+ # it imports. Besides bash, python3 is the only command this script runs (no dirname, mkdir or
14
+ # rm an agent could shadow on the PATH). ANSWER, EXPECTED and VERIFIER_DIR override the paths
15
+ # (no links in them), to test the grader locally.
16
+ case $0 in */*) here=${0%/*} ;; *) here=. ;; esac
17
+ export ANSWER=${ANSWER:-/app/answer.json}
18
+ export EXPECTED=${EXPECTED:-$here/expected.json}
19
+ export VERIFIER_DIR=${VERIFIER_DIR:-/logs/verifier}
20
+ [ -d "$VERIFIER_DIR" ] && echo 0 > "$VERIFIER_DIR/reward.txt"
21
+ python3 -I -S - <<'PY' || true
22
  import json
23
  import os
24
  import stat
 
64
 
65
 
66
  verifier = os.environ["VERIFIER_DIR"]
67
+ os.makedirs(verifier, exist_ok=True)
68
+ for name in ("reward.txt", "reward.json", "answer.json"): # never written through a link
69
+ try:
70
+ os.unlink(os.path.join(verifier, name))
71
+ except FileNotFoundError:
72
+ pass
73
+ write_new(os.path.join(verifier, "reward.txt"), "0")
74
  valid = False
75
  try:
76
  data = read_own(os.environ["ANSWER"])
tasks/agg-p32-n04/tests/test.sh CHANGED
@@ -7,15 +7,18 @@
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
- # of the check also scores 0. A copy of the answer stays with the trial's results. ANSWER,
11
- # EXPECTED and VERIFIER_DIR override the paths (no links in them), to test the grader locally.
12
- answer=${ANSWER:-/app/answer.json}
13
- expected=${EXPECTED:-$(dirname "$0")/expected.json}
14
- verifier=${VERIFIER_DIR:-/logs/verifier}
15
- mkdir -p "$verifier"
16
- rm -f "$verifier/reward.txt" "$verifier/reward.json" "$verifier/answer.json"
17
- echo 0 > "$verifier/reward.txt"
18
- ANSWER="$answer" EXPECTED="$expected" VERIFIER_DIR="$verifier" python3 - <<'PY' || true
 
 
 
19
  import json
20
  import os
21
  import stat
@@ -61,6 +64,13 @@ def parse(data):
61
 
62
 
63
  verifier = os.environ["VERIFIER_DIR"]
 
 
 
 
 
 
 
64
  valid = False
65
  try:
66
  data = read_own(os.environ["ANSWER"])
 
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
+ # of the check also scores 0. A copy of the answer stays with the trial's results.
11
+ # Python runs isolated (-I -S): no module from the working directory, PYTHON* variables, the
12
+ # user's site or site-packages hooks (sitecustomize, usercustomize, .pth files) can replace what
13
+ # it imports. Besides bash, python3 is the only command this script runs (no dirname, mkdir or
14
+ # rm an agent could shadow on the PATH). ANSWER, EXPECTED and VERIFIER_DIR override the paths
15
+ # (no links in them), to test the grader locally.
16
+ case $0 in */*) here=${0%/*} ;; *) here=. ;; esac
17
+ export ANSWER=${ANSWER:-/app/answer.json}
18
+ export EXPECTED=${EXPECTED:-$here/expected.json}
19
+ export VERIFIER_DIR=${VERIFIER_DIR:-/logs/verifier}
20
+ [ -d "$VERIFIER_DIR" ] && echo 0 > "$VERIFIER_DIR/reward.txt"
21
+ python3 -I -S - <<'PY' || true
22
  import json
23
  import os
24
  import stat
 
64
 
65
 
66
  verifier = os.environ["VERIFIER_DIR"]
67
+ os.makedirs(verifier, exist_ok=True)
68
+ for name in ("reward.txt", "reward.json", "answer.json"): # never written through a link
69
+ try:
70
+ os.unlink(os.path.join(verifier, name))
71
+ except FileNotFoundError:
72
+ pass
73
+ write_new(os.path.join(verifier, "reward.txt"), "0")
74
  valid = False
75
  try:
76
  data = read_own(os.environ["ANSWER"])
tasks/agg-p32-n08/tests/test.sh CHANGED
@@ -7,15 +7,18 @@
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
- # of the check also scores 0. A copy of the answer stays with the trial's results. ANSWER,
11
- # EXPECTED and VERIFIER_DIR override the paths (no links in them), to test the grader locally.
12
- answer=${ANSWER:-/app/answer.json}
13
- expected=${EXPECTED:-$(dirname "$0")/expected.json}
14
- verifier=${VERIFIER_DIR:-/logs/verifier}
15
- mkdir -p "$verifier"
16
- rm -f "$verifier/reward.txt" "$verifier/reward.json" "$verifier/answer.json"
17
- echo 0 > "$verifier/reward.txt"
18
- ANSWER="$answer" EXPECTED="$expected" VERIFIER_DIR="$verifier" python3 - <<'PY' || true
 
 
 
19
  import json
20
  import os
21
  import stat
@@ -61,6 +64,13 @@ def parse(data):
61
 
62
 
63
  verifier = os.environ["VERIFIER_DIR"]
 
 
 
 
 
 
 
64
  valid = False
65
  try:
66
  data = read_own(os.environ["ANSWER"])
 
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
+ # of the check also scores 0. A copy of the answer stays with the trial's results.
11
+ # Python runs isolated (-I -S): no module from the working directory, PYTHON* variables, the
12
+ # user's site or site-packages hooks (sitecustomize, usercustomize, .pth files) can replace what
13
+ # it imports. Besides bash, python3 is the only command this script runs (no dirname, mkdir or
14
+ # rm an agent could shadow on the PATH). ANSWER, EXPECTED and VERIFIER_DIR override the paths
15
+ # (no links in them), to test the grader locally.
16
+ case $0 in */*) here=${0%/*} ;; *) here=. ;; esac
17
+ export ANSWER=${ANSWER:-/app/answer.json}
18
+ export EXPECTED=${EXPECTED:-$here/expected.json}
19
+ export VERIFIER_DIR=${VERIFIER_DIR:-/logs/verifier}
20
+ [ -d "$VERIFIER_DIR" ] && echo 0 > "$VERIFIER_DIR/reward.txt"
21
+ python3 -I -S - <<'PY' || true
22
  import json
23
  import os
24
  import stat
 
64
 
65
 
66
  verifier = os.environ["VERIFIER_DIR"]
67
+ os.makedirs(verifier, exist_ok=True)
68
+ for name in ("reward.txt", "reward.json", "answer.json"): # never written through a link
69
+ try:
70
+ os.unlink(os.path.join(verifier, name))
71
+ except FileNotFoundError:
72
+ pass
73
+ write_new(os.path.join(verifier, "reward.txt"), "0")
74
  valid = False
75
  try:
76
  data = read_own(os.environ["ANSWER"])
tasks/agg-p32-n16/tests/test.sh CHANGED
@@ -7,15 +7,18 @@
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
- # of the check also scores 0. A copy of the answer stays with the trial's results. ANSWER,
11
- # EXPECTED and VERIFIER_DIR override the paths (no links in them), to test the grader locally.
12
- answer=${ANSWER:-/app/answer.json}
13
- expected=${EXPECTED:-$(dirname "$0")/expected.json}
14
- verifier=${VERIFIER_DIR:-/logs/verifier}
15
- mkdir -p "$verifier"
16
- rm -f "$verifier/reward.txt" "$verifier/reward.json" "$verifier/answer.json"
17
- echo 0 > "$verifier/reward.txt"
18
- ANSWER="$answer" EXPECTED="$expected" VERIFIER_DIR="$verifier" python3 - <<'PY' || true
 
 
 
19
  import json
20
  import os
21
  import stat
@@ -61,6 +64,13 @@ def parse(data):
61
 
62
 
63
  verifier = os.environ["VERIFIER_DIR"]
 
 
 
 
 
 
 
64
  valid = False
65
  try:
66
  data = read_own(os.environ["ANSWER"])
 
7
  # /tests/expected.json, which arrives only now), a link anywhere on the path (a symlinked /app),
8
  # a hardlink, a directory or a FIFO scores 0; expected.json is read the same way. Nothing here
9
  # follows a link the agent may have left, and 0 is written before anything is checked, so a crash
10
+ # of the check also scores 0. A copy of the answer stays with the trial's results.
11
+ # Python runs isolated (-I -S): no module from the working directory, PYTHON* variables, the
12
+ # user's site or site-packages hooks (sitecustomize, usercustomize, .pth files) can replace what
13
+ # it imports. Besides bash, python3 is the only command this script runs (no dirname, mkdir or
14
+ # rm an agent could shadow on the PATH). ANSWER, EXPECTED and VERIFIER_DIR override the paths
15
+ # (no links in them), to test the grader locally.
16
+ case $0 in */*) here=${0%/*} ;; *) here=. ;; esac
17
+ export ANSWER=${ANSWER:-/app/answer.json}
18
+ export EXPECTED=${EXPECTED:-$here/expected.json}
19
+ export VERIFIER_DIR=${VERIFIER_DIR:-/logs/verifier}
20
+ [ -d "$VERIFIER_DIR" ] && echo 0 > "$VERIFIER_DIR/reward.txt"
21
+ python3 -I -S - <<'PY' || true
22
  import json
23
  import os
24
  import stat
 
64
 
65
 
66
  verifier = os.environ["VERIFIER_DIR"]
67
+ os.makedirs(verifier, exist_ok=True)
68
+ for name in ("reward.txt", "reward.json", "answer.json"): # never written through a link
69
+ try:
70
+ os.unlink(os.path.join(verifier, name))
71
+ except FileNotFoundError:
72
+ pass
73
+ write_new(os.path.join(verifier, "reward.txt"), "0")
74
  valid = False
75
  try:
76
  data = read_own(os.environ["ANSWER"])