"""Strict ordered occurrence comparison; filenames optional, Python3.12+."""
import argparse,csv,json
from pathlib import Path
def verify(source,target):
    rows=json.loads(Path(source).read_text(encoding='utf-8'))
    expected=[[str(i),r['item'],r['status']] for i,r in enumerate(rows)]
    with Path(target).open(encoding='utf-8',newline='') as f:actual=list(csv.reader(f,strict=True))
    if not actual or actual[0]!=['source_position','item','status']:raise ValueError('unexpected header')
    if any(len(r)!=3 for r in actual[1:]):raise ValueError('unexpected row width')
    if actual[1:]!=expected:raise ValueError('ordered occurrences do not match source')
    return {'ordered_occurrences_equal':True,'records':len(expected)}
if __name__=='__main__':
    base=Path(__file__).parent
    p=argparse.ArgumentParser(description=__doc__);p.add_argument('source',nargs='?',default=str(base/'repeated-input.json'));p.add_argument('target',nargs='?',default=str(base/'repeated-output.csv'));a=p.parse_args()
    try:print(json.dumps(verify(a.source,a.target)))
    except (ValueError,OSError) as e:p.exit(1,type(e).__name__+': '+str(e)+'\n')
