Repository: bacalhau-project/bacalhau (language: python)

Issue:
Node manager periodically prints to stdout
https://github.com/bacalhau-project/bacalhau/blob/297f1eaded9495e65c6e025c1290a2bf29d89448/pkg/node/manager/node_manager.go#L103

This should be a log message.

https://github.com/bacalhau-project/bacalhau/blob/297f1eaded9495e65c6e025c1290a2bf29d89448/pkg/node/manager/node_manager.go#L146

Ahem.


Discussion / hints:

Fix patch:
diff --git a/cmd/cli/node/columns.go b/cmd/cli/node/columns.go
index 1174174ba7..b14d34cd88 100644
--- a/cmd/cli/node/columns.go
+++ b/cmd/cli/node/columns.go
@@ -24,6 +24,10 @@ var alwaysColumns = []output.TableColumn[*models.NodeInfo]{
 		ColumnConfig: table.ColumnConfig{Name: "type"},
 		Value:        func(ni *models.NodeInfo) string { return ni.NodeType.String() },
 	},
+	{
+		ColumnConfig: table.ColumnConfig{Name: "status"},
+		Value:        func(ni *models.NodeInfo) string { return ni.Approval.String() },
+	},
 }
 
 var toggleColumns = map[string][]output.TableColumn[*models.NodeInfo]{
diff --git a/pkg/models/node_approval.go b/pkg/models/node_approval.go
index 9d037bef08..93f8e141d6 100644
--- a/pkg/models/node_approval.go
+++ b/pkg/models/node_approval.go
@@ -1,6 +1,8 @@
 package models
 
-import "fmt"
+import (
+	"fmt"
+)
 
 type NodeApproval struct {
 	approval
@@ -89,6 +91,16 @@ func (t NodeApproval) MarshalJSON() ([]byte, error) {
 }
 
 func (t *NodeApproval) UnmarshalJSON(b []byte) error {
-	*t = Parse(string(b))
+	val := string(trimQuotes(b))
+	*t = Parse(val)
 	return nil
 }
+
+func trimQuotes(b []byte) []byte {
+	if len(b) >= 2 {
+		if b[0] == '"' && b[len(b)-1] == '"' {
+			return b[1 : len(b)-1]
+		}
+	}
+	return b
+}
diff --git a/pkg/node/manager/node_manager.go b/pkg/node/manager/node_manager.go
index 4e93fe4d24..5c82cd40d0 100644
--- a/pkg/node/manager/node_manager.go
+++ b/pkg/node/manager/node_manager.go
@@ -55,6 +55,10 @@ func (n *NodeManager) Register(ctx context.Context, request requests.RegisterReq
 		}, nil
 	}
 
+	// TODO: We will default to PENDING, but once we start filtering on NodeApprovals.APPROVED we will need to
+	// make a decision on how this is determined.
+	request.Info.Approval = models.NodeApprovals.PENDING
+
 	if err := n.nodeInfo.Add(ctx, request.Info); err != nil {
 		return nil, errors.Wrap(err, "failed to save nodeinfo during node registration")
 	}
@@ -100,7 +104,6 @@ func (n *NodeManager) UpdateResources(ctx context.Context,
 	}
 
 	log.Ctx(ctx).Debug().Msg("updating resources availability for node")
-	fmt.Println("UPDATE FROM", request.NodeID, "RESOURCES", request.Resources)
 
 	// Update the resources for the node in the stripedmap. This is a thread-safe operation as locking
 	// is handled by the stripedmap on a per-bucket basis.
@@ -143,7 +146,6 @@ func (n *NodeManager) GetByPrefix(ctx context.Context, prefix string) (models.No
 }
 
 func (n *NodeManager) List(ctx context.Context, filters ...routing.NodeInfoFilter) ([]models.NodeInfo, error) {
-	fmt.Println("NODE MANAGER LIST!!!!")
 	items, err := n.nodeInfo.List(ctx, filters...)
 	if err != nil {
 		return nil, err


Test patch:
diff --git a/pkg/models/node_approval_test.go b/pkg/models/node_approval_test.go
new file mode 100644
index 0000000000..8617c6f59d
--- /dev/null
+++ b/pkg/models/node_approval_test.go
@@ -0,0 +1,55 @@
+//go:build unit || !integration
+
+package models
+
+import (
+	"reflect"
+	"testing"
+)
+
+func TestTrimQuotes(t *testing.T) {
+	tests := []struct {
+		name     string
+		input    []byte
+		expected []byte
+	}{
+		{
+			name:     "with surrounding quotes",
+			input:    []byte(`"example"`),
+			expected: []byte(`example`),
+		},
+		{
+			name:     "with escaped quotes inside",
+			input:    []byte(`"ex\"ample"`),
+			expected: []byte(`ex\"ample`),
+		},
+		{
+			name:     "without surrounding quotes",
+			input:    []byte(`example`),
+			expected: []byte(`example`),
+		},
+		{
+			name:     "with only one quote at the beginning",
+			input:    []byte(`"example`),
+			expected: []byte(`"example`),
+		},
+		{
+			name:     "with only one quote at the end",
+			input:    []byte(`example"`),
+			expected: []byte(`example"`),
+		},
+		{
+			name:     "empty byte slice",
+			input:    []byte(``),
+			expected: []byte(``),
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := trimQuotes(tt.input); !reflect.DeepEqual(got, tt.expected) {
+				t.Errorf("trimQuotes() = %v, want %v", got, tt.expected)
+			}
+		})
+	}
+}