fix(traffic,server,sandbox): fix TCP/53 false positives, add error-traffic storage toggle, and fix spawn_task/sandbox polling

- Route external TCP/53 through netstack deferred handshake and real-target DNS inspection (RFC 7766 single-write framing) instead of hijacking to host DNS.
- Preserve explicit targetServer in ProcessDNSQueryToTarget under upstream proxy so external UDP/53 probes never fall back to host DNSUpstream.
- Default error traffic storage (net_flows/dns_queries action=error) to off with hot-toggle controls synced across gateway, Proxy & Egress, and Traffic pages.
- Restore json.Unmarshal in spawn_task orchestration tool and poll live sandbox container state in chat/task controls.
This commit is contained in:
ji ruo committed 2026-12-02 15:17:42 +08:00
1 parent 07309e4530
commit d5926d6420
22 files changed
+1189 -101

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
package server
import (
"context"
"encoding/json"
"strings"
"testing"
)
func TestToolSpawnTaskUnmarshalsInput(t *testing.T) {
s := &Server{m: &Manager{tasks: map[string]*Task{}}}
tool := s.toolSpawnTask()
t.Run("missing goal rejected", func(t *testing.T) {
res, err := tool.Call(context.Background(), json.RawMessage(`{"description":"端口探测"}`), nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !res.IsError || !strings.Contains(res.Flatten(), "goal 为必填") {
t.Fatalf("expected goal required error, got isError=%v text=%q", res.IsError, res.Flatten())
}
})
t.Run("invalid json rejected", func(t *testing.T) {
res, err := tool.Call(context.Background(), json.RawMessage(`{invalid`), nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !res.IsError || !strings.Contains(res.Flatten(), "参数无效") {
t.Fatalf("expected invalid json error, got isError=%v text=%q", res.IsError, res.Flatten())
}
})
t.Run("valid goal parsed past required check", func(t *testing.T) {
res, err := tool.Call(context.Background(), json.RawMessage(`{
"description": "47.116.200.74 端口探测",
"goal": "仅对 47.116.200.74 做端口探测",
"source_task_ids": ["99999"]
}`), nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !res.IsError || !strings.Contains(res.Flatten(), "关联任务 #99999 不存在") {
t.Fatalf("expected source_task_ids check after parsing goal, got isError=%v text=%q", res.IsError, res.Flatten())
}
})
}