mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-18 22:20:56 +08:00
Leave asset-coverage tools available when the flag read fails.
A missing task stays enabled. A database error is returned to the caller and logged, instead of being treated as a reason to hide the tools.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/Autumn-27/artex/db"
|
||||
)
|
||||
|
||||
// coverageOn reports whether asset-coverage tools stay available for this task.
|
||||
// A nil store is the historical default (enabled). A database error is logged and
|
||||
// treated as enabled so a transient read failure does not drop the tools mid-run.
|
||||
func coverageOn(as *db.AssetStore, taskID int64) bool {
|
||||
if as == nil {
|
||||
return true
|
||||
}
|
||||
enabled, err := as.CoverageEnabled(taskID)
|
||||
if err != nil {
|
||||
log.Printf("[coverage] task %d: reading the coverage flag failed; leaving coverage on: %v", taskID, err)
|
||||
return true
|
||||
}
|
||||
return enabled
|
||||
}
|
||||
+1
-1
@@ -118,7 +118,7 @@ func (m *MainAgent) Chat(ctx context.Context, taskID int64, mainSeg int, as *db.
|
||||
tsx.SetAssetStore(as, as.Companies())
|
||||
}
|
||||
tsx.SetTaskID(taskID)
|
||||
tsx.SetCoverageEnabled(as == nil || as.CoverageEnabled(taskID))
|
||||
tsx.SetCoverageEnabled(coverageOn(as, taskID))
|
||||
tsx.SetNotify(notify) // generic wake-up (write ops without a dedicated callback go through it, debounced)
|
||||
tsx.SetResumeTask(resume) // set_goals adds a goal → pull a completed/paused task back to running
|
||||
tsx.SetNotifyGoal(notifyGoal) // set_goals adds a goal → record a "human added a goal: …" trigger for the planner
|
||||
|
||||
+1
-1
@@ -473,7 +473,7 @@ func (p *Planner) Plan(ctx context.Context, taskID int64, as *db.AssetStore, ts
|
||||
tsx.SetAssetStore(as, as.Companies())
|
||||
}
|
||||
tsx.SetTaskID(taskID)
|
||||
tsx.SetCoverageEnabled(as == nil || as.CoverageEnabled(taskID))
|
||||
tsx.SetCoverageEnabled(coverageOn(as, taskID))
|
||||
tsx.killWork = p.killWork // enable kill_work tool (nil = unavailable)
|
||||
tsx.steerWork = p.steerWork // enable steer_work tool (nil = unavailable)
|
||||
if origin, _ := ts.OriginFactID(); origin > 0 {
|
||||
|
||||
+1
-1
@@ -412,7 +412,7 @@ func (w *Worker) execute(ctx context.Context, name string, taskID int64, as *db.
|
||||
tsx := NewToolSet(ts, name)
|
||||
tsx.SetFindingRecorder(w.findingRecorder)
|
||||
tsx.SetTaskID(taskID)
|
||||
coverageEnabled := as == nil || as.CoverageEnabled(taskID)
|
||||
coverageEnabled := coverageOn(as, taskID)
|
||||
tsx.SetCoverageEnabled(coverageEnabled)
|
||||
if as != nil {
|
||||
tsx.SetAssetStore(as, as.Companies())
|
||||
|
||||
+12
-7
@@ -297,17 +297,22 @@ type Coverage struct {
|
||||
}
|
||||
|
||||
// CoverageEnabled reports whether a task has the asset-coverage feature turned on
|
||||
// (tasks.coverage_enabled). Missing row / error → true (fail open to the default),
|
||||
// so unknown/legacy tasks keep the historical behavior. taskID<=0 → true.
|
||||
func (s *AssetStore) CoverageEnabled(taskID int64) bool {
|
||||
// (tasks.coverage_enabled). A missing row stays enabled, which is the historical
|
||||
// default for unknown and legacy tasks. taskID<=0 stays enabled. A query error is
|
||||
// returned with enabled=true so a database blip does not turn the feature off.
|
||||
func (s *AssetStore) CoverageEnabled(taskID int64) (bool, error) {
|
||||
if taskID <= 0 {
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
var enabled bool
|
||||
if err := s.db.QueryRow(`SELECT COALESCE(coverage_enabled,true) FROM tasks WHERE id=$1`, taskID).Scan(&enabled); err != nil {
|
||||
return true
|
||||
err := s.db.QueryRow(`SELECT COALESCE(coverage_enabled,true) FROM tasks WHERE id=$1`, taskID).Scan(&enabled)
|
||||
if err == sql.ErrNoRows {
|
||||
return true, nil
|
||||
}
|
||||
return enabled
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
return enabled, nil
|
||||
}
|
||||
|
||||
// declaredScopeFilter keeps a task_scope row ts in the coverage match only when it is
|
||||
|
||||
@@ -2,6 +2,13 @@ package db
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCoverageEnabledWithoutTask(t *testing.T) {
|
||||
on, err := (&AssetStore{}).CoverageEnabled(0)
|
||||
if err != nil || !on {
|
||||
t.Fatalf("enabled=%v err=%v", on, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestStripHostPort covers the ip:port / [ipv6]:port stripping used by the
|
||||
// ip/cidr scope path so a target like "10.0.188.136:3000" no longer 404s.
|
||||
func TestStripHostPort(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user