package ai import ( "strings" "testing" ) // TestGraphBenchIntentsAreRegistered proves the three G4 bench intents are in the closed Registry, so // ValidateRegistry asserts them at boot and ExecuteIntent can run them. A missing intent means the // registration regressed. Each binds exactly one SQL param (a ParamUUID id); the suppression threshold is // a Go argument, never a bound SQL param. func TestGraphBenchIntentsAreRegistered(t *testing.T) { cases := map[string]int{ IntentBenchSkillCoverage: 1, // skill_id IntentBenchReadinessDistribution: 1, // requirement_id IntentBenchGapForRequirement: 1, // requirement_id } for name, wantParams := range cases { it, ok := IntentByName(name) if !ok { t.Fatalf("intent %q must be registered in the closed Registry", name) } if len(it.Params) != wantParams { t.Errorf("intent %q must bind exactly %d params, got %d", name, wantParams, len(it.Params)) } if len(it.Params) == 1 && it.Params[0].Kind != ParamUUID { t.Errorf("intent %q must bind a ParamUUID id, got %q", name, it.Params[0].Kind) } } } // TestGraphBenchIntentsPassTheReadOnlyGuard is the load bearing security assertion the task requires: each // of the three new bench SQL consts passes GuardReadOnlyQuery against the real ReadAllowlist with no error. // A query that referenced a non allowlisted table, hid a mutation, put a set returning function in a FROM // or JOIN position, or named an eeo marker would fail here, the same gate ValidateRegistry runs at boot and // ExecuteIntent re runs at execution time. func TestGraphBenchIntentsPassTheReadOnlyGuard(t *testing.T) { for _, tc := range []struct { name string sql string }{ {"bench_skill_coverage", benchSkillCoverageSQL}, {"bench_readiness_distribution", benchReadinessDistributionSQL}, {"bench_gap_for_requirement", benchGapForRequirementSQL}, } { if err := GuardReadOnlyQuery(tc.sql, ReadAllowlist); err != nil { t.Errorf("the registered bench intent %q must pass the read only guard: %v", tc.name, err) } } } // TestValidateRegistryWithBenchIntents proves the whole closed Registry, now carrying the three G4 bench // intents alongside the TAG, G3, G1, G9, G7, G2, and G5 intents, validates at boot. This is the assertion // the api boot runs. func TestValidateRegistryWithBenchIntents(t *testing.T) { if err := ValidateRegistry(); err != nil { t.Fatalf("ValidateRegistry must pass with the three G4 bench intents registered: %v", err) } } // TestBenchIntentsAreGraphIntents proves the three G4 intents are classified as graph intents, so the // Answer dispatcher routes them to AnswerGraph rather than AnswerTAG. A regression that dropped one from // graphIntents would surface here. func TestBenchIntentsAreGraphIntents(t *testing.T) { for _, name := range []string{IntentBenchSkillCoverage, IntentBenchReadinessDistribution, IntentBenchGapForRequirement} { if !IsGraphIntent(name) { t.Errorf("the bench intent %q must be a graph intent", name) } } } // TestBenchIntentsAreBenchIntents proves the three G4 intents are in the benchIntents set, the person // touching intents that the D1 route gate will require an authenticated tenant context for. A regression // that dropped one would let a person touching read run without a resolved org. func TestBenchIntentsAreBenchIntents(t *testing.T) { for _, name := range []string{IntentBenchSkillCoverage, IntentBenchReadinessDistribution, IntentBenchGapForRequirement} { if !IsBenchIntent(name) { t.Errorf("the bench intent %q must be in the benchIntents set", name) } } // The G5 reference reads are NOT bench intents (no person data), so the gate must not require an // authenticated tenant for them; bench_clearance_coverage IS person touching, so it is a bench intent. if IsBenchIntent(IntentClearanceReachability) { t.Error("the clearance reachability reference read must NOT be a bench intent") } if !IsBenchIntent(IntentBenchClearanceCoverage) { t.Error("bench_clearance_coverage is person touching and must be a bench intent") } } // TestBenchSkillCoverageOrdersByBucketTiebreaker pins the byte stable mandate on the two bucket skill // coverage partition: it ends its ORDER BY with the bucket label, a total order over the two buckets. func TestBenchSkillCoverageOrdersByBucketTiebreaker(t *testing.T) { lower := strings.ToLower(benchSkillCoverageSQL) idx := strings.LastIndex(lower, "order by") if idx < 0 { t.Fatal("the skill coverage partition must be ordered for byte stability") } if !strings.Contains(lower[idx:], "bucket") { t.Errorf("the skill coverage ORDER BY must end with the bucket tiebreaker, got %q", lower[idx:]) } } // TestBenchReadinessReadsTheAuditedEvaluations pins that the readiness distribution reads the already // audited candidate_evaluations band, never recomputing a score. The band column is the frozen engine's // decision at evaluation time; the intent reports its distribution, it does not score anyone. func TestBenchReadinessReadsTheAuditedEvaluations(t *testing.T) { lower := strings.ToLower(benchReadinessDistributionSQL) if !strings.Contains(lower, "candidate_evaluations") { t.Error("the readiness distribution must read the already audited candidate_evaluations table") } if !strings.Contains(lower, "band") { t.Error("the readiness distribution must partition by the stored band, never a recomputed score") } } // TestBenchIntentsFilterErasedCandidates pins that the skill coverage and gap counts exclude a soft deleted // or an anonymized candidate, mirroring count_candidates_by_clearance, so an erased candidate is never // counted into a structural headcount. func TestBenchIntentsFilterErasedCandidates(t *testing.T) { for name, sql := range map[string]string{ "bench_skill_coverage": benchSkillCoverageSQL, "bench_gap_for_requirement": benchGapForRequirementSQL, } { lower := strings.ToLower(sql) if !strings.Contains(lower, "deleted_at is null") { t.Errorf("%s: the count must exclude soft deleted candidates (deleted_at IS NULL)", name) } if !strings.Contains(lower, "anonymized_at is null") { t.Errorf("%s: the count must exclude anonymized candidates (anonymized_at IS NULL)", name) } } } // TestNoFloatTouchesABenchNumber pins the decimal mandate across the three bench intents: no float cast may // touch any surfaced number. Every bench intent surfaces an int headcount, so no float cast belongs // anywhere on this plane. func TestNoFloatTouchesABenchNumber(t *testing.T) { for name, sql := range map[string]string{ "bench_skill_coverage": benchSkillCoverageSQL, "bench_readiness_distribution": benchReadinessDistributionSQL, "bench_gap_for_requirement": benchGapForRequirementSQL, } { lower := strings.ToLower(sql) for _, floatCast := range []string{"::float8", "::float", "::double precision", "::real"} { if strings.Contains(lower, floatCast) { t.Errorf("%s: a float cast %q must never touch a bench number (decimal mandate)", name, floatCast) } } } }