from __future__ import annotations import json import unittest from pathlib import Path from app.automation import get_node_definitions from app.schemas import AutomationWorkflowSaveRequest VIDEO_WORKFLOW_KEYS = { "youtube-home-random-video", "youtube-channel-latest-video", "bilibili-home-random-video", "bilibili-up-latest-video", "douyin-random-video", "douyin-next-video", } class VideoWorkflowTemplateTest(unittest.TestCase): def test_video_action_node_is_registered(self) -> None: definitions = {item["type"]: item for item in get_node_definitions()} self.assertIn("browser.video_action", definitions) self.assertIn("vision.locate_element", definitions) self.assertEqual( definitions["browser.video_action"]["params"]["action"]["options"], [ "youtube_home_random", "youtube_channel_latest", "bilibili_home_random", "bilibili_up_latest", "douyin_random", "douyin_next", ], ) def test_video_workflow_templates_match_schema(self) -> None: workflow_dir = Path(__file__).resolve().parents[2] / "workflows" checked_keys = set() for path in workflow_dir.glob("*.workflow.json"): raw = json.loads(path.read_text(encoding="utf-8")) if raw.get("workflow_key") not in VIDEO_WORKFLOW_KEYS: continue workflow = AutomationWorkflowSaveRequest.model_validate(raw) checked_keys.add(str(workflow.workflow_key)) # 视频模板使用真实页面截图定位,再把坐标交给鼠标节点点击。 self.assertTrue(any(node.type == "vision.locate_element" for node in workflow.nodes)) self.assertTrue(any(node.type == "mouse.click" for node in workflow.nodes)) self.assertEqual(workflow.settings.get("return"), {"node_id": "locate"}) self.assertEqual(checked_keys, VIDEO_WORKFLOW_KEYS) if __name__ == "__main__": unittest.main()