feat(agent): 云端 Agent 运行时 - 完善 Pi 桥接、上下文压力与临时故障重试
This commit is contained in:
1 parent
0030f4da9b
commit
76ca0fd247
32 files changed
+1663
-1485
No files matched your search
@@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -230,6 +231,68 @@ func TestCloudAgentMediaReferenceAndSnapshotGuards(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudAgentMediaArgumentFailureContinuesRun(t *testing.T) {
|
||||
s, db, args := agentMediaFixture(t)
|
||||
args.SourceNodeID = "cat" // Existing media node, invalid as a text source.
|
||||
args.ReferenceNodeIDs = []string{"hero"}
|
||||
run, state := agentMediaRun(t, s, args, "request_approval")
|
||||
if err := s.advanceCloudAgentTool(run, &state); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
stored, err := s.repo.CloudAgent("user", run.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
state, err = cloudAgentDecode(stored)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stored.Status != "running" {
|
||||
t.Fatalf("repairable media argument failure terminated run: status=%s message=%s", stored.Status, stored.FailureMessage)
|
||||
}
|
||||
var failed *CloudAgentEvent
|
||||
for i := range state.Events {
|
||||
if state.Events[i].Type == "tool_failed" {
|
||||
failed = &state.Events[i]
|
||||
}
|
||||
if state.Events[i].Type == "run_failed" {
|
||||
t.Fatalf("argument error emitted run_failed: %+v", state.Events[i])
|
||||
}
|
||||
}
|
||||
if failed == nil {
|
||||
t.Fatal("missing tool_failed event")
|
||||
}
|
||||
result, _ := failed.Payload["result"].(map[string]any)
|
||||
if result["field"] != "sourceNodeId" || result["issue"] != "invalid_value" || result["requiredAction"] != "fix_arguments" {
|
||||
t.Fatalf("missing actionable field feedback: %+v", result)
|
||||
}
|
||||
var tasks int64
|
||||
if err := db.Model(&model.Task{}).Where("type = ?", "canvas_video").Count(&tasks).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if tasks != 0 {
|
||||
t.Fatalf("invalid arguments submitted %d media tasks", tasks)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudAgentUnavailableTransientReferenceIsNotRetryable(t *testing.T) {
|
||||
s, _, args := agentMediaFixture(t)
|
||||
args.ReferenceNodeIDs = nil
|
||||
args.ReferenceTransientIDs = []string{"missing-transient"}
|
||||
_, _, _, err := cloudAgentMediaDocument(s.repo, "user", "agent-canvas", args, map[string]cloudAgentTransientReference{})
|
||||
if err == nil {
|
||||
t.Fatal("missing transient reference was accepted")
|
||||
}
|
||||
var argumentErr *cloudAgentArgumentError
|
||||
if errors.As(err, &argumentErr) {
|
||||
t.Fatalf("unavailable transient reference was classified as a model-correctable argument: %v", err)
|
||||
}
|
||||
class, retryable, action := cloudAgentToolErrorClass(agentTestRequest(), agentMediaCall(args), cloudAgentWrapMediaAdmissionError(err), true)
|
||||
if class != cloudAgentToolErrorAdmission || retryable || action != "report_to_user" {
|
||||
t.Fatalf("unavailable transient reference entered correction retry: class=%s retryable=%v action=%s", class, retryable, action)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudAgentImageCreatesReferencedNode(t *testing.T) {
|
||||
s, db, a := agentMediaFixture(t)
|
||||
capability := DefaultModelCapabilityConfigForModel(string(model.ChannelInterfaceGrokImage), "grok-image")
|
||||
|
||||
Reference in new issue
Block a user