Skip to content

tests: add test for dec private mode parser#914

Merged
gdamore merged 1 commit into
mainfrom
test-input-parser-private-mode
Dec 20, 2025
Merged

tests: add test for dec private mode parser#914
gdamore merged 1 commit into
mainfrom
test-input-parser-private-mode

Conversation

@gdamore

@gdamore gdamore commented Dec 19, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Tests
    • Added end-to-end tests verifying decoding of terminal private-mode responses across multiple scenarios, including per-case subtests and timeouts, ensuring reported mode state (mode, support, enabled, permanent) is correct and considered usable.
    • Extended special-keys coverage with an additional key/mapping case to validate modifier handling and key recognition.

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

@coderabbitai

coderabbitai Bot commented Dec 19, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a new test function TestDecPrivateModeResponse and a small extension to TestSpecialKeys in input_test.go; also imports fmt. Tests validate decoding of DEC private-mode response sequences into event fields (Mode, Supported, Enabled, Permanent) using per-case subtests and a receive timeout.

Changes

Cohort / File(s) Summary
Tests — private mode response & special keys
input_test.go
Added fmt import; extended TestSpecialKeys with a "CSI-1-$" case mapping to KeyHome with ModShift; added TestDecPrivateModeResponse with per-case subtests asserting decoded event fields (Mode, Supported, Enabled, Permanent) and using a channel receive timeout to validate produced events.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify numeric Mode values and boolean expectations in each test case.
  • Check fmt usage and subtest naming.
  • Confirm timeout behavior and event consumption to avoid flaky tests.

Possibly related PRs

Poem

🐰 I nibbled CSI crumbs with care,

Sequences turned to modes in the air,
Events hopped out, tidy and bright,
Assertions danced through the night,
A carrot nod for tests that pass 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'tests: add test for dec private mode parser' directly and specifically describes the main change: adding a new test function (TestDecPrivateModeResponse) to validate decoding of private mode responses in the tcell package.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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 test-input-parser-private-mode

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

codecov Bot commented Dec 19, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 19.74%. Comparing base (af992da) to head (895b705).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #914      +/-   ##
==========================================
+ Coverage   18.56%   19.74%   +1.17%     
==========================================
  Files          39       39              
  Lines        3404     3404              
==========================================
+ Hits          632      672      +40     
+ Misses       2717     2681      -36     
+ Partials       55       51       -4     

☔ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between af992da and ce1a08c.

📒 Files selected for processing (1)
  • input_test.go (2 hunks)
🧰 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:

  • input_test.go
🧬 Code graph analysis (1)
input_test.go (1)
event.go (1)
  • Event (23-26)
🔇 Additional comments (2)
input_test.go (2)

21-21: LGTM!

The fmt import is correctly added and used for formatting subtest names.


633-648: LGTM!

The event handling, type assertions, and timeout logic follow the established patterns in this test file. The error messages provide clear context for debugging test failures.

Comment thread input_test.go
Comment thread input_test.go
Comment on lines +630 to +631
// Send null in initial state
ip.ScanUTF8([]byte(tt.bytes))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Incorrect comment (copy-paste artifact).

The comment says "Send null in initial state" but the code actually sends the private mode escape sequence bytes. This appears to be copied from TestInputStateTransitions.

🔎 Proposed fix
-			// Send null in initial state
+			// Send private mode response sequence
 			ip.ScanUTF8([]byte(tt.bytes))
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Send null in initial state
ip.ScanUTF8([]byte(tt.bytes))
// Send private mode response sequence
ip.ScanUTF8([]byte(tt.bytes))
🤖 Prompt for AI Agents
In input_test.go around lines 630 to 631, the inline comment "Send null in
initial state" is incorrect (copy-paste artifact) because the code calls
ip.ScanUTF8([]byte(tt.bytes)) with a private mode escape sequence; update the
comment to accurately describe the action (e.g., "Send private mode escape
sequence bytes" or similar) or remove the misleading comment so it matches the
actual test input being sent.

@gdamore gdamore force-pushed the test-input-parser-private-mode branch from ce1a08c to 6157216 Compare December 19, 2025 19:03

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
input_test.go (2)

614-626: Unused usable field in test struct.

The usable field is defined in each test case but never used in assertions (line 638 compares pev.usable() to tt.result.usable() instead of tt.usable). Either remove the unused field or update the assertion to compare against tt.usable.

🔎 Proposed fix: Update assertion to use tt.usable
-					if pev.usable() != tt.result.usable() {
-						t.Errorf("Private mode usability wrong %v != %v", pev.usable(), tt.result.usable())
+					if pev.usable() != tt.usable {
+						t.Errorf("Private mode usability wrong %v != %v", pev.usable(), tt.usable)
 					}

Or alternatively, remove the unused field from the test table:

 	tests := []struct {
 		bytes  string
 		result eventPrivateMode
-		usable bool
 	}{
-		{"\x1b[?1001;0$y", eventPrivateMode{Mode: privateMode(1001)}, false},
-		{"\x1b[?1004;2$y", eventPrivateMode{Mode: privateMode(1004), Supported: true}, true},
-		{"\x1b[?7;1$y", eventPrivateMode{Mode: privateMode(7), Supported: true, Enabled: true}, true},
-		{"\x1b[?25;3$y", eventPrivateMode{Mode: privateMode(25), Supported: true, Enabled: true, Permanent: true}, false},
-		{"\x1b[?12;4$y", eventPrivateMode{Mode: privateMode(12), Supported: true, Enabled: false, Permanent: true}, false},
-		{"\x1b[?990;$y", eventPrivateMode{Mode: privateMode(990), Supported: false}, false},
-		{"\x1b[?991$y", eventPrivateMode{Mode: privateMode(991), Supported: false}, false},
+		{"\x1b[?1001;0$y", eventPrivateMode{Mode: privateMode(1001)}},
+		{"\x1b[?1004;2$y", eventPrivateMode{Mode: privateMode(1004), Supported: true}},
+		{"\x1b[?7;1$y", eventPrivateMode{Mode: privateMode(7), Supported: true, Enabled: true}},
+		{"\x1b[?25;3$y", eventPrivateMode{Mode: privateMode(25), Supported: true, Enabled: true, Permanent: true}},
+		{"\x1b[?12;4$y", eventPrivateMode{Mode: privateMode(12), Supported: true, Enabled: false, Permanent: true}},
+		{"\x1b[?990;$y", eventPrivateMode{Mode: privateMode(990), Supported: false}},
+		{"\x1b[?991$y", eventPrivateMode{Mode: privateMode(991), Supported: false}},
 	}

632-633: Incorrect comment (copy-paste artifact).

The comment states "Send null in initial state" but the code sends private mode escape sequence bytes. This appears to be copied from TestInputStateTransitions.

🔎 Proposed fix
-			// Send null in initial state
+			// Send private mode response sequence
 			ip.ScanUTF8([]byte(tt.bytes))
🧹 Nitpick comments (1)
input_test.go (1)

628-628: Consider more descriptive subtest names.

The current subtest naming "case #%d" is generic. Consider including the mode number or expected outcome for better test identification.

💡 Example improvement
-		t.Run(fmt.Sprintf("case #%d", i), func(t *testing.T) {
+		t.Run(fmt.Sprintf("mode_%d_%s", tt.result.Mode, tt.bytes), func(t *testing.T) {

Or even simpler:

-	for i, tt := range tests {
-		t.Run(fmt.Sprintf("case #%d", i), func(t *testing.T) {
+	for _, tt := range tests {
+		t.Run(fmt.Sprintf("mode_%d", tt.result.Mode), func(t *testing.T) {
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce1a08c and 6157216.

📒 Files selected for processing (1)
  • input_test.go (3 hunks)
🧰 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:

  • input_test.go
🧬 Code graph analysis (1)
input_test.go (3)
key.go (2)
  • KeyHome (348-348)
  • ModShift (317-317)
event.go (1)
  • Event (23-26)
tscreen.go (2)
  • t (387-426)
  • t (313-360)
🔇 Additional comments (3)
input_test.go (3)

21-21: LGTM!

The fmt import is appropriately used for formatting subtest names.


561-561: LGTM!

The new test case for the rxvt CSI-1-$ sequence is correctly structured and consistent with the existing test cases.


613-652: Well-structured test for DEC private mode responses.

The test function correctly validates decoding of DEC private mode response sequences into eventPrivateMode structures. The test cases cover various combinations of supported/enabled/permanent states, and the timeout mechanism is appropriate.

@gdamore gdamore force-pushed the test-input-parser-private-mode branch from 6157216 to 2bb583b Compare December 19, 2025 19:25

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
input_test.go (1)

633-634: Incorrect comment (copy-paste artifact).

The comment says "Send null in initial state" but the code sends a DEC private mode escape sequence (tt.bytes). This appears to be copied from TestInputStateTransitions at line 492.

🔎 Proposed fix
-			// Send null in initial state
+			// Send private mode response sequence
 			ip.ScanUTF8([]byte(tt.bytes))
🧹 Nitpick comments (1)
input_test.go (1)

642-644: Consider improving error message clarity.

The error message only shows the mode number but not the expected vs actual field values, making debugging more difficult.

🔎 Proposed enhancement
 			if *pev != tt.result {
-				t.Errorf("Private mode mismatch for %d", tt.result.Mode)
+				t.Errorf("Private mode mismatch for mode %d: got %+v, want %+v", tt.result.Mode, *pev, tt.result)
 			}
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6157216 and 2bb583b.

📒 Files selected for processing (1)
  • input_test.go (3 hunks)
🧰 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:

  • input_test.go
🧬 Code graph analysis (1)
input_test.go (2)
key.go (2)
  • KeyHome (348-348)
  • ModShift (317-317)
event.go (1)
  • Event (23-26)
🔇 Additional comments (2)
input_test.go (2)

21-21: LGTM!

The fmt import is correctly added and used at line 629 for formatting subtest names.


561-561: LGTM!

The new test case for rxvt-specific Home key with Shift modifier is consistent with the existing test structure.

Comment thread input_test.go
@gdamore gdamore force-pushed the test-input-parser-private-mode branch from 2bb583b to 895b705 Compare December 20, 2025 01:32

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
input_test.go (1)

633-633: Incorrect comment (copy-paste artifact).

The comment says "Send null in initial state" but the code actually sends DEC private mode escape sequence bytes from tt.bytes.

🔎 Proposed fix
-			// Send null in initial state
+			// Send DEC private mode response sequence
 			ip.ScanUTF8([]byte(tt.bytes))
🧹 Nitpick comments (1)
input_test.go (1)

643-643: Consider improving error message informativeness.

The error message only prints the mode number, making it harder to debug failures. Consider showing both the expected and actual structs.

🔎 Proposed improvement
 				if *pev != tt.result {
-					t.Errorf("Private mode mismatch for %d", tt.result.Mode)
+					t.Errorf("Private mode mismatch: got %+v, want %+v", *pev, tt.result)
 				}
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2bb583b and 895b705.

📒 Files selected for processing (1)
  • input_test.go (3 hunks)
🧰 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:

  • input_test.go
🧬 Code graph analysis (1)
input_test.go (2)
key.go (2)
  • KeyHome (348-348)
  • ModShift (317-317)
event.go (1)
  • Event (23-26)
🔇 Additional comments (3)
input_test.go (3)

21-21: LGTM!

The fmt import is used for fmt.Sprintf at line 629 in the new test function.


561-561: LGTM!

The new test case for the rxvt-specific CSI-1-$ sequence is consistent with the existing test structure and properly maps to KeyHome with ModShift.


614-627: LGTM! Good test coverage for DEC private mode responses.

The test table covers various response scenarios effectively: unsupported modes, supported-only, enabled modes, and permanent modes. The structure follows the established pattern in the file.

@gdamore gdamore merged commit e90d698 into main Dec 20, 2025
15 checks passed
@gdamore gdamore deleted the test-input-parser-private-mode branch December 20, 2025 01:44
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