feat(01-03): reconcile full-game capability and checkpoint coverage
Map all 33 requirements across six groups and reconcile 33 hashed source rows. Preserve startup current/history, unimplemented work and open native/reference acceptance; bind imported receipt identities and generate navigation.
This commit is contained in:
1 parent
fafbd05811
commit
4d07d60e2f
4 files changed
+4225
-10
No files matched your search
@@ -131,6 +131,30 @@ def _source(project, link, tracked):
|
||||
return name
|
||||
|
||||
|
||||
def checkpoint_rows(path):
|
||||
"""Identity every system/ownership table row and numbered assumption.
|
||||
|
||||
Exact line/paragraph bytes are hashed so reconciliation must be reviewed
|
||||
when its source changes. Top-level narrative remains in the linked report.
|
||||
"""
|
||||
text = Path(path).read_text()
|
||||
result, section = {}, None
|
||||
for line in text.splitlines():
|
||||
if line.startswith('| ID / system |'): section = 'system'
|
||||
elif line.startswith('| State / owner |'): section = 'ownership'
|
||||
elif line.startswith('#'): section = None
|
||||
elif section and line.startswith('|') and not line.startswith('|---'):
|
||||
key = section + ':' + line.split('|')[1].strip()
|
||||
if key in result: raise ValueError('Ambiguous checkpoint row: ' + key)
|
||||
result[key] = hashlib.sha256(line.encode()).hexdigest()
|
||||
marker = '## Assumptions and symptom-level adapters to replace'
|
||||
if marker not in text: raise ValueError('Missing checkpoint assumptions section')
|
||||
assumptions = text.split(marker, 1)[1].split('\n## ', 1)[0]
|
||||
for match in re.finditer(r'^([1-9][0-9]*)\. (.*(?:\n(?!\n|[1-9][0-9]*\. ).*)*)', assumptions, re.M):
|
||||
result['assumption:' + match[1]] = hashlib.sha256(match[0].encode()).hexdigest()
|
||||
return result
|
||||
|
||||
|
||||
def _records(row, project, tracked):
|
||||
records = _deduplicate(_list(row.get('evidence'), 'evidence'), 'id')
|
||||
_deduplicate(records, 'receipt_id')
|
||||
@@ -143,9 +167,15 @@ def _records(row, project, tracked):
|
||||
if kind not in KINDS: raise ValueError('Invalid receipt classification')
|
||||
platform = record['platform']
|
||||
execution = platform['execution']
|
||||
if kind in {'native_port', 'port_fixture'} and (execution != 'native' or platform['os'] not in {'linux', 'windows'}):
|
||||
if kind == 'native_port' and (execution != 'native' or platform['os'] not in {'linux', 'windows'}):
|
||||
raise ValueError('Native/fixture classification cannot use Wine or source proof')
|
||||
if kind == 'original_dxwnd' and platform != {'os': 'windows', 'execution': 'dxwnd'}:
|
||||
if kind == 'port_fixture' and (execution not in {'native', 'port_fixture'} or platform['os'] not in {'linux', 'windows'}):
|
||||
raise ValueError('Fixture classification requires its declared port host')
|
||||
if kind in {'component', 'managed', 'synthetic'} and execution != kind:
|
||||
raise ValueError('Component/managed/synthetic evidence must retain its execution category')
|
||||
if kind == 'inferred' and execution not in {'static', 'inferred'}:
|
||||
raise ValueError('Inference cannot become runtime proof')
|
||||
if kind == 'original_dxwnd' and (platform['os'] != 'windows' or execution != 'dxwnd'):
|
||||
raise ValueError('Original DxWnd requires Windows/DxWnd')
|
||||
if kind == 'wine' and execution != 'wine': raise ValueError('Wine must stay Wine')
|
||||
if kind == 'cross_publish' and execution != 'cross_publish': raise ValueError('Cross-publish is not execution')
|
||||
@@ -156,6 +186,10 @@ def _records(row, project, tracked):
|
||||
_text(record.get('revision'), 'evidence revision')
|
||||
_text(record.get('method'), 'observation method')
|
||||
_source(project, {'label': 'Evidence report', 'path': record.get('report_path')}, tracked)
|
||||
if 'report_sha256' in record['content']:
|
||||
report = contained_path(project, record['report_path'])
|
||||
if identify_file(report)['sha256'] != record['content']['report_sha256']:
|
||||
raise ValueError('Report content identity mismatch')
|
||||
claim = record.get('claim')
|
||||
if not isinstance(claim, dict): raise ValueError('Evidence claim required')
|
||||
_text(claim.get('key'), 'claim key')
|
||||
@@ -189,6 +223,12 @@ def _records(row, project, tracked):
|
||||
validate_receipt(receipt, receipt_path.parent)
|
||||
if receipt['receipt_id'] != record['receipt_id'] or receipt['evidence_kind'] != kind:
|
||||
raise ValueError('Receipt reference identity/classification mismatch')
|
||||
receipt_scope = receipt['scope'] if isinstance(receipt['scope'], list) else [receipt['scope']]
|
||||
if (receipt['platform'] != record['platform'] or sorted(receipt_scope) != sorted(record['scope'])
|
||||
or receipt['historical'] != record['historical']):
|
||||
raise ValueError('Receipt reference platform/scope/history mismatch')
|
||||
if record['content'].get('receipt_sha256') != identify_file(receipt_path)['sha256']:
|
||||
raise ValueError('Receipt reference requires its exact content digest')
|
||||
visiting, visited = set(), set()
|
||||
def visit(identifier):
|
||||
if identifier in visiting: raise ValueError('Supersession cycle')
|
||||
@@ -214,7 +254,7 @@ def validate_ledger(data, project=PROJECT, requirements=None):
|
||||
tracked = _tracked(project)
|
||||
scenarios = read_json(project / 'docs/evidence/scenarios.json')
|
||||
scenario_ids = {cell['id'] for cell in scenarios['cells']}
|
||||
mapped, groups = set(), set()
|
||||
mapped, groups, all_records = set(), set(), []
|
||||
for row in rows:
|
||||
if row.get('group') not in GROUPS: raise ValueError('Unknown capability group')
|
||||
groups.add(row['group'])
|
||||
@@ -239,6 +279,7 @@ def validate_ledger(data, project=PROJECT, requirements=None):
|
||||
for path in _list(implementation.get('paths'), 'implementation paths'):
|
||||
_source(project, {'label': 'Implementation', 'path': path}, tracked)
|
||||
records = _records(row, project, tracked)
|
||||
all_records.extend(records)
|
||||
targets = _deduplicate(_list(row.get('targets'), 'applicability targets'), 'id')
|
||||
for target in targets: _identity(target)
|
||||
for record in records:
|
||||
@@ -248,13 +289,32 @@ def validate_ledger(data, project=PROJECT, requirements=None):
|
||||
for gap in discrepancies:
|
||||
if gap.get('impact') not in IMPACTS: raise ValueError('Invalid discrepancy impact')
|
||||
_text(gap.get('summary'), 'discrepancy summary')
|
||||
_deduplicate(all_records, 'id')
|
||||
_deduplicate(all_records, 'receipt_id')
|
||||
expected = set()
|
||||
if requirements is not None:
|
||||
expected = set(re.findall(r'^- \[[ x]\] \*\*([A-Z]+-[0-9]{2})\*\*:', Path(requirements).read_text(), re.M))
|
||||
if not expected or expected != mapped: raise ValueError('Unmapped or unknown requirements: ' + str(sorted(expected ^ mapped)))
|
||||
if groups != set(GROUPS): raise ValueError('All six capability groups are required')
|
||||
if requirements is not None or 'reconciliation' in data:
|
||||
expected_rows = checkpoint_rows(project / 'docs/checkpoint/coverage.md')
|
||||
reconciliation = _list(data.get('reconciliation'), 'checkpoint reconciliation', True)
|
||||
actual_rows = {}
|
||||
for record in reconciliation:
|
||||
source_row = _text(record.get('source_row'), 'source row')
|
||||
if source_row in actual_rows: raise ValueError('Duplicate source reconciliation row')
|
||||
actual_rows[source_row] = record.get('source_sha256')
|
||||
if record.get('source_path') != 'docs/checkpoint/coverage.md': raise ValueError('Wrong checkpoint source')
|
||||
_source(project, {'label': 'Checkpoint', 'path': record['source_path']}, tracked)
|
||||
for identifier in _list(record.get('capability_ids'), 'reconciled capability IDs', True):
|
||||
if identifier not in {row['id'] for row in rows}: raise ValueError('Unknown reconciled capability')
|
||||
capability = next(row for row in rows if row['id'] == identifier)
|
||||
if not any(link['path'] == record['source_path'] for link in capability['source_links']):
|
||||
raise ValueError('Reconciled capability must link the retained checkpoint source')
|
||||
if actual_rows != expected_rows: raise ValueError('Missing, stale or extra checkpoint source-row reconciliation')
|
||||
return {'capabilities': len(rows), 'requirements': len(expected or mapped),
|
||||
'unmapped': len(expected - mapped), 'groups': len(groups), 'acceptance': 'OPEN'}
|
||||
'unmapped': len(expected - mapped), 'groups': len(groups),
|
||||
'reconciled_rows': len(data.get('reconciliation', [])), 'acceptance': 'OPEN'}
|
||||
|
||||
|
||||
def export_ledger(data, project=PROJECT, requirements=None):
|
||||
@@ -349,12 +409,15 @@ def main():
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
data = read_json(args.ledger)
|
||||
counts = validate_ledger(data, PROJECT, args.requirements)
|
||||
requirements = args.requirements
|
||||
if requirements is None and 'reconciliation' in data:
|
||||
requirements = PROJECT / '.planning/REQUIREMENTS.md'
|
||||
counts = validate_ledger(data, PROJECT, requirements)
|
||||
if args.command != 'validate':
|
||||
if args.output is None: raise ValueError('--output required')
|
||||
if args.output.resolve() == args.ledger.resolve(): raise ValueError('Cannot overwrite authoritative ledger')
|
||||
raw = (render_markdown(data, PROJECT, args.requirements).encode() if args.command == 'render'
|
||||
else canonical_bytes(export_ledger(data, PROJECT, args.requirements)))
|
||||
raw = (render_markdown(data, PROJECT, requirements).encode() if args.command == 'render'
|
||||
else canonical_bytes(export_ledger(data, PROJECT, requirements)))
|
||||
_write(args.output, raw)
|
||||
print(' '.join(f'{key}={value}' for key, value in counts.items()))
|
||||
return 0
|
||||
|
||||
Reference in new issue
Block a user