Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/integration/teaching_producer_integration_test.go |
| Original SHA-256 | e35a9ee6d7d99c46e65d139e8926ba80552ef8624b1b327816026caa15ee9e39 |
| Git blob SHA | edb447e456c22a7c12c415c009e49c3ccb003ec5 |
| Reading-copy SHA-256 | e35a9ee6d7d99c46e65d139e8926ba80552ef8624b1b327816026caa15ee9e39 |
Every recorded occurrence
These 14 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/teaching_producer_integration_test.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go | m5-price-to-win | 41000ad30fff4129fdaf5ec84e15ba14c27d4890 | Open original |
| Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go | ws8-teaching-loop | c823f0fb6bb2aba0f39001eb6de96f4000d9321f | Open original |
| Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go | mag-substrate | b82c7100a492dec67dfd1eda6b3f53def859be35 | Open original |
| Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go | graphrag-foundation | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 | Open original |
| Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go | ws9-bench-ingestion | f585a9ef32fa554663ce1fba9a414a54b6e49cf0 | Open original |
| Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go | phase2-connectors | e038d4c687aec16f8bd9bc4d907eea14d91f8704 | Open original |
| Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/integration/teaching_producer_integration_test.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓247 lines · 10.1 KB
//go:build integration
package integration
import (
"context"
"encoding/json"
"testing"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/shopspring/decimal"
"github.com/missionworkforce/missionmatch/internal/modules/ai"
"github.com/missionworkforce/missionmatch/internal/modules/matching/engine"
"github.com/missionworkforce/missionmatch/internal/platform/audit"
"github.com/missionworkforce/missionmatch/internal/platform/database/dbgen"
"github.com/missionworkforce/missionmatch/internal/platform/inference"
)
// TestTeachingProducerAggregatesInTenantRows proves the WS8 Phase 1 producer end to end against real
// Postgres: the read is RLS scoped (it sees only the caller org's slate decisions, never a second org's),
// the audit event commits on the same tenant tx, and the per tenant aggregates land in the global
// teaching_signal_aggregates table with tenant_id set and dp_applied false. It seeds TWO orgs with distinct
// reviewer craft; running the producer for org A must fold only org A's evidence.
func TestTeachingProducerAggregatesInTenantRows(t *testing.T) {
// Org A: a clearance gap override (required secret, clearance_score 0, approved) plus an adjacent skill
// substitution stored in the evaluation (a non exact match at cosine 0.91, a high band), approved.
orgA := seedOrg(t)
_ = seedTeachingMember(t, orgA, teachingSeed{
requiredLevel: "secret",
clearanceScore: "0",
experience: "100",
decision: "approved",
matchedSkills: []teachSeedSkill{{similarity: "0.91", exact: false, matched: true}},
})
// Org B: a completely different shape (no clearance required, an experience shortfall, rejected). If the
// producer's read were not RLS scoped, org A's run would fold this too and the counts would be wrong.
orgB := seedOrg(t)
_ = seedTeachingMember(t, orgB, teachingSeed{
requiredLevel: "none",
clearanceScore: "100",
experience: "20",
decision: "rejected",
matchedSkills: nil,
})
// A teaching client with TeachingEnabled false: Teach validates the boundary but transmits nothing.
teacher, err := inference.New(inference.Config{BaseURL: "http://127.0.0.1:0", TeachingEnabled: false})
if err != nil {
t.Fatalf("inference client: %v", err)
}
// The aggregate writer is backed by the MIGRATOR pool (the global table the app role cannot write).
writer := ai.NewMigratorAggregateWriter(migrator)
prod := ai.NewTeachingProducer(appDB, writer, audit.New(appDB), teacher)
res, err := prod.AggregateForOrg(ctxOrg(orgA))
if err != nil {
t.Fatalf("AggregateForOrg(orgA): %v", err)
}
// RLS scoped read: org A has exactly one slate member, so exactly one decision was read, never org B's.
if res.DecisionsRead != 1 {
t.Fatalf("DecisionsRead = %d, want 1 (the read must be RLS scoped to org A only)", res.DecisionsRead)
}
// Org A's evidence folds two patterns: clearance_gap_override_outcome (unknown band, approved) and
// adjacent_skill_substitution_outcome (high band, approved). Both must be persisted for org A.
rows := teachingAggregatesForTenant(t, orgA)
if len(rows) != len(res.Signals) || len(rows) == 0 {
t.Fatalf("persisted %d aggregate rows for org A, produced %d signals", len(rows), len(res.Signals))
}
sawClearance, sawSubstitution := false, false
for _, r := range rows {
if r.TenantID == nil || *r.TenantID != orgA {
t.Fatalf("aggregate tenant_id = %v, want org A %v (a live in tenant row)", r.TenantID, orgA)
}
if r.DpApplied {
t.Fatal("aggregate dp_applied = true, want false for a live in tenant row")
}
if r.ModelVersion != engine.ModelVersion {
t.Fatalf("aggregate model_version = %q, want engine.ModelVersion %q", r.ModelVersion, engine.ModelVersion)
}
switch r.Pattern {
case "clearance_gap_override_outcome":
sawClearance = true
if r.Band != "unknown" || r.Outcome != "approved" || r.Observations != 1 || r.Successes != 1 {
t.Fatalf("clearance aggregate = %+v, want unknown/approved/1/1", r)
}
case "adjacent_skill_substitution_outcome":
sawSubstitution = true
if r.Band != "high" || r.Outcome != "approved" || r.Observations != 1 || r.Successes != 1 {
t.Fatalf("substitution aggregate = %+v, want high/approved/1/1", r)
}
}
}
if !sawClearance || !sawSubstitution {
t.Fatalf("missing expected aggregates: clearance=%v substitution=%v", sawClearance, sawSubstitution)
}
// Org B has no aggregates, proving the producer never wrote for an org it was not run on.
if got := teachingAggregatesForTenant(t, orgB); len(got) != 0 {
t.Fatalf("org B has %d aggregate rows, want 0 (the producer ran only for org A)", len(got))
}
// The teaching.signal.aggregated audit event committed on org A's tenant tx, carrying counts only.
var auditCount int
var newVals []byte
if err := appDB.RunInTenantTx(ctxOrg(orgA), func(ctx context.Context, tx pgx.Tx) error {
return tx.QueryRow(ctx,
`SELECT count(*), max(new_values::text) FROM audit_logs
WHERE organization_id=$1 AND action='teaching.signal.aggregated'`,
orgA).Scan(&auditCount, &newVals)
}); err != nil {
t.Fatalf("count teaching audit: %v", err)
}
if auditCount != 1 {
t.Fatalf("want 1 teaching.signal.aggregated audit for org A, got %d", auditCount)
}
var payload map[string]int
if err := json.Unmarshal(newVals, &payload); err != nil {
t.Fatalf("audit payload not the counts only shape: %v (%s)", err, newVals)
}
if payload["decisions_aggregated"] != 1 {
t.Fatalf("audit decisions_aggregated = %d, want 1", payload["decisions_aggregated"])
}
// A rerun is idempotent (ON CONFLICT upserts in place), so the row count does not grow.
if _, err := prod.AggregateForOrg(ctxOrg(orgA)); err != nil {
t.Fatalf("AggregateForOrg(orgA) rerun: %v", err)
}
if got := teachingAggregatesForTenant(t, orgA); len(got) != len(rows) {
t.Fatalf("rerun changed the aggregate row count from %d to %d (upsert must be idempotent)", len(rows), len(got))
}
}
// ---- seed helpers (write across tenants via the BYPASSRLS migrator) ----
type teachSeedSkill struct {
similarity string
exact bool
matched bool
}
type teachingSeed struct {
requiredLevel string
clearanceScore string
experience string
decision string
matchedSkills []teachSeedSkill
}
// seedTeachingMember seeds one requirement, one slate, one decided slate member, and (when matchedSkills is
// set) one candidate_evaluations row carrying the match evidence the producer reads. It returns the
// candidate id. Everything is written through the migrator so the seed can span orgs.
func seedTeachingMember(t *testing.T, org uuid.UUID, s teachingSeed) uuid.UUID {
t.Helper()
ctx := context.Background()
q := dbgen.New(migrator)
req, err := q.CreateRequirement(ctx, dbgen.CreateRequirementParams{
OrganizationID: org, Title: "Teaching Role", RequiredLevel: s.requiredLevel, RequiredPoly: "none",
})
if err != nil {
t.Fatalf("seed requirement: %v", err)
}
cand := seedCandidate(t, org, "none", "active", true)
slate, err := q.CreateSlate(ctx, dbgen.CreateSlateParams{
OrganizationID: org, RequirementID: req.ID, Name: "Teaching Slate", Status: "in_review",
})
if err != nil {
t.Fatalf("seed slate: %v", err)
}
mv := engine.ModelVersion
if _, err := q.AddSlateMember(ctx, dbgen.AddSlateMemberParams{
OrganizationID: org, SlateID: slate.ID, CandidateID: cand.ID,
TotalScore: dec0("80"), Band: "yellow",
ClearanceScore: dec0(s.clearanceScore), SkillsScore: dec0("100"), CertsScore: dec0("100"),
CustomerScore: dec0("100"), ExperienceScore: dec0(s.experience), LocationScore: dec0("100"),
Explanation: "seeded", Trace: []byte("[]"), GapSummary: []byte("[]"), ModelVersion: &mv,
}); err != nil {
t.Fatalf("seed slate member: %v", err)
}
if _, err := q.SetSlateMemberDecision(ctx, dbgen.SetSlateMemberDecisionParams{
SlateID: slate.ID, CandidateID: cand.ID, Decision: s.decision,
}); err != nil {
t.Fatalf("seed decision: %v", err)
}
if len(s.matchedSkills) > 0 {
matched := make([]map[string]any, 0, len(s.matchedSkills))
for _, sk := range s.matchedSkills {
matched = append(matched, map[string]any{
"RequiredSkillID": "", "RequiredSkillName": "skill", "CandidateSkillID": "",
"CandidateName": "", "Similarity": sk.similarity, "Exact": sk.exact, "Matched": sk.matched,
})
}
mj, err := json.Marshal(matched)
if err != nil {
t.Fatalf("marshal matched skills: %v", err)
}
if err := q.UpsertCandidateEvaluation(ctx, dbgen.UpsertCandidateEvaluationParams{
OrganizationID: org, CandidateID: cand.ID, RequirementID: req.ID,
TotalScore: dec0("80"), Band: "yellow",
ClearanceScore: dec0(s.clearanceScore), SkillsScore: dec0("100"), CertsScore: dec0("100"),
CustomerScore: dec0("100"), ExperienceScore: dec0(s.experience), LocationScore: dec0("100"),
Explanation: "seeded", MatchedSkills: mj, GapSummary: []byte("[]"), ModelVersion: engine.ModelVersion,
}); err != nil {
t.Fatalf("seed evaluation: %v", err)
}
}
return cand.ID
}
// teachingAggregatesForTenant reads the global teaching_signal_aggregates rows for one tenant through the
// migrator (the table is global, so the migrator sees all rows; we filter by tenant_id in the query).
func teachingAggregatesForTenant(t *testing.T, tenantID uuid.UUID) []dbgen.TeachingSignalAggregate {
t.Helper()
rows, err := migrator.Query(context.Background(),
`SELECT id, tenant_id, dp_applied, pattern, band, outcome, model_version, observations, successes,
window_start, window_end, created_at
FROM teaching_signal_aggregates WHERE tenant_id=$1
ORDER BY pattern, band, outcome`, tenantID)
if err != nil {
t.Fatalf("query aggregates: %v", err)
}
defer rows.Close()
var out []dbgen.TeachingSignalAggregate
for rows.Next() {
var r dbgen.TeachingSignalAggregate
if err := rows.Scan(&r.ID, &r.TenantID, &r.DpApplied, &r.Pattern, &r.Band, &r.Outcome,
&r.ModelVersion, &r.Observations, &r.Successes, &r.WindowStart, &r.WindowEnd, &r.CreatedAt); err != nil {
t.Fatalf("scan aggregate: %v", err)
}
out = append(out, r)
}
if err := rows.Err(); err != nil {
t.Fatalf("rows err: %v", err)
}
return out
}
// dec0 builds a decimal for a seed value, failing the test on a malformed literal.
func dec0(s string) decimal.Decimal { return decimal.RequireFromString(s) }