Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/integration/graph_lifecycle_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_lifecycle_integration_test.go |
| Original SHA-256 | a8be4b2b5447597111355eeaf5d82212fdca2ef8614e568fbcdedc40b412fbaa |
| Git blob SHA | 026c3fa068b355ada685606afe6981545bf530c8 |
| Reading-copy SHA-256 | a8be4b2b5447597111355eeaf5d82212fdca2ef8614e568fbcdedc40b412fbaa |
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_lifecycle_integration_test.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/integration/graph_lifecycle_integration_test.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/integration/graph_lifecycle_integration_test.go | m5-price-to-win | 41000ad30fff4129fdaf5ec84e15ba14c27d4890 | Open original |
| Janady13/missionmatch / internal/integration/graph_lifecycle_integration_test.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/integration/graph_lifecycle_integration_test.go | mag-substrate | b82c7100a492dec67dfd1eda6b3f53def859be35 | Open original |
| Janady13/missionmatch / internal/integration/graph_lifecycle_integration_test.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/integration/graph_lifecycle_integration_test.go | graphrag-foundation | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 | Open original |
| Janady13/missionmatch / internal/integration/graph_lifecycle_integration_test.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/integration/graph_lifecycle_integration_test.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/integration/graph_lifecycle_integration_test.go | phase2-connectors | e038d4c687aec16f8bd9bc4d907eea14d91f8704 | Open original |
| Janady13/missionmatch / internal/integration/graph_lifecycle_integration_test.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/integration/graph_lifecycle_integration_test.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓283 lines · 12.8 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"
)
// seedLifecyclePhase inserts one opportunity_records phase (forecast, active_solicitation, or contract_award)
// through the migrator (the global catalog the app role may only read), carrying the FULL (agency, naics,
// psc, pop_state, set_aside) segment tuple plus the shared dedupe_key that links the phases, so the G9
// succession has a real lifecycle to walk. The contract_award phase carries the prior estimated_value and
// incumbent UEI; the forecast phase carries the estimated_award_date. It returns the generated uuid so the
// anchor solicitation can be walked.
func seedLifecyclePhase(t *testing.T, srcID, dedupe, kind, agency, naics, psc, popState, setAside string,
estVal *decimal.Decimal, incumbentUEI, incumbentName string, awardDate, estAwardDate, popEnd pgtype.Date) string {
t.Helper()
if err := dbgen.New(migrator).UpsertOpportunityRecord(context.Background(), dbgen.UpsertOpportunityRecordParams{
SourceName: "SAM.gov", SourceRecordID: srcID, DedupeKey: dedupe, RecordKind: kind,
Title: "Mission support " + kind, Agency: agency, Naics: naics, Psc: psc, PopState: popState,
SetAside: setAside, EstimatedValue: estVal, ValueSource: "operator",
IncumbentUei: incumbentUEI, IncumbentName: incumbentName,
AwardDate: awardDate, EstimatedAwardDate: estAwardDate, PopEndDate: popEnd,
IsPlanning: kind == "forecast", FetchedAt: time.Now().UTC(),
}); err != nil {
t.Fatalf("seed lifecycle phase %s (%s): %v", srcID, kind, err)
}
var id 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(&id); err != nil {
t.Fatalf("resolve lifecycle phase id %s: %v", srcID, err)
}
return id
}
// TestG9ProcurementSuccession is the live proof of the recompete lifecycle walk against real Postgres. It
// seeds one lifecycle in the SAME (agency, naics, psc, pop_state, set_aside) segment sharing one dedupe_key, a
// forecast, an active_solicitation anchor, and a predecessor contract_award, then proves the succession from
// the solicitation returns is_recompete true (a predecessor was found), the prior award amount as an exact
// decimal, the prior prime UEI explicitly labeled prime-of-record, and the announcing forecast, with the cited
// record ids. A second solicitation with no predecessor returns is_new true.
func TestG9ProcurementSuccession(t *testing.T) {
org := seedOrg(t)
run := uuid.NewString()[:8]
agency := "DEPT OF THE AIR FORCE " + run
naics, psc, popState, setAside := "541512", "R425", "HI", "SBA"
dedupe := "LIFECYCLE-DEDUPE-" + run
priorAmt := decimal.RequireFromString("7500000.00")
awardDate := pgtype.Date{Time: time.Now().UTC().AddDate(-3, 0, 0), Valid: true}
estAwardDate := pgtype.Date{Time: time.Now().UTC().AddDate(0, 4, 0), Valid: true}
// The predecessor contract award (the prior prime of record), the announcing forecast, and the anchor
// solicitation, all sharing the dedupe_key and the full segment tuple.
predID := seedLifecyclePhase(t, "G9-AWD-"+run, dedupe, "contract_award", agency, naics, psc, popState, setAside,
&priorAmt, "UEIPRIORPRIME", "Prior Prime LLC", awardDate, pgtype.Date{}, pgtype.Date{})
fcastID := seedLifecyclePhase(t, "G9-FCAST-"+run, dedupe, "forecast", agency, naics, psc, popState, setAside,
nil, "", "", pgtype.Date{}, estAwardDate, pgtype.Date{})
solID := seedLifecyclePhase(t, "G9-SOL-"+run, dedupe, "active_solicitation", agency, naics, psc, popState, setAside,
nil, "", "", pgtype.Date{}, pgtype.Date{}, pgtype.Date{})
rows, err := ai.ProcurementSuccession(ctxOrg(org), appDB, solID)
if err != nil {
t.Fatalf("procurement succession: %v", err)
}
if len(rows) != 1 {
t.Fatalf("the succession must return exactly the one anchored solicitation row, got %d", len(rows))
}
r := rows[0]
if r.SolicitationID != solID {
t.Errorf("the anchor must be the named solicitation, got %q", r.SolicitationID)
}
if !r.IsRecompete || r.IsNew {
t.Errorf("a solicitation with a predecessor award must read is_recompete true and is_new false, got recompete %v new %v", r.IsRecompete, r.IsNew)
}
if r.PredecessorAwardID != predID {
t.Errorf("the cited predecessor must be the matched award, got %q want %q", r.PredecessorAwardID, predID)
}
if r.IncumbentUEI != "UEIPRIORPRIME" {
t.Errorf("the prior prime UEI must be the predecessor incumbent, got %q", r.IncumbentUEI)
}
if r.IncumbentRole != "prime-of-record" {
t.Errorf("the incumbent edge must be labeled prime-of-record, got %q", r.IncumbentRole)
}
if r.PriorAwardAmount == nil || !r.PriorAwardAmount.Equal(priorAmt) {
t.Errorf("the prior award amount must be the decimal 7500000.00, got %v", r.PriorAwardAmount)
}
if r.ForecastID != fcastID {
t.Errorf("the announcing forecast must be cited, got %q want %q", r.ForecastID, fcastID)
}
// A second solicitation in a fresh segment with no predecessor reads as a new start.
freshDedupe := "LIFECYCLE-NEW-" + run
newSolID := seedLifecyclePhase(t, "G9-NEW-"+run, freshDedupe, "active_solicitation",
"DEPT OF THE NAVY "+run, "541330", "R408", "VA", "FULL", nil, "", "", pgtype.Date{}, pgtype.Date{}, pgtype.Date{})
newRows, err := ai.ProcurementSuccession(ctxOrg(org), appDB, newSolID)
if err != nil {
t.Fatalf("procurement succession (new start): %v", err)
}
if len(newRows) != 1 {
t.Fatalf("the new start succession must return one row, got %d", len(newRows))
}
if newRows[0].IsRecompete || !newRows[0].IsNew {
t.Errorf("a solicitation with no predecessor must read is_new true and is_recompete false, got recompete %v new %v",
newRows[0].IsRecompete, newRows[0].IsNew)
}
if newRows[0].PriorAwardAmount != nil {
t.Errorf("a new start must carry no prior award amount, got %v", newRows[0].PriorAwardAmount)
}
// Byte stable on a re run (the determinism mandate).
again, err := ai.ProcurementSuccession(ctxOrg(org), appDB, solID)
if err != nil {
t.Fatalf("procurement succession re run: %v", err)
}
first, _ := json.Marshal(rows)
second, _ := json.Marshal(again)
if string(first) != string(second) {
t.Errorf("the succession must be byte stable on a re run.\nfirst: %s\nsecond: %s", first, second)
}
}
// TestG9RecompeteClock proves the recompete clock returns the opportunities and awards whose period of
// performance end falls inside the forward window for an agency, ordered by that end date with a record id
// tiebreaker, each row carrying its source so an award is never conflated with an opportunity, the incumbent
// prime labeled prime-of-record, the dollars exact decimals, and the result byte stable. The award arm keys
// ONLY on awarding_agency, the only agency key usaspending_awards carries.
func TestG9RecompeteClock(t *testing.T) {
org := seedOrg(t)
run := uuid.NewString()[:8]
agency := "DEPT OF DEFENSE " + run
insideWindow := time.Now().UTC().AddDate(0, 6, 0) // inside the 24 month window
outsideWindow := time.Now().UTC().AddDate(5, 0, 0) // past the window
// An award ending inside the window and one far outside it (must not appear), reusing the G1 award seeder.
seedMarketAward(t, "G9-RC-IN-"+run, "PIID-IN", agency, "541512", "UEIAWARDIN999", "Award In Window LLC", "3000000.00", insideWindow, false)
seedMarketAward(t, "G9-RC-OUT-"+run, "PIID-OUT", agency, "541512", "UEIAWARDOUT99", "Award Out Window LLC", "3000000.00", outsideWindow, false)
// An opportunity ending inside the window.
estVal := decimal.RequireFromString("4250000.00")
_ = seedLifecyclePhase(t, "G9-RC-OPP-"+run, "G9-RC-OPP-"+run, "active_solicitation",
agency, "541512", "R425", "HI", "SBA", &estVal, "UEIOPPINCUMB9", "Opp Incumbent LLC",
pgtype.Date{}, pgtype.Date{}, pgtype.Date{Time: insideWindow, Valid: true})
rows, err := ai.RecompeteClock(ctxOrg(org), appDB, agency, ai.DefaultRecompeteWindowMonths)
if err != nil {
t.Fatalf("recompete clock: %v", err)
}
if len(rows) != 2 {
t.Fatalf("the clock must return exactly the in window award and opportunity, got %d", len(rows))
}
var sawAward, sawOpp bool
prev := time.Time{}
for _, r := range rows {
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 clock must be ordered by pop end date ascending; %s precedes %s", end, prev)
}
prev = end
if r.IncumbentRole != "prime-of-record" {
t.Errorf("every clock row must label the incumbent prime-of-record, got %q", r.IncumbentRole)
}
switch r.SourceTable {
case "usaspending_awards":
sawAward = true
if r.RecordID != "G9-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 clock row must carry a known source table, got %q", r.SourceTable)
}
}
if !sawAward || !sawOpp {
t.Errorf("the clock must include both the in window award and opportunity (award %v, opp %v)", sawAward, sawOpp)
}
again, err := ai.RecompeteClock(ctxOrg(org), appDB, agency, ai.DefaultRecompeteWindowMonths)
if err != nil {
t.Fatalf("recompete clock re run: %v", err)
}
first, _ := json.Marshal(rows)
second, _ := json.Marshal(again)
if string(first) != string(second) {
t.Errorf("the recompete clock must be byte stable on a re run.\nfirst: %s\nsecond: %s", first, second)
}
}
// TestG9ForecastRunway proves the forecast runway returns the forecasts whose estimated award date falls
// inside the forward window, joined to the federal mission area and carrying the place of performance state,
// ordered by estimated award date with an id tiebreaker, the dollars exact decimals, and byte stable. A
// forecast landing outside the window does not appear.
func TestG9ForecastRunway(t *testing.T) {
org := seedOrg(t)
run := uuid.NewString()[:8]
agency := "DEPT OF THE ARMY " + run
inside := pgtype.Date{Time: time.Now().UTC().AddDate(0, 5, 0), Valid: true} // inside a 12 month window
outside := pgtype.Date{Time: time.Now().UTC().AddDate(3, 0, 0), Valid: true} // 3 years out
estVal := decimal.RequireFromString("9100000.00")
insideID := seedLifecyclePhase(t, "G9-FR-IN-"+run, "G9-FR-IN-"+run, "forecast",
agency, "541512", "R425", "NM", "8A", &estVal, "", "", pgtype.Date{}, inside, pgtype.Date{})
_ = seedLifecyclePhase(t, "G9-FR-OUT-"+run, "G9-FR-OUT-"+run, "forecast",
agency, "541512", "R425", "NM", "8A", nil, "", "", pgtype.Date{}, outside, pgtype.Date{})
// Tag the in window forecast SIGINT so the runway carries the readable mission area.
if err := dbgen.New(migrator).UpsertFederalMissionTag(context.Background(), dbgen.UpsertFederalMissionTagParams{
RecordTable: "opportunity_records", RecordID: insideID, MissionCode: "SIGINT",
Mechanism: "keyword", Evidence: "signals intelligence", Confidence: decimal.RequireFromString("1.00"),
}); err != nil {
t.Fatalf("tag forecast: %v", err)
}
rows, err := ai.ForecastRunway(ctxOrg(org), appDB, 12)
if err != nil {
t.Fatalf("forecast runway: %v", err)
}
var sawInside, sawOutside bool
prev := time.Time{}
for _, r := range rows {
d, perr := time.Parse("2006-01-02", r.EstimatedAwardDate)
if perr != nil {
t.Fatalf("the estimated award date must be a stable ISO date, got %q", r.EstimatedAwardDate)
}
if d.Before(prev) {
t.Errorf("the runway must be ordered by estimated award date ascending; %s precedes %s", d, prev)
}
prev = d
if r.ForecastID == insideID {
sawInside = true
if r.PopState != "NM" {
t.Errorf("the forecast must carry its place of performance state, got %q", r.PopState)
}
if r.MissionCode != "SIGINT" || r.MissionArea == "" {
t.Errorf("the in window forecast must carry the SIGINT mission area, got code %q area %q", r.MissionCode, r.MissionArea)
}
if r.Dollars == nil || !r.Dollars.Equal(decimal.RequireFromString("9100000.00")) {
t.Errorf("the forecast dollars must be the decimal 9100000.00, got %v", r.Dollars)
}
}
if r.ForecastID == "G9-FR-OUT-"+run {
sawOutside = true
}
}
if !sawInside {
t.Error("the runway must include the in window forecast")
}
if sawOutside {
t.Error("the runway must NOT include the forecast landing outside the window")
}
again, err := ai.ForecastRunway(ctxOrg(org), appDB, 12)
if err != nil {
t.Fatalf("forecast runway re run: %v", err)
}
first, _ := json.Marshal(rows)
second, _ := json.Marshal(again)
if string(first) != string(second) {
t.Errorf("the forecast runway must be byte stable on a re run.\nfirst: %s\nsecond: %s", first, second)
}
}