Download tests/test_release_candidate.py from Helinity/python-security-benchmark: direct link, hf CLI and curl.
- Browser
- Download file 5.52 kB
-
https://huggingface.co/datasets/Helinity/python-security-benchmark/resolve/main/tests/test_release_candidate.py
- Command line
-
hf download hf://datasets/Helinity/python-security-benchmark/tests/test_release_candidate.py
-
curl -L -o test_release_candidate.py https://huggingface.co/datasets/Helinity/python-security-benchmark/resolve/main/tests/test_release_candidate.py
5.52 kB
| import json | |
| from copy import deepcopy | |
| import pytest | |
| from research.release_candidate.audit import reconcile | |
| from research.release_candidate.review import review_templates, validate_review | |
| from research.release_candidate.package import verify_manifest, file_inventory | |
| def test_release_counts_and_evidence_boundaries(): | |
| result = reconcile() | |
| assert result['unique_records'] == 154 | |
| assert result['eligible_records'] == 115 | |
| assert result['eligible_by_release'] == {'phase3b': 49, 'phase3c1': 66} | |
| assert result['eligible_evidence_methods'] == {'docker_runtime': 82, 'controlled_local_process': 33} | |
| assert result['excluded_records'] == 39 | |
| assert len(result['configurations']) == 6 | |
| def test_pending_reviews_cannot_be_treated_as_independent_validation(): | |
| reviews = review_templates() | |
| assert len(reviews) == 64 | |
| assert len({r['sample_id'] for r in reviews}) == 64 | |
| for review in reviews: | |
| validate_review(review) | |
| assert review['decision'] is None | |
| changed = deepcopy(reviews[0]) | |
| changed['decision'] = 'accept' | |
| with pytest.raises(ValueError): | |
| validate_review(changed) | |
| def test_review_acceptance_requires_identity_time_checks_and_source(): | |
| review = deepcopy(review_templates()[0]) | |
| review.update(reviewer_id='test-human-placeholder', reviewed_at_utc='2026-11-16T00:00:00Z', | |
| independent_of_authoring=True, decision='accept', rationale='Unit-test input only.') | |
| review['checks'] = dict.fromkeys(review['checks'], True) | |
| validate_review(review) | |
| changed = deepcopy(review) | |
| changed['checks']['evidence_completeness'] = False | |
| with pytest.raises(ValueError): | |
| validate_review(changed) | |
| changed = deepcopy(review) | |
| changed['record_sha256'] = '0' * 64 | |
| with pytest.raises(ValueError): | |
| validate_review(changed) | |
| def test_manifest_rejects_modified_or_extra_files(tmp_path): | |
| (tmp_path / 'README.md').write_text('candidate') | |
| inventory = file_inventory(tmp_path) | |
| manifest = {'files': inventory} | |
| (tmp_path / 'RELEASE_MANIFEST.json').write_text(json.dumps(manifest)) | |
| verify_manifest(tmp_path) | |
| (tmp_path / 'README.md').write_text('modified') | |
| with pytest.raises(ValueError): | |
| verify_manifest(tmp_path) | |
| def test_exclusion_probe_records_real_json_routes(): | |
| from research.release_candidate.audit import RELEASE | |
| report = json.loads((RELEASE / 'exclusion-audit.json').read_text()) | |
| assert len(report['results']) == 4 | |
| assert all(r['content_type'] == 'application/json' for r in report['results'].values()) | |
| assert all(r['status_code'] == 200 and r['location'] is None for r in report['results'].values()) | |
| assert all(r['eligible'] is False for r in report['results'].values()) | |
| def test_publisher_default_is_local_only(tmp_path, monkeypatch, capsys): | |
| import builtins | |
| from research.release_candidate.publish import publish | |
| original_import = builtins.__import__ | |
| def forbid_hub(name, *args, **kwargs): | |
| if name.startswith('huggingface_hub'): | |
| raise AssertionError('Default publication check must not access the Hub') | |
| return original_import(name, *args, **kwargs) | |
| (tmp_path / 'README.md').write_text('fixture') | |
| manifest = dict(files=file_inventory(tmp_path), version='v0.1.0', branch='rc-v0.1.0', file_count=1, | |
| repo_id='Helinity/python-security-benchmark', repo_type='dataset', intended_visibility='private') | |
| (tmp_path / 'RELEASE_MANIFEST.json').write_text(json.dumps(manifest)) | |
| monkeypatch.setattr(builtins, '__import__', forbid_hub) | |
| publish(tmp_path) | |
| assert 'LOCAL CHECK ONLY' in capsys.readouterr().out | |
| def test_all_historical_baselines_remain_reproducible(): | |
| from research.release_candidate.historical import check | |
| check() | |
| def test_future_publisher_refuses_public_repository(tmp_path, monkeypatch): | |
| from types import SimpleNamespace | |
| import huggingface_hub | |
| from research.release_candidate.publish import publish | |
| class FakeApi: | |
| def whoami(self): | |
| return {'name': 'Helinity'} | |
| def repo_info(self, *args, **kwargs): | |
| return SimpleNamespace(private=False) | |
| def upload_folder(self, **kwargs): | |
| raise AssertionError('Public target must never be uploaded to') | |
| monkeypatch.setattr(huggingface_hub, 'HfApi', FakeApi) | |
| (tmp_path / 'README.md').write_text('test-only') | |
| manifest = dict(files=file_inventory(tmp_path), version='v0.1.0', branch='rc-v0.1.0', file_count=1, | |
| repo_id='Helinity/python-security-benchmark', repo_type='dataset', intended_visibility='private') | |
| (tmp_path / 'RELEASE_MANIFEST.json').write_text(json.dumps(manifest)) | |
| with pytest.raises(ValueError, match='not private'): | |
| publish(tmp_path, execute=True) | |
| def test_extra_nested_manifest_is_not_silently_ignored(tmp_path): | |
| manifest = {'files': {}} | |
| (tmp_path / 'RELEASE_MANIFEST.json').write_text(json.dumps(manifest)) | |
| (tmp_path / 'nested').mkdir() | |
| (tmp_path / 'nested/RELEASE_MANIFEST.json').write_text('unexpected file') | |
| with pytest.raises(ValueError, match='unexpected files'): | |
| verify_manifest(tmp_path) | |
| def test_publisher_cannot_target_main(tmp_path): | |
| from research.release_candidate.publish import publish | |
| manifest = dict(files={}, version='v0.1.0', branch='main') | |
| (tmp_path / 'RELEASE_MANIFEST.json').write_text(json.dumps(manifest)) | |
| with pytest.raises(ValueError, match='never target main'): | |
| publish(tmp_path) | |