Skip to content

Commit 4c917cf

Browse files
Fix Windows CRLF handling in install safety tests (#1717)
Co-authored-by: danielmeppiel <danielmeppiel@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d1ad46b commit 4c917cf

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

tests/unit/install/test_install_safety.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,23 @@
3434
SENTINEL_END = re.compile(r"^# INSTALL_SAFETY_END", re.MULTILINE)
3535

3636

37+
def _read_install_sh() -> str:
38+
"""Read install.sh in a shell-safe form across platforms.
39+
40+
GitHub Actions on Windows can check out files with CRLF line endings. Bash
41+
treats stray carriage returns in the sourced function block as syntax
42+
errors, so normalize them before extracting or asserting on the script.
43+
"""
44+
return INSTALL_SH.read_text(encoding="utf-8").replace("\r\n", "\n").replace("\r", "\n")
45+
46+
3747
def _load_validator():
3848
"""Extract the apm_lib_dir_validate() block from install.sh and return the
3949
source text of the function plus a small driver wrapper. Tests source the
4050
result into a fresh shell to invoke the function in isolation -- no network
4151
and no real installation side effects.
4252
"""
43-
text = INSTALL_SH.read_text(encoding="utf-8")
53+
text = _read_install_sh()
4454
match_end = SENTINEL_END.search(text)
4555
assert match_end is not None, "INSTALL_SAFETY_END sentinel missing in install.sh"
4656
match_begin = SENTINEL_BEGIN.search(text)
@@ -340,11 +350,11 @@ class TestSentinelInvariants:
340350
"""
341351

342352
def test_begin_sentinel_present(self):
343-
text = INSTALL_SH.read_text(encoding="utf-8")
353+
text = _read_install_sh()
344354
assert SENTINEL_BEGIN.search(text) is not None
345355

346356
def test_end_sentinel_present(self):
347-
text = INSTALL_SH.read_text(encoding="utf-8")
357+
text = _read_install_sh()
348358
assert SENTINEL_END.search(text) is not None
349359

350360
def test_function_defined_in_extracted_block(self):

0 commit comments

Comments
 (0)