From d2606f9105e8fde65b93018b103a91af317996db Mon Sep 17 00:00:00 2001 From: Liu5201988 <341811709+Liu5201988@users.noreply.github.com> Date: Tue, 10 Nov 2026 02:46:48 +0800 Subject: [PATCH 1/2] Make the judge tests OS-portable and run the suite in CI The three EndToEndTest cases in tests/test_judge.py built their stub runner commands with 'sh -c "..."'. On Windows 'sh' is not on PATH, and where a POSIX shell does exist it rewrites the backslash-separated paths embedded in the script, so the stubs never read the payload. All three cases failed on Windows for reasons unrelated to the code under test. Replace 'sh -c' with 'python -c' and pass the script through stdin, using sys.stdin.read() instead of a shell command substitution. This keeps the 'the runner reads its prompt from stdin' contract that the stubs are there to verify, and behaves identically on POSIX and Windows. Also add .github/workflows/tests.yml: 'python -m unittest discover -s tests' is the documented pre-PR command, but nothing ran it in CI, which is how the Windows-only failures stayed green. --- .github/workflows/tests.yml | 31 ++++++++++++++++++++ tests/test_judge.py | 56 +++++++++++++++++++++++++++---------- 2 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..018b1d94 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 diff --git a/tests/test_judge.py b/tests/test_judge.py index 7e6e86e2..a8ac9d8e 100644 --- a/tests/test_judge.py +++ b/tests/test_judge.py @@ -8,6 +8,20 @@ ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "scripts")) + +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. + """ + return [sys.executable, "-c", "\n".join(lines)] + import judge # noqa: E402 import run_evals # noqa: E402 @@ -223,7 +237,14 @@ 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", + "data = sys.stdin.read()", + f"pathlib.Path({str(captured)!r}).write_text(" + "data, encoding='utf-8')", + f"sys.stdout.write(pathlib.Path({str(payload)!r})" + ".read_text(encoding='utf-8'))", + ), "response_format": "text", } } @@ -285,14 +306,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.read()", # `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.write(' + '\'{"A": {"correctness": 3}, ' + '"B": {"correctness": 3}}\')', + "else:", + f" sys.stdout.write(pathlib.Path({str(good)!r})" + ".read_text(encoding='utf-8'))", + ), "response_format": "text", } } @@ -339,7 +364,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", } } @@ -384,11 +409,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.read()", + "if 'direct-answer' in prompt:", + " sys.exit(7)", + f"sys.stdout.write(pathlib.Path({str(verdict)!r})" + ".read_text(encoding='utf-8'))", + ), "response_format": "text", } } From 986985778eef6c4242eef480f3d58db390f421f5 Mon Sep 17 00:00:00 2001 From: Liu5201988 <341811709+Liu5201988@users.noreply.github.com> Date: Mon, 9 Nov 2026 19:31:13 +0000 Subject: [PATCH 2/2] tests: move stub stdin/stdout to bytes and tidy the helper The stubs now read stdin and write stdout as bytes, so a non-ASCII prompt cannot round-trip through the locale encoding (cp1252 on a default Windows runner). The helper also moves below the imports and the return annotation is quoted so the module still imports on Python without PEP 585 builtins. --- tests/test_judge.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/tests/test_judge.py b/tests/test_judge.py index a8ac9d8e..aa371849 100644 --- a/tests/test_judge.py +++ b/tests/test_judge.py @@ -8,8 +8,11 @@ ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "scripts")) +import judge # noqa: E402 +import run_evals # noqa: E402 -def _script(*lines: str) -> list[str]: + +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. @@ -19,12 +22,13 @@ def _script(*lines: str) -> list[str]: `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)] -import judge # noqa: E402 -import run_evals # noqa: E402 - class LabelAssignmentTest(unittest.TestCase): def test_labels_are_a_stable_bijection_over_conditions(self): @@ -239,11 +243,10 @@ def test_judging_produces_paired_rows_the_scorer_accepts(self): # prompt appended to the command line. "command": _script( "import pathlib, sys", - "data = sys.stdin.read()", - f"pathlib.Path({str(captured)!r}).write_text(" - "data, encoding='utf-8')", - f"sys.stdout.write(pathlib.Path({str(payload)!r})" - ".read_text(encoding='utf-8'))", + 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", } @@ -308,15 +311,15 @@ def test_a_malformed_verdict_skips_its_group_instead_of_killing_the_run(self): "stub": { "command": _script( "import pathlib, sys", - "prompt = sys.stdin.read()", + "prompt = sys.stdin.buffer.read().decode('utf-8')", # `blocker` omitted for the casual-message group. "if 'casual-message' in prompt:", - ' sys.stdout.write(' - '\'{"A": {"correctness": 3}, ' + ' sys.stdout.buffer.write(' + 'b\'{"A": {"correctness": 3}, ' '"B": {"correctness": 3}}\')', "else:", - f" sys.stdout.write(pathlib.Path({str(good)!r})" - ".read_text(encoding='utf-8'))", + f" sys.stdout.buffer.write(" + f"pathlib.Path({str(good)!r}).read_bytes())", ), "response_format": "text", } @@ -411,11 +414,11 @@ def test_runner_failure_skips_its_group_and_continues(self): "stub": { "command": _script( "import pathlib, sys", - "prompt = sys.stdin.read()", + "prompt = sys.stdin.buffer.read().decode('utf-8')", "if 'direct-answer' in prompt:", " sys.exit(7)", - f"sys.stdout.write(pathlib.Path({str(verdict)!r})" - ".read_text(encoding='utf-8'))", + f"sys.stdout.buffer.write(" + f"pathlib.Path({str(verdict)!r}).read_bytes())", ), "response_format": "text", }