refactor: extract backend detection into testable interface with strict precedence#814
Open
Devansh-567 wants to merge 2 commits into
Open
Conversation
|
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.



What does this PR change?
GetCommand()inshared/connection.gopreviously coupled host system concerns interleavingPATHlookups,podman inspectevaluations, systemd service inspections, livekubectldeployment probes, andhelmrelease queries into a single 70-line block. This structural configuration created high maintenance risk and made the detection pipeline untestable without a live environment.This PR isolates these responsibilities by extracting the entire workflow into a decoupled
shared/backendpackage under a newBackendDetectorinterface. Individual I/O concerns (PATHlookups, container tracking, systemd tracking, and Kubernetes evaluations) have been split into targeted structural interfaces. This allows test environments to mock system states safely through fakes without invoking actual sub-processes.GetCommand()has been simplified into a 12-line validation pass that coordinates caching alongside a distinctDetect()call.Additionally, this change addresses a silent regression where the auto-detection branch's Helm release check failed to pass along the targeted
--kubeconfigcontext, introducing environmental edge-case failures acrossk3sclusters.Explicit Backend Precedence Rule:
kubectlexecution containing an active deployment matchingkubernetesFilter.podman/podman-remoteexecuting with an actively running instance of the target container.podmansupported by an installeduyuni-serveroruyuni-proxy-podsystemd service unit.kubectloperating against an active Helm release sequence designated asuyunioruyuni-proxy.Files changed:
shared/backend/detector.goshared/backend/detector_test.goshared/connection.goshared/connection_test.goshared/testutils/systemd.goTest coverage
New tests in
shared/backend/detector_test.go:podman,podman-remote,kubectl,host) during both active presence and missing state environments within the user'sPATH.New tests in
shared/connection_test.go:TestGetCommand: Evaluates an 8-case table tracking routing matrices, fallback triggers, error cascades, and state retention rules.TestGetCommand_DetectorReceivesCorrectArgs: Guarantees downstream propagation integrity for filters, wrappers, and context configurations.All tests use in-process fakes and run in parallel. No real processes are spawned.
Links
Issue(s): #
Changelogs
Before you merge
Check How to branch and merge properly!