Skip to content

Commit ee685d9

Browse files
committed
harden install script regression test
Signed-off-by: Sodawyx <sodawyx@126.com>
1 parent 2a87530 commit ee685d9

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

tests/integration/test_install_script.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
def _write_executable(path: Path, content: str) -> None:
1010
path.write_text(content)
11-
path.chmod(path.stat().st_mode | stat.S_IXUSR)
11+
executable_bits = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
12+
path.chmod(path.stat().st_mode | executable_bits)
1213

1314

1415
def test_install_sh_parses_latest_release_tag_on_posix_sed(tmp_path):
@@ -50,6 +51,42 @@ def test_install_sh_parses_latest_release_tag_on_posix_sed(tmp_path):
5051
-m) printf '%s\n' arm64 ;;
5152
*) printf '%s\n' Darwin ;;
5253
esac
54+
""",
55+
)
56+
_write_executable(
57+
fake_bin / "sed",
58+
"""#!/usr/bin/env sh
59+
expr=""
60+
while [ "$#" -gt 0 ]; do
61+
case "$1" in
62+
-E)
63+
shift
64+
expr="${1:-}"
65+
;;
66+
*)
67+
expr="$1"
68+
;;
69+
esac
70+
shift || break
71+
done
72+
73+
case "$expr" in
74+
*'[[:space:]]'*)
75+
while IFS= read -r line; do
76+
case "$line" in
77+
*tag_name*)
78+
printf '%s\n' 'v0.1.0'
79+
;;
80+
*)
81+
printf '%s\n' "$line"
82+
;;
83+
esac
84+
done
85+
;;
86+
*)
87+
cat
88+
;;
89+
esac
5390
""",
5491
)
5592
_write_executable(
@@ -76,7 +113,7 @@ def test_install_sh_parses_latest_release_tag_on_posix_sed(tmp_path):
76113

77114
env = {
78115
**os.environ,
79-
"PATH": f"{fake_bin}:{os.environ['PATH']}",
116+
"PATH": f"{fake_bin}:{os.environ.get('PATH', '')}",
80117
"AGENTRUN_INSTALL": str(install_dir),
81118
"AGENTRUN_REPO": "Serverless-Devs/agentrun-cli",
82119
}

0 commit comments

Comments
 (0)