Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/modules/ai/graph_teaming_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/modules/ai/graph_teaming_test.go |
| Original SHA-256 | a12b3037458fe945b7125d1377ce950d1afb9734c36d23f610b4ba91d33de17a |
| Git blob SHA | 36fd0f6e63d07930f4db7b930dfbe0ea85d9ae42 |
| Reading-copy SHA-256 | a12b3037458fe945b7125d1377ce950d1afb9734c36d23f610b4ba91d33de17a |
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/modules/ai/graph_teaming_test.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/modules/ai/graph_teaming_test.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/modules/ai/graph_teaming_test.go | m5-price-to-win | 41000ad30fff4129fdaf5ec84e15ba14c27d4890 | Open original |
| Janady13/missionmatch / internal/modules/ai/graph_teaming_test.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/modules/ai/graph_teaming_test.go | mag-substrate | b82c7100a492dec67dfd1eda6b3f53def859be35 | Open original |
| Janady13/missionmatch / internal/modules/ai/graph_teaming_test.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/modules/ai/graph_teaming_test.go | graphrag-foundation | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 | Open original |
| Janady13/missionmatch / internal/modules/ai/graph_teaming_test.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/modules/ai/graph_teaming_test.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/modules/ai/graph_teaming_test.go | phase2-connectors | e038d4c687aec16f8bd9bc4d907eea14d91f8704 | Open original |
| Janady13/missionmatch / internal/modules/ai/graph_teaming_test.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/modules/ai/graph_teaming_test.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓358 lines · 16.9 KB
package ai
import (
"strings"
"testing"
)
// TestGraphTeamingIntentsAreRegistered proves the three G2 vendor co occurrence and teaming field traversals
// are in the closed Registry, so ValidateRegistry asserts them at boot and ExecuteIntent can run them. A
// missing intent means the registration regressed.
func TestGraphTeamingIntentsAreRegistered(t *testing.T) {
cases := map[string]int{
IntentVendorCooccurrenceField: 2, // agency, naics
IntentPartnerOrCompetitorRatio: 2, // partner_uei, naics
IntentRecompeteTeamingField: 2, // agency, window_months
}
for name, wantParams := range cases {
it, ok := IntentByName(name)
if !ok {
t.Fatalf("intent %q must be registered in the closed Registry", name)
}
if len(it.Params) != wantParams {
t.Errorf("intent %q must bind exactly %d params, got %d", name, wantParams, len(it.Params))
}
}
}
// TestGraphTeamingIntentsPassTheReadOnlyGuard is the load bearing security assertion: each registered teaming
// intent passes GuardReadOnlyQuery against the real ReadAllowlist. A query that referenced a non allowlisted
// table, hid a mutation, or named an eeo marker would fail here, the same gate ValidateRegistry runs at boot
// and ExecuteIntent re runs at execution time.
func TestGraphTeamingIntentsPassTheReadOnlyGuard(t *testing.T) {
for _, sql := range []string{
vendorCooccurrenceFieldSQL,
partnerOrCompetitorRatioSQL,
recompeteTeamingFieldSQL,
} {
if err := GuardReadOnlyQuery(sql, ReadAllowlist); err != nil {
t.Errorf("a registered teaming intent must pass the read only guard: %v", err)
}
}
}
// TestValidateRegistryWithTeamingIntents proves the whole closed Registry, now carrying the three G2 intents
// alongside the TAG, G3, G1, G9, and G7 intents, validates at boot. This is the assertion the api boot runs.
func TestValidateRegistryWithTeamingIntents(t *testing.T) {
if err := ValidateRegistry(); err != nil {
t.Fatalf("ValidateRegistry must pass with the three G2 teaming intents registered: %v", err)
}
}
// TestTeamingAwardsCooccurrenceKeysOnlyOnAgencyAndNaics is the honesty mandate, pinned statically:
// usaspending_awards carries NO psc, NO set_aside, and NO pop_state column, so the awards co occurrence keys
// ONLY on (awarding_agency, naics_code). No G2 read may select or join on those phantom columns against the
// award alias. A regression that reached for a phantom award column would fail here.
func TestTeamingAwardsCooccurrenceKeysOnlyOnAgencyAndNaics(t *testing.T) {
for name, sql := range map[string]string{
"vendor_cooccurrence_field": vendorCooccurrenceFieldSQL,
"partner_or_competitor_ratio": partnerOrCompetitorRatioSQL,
"recompete_teaming_field": recompeteTeamingFieldSQL,
} {
lower := strings.ToLower(sql)
// The phantom columns the award table does NOT have. None may appear qualified to an award alias.
for _, phantom := range []string{"a.psc", "a.set_aside", "a.pop_state", "a.award_date", "inc.psc", "inc.set_aside", "inc.pop_state"} {
if strings.Contains(lower, phantom) {
t.Errorf("%s: usaspending_awards has no %s column; a G2 award read must not reference it", name, phantom)
}
}
}
// The vendor co occurrence awards arm keys on awarding_agency and naics_code, the only keys the award table
// carries; it must not key on a finer slice.
lower := strings.ToLower(vendorCooccurrenceFieldSQL)
if !strings.Contains(lower, "a.awarding_agency = $1") {
t.Error("the vendor co occurrence awards arm must key on awarding_agency")
}
if !strings.Contains(lower, "a.naics_code = $2") {
t.Error("the vendor co occurrence awards arm must key on naics_code")
}
}
// TestTeamingIntentsReferenceNoTenantTable is the Phase 1 scope boundary, pinned statically: G2 is PUBLIC
// DATA ONLY. NONE of the three intents may name a tenant table (requirements, candidates, the bench, the eeo
// schema). The tenant gap intersection questions (which partner closes OUR bench gap) are DEFERRED to Phase 2
// and G6. The only tenant side these reads touch is the PUBLIC is_galapagos self tag on usaspending_awards, a
// column on the public award catalog, never a tenant table. A regression that joined a tenant table would
// fail here, the same boundary the read allowlist enforces.
func TestTeamingIntentsReferenceNoTenantTable(t *testing.T) {
tenantTables := []string{
"requirement_mission_tags", "requirements", "required_skills",
"candidate_mission_tags", "candidate_skills", "candidates", "candidate_evaluations",
"slates", "slate_members", "candidate_demographics", "eeo",
"tenant_mission_tags", "bench_import_log",
}
for name, sql := range map[string]string{
"vendor_cooccurrence_field": vendorCooccurrenceFieldSQL,
"partner_or_competitor_ratio": partnerOrCompetitorRatioSQL,
"recompete_teaming_field": recompeteTeamingFieldSQL,
} {
lower := strings.ToLower(sql)
for _, tt := range tenantTables {
if strings.Contains(lower, "from "+tt) || strings.Contains(lower, "join "+tt) {
t.Errorf("%s: must not read the tenant or eeo table %q (Phase 1 is public data only)", name, tt)
}
}
}
// Positively confirm the partner ratio reaches the tenant side ONLY through the public is_galapagos self
// tag, never a tenant table.
if !strings.Contains(strings.ToLower(partnerOrCompetitorRatioSQL), "a.is_galapagos = true") {
t.Error("the partner ratio must reach the tenant side only through the public is_galapagos self tag")
}
}
// TestTeamingIntentsArePublicTablesOnly pins the public data mandate positively: every G2 intent reads ONLY
// the global public market tables (opportunity_records, usaspending_awards). A regression that read anything
// else would fail here.
func TestTeamingIntentsArePublicTablesOnly(t *testing.T) {
publicTables := map[string]bool{
"opportunity_records": true,
"usaspending_awards": true,
}
for name, sql := range map[string]string{
"vendor_cooccurrence_field": vendorCooccurrenceFieldSQL,
"partner_or_competitor_ratio": partnerOrCompetitorRatioSQL,
"recompete_teaming_field": recompeteTeamingFieldSQL,
} {
lower := strings.ToLower(sql)
var sawPublic bool
for pt := range publicTables {
if strings.Contains(lower, pt) {
sawPublic = true
}
}
if !sawPublic {
t.Errorf("%s: must read a public market table", name)
}
}
}
// TestTeamingRatioGuardsDivideByZero pins the divide by zero guard: the team versus compete ratio is a numeric
// over a numeric, and the denominator (the compete market count) is wrapped in NULLIF so a partner with no
// compete market divides to a null ratio rather than a divide by zero error. A regression that dropped the
// NULLIF would fail here.
func TestTeamingRatioGuardsDivideByZero(t *testing.T) {
lower := strings.ToLower(partnerOrCompetitorRatioSQL)
if !strings.Contains(lower, "nullif(") {
t.Error("the team versus compete ratio must guard the divisor with NULLIF so a partner with no compete market divides safely")
}
// The ratio is a numeric over a numeric (the divide by zero safe decimal), never a float division.
if !strings.Contains(lower, ")::numeric, 0)") {
t.Error("the ratio divisor must be a numeric guarded with NULLIF(..., 0)")
}
}
// TestTeamingNoFloatTouchesADollarOrRatio is the decimal mandate, pinned statically across all three G2
// intents: no ::float8, no ::float, no ::double precision, and no ::real cast may touch a dollar figure, a
// concentration, or the team versus compete ratio. Every dollar and the ratio stay Postgres numeric end to
// end and are scanned into shopspring/decimal in Go. A cast to a float type would silently lose the bit
// stable precision the AEDT compliance asset requires.
func TestTeamingNoFloatTouchesADollarOrRatio(t *testing.T) {
for name, sql := range map[string]string{
"vendor_cooccurrence_field": vendorCooccurrenceFieldSQL,
"partner_or_competitor_ratio": partnerOrCompetitorRatioSQL,
"recompete_teaming_field": recompeteTeamingFieldSQL,
} {
lower := strings.ToLower(sql)
for _, floatCast := range []string{"::float8", "::float", "::double precision", "::real"} {
if strings.Contains(lower, floatCast) {
t.Errorf("%s: a float cast %q must never touch a dollar, a concentration, or a ratio (decimal mandate)", name, floatCast)
}
}
}
}
// TestTeamingEveryListOrderEndsWithAUniqueTiebreaker pins the byte stable mandate: every G2 intent that
// returns a list ends its ORDER BY with a unique tiebreaker, so the same inputs yield byte identical rows. The
// vendor co occurrence field orders by the segment dollars then the source table then the UEI (a total order
// over the unioned rows), and the recompete teaming field orders by the period of performance end then the
// opportunity id then the neighbor UEI (a total order over the rows). The partner ratio returns a single
// summary row, a total order on its own, so it carries no ORDER BY.
func TestTeamingEveryListOrderEndsWithAUniqueTiebreaker(t *testing.T) {
listCases := []struct {
name string
sql string
mustContain string
}{
// The vendor co occurrence field unions the awards and the opportunity arms; the source_table plus the
// vendor_uei is the unique tiebreaker after the dollar concentration.
{"vendor_cooccurrence_field", vendorCooccurrenceFieldSQL, "source_table, vendor_uei"},
// The recompete teaming field orders by the period of performance end then the opportunity id then the
// neighbor UEI, a total order over the opportunity by neighbor rows.
{"recompete_teaming_field", recompeteTeamingFieldSQL, "e.id, neighbor_uei"},
}
for _, tc := range listCases {
lower := strings.ToLower(tc.sql)
idx := strings.LastIndex(lower, "order by")
if idx < 0 {
t.Errorf("%s: the list must be ordered for byte stability", tc.name)
continue
}
orderClause := lower[idx:]
if !strings.Contains(orderClause, strings.ToLower(tc.mustContain)) {
t.Errorf("%s: the ORDER BY must carry the unique tiebreaker %q, got %q", tc.name, tc.mustContain, orderClause)
}
}
}
// TestTeamingEdgesAreLabeledPrimeOfRecord pins the honesty mandate that every vendor or incumbent edge the G2
// graph surfaces is the PRIME recipient of record, never the staffing subcontractor: the public award data
// carries the prime recipient only, so labeling the edge prime-of-record is the honest statement of what the
// data supports. A regression that dropped the label would fail here.
func TestTeamingEdgesAreLabeledPrimeOfRecord(t *testing.T) {
for name, sql := range map[string]string{
"vendor_cooccurrence_field": vendorCooccurrenceFieldSQL,
"partner_or_competitor_ratio": partnerOrCompetitorRatioSQL,
"recompete_teaming_field": recompeteTeamingFieldSQL,
} {
if !strings.Contains(strings.ToLower(sql), "prime-of-record") {
t.Errorf("%s: every vendor or incumbent edge must be labeled prime-of-record", name)
}
}
// The constant label is also the package primeOfRecordLabel; pin they agree so the honest label is one
// source of truth across the market graph.
if primeOfRecordLabel != "prime-of-record" {
t.Errorf("the prime of record label constant must be prime-of-record, got %q", primeOfRecordLabel)
}
}
// TestTeamingNullableTargetsAreDecimalPointers pins the G9 NULL discipline carried into G2: the nullable
// numeric dollar figures (the co occurrence segment dollars, the team versus compete ratio, the neighbor
// dollars) are scanned into *decimal.Decimal so a row with no award dollars or a partner with no compete
// market scans cleanly rather than failing the scan. A live staging run will hit these NULLs, so the
// discipline is load bearing.
func TestTeamingNullableTargetsAreDecimalPointers(t *testing.T) {
co := CooccurrenceRow{}
if co.SegmentDollars != nil {
t.Error("the co occurrence segment dollars must be a nullable decimal pointer (null on an opportunity sourced edge)")
}
pr := PartnerRatioRow{}
if pr.TeamVsCompeteRatio != nil {
t.Error("the team versus compete ratio must be a nullable decimal pointer (null when the partner has no compete market)")
}
tf := TeamingFieldRow{}
if tf.NeighborDollars != nil {
t.Error("the neighbor dollars must be a nullable decimal pointer (null when the incumbent has no neighborhood)")
}
}
// TestTeamingIntentsAreGraphIntents proves the three G2 intents are classified as GRAPH intents (dispatched to
// AnswerGraph, not AnswerTAG), so the graph evidence rendering and the graph route audit apply, and each is
// also a real registered intent in the closed Registry.
func TestTeamingIntentsAreGraphIntents(t *testing.T) {
for _, name := range []string{IntentVendorCooccurrenceField, IntentPartnerOrCompetitorRatio, IntentRecompeteTeamingField} {
if !IsGraphIntent(name) {
t.Errorf("%q must be a graph intent", name)
}
if _, ok := IntentByName(name); !ok {
t.Errorf("graph intent %q must be registered in the closed Registry", name)
}
}
}
// TestGraphClassifyRoutesTeamingQuestions proves the conservative NL router maps a free form G2 question that
// clearly names a traversal AND carries the params to bind it unambiguously to the right intent with the right
// args. The vendor co occurrence field needs BOTH a quoted agency and a bare NAICS; the partner ratio needs a
// quoted UEI and a bare NAICS; the recompete teaming field needs a quoted agency. It never authors a param the
// user did not delimit.
func TestGraphClassifyRoutesTeamingQuestions(t *testing.T) {
cases := []struct {
name string
question string
intent string
args []any
}{
{
name: "vendor co occurrence with quoted agency and bare naics",
question: `who teams up, the teaming field in "DEPT OF THE AIR FORCE" for 541512`,
intent: IntentVendorCooccurrenceField,
args: []any{"DEPT OF THE AIR FORCE", "541512"},
},
{
name: "partner or competitor ratio with quoted uei and bare naics",
question: `does partner "N3GDEB78RNF8" team or compete with us in 541330`,
intent: IntentPartnerOrCompetitorRatio,
args: []any{"N3GDEB78RNF8", "541330"},
},
{
name: "recompete teaming field with quoted agency and stated window",
question: `show the recompete teaming field for "DEPT OF DEFENSE" over the next 18 months`,
intent: IntentRecompeteTeamingField,
args: []any{"DEPT OF DEFENSE", 18},
},
{
name: "recompete teaming field with quoted agency and default window",
question: `who could team on the recompete for "GSA"`,
intent: IntentRecompeteTeamingField,
args: []any{"GSA", 0},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
gr := graphClassify(tc.question)
if gr == nil {
t.Fatalf("graphClassify(%q) must route to a graph intent", tc.question)
}
if gr.intent != tc.intent {
t.Errorf("intent: got %q, want %q", gr.intent, tc.intent)
}
if len(gr.args) != len(tc.args) {
t.Fatalf("args length: got %d %v, want %d %v", len(gr.args), gr.args, len(tc.args), tc.args)
}
for i := range tc.args {
if gr.args[i] != tc.args[i] {
t.Errorf("arg %d: got %v, want %v", i, gr.args[i], tc.args[i])
}
}
})
}
}
// TestGraphClassifyTeamingFallsBackWhenParamsMissing is the conservatism test for the G2 routes: a teaming
// question that clearly names a traversal but does NOT carry the params to bind it returns nil, so the caller
// falls back to RAG rather than guessing an agency, a UEI, or a NAICS. The model never authors params; an
// unbindable teaming question is a RAG question.
func TestGraphClassifyTeamingFallsBackWhenParamsMissing(t *testing.T) {
fallback := []string{
// A co occurrence question with a NAICS but no quoted agency: the segment key is incomplete.
"who teams up in the cloud market for 541512",
// A co occurrence question with a quoted agency but no NAICS: still incomplete.
`who appears together in "DEPT OF THE AIR FORCE"`,
// A partner ratio question with a NAICS but no quoted UEI: nothing to bind.
"does the partner team or compete with us in 541330",
// A partner ratio question with a quoted UEI but no NAICS: the core NAICS is missing.
`does partner "N3GDEB78RNF8" team or compete with us`,
// A recompete teaming question with no quoted agency.
"who could team on the recompete in general",
}
for _, q := range fallback {
if gr := graphClassify(q); gr != nil {
t.Errorf("graphClassify(%q) must fall back (nil) when params cannot be bound, got intent %q args %v", q, gr.intent, gr.args)
}
}
}
// TestGraphClassifyExistingCompetitorRouteUnchanged pins the Phase 0 route is byte unchanged: a bare competitor
// or incumbent question with a quoted agency and a bare NAICS still routes to the existing G1
// IntentSegmentCompetitorField, not a new G2 intent. The new G2 intents are selected only by their distinct
// teaming keywords (co occur, teaming field, partner or competitor, recompete teaming), so the existing
// competitor route is untouched.
func TestGraphClassifyExistingCompetitorRouteUnchanged(t *testing.T) {
gr := graphClassify(`who is the competitor in "DEPT OF THE AIR FORCE" for 541512`)
if gr == nil {
t.Fatal("the existing G1 competitor question with a quoted agency and a NAICS must still route")
}
if gr.intent != IntentSegmentCompetitorField {
t.Errorf("the existing competitor question must route to the Phase 0 G1 intent, got %q", gr.intent)
}
}