Files
WoW-Hybrid-gateway/tests/isolated_render_windows_guard_test.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

45 lines
2.3 KiB
Python

from pathlib import Path
import os,sys,tempfile,types,unittest
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
import isolated_item_render_profile as profile
class Part:
def __init__(self,attrs,parents=()):self.attrs=attrs;self.parents=parents
def lstat(self):return types.SimpleNamespace(st_file_attributes=self.attrs)
class WindowsReparseContract(unittest.TestCase):
def test_regular_chain(self):profile._reject_windows_reparse_chain(Part(0x20,[Part(0x10)]))
def test_final_and_parent_reparse_rejected(self):
for path in [Part(0x420),Part(0x20,[Part(0x410)])]:
with self.assertRaisesRegex(ValueError,'reparse'):profile._reject_windows_reparse_chain(path)
def test_missing_windows_attributes_rejected(self):
with self.assertRaises(ValueError):profile._reject_windows_reparse_chain(Part(None))
@unittest.skipUnless(os.name=='nt','actual Windows handle boundary')
class NativeWindowsHeaderContract(unittest.TestCase):
def setUp(self):
self.tmp=tempfile.TemporaryDirectory();self.addCleanup(self.tmp.cleanup);self.root=Path(self.tmp.name)
self.file=self.root/'header.hpp';self.file.write_bytes(b'header\r\nexact\n')
def test_binary_read_preserves_exact_bytes(self):
fd=profile._open_header_nofollow(self.file)
try:self.assertEqual(os.read(fd,64),b'header\r\nexact\n')
finally:os.close(fd)
def test_file_symlink_rejected(self):
alias=self.root/'alias.hpp';alias.symlink_to(self.file)
with self.assertRaises((ValueError,OSError)):profile._open_header_nofollow(alias)
def test_ancestor_symlink_rejected(self):
directory=self.root/'real';directory.mkdir();(directory/'header.hpp').write_bytes(b'header')
alias=self.root/'alias';alias.symlink_to(directory,target_is_directory=True)
with self.assertRaises((ValueError,OSError)):profile._open_header_nofollow(alias/'header.hpp')
class ExactStagingBytes(unittest.TestCase):
def test_original_line_endings_are_preserved(self):
with tempfile.TemporaryDirectory() as directory:
root=Path(directory); header=root/'input.hpp'
for payload in (b'#pragma once\n// LF\n',b'#pragma once\r\n// CRLF\r\n'):
header.write_bytes(payload)
result=profile.stage_render_profile(header,root/'isolated',root/'canonical')
self.assertEqual((root/'isolated'/'staged-item-render-profile.hpp').read_bytes(),payload)
if __name__=='__main__':unittest.main()