File size: 5,515 Bytes
1340dfb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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)