//go:build integration // WS7 Phase 6 Command Center surfacing: the federal signal panel. Proves the two additive, read only // views populate from the global catalogs and carry their provenance, the WS7 acceptance criterion that // every inference is traceable to its source text. OpenByMission returns only the solicitation tagged to // the requested mission code and never an untagged one; IncumbentMix returns the incumbent labor mix on a // recompete relevant award with the evidence phrase. Mission tags are never a scoring input and never // reach the eeo schema; this test only exercises the surfacing. package integration import ( "context" "testing" "time" "github.com/jackc/pgx/v5/pgtype" "github.com/shopspring/decimal" "github.com/missionworkforce/missionmatch/internal/modules/commandcenter" "github.com/missionworkforce/missionmatch/internal/platform/database/dbgen" ) func TestFederalSignalOpenByMission(t *testing.T) { ctx := context.Background() org := seedOrg(t) // Seed two active solicitations through the migrator (the global catalog is migrator written). One is // tagged SIGINT, the other is left untagged so the filter must exclude it. stamp := time.Now().UTC().Format("20060102150405.000000") taggedSrc := "FS-TAG-" + stamp untaggedSrc := "FS-UNTAG-" + stamp // A very soon response deadline so the seeded solicitation sorts to the front of the soonest closing // first panel and stays inside the LIMIT 25 even as the global SIGINT catalog grows past 25 future // deadline solicitations (the daily sync accrues real ones). A null deadline sorts last and would fall // out of the panel once the catalog is large, which is a test fragility, not a product issue. soon := time.Now().UTC().Add(time.Hour) for _, src := range []string{taggedSrc, untaggedSrc} { if err := dbgen.New(migrator).UpsertOpportunityRecord(ctx, dbgen.UpsertOpportunityRecordParams{ SourceName: "SAM.gov", SourceRecordID: src, DedupeKey: src, RecordKind: "active_solicitation", Title: "Cyber support " + src, Agency: "DEPT OF DEFENSE", Naics: "541512", PopState: "HI", ValueSource: "operator", IsPlanning: false, PostedDate: pgtype.Date{Time: time.Now().UTC(), Valid: true}, FetchedAt: time.Now().UTC(), ResponseDeadline: &soon, RawObjectKey: "opportunity_records/sam.gov/" + src + ".json", RawSha256: "deadbeef", }); err != nil { t.Fatalf("seed solicitation %s: %v", src, err) } } // Resolve the generated uuid for the tagged record and write a SIGINT federal_mission_tag (global, // migrator owned). federal_mission_tags keys on record_id as the text form of the uuid. var taggedID, untaggedID string if err := migrator.QueryRow(ctx, "SELECT id::text FROM opportunity_records WHERE source_record_id=$1", taggedSrc).Scan(&taggedID); err != nil { t.Fatalf("resolve tagged id: %v", err) } if err := migrator.QueryRow(ctx, "SELECT id::text FROM opportunity_records WHERE source_record_id=$1", untaggedSrc).Scan(&untaggedID); err != nil { t.Fatalf("resolve untagged id: %v", err) } if err := dbgen.New(migrator).UpsertFederalMissionTag(ctx, dbgen.UpsertFederalMissionTagParams{ RecordTable: "opportunity_records", RecordID: taggedID, MissionCode: "SIGINT", Mechanism: "keyword", Evidence: "signals intelligence", Confidence: decimal.RequireFromString("1.00"), }); err != nil { t.Fatalf("write federal mission tag: %v", err) } svc := commandcenter.NewService(appDB) v, err := svc.FederalSignal(ctxOrg(org), "SIGINT") if err != nil { t.Fatalf("FederalSignal SIGINT: %v", err) } sawTagged, sawUntagged := false, false for _, o := range v.OpenByMission { if o.RecordID == taggedID { sawTagged = true if o.MissionCode != "SIGINT" || o.MissionMechanism != "keyword" || o.MissionEvidence != "signals intelligence" { t.Fatalf("tagged solicitation missing provenance: %+v", o) } } if o.RecordID == untaggedID { sawUntagged = true } } if !sawTagged { t.Fatal("OpenByMission(SIGINT) must return the SIGINT tagged solicitation") } if sawUntagged { t.Fatal("OpenByMission(SIGINT) must NOT return the untagged solicitation") } // An unknown mission code is rejected, never silently returning everything. if _, err := svc.FederalSignal(ctxOrg(org), "NOPE"); err == nil { t.Fatal("FederalSignal must reject an unknown mission code") } } func TestFederalSignalIncumbentMix(t *testing.T) { ctx := context.Background() org := seedOrg(t) // Seed a USASpending award with a period of performance that is ending (the recompete signal) and one // incumbent labor role with an evidence phrase. The award catalog and the role table are global and // migrator written. awardID := "FS-AWD-" + time.Now().UTC().Format("20060102150405.000000") amt := decimal.RequireFromString("3200000.00") if _, err := migrator.Exec(ctx, `INSERT INTO usaspending_awards (generated_internal_id, recipient_name, awarding_agency, naics_code, award_amount, pop_end_date, raw) VALUES ($1, $2, $3, $4, $5, $6, '{}'::jsonb)`, awardID, "Acme Defense LLC", "DEPT OF THE AIR FORCE", "541512", amt, time.Now().UTC().AddDate(0, 3, 0)); err != nil { t.Fatalf("seed award: %v", err) } if err := dbgen.New(migrator).UpsertAwardIncumbentRole(ctx, dbgen.UpsertAwardIncumbentRoleParams{ RecordTable: "usaspending_awards", RecordID: awardID, LaborCategory: "SIGINT Analyst", RoleCount: 3, Evidence: "SIGINT Analyst x3", }); err != nil { t.Fatalf("write incumbent role: %v", err) } svc := commandcenter.NewService(appDB) v, err := svc.FederalSignal(ctxOrg(org), "") if err != nil { t.Fatalf("FederalSignal incumbent mix: %v", err) } found := false for _, a := range v.IncumbentMix { if a.RecordID != awardID { continue } found = true if a.RecipientName != "Acme Defense LLC" || a.Source != "USASpending" { t.Fatalf("award identity wrong: %+v", a) } if a.AwardValue == nil || *a.AwardValue != "3200000.00" { t.Fatalf("award value not rendered: %v", a.AwardValue) } if len(a.Roles) != 1 || a.Roles[0].LaborCategory != "SIGINT Analyst" || a.Roles[0].RoleCount != 3 || a.Roles[0].Evidence != "SIGINT Analyst x3" { t.Fatalf("incumbent role or evidence wrong: %+v", a.Roles) } } if !found { t.Fatal("IncumbentMix must return the seeded recompete relevant award with its incumbent role") } }