Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/modules/ai/graph_loop_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 |
| Branch | graphrag-foundation |
| Path or archive member | internal/modules/ai/graph_loop_test.go |
| Original SHA-256 | 4a010ae763d15f582889aa08cbea644cdee4ebd1953c054da282d124690942c8 |
| Git blob SHA | 4d8532417938a2e21cd704d72570a1cf38abf6dd |
| Reading-copy SHA-256 | 4a010ae763d15f582889aa08cbea644cdee4ebd1953c054da282d124690942c8 |
Recovered source transcript
Download complete source text ↓118 lines · 6.3 KB
package ai
import (
"strings"
"testing"
)
// TestRequirementSegmentSQLPassesTheReadOnlyGuard is the load bearing security assertion for G6: the segment
// resolver SQL passes GuardReadOnlyQuery against the real ReadAllowlist with no error. It must be a single
// read over allowlisted tables (requirements, opportunities, opportunity_records) with no set returning
// function in a FROM or JOIN position, no mutating keyword, and no eeo marker, the same gate ValidateRegistry
// runs at boot and ExecuteIntent would re run. It is the SQL the composition runs to resolve the segment
// under RLS and the registered SQL of the composed intent.
func TestRequirementSegmentSQLPassesTheReadOnlyGuard(t *testing.T) {
if err := GuardReadOnlyQuery(requirementSegmentSQL, ReadAllowlist); err != nil {
t.Fatalf("the requirement segment resolver SQL must pass the read only guard: %v", err)
}
}
// TestValidateRegistryWithCaptureIntent proves the whole closed Registry, now carrying the G6 composed
// capture intent alongside the TAG, G3, G1, G9, G7, G2, G5, and G4 intents, validates at boot. ValidateRegistry
// runs GuardReadOnlyQuery on every intent's SQL, so the composed intent's registered SQL (the segment
// resolver read) must itself pass the guard for the whole Registry to validate. This is the assertion the api
// boot runs.
func TestValidateRegistryWithCaptureIntent(t *testing.T) {
if err := ValidateRegistry(); err != nil {
t.Fatalf("ValidateRegistry must pass with the G6 capture intent registered: %v", err)
}
}
// TestCaptureIntentIsRegistered proves capture_picture_for_requirement is in the closed Registry binding
// exactly one ParamUUID requirement_id, so ValidateRegistry asserts it at boot and the bench fork can bind its
// id. A missing intent or a wrong param shape means the registration regressed.
func TestCaptureIntentIsRegistered(t *testing.T) {
it, ok := IntentByName(IntentCapturePictureForRequirement)
if !ok {
t.Fatalf("intent %q must be registered in the closed Registry", IntentCapturePictureForRequirement)
}
if len(it.Params) != 1 {
t.Fatalf("the capture intent must bind exactly one param, got %d", len(it.Params))
}
if it.Params[0].Kind != ParamUUID {
t.Errorf("the capture intent must bind a ParamUUID requirement id, got %q", it.Params[0].Kind)
}
if it.SQL != requirementSegmentSQL {
t.Error("the capture intent's registered SQL must be the segment resolver read, the only guarded read it carries")
}
}
// TestCaptureIntentIsGraphAndBenchIntent proves the composed capture intent is BOTH a graph intent (so the
// Answer dispatcher routes it to AnswerGraph) AND a bench intent (so it is auth gated, rejected on the raw
// ExecuteIntent path, and forked to its composition). A regression dropping it from either set would let it
// route to TAG or run unsuppressed.
func TestCaptureIntentIsGraphAndBenchIntent(t *testing.T) {
if !IsGraphIntent(IntentCapturePictureForRequirement) {
t.Error("the capture intent must be a graph intent so Answer routes it to AnswerGraph")
}
if !IsBenchIntent(IntentCapturePictureForRequirement) {
t.Error("the capture intent reads the bench and must be a bench intent so it is auth gated and raw path rejected")
}
}
// TestCaptureClassifierBindsOnlyOnExplicitRequirementUUID pins the conservative NL posture: a capture picture
// question routes to the composed intent ONLY when it carries an explicit canonical requirement UUID, and a
// capture phrasing with no UUID falls back to RAG (a nil route) rather than guessing a requirement, the same
// posture as the bench gap and readiness routes.
func TestCaptureClassifierBindsOnlyOnExplicitRequirementUUID(t *testing.T) {
reqID := "11111111-2222-3333-4444-555555555555"
gr := graphClassify(`give me the capture picture for requirement ` + reqID)
if gr == nil {
t.Fatal("a capture picture question carrying an explicit requirement UUID must route to the composed intent")
}
if gr.intent != IntentCapturePictureForRequirement {
t.Errorf("the capture question must route to %q, got %q", IntentCapturePictureForRequirement, gr.intent)
}
if len(gr.args) != 1 || gr.args[0] != reqID {
t.Errorf("the capture route must bind the explicit requirement id, got %v", gr.args)
}
// A capture phrasing with NO explicit requirement id falls back to RAG (nil route), never a guessed id.
if got := graphClassify("can we staff this and what is the market"); got != nil {
t.Errorf("a capture question with no explicit requirement id must fall back to RAG, got %+v", got)
}
}
// TestCaptureNarrativeNamesThePriceFloorAndNeverADash pins two surfaced invariants of the deterministic
// narrative: it always states the price to win honest floor verbatim (no fabricated rate), and it carries no
// dash in surfaced prose (the platform writing rule). The bench legs are empty here, so the narrative is the
// pure structural and floor text with no person data.
func TestCaptureNarrativeNamesThePriceFloorAndNeverADash(t *testing.T) {
seg := RequirementSegment{Agency: "", NAICS: "", RequiredLevel: "secret", Found: true}
market := []string{"the market segment could not be bound: this requirement names no customer agency and links no opportunity."}
got := captureNarrative(seg, nil, nil, market)
if !strings.Contains(got, capturePriceToWinFloor) {
t.Errorf("the capture narrative must state the price to win honest floor, got %q", got)
}
if strings.Contains(got, "-") {
t.Errorf("the capture narrative must carry no dash in surfaced prose, got %q", got)
}
}
// TestSegmentBindRules pins the honest floor discipline: the agency keyed leg runs only with a non empty
// agency, the (agency, naics) keyed leg only with both, and SegmentBound (whether any market arm can run) is
// the non empty agency floor.
func TestSegmentBindRules(t *testing.T) {
none := RequirementSegment{Found: true}
if none.AgencyBound() || none.NAICSBound() || none.SegmentBound() {
t.Error("an empty segment must bind no market arm")
}
agencyOnly := RequirementSegment{Agency: "DEPT OF THE AIR FORCE", Found: true}
if !agencyOnly.AgencyBound() || agencyOnly.NAICSBound() || !agencyOnly.SegmentBound() {
t.Error("an agency only segment must bind the agency arm but not the naics arm")
}
full := RequirementSegment{Agency: "DEPT OF THE AIR FORCE", NAICS: "541512", Found: true}
if !full.AgencyBound() || !full.NAICSBound() || !full.SegmentBound() {
t.Error("a full segment must bind both market arms")
}
}