33 lines
838 B
Go
33 lines
838 B
Go
package agent
|
|
|
|
import "testing"
|
|
|
|
func TestParseDecisionPlainJSON(t *testing.T) {
|
|
raw := `{"thought":"t","action":"none","action_input":"","final":"ok"}`
|
|
got, err := parseDecision(raw)
|
|
if err != nil {
|
|
t.Fatalf("parseDecision error: %v", err)
|
|
}
|
|
if got.Action != "none" || got.Final != "ok" {
|
|
t.Fatalf("unexpected decision: %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestParseDecisionCodeFence(t *testing.T) {
|
|
raw := "```json\n{\"thought\":\"t\",\"action\":\"shell\",\"action_input\":\"ls\",\"final\":\"\"}\n```"
|
|
got, err := parseDecision(raw)
|
|
if err != nil {
|
|
t.Fatalf("parseDecision error: %v", err)
|
|
}
|
|
if got.Action != "shell" || got.ActionInput != "ls" {
|
|
t.Fatalf("unexpected decision: %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestParseDecisionInvalid(t *testing.T) {
|
|
_, err := parseDecision("not json")
|
|
if err == nil {
|
|
t.Fatal("expected parse error")
|
|
}
|
|
}
|