mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 17:14:28 +00:00
Remove stripNodesFromOptions function
This commit is contained in:
@@ -10,31 +10,10 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// stripNodesFromOptions creates a copy of the instance options without the Nodes field
|
|
||||||
// to prevent routing loops when sending requests to remote nodes
|
|
||||||
func (im *instanceManager) stripNodesFromOptions(options *instance.CreateInstanceOptions) *instance.CreateInstanceOptions {
|
|
||||||
if options == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a copy of the options struct
|
|
||||||
optionsCopy := *options
|
|
||||||
|
|
||||||
// Clear the Nodes field to prevent the remote node from trying to route further
|
|
||||||
optionsCopy.Nodes = nil
|
|
||||||
|
|
||||||
return &optionsCopy
|
|
||||||
}
|
|
||||||
|
|
||||||
// makeRemoteRequest is a helper function to make HTTP requests to a remote node
|
// makeRemoteRequest is a helper function to make HTTP requests to a remote node
|
||||||
func (im *instanceManager) makeRemoteRequest(nodeConfig *config.NodeConfig, method, path string, body any) (*http.Response, error) {
|
func (im *instanceManager) makeRemoteRequest(nodeConfig *config.NodeConfig, method, path string, body any) (*http.Response, error) {
|
||||||
var reqBody io.Reader
|
var reqBody io.Reader
|
||||||
if body != nil {
|
if body != nil {
|
||||||
// Strip nodes from CreateInstanceOptions to prevent routing loops
|
|
||||||
if options, ok := body.(*instance.CreateInstanceOptions); ok {
|
|
||||||
body = im.stripNodesFromOptions(options)
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonData, err := json.Marshal(body)
|
jsonData, err := json.Marshal(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to marshal request body: %w", err)
|
return nil, fmt.Errorf("failed to marshal request body: %w", err)
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
package manager
|
|
||||||
|
|
||||||
import (
|
|
||||||
"llamactl/pkg/backends"
|
|
||||||
"llamactl/pkg/instance"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestStripNodesFromOptions(t *testing.T) {
|
|
||||||
im := &instanceManager{}
|
|
||||||
|
|
||||||
// Test nil case
|
|
||||||
if result := im.stripNodesFromOptions(nil); result != nil {
|
|
||||||
t.Errorf("Expected nil, got %+v", result)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test main case: nodes should be stripped, other fields preserved
|
|
||||||
options := &instance.CreateInstanceOptions{
|
|
||||||
BackendType: backends.BackendTypeLlamaCpp,
|
|
||||||
Nodes: []string{"node1", "node2"},
|
|
||||||
Environment: map[string]string{"TEST": "value"},
|
|
||||||
}
|
|
||||||
|
|
||||||
result := im.stripNodesFromOptions(options)
|
|
||||||
|
|
||||||
if result.Nodes != nil {
|
|
||||||
t.Errorf("Expected Nodes to be nil, got %+v", result.Nodes)
|
|
||||||
}
|
|
||||||
if result.BackendType != backends.BackendTypeLlamaCpp {
|
|
||||||
t.Errorf("Expected BackendType preserved")
|
|
||||||
}
|
|
||||||
if result.Environment["TEST"] != "value" {
|
|
||||||
t.Errorf("Expected Environment preserved")
|
|
||||||
}
|
|
||||||
// Original should not be modified
|
|
||||||
if len(options.Nodes) != 2 {
|
|
||||||
t.Errorf("Original options should not be modified")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user