charmbracelet / charmbracelet/vhs

Testing output doesn't capture the viewport when the terminal content scrolls

Open
#657 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
20.9k
Forks
474
Avg merge
4d 1h
Merged PRs (30d)
2

Description

### Describe the bug

When a `.tape` file generates enough output to cause the terminal to scroll, the testing/golden file outputs (`.txt`, `.ascii`, `.test`) fail to capture the current viewport. Instead of saving the visible lines, `vhs` repeatedly writes the lines from the top of the buffer.

This issue likely stems from the `VHS.Buffer` method, which appears to [not account for the scroll position](https://github.com/charmbracelet/vhs/blob/1b7db05a951df65e30eb4fdb9429711e89c7e511/testing.go#L70) when generating the output frame.

### Setup

- OS: macOS (15.6.1)
- Shell: `zsh`, `bash`, `nu`

### To Reproduce

1. Create a file named `testing-output.tape` with the following content.

```tape
Set Height 300
Output testing-output.ascii

Type "echo $LINES"
Enter

Type "seq 10"
Enter

Type "echo foo"
Enter
```

2. Run the tape file: `vhs testing-output.tape`.
3. Inspect the generated `testing-output.ascii` file.

### Actual Behavior

The output file captures the top of the buffer at each step. The final frames are missing the scrolled output from `seq 10` and the subsequent `echo foo` command.

```
────────────────────────────────────────────────────────────────────────────────
> echo $LINES

────────────────────────────────────────────────────────────────────────────────
> echo $LINES
6
>

────────────────────────────────────────────────────────────────────────────────
> echo $LINES
6
> seq 10

────────────────────────────────────────────────────────────────────────────────
> echo $LINES
6
> seq 10
1
2
3
────────────────────────────────────────────────────────────────────────────────
> echo $LINES
6
> seq 10
1
2
3
────────────────────────────────────────────────────────────────────────────────
> echo $LINES
6
> seq 10
1
2
3
────────────────────────────────────────────────────────────────────────────────
```

### Expected Behavior

The output file should accurately reflect the terminal's viewport at each step, showing the content as it scrolls into view, e.g., like this:

```
────────────────────────────────────────────────────────────────────────────────
> echo $LINES

────────────────────────────────────────────────────────────────────────────────
> echo $LINES
6
>

────────────────────────────────────────────────────────────────────────────────
> echo $LINES
6
> seq 10

────────────────────────────────────────────────────────────────────────────────
6
7
8
9
10
>
────────────────────────────────────────────────────────────────────────────────
6
7
8
9
10
> echo foo
────────────────────────────────────────────────────────────────────────────────
8
9
10
> echo foo
foo
>
────────────────────────────────────────────────────────────────────────────────
```

Contributor guide

Open the contributing guide

Research direction

Start in testing.go at the linked VHS.Buffer method and reproduce the issue with the provided testing-output.tape steps. Verify that generated .txt, .ascii, and .test outputs reflect the terminal's current viewport after scrolling, including the final seq 10 and echo foo frames.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.