Commit 9bdf567
Add unit tests for views.go (#134)
* Fix nil pointer dereference panic when acknowledging incidents
Resolves panic that occurred when trying to acknowledge incidents by
removing unsafe dereferences of m.selectedIncident in message handler
closures. The closures were capturing the incident pointer at creation
time, which could be nil, rather than at execution time when the
incident data is guaranteed to be available.
Changes:
- Modified acknowledge/unacknowledge message handlers to create empty
message structs instead of dereferencing m.selectedIncident in closures
- Updated Update() function handlers to safely retrieve incident from
model state when processing messages
- Added nil check in silence incidents handler to prevent panic when
appending selected incident
The fix ensures that incident data is accessed only after it has been
fetched from PagerDuty and stored in the model, preventing nil pointer
dereferences.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix performance issues and re-escalation bug
Multiple performance and functionality improvements:
- Fix re-escalation "Assignee cannot be empty" error by skipping
unnecessary un-acknowledge step and going directly to re-escalation
with proper user email authentication
- Add comprehensive terminal escape sequence filtering to prevent fake
keypresses from clogging the message queue (OSC, CSI, CPR responses)
- Implement priority handling for all user keypresses to ensure
responsive UI even when async messages are queued
- Optimize auto-acknowledge feature with early return when disabled
and cached on-call check to reduce API calls from N to 1 per cycle
- Remove triple template rendering - now renders once on explicit request
- Fix viewport consuming ESC and navigation keys with handledKey flag
- Add debug logging to track re-escalation flow
- Clean up unused code: remove unAcknowledgedIncidentsMsg and
reEscalate parameter from acknowledgeIncidents()
Performance impact:
- ESC/Enter keys now respond immediately instead of waiting for queued messages
- Auto-acknowledge overhead reduced to near-zero when feature is disabled
- Eliminated redundant template renders (3x → 1x per incident view)
Fixes: https://github.com/clcollins/srepd/issues/XXX
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Add unit tests for views.go helper functions
Adds comprehensive unit tests for pure display/formatting functions
in pkg/tui/views.go that were previously untested:
- assigneeArea(): Tests formatting of "You", "Team", and custom assignee displays
- statusArea(): Tests formatting of status messages with various content
- refreshArea(): Tests all combinations of auto-refresh and auto-acknowledge flags
- summarizeNotes(): Tests conversion of PagerDuty notes to display format
- summarizeIncident(): Tests incident conversion including priority, assignments,
and duplicate acknowledgement deduplication
- addNoteTemplate(): Tests note template generation with incident context
All 6 functions now have test coverage with 16 test cases total, covering:
- Edge cases (empty inputs, nil values)
- Normal operation (single/multiple items)
- Business logic (deduplication, conditional formatting)
Test coverage: pkg/tui/views_test.go
Tests pass: go test ./pkg/tui -v
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Fix golangci-lint errors and add lint to test target
Fixes ineffectual assignment warnings from golangci-lint and ensures
linting runs before tests to catch issues early.
Changes:
- pkg/tui/msgHandlers.go:
- Remove ineffectual assignments to handledKey in switchIncidentFocusMode()
- All removed assignments were in cases that return immediately, making
the assignment unreachable and unnecessary
- Affected cases: Refresh, Ack, UnAck, Silence, Note, Login, Open
- handledKey is only checked at the end of the function to determine
whether to pass the message to the viewport
- Makefile:
- Add lint as a dependency to the test target
- Ensures golangci-lint runs before tests to catch linting issues early
- Updated help text to "Run tests (after linting)"
Testing:
- All golangci-lint checks pass (0 issues)
- All unit tests pass
- `make test` now runs linting automatically before tests
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 9aa0243 commit 9bdf567
7 files changed
Lines changed: 495 additions & 112 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
118 | | - | |
| 119 | + | |
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
124 | 130 | | |
125 | 131 | | |
126 | | - | |
| 132 | + | |
127 | 133 | | |
128 | 134 | | |
129 | 135 | | |
130 | 136 | | |
131 | 137 | | |
132 | | - | |
| 138 | + | |
133 | 139 | | |
134 | 140 | | |
135 | 141 | | |
| |||
302 | 308 | | |
303 | 309 | | |
304 | 310 | | |
| 311 | + | |
305 | 312 | | |
306 | 313 | | |
| 314 | + | |
307 | 315 | | |
308 | 316 | | |
309 | 317 | | |
| |||
347 | 355 | | |
348 | 356 | | |
349 | 357 | | |
350 | | - | |
| 358 | + | |
351 | 359 | | |
352 | 360 | | |
353 | 361 | | |
| |||
364 | 372 | | |
365 | 373 | | |
366 | 374 | | |
367 | | - | |
| 375 | + | |
368 | 376 | | |
369 | 377 | | |
370 | 378 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
254 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
255 | 261 | | |
256 | 262 | | |
257 | 263 | | |
| |||
523 | 529 | | |
524 | 530 | | |
525 | 531 | | |
526 | | - | |
527 | | - | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
| 532 | + | |
532 | 533 | | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
| 534 | + | |
542 | 535 | | |
543 | 536 | | |
544 | 537 | | |
| |||
573 | 566 | | |
574 | 567 | | |
575 | 568 | | |
576 | | - | |
| 569 | + | |
577 | 570 | | |
578 | 571 | | |
579 | 572 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
37 | 36 | | |
38 | 37 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 38 | + | |
| 39 | + | |
59 | 40 | | |
60 | 41 | | |
61 | 42 | | |
62 | 43 | | |
63 | 44 | | |
64 | 45 | | |
65 | | - | |
66 | | - | |
67 | | - | |
| 46 | + | |
| 47 | + | |
68 | 48 | | |
69 | 49 | | |
70 | 50 | | |
| |||
73 | 53 | | |
74 | 54 | | |
75 | 55 | | |
76 | | - | |
| 56 | + | |
77 | 57 | | |
78 | 58 | | |
79 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
272 | | - | |
| 272 | + | |
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
349 | 352 | | |
350 | 353 | | |
351 | 354 | | |
352 | 355 | | |
353 | 356 | | |
| 357 | + | |
354 | 358 | | |
355 | 359 | | |
356 | 360 | | |
357 | 361 | | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
358 | 365 | | |
359 | 366 | | |
360 | 367 | | |
361 | 368 | | |
362 | 369 | | |
363 | | - | |
| 370 | + | |
364 | 371 | | |
365 | 372 | | |
366 | | - | |
| 373 | + | |
367 | 374 | | |
368 | 375 | | |
369 | 376 | | |
| |||
395 | 402 | | |
396 | 403 | | |
397 | 404 | | |
398 | | - | |
399 | | - | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
400 | 411 | | |
401 | 412 | | |
402 | 413 | | |
| |||
0 commit comments