[Tests] serve/test_fatal_recovery.py: the fake engine's .cmd is written in UTF-8 while cmd.exe reads the console code page - 8 errors in UTF-8 mode

Aperta Adatta ai principianti
#5,632 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
testing

Direzione di ricerca

Leggi serve/test_fatal_recovery.py, in particolare FatalRecovery.setUp, dove viene scritto il file batch di Windows, e controlla come il test avvia quel file. Esegui python -X utf8 -m unittest serve.test_fatal_recovery su Windows con un percorso del repository contenente caratteri non ASCII e la code page coreana della console per riprodurre gli errori. Il lavoro è concluso quando tutti e otto i test passano in modalità UTF-8.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

needs-format

Strata app 0.2.12 (146df3c4) · Python 3.14 · OS Windows 11, Korean locale (console code page cp949)

Reproduce — four runs, one machine, one file

where the repo lives how the test was started result
C:\Users\lowho\Documents\기본 프로젝트\Strata python -m unittest serve.test_fatal_recovery Ran 8 tests in 5.720s → OK
same PYTHONUTF8=1 python -m unittest serve.test_fatal_recovery Ran 8 tests in 4.275s → FAILED (errors=8)
same python -X utf8 -m unittest serve.test_fatal_recovery FAILED (errors=8)
C:\Users\lowho\AppData\Local\Temp\opencode\wt-head (ASCII path) python -X utf8 -m unittest serve.test_fatal_recovery Ran 8 tests in 5.771s → OK

All eight errors are the same one, raised in setUp before a test body runs, so the file reports nothing about its real subject:

serve.server.EngineDied: the engine exited before it was ready
the engine process ended: exit code 1

Why

FatalRecovery.setUp (L38-40) runs the fake engine through a batch file, because StrataEngine starts [exe, "--serve", *args] (serve/server.py L1210) and a .py cannot take that:

if os.name=='nt':   # no shebangs on Windows: a .cmd runs the same fake engine
    py.write_text(FAKE);self.script=self.root/'native.cmd'
    self.script.write_text(f'@"{sys.executable}" "{py}" %*\r\n')

write_text() uses the interpreter's default encoding: cp949 normally, UTF-8 in UTF-8 mode (PYTHONUTF8=1, -X utf8). cmd.exe reads batch files in the console's code page. So in UTF-8 mode the batch file names sys.executable in bytes cmd does not read, and only when that path is non-ASCII — which is why an ASCII path hides it.

One file, two encodings, same content:

body = '@"' + sys.executable + '" -c "print(1)"\r\n'      # sys.executable on a Korean path
for name, enc in (('utf8.cmd', 'utf-8'), ('cp949.cmd', 'cp949')):
    (d / name).write_bytes(body.encode(enc))
    print(name, subprocess.run(['cmd', '/c', str(d / name)], capture_output=True).returncode)
utf8.cmd  file-enc=utf-8  rc=1  out=b''  err=b'\xc1\xf6\xc1\xa4\xb5\xc8 \xb0\xe6\xb7\xce...'   ("지정된 파일을 찾을 수 없습니다")
cp949.cmd file-enc=cp949  rc=0  out=b'1\r\n'

UTF-8 mode is exactly where the non-UTF-8 Windows fixes elsewhere in this project push people, so the combination is not exotic.

Fix

Write the batch file the way cmd.exe reads it. Probed with the real StrataEngine and the real fake engine, on the Korean path, in UTF-8 mode:

test_A_default_encoding (what the test does today) ... ERROR   -> EngineDied: the engine exited before it was ready (exit code 1)
test_C_console_code_page (encoding="mbcs")          ... ok
         if os.name=='nt':   # no shebangs on Windows: a .cmd runs the same fake engine
             py.write_text(FAKE);self.script=self.root/'native.cmd'
-            self.script.write_text(f'@"{sys.executable}" "{py}" %*\r\n')
+            # cmd.exe reads a batch file in the console's code page, not in UTF-8: a
+            # UTF-8 mode interpreter would otherwise write a path cmd cannot find
+            self.script.write_text(f'@"{sys.executable}" "{py}" %*\r\n', encoding='mbcs')

py.write_text(FAKE) can take encoding="utf-8" as well; the fake engine's own source is ASCII today, so it is not what breaks.

Lingua principale
C++
Stelle
11.6k
Fork
1k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Niko1221/Strata

Tutte le issue di Niko1221/Strata

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.