Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/integration/graph_bench_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_bench_integration_test.go |
| Original SHA-256 | 78c9fc058883b5765ee593b9727e7702a460177ef1ec4a29a423416e35c41a6d |
| Git blob SHA | 65d7e253c1e14c74a9c3b320f1e50fd7e97c8bb8 |
| Reading-copy SHA-256 | 78c9fc058883b5765ee593b9727e7702a460177ef1ec4a29a423416e35c41a6d |
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_bench_integration_test.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/integration/graph_bench_integration_test.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/integration/graph_bench_integration_test.go | m5-price-to-win | 41000ad30fff4129fdaf5ec84e15ba14c27d4890 | Open original |
| Janady13/missionmatch / internal/integration/graph_bench_integration_test.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/integration/graph_bench_integration_test.go | mag-substrate | b82c7100a492dec67dfd1eda6b3f53def859be35 | Open original |
| Janady13/missionmatch / internal/integration/graph_bench_integration_test.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/integration/graph_bench_integration_test.go | graphrag-foundation | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 | Open original |
| Janady13/missionmatch / internal/integration/graph_bench_integration_test.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/integration/graph_bench_integration_test.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/integration/graph_bench_integration_test.go | phase2-connectors | e038d4c687aec16f8bd9bc4d907eea14d91f8704 | Open original |
| Janady13/missionmatch / internal/integration/graph_bench_integration_test.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/integration/graph_bench_integration_test.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓388 lines · 16.0 KB
//go:build integration
package integration
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/missionworkforce/missionmatch/internal/modules/ai"
)
// ---------- G4 bench graph helpers (seed via the BYPASSRLS migrator so we can write across tenants) ----------
// seedCandidateSkill attaches a global skill to a candidate in one org via the migrator. The composite FK
// (organization_id, candidate_id) means the candidate must already exist in the org; the skill is a global
// row from seedSkillByName.
func seedCandidateSkill(t *testing.T, org, candidate, skill uuid.UUID) {
t.Helper()
if _, err := migrator.Exec(context.Background(),
`INSERT INTO candidate_skills (organization_id, candidate_id, skill_id) VALUES ($1,$2,$3)
ON CONFLICT (candidate_id, skill_id) DO NOTHING`,
org, candidate, skill); err != nil {
t.Fatalf("seed candidate skill: %v", err)
}
}
// seedRequirementWithLevel creates a requirement at a given required clearance level for one org and returns
// its id. It uses the migrator so the seed crosses tenants for the RLS isolation proof.
func seedRequirementWithLevel(t *testing.T, org uuid.UUID, level string) uuid.UUID {
t.Helper()
var id uuid.UUID
if err := migrator.QueryRow(context.Background(),
`INSERT INTO requirements (organization_id, title, required_level, required_poly)
VALUES ($1,'Bench Gap Req',$2,'none') RETURNING id`,
org, level).Scan(&id); err != nil {
t.Fatalf("seed requirement: %v", err)
}
return id
}
// seedRequiredSkill attaches a required skill to a requirement in one org via the migrator.
func seedRequiredSkill(t *testing.T, org, requirement, skill uuid.UUID, mandatory bool) {
t.Helper()
if _, err := migrator.Exec(context.Background(),
`INSERT INTO required_skills (organization_id, requirement_id, skill_id, mandatory) VALUES ($1,$2,$3,$4)
ON CONFLICT (requirement_id, skill_id) DO NOTHING`,
org, requirement, skill, mandatory); err != nil {
t.Fatalf("seed required skill: %v", err)
}
}
// seedEvaluation writes one candidate_evaluations row (the already audited frozen engine decision) for a
// candidate against a requirement, with the given band. The score columns are filled with valid placeholders
// (the band is the only field the readiness distribution reads), so the row satisfies the NOT NULL and CHECK
// constraints. It uses the migrator so the seed crosses tenants for the RLS isolation proof.
func seedEvaluation(t *testing.T, org, candidate, requirement uuid.UUID, band string) {
t.Helper()
if _, err := migrator.Exec(context.Background(),
`INSERT INTO candidate_evaluations (
organization_id, candidate_id, requirement_id, total_score, band,
clearance_score, skills_score, certs_score, customer_score, experience_score, location_score,
explanation, model_version
) VALUES ($1,$2,$3,80,$4,100,100,100,100,100,100,'seeded for the readiness distribution test','v1.4.0')
ON CONFLICT (organization_id, candidate_id, requirement_id) DO UPDATE SET band = EXCLUDED.band`,
org, candidate, requirement, band); err != nil {
t.Fatalf("seed evaluation: %v", err)
}
}
// bucketCount returns the published headcount for a bucket label from a skill or gap partition, or minus one
// when that cell is suppressed or absent (so a caller asserting an exact published count fails loudly).
func skillBucketCount(rows []ai.BenchSkillRow, bucket string) int {
for _, r := range rows {
if r.Bucket == bucket {
if r.Cell.Suppressed {
return -1
}
return r.Cell.Count
}
}
return -1
}
func gapBucketCount(rows []ai.BenchGapRow, bucket string) int {
for _, r := range rows {
if r.Bucket == bucket {
if r.Cell.Suppressed {
return -1
}
return r.Cell.Count
}
}
return -1
}
func bandCount(rows []ai.BenchBandRow, band string) int {
for _, r := range rows {
if r.Band == band {
if r.Cell.Suppressed {
return -1
}
return r.Cell.Count
}
}
return -1
}
// ---------- C1 bench_skill_coverage ----------
// TestG4BenchSkillCoverageSuppressesSubK proves bench_skill_coverage live under RLS: it seeds one org with at
// least k candidates HOLDING a skill (published) and fewer than k LACKING it (the smaller side), then asserts
// the sub k bucket renders the SuppressionSentinel (never the raw number), and complementary suppression
// hides at least two cells so the small bucket is never recoverable as the bench size minus the published
// bucket. The published plus the seeded (suppressed) counts sum to the seeded bench size, the two bucket
// partition invariant. Org and skill ids are unique per run.
func TestG4BenchSkillCoverageSuppressesSubK(t *testing.T) {
org := seedOrg(t)
k := ai.ConfiguredSuppressionThreshold()
skill := seedSkillByName(t, "BenchSkill-"+uuid.NewString())
// holds: k plus 2 candidates that carry the skill (published regardless of a configured k).
holds := k + 2
for i := 0; i < holds; i++ {
c := seedCandidate(t, org, "secret", "active", true)
seedCandidateSkill(t, org, c.ID, skill)
}
// lacks: 3 candidates with no skill row (below any valid k, which is floored at 5), so it must suppress.
lacks := 3
for i := 0; i < lacks; i++ {
seedCandidate(t, org, "secret", "active", true)
}
seededTotal := holds + lacks
rows, err := ai.BenchSkillCoverage(ctxOrg(org), appDB, skill.String(), k)
if err != nil {
t.Fatalf("bench skill coverage: %v", err)
}
if len(rows) != 2 {
t.Fatalf("the skill coverage must return the two bucket partition, got %d cells", len(rows))
}
// A two bucket partition with one sub k bucket fully suppresses. Primary suppression hides the small
// lacks cell (3), then complementary suppression hides the holds cell too, because the owner knows the
// bench size so a lone published holds would let lacks be recovered by subtraction. The privacy correct
// outcome for a two bucket partition with ANY sub k cell is that BOTH cells suppress.
hiddenCells, totalCount := 0, 0
for _, r := range rows {
totalCount += r.Cell.Count
if r.Cell.Suppressed {
hiddenCells++
if ai.RenderCount(r.Cell) != ai.SuppressionSentinel {
t.Errorf("a suppressed cell must render the sentinel %q, got %q", ai.SuppressionSentinel, ai.RenderCount(r.Cell))
}
} else {
t.Errorf("bucket %q published a count, but a two bucket partition with a sub k cell must hide both, the complement is recoverable by subtraction", r.Bucket)
}
}
if hiddenCells != 2 {
t.Errorf("a two bucket partition with a sub k cell must hide BOTH cells, got %d hidden", hiddenCells)
}
// The complete partition's counts sum to the seeded bench size even though both cells render the sentinel.
if totalCount != seededTotal {
t.Errorf("the two bucket partition counts must sum to the seeded bench size %d, got %d", seededTotal, totalCount)
}
// Re run determinism: the same org and skill yield the same suppression pattern.
again, err := ai.BenchSkillCoverage(ctxOrg(org), appDB, skill.String(), k)
if err != nil {
t.Fatalf("bench skill coverage re run: %v", err)
}
if len(again) != len(rows) {
t.Fatalf("the coverage must be byte stable on a re run, got %d then %d cells", len(rows), len(again))
}
for i := range rows {
if rows[i].Bucket != again[i].Bucket || rows[i].Cell.Suppressed != again[i].Cell.Suppressed {
t.Errorf("the suppression pattern must be deterministic across runs at index %d", i)
}
}
}
// TestG4BenchSkillCoverageRLSIsolation proves the skill coverage is RLS scoped: a second org's bench never
// enters the first org's partition. Each org holds a distinct number of holders of the SAME global skill;
// org A's coverage must report only org A's holders, never org A plus org B. Org ids are unique per run.
func TestG4BenchSkillCoverageRLSIsolation(t *testing.T) {
orgA, orgB := seedOrg(t), seedOrg(t)
k := ai.ConfiguredSuppressionThreshold()
skill := seedSkillByName(t, "BenchSkillRLS-"+uuid.NewString())
// A two bucket partition only publishes when NEITHER side is a small cell, so each org gets holders AND
// at least k lackers (candidates without the skill), making both buckets at or above k so the holds count
// publishes. org A: k+5 holders, org B: k+1 holders, each with k lackers. The holds count must reflect
// only the querying org's bench, never the other org's.
countA := k + 5
countB := k + 1
lackers := k
for i := 0; i < countA; i++ {
c := seedCandidate(t, orgA, "secret", "active", true)
seedCandidateSkill(t, orgA, c.ID, skill)
}
for i := 0; i < lackers; i++ {
seedCandidate(t, orgA, "secret", "active", true)
}
for i := 0; i < countB; i++ {
c := seedCandidate(t, orgB, "secret", "active", true)
seedCandidateSkill(t, orgB, c.ID, skill)
}
for i := 0; i < lackers; i++ {
seedCandidate(t, orgB, "secret", "active", true)
}
rowsA, err := ai.BenchSkillCoverage(ctxOrg(orgA), appDB, skill.String(), k)
if err != nil {
t.Fatalf("bench skill coverage org A: %v", err)
}
if got := skillBucketCount(rowsA, "holds"); got != countA {
t.Fatalf("org A holds coverage = %d, want %d (a leak of org B's bench?)", got, countA)
}
rowsB, err := ai.BenchSkillCoverage(ctxOrg(orgB), appDB, skill.String(), k)
if err != nil {
t.Fatalf("bench skill coverage org B: %v", err)
}
if got := skillBucketCount(rowsB, "holds"); got != countB {
t.Fatalf("org B holds coverage = %d, want %d", got, countB)
}
}
// ---------- C2 bench_readiness_distribution ----------
// TestG4BenchReadinessDistributionSuppressesSubK proves bench_readiness_distribution live under RLS, reading
// the already audited candidate_evaluations band (never recomputing a score): it seeds one requirement with
// at least k green evaluations (published) and fewer than k yellow (suppressed), then asserts the sub k band
// renders the sentinel, complementary suppression hides at least two cells, and the published plus seeded
// counts sum to the seeded evaluated count.
func TestG4BenchReadinessDistributionSuppressesSubK(t *testing.T) {
org := seedOrg(t)
k := ai.ConfiguredSuppressionThreshold()
req := seedRequirementWithLevel(t, org, "secret")
// green: k plus 2 evaluated candidates (published). yellow: 3 (suppressed). red: 0 (a true zero).
green := k + 2
for i := 0; i < green; i++ {
c := seedCandidate(t, org, "secret", "active", true)
seedEvaluation(t, org, c.ID, req, "green")
}
yellow := 3
for i := 0; i < yellow; i++ {
c := seedCandidate(t, org, "secret", "active", true)
seedEvaluation(t, org, c.ID, req, "yellow")
}
evaluatedTotal := green + yellow
rows, err := ai.BenchReadinessDistribution(ctxOrg(org), appDB, req.String(), k)
if err != nil {
t.Fatalf("bench readiness distribution: %v", err)
}
if len(rows) != 3 {
t.Fatalf("the readiness distribution must return the green, yellow, red partition, got %d cells", len(rows))
}
var hiddenCells, publishedSum int
for _, r := range rows {
if r.Cell.Suppressed {
hiddenCells++
if ai.RenderCount(r.Cell) != ai.SuppressionSentinel {
t.Errorf("a suppressed band cell must render the sentinel, got %q", ai.RenderCount(r.Cell))
}
} else {
publishedSum += r.Cell.Count
if r.Band == "green" && r.Cell.Count != green {
t.Errorf("the green band must count exactly the %d seeded green evaluations, got %d", green, r.Cell.Count)
}
}
}
if got := bandCount(rows, "green"); got != green {
t.Errorf("the green band of %d (at or above k=%d) must be published with its exact count, got %d", green, k, got)
}
// The yellow band of 3 is sub k and must be suppressed; complementary suppression then hides a second cell.
if hiddenCells < 2 {
t.Errorf("complementary suppression must hide at least 2 band cells when any is hidden, got %d", hiddenCells)
}
if publishedSum > evaluatedTotal {
t.Errorf("the published distribution sum %d must not exceed the seeded evaluated total %d", publishedSum, evaluatedTotal)
}
}
// ---------- C3 bench_gap_for_requirement ----------
// TestG4BenchGapForRequirementSuppressesSubK proves bench_gap_for_requirement live under RLS as a STRUCTURAL
// coverage count (never a match score): it seeds a requirement at secret with one required skill, at least k
// candidates that MEET it (hold secret or higher AND hold the required skill, published), and fewer than k
// that do NOT meet it (a lower clearance, suppressed), then asserts the sub k bucket renders the sentinel,
// complementary suppression hides at least two cells, and the published plus seeded counts sum to the seeded
// bench size.
func TestG4BenchGapForRequirementSuppressesSubK(t *testing.T) {
org := seedOrg(t)
k := ai.ConfiguredSuppressionThreshold()
req := seedRequirementWithLevel(t, org, "secret")
skill := seedSkillByName(t, "GapSkill-"+uuid.NewString())
seedRequiredSkill(t, org, req, skill, true)
// meets: k plus 2 candidates at secret holding the required skill (published).
meets := k + 2
for i := 0; i < meets; i++ {
c := seedCandidate(t, org, "secret", "active", true)
seedCandidateSkill(t, org, c.ID, skill)
}
// does not meet: 3 candidates at confidential (a lower rank than secret), so the clearance arm fails.
doesNotMeet := 3
for i := 0; i < doesNotMeet; i++ {
seedCandidate(t, org, "confidential", "active", true)
}
seededTotal := meets + doesNotMeet
rows, err := ai.BenchGapForRequirement(ctxOrg(org), appDB, req.String(), k)
if err != nil {
t.Fatalf("bench gap for requirement: %v", err)
}
if len(rows) != 2 {
t.Fatalf("the gap must return the two bucket partition, got %d cells", len(rows))
}
// A two bucket partition with one sub k bucket fully suppresses: primary hides the small does_not_meet
// cell (3), then complementary hides the meets cell too (the owner knows the bench size, so a lone
// published meets would let does_not_meet be recovered by subtraction). Both cells suppress.
hiddenCells, totalCount := 0, 0
for _, r := range rows {
totalCount += r.Cell.Count
if r.Cell.Suppressed {
hiddenCells++
if ai.RenderCount(r.Cell) != ai.SuppressionSentinel {
t.Errorf("a suppressed gap cell must render the sentinel, got %q", ai.RenderCount(r.Cell))
}
} else {
t.Errorf("gap bucket %q published a count, but a two bucket partition with a sub k cell must hide both", r.Bucket)
}
}
if hiddenCells != 2 {
t.Errorf("a two bucket gap partition with a sub k cell must hide BOTH cells, got %d hidden", hiddenCells)
}
if totalCount != seededTotal {
t.Errorf("the gap partition counts must sum to the seeded bench size %d, got %d", seededTotal, totalCount)
}
}
// TestG4BenchGapForRequirementRLSIsolation proves the gap count is RLS scoped: org A's gap for ITS OWN
// requirement never counts org B's bench. The requirement is org A's; under org A's session the gap counts
// only org A's candidates, and a foreign org requirement id returns an empty (zero) partition under org B.
func TestG4BenchGapForRequirementRLSIsolation(t *testing.T) {
orgA, orgB := seedOrg(t), seedOrg(t)
k := ai.ConfiguredSuppressionThreshold()
reqA := seedRequirementWithLevel(t, orgA, "secret")
// org A: k+3 candidates at secret (meet on clearance, no required skills so the skills arm is vacuously
// met) AND k candidates at confidential (a lower rank, so they do NOT meet), making both buckets at or
// above k so the meets count publishes. org B: k+9 candidates at secret, which must NOT enter org A's gap.
countA := k + 3
for i := 0; i < countA; i++ {
seedCandidate(t, orgA, "secret", "active", true)
}
for i := 0; i < k; i++ {
seedCandidate(t, orgA, "confidential", "active", true)
}
for i := 0; i < k+9; i++ {
seedCandidate(t, orgB, "secret", "active", true)
}
rowsA, err := ai.BenchGapForRequirement(ctxOrg(orgA), appDB, reqA.String(), k)
if err != nil {
t.Fatalf("bench gap org A: %v", err)
}
if got := gapBucketCount(rowsA, "meets"); got != countA {
t.Fatalf("org A meets count = %d, want %d (a leak of org B's bench?)", got, countA)
}
// Under org B's session, org A's requirement id is invisible (RLS), so the requirement CROSS JOIN yields
// no rows and the partition is all zeros, hence suppressed away. The meets bucket is not published.
rowsB, err := ai.BenchGapForRequirement(ctxOrg(orgB), appDB, reqA.String(), k)
if err != nil {
t.Fatalf("bench gap org B against org A's requirement: %v", err)
}
if got := gapBucketCount(rowsB, "meets"); got != -1 {
t.Fatalf("org B must not see org A's requirement gap, expected a suppressed or absent meets cell, got %d", got)
}
}