-
-
Notifications
You must be signed in to change notification settings - Fork 342
chore: More mock related improvements. #919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning Rate limit exceeded@gdamore has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 19 seconds before requesting another review. β How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. π¦ How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. π Files selected for processing (1)
WalkthroughMock TTY channels switched to mixed-type messages ( Changes
Estimated code review effortπ― 4 (Complex) | β±οΈ ~45 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touchesβ Failed checks (1 warning, 1 inconclusive)
β Passed checks (1 passed)
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. Comment |
Codecov Reportβ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #919 +/- ##
==========================================
+ Coverage 29.40% 30.76% +1.36%
==========================================
Files 41 41
Lines 3731 3787 +56
==========================================
+ Hits 1097 1165 +68
+ Misses 2535 2521 -14
- Partials 99 101 +2 β View full report in Codecov by Sentry. π New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
π§Ή Nitpick comments (1)
mock/mock.go (1)
606-622: Consider potential blocking on channel send.The
WriteQ <- wcqsend on line 611 could block if the channel buffer (128) is full andrun()is not consuming. While the current test patterns callDrain()beforeStop(), consider wrapping this send in a select with the timeout orstopQto prevent indefinite blocking if called in unexpected scenarios.π Optional defensive improvement
func (mt *MockTty) Drain() error { wcq := make(chan struct{}) - mt.WriteQ <- wcq + select { + case mt.WriteQ <- wcq: + case <-mt.stopQ: + return nil + case <-time.After(time.Millisecond * 200): + return nil + } select { case <-wcq: case <-time.After(time.Millisecond * 200): }
π Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
π Files selected for processing (2)
mock/mock.gomock/mock_test.go
π§° Additional context used
π§ Learnings (1)
π Learning: 2025-12-18T02:50:37.669Z
Learnt from: gdamore
Repo: gdamore/tcell PR: 908
File: stdin_unix.go:128-155
Timestamp: 2025-12-18T02:50:37.669Z
Learning: In the tcell Tty interface implementations (stdin_unix.go, tty_unix.go, tty_win.go, tty_plan9.go), the caller is responsible for providing synchronization/mutual exclusion guarantees for method calls like NotifyResize. The Tty implementations themselves do not need internal locking for these methods, as documented in tty.go. The tscreen.go layer handles the synchronization.
Applied to files:
mock/mock_test.go
𧬠Code graph analysis (2)
mock/mock.go (2)
color.go (2)
ColorWhite(73-73)ColorBlack(58-58)attr.go (1)
AttrNone(35-35)
mock/mock_test.go (4)
mock/mock.go (1)
MockTty(42-72)color.go (3)
ColorWhite(73-73)ColorBlack(58-58)ColorRed(67-67)attr.go (2)
AttrNone(35-35)AttrBold(28-28)vt/coord.go (2)
Col(25-25)Row(22-22)
π Additional comments (8)
mock/mock_test.go (3)
24-26: LGTM!Import addition for
vtpackage is appropriate for usingvt.Colandvt.Rowtypes in the cursor movement test.
48-100: LGTM!Well-structured test for DECALN functionality. The test correctly:
- Validates all 15 cells are filled with 'E'
- Checks default attributes in the first phase
- Verifies custom attributes (Red foreground, Bold) are applied in the second phase
- Tests the Start/Stop/Restart cycle
102-148: LGTM!Comprehensive test coverage for cursor movement primitives:
- CUP (H) for absolute positioning
- CUU/CUD (A/B) for vertical movement with boundary clamping
- CUF/CUB (C/D) for horizontal movement with boundary clamping
- CNL/CPL (E/F) for next/previous line with column reset
The
checkPoshelper keeps assertions concise and readable.mock/mock.go (5)
53-54: LGTM!Changing channel types from
chan bytetochan anyenables mixed-type messaging for control signals (checkpoints, drain notifications) alongside byte data. This is a reasonable approach for the mock's internal synchronization needs.
327-334: LGTM!The type switch correctly handles both byte data and checkpoint channels. Closing the checkpoint channel signals drain completion to the waiting caller.
554-591: LGTM!The
Readfunction correctly handles the mixed-type channel:
- Byte data is processed normally
- Checkpoint channels are closed to signal completion
- Boolean drain signals return immediately to unblock callers
636-650: LGTM!Good improvement to make default size initialization idempotent. This allows tests to pre-configure custom dimensions (e.g.,
Rows: 3, Cols: 5) before callingReset()without those values being overwritten.
503-511: LGTM!Clean consolidation of unimplemented escape sequence states (PM, SOS, APC, DCS). They share termination logic (ST byte or ESC+backslash) and safely reset to
stateInit.
This adds testing of the cursor movement primitives, and better synchronization for the drain operation, as well as support for DECALN and a supporting test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
π§Ή Nitpick comments (1)
mock/mock.go (1)
352-352: Consider setting Width field consistently across all Cell assignments.While this PR correctly sets
Width: 1for new Cell assignments (DECALN at line 308, eraseCell at line 145), existing Cell assignments at lines 352 and 420 don't set theWidthfield, leaving it at zero. For consistency and to ensure display width calculations work correctly throughout the mock, consider settingWidthexplicitly for all Cell assignments:
- Line 352: ASCII characters should have
Width: 1- Line 420: UTF-8 characters should have
Widthcalculated fromuniseg.StringWidth(string(r))Note: This is existing code not changed by this PR, so addressing it is optional and can be deferred to a future cleanup.
Example approach for UTF-8 width handling
// At line 420, calculate and set width w := uniseg.StringWidth(string(r)) mt.Cells[ix] = Cell{C: []rune{r}, Fg: mt.Fg, Bg: mt.Bg, Attr: mt.Attr, Width: w} if w > 1 && mt.X < mt.Cols { // ... existing continuation cell logic ... }Also applies to: 420-420
π Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
π Files selected for processing (1)
mock/mock.go
π§° Additional context used
π§ Learnings (2)
π Common learnings
Learnt from: gdamore
Repo: gdamore/tcell PR: 908
File: stdin_unix.go:128-155
Timestamp: 2025-12-18T02:50:37.669Z
Learning: In the tcell Tty interface implementations (stdin_unix.go, tty_unix.go, tty_win.go, tty_plan9.go), the caller is responsible for providing synchronization/mutual exclusion guarantees for method calls like NotifyResize. The Tty implementations themselves do not need internal locking for these methods, as documented in tty.go. The tscreen.go layer handles the synchronization.
π Learning: 2025-12-18T02:50:37.669Z
Learnt from: gdamore
Repo: gdamore/tcell PR: 908
File: stdin_unix.go:128-155
Timestamp: 2025-12-18T02:50:37.669Z
Learning: In the tcell Tty interface implementations (stdin_unix.go, tty_unix.go, tty_win.go, tty_plan9.go), the caller is responsible for providing synchronization/mutual exclusion guarantees for method calls like NotifyResize. The Tty implementations themselves do not need internal locking for these methods, as documented in tty.go. The tscreen.go layer handles the synchronization.
Applied to files:
mock/mock.go
𧬠Code graph analysis (1)
mock/mock.go (2)
color.go (2)
ColorWhite(73-73)ColorBlack(58-58)attr.go (1)
AttrNone(35-35)
π Additional comments (9)
mock/mock.go (9)
34-41: Well-structured Cell type.The new
Celltype properly captures all necessary display cell information including theWidthfield for handling multi-width characters. The struct is cleanly defined and well-documented.
55-56: Channel type change enables synchronization primitives.The change from
chan bytetochan anyforReadQandWriteQis well-motivated, enabling the checkpoint mechanism inDrain()to send control messages alongside data bytes. The type change is consistently applied throughout all I/O handling code.
296-313: DECALN implementation correctly addresses previous feedback.The
handle3Fpmethod properly implements DECALN support:
- State is reset to
stateInitat line 298 (previous review issue resolved).Width: 1is explicitly set at line 308 (previous review issue resolved).- The implementation correctly fills all screen cells with 'E' when no intermediate bytes are present.
332-339: Clean handling of mixed message types in run().The type switch correctly processes both data bytes and checkpoint control messages from
WriteQ. Closing the checkpoint channel signals completion to the waitingDrain()call, enabling proper write synchronization.
483-485: State machine properly integrates ESC-# handling.The state machine correctly integrates the new
state3Fp:
- Transition occurs on '#' in escape state (lines 483-485).
- Intermediate bytes (0x20-0x2F) are buffered, final bytes (0x30-0x3F) trigger
handle3Fp.- State reset is handled within
handle3Fp(line 298), ensuring the state machine returns tostateInitafter processing.- Unexpected bytes trigger proper fallback to
stateInit.Also applies to: 517-525
559-577: Read() correctly handles mixed message types for blocking and non-blocking phases.The implementation properly distinguishes between blocking (first byte) and non-blocking (subsequent bytes) read phases:
- First byte (blocking): Checkpoint and bool signals interrupt the read by returning 0, nil, which is correct for drain synchronization.
- Subsequent bytes (non-blocking): Checkpoints are closed but don't interrupt the read, allowing more data to be collected if available.
This design correctly supports both data transfer and control signaling through the same channel.
Also applies to: 583-590
611-631: Robust checkpoint mechanism for drain synchronization.The
Drain()implementation uses a well-designed checkpoint mechanism:
- Checkpoint sent to
WriteQensures all prior writes are processed.- Waiting with a 200ms timeout prevents indefinite blocking.
- Bool signal to
ReadQinterrupts any pending blocking read.The non-blocking send pattern (select with
stopQ) ensuresDrain()won't deadlock if channels are full or not being actively read.
645-650: Reset() idempotence improves flexibility.The conditional dimension initialization (only setting 24Γ80 defaults when zero) makes
Reset()idempotent and allows test code to specify custom terminal dimensions before initialization. This is a sensible design for test infrastructure.
658-659: Channel initialization consistent with type changes.The initialization of
WriteQandReadQaschan anywith 128-element buffers is consistent with the type declarations and provides appropriate buffering for mock I/O operations.
This adds testing of the cursor movement primitives, and better synchronization for the drain operation, as well as support for DECALN and a supporting test case.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
βοΈ Tip: You can customize this high-level summary in your review settings.