fix: --report darf keine erzeugte Datei ersetzen, Schreibfehler mit Exit 1 (QA2-07)

--report OUTPUT/manifest.json ersetzte das Manifest stillschweigend durch
den Bericht. Ein nicht beschreibbares --report-Ziel endete nach bereits
geschriebener Ausgabe mit Exit 4 ("Interner Fehler"). Jetzt: Abbruch mit
Exit 1 vor dem Schreiben bzw. verständliche Meldung mit Exit 1;
Überschreibverhalten in der README dokumentiert.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-10-06 00:02:50 +02:00
commit ff1a0ae5e4

View file

@ -107,3 +107,33 @@ def test_multiple_blank_lines_inside_code_are_kept(convert):
text = convert(Book(docs=[Doc("c.xhtml", body)])).chapter("001")
assert f"```python\n{code}\n```" in text, text
assert "\n\n\n" not in text.replace(code, "") # outside code blank lines are still normalized
def _simple() -> Book:
return Book(docs=[Doc("c.xhtml", "<h1>K</h1><p>Text.</p>")])
def test_report_must_not_overwrite_generated_output_file(convert, tmp_path):
"""QA2-07: --report OUTPUT/manifest.json silently replaced the manifest with the report."""
out = tmp_path / "ziel"
run = convert(_simple(), "--report", str(out / "manifest.json"), out=out)
assert run.rc == 1
assert "--report" in run.stderr
assert not out.exists()
def test_report_write_error_is_input_error_not_internal(convert, tmp_path):
"""QA2-07: an unwritable --report target ended with exit 4 ("Interner Fehler")."""
import os
import stat
ro = tmp_path / "ro"
ro.mkdir()
os.chmod(ro, stat.S_IRUSR | stat.S_IXUSR)
try:
run = convert(_simple(), "--report", str(ro / "bericht.json"), out=tmp_path / "ziel")
finally:
os.chmod(ro, stat.S_IRWXU)
assert run.rc == 1, run.stderr
assert "Interner Fehler" not in run.stderr
assert "Bericht" in run.stderr