Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/modules/opportunities/draftgen_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/modules/opportunities/draftgen_test.go |
| Original SHA-256 | a2b1f79d7c599237680939f3fa6fa5426d911f18fae11cec79b4adf36fb22ca5 |
| Git blob SHA | 4fafd0ddeee12e042a0ac4300fa79e6a0d714897 |
| Reading-copy SHA-256 | a2b1f79d7c599237680939f3fa6fa5426d911f18fae11cec79b4adf36fb22ca5 |
Recovered source transcript
Download complete source text ↓141 lines · 6.0 KB
package opportunities
import (
"reflect"
"strings"
"testing"
)
// PHASE 2 ITEM 5 and Section 6 screen 5: generate drafts from ACCEPTED staffing scope, show missing required
// fields, allow manual completion, require named approval, promote, preserve lineage. Generation did not
// exist, so the only way a draft ever appeared was for something else to write one.
//
// THE DERIVATION IS DETERMINISTIC AND PURE. It reads the accepted scope item's own text with the same signal
// extractor the rest of Section 5.1 uses, so what it produces is reproducible and explainable. A draft is
// pre approval by design, so a field it cannot find is left EMPTY and reported as missing rather than guessed.
// Guessing "secret" because a document mentions clearance would put a fabricated requirement in front of a
// reviewer with a plausible value already filled in, which is the worst possible shape for a human gate.
func TestDeriveDraftReadsClearanceQuantityAndYearsFromTheScopeText(t *testing.T) {
item := ScopeItem{
ID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
ScopeType: "labor_category",
Title: "Cyber Systems Operations Specialist",
Description: "The contractor shall provide four Cyber Systems Operations specialists holding TS/SCI with a CI polygraph, minimum of 5 years experience. Travel is estimated at 15 percent.",
}
got := DeriveDraft(item)
if got.LaborCategory != "Cyber Systems Operations Specialist" {
t.Errorf("labor category = %q, want the item title", got.LaborCategory)
}
if got.ClearanceLevel != "ts_sci" {
t.Errorf("clearance = %q, want ts_sci", got.ClearanceLevel)
}
if got.Polygraph != "ci" {
t.Errorf("polygraph = %q, want ci", got.Polygraph)
}
if got.Quantity != 4 {
t.Errorf("quantity = %d, want 4. Headcount is the most important number on the page", got.Quantity)
}
if got.MinimumYears != 5 {
t.Errorf("minimum years = %d, want 5", got.MinimumYears)
}
if got.TravelPercent != 15 {
t.Errorf("travel = %d, want 15", got.TravelPercent)
}
if got.SourceScopeItemID != item.ID {
t.Errorf("lineage lost: source scope item = %q, want %q", got.SourceScopeItemID, item.ID)
}
if got.DerivationMethod != "deterministic_scope" {
t.Errorf("derivation method = %q, want deterministic_scope", got.DerivationMethod)
}
}
func TestDeriveDraftLeavesWhatItCannotFindEmptyRatherThanGuessing(t *testing.T) {
item := ScopeItem{
ID: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
ScopeType: "labor_category",
Title: "Program Analyst",
// No clearance, no headcount, no years.
Description: "The contractor shall provide analytical support to the program office.",
}
got := DeriveDraft(item)
if got.ClearanceLevel != "unknown" {
t.Errorf("clearance = %q, want unknown. A guessed clearance is a fabricated requirement", got.ClearanceLevel)
}
if got.MinimumYears != 0 {
t.Errorf("minimum years = %d, want 0", got.MinimumYears)
}
// Quantity defaults to one because a named labor category is at least one person, which is a floor the
// document itself implies rather than an invention.
if got.Quantity != 1 {
t.Errorf("quantity = %d, want the implied floor of 1", got.Quantity)
}
}
func TestMissingRequiredDraftFieldsNamesEachGap(t *testing.T) {
d := DraftDerivation{}
missing := MissingRequiredDraftFields(d)
joined := strings.Join(missing, ",")
for _, want := range []string{"labor_category", "clearance_level"} {
if !strings.Contains(joined, want) {
t.Errorf("missing fields %v does not name %q", missing, want)
}
}
}
func TestMissingRequiredDraftFieldsIsEmptyOnACompleteDraft(t *testing.T) {
d := DraftDerivation{LaborCategory: "Cyber Analyst", ClearanceLevel: "secret", Quantity: 2}
if missing := MissingRequiredDraftFields(d); len(missing) != 0 {
t.Fatalf("a complete draft reported missing fields %v", missing)
}
}
func TestMissingRequiredDraftFieldsTreatsUnknownClearanceAsMissing(t *testing.T) {
// unknown is the column default, so it is what an ungrounded draft carries. It must read as a GAP rather
// than as a decision, because promoting it would write a requirement no candidate can fail to satisfy.
d := DraftDerivation{LaborCategory: "Cyber Analyst", ClearanceLevel: "unknown", Quantity: 1}
missing := MissingRequiredDraftFields(d)
if len(missing) == 0 || !strings.Contains(strings.Join(missing, ","), "clearance_level") {
t.Fatalf("unknown clearance was not reported as missing, got %v", missing)
}
}
func TestMissingRequiredDraftFieldsTreatsZeroQuantityAsMissing(t *testing.T) {
d := DraftDerivation{LaborCategory: "Cyber Analyst", ClearanceLevel: "secret", Quantity: 0}
if missing := MissingRequiredDraftFields(d); len(missing) == 0 {
t.Fatal("a zero headcount was accepted as complete; staffing zero people is not a requirement")
}
}
func TestStaffingScopeTypesAreTheStaffingRelevantOnes(t *testing.T) {
// Generation runs over STAFFING scope. An evaluation factor or a pricing instruction is real scope and
// belongs in the queue, but it does not describe a person, and turning one into a requirement draft would
// put a non staffing row in front of the scoring engine.
for _, want := range []string{"labor_category", "staffing_quantity", "key_personnel"} {
if !staffingScopeTypes[want] {
t.Errorf("%q should be staffing relevant", want)
}
}
for _, notWanted := range []string{"pricing_instruction", "evaluation_factor", "compliance_clause", "risk"} {
if staffingScopeTypes[notWanted] {
t.Errorf("%q is not a staffing type and must not generate a requirement draft", notWanted)
}
}
// Every staffing type must be a real scope type, or generation would filter on a value the column refuses.
for st := range staffingScopeTypes {
if !scopeTypes[st] {
t.Errorf("%q is in staffingScopeTypes but is not a valid scope_type", st)
}
}
}
func TestDeriveDraftIsDeterministic(t *testing.T) {
item := ScopeItem{ID: "cccccccc-cccc-cccc-cccc-cccccccccccc", ScopeType: "labor_category",
Title: "Analyst", Description: "two analysts with Secret clearance and 3 years"}
a := DeriveDraft(item)
b := DeriveDraft(item)
if !reflect.DeepEqual(a, b) {
t.Fatalf("same scope item produced different drafts:\n%+v\n%+v", a, b)
}
}