Files
AetherForge/server/internal/ai/commands_test.go
AetherForge 4b94776432
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Fix Fleet AI and LOTL test regressions after parallel merges.
Stub slow syscheck/listen-port probes in agent tests, fix ai_snapshot mutex deadlock, reorder fleet clearance vs connectivity checks, and add AI control precedence plus LotlTimeline vitest coverage.
2026-06-07 02:38:27 -07:00

60 lines
1.6 KiB
Go

package ai
import "testing"
func TestParseCommandsJSONBlock(t *testing.T) {
raw := `Here is my plan:
{"commands":[{"type":"restart_mining","args":{}}]}`
cmds := ParseCommands(raw)
if len(cmds) != 1 || cmds[0].Type != CmdRestartMining {
t.Fatalf("got %+v", cmds)
}
}
func TestParseCommandsToolCall(t *testing.T) {
raw := `{"tool":"restart_agent","args":{}}`
cmds := ParseCommands(raw)
if len(cmds) != 1 || cmds[0].Type != CmdRestartMining {
t.Fatalf("got %+v", cmds)
}
}
func TestParseCommandsLineFallback(t *testing.T) {
raw := "COMMAND: spread_now\nCOMMAND: noop"
cmds := ParseCommands(raw)
if len(cmds) != 2 || cmds[0].Type != CmdSpreadNow || cmds[1].Type != CmdNoop {
t.Fatalf("got %+v", cmds)
}
}
func TestParseCommandsEmptyInput(t *testing.T) {
if cmds := ParseCommands(""); cmds != nil {
t.Fatalf("expected nil, got %+v", cmds)
}
if cmds := ParseCommands(" "); cmds != nil {
t.Fatalf("expected nil, got %+v", cmds)
}
}
func TestParseCommandsUnknownToolBecomesAgentCommand(t *testing.T) {
raw := `{"tool":"pause","args":{}}`
cmds := ParseCommands(raw)
if len(cmds) != 1 || cmds[0].Type != CmdAgentCommand {
t.Fatalf("got %+v", cmds)
}
if cmds[0].Args["action"] != "pause" {
t.Fatalf("args: %+v", cmds[0].Args)
}
}
func TestParseCommandsAgentCommand(t *testing.T) {
raw := `{"commands":[{"type":"agent_command","args":{"action":"pause"}}]}`
cmds := ParseCommands(raw)
if len(cmds) != 1 || cmds[0].Type != CmdAgentCommand {
t.Fatalf("got %+v", cmds)
}
if cmds[0].Args["action"] != "pause" {
t.Fatalf("args: %+v", cmds[0].Args)
}
}