Verify recorded source manifest SHA and immutable legacy history
This commit is contained in:
@@ -109,6 +109,23 @@ def load_run_inputs(manifest, root):
|
||||
validate_inputs(catalog, profile)
|
||||
if profile['modelRevision'] != manifest.get('modelRevision'):
|
||||
raise ValueError('input snapshot model revision differs from manifest')
|
||||
migration_path = Path(root) / 'input-snapshot-migration.json'
|
||||
if migration_path.exists():
|
||||
migrated = [record for record in load_json(migration_path)['runs'] if record['runId'] == run_id]
|
||||
if migrated and (len(migrated) != 1 or file_hash(run_dir / 'manifest.json') != migrated[0]['originalManifestSha256']):
|
||||
raise ValueError(f'{run_id}: immutable legacy manifest SHA-256 mismatch')
|
||||
for reference in manifest.get('environment', {}).get('sourceGenerations', []):
|
||||
source_id = reference['runId']
|
||||
if not isinstance(source_id, str) or not re.fullmatch(r'[A-Za-z0-9_]+', source_id):
|
||||
raise ValueError('invalid source generation reference runId')
|
||||
if reference['manifest'] != f'generated/{source_id}/manifest.json':
|
||||
raise ValueError('source generation reference must identify its own run manifest')
|
||||
source_path = Path(root) / reference['manifest']
|
||||
if file_hash(source_path) != reference['manifestSha256']:
|
||||
raise ValueError(f'{source_id}: recorded source manifest SHA-256 mismatch')
|
||||
source = load_json(source_path)
|
||||
if source.get('runId') != source_id or source.get('environment') != reference.get('environment'):
|
||||
raise ValueError(f'{source_id}: source generation environment reference differs')
|
||||
clips = {clip['id']: clip for clip in catalog['clips']}
|
||||
for entry in manifest.get('clips', []):
|
||||
clip = clips.get(entry.get('id'))
|
||||
|
||||
Reference in New Issue
Block a user