Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/integration/graph_market_integration_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/integration/graph_market_integration_test.go |
| Original SHA-256 | 9062509316333bac347e052e181f1699b26aa852cd7fb143cb48200ae51178dc |
| Git blob SHA | 94538c1577b863e6c280f285fd4a2fd5fd27dd45 |
| Reading-copy SHA-256 | 9062509316333bac347e052e181f1699b26aa852cd7fb143cb48200ae51178dc |
Every recorded occurrence
These 12 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/missionmatch / internal/integration/graph_market_integration_test.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/integration/graph_market_integration_test.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/integration/graph_market_integration_test.go | m5-price-to-win | 41000ad30fff4129fdaf5ec84e15ba14c27d4890 | Open original |
| Janady13/missionmatch / internal/integration/graph_market_integration_test.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/integration/graph_market_integration_test.go | mag-substrate | b82c7100a492dec67dfd1eda6b3f53def859be35 | Open original |
| Janady13/missionmatch / internal/integration/graph_market_integration_test.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/integration/graph_market_integration_test.go | graphrag-foundation | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 | Open original |
| Janady13/missionmatch / internal/integration/graph_market_integration_test.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/integration/graph_market_integration_test.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/integration/graph_market_integration_test.go | phase2-connectors | e038d4c687aec16f8bd9bc4d907eea14d91f8704 | Open original |
| Janady13/missionmatch / internal/integration/graph_market_integration_test.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/integration/graph_market_integration_test.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓249 lines · 11.6 KB
//go:build integration
package integration
import (
"context"
"encoding/json"
"testing"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"github.com/shopspring/decimal"
"github.com/missionworkforce/missionmatch/internal/modules/ai"
"github.com/missionworkforce/missionmatch/internal/platform/database/dbgen"
)
// seedMarketAward inserts one usaspending_awards row as the migrator (the global award catalog the app role
// may only read), so the G1 market traversals have real award structure to aggregate. It keys only on the
// columns usaspending_awards actually carries (awarding_agency, naics_code, recipient, award_amount, the
// period of performance), the honest segment key the competitor field and incumbent walk use.
func seedMarketAward(t *testing.T, genID, awardPIID, agency, naics, recipientUEI, recipientName, amount string, popEnd time.Time, isGalapagos bool) {
t.Helper()
if _, err := migrator.Exec(context.Background(),
`INSERT INTO usaspending_awards
(generated_internal_id, award_id, recipient_uei, recipient_name, awarding_agency, naics_code,
award_amount, pop_end_date, is_galapagos, raw)
VALUES ($1, $2, $3, $4, $5, $6, $7::numeric, $8, $9, '{}'::jsonb)
ON CONFLICT (generated_internal_id) DO NOTHING`,
genID, awardPIID, recipientUEI, recipientName, agency, naics, amount, popEnd, isGalapagos); err != nil {
t.Fatalf("seed market award %s: %v", genID, err)
}
}
// TestG1SegmentCompetitorField is the live proof of the recency weighted competitor field against real
// Postgres. It seeds a (agency, naics) segment with a dominant recipient and two smaller ones, plus the
// tenant's own past performance, then proves: the field comes back ordered share descending, the shares are
// exact decimals (never float64) that the dominant recipient leads, the tenant's own row is flagged
// is_galapagos, the contributing award count is the cited evidence, and the result is byte stable on a re
// run. The segment keys ONLY on (agency, naics), the only keys usaspending_awards carries.
func TestG1SegmentCompetitorField(t *testing.T) {
org := seedOrg(t)
run := uuid.NewString()[:8]
agency := "DEPT OF THE AIR FORCE " + run // unique per run so the segment is isolated
naics := "541512"
recent := time.Now().UTC().AddDate(0, -3, 0) // inside the lookback window
// A dominant incumbent, two challengers, and the tenant's own award, all in the same (agency, naics).
seedMarketAward(t, "G1-CF-"+run+"-1", "PIID-1", agency, naics, "UEIDOMINANT01", "Dominant Defense LLC", "8000000.00", recent, false)
seedMarketAward(t, "G1-CF-"+run+"-2", "PIID-2", agency, naics, "UEICHALLENG02", "Challenger Two LLC", "1500000.00", recent, false)
seedMarketAward(t, "G1-CF-"+run+"-3", "PIID-3", agency, naics, "UEICHALLENG03", "Challenger Three LLC", "500000.00", recent, false)
seedMarketAward(t, "G1-CF-"+run+"-4", "PIID-4", agency, naics, "UEIGALAPAGOS4", "Galapagos Federal", "1000000.00", recent, true)
rows, err := ai.SegmentCompetitorField(ctxOrg(org), appDB, agency, naics, ai.DefaultCompetitorLookbackYears)
if err != nil {
t.Fatalf("segment competitor field: %v", err)
}
if len(rows) != 4 {
t.Fatalf("the competitor field must return the four distinct recipients in the segment, got %d", len(rows))
}
// Ordered share descending: the dominant recipient leads, and every share is a decimal in 0 to 1.
if rows[0].RecipientUEI != "UEIDOMINANT01" {
t.Errorf("the dominant recipient must lead the field, got %q", rows[0].RecipientUEI)
}
prev := decimal.NewFromInt(2) // larger than any valid share
var total decimal.Decimal
for _, r := range rows {
if r.DollarShare.GreaterThan(prev) {
t.Errorf("the field must be ordered share descending; %s share %s exceeds the previous %s", r.RecipientUEI, r.DollarShare, prev)
}
prev = r.DollarShare
if r.DollarShare.LessThan(decimal.Zero) || r.DollarShare.GreaterThan(decimal.NewFromInt(1)) {
t.Errorf("a dollar share must be a decimal in 0 to 1, got %s for %s", r.DollarShare, r.RecipientUEI)
}
if r.AwardCount < 1 {
t.Errorf("the contributing award count (the evidence) must be at least 1, got %d for %s", r.AwardCount, r.RecipientUEI)
}
total = total.Add(r.DollarShare)
}
// The shares sum to 1 within numeric rounding: each share is dollars_i divided by the total, rounded to
// the numeric scale, so the sum of the rounded fractions can differ from 1 by a tiny residual (here on the
// order of 1e-20). That is mathematically unavoidable for divided decimals and harmless for a ranking and
// display figure; the decimal mandate is satisfied because no float64 touches the computation. Assert the
// sum is within a tight epsilon of 1, not bit exact.
if total.Sub(decimal.NewFromInt(1)).Abs().GreaterThan(decimal.RequireFromString("0.0000001")) {
t.Errorf("the dollar shares must sum to 1 within a tight epsilon in decimal, got %s", total)
}
// The tenant's own past performance is flagged is_galapagos so the capture team sees where it stands.
var sawGalapagos bool
for _, r := range rows {
if r.RecipientUEI == "UEIGALAPAGOS4" {
sawGalapagos = true
if !r.IsGalapagos {
t.Error("the tenant's own award row must be labeled is_galapagos")
}
}
}
if !sawGalapagos {
t.Error("the competitor field must include the tenant's own past performance row")
}
// Byte stable: the same input yields byte identical rows on a re run (the determinism mandate). The
// ORDER BY with the recipient_uei tiebreaker guarantees a single stable order.
again, err := ai.SegmentCompetitorField(ctxOrg(org), appDB, agency, naics, ai.DefaultCompetitorLookbackYears)
if err != nil {
t.Fatalf("segment competitor field re run: %v", err)
}
first, _ := json.Marshal(rows)
second, _ := json.Marshal(again)
if string(first) != string(second) {
t.Errorf("the competitor field must be byte stable on a re run.\nfirst: %s\nsecond: %s", first, second)
}
}
// TestG1IncumbentOfRecord proves the incumbent walk returns the predecessor award for an opportunity matched
// on (agency, naics) and the cross source dedupe key, with the prime recipient explicitly labeled
// prime-of-record (never the staffing subcontractor, the only incumbent the public award data supports).
func TestG1IncumbentOfRecord(t *testing.T) {
org := seedOrg(t)
run := uuid.NewString()[:8]
agency := "DEPT OF DEFENSE " + run
naics := "541330"
dedupe := "INCUMBENT-DEDUPE-" + run
// The predecessor award. The opportunity's dedupe_key matches the award's PIID, the cross source link.
seedMarketAward(t, "G1-INC-"+run, dedupe, agency, naics, "UEIINCUMBENT9", "Incumbent Prime LLC", "5000000.00",
time.Now().UTC().AddDate(0, 6, 0), false)
// The recompete opportunity that walks back to its predecessor award.
srcID := "G1-OPP-" + run
if err := dbgen.New(migrator).UpsertOpportunityRecord(context.Background(), dbgen.UpsertOpportunityRecordParams{
SourceName: "SAM.gov", SourceRecordID: srcID, DedupeKey: dedupe, RecordKind: "active_solicitation",
Title: "Engineering services recompete", Agency: agency, Naics: naics,
FetchedAt: time.Now().UTC(),
}); err != nil {
t.Fatalf("seed opportunity: %v", err)
}
// Resolve the opportunity id (gen_random_uuid primary key) so we can walk from it.
var oppID string
if err := migrator.QueryRow(context.Background(),
`SELECT id::text FROM opportunity_records WHERE source_name = 'SAM.gov' AND source_record_id = $1`, srcID).Scan(&oppID); err != nil {
t.Fatalf("resolve opportunity id: %v", err)
}
edges, err := ai.IncumbentOfRecord(ctxOrg(org), appDB, oppID)
if err != nil {
t.Fatalf("incumbent of record: %v", err)
}
if len(edges) == 0 {
t.Fatal("the incumbent walk must return the predecessor award matched on agency, naics, and the dedupe key")
}
e := edges[0]
if e.IncumbentUEI != "UEIINCUMBENT9" {
t.Errorf("the incumbent must be the prime recipient of the matched award, got %q", e.IncumbentUEI)
}
if e.IncumbentRole != "prime-of-record" {
t.Errorf("the incumbent edge must be labeled prime-of-record, got %q", e.IncumbentRole)
}
if e.AwardID != "G1-INC-"+run {
t.Errorf("the cited evidence must be the matched award, got %q", e.AwardID)
}
if e.AwardAmount == nil || !e.AwardAmount.Equal(decimal.RequireFromString("5000000.00")) {
t.Errorf("the matched award amount must be the decimal 5000000.00, got %v", e.AwardAmount)
}
}
// TestG1RecompetePipeline proves the recompete pipeline returns the opportunities and awards whose period of
// performance end falls inside the forward window, ordered by that end date with a record id tiebreaker, each
// row carrying its source so an award is never conflated with an opportunity. It is byte stable on a re run.
func TestG1RecompetePipeline(t *testing.T) {
org := seedOrg(t)
run := uuid.NewString()[:8]
agency := "DEPT OF THE NAVY " + run
insideWindow := time.Now().UTC().AddDate(0, 6, 0) // 6 months out, inside the 24 month window
outsideWindow := time.Now().UTC().AddDate(5, 0, 0) // 5 years out, past the window
// An award ending inside the window (a takeaway target) and one ending far outside it (must not appear).
seedMarketAward(t, "G1-RC-IN-"+run, "PIID-IN", agency, "541512", "UEIAWARDIN001", "Award In Window LLC", "3000000.00", insideWindow, false)
seedMarketAward(t, "G1-RC-OUT-"+run, "PIID-OUT", agency, "541512", "UEIAWARDOUT01", "Award Out Window LLC", "3000000.00", outsideWindow, false)
// An opportunity ending inside the window.
oppSrc := "G1-RC-OPP-" + run
estVal := decimal.RequireFromString("4250000.00")
if err := dbgen.New(migrator).UpsertOpportunityRecord(context.Background(), dbgen.UpsertOpportunityRecordParams{
SourceName: "SAM.gov", SourceRecordID: oppSrc, RecordKind: "active_solicitation",
Title: "Logistics recompete", Agency: agency, Naics: "541512",
IncumbentUei: "UEIOPPINCUMB1", EstimatedValue: &estVal, ValueSource: "operator",
PopEndDate: pgtype.Date{Time: insideWindow, Valid: true},
FetchedAt: time.Now().UTC(),
}); err != nil {
t.Fatalf("seed pipeline opportunity: %v", err)
}
rows, err := ai.RecompetePipeline(ctxOrg(org), appDB, agency, ai.DefaultRecompeteWindowMonths)
if err != nil {
t.Fatalf("recompete pipeline: %v", err)
}
if len(rows) != 2 {
t.Fatalf("the pipeline must return exactly the award and the opportunity inside the window, got %d", len(rows))
}
var sawAward, sawOpp bool
prev := time.Time{}
for _, r := range rows {
// Ordered by pop_end_date ascending: each end date is at or after the previous, a total order.
end, perr := time.Parse("2006-01-02", r.PopEndDate)
if perr != nil {
t.Fatalf("the pop end date must be a stable ISO date, got %q", r.PopEndDate)
}
if end.Before(prev) {
t.Errorf("the pipeline must be ordered by pop end date ascending; %s precedes the previous %s", end, prev)
}
prev = end
switch r.SourceTable {
case "usaspending_awards":
sawAward = true
if r.RecordID != "G1-RC-IN-"+run {
t.Errorf("only the in window award may appear, got %q", r.RecordID)
}
case "opportunity_records":
sawOpp = true
if r.Dollars == nil || !r.Dollars.Equal(decimal.RequireFromString("4250000.00")) {
t.Errorf("the opportunity dollars must be the decimal 4250000.00, got %v", r.Dollars)
}
default:
t.Errorf("a pipeline row must carry a known source table, got %q", r.SourceTable)
}
}
if !sawAward || !sawOpp {
t.Errorf("the pipeline must include both the in window award and the in window opportunity (award %v, opp %v)", sawAward, sawOpp)
}
// Byte stable on a re run.
again, err := ai.RecompetePipeline(ctxOrg(org), appDB, agency, ai.DefaultRecompeteWindowMonths)
if err != nil {
t.Fatalf("recompete pipeline re run: %v", err)
}
first, _ := json.Marshal(rows)
second, _ := json.Marshal(again)
if string(first) != string(second) {
t.Errorf("the recompete pipeline must be byte stable on a re run.\nfirst: %s\nsecond: %s", first, second)
}
}