31 lines
2.1 KiB
Go
31 lines
2.1 KiB
Go
package cognitive_test
|
|
|
|
import (
|
|
"git.cin.su/m/Assistant/contracts/capability"
|
|
"git.cin.su/m/Assistant/contracts/cognitive"
|
|
"testing"
|
|
)
|
|
|
|
func TestContextCompilerV2TraceAndBudgetRemainDeterministic(t *testing.T) {
|
|
b, err := cognitive.CompileContext(cognitive.ContextCompileInput{MaxBytes: 5, DataPolicy: capability.DataPolicyLocalOnly, TaskRef: "task", FocusFrameRef: "frame", ContextScopeRef: "company-a", Candidates: []cognitive.ContextCandidate{{Excerpt: cognitive.ContextExcerpt{ID: "a", Text: "123", Sensitivity: cognitive.SensitivityPrivateAllowed}, ContextScopeRef: "company-a", Relevance: 10}, {Excerpt: cognitive.ContextExcerpt{ID: "b", Text: "123456", Sensitivity: cognitive.SensitivityPrivateAllowed}, ContextScopeRef: "company-b", Relevance: 100}}})
|
|
if err != nil || len(b.Excerpts) != 1 || len(b.Trace.Excluded) != 1 {
|
|
t.Fatalf("bundle=%#v err=%v", b, err)
|
|
}
|
|
}
|
|
|
|
func TestContextCompilerPreservesNegativeLaneWithinBoundedBudget(t *testing.T) {
|
|
b, err := cognitive.CompileContext(cognitive.ContextCompileInput{MaxBytes: 27, DataPolicy: capability.DataPolicyLocalOnly, Candidates: []cognitive.ContextCandidate{
|
|
{Excerpt: cognitive.ContextExcerpt{ID: "current", Text: "current-value", Sensitivity: cognitive.SensitivityPrivateAllowed}, Lane: "current-fact", Relevance: 100},
|
|
{Excerpt: cognitive.ContextExcerpt{ID: "failure", Text: "known-failure", Sensitivity: cognitive.SensitivityPrivateAllowed}, Lane: "negative-experience", Relevance: 1, Negative: true},
|
|
{Excerpt: cognitive.ContextExcerpt{ID: "crowd", Text: "similar-current", Sensitivity: cognitive.SensitivityPrivateAllowed}, Lane: "current-fact", Relevance: 99},
|
|
}})
|
|
if err != nil || len(b.Excerpts) != 2 || b.Excerpts[0].ID != "current" || b.Excerpts[1].ID != "failure" {
|
|
t.Fatalf("bundle=%#v err=%v", b, err)
|
|
}
|
|
// The negative record fits and is retained before a lower-value crowd of
|
|
// similar facts can consume the remaining bounded budget.
|
|
if len(b.Trace.Inclusions) != 2 || b.Trace.Inclusions[0].Reason != "lane_coverage" || b.Trace.Inclusions[1].Reason != "lane_coverage" {
|
|
t.Fatalf("trace=%#v", b.Trace)
|
|
}
|
|
}
|