package evidence import ( "testing" "antidrift/internal/domain" ) func TestWindowClassMatchesCaseAndTrim(t *testing.T) { ctx := domain.AllowedContext{WindowClasses: []string{" code "}} if !windowClassAllowed(ctx, " Code ") { t.Fatal("class should match case-insensitively after trim") } if windowClassAllowed(ctx, "firefox") { t.Fatal("unrelated class must not match") } if windowClassAllowed(ctx, " ") { t.Fatal("empty candidate must not match") } } func TestWindowTitleMatchesSubstring(t *testing.T) { ctx := domain.AllowedContext{WindowTitleSubstrings: []string{" antidrift "}} if !windowTitleAllowed(ctx, "Commitment OS - AntiDrift") { t.Fatal("title substring should match after trim/casefold") } if windowTitleAllowed(ctx, "random video") { t.Fatal("unrelated title must not match") } } func TestDomainMatchesExactAndSubdomain(t *testing.T) { ctx := domain.AllowedContext{Domains: []string{" GitHub.COM. "}} if !domainAllowed(ctx, "github.com") { t.Fatal("exact domain should match") } if !domainAllowed(ctx, " DOCS.GITHUB.COM. ") { t.Fatal("subdomain should match after normalization") } if domainAllowed(ctx, "evilgithub.com") { t.Fatal("suffix-without-dot must not match") } } func TestCommandMatchesExecutableBasename(t *testing.T) { ctx := domain.AllowedContext{Commands: []string{"cargo"}} if !commandAllowed(ctx, "/home/felixm/.cargo/bin/cargo test") { t.Fatal("basename of full path should match") } if !commandAllowed(ctx, "cargo") { t.Fatal("bare command should match") } if commandAllowed(ctx, "/usr/bin/git status") { t.Fatal("unrelated command must not match") } } func TestMatchesAllowedClassOrTitle(t *testing.T) { ctx := domain.AllowedContext{ WindowClasses: []string{"code"}, WindowTitleSubstrings: []string{"antidrift"}, } if !MatchesAllowed(ctx, "Code", "anything") { t.Fatal("class match should satisfy MatchesAllowed") } if !MatchesAllowed(ctx, "firefox", "my AntiDrift tab") { t.Fatal("title match should satisfy MatchesAllowed") } if MatchesAllowed(ctx, "firefox", "youtube") { t.Fatal("neither match must be off-task") } if MatchesAllowed(domain.AllowedContext{}, "code", "antidrift") { t.Fatal("empty context matches nothing") } }