修复
1、修复流量包里的复制按钮不工作问题 2、修复新建任务关联资产不同步到任务测试范围问题
This commit is contained in:
1 parent
3675bd815c
commit
cf0989c67d
10 files changed
+297
-32
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -51,6 +52,12 @@ func TestGraphOverviewExpandsAssociatedCompanyScope(t *testing.T) {
|
||||
if added != len(inputs) || skipped != 0 || invalid != 0 || len(scopeErrors) != 0 {
|
||||
t.Fatalf("add company scope: added=%d skipped=%d invalid=%d errors=%v", added, skipped, invalid, scopeErrors)
|
||||
}
|
||||
assets := d.Assets()
|
||||
assetID, err := assets.UpsertRootDomain(db.UpsertRootDomainReq{Domain: domain})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _, _ = assets.DeleteByIDs([]int64{assetID}) })
|
||||
|
||||
task, err := d.CreateTaskWithOptions("company context", "read configured scope", db.TaskCreateOptions{
|
||||
CompanyIDs: []int64{companyID},
|
||||
@@ -62,7 +69,14 @@ func TestGraphOverviewExpandsAssociatedCompanyScope(t *testing.T) {
|
||||
|
||||
tools := NewToolSet(d.Exploration(task.ExplorationID), "planner")
|
||||
tools.SetTaskID(task.ID)
|
||||
tools.SetAssetStore(d.Assets(), companies)
|
||||
tools.SetAssetStore(assets, companies)
|
||||
linkedAssets, err := assets.QueryByTask(task.ID, "root_domain", 10, 0)
|
||||
if err != nil || len(linkedAssets) != 1 || linkedAssets[0].ID != assetID {
|
||||
t.Fatalf("company asset was not linked to task: assets=%+v err=%v", linkedAssets, err)
|
||||
}
|
||||
if linkedAssets[0].TaskSource != "company" || !strings.Contains(linkedAssets[0].TaskSourceSummary, companiesName(t, companies, companyID)) {
|
||||
t.Fatalf("company asset provenance missing: %+v", linkedAssets[0])
|
||||
}
|
||||
overview := tools.graphOverviewData()
|
||||
coverage, ok := overview["coverage"].(map[string]any)
|
||||
if !ok {
|
||||
@@ -89,6 +103,95 @@ func TestGraphOverviewExpandsAssociatedCompanyScope(t *testing.T) {
|
||||
if !ok || len(keywords) != 1 || keywords[0] != keyword {
|
||||
t.Fatalf("company keywords missing: %#v", scopeRows[0]["company_keywords"])
|
||||
}
|
||||
hosts, ok := coverage["hosts"].([]string)
|
||||
if !ok || !containsString(hosts, domain) {
|
||||
t.Fatalf("company asset host missing from agent context: %#v", coverage["hosts"])
|
||||
}
|
||||
untested := callReadJSON(t, tools.listUntestedAssets(), `{"type":"root_domain","page":1,"page_size":10}`)
|
||||
if !strings.Contains(fmt.Sprint(untested), domain) {
|
||||
t.Fatalf("company asset missing from untested backlog: %#v", untested)
|
||||
}
|
||||
byTask := callReadJSON(t, tools.listAssets(), fmt.Sprintf(
|
||||
`{"dsl":"task_id==%d","type":"root_domain","limit":10}`, task.ID,
|
||||
))
|
||||
if !strings.Contains(fmt.Sprint(byTask), domain) {
|
||||
t.Fatalf("company asset missing from task-scoped agent query: %#v", byTask)
|
||||
}
|
||||
byCompany := callReadJSON(t, tools.listAssets(), fmt.Sprintf(
|
||||
`{"dsl":"company_id==%d","type":"root_domain","limit":10}`, companyID,
|
||||
))
|
||||
if !strings.Contains(fmt.Sprint(byCompany), domain) {
|
||||
t.Fatalf("company asset missing from company-scoped agent query: %#v", byCompany)
|
||||
}
|
||||
assetJSON, _ := json.Marshal(assetID)
|
||||
intentID, err := tools.addOneIntent(intentItem{
|
||||
Summary: "test associated company asset",
|
||||
AssetIDs: []json.RawMessage{assetJSON},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
workerAssets, err := assets.IntentAssets(task.ID)
|
||||
if err != nil || len(workerAssets) != 1 || workerAssets[0].IntentID != intentID || workerAssets[0].AssetID != assetID {
|
||||
t.Fatalf("worker target did not retain company asset: assets=%+v err=%v", workerAssets, err)
|
||||
}
|
||||
|
||||
coverageDisabled := false
|
||||
disabledTask, err := d.CreateTaskWithOptions("company context without coverage", "still expose company assets", db.TaskCreateOptions{
|
||||
CompanyIDs: []int64{companyID}, CoverageEnabled: &coverageDisabled,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = d.DeleteTask(disabledTask.ID) })
|
||||
disabledTools := NewToolSet(d.Exploration(disabledTask.ExplorationID), "planner")
|
||||
disabledTools.SetTaskID(disabledTask.ID)
|
||||
disabledTools.SetCoverageEnabled(false)
|
||||
disabledTools.SetAssetStore(assets, companies)
|
||||
disabledOverview := disabledTools.graphOverviewData()
|
||||
disabledCoverage, ok := disabledOverview["coverage"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("coverage-disabled task lost asset context: %#v", disabledOverview["coverage"])
|
||||
}
|
||||
disabledHosts, ok := disabledCoverage["hosts"].([]string)
|
||||
if !ok || !containsString(disabledHosts, domain) {
|
||||
t.Fatalf("coverage-disabled task lost company asset host: %#v", disabledCoverage["hosts"])
|
||||
}
|
||||
if _, exists := disabledCoverage["denominator"]; exists {
|
||||
t.Fatalf("coverage-disabled task unexpectedly exposed metrics: %#v", disabledCoverage)
|
||||
}
|
||||
if linked, err := assets.QueryByTask(disabledTask.ID, "root_domain", 10, 0); err != nil || len(linked) != 1 || linked[0].ID != assetID {
|
||||
t.Fatalf("coverage-disabled task asset link=%+v err=%v", linked, err)
|
||||
}
|
||||
disabledIntentID, err := disabledTools.addOneIntent(intentItem{
|
||||
Summary: "test associated company asset without coverage metrics",
|
||||
AssetIDs: []json.RawMessage{assetJSON},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
disabledWorkerAssets, err := assets.IntentAssets(disabledTask.ID)
|
||||
if err != nil || len(disabledWorkerAssets) != 1 || disabledWorkerAssets[0].IntentID != disabledIntentID || disabledWorkerAssets[0].AssetID != assetID {
|
||||
t.Fatalf("coverage-disabled worker target=%+v err=%v", disabledWorkerAssets, err)
|
||||
}
|
||||
}
|
||||
|
||||
func containsString(items []string, target string) bool {
|
||||
for _, item := range items {
|
||||
if item == target {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func companiesName(t *testing.T, companies *db.CompanyStore, companyID int64) string {
|
||||
t.Helper()
|
||||
company, err := companies.GetCompany(companyID)
|
||||
if err != nil || company == nil {
|
||||
t.Fatalf("company %d: company=%+v err=%v", companyID, company, err)
|
||||
}
|
||||
return company.Name
|
||||
}
|
||||
|
||||
func TestBlackboardToolsReadDirectSources(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user