Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/integration/fairness_snapshot_integration_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/integration/fairness_snapshot_integration_test.go |
| Original SHA-256 | 2dc1a4a315440f8924dd7bf458bcfab3df3a835e946e78992baf8349705e80b6 |
| Git blob SHA | 7268b7daacb39ab1d10e7f4ec7fe7033d8f076f7 |
| Reading-copy SHA-256 | 2dc1a4a315440f8924dd7bf458bcfab3df3a835e946e78992baf8349705e80b6 |
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/fairness_snapshot_integration_test.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/integration/fairness_snapshot_integration_test.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/integration/fairness_snapshot_integration_test.go | m5-price-to-win | 41000ad30fff4129fdaf5ec84e15ba14c27d4890 | Open original |
| Janady13/missionmatch / internal/integration/fairness_snapshot_integration_test.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/integration/fairness_snapshot_integration_test.go | mag-substrate | b82c7100a492dec67dfd1eda6b3f53def859be35 | Open original |
| Janady13/missionmatch / internal/integration/fairness_snapshot_integration_test.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/integration/fairness_snapshot_integration_test.go | graphrag-foundation | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 | Open original |
| Janady13/missionmatch / internal/integration/fairness_snapshot_integration_test.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/integration/fairness_snapshot_integration_test.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/integration/fairness_snapshot_integration_test.go | phase2-connectors | e038d4c687aec16f8bd9bc4d907eea14d91f8704 | Open original |
| Janady13/missionmatch / internal/integration/fairness_snapshot_integration_test.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/integration/fairness_snapshot_integration_test.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓171 lines · 7.7 KB
//go:build integration
package integration
// TestFairnessSnapshotTimeSeries proves the continuous adverse impact four fifths time series end to
// end against a real Postgres with the segregated eeo schema and the second eeo migration applied.
//
// It seeds a small demographic distribution, runs SnapshotAdverseImpact through the COMPLIANCE pool,
// and asserts one fairness_snapshots row per group is appended with the correct selection_rate and
// below_threshold flag. It then seeds a worse second batch, snapshots again, and asserts FairnessTrend
// returns the per group series and raises the drift alert when the female impact ratio crosses below
// 0.80. Finally it proves the isolation contract: the app role (MM_APP_DSN) is permission denied on
// eeo.fairness_snapshots, so the snapshots are reachable ONLY through the compliance pool.
//
// EEO isolation contract (non negotiable): demographics and snapshots are written and read ONLY through
// the compliance pool. No matching, scoring, or AI code file is touched, and no demographic value or per
// person row ever enters the matching path. This file imports eeo and tenant only.
import (
"context"
"testing"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/missionworkforce/missionmatch/internal/modules/eeo"
"github.com/missionworkforce/missionmatch/internal/platform/tenant"
)
// seedSelectionBlock seeds n decided slate members of one demographic gender, of which selected are
// approved and the rest rejected, with a fixed race so the by sex cut is the one under test. It writes
// the demographics through the compliance pool, exactly like the existing eeo integration tests.
func seedSelectionBlock(t *testing.T, org, slateID uuid.UUID, gender string, considered, selected int) {
t.Helper()
for i := 0; i < considered; i++ {
decision := "rejected"
if i < selected {
decision = "approved"
}
c := seedDecidedMember(t, org, slateID, decision)
seedDemographic(t, org, c, gender, "groupR")
}
}
func findSeries(series []eeo.FairnessSeries, decisionContext, group string) (eeo.FairnessSeries, bool) {
for _, s := range series {
if s.DecisionContext == decisionContext && s.GroupLabel == group {
return s, true
}
}
return eeo.FairnessSeries{}, false
}
func TestFairnessSnapshotTimeSeries(t *testing.T) {
if compliance == nil {
t.Skip("compliance pool not configured (MM_COMPLIANCE_DSN); skipping fairness snapshot integration")
}
ctx := context.Background()
svc := eeo.NewService(tenant.New(compliance))
// First batch: male 8/10 (rate 0.80, reference), female 7/10 (rate 0.70).
// Female ratio = 0.70 / 0.80 = 0.875, ABOVE the 0.80 threshold, so the first snapshot does not flag.
org := seedOrg(t)
slate1 := seedSlate(t, org)
seedSelectionBlock(t, org, slate1, "male", 10, 8)
seedSelectionBlock(t, org, slate1, "female", 10, 7)
t1 := time.Now().Add(-1 * time.Hour)
sum1, err := svc.SnapshotAdverseImpact(ctxOrg(org), t1)
if err != nil {
t.Fatalf("SnapshotAdverseImpact (first): %v", err)
}
if sum1.GroupsWritten == 0 {
t.Fatalf("first snapshot wrote no group rows")
}
// Assert one snapshot row per group was written with the correct selection_rate and below_threshold.
// The by sex selection cut carries a male reference (rate 0.80, the highest rate, so its ratio is a
// passing 1.0 against itself) and a female row (rate 0.70, ratio 0.875, not below threshold). The
// snapshot stores exactly what the report computes, so the reference group has a 1.0 ratio, not null;
// null is reserved for an n/a row (an unknown group or a cut with fewer than two known groups). Read
// back through the compliance pool under RLS.
const sexCtx = "selection (recorded slate decisions) :: by sex"
assertSnapshotRow(t, org, t1, sexCtx, "male", "0.800000", true, false)
assertSnapshotRow(t, org, t1, sexCtx, "female", "0.700000", true, false)
// Second batch: a fresh slate that drives the female rate down so the ratio crosses 0.80.
// To build a TWO point series for the SAME org, append a second slate to the same org with a worse
// female outcome, then snapshot again at a later instant. The report aggregates all decided members
// in the org, so the combined female rate falls and the ratio crosses below 0.80.
//
// After batch 2 the org totals are: male approved 8 of 10 (rate 0.80, still the reference), female
// approved 7 of 22 (7 from batch 1 plus 0 of 12 new), rate 0.318, ratio 0.318 / 0.80 = 0.398, BELOW
// the 0.80 threshold. So the female series goes 0.875 then 0.398, a drop that crosses the threshold.
slate2 := seedSlate(t, org)
seedSelectionBlock(t, org, slate2, "female", 12, 0)
t2 := time.Now()
sum2, err := svc.SnapshotAdverseImpact(ctxOrg(org), t2)
if err != nil {
t.Fatalf("SnapshotAdverseImpact (second): %v", err)
}
if sum2.BelowThreshold == 0 {
t.Fatalf("second snapshot should have at least one below threshold group (female), got 0")
}
// FairnessTrend must return the female by sex series with two points and the drift alert raised,
// because the latest impact ratio is now below 0.80.
series, err := svc.FairnessTrend(ctxOrg(org), t1.Add(-time.Hour))
if err != nil {
t.Fatalf("FairnessTrend: %v", err)
}
female, ok := findSeries(series, sexCtx, "female")
if !ok {
t.Fatalf("female by sex series missing from trend: %+v", series)
}
if len(female.Points) != 2 {
t.Fatalf("female series should have 2 points, got %d: %+v", len(female.Points), female.Points)
}
if female.Points[0].ImpactRatio != "0.8750" {
t.Fatalf("first female point ratio should be 0.8750 (above threshold), got %s", female.Points[0].ImpactRatio)
}
if !female.Alert {
t.Fatalf("female series must alert after the ratio crossed below 0.80, latest %s", female.Points[1].ImpactRatio)
}
// Isolation proof: the app role must be permission denied on eeo.fairness_snapshots.
if _, err := appDB.Pool.Exec(ctx, "SELECT 1 FROM eeo.fairness_snapshots LIMIT 1"); pgCode(err) != "42501" {
t.Fatalf("app role must be denied eeo.fairness_snapshots access (42501), got %v", err)
}
// The compliance role can reach it (RLS may legitimately return rows only for the scoped org).
if _, err := compliance.Exec(ctx, "SELECT 1 FROM eeo.fairness_snapshots LIMIT 1"); err != nil {
t.Fatalf("compliance role should access eeo.fairness_snapshots, got %v", err)
}
}
// assertSnapshotRow reads back one appended fairness_snapshots row through the compliance pool under RLS
// and asserts its selection_rate, whether it has an impact ratio, and its below_threshold flag. The rate
// is compared as the numeric(7,6) text form (for example "0.800000").
func assertSnapshotRow(t *testing.T, org uuid.UUID, snapAt time.Time, decisionContext, group, wantRate string, wantHasRatio, wantBelow bool) {
t.Helper()
var (
rate string
ratio *string
below bool
)
// A missing row surfaces as pgx.ErrNoRows from QueryRow, caught by the error check below.
err := tenant.New(compliance).RunInTenantTx(ctxOrg(org), func(ctx context.Context, tx pgx.Tx) error {
return tx.QueryRow(ctx,
`SELECT selection_rate::text, impact_ratio::text, below_threshold
FROM eeo.fairness_snapshots
WHERE decision_context=$1 AND group_label=$2
AND snapshot_at >= $3 AND snapshot_at < $4
ORDER BY snapshot_at DESC LIMIT 1`,
decisionContext, group, snapAt.Add(-time.Minute), snapAt.Add(time.Minute)).Scan(&rate, &ratio, &below)
})
if err != nil {
t.Fatalf("read back snapshot row (%s / %s): %v", decisionContext, group, err)
}
if rate != wantRate {
t.Fatalf("%s / %s selection_rate = %s, want %s", decisionContext, group, rate, wantRate)
}
if wantHasRatio != (ratio != nil) {
t.Fatalf("%s / %s impact_ratio present = %v, want %v", decisionContext, group, ratio != nil, wantHasRatio)
}
if below != wantBelow {
t.Fatalf("%s / %s below_threshold = %v, want %v", decisionContext, group, below, wantBelow)
}
}
Mathematical records from this source
0102
func TestFairnessSnapshotTimeSeries(t *testing.T) · Female ratio
This relation defines Female ratio in the source section “func TestFairnessSnapshotTimeSeries(t *testing.T) · Female ratio”. It specifies the displayed relationship between the…
func TestFairnessSnapshotTimeSeries(t *testing.T) · approved 7 of 22 (7 from batch 1 plus 0 of 12 new), rate 0.318, ratio 0.318 / 0.80
This relation defines approved 7 of 22 (7 from batch 1 plus 0 of 12 new), rate 0.318, ratio 0.318 / 0.80 in the source section “func TestFairnessSnapshotTimeSeries(t *testing.T) ·…