ความคืบหน้างาน ไฟล์ต้นฉบับ

docs/agent/tools/check_use_case_review.py

#!/usr/bin/env python3
"""Check full audit coverage and explicit workflow metadata against canonical UCs."""
import json
import sys
sys.dont_write_bytecode = True
from gen_use_cases import ROOT, load_data


def main():
    data = load_data()
    cases = data['uc']
    audit = json.loads((ROOT / 'docs/agent/reviews/2026-10-31-use-case-audit.json').read_text())
    rows = {row['id']: row for row in audit['cases']}
    assert len(rows) == len(audit['cases']) == len(cases) == 162
    assert set(rows) == set(cases)
    gates = 0
    for uid, u in cases.items():
        assert rows[uid]['assessment'] == u['review']['note'], uid
        assert u['review']['state'] == 'proposed', uid
        assert all(target in cases for _, target in u['r']), uid
        assert all(actor == 'ระบบ' or actor in u['a'] for actor, _ in u['f']), uid
        wf = u.get('wf', {})
        decisions = wf.get('decisions', [])
        assert len({g['before'] for g in decisions}) == len(decisions), uid
        assert rows[uid]['decisions'] == len(decisions), uid
        for g in decisions:
            assert 1 <= g['before'] <= len(u['f']), uid
            branches = g['branches']
            assert len(branches) >= 2 and len({b['label'] for b in branches}) == len(branches), uid
            for b in branches:
                assert bool(b.get('target')) != bool(b.get('outcome')), uid
                if 'target' in b:
                    assert 1 <= b['target'] <= len(u['f']), uid
        for step, target in wf.get('next', {}).items():
            assert 1 <= int(step) <= len(u['f']) and 1 <= target <= len(u['f']), uid
        for step, outcome in wf.get('stop', {}).items():
            assert 1 <= int(step) <= len(u['f']) and outcome, uid
        generated = (ROOT / 'docs/agent/use-cases' / (u['m'][0] + '.md')).read_text()
        assert u['review']['note'] in generated, uid
        gates += len(decisions)
    print(f'PASS: {len(cases)} audit entries, {gates} decisions, references/actors/targets and generated notes')


if __name__ == '__main__':
    main()