66 lines
4.5 KiB
Python
66 lines
4.5 KiB
Python
#!/usr/bin/env python3
|
|
"""One isolated integration boundary: actual roster wire + PUBLIC CMake selection."""
|
|
import hashlib,json,os,subprocess,sys,tempfile,unittest
|
|
from pathlib import Path
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0,str(ROOT/'ops'))
|
|
from isolated_item_render_profile import stage_render_profile,compiler_flags
|
|
|
|
HEADER='''#pragma once
|
|
#include <cstdint>
|
|
namespace gateway::item_render_profile {
|
|
struct Definition {uint32_t source_display,inventory_type,native_display,render_item;};
|
|
inline const Definition* find(uint32_t display,uint32_t type){
|
|
static constexpr Definition row{0x123456,1,0x99887766,123};
|
|
return display==row.source_display && type==row.inventory_type ? &row : nullptr;
|
|
}
|
|
inline uint32_t modified_appearance(uint32_t){return 0;}
|
|
}
|
|
'''
|
|
PROBE='''#include "gateway/roster_translation.hpp"
|
|
#include <algorithm>
|
|
int main(){
|
|
gateway::Character c{};c.guid=4509;c.name="Isolated";c.race=1;c.cls=1;c.gender=0;c.level=1;
|
|
c.visuals[0]={0x123456,1};auto result=gateway::forever_roster({c},{},false);
|
|
// Independent VisualItemInfo wire: ItemID0,transmog0,subclass0,type1,
|
|
// exact selected native display0x99887766,enchant0,secondary0,sheath0.
|
|
gateway::Bytes expected{0,0,0,0,0,0,0,0,0,1,0x66,0x77,0x88,0x99,0,0,0,0,0,0,0,0,0};
|
|
return std::search(result.begin(),result.end(),expected.begin(),expected.end())==result.end();
|
|
}
|
|
'''
|
|
class IsolatedRenderProfileTest(unittest.TestCase):
|
|
def test_isolated_override_reaches_real_roster_and_all_linked_consumers(self):
|
|
canonical=ROOT/'include/gateway/item_render_profile.hpp';before=hashlib.sha256(canonical.read_bytes()).hexdigest()
|
|
with tempfile.TemporaryDirectory(prefix='render-override-test-',dir=ROOT/'build') as folder:
|
|
root=Path(folder);header=root/'reviewed profile.hpp';header.write_text(HEADER);output=root/'codec';default=ROOT/'build/forever-schema'
|
|
self.assertIsNone(stage_render_profile(None,output,default));self.assertFalse(output.exists())
|
|
with self.assertRaisesRegex(ValueError,'separate'):stage_render_profile(header,default,default)
|
|
alias=root/'symlink.hpp';alias.symlink_to(header)
|
|
with self.assertRaises(ValueError):stage_render_profile(alias,output,default)
|
|
with self.assertRaises(ValueError):stage_render_profile(root,output,default)
|
|
fifo=root/'fifo.hpp';os.mkfifo(fifo)
|
|
with self.assertRaises(ValueError):stage_render_profile(fifo,output,default)
|
|
profile=stage_render_profile(header,output,default);staged=Path(profile['compiled_header']['path'])
|
|
self.assertEqual(staged.read_text(),HEADER);self.assertEqual(profile['header']['sha256'],hashlib.sha256(HEADER.encode()).hexdigest())
|
|
self.assertEqual(json.loads((output/'item-render-profile-override.json').read_text()),profile)
|
|
header.write_text('// original changed AFTER snapshot\n')
|
|
self.assertEqual(staged.read_text(),HEADER)
|
|
probe=root/'probe.cpp';probe.write_text(PROBE);exe=root/'probe'
|
|
result=subprocess.run(['c++','-std=c++20','-O0','-ffunction-sections','-fdata-sections','-I'+str(ROOT/'include'),*compiler_flags(profile),str(ROOT/'src/roster_translation.cpp'),str(ROOT/'src/character_creation.cpp'),str(ROOT/'src/protocol.cpp'),str(probe),'-Wl,--gc-sections','-lcrypto','-lz','-o',str(exe)],capture_output=True,text=True,timeout=60)
|
|
self.assertEqual(result.returncode,0,result.stderr)
|
|
self.assertEqual(subprocess.run([str(exe)],capture_output=True,timeout=5).returncode,0)
|
|
header.write_text(HEADER);cmake=root/'cmake'
|
|
result=subprocess.run(['cmake','-S',str(ROOT),'-B',str(cmake),'-DGW_ITEM_RENDER_PROFILE_HEADER='+str(header),'-DCMAKE_EXPORT_COMPILE_COMMANDS=ON'],capture_output=True,text=True,timeout=60)
|
|
self.assertEqual(result.returncode,0,result.stderr)
|
|
commands=json.loads((cmake/'compile_commands.json').read_text())
|
|
for source in ('src/roster_translation.cpp','native/inventory_translation.cpp'):
|
|
rows=[row for row in commands if Path(row['file'])==ROOT/source]
|
|
self.assertTrue(rows,source)
|
|
for row in rows:
|
|
self.assertIn('GW_ITEM_RENDER_PROFILE_HEADER',row['command']);self.assertIn(str(cmake/'staged-item-render-profile.hpp'),row['command'])
|
|
receipt=json.loads((cmake/'item-render-profile-override.json').read_text());self.assertEqual(receipt['header']['sha256'],profile['header']['sha256'])
|
|
help_result=subprocess.run([sys.executable,str(ROOT/'ops/build_forever_create.py'),'--help'],capture_output=True,text=True,timeout=5)
|
|
self.assertEqual(help_result.returncode,0);self.assertIn('--render-profile-header',help_result.stdout)
|
|
self.assertEqual(hashlib.sha256(canonical.read_bytes()).hexdigest(),before)
|
|
if __name__=='__main__':unittest.main()
|