Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/modules/matching/convert_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 39df94f92b2a33f852481fe1954dabed841524bb |
| Branch | w0-aedt-compliance |
| Path or archive member | internal/modules/matching/convert_test.go |
| Original SHA-256 | 3a0fc812d2ff1e8a1a5844cdc0be59a6e1ddbaca8df0da9020da7684c92579b1 |
| Git blob SHA | 681e6549cac0405e8401b7f72bf5252e29b5628d |
| Reading-copy SHA-256 | 3a0fc812d2ff1e8a1a5844cdc0be59a6e1ddbaca8df0da9020da7684c92579b1 |
Recovered source transcript
Download complete source text ↓149 lines · 5.4 KB
package matching
import (
"encoding/json"
"testing"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"github.com/shopspring/decimal"
"github.com/missionworkforce/missionmatch/internal/modules/matching/engine"
"github.com/missionworkforce/missionmatch/internal/platform/database/dbgen"
)
func TestToEngineCandidateMapsCodes(t *testing.T) {
id := uuid.New()
skillID := uuid.New()
c := dbgen.Candidate{
ID: id,
ClearanceLevel: "secret",
ClearancePoly: "none",
ClearanceStatus: "active",
YearsExperience: 7,
Available: true,
}
ec, err := ToEngineCandidate(c,
[]dbgen.ListCandidateSkillsRow{{ID: skillID, Name: "Go"}},
[]string{"Security+"}, []string{"DISA"}, time.Now())
if err != nil {
t.Fatalf("convert: %v", err)
}
if ec.Clearance.Level != engine.ClearanceSecret || ec.Clearance.Status != engine.StatusActive {
t.Fatalf("clearance mapped wrong: %+v", ec.Clearance)
}
if len(ec.Skills) != 1 || ec.Skills[0].SkillID != skillID.String() || ec.Skills[0].Name != "Go" {
t.Fatalf("skills mapped wrong: %+v", ec.Skills)
}
if ec.YearsExperience != 7 || !ec.Available {
t.Fatalf("scalar fields mapped wrong: %+v", ec)
}
}
func TestClearanceExpiryDowngradesActiveToExpired(t *testing.T) {
asOf := time.Date(2026, 6, 23, 0, 0, 0, 0, time.UTC)
expired := pgtype.Date{Time: asOf.AddDate(0, 0, -1), Valid: true}
future := pgtype.Date{Time: asOf.AddDate(0, 0, 30), Valid: true}
c := dbgen.Candidate{ID: uuid.New(), ClearanceLevel: "ts_sci", ClearancePoly: "full_scope", ClearanceStatus: "active"}
c.ClearanceExpiresAt = expired
ec, _ := ToEngineCandidate(c, nil, nil, nil, asOf)
if ec.Clearance.Status != engine.StatusExpired {
t.Fatalf("past expiry must downgrade Active->Expired, got %v", ec.Clearance.Status)
}
c.ClearanceExpiresAt = future
ec, _ = ToEngineCandidate(c, nil, nil, nil, asOf)
if ec.Clearance.Status != engine.StatusActive {
t.Fatalf("future expiry must remain Active, got %v", ec.Clearance.Status)
}
}
func TestClearanceExpiryBoundaryDay(t *testing.T) {
// asOf carries a wall-clock time (mimics s.clock()=time.Now()). A clearance expiring on the SAME
// civil day must stay Active so this agrees with the WCC's `>= as_of::date` boundary [ENGINE-1/2].
asOf := time.Date(2026, 6, 23, 14, 30, 0, 0, time.UTC)
c := dbgen.Candidate{ID: uuid.New(), ClearanceLevel: "secret", ClearancePoly: "none", ClearanceStatus: "active"}
c.ClearanceExpiresAt = pgtype.Date{Time: time.Date(2026, 6, 23, 0, 0, 0, 0, time.UTC), Valid: true}
ec, _ := ToEngineCandidate(c, nil, nil, nil, asOf)
if ec.Clearance.Status != engine.StatusActive {
t.Fatalf("clearance expiring on the as-of day must stay Active, got %v", ec.Clearance.Status)
}
c.ClearanceExpiresAt = pgtype.Date{Time: time.Date(2026, 6, 22, 0, 0, 0, 0, time.UTC), Valid: true}
ec, _ = ToEngineCandidate(c, nil, nil, nil, asOf)
if ec.Clearance.Status != engine.StatusExpired {
t.Fatalf("clearance expiring the day before must be Expired, got %v", ec.Clearance.Status)
}
}
func TestConvertRejectsInvalidCode(t *testing.T) {
c := dbgen.Candidate{ID: uuid.New(), ClearanceLevel: "TS/SCI", ClearancePoly: "none", ClearanceStatus: "active"}
if _, err := ToEngineCandidate(c, nil, nil, nil, time.Now()); err == nil {
t.Fatal("the human label 'TS/SCI' is not a DB code — must error")
}
}
func TestToEngineRequirementMapsCodes(t *testing.T) {
skillID := uuid.New()
agency := "DISA"
r := dbgen.Requirement{
ID: uuid.New(),
RequiredLevel: "top_secret",
RequiredPoly: "ci",
RequiredYears: 5,
CustomerAgency: &agency,
KeyPersonnel: true,
}
er, err := ToEngineRequirement(r,
[]dbgen.ListRequiredSkillsRow{{ID: skillID, Name: "AWS", Mandatory: true}}, []string{"CISSP"})
if err != nil {
t.Fatalf("convert: %v", err)
}
if er.RequiredLevel != engine.ClearanceTopSecret || er.RequiredPoly != engine.PolyCI {
t.Fatalf("clearance mapped wrong: %+v", er)
}
if er.CustomerAgency != "DISA" || er.RequiredYears != 5 || !er.KeyPersonnel {
t.Fatalf("fields mapped wrong: %+v", er)
}
if len(er.RequiredSkills) != 1 || !er.RequiredSkills[0].Mandatory {
t.Fatalf("required skills mapped wrong: %+v", er.RequiredSkills)
}
}
func TestToSlateMemberParamsFreezesDecision(t *testing.T) {
// Build a perfect engine result and freeze it.
c := engine.Candidate{
ID: uuid.New().String(),
Clearance: engine.Clearance{Level: engine.ClearanceSecret, Status: engine.StatusActive},
Available: true,
}
r := engine.Requirement{ID: uuid.New().String()} // nothing required => all components 100
res := engine.ScoreCandidate(c, r, nil)
orgID, slateID, candID := uuid.New(), uuid.New(), uuid.New()
rank := int32(1)
p, err := ToSlateMemberParams(orgID, slateID, candID, res, &rank)
if err != nil {
t.Fatalf("freeze: %v", err)
}
if p.Band != "green" {
t.Fatalf("band must be the DB code 'green', got %q", p.Band)
}
if !p.TotalScore.Equal(res.Total) || !p.TotalScore.Equal(decimal.NewFromInt(100)) {
t.Fatalf("total score not frozen correctly: %s", p.TotalScore)
}
// Trace must be a valid JSON array (the AEDT decision trace).
var trace []map[string]any
if err := json.Unmarshal(p.Trace, &trace); err != nil || len(trace) != 6 {
t.Fatalf("trace not valid 6-row JSON: err=%v len=%d", err, len(trace))
}
// Gap summary must be '[]' (never null) when there are no gaps.
if string(p.GapSummary) != "[]" {
t.Fatalf("gap summary should be '[]', got %q", string(p.GapSummary))
}
}