Files
Agent-System/internal/ctxmgr/semantic_shadow_test.go
T
weichenandCursor 8fdf50ab2a feat(chat): SEMANTIC_SUMMARY_SHADOW optional deterministic annotate
Default off; unauthorized views skipped; facts preserved.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-16 15:40:25 +00:00

41 lines
1.3 KiB
Go

package ctxmgr
import "testing"
func TestSemanticSummaryShadowDefaultOff(t *testing.T) {
t.Setenv("SEMANTIC_SUMMARY_SHADOW", "")
if SemanticSummaryShadowEnabled() {
t.Fatal("default off")
}
in := &ChatSummary{SessionID: "s1", Narrative: "hello", Facts: map[string]string{"a": "1"}}
out := MaybeApplySemanticShadow(t.Context(), in, true)
if out.Narrative != "hello" || out.Facts["semantic_shadow"] != "" {
t.Fatalf("unchanged when off: %+v", out)
}
}
func TestSemanticSummaryShadowAuthorized(t *testing.T) {
t.Setenv("SEMANTIC_SUMMARY_SHADOW", "1")
in := &ChatSummary{SessionID: "s1", Narrative: "topic", Facts: map[string]string{"k": "v"}}
out := MaybeApplySemanticShadow(t.Context(), in, true)
if !stringsHasPrefix(out.Narrative, "[shadow]") {
t.Fatalf("narrative=%q", out.Narrative)
}
if out.Facts["k"] != "v" || out.Facts["semantic_shadow"] != "applied" {
t.Fatalf("facts=%v", out.Facts)
}
}
func TestSemanticSummaryShadowUnauthorizedSkipped(t *testing.T) {
t.Setenv("SEMANTIC_SUMMARY_SHADOW", "true")
in := &ChatSummary{SessionID: "s1", Narrative: "x", Facts: map[string]string{}}
out := MaybeApplySemanticShadow(t.Context(), in, false)
if out.Facts["semantic_shadow"] != "skipped_unauthorized_view" {
t.Fatalf("%v", out.Facts)
}
}
func stringsHasPrefix(s, p string) bool {
return len(s) >= len(p) && s[:len(p)] == p
}