Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: tests

# `python -m unittest discover -s tests` is the documented pre-PR command
# (CONTRIBUTING, pull request template), but nothing ran it automatically, so
# tests that only failed on Windows stayed green. Run the whole suite on both
# platforms the project claims to support.
on:
pull_request:
push:
branches: [main]

permissions:
contents: read

jobs:
unittest:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Run the test suite
run: python -m unittest discover -s tests -v
59 changes: 45 additions & 14 deletions tests/test_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@
import run_evals # noqa: E402


def _script(*lines: str) -> "list[str]":
"""Build a stub-runner command that runs `lines` with this interpreter.

The stubs must read the prompt from stdin and write the reply to stdout.
`sh -c` cannot do that portably: `sh` may be absent on Windows, and the
Git Bash shipped with Git eats the backslashes of any Windows path
interpolated into the command, so `cat C:\\Users\\...` becomes
`cat C:Users...` and the runner fails for a reason unrelated to judging.
Running the snippet with the interpreter already executing the tests keeps
the same contract on every platform.

Snippets move stdin/stdout as bytes: the text wrappers decode and encode
with the locale encoding, so a non-ASCII prompt would round-trip through
cp1252 on a default Windows runner.
"""
return [sys.executable, "-c", "\n".join(lines)]


class LabelAssignmentTest(unittest.TestCase):
def test_labels_are_a_stable_bijection_over_conditions(self):
conditions = ["baseline", "candidate"]
Expand Down Expand Up @@ -223,7 +241,13 @@ def test_judging_produces_paired_rows_the_scorer_accepts(self):
# Reads the prompt from stdin, not argv: a trailing
# option such as `--tools ""` otherwise swallows a
# prompt appended to the command line.
"command": ["sh", "-c", f"cat > {captured}; cat {payload}"],
"command": _script(
"import pathlib, sys",
f"pathlib.Path({str(captured)!r})"
".write_bytes(sys.stdin.buffer.read())",
f"sys.stdout.buffer.write("
f"pathlib.Path({str(payload)!r}).read_bytes())",
),
"response_format": "text",
}
}
Expand Down Expand Up @@ -285,14 +309,18 @@ def test_a_malformed_verdict_skips_its_group_instead_of_killing_the_run(self):
json.dumps(
{
"stub": {
"command": [
"sh",
"-c",
"command": _script(
"import pathlib, sys",
"prompt = sys.stdin.buffer.read().decode('utf-8')",
# `blocker` omitted for the casual-message group.
f'p=$(cat); case "$p" in *casual-message*)'
f' echo \'{{"A":{{"correctness":3}},"B":{{"correctness":3}}}}\';;'
f" *) cat {good};; esac",
],
"if 'casual-message' in prompt:",
' sys.stdout.buffer.write('
'b\'{"A": {"correctness": 3}, '
'"B": {"correctness": 3}}\')',
"else:",
f" sys.stdout.buffer.write("
f"pathlib.Path({str(good)!r}).read_bytes())",
),
"response_format": "text",
}
}
Expand Down Expand Up @@ -339,7 +367,7 @@ def test_missing_entire_condition_fails_before_judging(self):
json.dumps(
{
"stub": {
"command": ["sh", "-c", "exit 99"],
"command": _script("import sys", "sys.exit(99)"),
"response_format": "text",
}
}
Expand Down Expand Up @@ -384,11 +412,14 @@ def test_runner_failure_skips_its_group_and_continues(self):
json.dumps(
{
"stub": {
"command": [
"sh",
"-c",
f'p=$(cat); case "$p" in *direct-answer*) exit 7;; *) cat {verdict};; esac',
],
"command": _script(
"import pathlib, sys",
"prompt = sys.stdin.buffer.read().decode('utf-8')",
"if 'direct-answer' in prompt:",
" sys.exit(7)",
f"sys.stdout.buffer.write("
f"pathlib.Path({str(verdict)!r}).read_bytes())",
),
"response_format": "text",
}
}
Expand Down