883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
68 lines
4.1 KiB
Python
68 lines
4.1 KiB
Python
"""Exercise actual Wire classification with the current generated hidden set."""
|
|
from pathlib import Path
|
|
import os,subprocess,tempfile,unittest
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
class HiddenClassifyIntegration(unittest.TestCase):
|
|
def test_production_filter_excludes_hidden_only_after_valid_canonical_reply(self):
|
|
source=(ROOT/'native/wine_pipe_host.c').read_text();start=source.index('static int spell_barrier_classify(void){');end=source.index('static int spell_barrier_flush(void){',start);actual=source[start:end]
|
|
self.assertIn('gw_spellbook_hidden_for_initial_gate(fields[1])',actual)
|
|
fixture=r'''
|
|
#include <assert.h>
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include "world_locator_fifo.h"
|
|
#include "gateway/spellbook_hidden_readiness.h"
|
|
#define GW_WIRE_DB_REPLY_MISSING 1u
|
|
struct gw_pipe_spell_locator_barrier {uint32_t classified,known_count,required_count;};
|
|
struct gw_wire_call {uint32_t operation,input_bytes,capacity,required;const unsigned char*input;unsigned char*output;};
|
|
static struct gw_pipe_spell_locator_barrier gw_wire_spell_locator_barrier;
|
|
static uint32_t spell_barrier_known[8],spell_barrier_required[8];
|
|
static unsigned char spell_barrier_metadata[128];
|
|
static int reply_status=1,failed;
|
|
static void init(struct gw_wire_call*c,uint32_t operation){memset(c,0,sizeof(*c));c->operation=operation;}
|
|
static void put32(unsigned char*p,uint32_t v){for(unsigned i=0;i<4;++i)p[i]=(unsigned char)(v>>(8*i));}
|
|
static int call(struct gw_wire_call*c){
|
|
assert(c->operation==GW_WIRE_DB_REPLY_MISSING&&c->input_bytes==12&&c->capacity==sizeof(spell_barrier_metadata));
|
|
assert(gw_world_locator_u32(c->input)==0xe111669eu);
|
|
uint32_t id=gw_world_locator_u32(c->input+4);assert(id>0);
|
|
memset(c->output,0,c->capacity);put32(c->output,0xe111669eu);put32(c->output+4,id);c->output[12]=(unsigned char)(reply_status<<5);
|
|
c->required=reply_status==1?18u:17u;put32(c->output+13,c->required-17u);
|
|
if(reply_status==1)c->output[17]=0; /* bounded valid canonical payload; no native submission */
|
|
return 0;
|
|
}
|
|
static int spell_barrier_fail(uint32_t reason){assert(reason==5);failed++;return -1;}
|
|
'''
|
|
fixture+=actual
|
|
fixture+=r'''
|
|
static void reset(uint32_t a,uint32_t b,uint32_t c){
|
|
memset(&gw_wire_spell_locator_barrier,0,sizeof(gw_wire_spell_locator_barrier));
|
|
memset(spell_barrier_required,0,sizeof(spell_barrier_required));
|
|
gw_wire_spell_locator_barrier.known_count=3;spell_barrier_known[0]=a;spell_barrier_known[1]=b;spell_barrier_known[2]=c;failed=0;reply_status=1;
|
|
}
|
|
int main(void){
|
|
/* These are real frozen relationships: hidden12727, nonhidden passive3127,
|
|
* and the custom visible Concussion51602 first-login target. */
|
|
assert(gw_spellbook_hidden_for_initial_gate(12727));
|
|
assert(!gw_spellbook_hidden_for_initial_gate(3127));
|
|
assert(!gw_spellbook_hidden_for_initial_gate(51602));
|
|
reset(3127,12727,51602);
|
|
assert(spell_barrier_classify()==1&&!failed);
|
|
assert(gw_wire_spell_locator_barrier.classified==3&&gw_wire_spell_locator_barrier.required_count==2);
|
|
assert(spell_barrier_required[0]==3127&&spell_barrier_required[1]==51602);
|
|
/* A canonical-valid ID without generated metadata stays required. */
|
|
reset(3127,12727,0x7fffffffu);assert(!gw_spellbook_hidden_for_initial_gate(0x7fffffffu));
|
|
assert(spell_barrier_classify()==1&&!failed&&gw_wire_spell_locator_barrier.required_count==2);
|
|
assert(spell_barrier_required[1]==0x7fffffffu);
|
|
/* Hidden membership never bypasses an invalid canonical status. */
|
|
reset(12727,3127,51602);reply_status=2;
|
|
assert(spell_barrier_classify()==-1&&failed==1&&gw_wire_spell_locator_barrier.classified==0&&gw_wire_spell_locator_barrier.required_count==0);
|
|
return 0;
|
|
}
|
|
'''
|
|
with tempfile.TemporaryDirectory(prefix='hidden-classify-',dir=ROOT/'runtime')as tmp:
|
|
out=Path(tmp);(out/'fixture.c').write_text(fixture)
|
|
subprocess.run(['cc','-std=c11','-Wall','-Wextra','-Werror','-fsanitize=address,undefined','-fno-omit-frame-pointer','-I',str(ROOT/'native'),'-I',str(ROOT/'include'),str(out/'fixture.c'),'-o',str(out/'fixture')],check=True)
|
|
subprocess.run([str(out/'fixture')],env={**os.environ,'ASAN_OPTIONS':'detect_leaks=1'},check=True)
|
|
if __name__=='__main__':unittest.main()
|