Repository navigation
Description
Summary
A failed pytest terminal assertion can show two identical-looking boxes for a written space. A flight recorder can retain the full output byte stream while missing a resize that determined the final grid. A saved test artifact should let someone inspect the difference and replay that exact sequence on a different machine.
Motivation
A developer looking at CI output has the failure report and its artifacts. The original process may have exited. Existing issues cover the assertion text (#117) and capturing resize events (#127). The missing step is the pytest workflow that writes, identifies, and reopens the failing terminal state.
Evidence
Failure and offline replay from a test that narrowed its terminal before drawing
First difference at row 0, column 4: expected padding, actual ' '
row 0: ' X '
The example starts eight columns wide, shrinks to four, draws the marker, and expands again. Dropping the resize records from the file makes replay report a mismatch. A genuine PTY child can supply the recorded output bytes through the same fixture workflow.
Proposal
Give pytest users an opt-in artifact directory. On failure, preserve the initial geometry, incoming terminal bytes, ordered resizes, final rows and cursor, and the first known assertion difference. Print the file path in the test report. Provide a CLI that replays it offline and signals an incomplete or mismatched capture. Demonstrate a deliberately failing test, replay from another working directory, and a passing test that emits no artifact.
References
Replay must preserve successful input and the failing frame
Two cases hold the replay PR. On #193, term.feed_until(memoryview(b"AXBY")[::2]) writes AB. With --vt-replay-dir enabled, the fixture wrapper then raises TypeError and emits no feed event. With replay disabled the call succeeds. #122 describes the supported buffer contract.
A failure in a worker can also be rethrown after the terminal changes. Run this test with pytest --vt-replay-dir=replays and inspect the resulting artifact.
from concurrent.futures import ThreadPoolExecutor
from libvt.testing import assert_screen
def test_worker(vt_factory):
term = vt_factory(rows=1, cols=6)
term.feed(b"before")
with ThreadPoolExecutor(max_workers=1) as workers:
try:
workers.submit(assert_screen, term, "wanted").result()
finally:
term.feed(b"\rlate!!")The artifact on the published head records late!! and omits the expected row. The assertion observed before and expected wanted. The worker case passed before the change to a context-local observer.
Check feed, a partially consumed feed_until, ordered caller resizes, and the assertion-time frame through the normal fixture and PTY entry points. The component that consumes a buffer knows its logical bytes and consumed extent. The assertion owns the observed and expected frames. #196 tracks distribution of the replay example.
Interleaved feeds and resizes
A candidate operation recorder also exposed an ordering limit. Start at two rows by four columns and consume ABC\x07D. If a callback resizes to two columns between the earlier bytes and D, the live first row can be AD. Recording the resize before the whole feed instead replays two rows, AB and CD, with a different cursor.
The proposed recorder reports the interleaving before accepting further events. The pytest artifact keeps its known input prefix and its actual assertion-time rows, and the CLI exits 1 with the reason the trace is incomplete. Cover a callback that feeds more input as well as one that resizes. Ordinary split input, ordered caller resizes and ordered replay of DECCOLM remain covered. This result is from a local patch on #139.
Activity
tony commentedon Dec 3, 2026
The local replay CLI detected removal of a resize and alteration of a cell style, including the case where visible text was identical. The failing pytest fixture saved the input, geometry changes and screen under
--vt-replay-dir. Related PR #139pytest(feat[replay]): Replay failed screens