# -*- coding: utf-8 -*- """ Screencast 录制入口(模板)。 启用方式: 复制为 record_screencast.py,修改 SKILL_SLUG 和 SUBTITLE_SCRIPT,然后运行: python tests/desktop/record_screencast.py 依赖: 1. pip install mss 2. 系统已安装 ffmpeg 并在 PATH 中 3. jiangchang-platform-kit 在本机可推断路径(见 _bootstrap 逻辑) 4. MEDIA_ASSETS_ROOT 环境变量指向 media-assets 仓库(或使用默认路径) """ from __future__ import annotations import os import sys from pathlib import Path def _bootstrap_screencast() -> None: """将 jiangchang-platform-kit/tools 加入 sys.path,使 screencast 包可导入。""" here = Path(__file__).resolve() skill_root = here.parents[2] # tests/desktop → tests → skill_root workspace_root = skill_root.parent # skill_root → workspace open_claw_root = workspace_root.parent # workspace → OpenClaw candidates = [ workspace_root / "jiangchang-platform-kit" / "tools", open_claw_root / "jiangchang-platform-kit" / "tools", Path(r"D:\AI\jiangchang-platform-kit") / "tools", ] env_kit = os.environ.get("JIANGCHANG_KIT_ROOT", "") if env_kit: candidates.insert(0, Path(env_kit) / "tools") for cand in candidates: if (cand / "screencast" / "__init__.py").exists(): if str(cand) not in sys.path: sys.path.insert(0, str(cand)) return raise RuntimeError( "找不到 jiangchang-platform-kit/tools/screencast。\n" "请设置 JIANGCHANG_KIT_ROOT 环境变量,或将 platform-kit 放在 workspace 同级目录。" ) _bootstrap_screencast() from screencast import run_screencast # noqa: E402 # ============================================================ # ↓↓↓ 复制后只需修改这两处 ↓↓↓ # ============================================================ SKILL_SLUG = "your-skill-slug" # 替换为本技能 slug SUBTITLE_SCRIPT = [ # (pytest stdout 中出现的关键词, 字幕显示文案) ("ensure_app_running", "正在启动匠厂智能体平台..."), ("wait_gateway_ready", "网关就绪,准备发起任务"), ("ask(", "向助手发送指令..."), ("PASSED", "任务完成"), ] # ============================================================ if __name__ == "__main__": _here = Path(__file__).resolve() skill_root = _here.parents[2] test_file = str(_here.parent / "test_desktop_smoke.py") output_dir = str(_here.parent / "artifacts" / "recordings") run_screencast( skill_slug=SKILL_SLUG, subtitle_script=SUBTITLE_SCRIPT, pytest_args=[test_file, "-v", "-s"], output_dir=output_dir, )