From 77a029649627d88ad9b32faca389e839202d149d Mon Sep 17 00:00:00 2001 From: serversdown Date: Thu, 12 Nov 2026 16:38:10 -0500 Subject: [PATCH] chore: every text file LF by default, and a test that fails on CRLF 5dff54b listed file types; a Dockerfile, .jsonl, .gitignore or any type not yet invented had no rule. .gitattributes now defaults every file to `text=auto eol=lf` (Terra-View's rule), marks the binaries, and keeps tests/fixtures/** -text. Renormalizing under it changes no file. tests/test_line_endings.py fails if a tracked file outside the fixtures is stored CRLF, or if the rule stops covering new text types, fixtures or binaries. Its CRLF detector, pointed at the fixtures, finds all 38. Suite: 1,711 passed, 0 failed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44 --- .gitattributes | 41 +++++++++++++---------- tests/test_line_endings.py | 66 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 tests/test_line_endings.py diff --git a/.gitattributes b/.gitattributes index 0a4d9f2..ead8b36 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,20 +1,27 @@ -# Line endings (2026-11-12): source and docs are stored and checked out with LF, -# whatever tool or OS wrote them. The protocol reference and seismo_lab.py were -# CRLF, so any rewrite outside the Edit tool turned them into whole-file diffs. -*.py text eol=lf -*.md text eol=lf -*.js text eol=lf -*.html text eol=lf -*.css text eol=lf -*.json text eol=lf -*.toml text eol=lf -*.yml text eol=lf -*.yaml text eol=lf -*.sh text eol=lf -*.txt text eol=lf -*.csv text eol=lf -*.cfg text eol=lf -*.ini text eol=lf +# Line endings (2026-11-12): every text file is stored and checked out with LF, +# whatever tool or OS wrote it -- file types we have not invented yet included. +# The protocol reference and seismo_lab.py were CRLF, so any rewrite outside the +# Edit tool turned them into whole-file diffs, and merges into them had to be +# resolved byte by byte. Same rule as Terra-View's. tests/test_line_endings.py +# fails if a CRLF file gets in anyway. +* text=auto eol=lf + +# Binary -- never converted. +*.bin binary +*.pdf binary +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.ico binary +*.h5 binary +*.pkl binary +*.db binary +*.sqlite binary +*.zip binary +*.gz binary +*.xlsx binary +*.docx binary # Test fixtures are recorded bytes -- Blastware's own reports and exports, unit # captures, event files -- kept byte for byte as ground truth: never converted. diff --git a/tests/test_line_endings.py b/tests/test_line_endings.py new file mode 100644 index 0000000..5e9d6bc --- /dev/null +++ b/tests/test_line_endings.py @@ -0,0 +1,66 @@ +"""Line endings (2026-11-12): every tracked text file outside the fixtures is LF. + +.gitattributes defaults every file to `text=auto eol=lf`, so git stores and checks +out text as LF whatever wrote it, file types not invented yet included. Binaries +are never converted. tests/fixtures/** is -text: recorded bytes (Blastware's own +reports and exports, captures, event files) stay exactly as recorded, CRLF and all. + +The protocol reference and seismo_lab.py were CRLF until 5dff54b, so any rewrite +outside the Edit tool turned them into whole-file diffs, and merges into them had +to be resolved byte by byte. +""" +from __future__ import annotations + +import shutil +import subprocess +from pathlib import Path + +import pytest + +ROOT = Path(__file__).resolve().parent.parent +FIXTURES = "tests/fixtures/" + +pytestmark = pytest.mark.skipif( + shutil.which("git") is None or not (ROOT / ".git").exists(), reason="not a git checkout") + + +def _git(*args: str) -> str: + return subprocess.run(["git", "-C", str(ROOT), *args], + capture_output=True, text=True, check=True).stdout + + +def crlf_files(include_fixtures: bool = False) -> list: + """Tracked files stored (in the index) with CRLF or mixed line endings.""" + out = [] + for line in _git("ls-files", "--eol").splitlines(): + meta, path = line.split("\t", 1) + if meta.split()[0] in ("i/crlf", "i/mixed") and (include_fixtures or not path.startswith(FIXTURES)): + out.append(path) + return out + + +def attr(name: str, path: str) -> str: + return _git("check-attr", name, "--", path).rsplit(": ", 1)[-1].strip() + + +def test_no_tracked_file_outside_the_fixtures_is_crlf(): + assert crlf_files() == [] + + +@pytest.mark.parametrize("path", ["sfm/new_module.py", "docs/notes.md", "Dockerfile", "events.jsonl", + ".gitignore", "deploy/sfm.service", "a.kind-of-file-not-invented-yet"]) +def test_any_text_file_is_stored_as_lf(path): + assert (attr("text", path), attr("eol", path)) == ("auto", "lf") + + +@pytest.mark.parametrize("path", ["tests/fixtures/minimate-bench-10-26-26-blastware/blastware/K441LTOG.000", + "tests/fixtures/decode-checker-10-29-26/M007HVWF_K30W_XML.XML", + "tests/fixtures/new-bench/README.md"]) +def test_fixtures_are_never_converted(path): + assert attr("text", path) == "unset" + + +@pytest.mark.parametrize("path", ["parsers/raw_bw.bin", "analysis_idf/thor_report.pdf", "docs/photo.png", + "docs/photo.jpg", "out/event.h5", "out/event.a5.pkl", "sfm/data/cache.db"]) +def test_binaries_are_never_converted(path): + assert attr("text", path) == "unset"