fix(findings): address grok review on traffic step_index UX, ref merge, tool schema migration

This commit is contained in:
RuoJi6 committed 2026-10-27 17:56:50 +08:00
1 parent fb0146f4b6
commit 8ad507e31f
6 files changed
+433 -125

No files matched your search

+46
View File
@@ -15,6 +15,7 @@ import (
)
func (s *Server) seedFindingWorkflowTools() {
s.migrateFindingWorkflowSchemas()
const hostSearchDescriptionFlag = "finding_workflow_tools_v3_host_search_description"
if value, _, _ := s.m.pg.GetSetting(hostSearchDescriptionFlag); value != "true" {
// Only replace the original built-in text. A user-edited description is
@@ -106,6 +107,51 @@ func (s *Server) seedFindingWorkflowTools() {
_ = s.m.pg.SetSetting(flag, "true")
}
// migrateFindingWorkflowSchemas adds schema fields introduced after the
// original finding workflow seed. It patches only missing properties so a
// user's description, agent bindings, enabled state, and other schema edits
// remain untouched.
func (s *Server) migrateFindingWorkflowSchemas() {
const flag = "finding_workflow_tools_v3_reproduction_step_index"
if value, _, _ := s.m.pg.GetSetting(flag); value == "true" {
return
}
properties := map[string]json.RawMessage{}
for _, seed := range agent.BuiltinToolSeeds() {
if seed.Key != "report_finding" {
continue
}
if raw, err := json.Marshal(objectProperty(seed.Schema, "properties")["reproduction"]); err == nil && string(raw) != "null" {
properties["report_finding"] = raw
}
break
}
for _, tool := range s.orchestrationTools() {
if tool.Name() != "bind_finding_traffic" {
continue
}
schema := tool.InputSchema()
if raw, err := json.Marshal(objectProperty(schema, "properties")["step_index"]); err == nil && string(raw) != "null" {
properties["bind_finding_traffic"] = raw
}
break
}
for key, property := range map[string]string{"report_finding": "reproduction", "bind_finding_traffic": "step_index"} {
raw := properties[key]
if len(raw) == 0 {
log.Printf("[evidence] missing code schema property %s.%s", key, property)
continue
}
if _, err := s.m.pg.Exec(`UPDATE tools
SET schema=jsonb_set(COALESCE(schema,'{}'::jsonb),ARRAY['properties',$2::text],$3::jsonb,true),updated_at=now()
WHERE key=$1 AND system AND NOT(COALESCE(schema->'properties','{}'::jsonb) ? $2)`, key, property, string(raw)); err != nil {
log.Printf("[evidence] upgrade %s.%s: %v", key, property, err)
return
}
}
_ = s.m.pg.SetSetting(flag, "true")
}
func objectProperty(parent map[string]any, key string) map[string]any {
value, ok := parent[key].(map[string]any)
if !ok {
+10
View File
@@ -227,6 +227,9 @@ func TestFindingWorkflowMigrationPreservesUserConfiguration(t *testing.T) {
if err := pg.SetSetting("finding_workflow_tools_v2_reporter", "false"); err != nil {
t.Fatal(err)
}
if err := pg.SetSetting("finding_workflow_tools_v3_reproduction_step_index", "false"); err != nil {
t.Fatal(err)
}
s.seedFindingWorkflowTools()
for _, key := range []string{"report_finding", "add_hint", "add_task_hint"} {
row, _ := pg.GetTool(key)
@@ -243,6 +246,13 @@ func TestFindingWorkflowMigrationPreservesUserConfiguration(t *testing.T) {
if !strings.Contains(string(row.Schema), field) {
t.Fatal("missing optional field", key)
}
if key == "report_finding" && !strings.Contains(string(row.Schema), "reproduction") {
t.Fatal("missing reproduction schema migration")
}
}
bindSchema, _ := pg.GetTool("bind_finding_traffic")
if !strings.Contains(string(bindSchema.Schema), "step_index") {
t.Fatal("missing bind_finding_traffic step_index migration")
}
search, _ := pg.GetTool("traffic_search")
get, _ := pg.GetTool("traffic_get")