chore: ffmpeg record log, remove legacy video fields, logging fallback
All checks were successful
Publish Python Package to Gitea / publish (push) Successful in 19s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-02 14:29:01 +08:00
parent 4a9d358aef
commit fb2fa20306
3 changed files with 128 additions and 63 deletions

View File

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"""RpaVideoSessionffmpeg 桌面录屏,无 Playwright record_video_dir"""
"""RpaVideoSessionffmpeg 桌面录屏。"""
from __future__ import annotations
import asyncio
@@ -28,18 +28,17 @@ class TestRpaVideoSession(unittest.TestCase):
batch_id="batch_test",
)
self.assertFalse(session.enabled)
self.assertIsNone(session.record_video_dir)
self.assertIsNone(session.output_video_path)
self.assertIsNone(session.capture_path)
summ = session.summary()
self.assertFalse(summ["enabled"])
self.assertIsNone(summ["path"])
self.assertIsNone(summ["capture_path"])
self.assertIsNone(summ["record_log_path"])
finally:
if old is not None:
os.environ["OPENCLAW_RECORD_VIDEO"] = old
config.reset_cache()
def test_enabled_paths_no_raw_video(self) -> None:
def test_enabled_paths_use_ffmpeg_capture(self) -> None:
os.environ["OPENCLAW_RECORD_VIDEO"] = "1"
try:
with tempfile.TemporaryDirectory() as tmp:
@@ -51,12 +50,16 @@ class TestRpaVideoSession(unittest.TestCase):
title="接收订单",
)
self.assertTrue(session.enabled)
self.assertIsNone(session.record_video_dir)
self.assertTrue(
session._capture_path.replace("\\", "/").endswith(
"/rpa-artifacts/exmail_20260602_120000/capture.mp4"
)
)
self.assertTrue(
session._ffmpeg_record_log_path.replace("\\", "/").endswith(
"/rpa-artifacts/exmail_20260602_120000/logs/ffmpeg-record.log"
)
)
self.assertTrue(
session._planned_output.replace("\\", "/").startswith(
tmp.replace("\\", "/") + "/videos/"
@@ -87,15 +90,17 @@ class TestRpaVideoSession(unittest.TestCase):
batch_id="batch_ff",
) as video:
video.add_step("测试步骤")
with patch.object(video, "finalize", return_value=None):
pass
asyncio.run(_run())
with patch.object(RpaVideoSession, "finalize", return_value=None):
asyncio.run(_run())
self.assertTrue(mock_popen.called)
cmd = mock_popen.call_args[0][0]
self.assertIn("ffmpeg", cmd)
self.assertIn("gdigrab", cmd)
self.assertIn("desktop", cmd)
kwargs = mock_popen.call_args[1]
self.assertIsNot(kwargs.get("stderr"), os.devnull)
finally:
os.environ.pop("OPENCLAW_RECORD_VIDEO", None)
config.reset_cache()
@@ -106,16 +111,6 @@ class TestRpaVideoSession(unittest.TestCase):
try:
with tempfile.TemporaryDirectory() as tmp:
config.reset_cache()
async def _run() -> None:
async with RpaVideoSession(
skill_slug="receive-order",
skill_data_dir=tmp,
batch_id="batch_no_ff",
):
pass
asyncio.run(_run())
session = RpaVideoSession(
skill_slug="receive-order",
skill_data_dir=tmp,
@@ -138,10 +133,11 @@ class TestRpaVideoSession(unittest.TestCase):
batch_id="batch_warn",
)
asyncio.run(session.finalize())
self.assertIn("ffmpeg_capture_missing", session.warnings)
self.assertTrue(
any("ffmpeg_capture_missing" in w for w in session.warnings)
)
self.assertIn("record_log=", "".join(session.warnings))
self.assertIsNone(session.output_video_path)
summ = session.summary()
self.assertIsNone(summ["path"])
finally:
os.environ.pop("OPENCLAW_RECORD_VIDEO", None)
config.reset_cache()