Skip to content

Continued progress on emulation and tests thereof#929

Merged
gdamore merged 3 commits intomainfrom
emulate
Dec 28, 2025
Merged

Continued progress on emulation and tests thereof#929
gdamore merged 3 commits intomainfrom
emulate

Conversation

@gdamore
Copy link
Copy Markdown
Owner

@gdamore gdamore commented Dec 27, 2025

Summary by CodeRabbit

  • Tests

    • Added comprehensive unit tests for terminal cursor movement, bell character handling, device attributes, cursor position reporting, and private mode querying.
  • Performance

    • Increased input buffer capacity for improved handling of terminal sequences.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 27, 2025

📝 Walkthrough

Walkthrough

This pull request adds comprehensive unit tests for terminal mock implementations (covering cursor movement, bell signals, device attributes, cursor reporting, and private modes) and adjusts buffer handling logic in the emulator, including increasing channel capacity and refining CSI parameter extraction.

Changes

Cohort / File(s) Summary
Terminal Mock Tests
mock/term_test.go
Adds 7 new test functions validating terminal behaviors: TestCursorMovement (CSI sequences and window sizing), TestDECALN (DEC rendering), TestBell (bell character counting), TestPrimaryDA (device attributes), TestExtendedAttr (terminal identification), TestCursorReport (cursor position reporting), TestPrivateModes (private mode querying and toggling).
Emulator Core Logic
vt/emulate.go
Increases readQ channel buffer from 32 to 128; adds inline comments to case branches; updates CSI condition from b < '?' to b <= '?'; replaces em.inBuf.ReadByte() with em.inBuf.Truncate(l - 1) for buffer trimming.
Mode Test Suite
vt/mode_test.go
New test file validating PmAutoMargin string representations (Enable, Disable, Query, Reply) across multiple mode states.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Buffers grow and channels widen,
CSI conditions shift and lighten,
Bells do ring, cursors dance with glee,
Terminal tests: a harmony! 🔔✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title is vague and generic, using the phrase 'Continued progress' without specifying what was actually implemented or changed in the codebase. Make the title more specific by describing the actual changes, such as 'Add comprehensive emulation tests for terminal features' or 'Expand VT emulator with cursor and mode handling tests'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch emulate

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a132a5 and 76dac75.

📒 Files selected for processing (3)
  • mock/term_test.go
  • vt/emulate.go
  • vt/mode_test.go
🧰 Additional context used
🧬 Code graph analysis (2)
mock/term_test.go (2)
mock/term.go (1)
  • NewMockTerm (111-117)
mock/backend.go (2)
  • MockOptSize (164-164)
  • MockOptColors (169-169)
vt/mode_test.go (1)
vt/mode.go (6)
  • PmAutoMargin (27-27)
  • ModeNA (66-66)
  • ModeOn (67-67)
  • ModeOff (68-68)
  • ModeOnLocked (69-69)
  • ModeOffLocked (70-70)
🔇 Additional comments (12)
vt/mode_test.go (1)

19-45: LGTM! Comprehensive test coverage for PmAutoMargin.

The test validates all string representations (Enable, Disable, Query, Reply) with proper escape sequences for DEC private mode 7 (automargin). The coverage includes all ModeStatus values, ensuring the formatting is correct.

vt/emulate.go (4)

68-68: LGTM! Increased input buffering capacity.

The readQ buffer size increase from 32 to 128 provides more headroom for queuing data from the emulator to the application, which should improve performance when handling bursts of input.


127-141: LGTM! Improved code documentation.

The inline comments clarify the control character handling (ESC, BEL, BS, NL, VT, FF, CR), making the code more readable without changing behavior.


425-428: LGTM! Bug fix to include '?' as a valid CSI prefix.

Changing the condition from b < '?' to b <= '?' correctly includes '?' (0x3F) as a CSI prefix character, which is essential for DEC private mode sequences like DECSET/DECRST (e.g., \x1b[?7h for automargin). The comprehensive tests in mock/term_test.go validate this works correctly.


430-434: LGTM! Bug fix for removing trailing intermediate bytes.

Replacing em.inBuf.ReadByte() with em.inBuf.Truncate(l - 1) correctly removes the trailing intermediate byte from the CSI parameter buffer. The previous code would have removed a byte from the front of the buffer instead of the end, which was incorrect.

mock/term_test.go (7)

63-108: LGTM! Comprehensive cursor movement test coverage.

The test thoroughly validates cursor movement commands (CUP, CUU, CUD, CUF, CUB, CNL, CPL) including boundary conditions where movements exceed window dimensions. The position checks after each operation ensure correct clamping behavior.


110-158: LGTM! Thorough DECALN test coverage.

The test validates the DEC Alignment Test (DECALN) sequence in three scenarios: basic fill, after clearing, and with attributes (bold). Each scenario correctly verifies that all cells contain the expected character ('E' or ' ') with the correct attributes.


160-177: LGTM! Simple and effective bell test.

The test validates that BEL characters (0x07) correctly increment the bell counter, verifying basic beeper functionality.


179-216: LGTM! Complete primary device attributes testing.

The test validates primary device attributes (DA) using both the modern CSI c and legacy ESC Z sequences. The response format checks correctly verify the VT level and attribute reporting.


218-244: LGTM! Extended attributes test validates terminal identification.

The test correctly verifies the extended terminal identification response to CSI > q, checking for proper DCS formatting and the expected terminal name/version string.


246-280: LGTM! Cursor position reporting test with proper coordinate translation.

The test validates cursor position reporting (DSR, CSI 6n) and correctly handles the translation between 0-based internal coordinates and 1-based reported coordinates. Testing both static position and position after movement ensures the feature works reliably.


282-307: LGTM! Comprehensive private mode testing.

The test thoroughly validates DECRQM (query), DECSET (enable), and DECRST (disable) for private modes, including:

  • Automargin mode (7) state transitions (on→off→on)
  • Invalid mode handling (1919 returns status 0=NA)
  • Correct response format for all queries

The expected response string correctly matches the sequence of operations.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 27, 2025

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.05%. Comparing base (4a132a5) to head (76dac75).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
vt/emulate.go 60.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #929      +/-   ##
==========================================
+ Coverage   30.40%   32.05%   +1.65%     
==========================================
  Files          32       32              
  Lines        3029     3029              
==========================================
+ Hits          921      971      +50     
+ Misses       2052     2003      -49     
+ Partials       56       55       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant