Skip to content

feat(sidebar): add resize debug logging#95

Merged
bnema merged 1 commit into
mainfrom
debug/resize-hook-logging
Jun 23, 2026
Merged

feat(sidebar): add resize debug logging#95
bnema merged 1 commit into
mainfrom
debug/resize-hook-logging

Conversation

@bnema

@bnema bnema commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • add verbose debug logging for sidebar resize hooks, baseline capture, work group calculation, weights, skips, and resize errors
  • propagate an optional sidebar logger through the tmux adapter without using context as logger transport
  • regenerate ports mocks for the new sidebar logger port

Verification

  • go test ./internal/app ./internal/adapters/tmuxcli ./internal/ports -count=1
  • make test-go
  • make lint

Runtime check

  • rebuilt binary writes the new resize debug events to the scoped activity log under tmux-session-sidebar/servers/*/activity.log

Summary by CodeRabbit

Release Notes

  • New Features

    • Added debug logging for sidebar resize operations to help diagnose width synchronization issues; when enabled, detailed diagnostics are written to an activity log file.
  • Tests

    • Added tests verifying debug logging works correctly and can be toggled on/off independently.
  • Chores

    • Updated mock implementations to use modern Go syntax.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds an optional file-based resize debug logging capability to the sidebar resize hooks. A new SidebarLoggerPort interface is introduced in internal/ports, implemented by the tmuxcli.Client via a new Logger field and WithSidebarLogger method, and structured debug calls are threaded throughout the rebalance pipeline. The router hooks (syncSidebarWidth, captureSidebarWidthBaseline) are rewritten to fetch a debug-enabled flag from tmux, optionally open activity.log, and pass the logger to the sidebar adapter. All mocks are regenerated with any instead of interface{}.

Changes

Resize Debug Logging via SidebarLoggerPort

Layer / File(s) Summary
SidebarLoggerPort interface, mockery config, and generated mock
internal/ports/multiplexer.go, .mockery.yaml, internal/ports/mocks/mock_sidebar_logger_port.go
Defines the SidebarLoggerPort interface with WithSidebarLogger(LoggerPort) SidebarPort, updates mockery config to internal/ports path and adds SidebarLoggerPort, and adds the generated MockSidebarLoggerPort test double.
Client Logger field, WithSidebarLogger, and rebalance debug logging
internal/adapters/tmuxcli/client.go, internal/adapters/tmuxcli/sidebar_rebalance.go
Adds Logger ports.LoggerPort to Client, adds compile-time SidebarLoggerPort assertion, introduces WithSidebarLogger, and adds resizeDebug helper plus format helpers; threads debug log calls through all skip/success paths in the rebalance pipeline (CaptureAttachedSidebarWidthBaseline, SyncAttachedSidebarWidth, captureSidebarWorkWeights, saveSidebarOpenWorkBaseline, loadSidebarOpenWorkBaseline, applySidebarWorkWeightsBestEffort, sidebarHorizontalWorkGroups).
Router resize hook debug logging and helper rewrites
internal/app/router.go
Rewrites syncSidebarWidth and captureSidebarWidthBaseline to use configuredSidebarWidthAndDebug (fetching width and debug flag together via display-message), optionally open activity.log via withResizeDebugLogger, wrap the sidebar in sidebarWithLogger, and emit structured debug events; removes findSidebarForHook and configuredSidebarWidth, adds parseSidebarTmuxBool, resizeHookTarget, logResizeDebug, and filepath import.
Rebalance and router hook tests
internal/adapters/tmuxcli/sidebar_rebalance_test.go, internal/app/sidebar_layout_test.go
Adds TestSyncAttachedSidebarWidthLogsBaselineAndComputedWidths with a recordingResizeLogger; updates existing hook tests to use display-message tmux stubs; adds four new hook tests covering debug-enabled activity.log assertions, no-file-when-disabled, graceful failure on invalid XDG_STATE_HOME, and logger pass-through to the sidebar port.
Regenerated mocks: interface{}any
internal/ports/mocks/mock_*.go
Bulk regeneration of all mock expecter helper methods using any instead of interface{}; minor parameter renaming in MockQueryPort Return helpers; no behavioral change.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • bnema/tmux-session-sidebar#21: Both PRs modify internal/app/router.go's resize-hook handling, with the current PR extending that path via the new debug/logging flow.
  • bnema/tmux-session-sidebar#85: The current PR's SidebarLoggerPort and mocks wiring directly builds on the port interface refactor and mock regeneration pattern introduced in that PR.

Poem

🐇 A logger hops into the resize flow,
Writing debug crumbs wherever panes grow,
activity.log blooms when the flag is on,
Stays quiet as moonlight when the flag is gone.
Each baseline and weight gets a trail to trace—
No mysterious resize can hide from this place! 🪵

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.23% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(sidebar): add resize debug logging' clearly and concisely describes the main change: adding debug logging functionality to sidebar resize operations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch debug/resize-hook-logging

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/app/router.go`:
- Around line 461-469: The sidebarWithLogger function returns early when logger
is nil, preventing WithSidebarLogger(nil) from being called on mutable
SidebarLoggerPort implementations. This leaves previously attached loggers
active when debug is disabled. Move the nil logger check to after the type
assertion for ports.SidebarLoggerPort, so that WithSidebarLogger is always
invoked with the provided logger value (including nil) on implementations that
support it, ensuring previous logger state is properly cleared.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: becff809-290d-49f2-b006-d606f90b2110

📥 Commits

Reviewing files that changed from the base of the PR and between c58e242 and a3e5126.

📒 Files selected for processing (23)
  • .mockery.yaml
  • internal/adapters/tmuxcli/client.go
  • internal/adapters/tmuxcli/sidebar_rebalance.go
  • internal/adapters/tmuxcli/sidebar_rebalance_test.go
  • internal/app/router.go
  • internal/app/sidebar_layout_test.go
  • internal/ports/mocks/mock_daemon_launcher_port.go
  • internal/ports/mocks/mock_file_watcher_port.go
  • internal/ports/mocks/mock_filesystem_port.go
  • internal/ports/mocks/mock_git_port.go
  • internal/ports/mocks/mock_ipc_client_port.go
  • internal/ports/mocks/mock_ipc_handler.go
  • internal/ports/mocks/mock_ipc_server_port.go
  • internal/ports/mocks/mock_locker_port.go
  • internal/ports/mocks/mock_logger_port.go
  • internal/ports/mocks/mock_process_port.go
  • internal/ports/mocks/mock_query_port.go
  • internal/ports/mocks/mock_release_checker_port.go
  • internal/ports/mocks/mock_sidebar_logger_port.go
  • internal/ports/mocks/mock_sidebar_refresher_port.go
  • internal/ports/mocks/mock_state_store_port.go
  • internal/ports/mocks/mock_system_color_scheme_port.go
  • internal/ports/multiplexer.go

Comment thread internal/app/router.go
Comment on lines +461 to +469
func sidebarWithLogger(sidebar ports.SidebarPort, logger ports.LoggerPort) ports.SidebarPort {
if logger == nil {
return sidebar
}
width := strings.TrimSpace(widthOutput)
if width == "" {
width = "30"
withLogger, ok := sidebar.(ports.SidebarLoggerPort)
if !ok {
return sidebar
}
return withLogger.WithSidebarLogger(logger)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Clear logger state even when debug is disabled.

Line 462 short-circuits on logger == nil, so WithSidebarLogger(nil) is never called. For mutable SidebarLoggerPort implementations, this can leave a previously attached logger active after debug is turned off.

💡 Suggested fix
 func sidebarWithLogger(sidebar ports.SidebarPort, logger ports.LoggerPort) ports.SidebarPort {
-	if logger == nil {
-		return sidebar
-	}
 	withLogger, ok := sidebar.(ports.SidebarLoggerPort)
 	if !ok {
 		return sidebar
 	}
-	return withLogger.WithSidebarLogger(logger)
+	logged := withLogger.WithSidebarLogger(logger)
+	if logged == nil {
+		return sidebar
+	}
+	return logged
 }
📝 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
func sidebarWithLogger(sidebar ports.SidebarPort, logger ports.LoggerPort) ports.SidebarPort {
if logger == nil {
return sidebar
}
width := strings.TrimSpace(widthOutput)
if width == "" {
width = "30"
withLogger, ok := sidebar.(ports.SidebarLoggerPort)
if !ok {
return sidebar
}
return withLogger.WithSidebarLogger(logger)
func sidebarWithLogger(sidebar ports.SidebarPort, logger ports.LoggerPort) ports.SidebarPort {
withLogger, ok := sidebar.(ports.SidebarLoggerPort)
if !ok {
return sidebar
}
logged := withLogger.WithSidebarLogger(logger)
if logged == nil {
return sidebar
}
return logged
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/app/router.go` around lines 461 - 469, The sidebarWithLogger
function returns early when logger is nil, preventing WithSidebarLogger(nil)
from being called on mutable SidebarLoggerPort implementations. This leaves
previously attached loggers active when debug is disabled. Move the nil logger
check to after the type assertion for ports.SidebarLoggerPort, so that
WithSidebarLogger is always invoked with the provided logger value (including
nil) on implementations that support it, ensuring previous logger state is
properly cleared.

@bnema bnema merged commit 07182c2 into main Jun 23, 2026
4 checks passed
@bnema bnema deleted the debug/resize-hook-logging branch June 23, 2026 04:30
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