Skip to content

test(eval): write scorecard fixtures as UTF-8 so Windows can run them - #4119

Merged
kovtcharov-amd merged 1 commit into
mainfrom
fix/scorecard-test-encoding
Sep 24, 2026
Merged

kovtcharov-amd merged 1 commit into
mainfrom
fix/scorecard-test-encoding

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Eight tests in test_release_scorecard.py fail on every Windows machine against clean main — the rendered scorecard contains a Σ, and these fixture writes inherit the cp1252 locale encoding, so they blow up with UnicodeEncodeError before asserting anything. After this, they pass everywhere. It's a constant that every delta-vs-baseline run on Windows has been quietly subtracting, so it corrupts the measuring instrument, not just the file.

The production writer and the sibling gate tests already pass encoding="utf-8"; this file was the only place missing it.

Test plan

  • On Windows, python -m pytest tests/unit/eval/test_release_scorecard.py -q — was 8 failed / 100 passed, now 108 passed
  • python -m pytest tests/unit/eval/ -q — 683 passed, 1 skipped

Eight tests in this file are permanently red for every Windows
contributor on clean main: the rendered scorecard contains a sigma, and
these write_text calls inherit the cp1252 locale encoding, so they die
with UnicodeEncodeError before asserting anything.

The production writer in release_scorecard.py and the sibling
test_scorecard_gate.py already pass encoding="utf-8"; this file was the
only place missing it.
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

This makes eight test fixture writes save as UTF-8 so they stop crashing on Windows, where the default encoding can't represent the maths symbols the scorecard renders. The fix is right, matches what the real scorecard writer already does, and the claim that this file was the last place missing it checks out across the repo.

One thing worth a follow-up, not a blocker: a nearby test reads a scorecard back without pinning UTF-8 too. On Windows that won't crash — it quietly mangles the text and the test still passes, which is a weaker check than it looks.

Real-world evidence

No evidence bundle was produced for this PR, and none is needed — the change touches only a test file, no user-facing CLI, API, MCP, or UI surface. The verdict rests on static review plus a local check of the failure mechanism.

I could not run the test suite in this review container (no pytest installed), so the PR's "108 passed" numbers are unverified here; both test-plan boxes are still unchecked. What I did confirm locally is the root cause the PR describes:

$ python3 -c "'… Σ(weightᵢ) …'.encode('cp1252')"
UnicodeEncodeError: 'charmap' codec can't encode character 'Σ': character maps to <undefined>
🔍 Technical details

Verification performed

  • src/gaia/eval/release_scorecard.py:255 renders Σ, ×, ᵢ, → and em dashes into every scorecard body, so any write of render_scorecard() output under a cp1252/ASCII locale raises. Confirmed by encoding the real template string to cp1252 (output above).
  • Production writer already correct: write_scorecard uses encoding="utf-8" (src/gaia/eval/release_scorecard.py:365), as does the reader at line 384.
  • Repo-wide check backs the "only place missing it" claim — no unencoded write of rendered scorecard output remains:
    $ grep -rn "render_scorecard(" --include=*.py tests hub src | grep "write_text\|open(" | grep -v "encoding="
    (no matches)
    
  • The eight changed lines account for exactly the eight reported Windows failures; every other write_text in the file writes json.dumps(...) (ASCII by default) or reads tests/fixtures/eval/email_benchmark_scorecard.json, which I verified is pure ASCII.

🟢 Minor — read path still uses the platform encoding (tests/unit/eval/test_release_scorecard.py:450)

This reads back a scorecard written by write_scorecard as UTF-8. On Windows it decodes as cp1252 and silently mojibakes the body (— → â€"); the test still passes because only the ASCII front matter is asserted on, so it validates mangled text rather than what was written. A payload carrying a character like U+2010 would turn it into a hard UnicodeDecodeError. Line 1958 in the same file already pins the encoding on read.

        text = scorecard_path.read_text(encoding="utf-8")

Strengths

  • Root cause named precisely, and the fix mirrors the production writer instead of inventing a test-local workaround.
  • Minimal and scope-clean: eight lines, one file, no drive-by edits.

kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Sep 24, 2026
…#4136)

## Why this matters

A Windows contributor running the four shell test suites sees `112
skipped`, which is visually indistinguishable from green. CI on ubuntu
and macOS sees 112 real results. So the loop is: verify locally, see no
red, push, watch CI fail — which is exactly how the confirm-gate defect
in amd#3808 reached CI undetected.

The skip reason is genuine for the tests that actually launch a process:
Windows runs each pipeline through `cmd.exe`, and `os.killpg` / process
groups are POSIX-only. It is *not* genuine for the refusal, parsing,
grant and tool-description tests — those decide before anything reaches
a shell, and a module-level skip was hiding them on the platform most
GAIA contributors develop on. After this change Windows runs **70 passed
/ 42 skipped** instead of `112 skipped`, and every one of those 70 is a
real assertion about the security-adjacent refusal path.

POSIX is untouched: the per-test mark carries the same `sys.platform ==
"win32"` condition the module-level one did, so off Windows it is a
no-op and all 112 still run.

<details>
<summary>🔍 Technical details</summary>

**Membership was measured, not guessed.** A throwaway pytest plugin
stripped the `cmd.exe` skipifs, wrapped `shell_tools.subprocess.Popen` /
`.run`, and recorded which node IDs actually spawned a child. 42 did; 70
did not. The 70 were then run on Windows 11 and all passed; every one of
the 10 failures fell inside the 42. So the split is empirical, not a
reading of the test names.

That measurement mattered, because *running the tests* would have given
the wrong answer. This dev box has MSYS coreutils on `PATH`, so `ls`,
`cat`, `sort` and `date` resolve and most execution tests pass here —
they would not on a clean Windows machine or a `windows-latest` runner.
Classifying on "does it pass on my box" is the hidden-state trap
CLAUDE.md warns about; classifying on "does it spawn a process" is not.

- `pytestmark = pytest.mark.skipif(...)` → `posix_only =
pytest.mark.skipif(...)`, same reason string per module, applied as
`@posix_only` to the 35 spawning tests across three files.
- **No assertion was weakened, relaxed, or deleted.** The diff is 53
insertions / 3 deletions; the 3 deletions are the `pytestmark` name on
each of the three lines.
- Node IDs are unchanged (no reorganisation into classes), so other
in-flight PRs that name these tests in their test plans still resolve.
- `test_shell_env_assignment.py`'s two existing `shutil.which("pytest")`
skipifs stack above `@posix_only`; pytest ORs them, so behaviour off
Windows is identical.
- `tests/unit/test_shell_pipelines.py` keeps its module-level mark — all
seven of its tests genuinely run a pipeline, so there is nothing to
promote. `test_shell_output_encoding.py` already used per-test marks and
is untouched.
- One pleasing side effect:
`test_windows_never_hands_a_compound_line_to_cmd_exe_as_one_string` — a
fully-mocked test *about* the Windows path — was itself skipped on
Windows. It now runs there.

**Merge-conflict note for reviewers:** amd#3721 and amd#3402 both touch
`test_shell_compound_commands.py`, neither near the `pytestmark` line.
Whichever lands second may need a trivial rebase.
</details>

## Scope

This does **not** close amd#4127. That issue asks for `windows-latest` in
the `test_unit.yml` matrix, gated on amd#4115 and amd#4119 landing first so
the lane starts green. This is a prerequisite for that lane being worth
anything — without it, 112 of the tests the new lane would run are
skipped by construction.

## Test plan

- [x] `python -m pytest tests/unit/test_shell_compound_commands.py
tests/unit/test_shell_env_assignment.py -q` on Windows 11 — was `77
skipped`, now `51 passed, 26 skipped`
- [x] Same for all four modules — was `112 skipped`, now `70 passed, 42
skipped`
- [x] `python -m pytest tests/unit/test_shell*.py
tests/unit/test_powershell_command_injection.py -q` — `266 passed, 42
skipped`
- [x] `python util/lint.py --all` — output byte-identical to a clean
`origin/main` worktree (both exit 1 on the same pre-existing mypy
findings in `src/gaia/`, none in files this PR touches)
- [ ] CI on ubuntu/macOS — expect the same counts as before this PR; the
mark is a no-op off Windows

Towards amd#4127.

Co-authored-by: Kalin Ovtcharov <[email protected]>
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 24, 2026
Merged via the queue into main with commit 519799a Sep 24, 2026
51 of 54 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/scorecard-test-encoding branch September 24, 2026 17:05
kovtcharov added a commit to kovtcharov/gaia that referenced this pull request Sep 25, 2026
…4126)

A review bot that ran out of budget now looks different from a review
that found problems. Until now both rendered the same: `pr-review / run`
went red with "Claude produced no review" plus a warning blaming an
upstream install crash, and the only way to tell a spend cap from a
genuinely broken review was to pull the job log and read the CLI's raw
result object. On amd#4119 and amd#4120 that was a weekly-cap rejection both
times, and the lane said "the action crashed" — a cause that wasn't
there.

The lane still fails. That's the point: an outage that renders as a pass
is how 50 PRs once merged unreviewed. What changed is that the red is
now legible — each verdict gets its own named step, so the checks list
carries the cause without opening a log.

<details>
<summary>🔍 Technical details</summary>

`claude-run.yml` classifies the run from `claude-code-action`'s
`execution_file` into `ok` / `errored` / `not_started` / `no_output`,
and each gets its own named step.

The outage gate keys on the CLI's own numbers, never on the rejection
wording: a run that reached a model always bills tokens into
`modelUsage`, so `is_error` with an empty usage map and zero cost means
the request was refused before any model work. Wording is used only to
*narrow* an outage the numbers already established (to name the budget
case and say "don't rotate the credential"), never to create or suppress
one — the rejection text quotes a reset date that moves, embeds a
U+00B7, and in both observed cases carried no body at all. That's the
same failure mode amd#4120 fixed on the eval preflight's probe classifier,
which owns the authoritative phrase list.

The ENOENT install-crash claim now fires only when there is genuinely no
execution log — which is what that crash actually looks like.

Only `require_comment` callers (`pr-review`) fail, unchanged from
before: an outage on the optional lanes still must not red-X a
contributor's PR.

**Not doable outside YAML:** `pull_request_target` checks out the
untrusted fork tree with secrets in scope, so this file must not run a
script from that tree — the detection itself has to be inline bash + jq.
The tests compensate by extracting the step's real `run:` body and
executing it against captured execution logs.
</details>

## Test plan

- [ ] `pytest tests/unit/test_claude_review_posting.py` — 24 tests. Nine
execute the step's actual `run:` body against real captured execution
logs, including the verbatim amd#4119/amd#4120 outage result.
- [ ] Mutation check (already run): dropping the `modelUsage` term,
dropping the cost term, or accepting any `is_error` record instead of
the CLI's `result` record each fails exactly one test.
- [ ] Zero-cost is not sufficient on its own — a Claude *subscription*
run bills $0 per request, and the fixtures assert such a run still
classifies `ok` / `errored`, never as an outage.
- [ ] On the next real cap, confirm the `pr-review` checks list shows
**"Claude never reached a model — budget or credential, not this PR"**
rather than "Claude produced no review".

Closes nothing; makes amd#4080 self-reporting. Companion to amd#4120, which
fixed the same misclassification on the eval preflight's probe.

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants