File size: 3,524 Bytes
7dfdbfb d1a3753 7dfdbfb | 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 | """Population selection must keep intended tasks and reject ambiguous inputs."""
from copy import deepcopy
from pathlib import Path
import unittest
from task_population import select, validate
ROOT = Path(__file__).resolve().parents[1]
class PopulationTests(unittest.TestCase):
def setUp(self):
self.spec = validate(ROOT)
self.records = self.spec['cases'] + self.spec['excluded']
def test_selection_matches_report_and_retains_dynamic_suite(self):
result = select(ROOT, self.records, self.spec['revision'])
self.assertEqual(len(result), 530)
self.assertIn({'suite': 'dynamic-content', 'id': 'dynamic-iframe'}, result)
self.assertNotIn(('webfetch', 'dynamic-iframe'), {(r['suite'], r['id']) for r in result})
def test_already_selected_input(self):
self.assertEqual(select(ROOT, self.spec['cases'], self.spec['revision']), self.spec['cases'])
def test_duplicate_rejected(self):
with self.assertRaises(ValueError):
select(ROOT, self.records + [self.records[0]], self.spec['revision'])
def test_missing_task_rejected(self):
with self.assertRaises(ValueError):
select(ROOT, self.records[1:], self.spec['revision'])
def test_unknown_task_rejected(self):
with self.assertRaises(ValueError):
select(ROOT, self.records + [{'suite': 'webfetch', 'id': 'unknown'}], self.spec['revision'])
def test_other_revision_rejected(self):
with self.assertRaises(ValueError):
select(ROOT, self.records, 'review-550-20261023')
def test_tampered_binding_rejected(self):
spec = deepcopy(self.spec)
spec['frozen_task_bindings']['webfetch']['sha256'] = '0' * 64
with self.assertRaises(ValueError):
validate(ROOT, spec)
def test_overlap_rejected(self):
spec = deepcopy(self.spec)
spec['excluded'][0] = spec['cases'][0]
with self.assertRaises(ValueError):
validate(ROOT, spec)
def test_wrong_count_rejected(self):
spec = deepcopy(self.spec)
spec['task_count'] = 550
with self.assertRaises(ValueError):
validate(ROOT, spec)
def test_wrong_revision_hash_rejected(self):
spec = deepcopy(self.spec)
spec['revision_sha256'] = '0' * 64
with self.assertRaisesRegex(ValueError, 'revision hash'):
validate(ROOT, spec)
class RunnerSelectionTests(unittest.TestCase):
def test_cli_selects_exactly_the_report_population(self):
import subprocess
import sys
spec = validate(ROOT)
actual = []
for suite, count in spec['suite_counts'].items():
command = [sys.executable, str(ROOT / 'tools/task_population.py'), '--suite', suite]
result = subprocess.run(command, check=True, text=True, capture_output=True)
ids = result.stdout.strip().split(',')
self.assertEqual(len(ids), count)
actual.extend((suite, identifier) for identifier in ids)
self.assertEqual(set(actual), {(r['suite'], r['id']) for r in spec['cases']})
self.assertEqual(len(actual), 530)
def test_cli_rejects_unknown_suite(self):
import subprocess
import sys
result = subprocess.run([sys.executable, str(ROOT / 'tools/task_population.py'),
'--suite', 'unknown'], text=True, capture_output=True)
self.assertNotEqual(result.returncode, 0)
self.assertEqual(result.stdout, '')
|