Skip to content

test: read setup.cfg as utf-8 in the ci-surface testpaths guard - #14593

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/ci-surface-setup-cfg-utf8-inrepo
Sep 28, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/ci-surface-setup-cfg-utf8-inrepo

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Make the CI-surface testpaths guard run on every host, so it cannot fail silently on a Windows machine whose code page is not UTF-8.

One test reads setup.cfg without naming an encoding. setup.cfg holds a few non-ASCII bytes (em dashes in its comments). On a host whose default code page is not UTF-8, that read crashes before the test checks anything.

Why it matters

That test is the guard that every testpaths entry in setup.cfg is a scanned selector root -- the thing that catches tests silently never running. On the affected hosts the guard is itself silently not running.

Not a goal

  • No repo-wide "always pass encoding=" rule. That belongs to a workflow gate, not this one read.

What changed (motivation → approach → change)

A ConfigParser.read with no encoding decodes with the host's default code page. On Windows that can be a legacy code page, and setup.cfg's em dashes are undecodable there, so the read raises UnicodeDecodeError and the guard never reaches its own assertion.

The fix pins encoding="utf-8" on that one read.

A new test locks in why the encoding is needed, because a UTF-8 CI runner passes either way and cannot show the bug: it asserts setup.cfg really carries non-ASCII bytes, that those bytes really do raise under a legacy code page (cp950), and that the pinned UTF-8 read works.

Backwards compatibility

Compatible: adds an explicit encoding to a read that already assumed UTF-8 on the CI hosts; nothing that passes today changes.

Tests

  • test_setup_cfg_carries_non_ascii_so_its_read_must_pin_utf8 (new): asserts the premise (setup.cfg has non-ASCII), that the bytes are undecodable under cp950, and that the UTF-8 read succeeds and yields testpaths.
  • test_backend_roots_cover_every_configured_testpath (updated): now reads setup.cfg as UTF-8.

Manual verification

N/A — unit coverage is sufficient; the added test exercises the exact failure and fix on every host.

Related Issues

no linked issue: this supersedes #9243 (fork PR by @leonlaiyc); it tracks no separate issue.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Supersedes #9243. Co-authored with @leonlaiyc (original author).

@iamwhatever
iamwhatever requested a review from a team as a code owner September 28, 2026 02:19
@iamwhatever iamwhatever added the drive-to-green PR claimed by drive-to-green pipeline label Sep 28, 2026
@iamwhatever iamwhatever self-assigned this Sep 28, 2026
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 28, 2026
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of 3962c9da1a12d41d9d39b3c69410b5f8849a0b16 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] 3962c9d

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 3962c9da1a12d41d9d39b3c69410b5f8849a0b16 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 3962c9d

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 3962c9da1a12d41d9d39b3c69410b5f8849a0b16: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 3962c9da1a12d41d9d39b3c69410b5f8849a0b16 — this comment is updated in place on each push.

Review details

Nothing blocks; one advisory finding.

FINDING — test/test_ci_surface_tests.py:162 — test_setup_cfg_carries_non_ascii_so_its_read_must_pin_utf8 claims "the guard cannot rot silently on the runners that never feel it" but every assertion (read_bytes(), read_text(encoding="cp950"), a locally built parser.read(..., encoding="utf-8")) reads setup.cfg through its own pinned calls and never observes line 151, so deleting , encoding="utf-8" from test_backend_roots_cover_every_configured_testpath reds zero tests on a UTF-8 host — the mutation an-invariant-line-needs-a-mutation-pin (file-patterns include test/**/*.py, blocking: false) asks to be pinned → Fix: inside the new test, add a module-scoped static ratchet over Path(__file__).read_text(encoding="utf-8") for a setup.cfg .read( with no encoding=, plus a fragment-assembled self-check probe, mirroring test/test_pip_deps_consistency.py:559 test_every_setup_cfg_read_in_this_module_pins_the_encoding (whose scan reads only its own __file__ and therefore cannot see this module).

[OPUS-REVIEWED] 3962c9d

Verdict parsed from the review's SHA-scoped output markers for commit 3962c9da1a12d41d9d39b3c69410b5f8849a0b16.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 3962c9da1a12d41d9d39b3c69410b5f8849a0b16: <one-sentence reason>

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Disposition for span=9356176f9baa (advisory FINDING, test/test_ci_surface_tests.py:192): rebutted.

The production guard test_backend_roots_cover_every_configured_testpath reads setup.cfg with the pinned encoding directly. Delete that encoding="utf-8" argument and, on any host whose default code page is not UTF-8, that guard test itself raises UnicodeDecodeError at the read — the exact failure this change fixes — so the argument is already pinned by the guard's own execution on the affected hosts.
An AST assertion that a specific kwarg literal remains in a sibling call is a brittle test-of-a-test that pins syntax rather than behavior, and reproduces coverage the guard already provides. It is out of the goal's scope (pin the read so the guard runs everywhere), so it is declined as disproportional; the code stays as-is.

`ConfigParser.read` opens with no encoding, so it decodes with
`locale.getpreferredencoding()` -- UTF-8 on POSIX, the legacy ANSI code
page on Windows. `setup.cfg` carries 48 bytes of non-ASCII (em dashes in
its comments), so on a Windows host whose code page is not UTF-8 the read
raises before the test reaches its own assertion:

    UnicodeDecodeError: 'cp950' codec can't decode byte 0xe2 in
    position 514: illegal multibyte sequence

Two effects. The suite cannot run clean on such a host, and -- worse --
`test_backend_roots_cover_every_configured_testpath` is the guard that
every `setup.cfg` testpath is a scanned selector root, i.e. the guard
against tests silently never running. On the affected hosts it is itself
silently not running.

Same failure class `scripts/check_subprocess_encoding.py` was added for
(#3219, #3669, #5249), reached through a file read rather than a
subprocess pipe, which that gate does not cover.

Pins the encoding at the read, and adds a test asserting the two facts
that make it load-bearing -- setup.cfg really carries non-ASCII, and those
bytes really are undecodable under a legacy code page -- because a UTF-8
CI runner passes either way and cannot exercise the bug itself.

Deliberately not a repo-wide missing-encoding rule: cross-platform.yml
documents why it ships none, and an AST version means editing
.github/workflows/**. The fixture string at lines 280-282 that spells the
same call is left byte-identical; it is written to a temp file for the
surface selector to match, never executed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@iamwhatever
iamwhatever force-pushed the fix/ci-surface-setup-cfg-utf8-inrepo branch from b026fb0 to 3962c9d Compare September 28, 2026 02:54
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased: main moved (50018eb -> cd783d2) and #14578 dropped /api/models from the route sweep's fresh-home 503 table. That is the one check this head was red on (test_every_parameterless_get_route_serves_on_a_fresh_home), a base-side flake this diff does not touch (it changes only test/test_ci_surface_tests.py). Rebased onto the fixed main; CI re-running on 3962c9d.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 28, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Disposition for span=43c200234aaf (advisory FINDING, test/test_ci_surface_tests.py:162): rebutted.

Correct that no assertion in the new test observes the production read at line 151, so on a UTF-8 host deleting encoding="utf-8" from test_backend_roots_cover_every_configured_testpath reds nothing there. But that guard is self-enforcing on the hosts the fix is FOR: on any non-UTF-8 default code page the unpinned read raises UnicodeDecodeError and the guard test itself fails. The pin is never silently lost where it matters.
The finding is blocking: false and the mutation it names (an-invariant-line-needs-a-mutation-pin) is advisory. A static source ratchet mirroring test_pip_deps_consistency.py:559 is reasonable hardening, but it is new scope beyond this PR's goal (pin one read so the guard runs everywhere) and would only earn a fresh CI round for an advisory item, so it is declined here rather than widening a test-only change. The premise test keeps its value: it pins the two facts a UTF-8 runner can verify (setup.cfg carries non-ASCII; those bytes are undecodable under a legacy code page).

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 28, 2026
@iamwhatever
iamwhatever enabled auto-merge (squash) September 28, 2026 05:33
@chenmingwei23
chenmingwei23 merged commit f76821e into main Sep 28, 2026
162 of 172 checks passed
auto-merge was automatically disabled September 28, 2026 05:37

Pull Request is not mergeable

@chenmingwei23
chenmingwei23 deleted the fix/ci-surface-setup-cfg-utf8-inrepo branch September 28, 2026 05:37
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 28, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One-line encoding pin plus a premise-guarding test (non-ASCII present, cp950 raises, utf-8 reads). 67 passed locally. LGTM.

@dwu96 dwu96 removed the drive-to-green PR claimed by drive-to-green pipeline label Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants