feat(agentic): preserve nullable fleet task id
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
8efa9460bd
commit
a3043e786a
2 changed files with 44 additions and 2 deletions
|
|
@ -31,7 +31,7 @@ type FleetNode struct {
|
|||
Capabilities []string `json:"capabilities,omitempty"`
|
||||
Status string `json:"status"`
|
||||
ComputeBudget *ComputeBudget `json:"compute_budget,omitempty"`
|
||||
CurrentTaskID int `json:"current_task_id,omitempty"`
|
||||
CurrentTaskID *int `json:"current_task_id,omitempty"`
|
||||
LastHeartbeatAt string `json:"last_heartbeat_at,omitempty"`
|
||||
RegisteredAt string `json:"registered_at,omitempty"`
|
||||
}
|
||||
|
|
@ -738,12 +738,20 @@ func parseFleetNode(values map[string]any) FleetNode {
|
|||
Capabilities: listValue(values["capabilities"]),
|
||||
Status: stringValue(values["status"]),
|
||||
ComputeBudget: computeBudgetFromValue(values["compute_budget"]),
|
||||
CurrentTaskID: intValue(values["current_task_id"]),
|
||||
CurrentTaskID: intPointerValue(values["current_task_id"]),
|
||||
LastHeartbeatAt: stringValue(values["last_heartbeat_at"]),
|
||||
RegisteredAt: stringValue(values["registered_at"]),
|
||||
}
|
||||
}
|
||||
|
||||
func intPointerValue(value any) *int {
|
||||
number, ok := intValueOK(value)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return &number
|
||||
}
|
||||
|
||||
func computeBudgetFromValue(value any) *ComputeBudget {
|
||||
switch typed := value.(type) {
|
||||
case *ComputeBudget:
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ func TestPlatform_HandleFleetRegister_Good(t *testing.T) {
|
|||
assert.Equal(t, "linux", node.Platform)
|
||||
assert.Equal(t, []string{"codex"}, node.Models)
|
||||
assert.Equal(t, []string{"go", "review"}, node.Capabilities)
|
||||
assert.Nil(t, node.CurrentTaskID)
|
||||
}
|
||||
|
||||
func TestPlatform_HandleFleetHeartbeat_Good_ComputeBudget(t *testing.T) {
|
||||
|
|
@ -194,6 +195,39 @@ func TestPlatform_HandleFleetNextTask_Ugly(t *testing.T) {
|
|||
assert.Nil(t, task)
|
||||
}
|
||||
|
||||
func TestPlatform_ParseFleetNode_Good_CurrentTaskID(t *testing.T) {
|
||||
node := parseFleetNode(map[string]any{
|
||||
"agent_id": "charon",
|
||||
"platform": "linux",
|
||||
"status": "online",
|
||||
"current_task_id": 17,
|
||||
})
|
||||
|
||||
require.NotNil(t, node.CurrentTaskID)
|
||||
assert.Equal(t, 17, *node.CurrentTaskID)
|
||||
}
|
||||
|
||||
func TestPlatform_ParseFleetNode_Bad_CurrentTaskIDMissing(t *testing.T) {
|
||||
node := parseFleetNode(map[string]any{
|
||||
"agent_id": "charon",
|
||||
"platform": "linux",
|
||||
"status": "online",
|
||||
})
|
||||
|
||||
assert.Nil(t, node.CurrentTaskID)
|
||||
}
|
||||
|
||||
func TestPlatform_ParseFleetNode_Ugly_CurrentTaskIDNull(t *testing.T) {
|
||||
node := parseFleetNode(map[string]any{
|
||||
"agent_id": "charon",
|
||||
"platform": "linux",
|
||||
"status": "online",
|
||||
"current_task_id": nil,
|
||||
})
|
||||
|
||||
assert.Nil(t, node.CurrentTaskID)
|
||||
}
|
||||
|
||||
func TestPlatform_HandleFleetEvents_Good(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
require.Equal(t, "/v1/fleet/events", r.URL.Path)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue