Samples / tests /smoke.py
TidorP's picture
Publish seven selected GDPVal, STEM and code samples with a unified Docker runner
700c7f4 verified
Raw History Blame Contribute Delete
4.45 kB
"""Offline checks through the actual Docker CLI. Run: python tests/smoke.py"""
import json
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
import zipfile
ROOT = Path(__file__).resolve().parents[1]
IMAGE = os.getenv('SAMPLES_IMAGE', 'poindexter-samples')
def run(*args, mounts=()):
command = ['docker', 'run', '--rm']
for source, destination in mounts:
command += ['-v', f'{source}:{destination}:ro']
return subprocess.run(command + [IMAGE, *args], capture_output=True, text=True)
def documents(output):
# Each group emits a heading followed by one JSON document.
result = []
for section in output.split('\n--- ')[1:]:
payload = section.split('\n', 1)[1]
result.append(json.JSONDecoder().raw_decode(payload)[0])
return result
class SamplesTests(unittest.TestCase):
def test_exact_selection(self):
r = run('list')
self.assertEqual(r.returncode, 0, r.stderr)
selected = json.loads(r.stdout)
self.assertEqual(len(selected), 7)
self.assertEqual({t['id'] for t in selected}, {
'german-664a42e5-3240-413a-9a57-ea93c6303269',
'japanese-ec2fccc9-b7f6-4c73-bf51-896fdb433cec',
'french-43dc9778-450b-4b46-b77e-b6d82b202035',
'PDS136', 'PDS049', 'swe_rl_cybersecurity_task_02',
'pdl_qna_signed_package_resolution_014'})
def test_native_plans_for_both_providers(self):
for provider in ['openai', 'anthropic']:
r = run('plan', '--provider', provider)
self.assertEqual(r.returncode, 0, r.stderr)
plans = documents(r.stdout)
self.assertEqual(sum(p['tasks'] for p in plans), 7)
self.assertEqual(sum(p['attempts'] for p in plans), 7)
self.assertEqual(len(plans), 4)
for p in plans:
keys = p['required_environment_variables']
self.assertFalse(any('AZURE' in k or 'AWS' in k for k in keys))
self.assertEqual(len(p['models']), 1)
if 'families' in p:
self.assertIsNone(p['models'][0]['endpoint'])
if 'qna' in p['families']:
self.assertEqual(len(p['families']['qna']['judges']), 2)
def test_selection_validation_before_execution(self):
for args in [('run', '--task', 'missing'),
('run', '--group', 'stem', '--task', 'swe_rl_cybersecurity_task_02'),
('run', '--attempts', '0'), ('run', '--agent', 'gold')]:
r = run(*args)
self.assertNotEqual(r.returncode, 0)
self.assertNotIn('SOLVING', r.stdout)
def test_missing_credentials(self):
r = run('doctor', '--group', 'stem')
self.assertNotEqual(r.returncode, 0)
self.assertIn('OPENAI_API_KEY', r.stderr)
def test_checksum_rejection(self):
with tempfile.TemporaryDirectory() as d:
shutil.copytree(ROOT / 'data/gdpval', Path(d) / 'gdpval')
rows = list(map(json.loads, (Path(d) / 'gdpval/tasks.jsonl').read_text().splitlines()))
task = next(t for t in rows if t['language'] == 'Japanese')
file = Path(d) / 'gdpval' / task['inputs'][0]['path']
file.write_bytes(file.read_bytes() + b'tampered')
r = run('plan', '--task', task['id'], '--data', '/testdata', mounts=[(d, '/testdata')])
self.assertNotEqual(r.returncode, 0)
self.assertIn('checksum mismatch', r.stderr)
def test_qna_rejects_undersized_panel_before_execution(self):
r = run('plan', '--group', 'qna', '--judges', 'openai:gpt-6.1-sol@https://api.openai.com/v1')
self.assertNotEqual(r.returncode, 0)
self.assertIn('at least two', r.stderr)
def test_archive_integrity_and_paths(self):
for path in (ROOT / 'data').rglob('*.zip'):
with zipfile.ZipFile(path) as z:
self.assertIsNone(z.testzip(), str(path))
for name in z.namelist():
self.assertFalse(Path(name).is_absolute())
self.assertNotIn('..', Path(name).parts)
for path in (ROOT / 'data').rglob('*.docx'):
with zipfile.ZipFile(path) as z:
self.assertIsNone(z.testzip())
self.assertIn('word/document.xml', z.namelist())
if __name__ == '__main__':
unittest.main(verbosity=2)