"""Compare the materialized online value with the same eligible history row.""" import argparse import json from pathlib import Path from history import History, COUNT, compute, source_rows, minute from inspect_history import events, KEY, CUTOFF, FIRST, ROOT def record(): db=History() try: db.materialize(events(), CUTOFF, FIRST) now=minute('2026-01-08T13:00:00Z'); max_age=120 online=db.read_online(KEY,'user-01',now,max_age) offline=db.point_in_time(KEY,'user-01',now) # Reference recomputation must use the *same* cutoff, arrival rule and definition. same_input=compute(COUNT,source_rows(events()),CUTOFF,'as_known')['user-01'] changed_rule=compute(COUNT,source_rows(events()),CUTOFF,'corrected')['user-01'] checks={'online':online,'historical':offline,'same_input_recomputed':same_input, 'same_snapshot_parity':online['value']==offline['value']==same_input, 'different_arrival_rule':changed_rule, 'different_rule_parity':online['value']==changed_rule} checks['at_age_limit']=db.read_online(KEY,'user-01',CUTOFF+max_age,max_age) checks['past_age_limit']=db.read_online(KEY,'user-01',CUTOFF+max_age+1,max_age) db.materialize(events(),CUTOFF,now+60) checks['old_value_after_recent_write']=db.read_online(KEY,'user-01',now+120,max_age) checks['before_publication']=db.read_online(KEY,'user-01',now,max_age) # The one-row online projection cannot answer an earlier historical request. future_cutoff=minute('2026-01-08T16:00:00Z') db.materialize(events(),future_cutoff,future_cutoff+30) checks['future_online_row']=db.read_online(KEY,'user-01',now,max_age) checks['missing']=db.read_online(KEY,'unknown',now,max_age) return {'mode':'local SQLite; authored snapshots, no service benchmark', 'max_age_minutes':max_age,'checks':checks} finally: db.close() def main(): p=argparse.ArgumentParser();p.add_argument('--check',action='store_true');p.add_argument('--save',type=Path) args=p.parse_args();result=record() if args.check and result!=json.loads((ROOT/'serving-result.json').read_text()): raise SystemExit('serving checks differ from the bundled record') if args.save:args.save.write_text(json.dumps(result,indent=2)+'\n') checks=result['checks'] print('Online/history/same-input parity:',checks['same_snapshot_parity']) print('Parity after changing the arrival rule:',checks['different_rule_parity']) for name in ['at_age_limit','past_age_limit','old_value_after_recent_write','before_publication','future_online_row','missing']: row=checks[name];print(f"{name}: status={row['status']}; value={row['value']}; age={row['age_minutes']}") print('Age is measured from the feature cutoff; rejected reads withhold the value.') if __name__=='__main__':main()