added
This commit is contained in:
1 parent
4eaec52904
commit
df7571392e
50 files changed
+3390
-258
No files matched your search
@@ -5,12 +5,47 @@ import re
|
||||
from pathlib import Path
|
||||
from urllib.parse import unquote
|
||||
|
||||
from jsonschema import Draft202012Validator
|
||||
from jsonschema import Draft202012Validator, FormatChecker
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SKIP = {'build', '.git', '__pycache__', '.test-work', '.venv'}
|
||||
|
||||
|
||||
def validate_contracts(root=ROOT):
|
||||
def load(name):
|
||||
return json.loads((root/name).read_text(encoding='utf-8-sig'))
|
||||
for document,schema in [('repository.json','repository'),('repository-variables.json','repository-variables'),('content-index.json','content-index')]:
|
||||
Draft202012Validator(load('schemas/'+schema+'.schema.json'), format_checker=FormatChecker()).validate(load(document))
|
||||
manifest,variables,index=load('repository.json'),load('repository-variables.json'),load('content-index.json')
|
||||
assert variables['identity']['authors']==manifest['authors'], 'Author mismatch'
|
||||
assert variables['identity']['publisher']==manifest['publisher'], 'Publisher mismatch'
|
||||
assert variables['identity']['maintainer']['name']==manifest['maintenance']['maintainer'], 'Maintainer mismatch'
|
||||
for key,value in variables['repository'].items():
|
||||
assert manifest.get(key)==value, 'Repository identity mismatch: '+key
|
||||
for key,value in variables['rights'].items():
|
||||
assert manifest['rights'][key]==value, 'Rights mismatch: '+key
|
||||
version=(root/'VERSION').read_text(encoding='utf-8-sig').strip()
|
||||
assert manifest['version']==version, 'Manifest/version mismatch'
|
||||
citation=(root/'CITATION.cff').read_text(encoding='utf-8')
|
||||
assert re.search(r'(?m)^version:\s*[\"\x27]?'+re.escape(version)+r'[\"\x27]?\s*$',citation), 'Citation version mismatch'
|
||||
assert 'license: MIT' in citation and manifest['rights']['license']=='MIT', 'Citation/license mismatch'
|
||||
assert manifest['canonical_url'] in citation, 'Citation URL mismatch'
|
||||
for record in manifest['authors']:
|
||||
assert record['name'] in (root/'AUTHOR.md').read_text(encoding='utf-8'), 'Author notice mismatch'
|
||||
assert 'Copyright (c) 2026 Eddie Soehnel' in (root/manifest['rights']['license_file']).read_text(encoding='utf-8'), 'License attribution mismatch'
|
||||
ids=[item['content_id'] for item in index['items']]
|
||||
paths=[item['path'] for item in index['items']]
|
||||
assert len(ids)==len(set(ids)) and len(paths)==len(set(paths)), 'Duplicate content identity/path'
|
||||
for item in index['items']:
|
||||
target=(root/item['path']).resolve()
|
||||
assert target.is_relative_to(root.resolve()) and target.is_file(), 'Missing/unsafe indexed path'
|
||||
assert set(item.get('related_content_ids',[])) <= set(ids), 'Unresolved content relation'
|
||||
for declared in [v for v in manifest['entrypoints'].values() if v] + [c['path'] for c in manifest['contents']] + manifest['ai_retrieval']['read_first'] + manifest['ai_retrieval']['retrieve_as_needed']:
|
||||
target=(root/declared).resolve()
|
||||
assert target.is_relative_to(root.resolve()) and target.exists(), 'Missing/unsafe declared path: '+declared
|
||||
return {'version':version,'license':manifest['rights']['license'],'indexed_documents':len(ids)}
|
||||
|
||||
|
||||
def check():
|
||||
files = [p for p in ROOT.rglob('*') if p.is_file() and not (set(p.relative_to(ROOT).parts) & SKIP)]
|
||||
count = {'json': 0, 'markdown_links': 0, 'schema_refs': 0, 'python': 0}
|
||||
@@ -59,12 +94,12 @@ def check():
|
||||
except Exception as error:
|
||||
errors.append(f'{path.relative_to(ROOT)}: {error}')
|
||||
manifest = json.loads((ROOT/'repository.json').read_text(encoding='utf-8'))
|
||||
for name in list(manifest['entrypoints'].values()) + [v['path'] for v in manifest['contents']]:
|
||||
for name in [v for v in manifest['entrypoints'].values() if v] + [v['path'] for v in manifest['contents']]:
|
||||
if not (ROOT/name).exists():
|
||||
errors.append('Missing manifest path: ' + name)
|
||||
if errors:
|
||||
raise ValueError('\n'.join(errors))
|
||||
print(json.dumps({'valid': True, **count}, indent=2))
|
||||
print(json.dumps({'valid': True, **count, **validate_contracts(ROOT)}, indent=2))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in new issue
Block a user