tui-tests

GitHub

指导如何为 GitButler 的 Ratatui TUI 编写、运行和断言测试,涵盖测试文件位置、驱动交互模式及快照比对方法。

.agents/skills/tui-tests/SKILL.md gitbutlerapp/gitbutler

Trigger Scenarios

添加或修改 TUI 相关测试 调试终端界面渲染问题

Install

npx skills add gitbutlerapp/gitbutler --skill tui-tests -g -y
More Options

Non-standard path

npx skills add https://github.com/gitbutlerapp/gitbutler/tree/master/.agents/skills/tui-tests -g -y

Use without installing

npx skills use gitbutlerapp/gitbutler@tui-tests

指定 Agent (Claude Code)

npx skills add gitbutlerapp/gitbutler --skill tui-tests -a claude-code -g -y

安装 repo 全部 skill

npx skills add gitbutlerapp/gitbutler --all -g -y

预览 repo 内 skill

npx skills add gitbutlerapp/gitbutler --list

SKILL.md

Frontmatter
{
    "name": "tui-tests",
    "description": "Use when adding or modifying tests for one of GitButler's Ratatui TUIs"
}

Where tests live

  • Main TUI tests: crates/but/src/command/legacy/status/tui/tests/
  • Test harness/helpers: crates/but/src/tui/test_utils.rs and crates/but/src/command/legacy/status/tui/tests/utils.rs
  • Snapshots: crates/but/src/command/legacy/status/tui/tests/snapshots/

Basic pattern

#[test]
fn describes_behavior_under_test() {
    let env = Sandbox::init_scenario_with_target_and_default_settings("one-stack").unwrap();
    env.setup_metadata(&["A"]).unwrap();

    let mut tui = test_status_tui(env);

    tui.input_then_render(KeyCode::Down)
        .assert_rendered_term_svg_eq(file!["snapshots/describes_behavior_under_test_001.svg"]);
}

Driving the TUI

Useful input examples:

tui.input_then_render(None);                                       // render without inputs
tui.input_then_render('j');                                        // single char input
tui.input_then_render(KeyCode::Down);                              // special key
tui.input_then_render(Shift('j'));                                 // keys with shift
tui.input_then_render(Control('j'));                               // keys with control
tui.input_then_render([KeyCode::Down, KeyCode::Down]);             // multiple keys from array
tui.input_then_render("commit message text");                      // multiple keys from string
tui.reload();                                                      // reload state after making external changes

Assertions

Generally prefer

  • assert_current_line_eq(str![...]) for cursor/selection behavior.
  • assert_rendered_term_svg_eq(file!["snapshots/test_function_name_001.svg"]) for everything else.

Generally you should include one assert_rendered_term_svg_eq per logical group of inputs, to catch bad states early.

Be careful using assert_rendered_contains and assert_rendered_not_contains since they might lead to false positives. They're intended to use while iterating on a test where snapshots would cause too much churn.

Read crates/but/src/tui/test_utils.rs and crates/but/src/command/legacy/status/tui/tests/utils.rs for more specialized assertions.

You're not allowed to add new kinds of assertions to crates/but/src/tui/test_utils.rs or crates/but/src/command/legacy/status/tui/tests/utils.rs. Rely entirely on the existing assertions.

Running tests

  • cargo test -p but <test-name> to run one test.
  • SNAPSHOTS=overwrite cargo test -p but <test-name> to run and update snapshots.
  • cargo test -p but tui to run all tui tests. Do this after changing things.

If a test fails the output will include the rendered state of the test backend. This can be used when iterating on a test as a way of inspecting the state.

Version History

  • caf1f22 Current 2026-08-20 12:36

Same Skill Collection

.agents/skills/cli-commands/SKILL.md
.agents/skills/lite-render-perf/SKILL.md
.agents/skills/lite-screenshots/SKILL.md
crates/but-agentlog/skill/SKILL.md
crates/but/skill/SKILL.md

Metadata

Files
0
Version
d5d97c8
Hash
91b84775
Indexed
2026-08-20 12:36

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-09-04 04:23
浙ICP备14020137号-1 $bản đồ khách truy cập$