mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-25 01:10:54 +08:00
With agent_traffic_binding disabled (the default) findingWorkflowTools strips bind_finding_traffic from every agent toolset and removes traffic_refs / evidence_hint_id from the report_finding and hint schemas, but the tool descriptions keep promising the binding path: prove_goal says a finding closes a goal once a traffic_ref is bound, and the report_finding error path says already-registered findings can be bound later via bind_finding_traffic. An agent then chases a tool that is not in its toolset. Observed on a live run (v0.7.0, local OpenAI-compatible model): a worker spent minutes on it — "the tool bind_finding_traffic must be invoked as a tool", a bare Bash true, then grepping the transcripts and the strings of the binary. The task registered findings with poe_level 3, zero bound traffic, and closed no goal; a run with the switch on bound traffic and closed 4 of 6 goals. Fix: attach binding-off notes to the same tools the capture-off notes ride on (report_finding, add_hint / add_task_hint, prove_goal) in the disabled branch, so the standing guidance stays empty — the contract the PG test asserts — while the agent is told the tool and the parameters are absent, that findings stay unverified, and that an operator can enable binding or bind manually. Test: agent/finding_workflow_test.go asserts the notes exist on the tools and name the absent tool; red on the planted break, green with the fix. Verified against the PostgreSQL-dependent server test that CI runs (TestFindingWorkflowAutoHintToPlannerAndSetting) and go test ./agent/ ./server/.
147 lines
5.2 KiB
Go
147 lines
5.2 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
actool "github.com/Autumn-27/norma/tool"
|
|
)
|
|
|
|
func TestFindingWorkflowSharedAssemblyAndSwitch(t *testing.T) {
|
|
oldPolicy, oldResolve, oldAugment := FindingTrafficBindingEnabled(), ToolResolve(), ToolAugment()
|
|
t.Cleanup(func() {
|
|
SetFindingTrafficBindingEnabled(oldPolicy)
|
|
SetToolResolve(oldResolve)
|
|
SetToolAugment(oldAugment)
|
|
})
|
|
SetToolAugment(nil)
|
|
on := false
|
|
SetFindingTrafficBindingEnabled(func() bool { return on })
|
|
ts := NewToolSet(nil, "fixture")
|
|
SetToolResolve(func(_ context.Context, _ string, base []actool.CoreTool) []actool.CoreTool {
|
|
out := make([]actool.CoreTool, len(base))
|
|
for i, tool := range base {
|
|
out[i] = DecorateTool(tool, "CUSTOM DESCRIPTION", tool.InputSchema())
|
|
}
|
|
return out
|
|
})
|
|
for _, role := range []string{"worker", "planner", "mainagent", "auto", "pentest", "custom-agent"} {
|
|
for _, enabled := range []bool{false, true, false} {
|
|
on = enabled
|
|
out, def, cleanup := AugmentTools(t.Context(), role, []actool.CoreTool{ts.addFinding(), ts.addHint()})
|
|
cleanup()
|
|
system, _ := deferredSystem("USER CUSTOM PROMPT", def)
|
|
if !strings.HasPrefix(system[0], "USER CUSTOM PROMPT") {
|
|
t.Fatal("custom prompt replaced")
|
|
}
|
|
if strings.Contains(system[0], "traffic_refs") != on {
|
|
t.Fatalf("%s: guidance ignored switch: %v", role, on)
|
|
}
|
|
if !on {
|
|
// The switch strips the tool and the schema, so the tool descriptions
|
|
// must say so: otherwise the agent chases bind_finding_traffic, which
|
|
// is not in its toolset, and burns turns on it.
|
|
if def.FindingGuidance != "" {
|
|
t.Fatalf("%s: disabled deployment must keep the standing guidance empty, got %q", role, def.FindingGuidance)
|
|
}
|
|
noted := false
|
|
for _, tool := range out {
|
|
if !strings.Contains(tool.Description(), "automatic traffic binding is OFF") {
|
|
continue
|
|
}
|
|
noted = true
|
|
// The tool that carries traffic parameters is the one whose
|
|
// schema lost them, so it must name the absent tool.
|
|
if tool.Name() == "report_finding" && !strings.Contains(tool.Description(), "bind_finding_traffic") {
|
|
t.Fatalf("%s: report_finding note must name the absent tool", role)
|
|
}
|
|
}
|
|
if !noted {
|
|
t.Fatalf("%s: disabled deployment must state on the tools that binding is off", role)
|
|
}
|
|
}
|
|
if on && (!strings.Contains(system[0], "TCP") || !strings.Contains(system[0], "evidence_hint_id")) {
|
|
t.Fatal("missing optional/handoff contract")
|
|
}
|
|
for _, tool := range out {
|
|
if !strings.HasPrefix(tool.Description(), "CUSTOM DESCRIPTION") {
|
|
t.Fatal("custom description replaced")
|
|
}
|
|
raw, _ := json.Marshal(tool.InputSchema())
|
|
var schema map[string]any
|
|
json.Unmarshal(raw, &schema)
|
|
props := schema["properties"].(map[string]any)
|
|
if (props["traffic_refs"] != nil) != on {
|
|
t.Fatalf("%s: binding schema ignored switch", role)
|
|
}
|
|
if tool.Name() == "add_hint" {
|
|
nested := props["hints"].(map[string]any)["items"].(map[string]any)["properties"].(map[string]any)
|
|
if (nested["traffic_refs"] != nil) != on {
|
|
t.Fatal("nested hint schema ignored switch")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
on = true
|
|
SetToolResolve(func(context.Context, string, []actool.CoreTool) []actool.CoreTool { return nil })
|
|
out, def, cleanup := AugmentTools(t.Context(), "planner", []actool.CoreTool{ts.addFinding()})
|
|
defer cleanup()
|
|
if len(out) != 0 || def.FindingGuidance != "" {
|
|
t.Fatal("reintroduced disabled tool or its guidance")
|
|
}
|
|
}
|
|
|
|
func TestFindingWorkflowToolsTrafficCaptureOffNotice(t *testing.T) {
|
|
oldPolicy, oldCapture, oldResolve, oldAugment := FindingTrafficBindingEnabled(), TrafficCaptureEnabled(), ToolResolve(), ToolAugment()
|
|
t.Cleanup(func() {
|
|
SetFindingTrafficBindingEnabled(oldPolicy)
|
|
SetTrafficCaptureEnabled(oldCapture)
|
|
SetToolResolve(oldResolve)
|
|
SetToolAugment(oldAugment)
|
|
})
|
|
SetToolAugment(nil)
|
|
SetToolResolve(nil)
|
|
ts := NewToolSet(nil, "fixture")
|
|
base := []actool.CoreTool{ts.proveGoal(), ts.addFinding(), ts.addHint()}
|
|
|
|
for _, binding := range []bool{false, true} {
|
|
SetFindingTrafficBindingEnabled(func() bool { return binding })
|
|
|
|
calls := 0
|
|
SetTrafficCaptureEnabled(func() bool {
|
|
calls++
|
|
return false
|
|
})
|
|
outOff, _, clOff := AugmentTools(t.Context(), "planner", base)
|
|
clOff()
|
|
if calls != 1 {
|
|
t.Fatalf("binding=%v: capture hook called %d times for %d tools, want 1", binding, calls, len(base))
|
|
}
|
|
for _, tool := range outOff {
|
|
desc := tool.Description()
|
|
switch tool.Name() {
|
|
case "prove_goal", "report_finding":
|
|
if !strings.Contains(desc, "traffic capture is currently OFF") {
|
|
t.Fatalf("binding=%v %s: expected capture-off notice in description, got %q", binding, tool.Name(), desc)
|
|
}
|
|
case "add_hint":
|
|
if strings.Contains(desc, "traffic capture is currently OFF") {
|
|
t.Fatalf("binding=%v add_hint: unexpected capture-off notice", binding)
|
|
}
|
|
}
|
|
}
|
|
|
|
SetTrafficCaptureEnabled(func() bool { return true })
|
|
outOn, _, clOn := AugmentTools(t.Context(), "planner", base)
|
|
clOn()
|
|
for _, tool := range outOn {
|
|
if strings.Contains(tool.Description(), "traffic capture is currently OFF") {
|
|
t.Fatalf("binding=%v %s: unexpected capture-off notice when capture is ON", binding, tool.Name())
|
|
}
|
|
}
|
|
}
|
|
}
|