Skip to content

Read Wave test metadata as UTF-8 independently of the host locale #584

Closed

Description

@LunaStev

Problem

parse_test_metadata calls Path.read_text() without an explicit encoding. A UTF-8 Wave source containing a non-ASCII comment can fail metadata discovery under an ASCII locale, even if the metadata itself is entirely ASCII. The case-manifest reader already uses UTF-8 explicitly.

The function also wraps OSError with the case display path, but decoding errors escape that wrapper. Invalid UTF-8 therefore produces an error without the caller-supplied case path.

Both behaviors were reproduced against master ecb1637602ff409aab3d0c480fd9ec1e73e645ba with temporary files, without compiling Wave.

Reproduce from the repository root

On a POSIX host, run:

LC_ALL=C PYTHONUTF8=0 PYTHONCOERCECLOCALE=0 python3 - <<'PYTHON'
from pathlib import Path
from tempfile import TemporaryDirectory
from tools.test_contracts import parse_test_metadata

with TemporaryDirectory() as temporary:
    source = Path(temporary) / "case.wave"
    source.write_bytes(
        b"// wave-test: mode=check\n// "
        + "\uC548\uB155".encode("utf-8")
        + b"\nfun main() {}\n"
    )
    print(parse_test_metadata(source, "shared/case.wave"))
PYTHON

Actual on the audited Python runtime: UnicodeDecodeError: 'ascii' codec can't decode byte 0xec in position 28.

Separately, b"// wave-test: mode=check\n// \xff\n" under a UTF-8 locale produces a decoding error without shared/case.wave in its message.

Starting points

Small contribution scope

  • Read Wave sources explicitly as UTF-8.
  • Report a decoding failure through the existing ValueError interface with the supplied display_path (or source path when omitted).
  • Add regressions for UTF-8 text and invalid bytes. Write fixtures with explicit encodings/bytes so the tests themselves do not depend on the host locale.
  • Exercise a non-UTF-8 default encoding with an isolated subprocess or a narrowly scoped test double; do not change the global developer environment.

Done when

  • UTF-8 non-ASCII comments do not change the parsed ASCII metadata.
  • Malformed UTF-8 remains an error and identifies the affected case.
  • Existing ASCII metadata behavior is preserved.
  • python3 -m unittest tools.test_test_contracts passes.

This is a Python-only task with no LLVM build or Windows machine requirement. It concerns test-source decoding, separate from compiler filename handling in #400.

Activity

  1. added
    bug
    good first issue
    cross-platform
    on Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcross-platformgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions