Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/integration/graph_loop_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_loop_integration_test.go |
| Original SHA-256 | f83f23ff970a7916f6dfb22503e5e6395813867d0d91875dbadb501aa4ba42d8 |
| Git blob SHA | e267de2ecd832274f5ed05d04620defbc98b9c66 |
| Reading-copy SHA-256 | f83f23ff970a7916f6dfb22503e5e6395813867d0d91875dbadb501aa4ba42d8 |
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_loop_integration_test.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/integration/graph_loop_integration_test.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/integration/graph_loop_integration_test.go | m5-price-to-win | 41000ad30fff4129fdaf5ec84e15ba14c27d4890 | Open original |
| Janady13/missionmatch / internal/integration/graph_loop_integration_test.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/integration/graph_loop_integration_test.go | mag-substrate | b82c7100a492dec67dfd1eda6b3f53def859be35 | Open original |
| Janady13/missionmatch / internal/integration/graph_loop_integration_test.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/integration/graph_loop_integration_test.go | graphrag-foundation | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 | Open original |
| Janady13/missionmatch / internal/integration/graph_loop_integration_test.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/integration/graph_loop_integration_test.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/integration/graph_loop_integration_test.go | phase2-connectors | e038d4c687aec16f8bd9bc4d907eea14d91f8704 | Open original |
| Janady13/missionmatch / internal/integration/graph_loop_integration_test.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/integration/graph_loop_integration_test.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓288 lines · 13.1 KB
//go:build integration
package integration
import (
"context"
"strconv"
"strings"
"testing"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/missionworkforce/missionmatch/internal/modules/ai"
"github.com/missionworkforce/missionmatch/internal/platform/audit"
)
// seedRequirementForCapture creates a requirement at a given agency and required level for one org, linked to
// a tenant opportunity whose federal_ref points at a global opportunity_records row carrying the naics, so the
// G6 segment resolver binds BOTH the agency (from customer_agency) and the naics (from the linked
// opportunity record). It uses the migrator so the seed crosses tenants for the RLS posture, and returns the
// requirement id. The opportunity record carries the naics only; the market award structure is seeded
// separately under the same agency.
func seedRequirementForCapture(t *testing.T, org uuid.UUID, agency, level, naics, run string) uuid.UUID {
t.Helper()
ctx := context.Background()
// The global opportunity_records row that carries the naics, linked from the tenant opportunity by
// federal_ref = source_record_id. It is the only honest place the segment naics comes from.
federalRef := "G6-OPPREC-" + run
if _, err := migrator.Exec(ctx,
`INSERT INTO opportunity_records
(source_name, source_record_id, dedupe_key, record_kind, title, agency, naics, fetched_at)
VALUES ('SAM.gov', $1, $2, 'active_solicitation', 'Capture loop opportunity', $3, $4, now())
ON CONFLICT (source_name, source_record_id) DO NOTHING`,
federalRef, "G6-DEDUPE-"+run, agency, naics); err != nil {
t.Fatalf("seed opportunity record: %v", err)
}
// The tenant opportunity, linked to the global record by federal_ref, carrying the customer agency.
var oppID uuid.UUID
if err := migrator.QueryRow(ctx,
`INSERT INTO opportunities (organization_id, name, customer_agency, federal_ref)
VALUES ($1, 'Capture loop opportunity', $2, $3) RETURNING id`,
org, agency, federalRef).Scan(&oppID); err != nil {
t.Fatalf("seed opportunity: %v", err)
}
// The requirement, linked to the opportunity (composite FK) and carrying the customer agency and level.
var reqID uuid.UUID
if err := migrator.QueryRow(ctx,
`INSERT INTO requirements (organization_id, opportunity_id, title, customer_agency, required_level, required_poly)
VALUES ($1, $2, 'Capture loop requirement', $3, $4, 'none') RETURNING id`,
org, oppID, agency, level).Scan(&reqID); err != nil {
t.Fatalf("seed requirement: %v", err)
}
return reqID
}
// TestG6CapturePictureClosesTheLoop is the live keystone proof of G6: it composes the SUPPRESSED bench legs
// (the structural gap and clearance coverage), the PUBLIC market context (the recompete clock and incumbent
// field for the requirement's agency and naics), and the price to win honest floor into one integrated
// capture answer for a requirement, all on the graph route, auth gated, suppressed, and counts only audited,
// and it NEVER computes a match score. It seeds a bench that exercises both sides of the structural gap (at
// least k meet AND at least k do not, so a published answer is readable) and a market segment with award
// structure under the requirement's agency.
func TestG6CapturePictureClosesTheLoop(t *testing.T) {
org := seedOrg(t)
k := ai.ConfiguredSuppressionThreshold()
run := uuid.NewString()[:8]
agency := "DEPT OF THE AIR FORCE " + run // unique per run so the market segment is isolated
naics := "541512"
req := seedRequirementForCapture(t, org, agency, "secret", naics, run)
// A mandatory required skill so the structural gap's skill arm is meaningful: a meets candidate holds it,
// a does not meet candidate fails on clearance.
skill := seedSkillByName(t, "CaptureSkill-"+run)
seedRequiredSkill(t, org, req, skill, true)
// MEETS: k candidates hold the required clearance (secret, rank at or above the required secret) AND the
// required skill, so they meet the structural coverage test. DOES NOT MEET: k candidates hold none (rank
// below secret), so they fail the clearance arm. Both buckets are at or above k, so the gap publishes real
// counts and the clearance coverage publishes the secret and none levels.
for i := 0; i < k; i++ {
c := seedCandidate(t, org, "secret", "active", true)
seedCandidateSkill(t, org, c.ID, skill)
}
for i := 0; i < k; i++ {
seedCandidate(t, org, "none", "active", true)
}
// The market segment: an award ending inside the recompete window under the requirement's agency and naics,
// so the public recompete clock and the incumbent and competitor field both have structure to report.
insideWindow := time.Now().UTC().AddDate(0, 6, 0)
recent := time.Now().UTC().AddDate(0, -3, 0)
seedMarketAward(t, "G6-INC-"+run, "PIID-G6-IN", agency, naics, "UEIINCUMBENT6", "Capture Incumbent LLC", "6000000.00", insideWindow, false)
seedMarketAward(t, "G6-CF-"+run, "PIID-G6-CF", agency, naics, "UEICHALLENG62", "Capture Challenger LLC", "2000000.00", recent, false)
orch := ai.NewOrchestrator(appDB, nil, audit.New(appDB))
resp, err := orch.Answer(ctxOrg(org), "", ai.IntentCapturePictureForRequirement, []any{req.String()})
if err != nil {
t.Fatalf("capture picture answer: %v", err)
}
// (a) The answer carries the graph route and is not refused for an authenticated tenant.
if resp.Refused {
t.Fatalf("an authenticated capture question must not be refused, got %+v", resp)
}
if resp.Route != ai.RouteGraph {
t.Errorf("the capture composition must dispatch to the graph route, got %q", resp.Route)
}
// (b) The bench fit reports suppression safe counts: both gap buckets are at or above k, so the real meets
// and does not meet counts publish (the exact seeded k for each).
if !strings.Contains(resp.Answer, "meets="+strconv.Itoa(k)) {
t.Errorf("the bench fit must publish the exact meets count when both sides are at or above k, got %q", resp.Answer)
}
if !strings.Contains(resp.Answer, "does_not_meet="+strconv.Itoa(k)) {
t.Errorf("the bench fit must publish the exact does not meet count when both sides are at or above k, got %q", resp.Answer)
}
// The clearance coverage publishes the secret and none levels (each at or above k), suppressed safe.
if !strings.Contains(resp.Answer, "secret=") || !strings.Contains(resp.Answer, "none=") {
t.Errorf("the clearance coverage must report the held levels, got %q", resp.Answer)
}
// (c) The market context names the seeded agency in the recompete or incumbent line.
if !strings.Contains(resp.Answer, agency) {
t.Errorf("the market context must name the seeded agency, got %q", resp.Answer)
}
if !strings.Contains(resp.Answer, "recompete clock") {
t.Errorf("the market context must carry the recompete clock line for the agency, got %q", resp.Answer)
}
// (d) The price to win honest floor is present and no rate is fabricated.
if !strings.Contains(resp.Answer, "labor rate data not yet ingested") {
t.Errorf("the answer must state the price to win honest floor, got %q", resp.Answer)
}
// The frozen engine path is never invoked. The bench fit carries the honest disclaimer "not a match
// score" (so that bare phrase is expected and required); a real leak is an engine score VALUE, a
// total_score or a band value, which must never appear.
if !strings.Contains(strings.ToLower(resp.Answer), "not a match score") {
t.Errorf("the bench fit must carry the honest not a match score disclaimer, got %q", resp.Answer)
}
for _, scoreWord := range []string{"total_score", "band="} {
if strings.Contains(strings.ToLower(resp.Answer), scoreWord) {
t.Errorf("the capture answer must report no engine score, leaked %q in %q", scoreWord, resp.Answer)
}
}
// (f) The counts only audit holds no candidate id, no raw sub k count, and no requirement id.
var payloads []string
if err := appDB.RunInTenantTx(ctxOrg(org), func(ctx context.Context, tx pgx.Tx) error {
rows, qerr := tx.Query(ctx,
"SELECT new_values::text FROM audit_logs WHERE organization_id=$1 AND action='aedt.ai.capture_answered'", org)
if qerr != nil {
return qerr
}
defer rows.Close()
for rows.Next() {
var p string
if serr := rows.Scan(&p); serr != nil {
return serr
}
payloads = append(payloads, p)
}
return rows.Err()
}); err != nil {
t.Fatalf("read capture audit: %v", err)
}
if len(payloads) == 0 {
t.Fatal("a capture answer must emit an aedt.ai.capture_answered audit event")
}
for _, p := range payloads {
if !strings.Contains(p, "capture_picture_for_requirement") || !strings.Contains(p, "segment_bound") {
t.Errorf("the capture audit must record the intent and whether the segment bound, got %q", p)
}
// NO requirement id, NO candidate id, NO raw count in the audit payload.
if strings.Contains(p, req.String()) {
t.Errorf("the capture audit must hold no requirement id, leaked it in %q", p)
}
for _, leak := range []string{"candidate", "requirement_id", "answer"} {
if strings.Contains(p, leak) {
t.Errorf("the capture audit must hold no candidate id, requirement id, or answer text, leaked %q in %q", leak, p)
}
}
}
}
// TestG6CaptureRefusesWithoutTenantContext proves the auth gate on the composed capture intent: with NO
// authenticated tenant context it refuses (route graph, no answer) rather than running a person touching read,
// instead of relying only on the RLS empty result fail safe.
func TestG6CaptureRefusesWithoutTenantContext(t *testing.T) {
orch := ai.NewOrchestrator(appDB, nil, audit.New(appDB))
resp, err := orch.Answer(context.Background(), "", ai.IntentCapturePictureForRequirement, []any{uuid.NewString()})
if err != nil {
t.Fatalf("an unauthenticated capture question must refuse cleanly, got error %v", err)
}
if !resp.Refused {
t.Fatalf("an unauthenticated capture question must be refused, got %+v", resp)
}
if resp.Route != ai.RouteGraph {
t.Errorf("the refusal must carry route graph, got %q", resp.Route)
}
if resp.Answer != "" {
t.Errorf("a refusal must ship no answer, got %q", resp.Answer)
}
}
// TestG6CaptureRejectsRawIntentPath proves the defense in depth guard: the generic ExecuteIntent (the raw path
// that returns database rows verbatim) hard rejects the composed capture intent because it is a bench intent,
// so the composition is the only way to run it and an unsuppressed bench count can never be served on the raw
// path even if a future caller tried it.
func TestG6CaptureRejectsRawIntentPath(t *testing.T) {
intent, ok := ai.IntentByName(ai.IntentCapturePictureForRequirement)
if !ok {
t.Fatalf("the capture intent %q must be registered", ai.IntentCapturePictureForRequirement)
}
_, err := ai.ExecuteIntent(ctxOrg(seedOrg(t)), appDB, intent, []any{uuid.NewString()})
if err == nil {
t.Fatalf("ExecuteIntent must reject the capture intent on the raw path, got nil error")
}
if !strings.Contains(err.Error(), "suppressing executor") {
t.Errorf("the raw path rejection of the capture intent must name the suppressing executor, got %v", err)
}
}
// TestG6CaptureUnbindableSegmentStatesTheFloor proves the honest floor: a requirement with no customer agency
// and no linked opportunity resolves no market segment, so the composition states that plainly and calls no
// market executor with empty args, while the bench legs and the price floor still answer. The audit records
// segment_bound false.
func TestG6CaptureUnbindableSegmentStatesTheFloor(t *testing.T) {
org := seedOrg(t)
k := ai.ConfiguredSuppressionThreshold()
// A requirement with no customer agency and no opportunity link: the segment cannot bind.
req := seedRequirementWithLevel(t, org, "secret")
// A small bench so the legs run; both gap buckets may suppress, which is fine, the floor still answers.
for i := 0; i < k; i++ {
seedCandidate(t, org, "secret", "active", true)
}
orch := ai.NewOrchestrator(appDB, nil, audit.New(appDB))
resp, err := orch.Answer(ctxOrg(org), "", ai.IntentCapturePictureForRequirement, []any{req.String()})
if err != nil {
t.Fatalf("capture picture answer: %v", err)
}
if resp.Refused || resp.Route != ai.RouteGraph {
t.Fatalf("a bound tenant capture question must answer on the graph route, got %+v", resp)
}
if !strings.Contains(resp.Answer, "market segment could not be bound") {
t.Errorf("an unbindable segment must state the honest floor plainly, got %q", resp.Answer)
}
if !strings.Contains(resp.Answer, "labor rate data not yet ingested") {
t.Errorf("the price to win honest floor must still be present, got %q", resp.Answer)
}
// The audit records segment_bound false for the unbindable segment.
var sawFalse bool
if err := appDB.RunInTenantTx(ctxOrg(org), func(ctx context.Context, tx pgx.Tx) error {
rows, qerr := tx.Query(ctx,
"SELECT new_values::text FROM audit_logs WHERE organization_id=$1 AND action='aedt.ai.capture_answered'", org)
if qerr != nil {
return qerr
}
defer rows.Close()
for rows.Next() {
var p string
if serr := rows.Scan(&p); serr != nil {
return serr
}
// Postgres renders jsonb to text with a space after the colon, so match that form.
if strings.Contains(p, "\"segment_bound\": false") {
sawFalse = true
}
}
return rows.Err()
}); err != nil {
t.Fatalf("read capture audit: %v", err)
}
if !sawFalse {
t.Error("the capture audit must record segment_bound false for an unbindable segment")
}
}