//go:build integration package integration import ( "context" "testing" "github.com/google/uuid" "github.com/jackc/pgx/v5" "github.com/missionworkforce/missionmatch/internal/modules/matching" "github.com/missionworkforce/missionmatch/internal/platform/database/dbgen" ) // TestSharedCoreScoresIdenticalAcrossTools proves the central acceptance criterion of the three tool // separation: the SAME candidate against the SAME requirement produces byte identical numbers no // matter which tool path computed it. screenMATCH (ScreenCandidate and the Screen Mission Readiness // view) and slateMATCH (GenerateSlate, which persists the frozen member score) both run the one shared // engine, so the total and band must agree to the cent. This is the regression lock for Workstreams B, // C, and D: when the flat handler is split across three routers, this test stays green or a number // drifted. // // The candidate is deliberately partial (75.00, the Yellow boundary): Secret active meets the Secret // requirement (100), no skills or certs are required (100), but there is no DISA customer history (0), // only 5 of 10 required years (50), and a fixed work location the candidate neither matches nor will // relocate to while still being available (50). 25 + 25 + 15 + 0 + 5 + 5 = 75.00. func TestSharedCoreScoresIdenticalAcrossTools(t *testing.T) { ctx := context.Background() org := seedOrg(t) agency := "DISA" location := "Fort Meade, MD" req, err := dbgen.New(migrator).CreateRequirement(ctx, dbgen.CreateRequirementParams{ OrganizationID: org, Title: "Cross Tool Role", RequiredLevel: "secret", RequiredPoly: "none", RequiredYears: 10, CustomerAgency: &agency, WorkLocation: &location, RemoteAllowed: false, }) if err != nil { t.Fatalf("seed requirement: %v", err) } cand := seedCandidate(t, org, "secret", "active", true) if _, err := migrator.Exec(ctx, "UPDATE candidates SET years_experience=5 WHERE id=$1", cand.ID); err != nil { t.Fatalf("enrich candidate: %v", err) } svc := matching.NewService(appDB, nil, nil) // exact only matcher; the engine is the shared core // screenMATCH path 1: the raw explainable result. mr, err := svc.ScreenCandidate(ctxOrg(org), cand.ID, req.ID) if err != nil { t.Fatalf("ScreenCandidate: %v", err) } screenTotal := mr.Total.StringFixed(2) // screenMATCH path 2: the Mission Readiness view a recruiter sees. view, err := svc.Screen(ctxOrg(org), cand.ID, req.ID) if err != nil { t.Fatalf("Screen: %v", err) } // slateMATCH path: generate the slate, which scores and FREEZES the member at generation time. slate, err := svc.GenerateSlate(ctxOrg(org), matching.GenerateSlateInput{RequirementID: req.ID, Name: "Cross Tool Slate"}) if err != nil { t.Fatalf("GenerateSlate: %v", err) } if len(slate.Members) != 1 || slate.Members[0].CandidateID != cand.ID.String() { t.Fatalf("expected one slate member for the candidate, got %+v", slate.Members) } slateTotal := slate.Members[0].Total // The persisted decision record (what missionMATCH rollups read, never recompute). var members []dbgen.SlateMember if err := readMembers(ctxOrg(org), slate.SlateID, &members); err != nil { t.Fatalf("read back slate members: %v", err) } if len(members) != 1 { t.Fatalf("expected one persisted member, got %d", len(members)) } persistedTotal := members[0].TotalScore.StringFixed(2) // Every path must agree to the cent. const want = "75.00" for label, got := range map[string]string{ "screenMATCH ScreenCandidate": screenTotal, "screenMATCH Screen view": view.MissionReadiness.Score, "slateMATCH generated member": slateTotal, "slateMATCH persisted member row": persistedTotal, } { if got != want { t.Fatalf("%s scored %s, every tool must score %s for the same candidate", label, got, want) } } // The band must agree too: 75.00 is the Yellow lower bound. if mr.Band.String() != "Yellow" || slate.Members[0].Band != "yellow" { t.Fatalf("band disagreement: screen=%s slate=%s, want Yellow", mr.Band, slate.Members[0].Band) } } // readMembers reads the persisted slate member rows under the org tenant transaction. func readMembers(ctx context.Context, slateID uuid.UUID, out *[]dbgen.SlateMember) error { return appDB.RunInTenantTx(ctx, func(ctx context.Context, tx pgx.Tx) error { rows, e := dbgen.New(tx).ListSlateMembers(ctx, slateID) if e != nil { return e } *out = rows return nil }) }