Files
EscapistsReintroduced/tests/test_self_epinephrine.py
T

47 lines
3.3 KiB
Python

"""Execute self-injection eligibility and authoritative request throttling."""
from policy_harness import ROOT, body, run
p=ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_SelfEpinephrine.c'
rule=body(p,'static bool Allowed(')
request=body(p,'protected void ERR_RequestSelfEpinephrine(').replace('protected ','').replace('Replication.IsServer()', 'server').replace('GetGame().GetWorld().GetWorldTime()', 'this->now').replace('Rpc(ERR_SelfEpinephrineResponse, result)', 'Reply(result)')
run(r'''
#include <cassert>
#include <string>
struct string:std::string{using std::string::string;bool IsEmpty(){return empty();}};
'''+rule+r'''
struct Controller{bool server=true;float now=0,m_ERRLastSelfEpinephrine=-10000;int calls=0,replies=0;bool eligible=true;
string ERR_TrySelfEpinephrine(){calls++;return eligible?"used":"";}void Reply(string){replies++;}
'''+request+r'''
};
int main(){
for(int bits=0;bits<32;bits++)assert(Allowed(bits&1,bits&2,bits&4,bits&8,bits&16)==(bits==31));
Controller c;c.server=false;c.ERR_RequestSelfEpinephrine();assert(c.calls==0);
c.server=true;c.ERR_RequestSelfEpinephrine();assert(c.calls==1&&c.replies==1);
for(int i=0;i<100;i++){c.ERR_RequestSelfEpinephrine();}assert(c.calls==1);
c.now=999;c.ERR_RequestSelfEpinephrine();assert(c.calls==1);
c.now=1000;c.eligible=false;c.ERR_RequestSelfEpinephrine();assert(c.calls==2&&c.replies==1);
c.eligible=true;c.now=1999;c.ERR_RequestSelfEpinephrine();assert(c.calls==2);
c.now=2000;c.ERR_RequestSelfEpinephrine();assert(c.calls==3&&c.replies==2);
c.now=0;c.ERR_RequestSelfEpinephrine();assert(c.calls==4&&c.replies==3);
}
''')
source=body(p,'protected string ERR_TrySelfEpinephrine(')
assert 'if (!Replication.IsServer()) return "";' in source
assert 'GetControlledEntity()' in source and 'life.Actor == actor' in source and 'mode.Players().CurrentActor(actor) == life' in source
assert 'mode.Settings().Get("selfEpinephrine") == 1' in source
assert 'inventory.Contains(injector)' in source and 'items.Count() > 512' in source
assert source.index('effect.CanApplyEffect(') < source.index('item.ApplyItemEffect(')
assert 'effect.GetDeleteOnUse()' in source and 'Spawn(' not in source and 'SetHealth' not in source
settings=ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_Settings.c'
assert '"selfEpinephrine"' in body(settings,'static array<string> Keys(')
assert 'key == "selfEpinephrine"' in body(settings,'static bool Valid(')
assert 'if (key == "startMode" || key == "selfEpinephrine") return 0;' in body(settings,'static int AddedDefault(')
assert 'selfEpinephrine' not in body(settings,'static bool Randomizable(')
menu=(ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_AdminMenu.c').read_text()
assert 'ERR_AdminSubmit("mission selfepi set " + selfEpi, true)' in menu
assert 'Pair(GetRootWidget(), "SelfEpiOn", "SelfEpiOff", m_SelfEpiState)' in menu
assert 'button.SetEnabled(m_Ready && m_SelfEpiState == 0)' in menu
assert 'button.SetEnabled(m_Ready && m_SelfEpiState == 1)' in menu
config=(ROOT/'addons/core/Configs/ERR/ObserverInput.conf').read_text()
assert 'keyboard:KC_SPACE' in body(ROOT/'addons/core/Configs/ERR/ObserverInput.conf','Action ERR_SelfEpinephrine')
print('PASS: actual self-injection eligibility matrix and authority/rate limit; default-off persistence, authenticated menu route, owned finite injector and native effect/consumption boundaries')