自动化与脚本
本地无外部服务驱动交互式 CLI/TUI:做 UX 检查…
用可重复的本地 harness(优先仓库自带脚本,否则用 tmux、PTY 探针或 Node/Bun inspector)驱动交互式 CLI 或 TUI,以确定性输入捕获屏幕、复现问题并做性能剖析。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 49/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 85/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 60/100 ×0.15
适用场景
本地无外部服务驱动交互式 CLI/TUI通用
解决思路
- 识别待测试命令和最小可复现工作区。
- 发现现有本地 harness:package scripts、e2e tests、demo recorders、expect scripts 或 PTY helpers。
- 若没有 harness,在隔离的终端会话中启动 CLI,并使用确定性环境变量。
- 交互前先捕获当前屏幕。
- 一次只发送一个动作:文本、Enter、方向键、Escape、Ctrl-C、resize。
- 等待具体屏幕模式或提示符出现后,再执行下一个动作。
- 保存 transcript 和任何 profile 产物。
- 干净地杀掉会话。
- Harness 选项:优先使用 repo-native harness,即已签入的脚本,因为它们了解应用的启动、环境和提示符。
- Harness 选项:使用 tmux 管理会话,通过 capture-pane、send-keys、attach/detach 操作。
- Harness 选项:当 tmux 不可用时,用短的 Python、Node 或 Expect 脚本做 PTY probe。
- Harness 选项:使用 Node 或 Bun inspector 做 CPU profile、heap snapshot 和 live evaluation。
- Harness 选项:当用户要求 demo 时,使用 repo-local demo 工具或 asciinema 兼容工具录制终端。
- 最小 tmux harness:SESSION="cli-harness-$(date +%s)";tmux new-session -d -s "$SESSION" -- <command-under-test>;tmux capture-pane -pt "$SESSION";tmux send-keys -t "$SESSION" "help" Enter;tmux capture-pane -pt "$SESSION";tmux kill-session -t "$SESSION"。
- 对 Node CLI:NODE_OPTIONS="--inspect=127.0.0.1:0" tmux new-session -d -s "$SESSION" -- <node-cli-command>;读取终端输出以找到 inspector URL,然后按需使用 Chrome DevTools 兼容工具做 profiling。
- 最小 PTY harness:当仓库没有 tmux 或 demo harness 且需要确定性等待时,使用 PTY 脚本;除非用户要求添加可复用测试,否则保持临时。
- 最小 PTY harness 脚本: ```python import os import pty import select import subprocess import time master_fd, slave_fd = pty.openpty() proc = subprocess.Popen( ["<command>", "<arg>"], stdin=slave_fd, stdout=slave_fd, stderr=slave_fd, close_fds=True, ) os.close(slave_fd) deadline = time.time() + 30 buffer = b"" while time.time() < deadline: ready, _, _ = select.select([master_fd], [], [], 0.25) if not ready: continue chunk = os.read(master_fd, 4096) buffer += chunk if b"<ready text>" in buffer: os.write(master_fd, b"help\n") break print(buffer.decode(errors="replace")) proc.terminate() os.close(master_fd) ```
- 如果 CLI 需要更丰富的终端控制,使用 pty.fork() 或现有 PTY 库。
- Profiling 启动回归:在同一机器、环境和命令下,捕获 baseline 和 treatment 的启动耗时。
- Profiling 慢操作:启动 CPU profile,执行操作,停止 profile,并比较 top self-time functions。
- Profiling 内存泄漏:若可用则强制 GC,取 heap snapshot,重复执行操作,再次强制 GC,再取一次 snapshot。
- Profiling 挂起:在中断前捕获屏幕、active handles/resources,以及 stack/CPU sample。
- Guardrail:优先使用确定性等待而非 sleeps;如果必须 sleep,解释原因。
- Guardrail:不要向受控会话发送凭据或破坏性命令。
- Guardrail:除非仓库已经有 testing/demo harness,否则把 harness 放在 /tmp。
- Guardrail:不要硬编码来自另一个仓库的路径;让命令适配当前仓库的脚本和运行时。
- Guardrail:清理 tmux sessions、临时目录、inspector 进程和 demo 产物,除非用户要求保留。
适用边界 · 注意事项
- 需要向受控会话发送凭据或执行破坏性命令时。
- 无法在本地启动隔离终端会话、PTY 或 tmux,且仓库也没有自带 harness 时。
- 期望依赖外部服务或云托管环境来驱动交互式 CLI/TUI 时。