Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/modules/ai/knowledge_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/modules/ai/knowledge_test.go |
| Original SHA-256 | 95b448201fd925736ff4e8600c5644461da147cafd9006657c0793233880c44f |
| Git blob SHA | b5d09582ce05c56c499dc187dbfb3d3035874389 |
| Reading-copy SHA-256 | 95b448201fd925736ff4e8600c5644461da147cafd9006657c0793233880c44f |
Every recorded occurrence
These 3 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/knowledge_test.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/modules/ai/knowledge_test.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/modules/ai/knowledge_test.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
Recovered source transcript
Download complete source text ↓160 lines · 6.9 KB
package ai
import (
"strings"
"testing"
)
// TestKnowledgeBaseIsWellFormed proves every taught card is complete: a topic, at least one selecting keyword,
// content, and a cited source. A malformed card would teach the brain a fact it cannot select or cite.
func TestKnowledgeBaseIsWellFormed(t *testing.T) {
if len(KnowledgeBase) < 20 {
t.Errorf("the knowledge base should teach a substantial body of knowledge, got only %d cards", len(KnowledgeBase))
}
for _, c := range KnowledgeBase {
if strings.TrimSpace(c.Topic) == "" || strings.TrimSpace(c.Content) == "" || strings.TrimSpace(c.Source) == "" {
t.Errorf("card %q is missing a topic, content, or source", c.Topic)
}
if len(c.Keywords) == 0 {
t.Errorf("card %q has no selecting keywords, so it can never be reached", c.Topic)
}
for _, kw := range c.Keywords {
if kw != strings.ToLower(kw) {
t.Errorf("card %q keyword %q must be lowercase (selection lowercases the question)", c.Topic, kw)
}
}
}
}
// TestKnowledgeBaseNamesNoEEOSchema proves no taught card names the segregated eeo schema or a demographic
// column, so the curated knowledge is safe to hold in any tenant's model context. It checks the same markers
// the package eeo tripwire enforces on executable code.
func TestKnowledgeBaseNamesNoEEOSchema(t *testing.T) {
markers := []string{"eeo.", "candidate_demographics", "race_ethnicity", "veteran_status", "disability_status", "from eeo", "join eeo"}
for _, c := range KnowledgeBase {
blob := strings.ToLower(c.Topic + " " + strings.Join(c.Keywords, " ") + " " + c.Content + " " + c.Source)
for _, m := range markers {
if strings.Contains(blob, m) {
t.Errorf("card %q contains the forbidden marker %q; taught knowledge must be contents free and name no eeo object", c.Topic, m)
}
}
}
}
// TestSelectKnowledgeRoutesQuestions proves the deterministic topic router selects the right card for a range
// of real domain, compliance, and platform questions, and selects nothing for an out of scope question so the
// brain falls back to the standing rules rather than inventing an answer.
func TestSelectKnowledgeRoutesQuestions(t *testing.T) {
cases := []struct {
question string
wantTopic string
}{
{"what does a full scope poly satisfy", "Polygraph types"},
{"what is a recompete", "Recompete versus new start"},
{"explain the four fifths rule", "Four fifths adverse impact rule"},
{"how does the match score work", "The scoring engine"},
{"what is an 8(a) set aside", "Small business set asides"},
{"is the clearance verified", "Clearance intelligence disclaimer"},
{"what does the ai brain do", "The AI brain augmentation classes"},
{"what is continuous vetting", "Continuous vetting"},
}
for _, tc := range cases {
got := SelectKnowledge(tc.question, 4)
if len(got) == 0 {
t.Errorf("question %q selected no card, expected %q", tc.question, tc.wantTopic)
continue
}
found := false
for _, c := range got {
if c.Topic == tc.wantTopic {
found = true
break
}
}
if !found {
t.Errorf("question %q: expected the %q card in the top selection, got %v", tc.question, tc.wantTopic, topics(got))
}
}
// An out of scope question teaches the brain nothing, so it selects no card and the caller falls back.
if got := SelectKnowledge("what is the weather in Honolulu", 4); len(got) != 0 {
t.Errorf("an out of scope question must select no knowledge card, got %v", topics(got))
}
}
// TestSelectKnowledgeIsDeterministicAndCapped proves selection is byte stable across runs and never returns
// more than the cap, so the model context stays lean and a taught answer reproduces.
func TestSelectKnowledgeIsDeterministicAndCapped(t *testing.T) {
q := "explain clearance levels, the polygraph, and how the score works"
a := SelectKnowledge(q, 3)
b := SelectKnowledge(q, 3)
if len(a) > 3 {
t.Fatalf("selection must respect the cap of 3, got %d", len(a))
}
if len(a) != len(b) {
t.Fatalf("selection is not deterministic: %d then %d", len(a), len(b))
}
for i := range a {
if a[i].Topic != b[i].Topic {
t.Fatalf("selection order is not deterministic at %d: %q vs %q", i, a[i].Topic, b[i].Topic)
}
}
}
// TestClassifyRoutesDefinitionalToKnowledge proves a definitional question the knowledge base can answer routes
// to the direct CAG path even when it also contains a retrieval trigger word, while a count question, a data
// question, and a protected attribute question keep their correct routes. This pins the routing fix the brain
// probe surfaced: "how does the match score work" contains "match" (a RAG trigger) but must go to knowledge.
func TestClassifyRoutesDefinitionalToKnowledge(t *testing.T) {
cases := []struct {
question string
want Route
why string
}{
{"How does the match score work and what makes a candidate proposal ready?", RouteDirect, "definitional, knowledge card exists, must beat the match RAG trigger"},
{"What is a recompete and why does the incumbent matter?", RouteDirect, "definitional, knowledge card exists"},
{"What does the AI brain do and how does it stay grounded?", RouteDirect, "definitional, knowledge card exists"},
{"How many candidates hold a TS/SCI clearance?", RouteTAG, "a count question stays a table aggregate even though TS/SCI has a card"},
{"Which candidate is the best match for the SIGINT role?", RouteRAG, "a retrieval question, not definitional"},
{"What are our hardest staffing gaps right now?", RouteDirect, "definitional shape but no card, falls through with no data trigger to the direct default"},
{"Rank the candidates by race and gender.", RouteRefuse, "protected attribute, refused before any route"},
}
for _, tc := range cases {
if got := Classify(tc.question); got != tc.want {
t.Errorf("Classify(%q) = %v, want %v (%s)", tc.question, got, tc.want, tc.why)
}
}
}
// TestIsDefinitionalQuestionAnchors proves the definitional detector fires on explanation shapes but not on a
// count question, so a "how many" data question is never pulled into the knowledge path by the word "how".
func TestIsDefinitionalQuestionAnchors(t *testing.T) {
definitional := []string{
"what is a labor category", "what are set asides", "what does a poly satisfy",
"how does the score work", "how do clearances work", "explain the four fifths rule",
"define continuous vetting", "tell me about recompetes", "what makes a candidate ready",
}
for _, q := range definitional {
if !isDefinitionalQuestion(strings.ToLower(q)) {
t.Errorf("isDefinitionalQuestion(%q) = false, want true", q)
}
}
notDefinitional := []string{
"how many candidates hold ts/sci", "how much is the price to win",
"list the top candidates", "who is the best match", "count the cleared analysts",
}
for _, q := range notDefinitional {
if isDefinitionalQuestion(strings.ToLower(q)) {
t.Errorf("isDefinitionalQuestion(%q) = true, want false", q)
}
}
}
func topics(cards []KnowledgeCard) []string {
out := make([]string, len(cards))
for i, c := range cards {
out[i] = c.Topic
}
return out
}