package engine import ( "context" "reflect" "testing" "github.com/shopspring/decimal" ) // TestDefaultWeightsIdentity proves the weighted entry point with the default weights reproduces // ScoreCandidate exactly, so the AIOE wiring cannot drift the historical scores. func TestDefaultWeightsIdentity(t *testing.T) { cands := []Candidate{ { ID: "c1", Clearance: Clearance{Level: ClearanceTSSCI, Status: StatusActive}, Skills: []CandidateSkill{ {SkillID: "s1", Name: "Signals Intelligence"}, {SkillID: "s2", Name: "Network Analysis"}, }, Certifications: []string{"Security+"}, CustomerExperience: []string{"NSA"}, YearsExperience: 7, Location: "Fort Meade, MD", Available: true, }, {ID: "c2", Clearance: Clearance{Level: ClearanceSecret, Status: StatusExpired}}, {ID: "c3", YearsExperience: 2, Relocatable: true}, } reqs := []Requirement{ { ID: "r1", RequiredLevel: ClearanceTSSCI, RequiredSkills: []RequiredSkill{ {SkillID: "s1", Name: "Signals Intelligence", Mandatory: true}, {SkillID: "s9", Name: "Targeting"}, }, RequiredCerts: []string{"Security+", "CISSP"}, CustomerAgency: "NSA", RequiredYears: 5, WorkLocation: "Fort Meade, MD", }, {ID: "r2"}, } for _, c := range cands { for _, r := range reqs { a := ScoreCandidate(context.Background(), c, r, nil) b := ScoreCandidateWithWeights(context.Background(), c, r, nil, DefaultWeights()) if !reflect.DeepEqual(a, b) { t.Fatalf("weighted default diverges for c=%s r=%s:\n a=%+v\n b=%+v", c.ID, r.ID, a, b) } } } } // TestCustomWeightsChangeOnlyTheWeighting proves an alternate profile changes weights and totals but // never the raw dimension scores, so the adaptive layer can only rebalance, never rescore. func TestCustomWeightsChangeOnlyTheWeighting(t *testing.T) { c := Candidate{ ID: "c1", Clearance: Clearance{Level: ClearanceTopSecret, Status: StatusActive}, Skills: []CandidateSkill{{SkillID: "s1", Name: "RMF"}}, Available: true, } r := Requirement{ ID: "r1", RequiredLevel: ClearanceSecret, RequiredSkills: []RequiredSkill{{SkillID: "s1", Name: "RMF"}, {SkillID: "s2", Name: "ATO"}}, RequiredYears: 4, } alt := Weights{ Clearance: decimal.RequireFromString("0.30"), Skills: decimal.RequireFromString("0.30"), Certifications: decimal.RequireFromString("0.10"), CustomerExperience: decimal.RequireFromString("0.10"), Experience: decimal.RequireFromString("0.10"), Location: decimal.RequireFromString("0.10"), } if err := alt.Validate(); err != nil { t.Fatalf("alt weights should validate: %v", err) } a := ScoreCandidate(context.Background(), c, r, nil) b := ScoreCandidateWithWeights(context.Background(), c, r, nil, alt) for name, pair := range map[string][2]decimal.Decimal{ "clearance": {a.Clearance, b.Clearance}, "skills": {a.Skills, b.Skills}, "certs": {a.Certifications, b.Certifications}, "customer": {a.CustomerExperience, b.CustomerExperience}, "experience": {a.Experience, b.Experience}, "location": {a.Location, b.Location}, } { if !pair[0].Equal(pair[1]) { t.Fatalf("raw %s score changed under alternate weights: %s vs %s", name, pair[0], pair[1]) } } if a.Total.Equal(b.Total) { t.Fatalf("alternate weights should change the total for this fixture (both %s)", a.Total) } if b.Trace[0].Weight.String() != "0.3" && b.Trace[0].Weight.String() != "0.30" { t.Fatalf("trace should carry the injected weight, got %s", b.Trace[0].Weight) } } func TestWeightsValidate(t *testing.T) { ok := DefaultWeights() if err := ok.Validate(); err != nil { t.Fatalf("default weights must validate: %v", err) } bad := DefaultWeights() bad.Skills = decimal.RequireFromString("0.30") if err := bad.Validate(); err == nil { t.Fatal("weights not summing to one must fail validation") } zeroed := DefaultWeights() zeroed.Location = decimal.Zero zeroed.Experience = decimal.RequireFromString("0.20") if err := zeroed.Validate(); err == nil { t.Fatal("a zero weight must fail validation") } }