77import textwrap
88from pathlib import Path
99
10+ import pytest
11+
1012REPOSITORY = Path (__file__ ).resolve ().parents [3 ]
1113PUBLISH_SCRIPT = REPOSITORY / "projects/openshell-agent-runner/scripts/publish.sh"
1214
1315
14- def test_publish_retry_uploads_only_the_missing_artifact (
15- tmp_path : Path ,
16+ @pytest .mark .parametrize (
17+ ("first_accepts_wheel" , "retry_artifact" ),
18+ [(True , "sdist" ), (False , "both" )],
19+ )
20+ def test_publish_retry_uploads_only_missing_artifacts (
21+ tmp_path : Path , first_accepts_wheel : bool , retry_artifact : str
1622) -> None :
1723 project = tmp_path / "project"
1824 script = project / "scripts/publish.sh"
@@ -73,8 +79,16 @@ def test_publish_retry_uploads_only_the_missing_artifact(
7379 if [[ "$*" == *"twine upload"* ]]; then
7480 if [[ "$*" == *"--skip-existing"* ]]; then exit 92; fi
7581 if [[ "$*" == *".whl"* && "$*" == *".tar.gz"* ]]; then
82+ if [[ ! -e "$FAKE_REPOSITORY_STATE/attempted" ]]; then
83+ touch "$FAKE_REPOSITORY_STATE/attempted"
84+ if [[ "$FAKE_FIRST_ACCEPTS_WHEEL" == "true" ]]; then
85+ touch "$FAKE_REPOSITORY_STATE/wheel"
86+ fi
87+ exit 93
88+ fi
7689 touch "$FAKE_REPOSITORY_STATE/wheel"
77- exit 93
90+ touch "$FAKE_REPOSITORY_STATE/sdist"
91+ exit 0
7892 fi
7993 if [[ "$*" == *".tar.gz"* ]]; then
8094 touch "$FAKE_REPOSITORY_STATE/sdist"
@@ -95,6 +109,7 @@ def test_publish_retry_uploads_only_the_missing_artifact(
95109 environment ["FAKE_UV_LOG" ] = str (uv_log )
96110 environment ["FAKE_GIT_STATE" ] = str (git_state )
97111 environment ["FAKE_REPOSITORY_STATE" ] = str (repository_state )
112+ environment ["FAKE_FIRST_ACCEPTS_WHEEL" ] = str (first_accepts_wheel ).lower ()
98113
99114 first_attempt = subprocess .run (
100115 ["bash" , str (script ), "0.1.0" ],
@@ -104,11 +119,11 @@ def test_publish_retry_uploads_only_the_missing_artifact(
104119 check = False ,
105120 )
106121 assert first_attempt .returncode == 1
107- assert (repository_state / "wheel" ).exists ()
122+ assert (repository_state / "wheel" ).exists () is first_accepts_wheel
108123 assert not (repository_state / "sdist" ).exists ()
109124
110125 retry = subprocess .run (
111- ["bash" , str (script ), "0.1.0" , "--retry-artifact" , "sdist" ],
126+ ["bash" , str (script ), "0.1.0" , "--retry-artifact" , retry_artifact ],
112127 text = True ,
113128 capture_output = True ,
114129 env = environment ,
@@ -121,7 +136,11 @@ def test_publish_retry_uploads_only_the_missing_artifact(
121136 line for line in uv_log .read_text ().splitlines () if "twine upload" in line
122137 ]
123138 assert ".whl" in uploads [0 ] and ".tar.gz" in uploads [0 ]
124- assert ".whl" not in uploads [1 ] and ".tar.gz" in uploads [1 ]
139+ assert (".whl" in uploads [1 ]) is (retry_artifact == "both" )
140+ assert ".tar.gz" in uploads [1 ]
141+ if retry_artifact == "sdist" :
142+ assert "Uploaded the missing sdist artifact" in retry .stdout
143+ assert "Published openshell-agent-runner" not in retry .stdout
125144
126145
127146def _write_executable (path : Path , content : str ) -> None :
0 commit comments