mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-11-28 10:23:24 +01:00
Introduce an isolated Node worker that hosts the Pi SDK while Go keeps business state, permissions, MCP execution, evidence and delivery checks. The worker is published per source fingerprint, streams events back to Go and supports tool callbacks, cancellation, session resume and per-model transport settings. Agent dispatch, tool search, plan/task tools and migration controls are wired on top of it: large tool catalogs load through Pi tool_search, the conversation task board keeps its existing tools, and legacy mode/route values still resolve. Workflow gains a native DAG with versioned JSON checkpoints, and knowledge retrieval moves to native documents, splitter, HTTP embeddings, vector search and reranking.
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package knowledge
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"cyberstrike-ai/internal/config"
|
|
)
|
|
|
|
func doc(id, content string, score float64) *Document {
|
|
d := &Document{ID: id, Content: content, MetaData: map[string]any{metaKBItemID: "it1"}}
|
|
d.WithScore(score)
|
|
return d
|
|
}
|
|
|
|
func TestDedupeByNormalizedContent(t *testing.T) {
|
|
a := doc("1", "hello world", 0.9)
|
|
b := doc("2", "hello world", 0.8)
|
|
c := doc("3", "other", 0.7)
|
|
out := dedupeByNormalizedContent([]*Document{a, b, c})
|
|
if len(out) != 2 {
|
|
t.Fatalf("len=%d want 2", len(out))
|
|
}
|
|
if out[0].ID != "1" || out[1].ID != "3" {
|
|
t.Fatalf("order/ids wrong: %#v", out)
|
|
}
|
|
}
|
|
|
|
func TestEffectivePrefetchTopK(t *testing.T) {
|
|
if g := EffectivePrefetchTopK(5, nil); g != 20 {
|
|
t.Fatalf("default prefetch got %d want 20", g)
|
|
}
|
|
if g := EffectivePrefetchTopK(5, &config.PostRetrieveConfig{PrefetchTopK: 50}); g != 50 {
|
|
t.Fatalf("got %d", g)
|
|
}
|
|
if g := EffectivePrefetchTopK(5, &config.PostRetrieveConfig{PrefetchTopK: 9999}); g != postRetrieveMaxPrefetchCap {
|
|
t.Fatalf("cap: got %d", g)
|
|
}
|
|
}
|
|
|
|
func TestApplyPostRetrieveTruncateAndTopK(t *testing.T) {
|
|
d1 := doc("1", "ab", 0.9)
|
|
d2 := doc("2", "cd", 0.8)
|
|
d3 := doc("3", "ef", 0.7)
|
|
po := &config.PostRetrieveConfig{MaxContextChars: 3}
|
|
out, err := ApplyPostRetrieve([]*Document{d1, d2, d3}, po, "gpt-4", 5)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(out) != 1 || out[0].ID != "1" {
|
|
t.Fatalf("got %#v", out)
|
|
}
|
|
|
|
out2, err := ApplyPostRetrieve([]*Document{d1, d2, d3}, nil, "gpt-4", 2)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(out2) != 2 {
|
|
t.Fatalf("topk: len=%d", len(out2))
|
|
}
|
|
}
|