Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/integration/mag_timetofill_integration_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/integration/mag_timetofill_integration_test.go |
| Original SHA-256 | aedb678ca151cdef0a02c2fcd0f9666aef9d2c5b5d3bde274f8cda185850f8c3 |
| Git blob SHA | 7adf111f7f141f1ce0b6ae92160e50c6312f0e5b |
| Reading-copy SHA-256 | aedb678ca151cdef0a02c2fcd0f9666aef9d2c5b5d3bde274f8cda185850f8c3 |
Every recorded occurrence
These 8 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/mag_timetofill_integration_test.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/integration/mag_timetofill_integration_test.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/integration/mag_timetofill_integration_test.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/integration/mag_timetofill_integration_test.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/integration/mag_timetofill_integration_test.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/integration/mag_timetofill_integration_test.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/integration/mag_timetofill_integration_test.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/integration/mag_timetofill_integration_test.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓136 lines · 5.6 KB
//go:build integration
// MAG time to fill survival loop integration. Proves at runtime against a REAL Postgres and the migrated 0039
// prior only baseline what the unit tests cannot: the offline TRAINER estimates the empirical discrete time
// hazard from requirement fill durations (created to first approved slate member, or right censored when still
// open), the EVALUATOR compares the challenger's fill within horizon calibration to the prior only constant
// baseline, a human promotion flips the champion, and the served fill within horizon probability then reflects
// the LEARNED hazard, with the frozen engine untouched (this is an opportunity level forecast, never a candidate
// score).
//
// Run: go test -tags=integration ./internal/integration/ -run MAGTimeToFill -v
// Env: MM_APP_DSN, MM_MIGRATOR_DSN, MM_COMPLIANCE_DSN.
package integration
import (
"context"
"testing"
"github.com/missionworkforce/missionmatch/internal/platform/magstore"
)
func TestMAGTimeToFillTrainsEvaluatesPromotesAndServes(t *testing.T) {
modelKey := magstore.TimeToFillModelKey
const priorOnlyVersion = 1
ctx := context.Background()
if _, err := magstore.PromoteChampion(ctx, migrator, modelKey, priorOnlyVersion); err != nil {
t.Fatalf("reset time to fill champion: %v", err)
}
t.Cleanup(func() {
if _, cerr := magstore.PromoteChampion(ctx, migrator, modelKey, priorOnlyVersion); cerr != nil {
t.Logf("cleanup: could not restore prior only time to fill champion: %v", cerr)
}
})
// Seed a handful of FILLED requirements (an approved slate member is the fill event) so the pooled fit has a
// fill signal to learn from. Each is created and decided in this run, so it fills at month 1.
org := seedOrg(t)
approved := [6]float64{50, 50, 50, 50, 50, 50}
for i := 0; i < 6; i++ {
seedDecidedSlate(t, org, []memberSpec{
{approved: true, features: approved},
{approved: false, features: approved},
})
}
// The prior only champion forecasts P(fill within 3) from the constant 0.25 monthly hazard (about 0.578).
champV1, err := magstore.LoadModel(ctx, migrator, modelKey, priorOnlyVersion)
if err != nil {
t.Fatalf("load prior only champion: %v", err)
}
priorFill3 := magstore.FillWithinHorizon(champV1, 3)
t.Logf("prior only P(fill within 3 months) = %.4f", priorFill3)
// TRAIN: estimate the empirical hazard challenger. min 5 requirements so the pooled staging set clears it.
res, err := magstore.TrainTimeToFill(ctx, migrator, modelKey, 5, false)
if err != nil {
t.Fatalf("train time to fill: %v", err)
}
if res.Skipped {
t.Fatalf("the fit must not be skipped with %d requirements (%d filled): %s", res.Requirements, res.Filled, res.SkipReason)
}
if res.Version <= priorOnlyVersion {
t.Fatalf("the challenger version %d must be newer than the prior", res.Version)
}
if len(res.Hazard) != magstore.HorizonMonths {
t.Fatalf("the hazard curve must have %d months, got %d", magstore.HorizonMonths, len(res.Hazard))
}
anyHazard := false
for _, h := range res.Hazard {
if h > 0 {
anyHazard = true
}
if h < 0 || h > 1 {
t.Fatalf("every hazard must be a probability in [0,1], got %v", res.Hazard)
}
}
if !anyHazard {
t.Fatal("with filled requirements in the pool at least one month must carry a positive hazard")
}
t.Logf("challenger v%d learned hazard month 1 = %.4f over %d requirements (%d filled)", res.Version, res.Hazard[0], res.Requirements, res.Filled)
// The trainer must NOT flip champion.
stillV1, err := magstore.ChampionVersion(ctx, migrator, modelKey)
if err != nil {
t.Fatalf("champion after train: %v", err)
}
if stillV1 != priorOnlyVersion {
t.Fatalf("the trainer must not flip champion, moved to v%d", stillV1)
}
chal, err := magstore.LoadModel(ctx, migrator, modelKey, res.Version)
if err != nil {
t.Fatalf("load challenger: %v", err)
}
chalFill3 := magstore.FillWithinHorizon(chal, 3)
if chalFill3 < 0 || chalFill3 > 1 {
t.Fatalf("the learned P(fill within 3) must be a probability, got %v", chalFill3)
}
if chalFill3 == priorFill3 {
t.Fatalf("the learned forecast must differ from the constant prior, both %v", chalFill3)
}
// EVALUATE calibration at a 1 month horizon (robustly decidable regardless of the staging data age): the
// challenger empirical hazard must calibrate at least as well as the arbitrary constant prior.
quality, err := magstore.EvaluateTimeToFill(ctx, migrator, champV1, chal, 1, 0.30)
if err != nil {
t.Fatalf("evaluate time to fill: %v", err)
}
t.Logf("horizon 1: %d decidable, observed fill rate %.4f, P champion %.4f vs challenger %.4f, ECE champion %.4f vs challenger %.4f",
quality.Evaluated, quality.FillRate, quality.ChampPred, quality.ChalPred, quality.ChampECE, quality.ChalECE)
if quality.Evaluated == 0 {
t.Fatal("the held out split must have decidable requirements at a 1 month horizon")
}
if !quality.Pass {
t.Errorf("the empirical challenger must clear the calibration gate against the arbitrary prior, got %+v", quality)
}
// PROMOTE and serve: the champion forecast now reflects the learned hazard.
from, err := magstore.PromoteChampion(ctx, migrator, modelKey, res.Version)
if err != nil {
t.Fatalf("promote: %v", err)
}
if from != priorOnlyVersion {
t.Errorf("the promotion must replace the prior champion v%d, replaced v%d", priorOnlyVersion, from)
}
champNew, err := magstore.LoadModel(ctx, migrator, modelKey, res.Version)
if err != nil {
t.Fatalf("load new champion: %v", err)
}
if got := magstore.FillWithinHorizon(champNew, 3); got != chalFill3 {
t.Fatalf("the served forecast must reflect the learned hazard %v, got %v", chalFill3, got)
}
t.Logf("promoted: served P(fill within 3) moved from prior %.4f to learned %.4f", priorFill3, chalFill3)
}