883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
55 lines
4.3 KiB
C++
55 lines
4.3 KiB
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#include "quest_status_refresh.hpp"
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
static void check(bool b){if(!b)throw Error("quest status refresh fixture");}
|
|
static NativeQuestTranslation::Binding actor(uint64_t generation,bool questgiver=true,uint8_t kind=3){
|
|
NativeQuestTranslation::Binding a;a.generation=generation;a.questgiver=questgiver;a.kind=kind;a.modern[0]=1;return a;
|
|
}
|
|
int main(){try{
|
|
QuestStatusRefresh refresh;NativeQuestTranslation::Bindings visible{{10,actor(1)},{11,actor(1,false)},{12,actor(1,true,4)}};
|
|
refresh.observe(visible);check(refresh.pending.size()==1);auto q=refresh.next(visible);check(q&&q->guid==10&&q->generation==1);
|
|
refresh.observe(visible);check(refresh.pending.size()==1); // Not again for the same generation.
|
|
// Sizing failure is non-mutating: it stays queued until actual send.
|
|
check(refresh.next(visible).has_value()&&refresh.inflight_count==0);refresh.sent_pending(*q);
|
|
// A native single query to the same GUID overlaps the refresh.
|
|
refresh.sent({10,1,false});check(refresh.inflight_count==2);
|
|
check(refresh.accept(10,visible));check(refresh.accept(10,visible));check(refresh.inflight_count==0);
|
|
// A native single query may validly target a non-questgiver actor.
|
|
refresh.sent({11,1,false});check(refresh.accept(11,visible));
|
|
// Old replies cannot attach to a recreated actor even when its GUID is reused.
|
|
refresh.sent({10,1,true});visible[10]=actor(2);refresh.observe(visible);check(!refresh.accept(10,visible));
|
|
auto next=refresh.next(visible);check(next&&next->guid==10&&next->generation==2);
|
|
// A removed/not-yet-published actor cannot cause a queued Source query.
|
|
visible.erase(10);check(!refresh.next(visible));visible[10]=actor(3);refresh.observe(visible);
|
|
next=refresh.next(visible);check(next&&next->generation==3);refresh.sent_pending(*next);
|
|
check(refresh.accept(10,visible));check(refresh.accept(99,visible)); // Genuine unsolicited Source behavior unchanged.
|
|
// Even unchanged actor generations cannot rebind a reply across SELF recreation.
|
|
refresh.sent({10,3,true});refresh.reset_presentation();check(!refresh.accept(10,visible));
|
|
refresh.observe(visible);next=refresh.next(visible);check(next&&next->guid==10);refresh.sent_pending(*next);check(refresh.accept(10,visible));
|
|
// A real quest change invalidates status freshness without recreating the
|
|
// NPC. Preserve both tokenless old requests until their replies arrive.
|
|
refresh.sent({10,3,true});refresh.sent({10,3,false});
|
|
const auto before_change=refresh.epoch;refresh.invalidate();refresh.observe(visible);
|
|
check(refresh.epoch==before_change+1&&refresh.inflight_count==2&&!refresh.next(visible));
|
|
// Repeated changes coalesce unsent work, but cannot erase old reply debt.
|
|
refresh.invalidate();refresh.observe(visible);check(refresh.pending.size()==1);
|
|
// A blocked GUID must not block a different visible questgiver.
|
|
visible[20]=actor(1);refresh.observe(visible);next=refresh.next(visible);
|
|
check(next&&next->guid==20);refresh.sent_pending(*next);check(refresh.accept(20,visible));
|
|
check(!refresh.accept(10,visible)&&refresh.inflight_count==1&&!refresh.next(visible));
|
|
check(!refresh.accept(10,visible)&&refresh.inflight_count==0);
|
|
next=refresh.next(visible);check(next&&next->guid==10&&next->epoch==refresh.epoch);
|
|
refresh.sent_pending(*next);check(refresh.inflight_count==1&&refresh.accept(10,visible));
|
|
visible.erase(20);
|
|
check(refresh.can_send(QuestStatusRefresh::Limit));check(!refresh.can_send(QuestStatusRefresh::Limit+1));
|
|
// Multiple native queries and refresh replies share real Source replies;
|
|
// the existing fanout assembler remains responsible for native packet shape.
|
|
NativeQuestTranslation qt;Bytes empty;auto prepared=qt.client(0x3f0034,empty,visible);qt.sent(prepared);
|
|
for(auto [id,gen]:prepared.status_multiple)refresh.sent({id,gen,false});
|
|
Bytes reply;le(reply,10,8);le(reply,5,4);check(refresh.accept(10,visible));
|
|
auto translated=qt.receive(0x183,reply,visible,70,0,[](uint32_t,const Bytes&){return Bytes{};});
|
|
check(translated&&translated->size()==1&&translated->front().opcode==0x670011);
|
|
std::cout<<"Quest refresh publication, overlap, generation, bounds and fanout passed\n";return 0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|