Refactor: Eliminate session-aware logging if/else duplication with helper functions#944
Draft
Refactor: Eliminate session-aware logging if/else duplication with helper functions#944
Conversation
…lper functions Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three logging functions in
internal/launcher/log_helpers.gocontained identical if/else branching to handle session-aware vs non-session logging, resulting in ~30 lines of duplicated conditional logic.Changes
Added inline helper functions following the repository's pattern of placing helpers in the same file:
tripleLogInfoWithSession(): Encapsulates file/stdout/debug logging with session branchingdebugLogWithSession(): Handles debug-only logging with session branchingRefactored 3 functions to use helpers, eliminating duplicate branching:
logLaunchStart()logTimeoutError()logLaunchSuccess()Example
Before:
After:
Log output remains identical. Session-aware branching logic is now centralized in reusable helpers.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/tmp/go-build2301924257/b275/launcher.test /tmp/go-build2301924257/b275/launcher.test -test.testlogfile=/tmp/go-build2301924257/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true --abbrev-ref HEAD /usr/bin/base64 s#^versions/##; s#^v#node/v#; \#system# !d; 1_ nfig/composer/ve--abbrev-ref base64 -d ache/go/1.25.7/x64/pkg/tool/linux_amd64/vet git /usr/bin/dirname --abbrev-ref HEAD x_amd64/link dirname(dns block)/tmp/go-build2359477819/b275/launcher.test /tmp/go-build2359477819/b275/launcher.test -test.testlogfile=/tmp/go-build2359477819/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true NVM_DIR=/home/REDACTED/.nvm -v /usr/bin/gcc index($0, NVM/usr/libexec/docker/cli-plugins/docker-compose git de/node/bin/git gcc -###�� -x c(dns block)/tmp/go-build4148141444/b275/launcher.test /tmp/go-build4148141444/b275/launcher.test -test.testlogfile=/tmp/go-build4148141444/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ; git /usr/bin/git --abbrev-ref HEAD cal/bin/git git rev-�� --abbrev-ref HEAD docker-buildx --abbrev-ref HEAD ache/uv/0.10.2/x86_64/git tf "%s%s", sep, $0; sep=RS }(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build2301924257/b260/config.test /tmp/go-build2301924257/b260/config.test -test.testlogfile=/tmp/go-build2301924257/b260/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true --abbrev-ref HEAD(dns block)/tmp/go-build726308285/b264/config.test /tmp/go-build726308285/b264/config.test -test.testlogfile=/tmp/go-build726308285/b264/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.short=true /usr/bin/git base64 64/pkg/tool/linux_amd64/compile 64/pkg/tool/linusleep git /usr/bin/git 64/pkg/tool/linux_amd64/compile dock�� else if (a[i] --abbrev-ref git /usr/bin/grep --abbrev-ref HEAD /usr/bin/base64 tf "%s%s", sep, $0; sep=RS }(dns block)/tmp/go-build758265063/b260/config.test /tmp/go-build758265063/b260/config.test -test.testlogfile=/tmp/go-build758265063/b260/testlog.txt -test.paniconexit0 -test.timeout=10m0s t \t base64 tnet/tools/git ache/go/1.25.7/xecho git /usr/bin/tail base64 -d it tail /usr/bin/tail 1 base64 /usr/bin/base64 tail(dns block)nonexistent.local/tmp/go-build2301924257/b275/launcher.test /tmp/go-build2301924257/b275/launcher.test -test.testlogfile=/tmp/go-build2301924257/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true --abbrev-ref HEAD /usr/bin/base64 s#^versions/##; s#^v#node/v#; \#system# !d; 1_ nfig/composer/ve--abbrev-ref base64 -d ache/go/1.25.7/x64/pkg/tool/linux_amd64/vet git /usr/bin/dirname --abbrev-ref HEAD x_amd64/link dirname(dns block)/tmp/go-build2359477819/b275/launcher.test /tmp/go-build2359477819/b275/launcher.test -test.testlogfile=/tmp/go-build2359477819/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true NVM_DIR=/home/REDACTED/.nvm -v /usr/bin/gcc index($0, NVM/usr/libexec/docker/cli-plugins/docker-compose git de/node/bin/git gcc -###�� -x c(dns block)/tmp/go-build4148141444/b275/launcher.test /tmp/go-build4148141444/b275/launcher.test -test.testlogfile=/tmp/go-build4148141444/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ; git /usr/bin/git --abbrev-ref HEAD cal/bin/git git rev-�� --abbrev-ref HEAD docker-buildx --abbrev-ref HEAD ache/uv/0.10.2/x86_64/git tf "%s%s", sep, $0; sep=RS }(dns block)slow.example.com/tmp/go-build2301924257/b275/launcher.test /tmp/go-build2301924257/b275/launcher.test -test.testlogfile=/tmp/go-build2301924257/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true --abbrev-ref HEAD /usr/bin/base64 s#^versions/##; s#^v#node/v#; \#system# !d; 1_ nfig/composer/ve--abbrev-ref base64 -d ache/go/1.25.7/x64/pkg/tool/linux_amd64/vet git /usr/bin/dirname --abbrev-ref HEAD x_amd64/link dirname(dns block)/tmp/go-build2359477819/b275/launcher.test /tmp/go-build2359477819/b275/launcher.test -test.testlogfile=/tmp/go-build2359477819/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true NVM_DIR=/home/REDACTED/.nvm -v /usr/bin/gcc index($0, NVM/usr/libexec/docker/cli-plugins/docker-compose git de/node/bin/git gcc -###�� -x c(dns block)/tmp/go-build4148141444/b275/launcher.test /tmp/go-build4148141444/b275/launcher.test -test.testlogfile=/tmp/go-build4148141444/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ; git /usr/bin/git --abbrev-ref HEAD cal/bin/git git rev-�� --abbrev-ref HEAD docker-buildx --abbrev-ref HEAD ache/uv/0.10.2/x86_64/git tf "%s%s", sep, $0; sep=RS }(dns block)this-host-does-not-exist-12345.com/tmp/go-build2301924257/b284/mcp.test /tmp/go-build2301924257/b284/mcp.test -test.testlogfile=/tmp/go-build2301924257/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true --abbrev-ref HEAD 64/pkg/tool/linux_amd64/link E=3 nwind-tables ache/Python/3.12--abbrev-ref 64/pkg/tool/linuHEAD -d ncher.test git ortcfg.link #; HEAD 86_64/git MCp-3kFl8D2k02Xijt/aVOK8Uts-pP0nQ-KRI0F/UWIyND62jcK9CRxbr1K5(dns block)/tmp/go-build726308285/b288/mcp.test /tmp/go-build726308285/b288/mcp.test -test.testlogfile=/tmp/go-build726308285/b288/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.short=true ache/go/1.25.7/x. sed /usr/sbin/bash s/^\([0-9]\)/v\1base64 m/nvm.sh /usr/bin/base64 bash /usr�� --version base64 /usr/bin/echo ache/go/1.25.7/x/usr/bin/runc.original sed it echo(dns block)/tmp/go-build758265063/b284/mcp.test /tmp/go-build758265063/b284/mcp.test -test.testlogfile=/tmp/go-build758265063/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s rev-�� --abbrev-ref HEAD 2a51a1f2909b033e-d nner/.nvm git /usr/local/.ghcup/bin/git base64 -d de/node/bin/git git x_amd64/link --abbrev-ref HEAD duplication x_amd64/link(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>[duplicate-code] Session-Aware Logging Branching Duplication</issue_title>
<issue_description># 🔍 Duplicate Code Pattern: Session-Aware Logging Branching
Part of duplicate code analysis: #929
Summary
Multiple logging functions in
internal/launcher/log_helpers.gocontain identical if/else branching logic to handle sessionID-aware logging. This pattern appears in 3 functions with nearly identical structure, leading to ~45 lines of duplicated conditional logic.Duplication Details
Pattern: Conditional Session Logging
Severity: High
Occurrences: 3 functions
Locations:
internal/launcher/log_helpers.golines 31-44 (logLaunchStart)internal/launcher/log_helpers.golines 95-106 (logTimeoutError)internal/launcher/log_helpers.golines 109-119 (logLaunchSuccess)Code Sample (from
logLaunchStart):Similar Pattern (from
logLaunchSuccess):Impact Analysis
Refactoring Recommendations
Option 1: Extract Session-Aware Logging Helper (Recommended)
internal/launcher/session_logger.goOption 2: Use sessionSuffix() More Consistently
sessionSuffix()helper more broadlyImplementation Che...