infrastructure/tests/layer-conformance.py
2026-11-04 21:39:11 +00:00

42 lines
1.5 KiB
Python

"""Run the approved reference fixtures against the Rust CLI too."""
import json
import os
from pathlib import Path
import subprocess
import tempfile
source = Path('/src/rfc/schemas/check-fixtures.py')
namespace = {'__file__': str(source), '__name__': 'fixture_reference'}
text = source.read_text()
# Load reference functions before its fixtures execute, then wrap validate.
prefix, fixtures = text.split('base = parse(', 1)
exec(compile(prefix, str(source), 'exec'), namespace)
reference = namespace['validate']
binary = os.environ.get('ARCHIPELAGO_BINARY', '/build/target/release/archipelago')
count = 0
def validate(data):
global count
try:
result = reference(data)
expected = True
except (ValueError, namespace['jsonschema'].ValidationError) as error:
result = error
expected = False
with tempfile.NamedTemporaryFile(mode='w', suffix='.json') as stream:
json.dump(data, stream)
stream.flush()
cli = subprocess.run([binary, 'layer', 'validate', stream.name], capture_output=True, text=True)
assert (cli.returncode == 0) == expected, cli.stderr
count += 1
if not expected:
raise result
return result
namespace['validate'] = validate
exec(compile('base = parse(' + fixtures, str(source), 'exec'), namespace)
for path in [Path('/src/core/layers/arch.yaml'), *Path('/src/purposes/proposals').glob('*.yaml')]:
subprocess.run([binary, 'layer', 'validate', str(path)], check=True)
print(f'PASS: Rust/reference agreement on {count} validation fixtures and three registry YAMLs')