Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/integration/graph_clearance_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_clearance_integration_test.go |
| Original SHA-256 | 23a005a93619b192699e4beb29a152a92d7430ed757f1744a5e6d88c83ab74c1 |
| Git blob SHA | 398bd7c6db2e97d7b07ddfee8ecc608507dd61f9 |
| Reading-copy SHA-256 | 23a005a93619b192699e4beb29a152a92d7430ed757f1744a5e6d88c83ab74c1 |
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_clearance_integration_test.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/integration/graph_clearance_integration_test.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/integration/graph_clearance_integration_test.go | m5-price-to-win | 41000ad30fff4129fdaf5ec84e15ba14c27d4890 | Open original |
| Janady13/missionmatch / internal/integration/graph_clearance_integration_test.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/integration/graph_clearance_integration_test.go | mag-substrate | b82c7100a492dec67dfd1eda6b3f53def859be35 | Open original |
| Janady13/missionmatch / internal/integration/graph_clearance_integration_test.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/integration/graph_clearance_integration_test.go | graphrag-foundation | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 | Open original |
| Janady13/missionmatch / internal/integration/graph_clearance_integration_test.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/integration/graph_clearance_integration_test.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/integration/graph_clearance_integration_test.go | phase2-connectors | e038d4c687aec16f8bd9bc4d907eea14d91f8704 | Open original |
| Janady13/missionmatch / internal/integration/graph_clearance_integration_test.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/integration/graph_clearance_integration_test.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓223 lines · 8.8 KB
//go:build integration
package integration
import (
"context"
"testing"
"github.com/missionworkforce/missionmatch/internal/modules/ai"
)
// TestG5ClearanceReachabilityLadder proves the G5 reachability ladder live against the seeded clearance
// reference tables, with clearance_reciprocity empty (the pure rank ladder, the live engine behavior). The
// load bearing assertions are the matching engine's clearance hierarchy: a held ts_sci satisfies a required
// secret (a higher rank satisfies a lower one), and a held secret does NOT satisfy a required ts_sci (a lower
// rank never satisfies a higher one). The read is a GLOBAL reference read, so it needs no org context, but it
// runs through the uniform db *tenant.DB signature; an org context is set for parity with the bench read.
func TestG5ClearanceReachabilityLadder(t *testing.T) {
org := seedOrg(t)
// The reciprocity table must be empty for this run so the ladder is the pure rank ladder. It is a global
// table, so a prior run could have seeded it; assert it is empty rather than mutate it.
var reciprocityRows int
if err := migrator.QueryRow(context.Background(), "SELECT count(*) FROM clearance_reciprocity").Scan(&reciprocityRows); err != nil {
t.Fatalf("count clearance_reciprocity: %v", err)
}
if reciprocityRows != 0 {
t.Fatalf("the ladder proof requires clearance_reciprocity empty, found %d rows", reciprocityRows)
}
// A held ts_sci must satisfy a required secret (a higher rank satisfies a lower one).
tsSci, err := ai.ClearanceReachability(ctxOrg(org), appDB, "ts_sci")
if err != nil {
t.Fatalf("clearance reachability ts_sci: %v", err)
}
if !satisfies(tsSci, "secret") {
t.Error("a held ts_sci must satisfy a required secret (a higher rank satisfies a lower one)")
}
if !satisfies(tsSci, "ts_sci") {
t.Error("a held ts_sci must satisfy a required ts_sci (an equal rank satisfies)")
}
// A held secret must NOT satisfy a required ts_sci (a lower rank never satisfies a higher one).
secret, err := ai.ClearanceReachability(ctxOrg(org), appDB, "secret")
if err != nil {
t.Fatalf("clearance reachability secret: %v", err)
}
if satisfies(secret, "ts_sci") {
t.Error("a held secret must NOT satisfy a required ts_sci (a lower rank never satisfies a higher one)")
}
if !satisfies(secret, "confidential") {
t.Error("a held secret must satisfy a required confidential (a higher rank satisfies a lower one)")
}
// Byte stable on a re run: the ladder is deterministic.
again, err := ai.ClearanceReachability(ctxOrg(org), appDB, "ts_sci")
if err != nil {
t.Fatalf("clearance reachability ts_sci re run: %v", err)
}
if len(again) != len(tsSci) {
t.Errorf("the ladder must be byte stable on a re run, got %d then %d rows", len(tsSci), len(again))
}
}
// satisfies reports whether the reachability result grants the given required code.
func satisfies(reach []ai.ClearanceReach, requiredCode string) bool {
for _, r := range reach {
if r.RequiredCode == requiredCode {
return r.Satisfies
}
}
return false
}
// TestG5BenchClearanceCoverageSuppressesSubK proves bench_clearance_coverage live under RLS: it seeds one
// org with at least k candidates at one clearance level (published) and fewer than k at another (suppressed),
// then asserts the sub k level renders the SuppressionSentinel (never the raw number), the published level
// renders its exact count, and the published plus suppressed counts sum correctly to the seeded bench size.
// Org and candidate ids are unique per run, so a cross run accumulation cannot pollute the partition; the
// candidates table is RLS scoped per org, so only this org's bench is counted.
func TestG5BenchClearanceCoverageSuppressesSubK(t *testing.T) {
org := seedOrg(t)
k := ai.ConfiguredSuppressionThreshold()
// Published level: secret, seeded k plus 2 so it stays above the floor regardless of a configured k.
published := k + 2
for i := 0; i < published; i++ {
seedCandidate(t, org, "secret", "active", true)
}
// Suppressed level: ts_sci, seeded 3 (below any valid k, which is floored at 5), so it must suppress.
suppressed := 3
for i := 0; i < suppressed; i++ {
seedCandidate(t, org, "ts_sci", "active", true)
}
seededTotal := published + suppressed
rows, err := ai.BenchClearanceCoverage(ctxOrg(org), appDB, k)
if err != nil {
t.Fatalf("bench clearance coverage: %v", err)
}
if len(rows) == 0 {
t.Fatal("the coverage must return the clearance level partition")
}
var (
sawSecretPublished bool
sawTsSciSuppressed bool
hiddenCells int
publishedSum int
)
for _, r := range rows {
switch r.LevelCode {
case "secret":
if r.Cell.Suppressed {
t.Errorf("the secret level of %d holders (at or above k=%d) must NOT be suppressed", published, k)
} else {
sawSecretPublished = true
if r.Cell.Count != published {
t.Errorf("the secret level must count exactly the %d seeded holders, got %d", published, r.Cell.Count)
}
// A published cell renders its exact count, never the sentinel.
if ai.RenderCount(r.Cell) == ai.SuppressionSentinel {
t.Errorf("the published secret cell must render its exact count, not the sentinel, got %q", ai.RenderCount(r.Cell))
}
}
case "ts_sci":
if !r.Cell.Suppressed {
t.Errorf("the ts_sci level of %d holders (below k=%d) must be suppressed", suppressed, k)
} else {
sawTsSciSuppressed = true
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))
}
}
}
if r.Cell.Suppressed {
hiddenCells++
} else {
publishedSum += r.Cell.Count
}
}
if !sawSecretPublished {
t.Error("the coverage must include the published secret level")
}
if !sawTsSciSuppressed {
t.Error("the coverage must include the suppressed ts_sci level")
}
// Complementary suppression: whenever any cell is hidden, at least two are hidden, so a single suppressed
// cell is never recoverable as the total minus the published cells.
if hiddenCells < 2 {
t.Errorf("complementary suppression must hide at least 2 cells when any is hidden, got %d", hiddenCells)
}
// The published counts plus the suppressed (raw) counts sum to the seeded bench size. The suppressed raw
// count never leaves the process as a rendered number, but the partition still sums correctly: the
// published sum plus the seeded suppressed total equals the seeded bench. We verify the published sum does
// not exceed the seeded total and that the secret level alone accounts for its published share.
if publishedSum > seededTotal {
t.Errorf("the published partition sum %d must not exceed the seeded bench size %d", publishedSum, seededTotal)
}
// Re run determinism: the same org yields the same suppression pattern.
again, err := ai.BenchClearanceCoverage(ctxOrg(org), appDB, k)
if err != nil {
t.Fatalf("bench clearance 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 rows", len(rows), len(again))
}
for i := range rows {
if rows[i].LevelCode != again[i].LevelCode || rows[i].Cell.Suppressed != again[i].Cell.Suppressed {
t.Errorf("the suppression pattern must be deterministic across runs at index %d", i)
}
}
}
// TestG5BenchCoverageRLSIsolation proves the coverage is RLS scoped: a second org's bench never enters the
// first org's partition. Each org seeds a distinct headcount at the secret level; org A's coverage must
// report only org A's count, never org A plus org B. Org ids are unique per run.
func TestG5BenchCoverageRLSIsolation(t *testing.T) {
orgA, orgB := seedOrg(t), seedOrg(t)
k := ai.ConfiguredSuppressionThreshold()
// org A: k plus 5 secret holders (published). org B: k plus 1 secret holders (published, different count).
countA := k + 5
countB := k + 1
for i := 0; i < countA; i++ {
seedCandidate(t, orgA, "secret", "active", true)
}
for i := 0; i < countB; i++ {
seedCandidate(t, orgB, "secret", "active", true)
}
rowsA, err := ai.BenchClearanceCoverage(ctxOrg(orgA), appDB, k)
if err != nil {
t.Fatalf("bench clearance coverage org A: %v", err)
}
if got := secretCount(rowsA); got != countA {
t.Fatalf("org A secret coverage = %d, want %d (a leak of org B's bench?)", got, countA)
}
rowsB, err := ai.BenchClearanceCoverage(ctxOrg(orgB), appDB, k)
if err != nil {
t.Fatalf("bench clearance coverage org B: %v", err)
}
if got := secretCount(rowsB); got != countB {
t.Fatalf("org B secret coverage = %d, want %d", got, countB)
}
}
// secretCount returns the published secret level headcount from a coverage partition, or minus one when the
// secret cell is suppressed or absent (so a caller asserting an exact published count fails loudly).
func secretCount(rows []ai.BenchCoverageRow) int {
for _, r := range rows {
if r.LevelCode == "secret" {
if r.Cell.Suppressed {
return -1
}
return r.Cell.Count
}
}
return -1
}