Capture current mission, AI, map and administration development

Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
This commit is contained in:
2026-10-13 22:52:53 +02:00
parent a951a96edc
commit 6a667d8deb
8104 changed files with 2124945 additions and 2061 deletions
+190
View File
@@ -0,0 +1,190 @@
"""Actual opt-in native interception witness and fixed lifecycle, with native boundaries doubled."""
from pathlib import Path
import os,re,ast,argparse
from policy_harness import ROOT,body,run
P=Path(os.environ.get('ERR_MOUNTED_INTERCEPT_PROBE',ROOT/'addons/core/Scripts/Game/ERR/40_Chat/ERR_NativeMountedInterceptProbe.c'))
s=P.read_text();code=s[s.index('class ERR_NativeMountedInterceptProbe\n'):s.rindex('#endif')]
code=code.replace('class ERR_NativeMountedInterceptProbe','struct ERR_NativeMountedInterceptProbe').replace('protected ','').replace('ref ','').replace('foreach (','for (').replace('array<','Array<')
for t in ('ERR_NativeMountedInterceptProbe','ERR_GameMode','ERR_HQ','ERR_ConvoyTask','ERR_HQReport','ERR_HQRoute','ERR_ConvoyInterceptOrder','ERR_ConvoyVehicle','ERR_HQBelief'):
code=re.sub(r'\b'+t+r' (?=\w)',t+'* ',code)
code=code.replace('static ERR_NativeMountedInterceptProbe* s_Active;', 'inline static ERR_NativeMountedInterceptProbe* s_Active=null;')
code=code.replace('void ERR_NativeMountedInterceptProbe(', 'ERR_NativeMountedInterceptProbe(')
for v in ('mode','hq','task','vehicle','report','route','order','belief','m_Mode','m_HQ','m_Task','m_First','m_Second','m_Intercept','m_Order'):
code=re.sub(r'\b'+v+r'\.',v+'->',code)
for v in ('Route','Entity'):code=code.replace('->'+v+'.','->'+v+'->')
code=code.replace('task->Vehicles[0].', 'task->Vehicles[0]->').replace('Forces().','Forces()->').replace('Memory().','Memory()->')
for t in ('ERR_NativeConvoyProbe','ERR_NativeMountedInterceptProbe','System','Math','ERR_ForceRules','ERR_GameMode','LogLevel','vector'):code=code.replace(t+'.',t+'::')
code=code.replace('null','nullptr').replace('\n}\n','\n};\n')
code=re.sub(r'\b(bool|int|float|IEntity|SCR_AIGroup|AIWaypoint|[A-Za-z_]\w*\*) (\w+);',r'\1 \2{};',code)
run(r'''
#include <cassert>
#include <cmath>
#include <string>
#include <map>
#include <vector>
using string=std::string;
struct vector{float x=0,y=0,z=0;float&operator[](int i){return i==0?x:i==1?y:z;}vector operator-(vector b){return {x-b.x,y-b.y,z-b.z};}vector operator+(vector b){return{x+b.x,y+b.y,z+b.z};}vector operator*(float f){return{x*f,y*f,z*f};}bool operator==(vector b){return x==b.x&&y==b.y&&z==b.z;}bool operator!=(vector b){return !(*this==b);}float Length(){return std::hypot(x,z);}void Normalize(){float n=Length();x/=n;z/=n;}static float DistanceXZ(vector a,vector b){return(a-b).Length();}};
template<class T>struct Array:std::vector<T>{using std::vector<T>::vector;int Count(){return this->size();}bool IsEmpty(){return this->empty();}void Insert(T v){this->push_back(v);}};
struct Entity{vector position;vector GetOrigin(){return position;}};using IEntity=Entity*;
struct Group{};using SCR_AIGroup=Group*;struct Waypoint{};using AIWaypoint=Waypoint*;
struct ERR_HQReport{IEntity Target=nullptr;Group*Source=nullptr;float ObservedAt=0;vector Position;string TravelMode;int MessageId=0;};
struct ERR_HQRoute{bool Downlink=false,Failed=false,Originated=false,Sending=false;int MessageId=0,Cursor=0;float StartedAt=-1;Array<int>Nodes={1};};
struct ERR_HQBelief{int MessageId=0;float ObservedAt=0;vector Position;};
struct ERR_ConvoyInterceptOrder{int Token=400001,VehicleIndex=0,BeliefId=1,BeliefRevision=2,ReportId=2;Group*Group=nullptr;vector Position{700,0,0};float IssuedAt=10000,ExpiresAt=120000,ObservedAt=0;};
struct Road{Array<vector>points={{0,0,0},{800,0,0}};int Count(){return points.Count();}vector At(int i){return points[i];}};
struct ERR_GameMode;
struct ERR_ConvoyVehicle{struct Entity*Entity=nullptr;struct Group*Group=nullptr;Array<IEntity>Members;bool Released=false,valid=true,InterceptActive=false;int RouteIndex=0,InterceptToken=0;ERR_ConvoyInterceptOrder*InterceptOrder=nullptr;AIWaypoint InterceptWaypoint=nullptr,Waypoint=nullptr;bool CrewValid(ERR_GameMode*){return valid;}};
struct ERR_ConvoyTask{bool Ready=true,Stopped=false;Array<ERR_ConvoyVehicle*>Vehicles;Array<int>Cargo=Array<int>(56);struct Road road;struct Road*Route=&road;};
struct Ledger{int count=6;int Count(){return count;}};
struct ERR_HQ;struct ERR_GameMode:Entity{inline static ERR_GameMode*current=nullptr;ERR_HQ*command=nullptr;Ledger ledger;bool active=true;static ERR_GameMode*Get(){return current;}bool Active(){return active;}ERR_HQ*Command(){return command;}Ledger*Forces(){return &ledger;}};
struct Memory{ERR_HQBelief*belief=nullptr;ERR_HQBelief*Get(IEntity){return belief;}};
struct ERR_HQ{struct Memory memory;int token=400001,queued=0;ERR_HQRoute*next=nullptr;Group*source=nullptr;struct Memory*Memory(){return &memory;}int LogisticsToken(Group*){return token;}ERR_HQRoute*ERR_InterceptFixtureQueue(ERR_HQReport*r){queued++;r->MessageId=queued;r->Source=source;return next;}};
struct ERR_NativeConvoyProbe{inline static bool enabled=true;static bool Enabled(){return enabled;}};
namespace System{std::map<string,string>flags={{"errMountedIntercept","1"}};bool GetCLIParam(string key,string&value){auto it=flags.find(key);if(it==flags.end())return false;value=it->second;return true;}}
namespace Math{int Min(int a,int b){return a<b?a:b;}}
namespace ERR_ForceRules{bool Finite(float n){return std::isfinite(n);}}
namespace LogLevel{const int ERROR=1;}
void Print(string,int=0){}template<class...T>void PrintFormat(string,T...){}
'''.replace('Group*Group=nullptr','struct Group*Group=nullptr').replace('struct struct','struct')+code+r'''
struct Setup{
ERR_GameMode mode;ERR_HQ hq;ERR_ConvoyTask task;ERR_ConvoyVehicle v[6];Entity e[6],actors[6];Group groups[6];ERR_HQReport second;ERR_HQRoute uplink,downlink;ERR_HQBelief belief;ERR_ConvoyInterceptOrder order;Waypoint detour,ordinary;ERR_NativeMountedInterceptProbe*p;
Setup(){ERR_GameMode::current=&mode;mode.command=&hq;hq.source=&groups[1];for(int i=0;i<6;i++){v[i].Entity=&e[i];v[i].Group=&groups[i];v[i].Members={&actors[i]};task.Vehicles.Insert(&v[i]);}p=new ERR_NativeMountedInterceptProbe(&mode,&hq,&task,0);
second.Target=&mode;second.Source=&groups[1];second.MessageId=2;second.ObservedAt=0;second.Position={370,0,0};uplink.MessageId=2;uplink.Cursor=1;uplink.Originated=true;uplink.StartedAt=0;belief.MessageId=2;belief.ObservedAt=0;belief.Position=second.Position;hq.memory.belief=&belief;
downlink.Downlink=true;downlink.StartedAt=10000;downlink.Cursor=0;order.Group=&groups[0];p->m_Second=&second;p->m_SecondRoute=&uplink;p->m_Step=2;v[0].InterceptToken=order.Token;v[0].InterceptOrder=&order;}
void Pending(){p->Pending(&order,&downlink,&task,10000);}void Delivered(){v[0].InterceptActive=true;v[0].InterceptWaypoint=&detour;p->Delivered(&order,&downlink,12000);}
};
int main(){
{Setup f;f.Pending();f.Delivered();f.e[0].position=f.order.Position;f.v[0].InterceptWaypoint=nullptr;assert(f.p->Tick(20000)==0);
f.e[0].position.x+=100;assert(f.p->Tick(23000)==0&&f.p->m_HoldAt<0);f.e[0].position=f.order.Position;assert(f.p->Tick(26000)==0&&!f.p->m_Held);assert(f.p->Tick(30000)==0&&!f.p->m_Held);assert(f.p->Tick(31000)==0&&f.p->m_Held);
f.e[0].position.x+=6;assert(f.p->Tick(32000)==-1);}
assert(ERR_NativeMountedInterceptProbe::Enabled());System::flags["errConvoyCover"]="1";assert(!ERR_NativeMountedInterceptProbe::Enabled());System::flags.erase("errConvoyCover");
{Setup f;f.Pending();assert(f.p->m_Order==&f.order&&!f.p->m_Failed&&f.p->m_DeliveredAt<0);f.Delivered();assert(!f.p->m_Failed&&f.p->m_DeliveredAt==12000);
assert(f.p->Tick(13000)==0);f.e[0].position=f.order.Position;f.v[0].InterceptWaypoint=nullptr;assert(f.p->Tick(20000)==0);assert(f.p->Tick(25000)==0&&f.p->m_Held);
f.v[0].InterceptToken=0;f.v[0].InterceptActive=false;f.v[0].InterceptOrder=nullptr;f.v[0].Waypoint=&f.ordinary;f.hq.token=0;assert(f.p->Tick(120000)==0);f.e[0].position.x+=9;assert(f.p->Tick(121000)==0);f.e[0].position.x+=1;assert(f.p->Tick(122000)==1);
f.p->Stop();assert(f.p->Tick(122001)==-1&&ERR_NativeMountedInterceptProbe::Active()==nullptr);}
for(int bad=0;bad<6;bad++){Setup f;
if(bad==0)f.uplink.Failed=true;
if(bad==1)f.uplink.Cursor=0;
if(bad==2)f.uplink.Originated=false;
if(bad==3)f.uplink.Sending=true;
if(bad==4)f.belief.MessageId=9;
if(bad==5)f.uplink.StartedAt=-1;
f.Pending();assert(f.p->m_Failed&&!f.p->m_Order);}
for(int bad=0;bad<5;bad++){Setup f;f.Pending();
if(bad==0)f.downlink.Failed=true;
if(bad==1)f.downlink.Sending=true;
if(bad==2)f.downlink.Cursor=-1;
if(bad==3)f.downlink.StartedAt=-1;
if(bad==4)f.v[0].Waypoint=&f.ordinary;
f.Delivered();assert(f.p->m_Failed&&f.p->m_DeliveredAt<0);}
{Setup f;f.Pending();f.Delivered();assert(f.p->Tick(120000)==-1&&!f.p->m_Held);} // elapsed expiry cannot substitute for movement
{Setup f;f.Pending();f.Delivered();f.order.Position.x++;assert(f.p->Tick(13000)==-1);} // detached target remains fixed
{Setup f;f.Pending();f.Delivered();f.v[0].Entity=&f.e[1];assert(f.p->Tick(13000)==-1);} // replacement cannot qualify
{Setup f;assert(f.p->CheckTime(239999));assert(!f.p->CheckTime(240000));}
{Setup f;assert(!f.p->CheckTime(-1));}
assert(ERR_NativeMountedInterceptProbe::CompletionText(true).find("synthetic")!=string::npos);
assert(ERR_NativeMountedInterceptProbe::CompletionText(false)=="ERR SMOKE COMPLETE: native convoy readiness, cargo and road movement; explicit fixture reset");
}
''')
assert s.startswith('#ifdef WORKBENCH')
for forbidden in ('ApplyIntercept(', 'ReserveIntercept(', '.Advance(', '.SetOrigin(', 'EnableDamageHandling(', 'TrySpawn', 'Spawn(', 'm_Memory.Ingest', 'm_Memory.Deliver'):
assert forbidden not in s,forbidden
hook=body(P,'protected override void TickMountedIntercept(')
assert hook.count('super.TickMountedIntercept(now)')==1
assert hook.index('proof.Pending')<hook.index('super.TickMountedIntercept(now)')<hook.index('proof.Delivered')
print('PASS: actual native interception witness requires real radio cursor/lineage, original actor identities, fixed movement/hold/expiry/resume and immutable deadline; no movement/delivery injection')
# Execute only argparse declarations and the exact opt-in validation/command AST.
# No filesystem/process setup or native runner is executed.
runner=Path(os.environ.get('ERR_MOUNTED_INTERCEPT_RUNNER',ROOT/'tools/headless_workbench.py'))
tree=ast.parse(runner.read_text());declarations=[];guards=[];flag=None
for node in tree.body:
if isinstance(node,ast.Assign) and any(isinstance(t,ast.Name) and t.id=='p' for t in node.targets):declarations.append(node)
if isinstance(node,ast.Expr) and isinstance(node.value,ast.Call) and isinstance(node.value.func,ast.Attribute) and isinstance(node.value.func.value,ast.Name) and node.value.func.value.id=='p' and node.value.func.attr=='add_argument':declarations.append(node)
if isinstance(node,ast.If) and any(isinstance(n,ast.Attribute) and n.attr=='mounted_intercept' for n in ast.walk(node.test)):
if any(isinstance(n,ast.Call) and isinstance(n.func,ast.Attribute) and n.func.attr=='error' for n in ast.walk(node)):guards.append(node)
elif any(isinstance(n,ast.AugAssign) and isinstance(n.target,ast.Name) and n.target.id=='command' for n in ast.walk(node)):flag=node
assert len(guards)==2 and flag is not None
base=['--compat','/tmp/erri-unused-intercept-prefix','--profile','/tmp/erri-unused-intercept-profile']
def validate(args):
scope={'argparse':argparse,'Path':Path,'__doc__':'test'}
exec(compile(ast.Module(body=declarations,type_ignores=[]),str(runner),'exec'),scope)
scope['a']=scope['p'].parse_args(base+args)
exec(compile(ast.Module(body=guards,type_ignores=[]),str(runner),'exec'),scope)
scope['command']=[];exec(compile(ast.Module(body=[flag],type_ignores=[]),str(runner),'exec'),scope)
return scope['command']
valid=['--mounted-intercept','--smoke','convoy','--project','chat','--rounds','1','--timeout','900']
assert validate(valid)==['-errMountedIntercept','1']
assert validate(['--smoke','convoy','--timeout','600'])==[]
for replacement in [('convoy','victory'),('chat','core'),('1','2'),('900','899')]:
args=valid.copy();args[args.index(replacement[0])]=replacement[1]
try:validate(args)
except SystemExit as error:assert error.code==2
else:raise AssertionError(args)
try:validate(valid+['--convoy-cover'])
except SystemExit as error:assert error.code==2
else:raise AssertionError('conflicting fixture accepted')
convoy=Path(os.environ.get('ERR_CONVOY_PROBE_SOURCE',ROOT/'addons/core/Scripts/Game/ERR/40_Chat/ERR_NativeConvoyProbe.c')).read_text()
assert convoy.index('all five native vehicles drove at least 20m')<convoy.index('m_Intercept = new ERR_NativeMountedInterceptProbe')
assert 'if (m_Step == 5) return m_Intercept.Tick(now);' in convoy
smoke=Path(os.environ.get('ERR_NATIVE_SMOKE_SOURCE',ROOT/'addons/core/Scripts/Game/ERR/40_Chat/ERR_NativeSmoke.c'))
assert 'if (ERR_NativeMountedInterceptProbe.Enabled()) m_ERRSmokeDeadline = GetWorld().GetWorldTime() + 840000;' in smoke.read_text()
assert 'synthetic observations, actual mounted interception radio and physical detour/hold/expiry/resume' in smoke.read_text()
terminal=body(smoke,'if (m_ERRTestConvoy)\n\t\t{').replace('ERR_Phase.DEFEAT','2').replace('GetGame().GetCallqueue().Remove(ERR_SmokeTick);','removed = true;').replace('ERR_StopHQPatrol();','stopped = true;').replace('Print(','Record(').replace('ERR_NativeMountedInterceptProbe.','ERR_NativeMountedInterceptProbe::')
completion=body(P,'static string CompletionText(')
run(r'''
#include <cassert>
#include <string>
using string=std::string;
struct ERR_NativeMountedInterceptProbe{inline static bool enabled=false;static bool Enabled(){return enabled;}
'''+completion+r'''};
struct Smoke{bool m_ERRTestConvoy=true,m_ERRSmokeDone=false,removed=false,stopped=false;int m_ERRSmokeStep=1061;string marker;bool ERR_Check(bool ok,string){return ok;}void Record(string text){marker=text;}void Terminal(int current){
'''+terminal+r'''
}};
int main(){Smoke ordinary;ordinary.Terminal(2);assert(ordinary.m_ERRSmokeDone&&ordinary.marker==ERR_NativeMountedInterceptProbe::CompletionText(false));
ERR_NativeMountedInterceptProbe::enabled=true;Smoke mounted;mounted.Terminal(2);assert(mounted.m_ERRSmokeDone&&mounted.removed&&mounted.stopped&&mounted.marker.find("synthetic")!=string::npos);
Smoke premature;premature.m_ERRSmokeStep=106;premature.Terminal(2);assert(!premature.m_ERRSmokeDone&&premature.marker.empty());}
''')
print('PASS: actual CLI rejects wrong mode/project/rounds/899s/conflict before runtime; valid flag and terminal branch identify synthetic-observation qualification')
# The native fixture is a second modded layer over the production dispatch.
# Missing base hook previously caused a native compile failure; keep its exact
# declaration and the production override in this integration contract.
hqbase=ROOT/'addons/core/Scripts/Game/ERR/10_AI/ERR_HQ.c'
dispatch=ROOT/'addons/core/Scripts/Game/ERR/10_AI/ERR_HQMountedDispatch.c'
assert body(hqbase,'protected void TickMountedIntercept(float now)').endswith('{}')
production=body(dispatch,'protected override void TickMountedIntercept(float now)')
assert 'm_MountedInterceptRoute.Advance(now, m_Journal)' in production
assert 'm_Convoys.ApplyIntercept(m_MountedInterceptTask, order, now)' in production
for declaration in ('protected ref ERR_ConvoyInterceptOrder m_MountedIntercept;',
'protected ref ERR_HQRoute m_MountedInterceptRoute;',
'protected ERR_ConvoyTask m_MountedInterceptTask;',
'protected bool m_MountedInterceptDelivered;'):
assert declaration in dispatch.read_text(),declaration
hook=body(P,'protected override void TickMountedIntercept(').replace('protected override void','void').replace('ref ','').replace('super.TickMountedIntercept','Base::TickMountedIntercept').replace('ERR_NativeMountedInterceptProbe.Active()','ERR_NativeMountedInterceptProbe::Active()')
for t in ('ERR_NativeMountedInterceptProbe','ERR_ConvoyInterceptOrder','ERR_HQRoute'):
hook=re.sub(r'\b'+t+r' (?=\w)',t+'* ',hook)
hook=hook.replace('proof.Pending','proof->Pending').replace('proof.Delivered','proof->Delivered')
run(r'''
#include <cassert>
#include <vector>
struct ERR_ConvoyInterceptOrder{};struct ERR_HQRoute{};struct ERR_ConvoyTask{};
std::vector<int> events;
struct ERR_NativeMountedInterceptProbe{
inline static ERR_NativeMountedInterceptProbe* active=nullptr;ERR_ConvoyInterceptOrder*order=nullptr;ERR_HQRoute*route=nullptr;
static ERR_NativeMountedInterceptProbe*Active(){return active;}
void Pending(ERR_ConvoyInterceptOrder*o,ERR_HQRoute*r,ERR_ConvoyTask*,float){order=o;route=r;events.push_back(1);}
void Delivered(ERR_ConvoyInterceptOrder*o,ERR_HQRoute*r,float){assert(o==order&&r==route&&r);events.push_back(3);}
};
struct Base{
ERR_ConvoyInterceptOrder*m_MountedIntercept=nullptr;ERR_HQRoute*m_MountedInterceptRoute=nullptr;ERR_ConvoyTask*m_MountedInterceptTask=nullptr;bool m_MountedInterceptDelivered=false;int outcome=0,calls=0;
virtual void TickMountedIntercept(float){events.push_back(2);calls++;if(outcome==1){m_MountedInterceptRoute=nullptr;m_MountedInterceptDelivered=true;}if(outcome==-1){m_MountedIntercept=nullptr;m_MountedInterceptRoute=nullptr;}}
};
struct Fixture:Base{
'''+hook+r'''
};
int main(){ERR_NativeMountedInterceptProbe p;ERR_NativeMountedInterceptProbe::active=&p;ERR_ConvoyInterceptOrder o;ERR_HQRoute r;
for(int outcome=-1;outcome<=1;outcome++){events.clear();Fixture f;f.m_MountedIntercept=&o;f.m_MountedInterceptRoute=&r;f.outcome=outcome;f.TickMountedIntercept(2);assert(f.calls==1);assert(events==(outcome==1?std::vector<int>{1,2,3}:std::vector<int>{1,2}));}
events.clear();ERR_NativeMountedInterceptProbe::active=nullptr;Fixture ordinary;ordinary.TickMountedIntercept(2);assert(ordinary.calls==1&&events==std::vector<int>{2});
events.clear();ERR_NativeMountedInterceptProbe::active=&p;Fixture delivered;delivered.m_MountedIntercept=&o;delivered.m_MountedInterceptDelivered=true;delivered.TickMountedIntercept(2);assert(delivered.calls==1&&events==std::vector<int>{2});
}
''')
print('PASS: visible base hook and actual fixture override delegate once; delivery proof uses retained pre-super route only on successful production transition')