Skip to content

Commit e32404e

Browse files
committed
ci: harden dependency audit sync checks
Assisted-by: Codex (model: GPT-5, autonomous)
1 parent 78ee765 commit e32404e

4 files changed

Lines changed: 34 additions & 10 deletions

File tree

.github/scripts/check_security_requirements.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,15 @@ def main() -> int:
6767
if not _dependency_inputs_changed():
6868
return 0
6969

70-
generated_requirements = Path(os.environ["GENERATED_REQUIREMENTS"])
70+
generated_requirements_env = os.environ.get("GENERATED_REQUIREMENTS", "").strip()
71+
if not generated_requirements_env:
72+
print(
73+
"GENERATED_REQUIREMENTS must be set to the temporary output file path.",
74+
file=sys.stderr,
75+
)
76+
return 1
77+
78+
generated_requirements = Path(generated_requirements_env)
7179
generated_requirements.parent.mkdir(parents=True, exist_ok=True)
7280

7381
subprocess.run(

.github/security-audit-requirements.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ annotated-doc==0.0.4 \
22
--hash=sha256:571ac1dc6991c450b25a9c2d84a3705e2ae7a53467b5d111c24fa8baabbed320 \
33
--hash=sha256:fbcda96e87e9c92ad167c2e53839e57503ecfda18804ea28102353485033faa4
44
# via typer
5-
click==8.4.1 \
6-
--hash=sha256:482be17c6991b8c19c5429a1e995d9b0efdbb63172824c41f99965dc0ade8ec2 \
7-
--hash=sha256:918b5633eddf6b41c32d4f454bf0de810065c74e3f7dbf8ee5452f8be88d3e96
5+
click==8.4.2 \
6+
--hash=sha256:9a6cea6e60b17ebe0a44c5cc636d94f09bd66142c1cd7d8b4cd731c4917a15f6 \
7+
--hash=sha256:e6f9f66136c816745b9d65817da91d61d957fb16e02e4dcd0552553c5a197b76
88
# via specify-cli (pyproject.toml)
99
colorama==0.4.6 ; sys_platform == 'win32' \
1010
--hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44 \
@@ -247,7 +247,7 @@ shellingham==1.5.4 \
247247
--hash=sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686 \
248248
--hash=sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de
249249
# via typer
250-
typer==0.26.7 \
251-
--hash=sha256:5c87cfbc5d34491c5346ebf49c23e18d56ccb863268d3a8d592b26087c2f5e58 \
252-
--hash=sha256:e314a34c617e419c091b2830dda3ea1f257134ff593061a8f5b9717ab8dddb3a
250+
typer==0.26.8 \
251+
--hash=sha256:3512ca79ac5c11113414b36e80281b872884477722440691c89d1112e321a49c \
252+
--hash=sha256:c244a6bd558886fe3f8780efb6bdd28bb9aff005a94eedebaa5cb32926fe2f7e
253253
# via specify-cli (pyproject.toml)

.github/workflows/security.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Checkout
2222
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
2323
with:
24-
fetch-depth: 2
24+
fetch-depth: 0
2525

2626
- name: Install uv
2727
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0

tests/test_security_workflow.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ def test_dependency_audit_uses_committed_requirements_for_prs_and_pushes(self):
124124
assert "uv.lock" not in protection_text
125125
assert "/tmp/" not in protection_text
126126

127-
def test_dependency_audit_checkout_fetches_previous_commit(self):
127+
def test_dependency_audit_checkout_fetches_full_history_for_diff_base(self):
128128
checkout = _step("dependency-audit", "Checkout")
129129

130-
assert checkout["with"]["fetch-depth"] == 2
130+
assert checkout["with"]["fetch-depth"] == 0
131131

132132
def test_security_workflow_triggers(self):
133133
triggers = _workflow_triggers()
@@ -253,6 +253,22 @@ def fake_run(command, **kwargs):
253253
assert "--output-file" in compile_commands[0]
254254
assert str(generated_requirements) in compile_commands[0]
255255

256+
def test_sync_script_reports_missing_generated_requirements_env(
257+
self, monkeypatch, capsys
258+
):
259+
sync_script = _load_sync_script()
260+
monkeypatch.delenv("GENERATED_REQUIREMENTS", raising=False)
261+
262+
def fake_run(command, **_kwargs):
263+
if command[0] == "git":
264+
return subprocess.CompletedProcess(command, 0, stdout="pyproject.toml\n", stderr="")
265+
raise AssertionError("compile should not run without GENERATED_REQUIREMENTS")
266+
267+
monkeypatch.setattr(sync_script.subprocess, "run", fake_run)
268+
269+
assert sync_script.main() == 1
270+
assert "GENERATED_REQUIREMENTS must be set" in capsys.readouterr().err
271+
256272
def test_sync_script_fails_when_generated_requirements_differ(
257273
self, monkeypatch, tmp_path, capsys
258274
):

0 commit comments

Comments
 (0)