// Actual release readiness/acceptance helpers and state; explicit actor, // snapshot, restoration-plan and transport boundaries (not a freeze proof). #define main cubeBaseMain #include "tests/features/fixtures/cube_batch_probe.cpp" #undef main #include "src/server/common/cube_live_image.h" static bool audited=true,online=true,actorMatches=true,eventsReady=true,captureOK=true; static InventoryImage current;static std::string currentSeal="applied"; struct TQuickslot{uint8_t type=0;uint16_t pos=0;}; struct CHARACTER{TQuickslot slots[36];int missing=-1;int64_t GetGold(){return current.gold;}bool GetQuickslot(unsigned n,TQuickslot** p){*p=&slots[n];return int(n)!=missing;}}; using LPCHARACTER=CHARACTER*; struct RestorePlan{bool prepared=true,enabled=false;bool Prepared()const{return prepared;}bool Enabled()const{return enabled;}}; struct Owner{Batch batch;ActorHandshake flow;CraftFlow craft;LiveImageFlow image;LiveReleaseFlow release;bool frozen=true,quickslotsCaptured=true,published=true;RestorePlan restore;std::string appliedSeal="applied";std::array quickslots={};}; struct Snapshot{std::string seal;std::vector ordinary;}; bool capture(CHARACTER*,Snapshot& s){s.seal=currentSeal;s.ordinary=current.items;return captureOK;} bool matches(CHARACTER*,const Owner&){return actorMatches;}bool connected(){return online;} bool PortCubeRestoredInventoryReady(CHARACTER*,const RestorePlan&){return eventsReady;} // ACTUAL_HELPERS_HERE Owner ready(CHARACTER& ch){ Owner o;o.batch=batch();assert(o.flow.Start(o.batch,8,1,true));auto f=ArmFrame(o.batch,8);f.body.clear();f.cookie=7;f.message=Message::Answer;f.status=Status::Armed; assert(o.flow.Armed(f,1)&&o.flow.Submit(true,1));f.status=Status::Frozen;assert(o.flow.Answer(f)); assert(o.craft.Start(o.flow.Request(Message::Poll),true,true));f.message=Message::CraftAnswer;f.status=Status::Prepared;assert(o.craft.Answer(f,o.batch,proto)); const auto plan=SettlePlan(o.batch,std::string("\1\144\1",3),proto);f.status=Status::Complete;f.body=EncodeCraftReceipt({plan.result,plan.successes,plan.fee,plan.awards});assert(o.craft.Answer(f,o.batch,proto)); assert(o.image.Start(o.flow.Request(Message::Poll),o.batch,o.craft.Receipt(),60,proto,true));f=o.image.Request();f.message=Message::LiveImageAnswer;f.status=Status::LiveImageReady;f.body=o.image.Image();assert(o.image.Answer(f)&&o.image.MarkApplied(f.body)&&o.image.BeginAcknowledge(f.body)); f.message=Message::LiveImageAckAnswer;f.status=Status::LiveImageAcknowledged;assert(o.image.Answer(f));assert(DecodeInventoryImage(o.image.Image(),current)); o.quickslots[0]={1,0};o.quickslots[1]={2,6};o.quickslots[2]={1,225};o.quickslots[3]={1,224}; ch.slots[0]={1,0};ch.slots[1]={2,6};ch.slots[2]={1,225}; // original empty224 clears return o; } int main(){ CHARACTER ch;auto o=ready(ch);assert(releaseReady(&ch,o)); for(auto* flag:{&audited,&online,&actorMatches,&eventsReady,&captureOK,&o.frozen,&o.quickslotsCaptured,&o.published,&o.restore.prepared}){*flag=false;assert(!releaseReady(&ch,o));*flag=true;} o.restore.enabled=true;assert(!releaseReady(&ch,o));o.restore.enabled=false; currentSeal="changed-other-window";assert(!releaseReady(&ch,o));currentSeal=o.appliedSeal; ++current.gold;assert(!releaseReady(&ch,o));--current.gold; ++current.items[0].value.extra[68];assert(!releaseReady(&ch,o));--current.items[0].value.extra[68]; ch.slots[3]={1,224};assert(!releaseReady(&ch,o));ch.slots[3]={}; ch.slots[1].pos++;assert(!releaseReady(&ch,o));ch.slots[1].pos--; ch.missing=35;assert(!releaseReady(&ch,o));ch.missing=-1; // No early start, and no retry may regenerate image/identity after submission. LiveImageFlow unconfirmed;LiveReleaseFlow denied;assert(!denied.Start(unconfirmed,true)&&!denied.Start(o.image,false)); assert(o.release.Start(o.image,releaseReady(&ch,o))&&!o.release.Start(o.image,true));auto request=o.release.Request(); assert(request.message==Message::LiveReleaseRequest&&request.body==o.image.Image()&&o.release.MayRetry()); const auto wire=EncodeHandshake(request);assert(!wire.empty()&&wire==EncodeHandshake(o.release.Request())); auto f=request;f.message=Message::LiveReleaseAnswer;f.status=Status::LiveReleased; for(unsigned field=0;field<7;++field){auto stale=f;switch(field){case 0:++stale.account;break;case 1:++stale.player;break;case 2:++stale.session;break;case 3:++stale.epoch;break;case 4:++stale.cookie;break;case 5:stale.owner=std::string(32,'e');break;case 6:stale.token=std::string(32,'f');break;}assert(!acceptRelease(&ch,o,stale)&&o.release.MayRetry());} auto held=f;held.status=Status::Held;held.body.clear();assert(acceptRelease(&ch,o,held)&&o.release.MayRetry()); assert(acceptRelease(&ch,o,f)&&o.release.State()==LiveReleaseFlow::Released&&!o.release.MayRetry()&&o.flow.BlocksActions()&&!o.restore.enabled); assert(acceptRelease(&ch,o,f)&&!acceptRelease(&ch,o,held)&&o.release.State()==LiveReleaseFlow::Released); // Delayed positive answer must recheck current presentation/asset readiness. ch.slots[0].pos++;assert(!acceptRelease(&ch,o,f)&&o.release.State()==LiveReleaseFlow::Held&&o.flow.BlocksActions()&&!o.restore.enabled);ch.slots[0].pos--; auto altered=ready(ch);assert(altered.release.Start(altered.image,true));auto bad=altered.release.Request();bad.message=Message::LiveReleaseAnswer;bad.status=Status::LiveReleased; InventoryImage conflict;assert(DecodeInventoryImage(bad.body,conflict));++conflict.gold;bad.body=EncodeInventoryImage(conflict);assert(!acceptRelease(&ch,altered,bad)&&altered.release.State()==LiveReleaseFlow::Held); auto disconnected=ready(ch);assert(disconnected.release.Start(disconnected.image,true));online=false;assert(!acceptRelease(&ch,disconnected,f)&&disconnected.release.State()==LiveReleaseFlow::Held&&disconnected.flow.BlocksActions()); online=true;auto invalidated=ready(ch);invalidated.flow.Invalidate(PortCube::ContextChanged);assert(!releaseReady(&ch,invalidated)&&invalidated.flow.BlocksActions()); puts("PASS actual release readiness/acceptance and transport: full image/seal/registry-plan boundary, exact shortcuts, original identity retries, stale/conflicting/late answers, no save-enable/resume/thaw; explicit actor/DB boundary"); }