Skip to content

refactor: inline generateRandomID, delegate truncation to strutil, move loadEnvFile to envutil#5104

Merged
lpcox merged 4 commits intomainfrom
copilot/refactor-semantic-function-clustering-analysis
May 4, 2026
Merged

refactor: inline generateRandomID, delegate truncation to strutil, move loadEnvFile to envutil#5104
lpcox merged 4 commits intomainfrom
copilot/refactor-semantic-function-clustering-analysis

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

Static analysis identified three refactoring opportunities: a redundant one-line wrapper, reimplemented truncation logic that bypasses strutil, and an env-file utility misplaced in the CLI root command.

Changes

  • Inline generateRandomID (middleware/jqschema.go): Removed wrapper around strutil.RandomHexWithFallback(16); introduced const queryIDHexLen = 16 and call the utility directly at the use site.

  • sanitize.TruncateSecret → delegates to strutil.TruncateWithSuffix (logger/sanitize/sanitize.go): Was reimplementing byte-slice truncation inline; now calls strutil.TruncateWithSuffix(input, 4, "...") for the truncation path. Semantics preserved (≤4-char inputs still return "...", empty returns "").

    // before
    func TruncateSecret(input string) string {
        if len(input) > 4 {
            return input[:4] + "..."
        } else if len(input) > 0 {
            return "..."
        }
        return ""
    }
    
    // after
    func TruncateSecret(input string) string {
        if len(input) == 0 {
            return ""
        }
        if len(input) <= 4 {
            return "..."
        }
        return strutil.TruncateWithSuffix(input, 4, "...")
    }
  • Move loadEnvFileenvutil.LoadEnvFile (envutil/envfile.go): Extracted 44-line .env parser from cmd/root.go into its natural home in envutil; exported as LoadEnvFile. Removed now-unused bufio and sanitize imports from root.go. Tests relocated from cmd/root_test.go to envutil/envfile_test.go.

  • rpc_helpers.truncateAndSanitize: Already delegates to strutil.Truncate — no change required.

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
    • Triggering command: /tmp/go-build3751646541/b509/launcher.test /tmp/go-build3751646541/b509/launcher.test -test.testlogfile=/tmp/go-build3751646541/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/runtime/c-errorsas 3823591/b314/ /home/REDACTED/.do-nilfunc . --gdwarf2 --64 04.o 3823�� 64/src/runtime/c-errorsas -I x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build623460966/b513/launcher.test /tmp/go-build623460966/b513/launcher.test -test.testlogfile=/tmp/go-build623460966/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build623460966/b494/vet.cfg Y2BynxhhJ -o/tmp/go-build3751646541/b169//_cgo_.o x_amd64/vet -c -I /tmp/go-build3751646541/b169/ x_amd64/vet ortc�� o t.go x_amd64/compile -pthread -Wl,--no-gc-sect-test.testlogfile=/tmp/go-build623460966/b001/testlog.txt -fmessage-length-test.paniconexit0 x_amd64/compile (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3751646541/b491/config.test /tmp/go-build3751646541/b491/config.test -test.testlogfile=/tmp/go-build3751646541/b491/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go elemetry.io/otel@v1.43.0/semconv-imultiarch x_amd64/vet 3823591/b150/ --64 -o x_amd64/vet -W -MOQeqnD5 /tmp/go-build287-ifaceassert 3823591/b300=&gt; . .io/otel/metric --64 ortcfg (dns block)
    • Triggering command: /tmp/go-build623460966/b495/config.test /tmp/go-build623460966/b495/config.test -test.testlogfile=/tmp/go-build623460966/b495/testlog.txt -test.paniconexit0 -test.timeout=10m0s ner_�� se 1646541/b071/vet.cfg ache/go/1.25.9/x64/pkg/tool/linux_amd64/vet . -imultiarch x86_64-linux-gnu ache/go/1.25.9/x64/pkg/tool/linux_amd64/vet -W -I /tmp/go-build3751646541/b169/ x_amd64/vet . --gdwarf2 --64 x_amd64/vet (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build3751646541/b509/launcher.test /tmp/go-build3751646541/b509/launcher.test -test.testlogfile=/tmp/go-build3751646541/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/runtime/c-errorsas 3823591/b314/ /home/REDACTED/.do-nilfunc . --gdwarf2 --64 04.o 3823�� 64/src/runtime/c-errorsas -I x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build623460966/b513/launcher.test /tmp/go-build623460966/b513/launcher.test -test.testlogfile=/tmp/go-build623460966/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build623460966/b494/vet.cfg Y2BynxhhJ -o/tmp/go-build3751646541/b169//_cgo_.o x_amd64/vet -c -I /tmp/go-build3751646541/b169/ x_amd64/vet ortc�� o t.go x_amd64/compile -pthread -Wl,--no-gc-sect-test.testlogfile=/tmp/go-build623460966/b001/testlog.txt -fmessage-length-test.paniconexit0 x_amd64/compile (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build3751646541/b509/launcher.test /tmp/go-build3751646541/b509/launcher.test -test.testlogfile=/tmp/go-build3751646541/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/runtime/c-errorsas 3823591/b314/ /home/REDACTED/.do-nilfunc . --gdwarf2 --64 04.o 3823�� 64/src/runtime/c-errorsas -I x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build623460966/b513/launcher.test /tmp/go-build623460966/b513/launcher.test -test.testlogfile=/tmp/go-build623460966/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build623460966/b494/vet.cfg Y2BynxhhJ -o/tmp/go-build3751646541/b169//_cgo_.o x_amd64/vet -c -I /tmp/go-build3751646541/b169/ x_amd64/vet ortc�� o t.go x_amd64/compile -pthread -Wl,--no-gc-sect-test.testlogfile=/tmp/go-build623460966/b001/testlog.txt -fmessage-length-test.paniconexit0 x_amd64/compile (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3751646541/b518/mcp.test /tmp/go-build3751646541/b518/mcp.test -test.testlogfile=/tmp/go-build3751646541/b518/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/runtime/c-errorsas om/spf13/pflag@v-ifaceassert x_amd64/vet --gdwarf-5 g/protobuf/inter--version -o x_amd64/vet -p DELC/KeoNfyou8G7ZaqPWDELC -trimpath x_amd64/vet -I 3823591/b469/ -I x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build623460966/b522/mcp.test /tmp/go-build623460966/b522/mcp.test -test.testlogfile=/tmp/go-build623460966/b522/testlog.txt -test.paniconexit0 -test.timeout=10m0s /home/REDACTED/.cache/go-build/77/7710171347be097cb0663f048e8f5ad858c953b3f355354b9ed9239a70adf7ca-d /testutil/mcptest/example_test.g-p /testutil/mcptest/gateway_integrgithub.com/github/gh-aw-mcpg/internal/oidc x_amd64/vet 64/src/net (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Refactor semantic function clustering analysis opportunities refactor: inline generateRandomID, delegate truncation to strutil, move loadEnvFile to envutil May 4, 2026
Copilot finished work on behalf of lpcox May 4, 2026 17:28
Copilot AI requested a review from lpcox May 4, 2026 17:28
@lpcox lpcox marked this pull request as ready for review May 4, 2026 17:29
Copilot AI review requested due to automatic review settings May 4, 2026 17:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors a few small utilities without changing their intended behavior: it inlines jq-schema query ID generation, reuses strutil for secret truncation, and moves .env loading into internal/envutil so the logic lives with other environment helpers.

Changes:

  • Removed the one-line generateRandomID wrapper and inlined the strutil.RandomHexWithFallback call in jq-schema middleware.
  • Updated sanitize.TruncateSecret to delegate truncation to strutil.TruncateWithSuffix while preserving current behavior.
  • Moved .env file loading from internal/cmd/root.go into a new exported envutil.LoadEnvFile, and relocated its tests.
Show a summary per file
File Description
internal/middleware/jqschema.go Replaces the local random-ID helper with a constant plus direct strutil call.
internal/middleware/jqschema_test.go Removes the test for the deleted wrapper function.
internal/logger/sanitize/sanitize.go Refactors secret truncation to reuse strutil.TruncateWithSuffix.
internal/envutil/envfile.go Adds the new exported .env loading helper under envutil.
internal/envutil/envfile_test.go Moves and preserves test coverage for .env parsing behavior.
internal/cmd/root.go Switches the CLI startup path to call envutil.LoadEnvFile.
internal/cmd/root_test.go Removes the tests that were moved into internal/envutil.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 7/7 changed files
  • Comments generated: 2

Comment thread internal/middleware/jqschema.go Outdated
func generateRandomID() string {
return strutil.RandomHexWithFallback(16)
}
// queryIDHexLen is the number of hex characters used for random query IDs.
Comment thread internal/envutil/envfile.go Outdated
}
defer file.Close()

log.Printf("Loading environment from %s...", path)
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 4, 2026

@copilot merge main and address the review feedback

Copilot AI and others added 2 commits May 4, 2026 17:38
…ntic-function-clustering-analysis

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 4, 2026

@copilot merge main and address the review feedback

Done in 325a2fb. Merged main and addressed both review items:

  1. queryIDHexLenqueryIDBytes — renamed the constant with a comment clarifying that 16 bytes produces a 32-character hex string, so there's no ambiguity about what the value represents.

  2. log.PrintflogEnvFile.Printfenvfile.go now declares var logEnvFile = logger.New("envutil:envfile") and uses it for all logging, consistent with the rest of the envutil package.

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
    • Triggering command: /tmp/go-build310591056/b513/launcher.test /tmp/go-build310591056/b513/launcher.test -test.testlogfile=/tmp/go-build310591056/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build310591056/b426/vet.cfg ache/go/1.25.9/x64/src/runtime/cgo -I x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet go_.�� ache/go/1.25.9/x-errorsas 64/src/net x_amd64/vet -p golang.org/x/oau-atomic -lang=go1.24 x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build940554890/b509/launcher.test /tmp/go-build940554890/b509/launcher.test -test.testlogfile=/tmp/go-build940554890/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 0b4294565bf642fa-- /tmp/go-build310veth32fa765 bash by/fdecf03406cb2/usr/lib/open-iscsi/net-interface-handler 64/src/flag/flagstop x_amd64/vet /opt/hostedtoolcache/go/1.25.9/x--bundle -ato�� 423611e4b67b3b91 -buildtags /opt/hostedtoolcache/go/1.25.9/x64/pkg/tool/linu/tmp/TestLargePayload_StoredInPayloadDir25172480/tmp/go-build940554890/b512/logger.test -errorsas -ifaceassert -nilfunc /opt/hostedtoolc-test.timeout=10m0s (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build310591056/b495/config.test /tmp/go-build310591056/b495/config.test -test.testlogfile=/tmp/go-build310591056/b495/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build310591056/b397/vet.cfg ache/go/1.25.9/x64/src/runtime/cgo _cgo_.o x_amd64/vet -c -I /tmp/go-build410-bool x_amd64/vet -o 64/src/net -trimpath x_amd64/vet ocessor.go google.golang.or-atomic -lang=go1.23 x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build940554890/b491/config.test /tmp/go-build940554890/b491/config.test -test.testlogfile=/tmp/go-build940554890/b491/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 85b1f1edb94a1cdbed7be14188f282dfeabd20232ac079a841d x_amd64/vet ateway_with_pipe.sh 51a60e977be8b31d86f813bcfe239c29d53/log.json olang.org/protob--prefix=/net/ipv4/conf/veth32fa765 ache/go/1.25.9/x--prefix=/net/ipv4/neigh/veth32fa765 ateway_with_pipe--prefix=/net/ipv6/conf/veth32fa765 0b42�� ry=1 -buildtags by/fdecf03406cb256a137e7d3a6a3342695ae08fb39c82ed13423611e4b67b3b91/log.json -errorsas -ifaceassert -nilfunc /opt/hostedtoolc--no-legend (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build310591056/b513/launcher.test /tmp/go-build310591056/b513/launcher.test -test.testlogfile=/tmp/go-build310591056/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build310591056/b426/vet.cfg ache/go/1.25.9/x64/src/runtime/cgo -I x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet go_.�� ache/go/1.25.9/x-errorsas 64/src/net x_amd64/vet -p golang.org/x/oau-atomic -lang=go1.24 x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build940554890/b509/launcher.test /tmp/go-build940554890/b509/launcher.test -test.testlogfile=/tmp/go-build940554890/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 0b4294565bf642fa-- /tmp/go-build310veth32fa765 bash by/fdecf03406cb2/usr/lib/open-iscsi/net-interface-handler 64/src/flag/flagstop x_amd64/vet /opt/hostedtoolcache/go/1.25.9/x--bundle -ato�� 423611e4b67b3b91 -buildtags /opt/hostedtoolcache/go/1.25.9/x64/pkg/tool/linu/tmp/TestLargePayload_StoredInPayloadDir25172480/tmp/go-build940554890/b512/logger.test -errorsas -ifaceassert -nilfunc /opt/hostedtoolc-test.timeout=10m0s (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build310591056/b513/launcher.test /tmp/go-build310591056/b513/launcher.test -test.testlogfile=/tmp/go-build310591056/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build310591056/b426/vet.cfg ache/go/1.25.9/x64/src/runtime/cgo -I x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet go_.�� ache/go/1.25.9/x-errorsas 64/src/net x_amd64/vet -p golang.org/x/oau-atomic -lang=go1.24 x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build940554890/b509/launcher.test /tmp/go-build940554890/b509/launcher.test -test.testlogfile=/tmp/go-build940554890/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 0b4294565bf642fa-- /tmp/go-build310veth32fa765 bash by/fdecf03406cb2/usr/lib/open-iscsi/net-interface-handler 64/src/flag/flagstop x_amd64/vet /opt/hostedtoolcache/go/1.25.9/x--bundle -ato�� 423611e4b67b3b91 -buildtags /opt/hostedtoolcache/go/1.25.9/x64/pkg/tool/linu/tmp/TestLargePayload_StoredInPayloadDir25172480/tmp/go-build940554890/b512/logger.test -errorsas -ifaceassert -nilfunc /opt/hostedtoolc-test.timeout=10m0s (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build310591056/b522/mcp.test /tmp/go-build310591056/b522/mcp.test -test.testlogfile=/tmp/go-build310591056/b522/testlog.txt -test.paniconexit0 -test.timeout=10m0s go_.�� 64/src/net -trimpath x_amd64/vet -p google.golang.or-atomic -lang=go1.23 x_amd64/vet -E -dM .cfg x_amd64/vet /tmp/go-build311bash -O2 -Wall x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build940554890/b518/mcp.test /tmp/go-build940554890/b518/mcp.test -test.testlogfile=/tmp/go-build940554890/b518/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 423611e4b67b3b91 y e-handler by/1367e8b8f9247bash -ifaceassert dfb/log.json e-handler -tes�� d20232ac079a841d -test.timeout=10m0s 8de004d9295a50c051a60e977be8b31d86f813bcfe239c29d53/log.json by/790ad9f869bddbash ache/go/1.25.9/x/usr/bin/runc dfb/init.pid ker/cli-plugins/docker-compose (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of lpcox May 4, 2026 17:43
@lpcox lpcox merged commit 561a34e into main May 4, 2026
14 checks passed
@lpcox lpcox deleted the copilot/refactor-semantic-function-clustering-analysis branch May 4, 2026 17:50
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.

[refactor] Semantic Function Clustering Analysis — Refactoring Opportunities

3 participants