@@ -61,6 +61,15 @@ def _step(job_name: str, step_name: str) -> dict:
6161 raise AssertionError (f"Step { step_name !r} not found in job { job_name !r} ." )
6262
6363
64+ def _job_run_text (* job_names : str ) -> str :
65+ workflow = _load_security_workflow ()
66+ return "\n " .join (
67+ step .get ("run" , "" )
68+ for job_name in job_names
69+ for step in workflow ["jobs" ][job_name ]["steps" ]
70+ )
71+
72+
6473def _load_sync_script ():
6574 spec = importlib .util .spec_from_file_location (
6675 "check_security_requirements" ,
@@ -77,27 +86,26 @@ class TestDependencyAuditWorkflow:
7786 """Guard the dependency-audit security workflow."""
7887
7988 def test_dependency_audit_uses_committed_requirements_for_prs_and_pushes (self ):
80- scheduled_compile = _step ( "dependency-audit" , "Compile scheduled audit requirements" )
81- scheduled_audit = _step ( "dependency-audit" , "Run pip -audit (scheduled live resolution)" )
89+ workflow = _load_security_workflow ( )
90+ job = workflow [ "jobs" ][ "dependency -audit" ]
8291 committed_audit = _step ("dependency-audit" , "Run pip-audit (committed requirements)" )
8392 sync_check = _step ("dependency-audit" , "Check committed audit requirements are current" )
93+ setup_python = _step ("dependency-audit" , "Set up Python" )
8494
85- assert scheduled_compile ["if" ] == "${{ github.event_name == 'schedule' }}"
86- assert WORKFLOW_COMPILE_SCHEDULED_TEST_EXTRA_DEPS in scheduled_compile ["run" ]
87- assert scheduled_audit ["if" ] == "${{ github.event_name == 'schedule' }}"
88- assert scheduled_audit ["run" ] == WORKFLOW_LIVE_PIP_AUDIT
89- assert sync_check ["if" ] == "${{ github.event_name != 'schedule' }}"
95+ assert job ["if" ] == "${{ github.event_name != 'schedule' }}"
96+ assert job ["runs-on" ] == "ubuntu-latest"
97+ assert "strategy" not in job
98+ assert setup_python ["with" ]["python-version" ] == "3.13"
9099 assert sync_check ["env" ]["DEPENDENCY_DIFF_BASE" ] == (
91100 "${{ github.event.pull_request.base.sha || github.event.before || '' }}"
92101 )
93102 assert sync_check ["env" ]["DEPENDENCY_DIFF_HEAD" ] == "${{ github.sha }}"
94103 assert sync_check ["run" ] == WORKFLOW_SYNC_SCRIPT
95- assert committed_audit ["if" ] == "${{ github.event_name != 'schedule' }}"
96104 assert committed_audit ["run" ] == LOCAL_PIP_AUDIT
97105
98- dependency_job_text = " \n " . join (
99- step . get ( "run" , "" )
100- for step in _load_security_workflow ()[ "jobs" ][ " dependency-audit" ][ "steps" ]
106+ dependency_job_text = _job_run_text (
107+ "dependency-audit" ,
108+ " dependency-audit-scheduled" ,
101109 )
102110 protection_text = (
103111 dependency_job_text
@@ -133,13 +141,25 @@ def test_security_workflow_triggers(self):
133141 assert "workflow_dispatch" in triggers
134142 assert triggers ["schedule" ] == [{"cron" : "17 4 * * 1" }]
135143
136- def test_dependency_audit_runs_supported_python_os_matrix (self ):
144+ def test_scheduled_dependency_audit_runs_supported_python_os_matrix (self ):
137145 workflow = _load_security_workflow ()
138- matrix = workflow ["jobs" ]["dependency-audit" ]["strategy" ]["matrix" ]
146+ job = workflow ["jobs" ]["dependency-audit-scheduled" ]
147+ matrix = job ["strategy" ]["matrix" ]
148+ scheduled_compile = _step (
149+ "dependency-audit-scheduled" ,
150+ "Compile scheduled audit requirements" ,
151+ )
152+ scheduled_audit = _step (
153+ "dependency-audit-scheduled" ,
154+ "Run pip-audit (scheduled live resolution)" ,
155+ )
139156
157+ assert job ["if" ] == "${{ github.event_name == 'schedule' }}"
140158 assert matrix ["os" ] == ["ubuntu-latest" , "windows-latest" ]
141159 assert matrix ["python-version" ] == ["3.11" , "3.12" , "3.13" ]
142- assert workflow ["jobs" ]["dependency-audit" ]["runs-on" ] == "${{ matrix.os }}"
160+ assert job ["runs-on" ] == "${{ matrix.os }}"
161+ assert WORKFLOW_COMPILE_SCHEDULED_TEST_EXTRA_DEPS in scheduled_compile ["run" ]
162+ assert scheduled_audit ["run" ] == WORKFLOW_LIVE_PIP_AUDIT
143163
144164 def test_pip_audit_is_pinned (self ):
145165 workflow_text = SECURITY_WORKFLOW .read_text (encoding = "utf-8" )
0 commit comments