import cn.jojo.cc.biz.model.cache.*;import cn.jojo.cc.biz.service.english.segment.*;import cn.jojo.cc.common.enums.*;import com.alibaba.fastjson.*;
public class CacheRoundTripProbe{static int failed;static void check(boolean b,String n){System.out.println((b?"PASS ":"FAIL ")+n);if(!b)failed++;}public static void main(String[]args)throws Exception{
 var output=JSON.parseObject("{\"questionInfo\":{\"body\":\"hello\",\"explicitNull\":null},\"array\":[1,null,2]}");String expected=SegmentPayloadIdentity.outputHash(output);
 var bo=new FormAndDataCacheBo(8L,1,2,1,"/v2.json",output);bo.setSegmentSourceFormDataId(7L);bo.setSegmentSourcePayloadHash(SegmentPayloadIdentity.hash(output));
 try{var f=FormAndDataCacheBo.class.getDeclaredField("segmentSourceOutputHash");f.setAccessible(true);f.set(bo,expected);}catch(NoSuchFieldException old){}
 var direct=SelectedSegmentOutput.capture(DataBaseTypeEnum.TEACHING,8L,bo,"/v2.json");check(direct.known()&&expected.equals(direct.identity().outputPayloadHash()),"direct DB BO output identity matches");
 String serialized=JSON.toJSONString(bo);System.out.println("actual default BO serializer="+serialized);
 var fromRedis=JSON.parseObject(serialized,FormAndDataCacheBo.class);var selected=SelectedSegmentOutput.capture(DataBaseTypeEnum.TEACHING,8L,fromRedis,"/v2.json");
 check(selected.known()&&expected.equals(selected.identity().outputPayloadHash()),"real BO default serializer Redis roundtrip preserves scalar identity despite nested null loss");
 // A cache from the preceding app version has old source fields but lacks the new output scalar.
 try{var f=FormAndDataCacheBo.class.getDeclaredField("segmentSourceOutputHash");f.setAccessible(true);f.set(fromRedis,null);}catch(NoSuchFieldException old){}
 check(!SelectedSegmentOutput.capture(DataBaseTypeEnum.TEACHING,8L,fromRedis,"/v2.json").known(),"legacy missing output scalar fails closed without synthesizing from object or DB");
 if(failed>0)System.exit(1);}}
