3030 f"--quiet --no-header --output-file { COMMITTED_AUDIT_REQUIREMENTS } "
3131)
3232WORKFLOW_SYNC_COMPILE_TEST_EXTRA_DEPS = (
33- "uv pip compile pyproject.toml --extra test --universal --upgrade -- generate-hashes "
33+ "uv pip compile pyproject.toml --extra test --universal --generate-hashes "
3434 "--quiet --no-header --output-file"
3535)
3636WORKFLOW_SYNC_SCRIPT = "python .github/scripts/check_security_requirements.py"
@@ -99,7 +99,9 @@ def test_dependency_audit_uses_committed_requirements_for_prs_and_pushes(self):
9999 assert sync_check ["env" ]["DEPENDENCY_DIFF_BASE" ] == (
100100 "${{ github.event.pull_request.base.sha || github.event.before || '' }}"
101101 )
102- assert sync_check ["env" ]["DEPENDENCY_DIFF_HEAD" ] == "${{ github.sha }}"
102+ assert sync_check ["env" ]["DEPENDENCY_DIFF_HEAD" ] == (
103+ "${{ github.event.pull_request.head.sha || github.sha }}"
104+ )
103105 assert sync_check ["run" ] == WORKFLOW_SYNC_SCRIPT
104106 assert committed_audit ["run" ] == LOCAL_PIP_AUDIT
105107
@@ -239,10 +241,14 @@ def test_committed_audit_requirements_are_hashed(self):
239241
240242 def test_sync_script_skips_when_dependency_inputs_are_unchanged (self , monkeypatch , capsys ):
241243 sync_script = _load_sync_script ()
244+ commands = []
242245
243246 def fake_run (command , ** kwargs ):
247+ commands .append (command )
248+ if command [:2 ] == ["git" , "merge-base" ]:
249+ return subprocess .CompletedProcess (command , 0 , stdout = "base123\n " , stderr = "" )
244250 assert command == [
245- "git" , "diff" , "--name-only" , "HEAD^ " , "HEAD" , "--" ,
251+ "git" , "diff" , "--name-only" , "base123 " , "HEAD" , "--" ,
246252 "pyproject.toml" , ".github/security-audit-requirements.txt" ,
247253 ]
248254 assert kwargs ["check" ] is True
@@ -251,23 +257,29 @@ def fake_run(command, **kwargs):
251257 monkeypatch .setattr (sync_script .subprocess , "run" , fake_run )
252258
253259 assert sync_script .main () == 0
260+ assert commands [0 ] == ["git" , "merge-base" , "HEAD^" , "HEAD" ]
254261 assert "sync check skipped" in capsys .readouterr ().out
255262
256263 def test_sync_script_uses_github_diff_refs_when_available (self , monkeypatch ):
257264 sync_script = _load_sync_script ()
258265 monkeypatch .setenv ("DEPENDENCY_DIFF_BASE" , "abc123" )
259266 monkeypatch .setenv ("DEPENDENCY_DIFF_HEAD" , "def456" )
267+ commands = []
260268
261269 def fake_run (command , ** _kwargs ):
270+ commands .append (command )
271+ if command [:2 ] == ["git" , "merge-base" ]:
272+ return subprocess .CompletedProcess (command , 0 , stdout = "merge123\n " , stderr = "" )
262273 assert command == [
263- "git" , "diff" , "--name-only" , "abc123 " , "def456" , "--" ,
274+ "git" , "diff" , "--name-only" , "merge123 " , "def456" , "--" ,
264275 "pyproject.toml" , ".github/security-audit-requirements.txt" ,
265276 ]
266277 return subprocess .CompletedProcess (command , 0 , stdout = "" , stderr = "" )
267278
268279 monkeypatch .setattr (sync_script .subprocess , "run" , fake_run )
269280
270281 assert sync_script ._dependency_inputs_changed () is False
282+ assert commands [0 ] == ["git" , "merge-base" , "abc123" , "def456" ]
271283
272284 def test_sync_script_compiles_and_compares_when_dependency_inputs_changed (
273285 self , monkeypatch , tmp_path
@@ -284,10 +296,13 @@ def test_sync_script_compiles_and_compares_when_dependency_inputs_changed(
284296 monkeypatch .setenv ("GENERATED_REQUIREMENTS" , str (generated_requirements ))
285297
286298 def fake_run (command , ** kwargs ):
287- if command [0 ] == "git" :
299+ if command [:2 ] == ["git" , "merge-base" ]:
300+ return subprocess .CompletedProcess (command , 0 , stdout = "base123\n " , stderr = "" )
301+ if command [:2 ] == ["git" , "diff" ]:
288302 return subprocess .CompletedProcess (command , 0 , stdout = "pyproject.toml\n " , stderr = "" )
289303 compile_commands .append (command )
290304 assert kwargs ["check" ] is True
305+ assert generated_requirements .read_text (encoding = "utf-8" ) == "pytest==1\n "
291306 generated_requirements .write_text ("pytest==1\n " , encoding = "utf-8" )
292307 return subprocess .CompletedProcess (command , 0 )
293308
@@ -297,6 +312,7 @@ def fake_run(command, **kwargs):
297312 assert len (compile_commands ) == 1
298313 compile_command = " " .join (compile_commands [0 ])
299314 assert WORKFLOW_SYNC_COMPILE_TEST_EXTRA_DEPS in compile_command
315+ assert "--upgrade" not in compile_commands [0 ]
300316 assert "--output-file" in compile_commands [0 ]
301317 assert str (generated_requirements ) in compile_commands [0 ]
302318
0 commit comments