mission_ember_wipe_test.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package.path = "scripts/?.lua;" .. package.path
  2. local vars, messages, timers, calls = {}, {}, {}, {}
  3. local state = {variable = function(_,key) return vars[key] end}
  4. local context = {}
  5. function context:set_variable(key,value) assert(type(value)=="number" or type(value)=="string" or type(value)=="boolean", "durable variables accept only scalars");vars[key]=value end
  6. function context:clear_variable(key) vars[key]=nil end
  7. function context:start_timer(name,delay) assert(delay==1000);timers[#timers+1]=name end
  8. function context:cancel_timer(name) calls[#calls+1]="cancel:"..name end
  9. function context:slot() return {set_darkness_zone=function(_,args) messages[#messages+1]=args end} end
  10. function context:restart_checkpoint(args)
  11. assert(args.region==(vars["ember.checkpoint.region"] or 64) and args.spawn_set_hash==(vars["ember.checkpoint.hash"] or 0x9C58857A))
  12. calls[#calls+1]=args.release_request and "release" or "arm"
  13. if args.release_request then assert(args.release_request=="77") end
  14. return {value="77"}
  15. end
  16. local resets=0
  17. local landing={region=64,reset_checkpoint=function()
  18. resets=resets+1;calls[#calls+1]="reset";vars["ember.darkness.enabled"]=false
  19. end}
  20. local wipe=require("mission_ember.wipe")({Slot={HARD_WIPE_GLOBALS=1}},landing)
  21. local function life(alive,dead,unknown)
  22. wipe.fireteam(context,state,{alive_count=alive,dead_count=dead,unknown_count=unknown})
  23. end
  24. local function tick(name) return wipe.timer(context,state,{timer_name=name or timers[#timers]}) end
  25. life(0,1,0);assert(#timers==0,"normal death cannot wipe")
  26. vars["ember.darkness.enabled"]=true
  27. life(1,1,0);life(0,1,1);assert(#timers==0,"alive/unknown teammates block wipe")
  28. life(0,2,0);assert(#timers==1 and messages[#messages].wipe_seconds==3)
  29. local old=timers[#timers]
  30. life(0,2,0);assert(#timers==1,"duplicate death cannot restart countdown")
  31. life(1,1,0);assert(not vars["ember.wipe.stage"])
  32. life(0,2,0);assert(timers[#timers]~=old)
  33. assert(not tick(old));assert(vars["ember.wipe.seconds"]==3,"old timer cannot consume next countdown")
  34. tick();assert(messages[#messages].wipe_seconds==2)
  35. tick();assert(messages[#messages].wipe_seconds==1)
  36. tick();assert(messages[#messages].wipe_seconds==0 and wipe.active(state))
  37. assert(calls[#calls]=="arm")
  38. life(0,0,2);assert(wipe.active(state),"native teardown must not cancel committed wipe")
  39. wipe.client_state(context,state,{spawn_state=0});assert(resets==0,"old idle receipt cannot reset encounter")
  40. wipe.client_state(context,state,{spawn_state=1});assert(resets==0)
  41. wipe.client_state(context,state,{spawn_state=2});assert(resets==1)
  42. assert(calls[#calls-1]=="reset" and calls[#calls]=="release","reset outputs must precede native spawn release")
  43. wipe.client_state(context,state,{spawn_state=4});assert(resets==1)
  44. wipe.client_state(context,state,{spawn_state=0});assert(not wipe.active(state))
  45. assert(messages[#messages].enabled==false)
  46. wipe.client_state(context,state,{spawn_state=2});assert(resets==1)
  47. vars["ember.darkness.enabled"]=true
  48. life(0,1,0);tick();tick();tick()
  49. wipe.effect(context,state,{request_key={value="77"},outcome="refused"})
  50. assert(not wipe.active(state) and not vars["ember.wipe.stage"])
  51. assert(messages[#messages].enabled==true,"refused restart must preserve encounter restriction")
  52. print("wipe countdown, teammate revival, stale timers, native handshake order and refusal checks passed")
  53. local laterResets=0
  54. wipe=require("mission_ember.wipe")({Slot={HARD_WIPE_GLOBALS=1}},landing,function()
  55. laterResets=laterResets+1;calls[#calls+1]="later_reset"
  56. end)
  57. vars["ember.checkpoint.region"]=0;vars["ember.checkpoint.hash"]=0xDF59C25C;vars["ember.checkpoint.name"]="reactor"
  58. life(0,1,0);tick();tick();tick()
  59. wipe.client_state(context,state,{spawn_state=2})
  60. assert(laterResets==1 and resets==1 and calls[#calls-1]=="later_reset" and calls[#calls]=="release")
  61. wipe.client_state(context,state,{spawn_state=0});assert(not wipe.active(state))
  62. print("region-zero reactor checkpoint uses the later reset provider and exact authored spawn set")