883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
65 lines
3.0 KiB
Python
65 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Owned action-ring persistence across untracked targets, rotation and file failure."""
|
|
import json
|
|
import stat
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
|
|
from native_world_trace import WorldTrace
|
|
|
|
|
|
def action(sequence,action_id='1',**fields):
|
|
return dict(sequence=str(sequence),action=action_id,source_target='42',source_mover='7',
|
|
kind=1,spell=20662,opcode=0x12e,status=0,reason=0,spline_id=None,
|
|
source_flags=None,match=0,available=1,facing=None,observed_fields=0,**fields)
|
|
|
|
|
|
class ActionCaptureTests(unittest.TestCase):
|
|
def test_untracked_target_retains_unique_actions_and_exposes_rotated_gap(self):
|
|
trace=WorldTrace(object())
|
|
trace.capture_actions({'actions':[action(2),action(1)]})
|
|
trace.capture_actions({'actions':[action(2),action(5)]})
|
|
changed=action(6)
|
|
changed.update(kind=7,map=1,realm=2)
|
|
trace.capture_actions({'actions':[changed]})
|
|
result=trace.report()['source_actions']
|
|
self.assertIsNone(trace.motion_guid)
|
|
self.assertEqual([int(x['sequence']) for x in result['records']],[1,2,5,6])
|
|
self.assertEqual((result['observed'],result['missing_between_reads']),(4,2))
|
|
self.assertIsNone(result['records'][0]['source_flags'])
|
|
self.assertEqual(result['records'][-1]['map'],1)
|
|
|
|
def test_private_stream_preserves_history_beyond_memory_limit(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path=Path(directory)/'actions.jsonl'
|
|
with patch.object(WorldTrace,'ACTION_RECORD_LIMIT',1):
|
|
trace=WorldTrace(object(),action_log=path)
|
|
trace.capture_actions({'actions':[action(1),action(2)]})
|
|
trace.capture_actions({'actions':[action(2),action(3)]})
|
|
result=trace.report()['source_actions']
|
|
rows=[json.loads(line) for line in path.read_text().splitlines()]
|
|
self.assertEqual([int(row['sequence']) for row in rows],[1,2,3])
|
|
self.assertEqual((result['observed'],result['streamed'],result['memory_dropped']),(3,3,2))
|
|
self.assertEqual(stat.S_IMODE(path.stat().st_mode),0o600)
|
|
self.assertIsNone(result['log_error'])
|
|
|
|
def test_unavailable_legacy_ring_and_failed_stream_are_explicit(self):
|
|
trace=WorldTrace(object())
|
|
trace.capture_actions({'rows':[]})
|
|
self.assertFalse(trace.report()['source_actions']['available'])
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
trace=WorldTrace(object(),action_log=Path(directory)/'absent'/'actions.jsonl')
|
|
trace.capture_actions({'actions':[action(1)]})
|
|
result=trace.report()['source_actions']
|
|
self.assertEqual(result['observed'],1)
|
|
self.assertEqual(result['streamed'],0)
|
|
self.assertEqual(result['log_error'],'FileNotFoundError')
|
|
self.assertEqual(len(result['records']),1)
|
|
|
|
|
|
if __name__=='__main__':unittest.main()
|