ThatAIguyA world of ideas

THE CONSCIOUSNESS ATLAS
Read. Experiment. Follow the evidence.

ConsciousnessLearn · Explore · Joseph Anady

Janady13/missionmatch / internal/modules/ai/curation_test.go

Source identity, revision, and recovered contents.

GitHub sourceSource text recovered

Source identity

FieldRecorded value
Source typeGitHub source
Original recordJanady13/missionmatch / internal/modules/ai/curation_test.go
DateNot specified in source
RepositoryJanady13/missionmatch
Revision720d47fae476b0d38477ae4401697d372b1ea2bc
Branchfeature/opportunity-to-outcome
Path or archive memberinternal/modules/ai/curation_test.go
Original SHA-256b47a7be9b75b4d974e84b6722e612e76a9860560b09bc29b5f6fd8de833ac53c
Git blob SHA984120c846379f7bf1a1bb16fe87628a20a3fb6d
Reading-copy SHA-256b47a7be9b75b4d974e84b6722e612e76a9860560b09bc29b5f6fd8de833ac53c

Original source ↗

Every recorded occurrence

These 14 records contain identical original source bytes. Their paths and revisions remain part of the archive.

Original recordBranch or archiveRevision / identifierOriginal location
Janady13/missionmatch / internal/modules/ai/curation_test.gofeature/opportunity-to-outcome720d47fae476b0d38477ae4401697d372b1ea2bcOpen original
Janady13/missionmatch / internal/modules/ai/curation_test.gocollision-deconfliction4ee5a09972608ed89f8377c6665542d5f450f0a6Open original
Janady13/missionmatch / internal/modules/ai/curation_test.gom5-price-to-win41000ad30fff4129fdaf5ec84e15ba14c27d4890Open original
Janady13/missionmatch / internal/modules/ai/curation_test.gomaster1e9249840a4302ec82e123b9c9cb6f75badea3e4Open original
Janady13/missionmatch / internal/modules/ai/curation_test.gows8-teaching-loopc823f0fb6bb2aba0f39001eb6de96f4000d9321fOpen original
Janady13/missionmatch / internal/modules/ai/curation_test.gomag-substrateb82c7100a492dec67dfd1eda6b3f53def859be35Open original
Janady13/missionmatch / internal/modules/ai/curation_test.gotime-to-fill-survivalb66e1e505863d4f17741a4b9ede73509e45bd6c6Open original
Janady13/missionmatch / internal/modules/ai/curation_test.gographrag-foundationb0ddeb9f633fd138d09309d1a17b7d13bc3a67f7Open original
Janady13/missionmatch / internal/modules/ai/curation_test.gows9-bench-ingestionf585a9ef32fa554663ce1fba9a414a54b6e49cf0Open original
Janady13/missionmatch / internal/modules/ai/curation_test.gopresentation-readinesseb574acaa29d71ce4d0f852572e87c275c79fdb7Open original
Janady13/missionmatch / internal/modules/ai/curation_test.govendor-intelligencefe9796a19c261951d3f2565206c0c1b5ac294465Open original
Janady13/missionmatch / internal/modules/ai/curation_test.gophase2-connectorse038d4c687aec16f8bd9bc4d907eea14d91f8704Open original
Janady13/missionmatch / internal/modules/ai/curation_test.gofeature/aioe-upgrade2178e7298d0e5d9af83afa12402fd587f0ba6ed8Open original
Janady13/missionmatch / internal/modules/ai/curation_test.gocapture-readinessbae6af7cb2997e819174a9e9cfff5e16067a1975Open original

Recovered source transcript

package ai // curation_test.go unit tests the WS8 Phase 4 proposal generator with NO database. The derivation // (derivePairs) and the selection (selectProposals) are pure functions of the stored evaluation evidence, the // clearance override count, and the contents free governance confidence, so a fixture of evaluation rows and // aggregates fully exercises them: a recurring approved non exact pair above the threshold yields one // substitutes_for_edge with the right from, to, strength, and evidence; a one off pair does not; an exact // match never proposes; the governance confidence double gate holds; and the idempotency check suppresses a // duplicate. The full GenerateProposalsForOrg path (the RLS scoped scan and the migrator pool write) needs a // real Postgres and is covered by the integration test. import ( "context" "encoding/json" "testing" "github.com/google/uuid" "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/scrub" ) // two fixed skill ids so the fixtures speak in ids the matcher already populated (the common case). When a // fixture wants to exercise the name resolution path it leaves the id empty and sets the name. var ( skillReqA = uuid.MustParse("11111111-1111-1111-1111-111111111111") skillCandA = uuid.MustParse("22222222-2222-2222-2222-222222222222") skillReqB = uuid.MustParse("33333333-3333-3333-3333-333333333333") skillCandB = uuid.MustParse("44444444-4444-4444-4444-444444444444") ) // fullSkill builds a matched_skills entry with explicit ids (the populated id case). func fullSkill(reqID, candID uuid.UUID, similarity string, exact, matched bool) map[string]any { return map[string]any{ "RequiredSkillID": reqID.String(), "RequiredSkillName": "req", "CandidateSkillID": candID.String(), "CandidateName": "cand", "Similarity": similarity, "Exact": exact, "Matched": matched, } } // namedSkill builds a matched_skills entry with NO ids, only names (the resolution case). func namedSkill(reqName, candName, similarity string, exact, matched bool) map[string]any { return map[string]any{ "RequiredSkillID": "", "RequiredSkillName": reqName, "CandidateSkillID": "", "CandidateName": candName, "Similarity": similarity, "Exact": exact, "Matched": matched, } } func curationEvalRow(t *testing.T, decision string, skills ...map[string]any) evalRow { t.Helper() mj, err := json.Marshal(skills) if err != nil { t.Fatalf("marshal matched skills: %v", err) } return evalRow{ Decision: decision, ClearanceScore: dec("100"), ExperienceScore: dec("100"), RequiredLevel: "none", MatchedSkills: mj, } } // fakeScanner returns fixture rows and resolves a name to an id from a static map. type fakeScanner struct { rows []evalRow nameMap map[string]uuid.UUID } func (f fakeScanner) ScanEvaluations(ctx context.Context) ([]evalRow, error) { return f.rows, nil } func (f fakeScanner) ResolveSkillID(ctx context.Context, name string) (uuid.UUID, bool, error) { id, ok := f.nameMap[name] return id, ok, nil } // govHigh is a governance aggregate that confirms the substitution pattern is reliably approved at the high // band (more approved than not), so the double gate is satisfied for a high band pair. func govHigh() []dbgen.TeachingSignalAggregate { return []dbgen.TeachingSignalAggregate{ {Pattern: "adjacent_skill_substitution_outcome", Band: "high", Outcome: "approved", Observations: 5, Successes: 5}, } } // TestDerivePairsCountsRecurringApprovedNonExact proves a recurring approved non exact pair is counted with // the right approval, total, and band, and that an exact match and a one off contribute correctly. func TestDerivePairsCountsRecurringApprovedNonExact(t *testing.T) { rows := []evalRow{ curationEvalRow(t, "approved", fullSkill(skillReqA, skillCandA, "0.92", false, true)), curationEvalRow(t, "approved", fullSkill(skillReqA, skillCandA, "0.95", false, true)), curationEvalRow(t, "approved", fullSkill(skillReqA, skillCandA, "1", true, true)), // exact, never a pair curationEvalRow(t, "rejected", fullSkill(skillReqA, skillCandA, "0.91", false, true)), } pairs, err := derivePairs(context.Background(), rows, fakeScanner{rows: rows}) if err != nil { t.Fatalf("derivePairs: %v", err) } k := pairKey{fromSkillID: skillCandA.String(), toSkillID: skillReqA.String()} ev := pairs[k] if ev == nil { t.Fatal("expected a derived pair for cand A to req A") } // Three non exact observations (two approved, one rejected); the exact one is never counted. if ev.total != 3 { t.Fatalf("pair total = %d, want 3 (the exact match is excluded)", ev.total) } if ev.approvals != 2 { t.Fatalf("pair approvals = %d, want 2", ev.approvals) } if ev.band != scrub.BandHigh { t.Fatalf("pair band = %q, want high (the strongest approved similarity 0.95)", ev.band) } } // TestSelectProposalsRecurringApprovedPairProposesEdge proves a recurring approved high band pair, supported // by the governance confidence, yields exactly one substitutes_for_edge with the right from, to, strength, and // evidence counts. func TestSelectProposalsRecurringApprovedPairProposesEdge(t *testing.T) { pairs := map[pairKey]*pairEvidence{ {fromSkillID: skillCandA.String(), toSkillID: skillReqA.String()}: {approvals: 3, total: 4, band: scrub.BandHigh}, } plans := selectProposals(pairs, 0, govHigh()) if len(plans) != 1 { t.Fatalf("got %d plans, want exactly 1 substitutes_for_edge", len(plans)) } p := plans[0] if p.kind != kindSubstitutesForEdge { t.Fatalf("plan kind = %q, want substitutes_for_edge", p.kind) } if p.fromSkillID == nil || *p.fromSkillID != skillCandA { t.Fatalf("from_skill_id = %v, want the candidate skill %v", p.fromSkillID, skillCandA) } if p.toSkillID == nil || *p.toSkillID != skillReqA { t.Fatalf("to_skill_id = %v, want the required skill %v", p.toSkillID, skillReqA) } if p.relation != substitutionRelation { t.Fatalf("relation = %q, want substitutes_for", p.relation) } if p.strength == nil || p.strength.String() != "0.9" { t.Fatalf("strength = %v, want 0.90 for the high band", p.strength) } if p.successes != 3 || p.observations != 4 { t.Fatalf("evidence = %d of %d, want 3 of 4", p.successes, p.observations) } } // TestSelectProposalsOneOffDoesNotPropose proves a single approval (below the recurring threshold) never // proposes an edge, even with a supporting governance aggregate. func TestSelectProposalsOneOffDoesNotPropose(t *testing.T) { pairs := map[pairKey]*pairEvidence{ {fromSkillID: skillCandA.String(), toSkillID: skillReqA.String()}: {approvals: 1, total: 1, band: scrub.BandHigh}, } plans := selectProposals(pairs, 0, govHigh()) for _, p := range plans { if p.kind == kindSubstitutesForEdge { t.Fatalf("a one off pair must not propose a substitutes_for_edge, got %+v", p) } } } // TestSelectProposalsRequiresGovernanceConfidence proves the double gate: a recurring approved pair does NOT // propose when the contents free governance aggregate does not support the pattern at that band, even though // the within tenant pair count clears the threshold. func TestSelectProposalsRequiresGovernanceConfidence(t *testing.T) { pairs := map[pairKey]*pairEvidence{ {fromSkillID: skillCandA.String(), toSkillID: skillReqA.String()}: {approvals: 5, total: 5, band: scrub.BandHigh}, } // Governance says the pattern was mostly NOT approved at the high band, so the gate fails. govWeak := []dbgen.TeachingSignalAggregate{ {Pattern: "adjacent_skill_substitution_outcome", Band: "high", Outcome: "approved", Observations: 1, Successes: 1}, {Pattern: "adjacent_skill_substitution_outcome", Band: "high", Outcome: "rejected", Observations: 9, Successes: 0}, } plans := selectProposals(pairs, 0, govWeak) for _, p := range plans { if p.kind == kindSubstitutesForEdge { t.Fatalf("without governance confidence the pair must not propose an edge, got %+v", p) } } } // TestSelectProposalsLowBandNeverProposes proves a low band similarity, even when recurring and approved, is // too weak to curate as a substitution. func TestSelectProposalsLowBandNeverProposes(t *testing.T) { pairs := map[pairKey]*pairEvidence{ {fromSkillID: skillCandA.String(), toSkillID: skillReqA.String()}: {approvals: 4, total: 4, band: scrub.BandLow}, } gov := []dbgen.TeachingSignalAggregate{ {Pattern: "adjacent_skill_substitution_outcome", Band: "low", Outcome: "approved", Observations: 4, Successes: 4}, } plans := selectProposals(pairs, 0, gov) for _, p := range plans { if p.kind == kindSubstitutesForEdge { t.Fatalf("a low band pair must not propose a substitutes_for_edge, got %+v", p) } } } // TestSelectProposalsReciprocityReview proves recurring approved clearance gap overrides raise a // reciprocity_review (evidence only, no skill ids) and that a single override does not. func TestSelectProposalsReciprocityReview(t *testing.T) { plansTwo := selectProposals(nil, 2, nil) sawReview := false for _, p := range plansTwo { if p.kind == kindReciprocityReview { sawReview = true if p.fromSkillID != nil || p.toSkillID != nil { t.Fatal("a reciprocity_review carries no skill ids, it is evidence only") } if p.observations != 2 { t.Fatalf("reciprocity evidence = %d, want 2", p.observations) } } } if !sawReview { t.Fatal("two recurring clearance overrides must raise a reciprocity_review") } plansOne := selectProposals(nil, 1, nil) for _, p := range plansOne { if p.kind == kindReciprocityReview { t.Fatal("a single clearance override must not raise a reciprocity_review") } } } // TestDerivePairsResolvesNamesWhenIdsAbsent proves a matched_skills entry that carries only names is resolved // to skill ids through the scanner, so the pair is still derivable when the matcher did not populate ids. func TestDerivePairsResolvesNamesWhenIdsAbsent(t *testing.T) { rows := []evalRow{ curationEvalRow(t, "approved", namedSkill("Splunk", "Elastic SIEM", "0.93", false, true)), curationEvalRow(t, "approved", namedSkill("Splunk", "Elastic SIEM", "0.94", false, true)), } scanner := fakeScanner{ rows: rows, nameMap: map[string]uuid.UUID{"Splunk": skillReqB, "Elastic SIEM": skillCandB}, } pairs, err := derivePairs(context.Background(), rows, scanner) if err != nil { t.Fatalf("derivePairs: %v", err) } k := pairKey{fromSkillID: skillCandB.String(), toSkillID: skillReqB.String()} ev := pairs[k] if ev == nil { t.Fatal("expected a derived pair resolved from names") } if ev.approvals != 2 || ev.total != 2 { t.Fatalf("resolved pair = %d of %d, want 2 of 2", ev.approvals, ev.total) } } // TestDerivePairsUnresolvedNameYieldsNoPair proves a name the ontology does not know yields NO pair, never a // fabricated id. func TestDerivePairsUnresolvedNameYieldsNoPair(t *testing.T) { rows := []evalRow{ curationEvalRow(t, "approved", namedSkill("UnknownReq", "UnknownCand", "0.93", false, true)), curationEvalRow(t, "approved", namedSkill("UnknownReq", "UnknownCand", "0.94", false, true)), } pairs, err := derivePairs(context.Background(), rows, fakeScanner{rows: rows, nameMap: map[string]uuid.UUID{}}) if err != nil { t.Fatalf("derivePairs: %v", err) } if len(pairs) != 0 { t.Fatalf("an unresolved name must yield no pair, got %d", len(pairs)) } } // silentAuditor is a no op systemAuditor for the unit test: it records nothing and never errors, so the write // loop can be exercised with no database. The live path uses audit.Writer.System (covered by the integration // test, where the global event is asserted against real Postgres). type silentAuditor struct{} func (silentAuditor) System(ctx context.Context, e audit.Event) error { return nil } func newSilentAuditWriter() systemAuditor { return silentAuditor{} } // fakeProposalWriter records the inserts and answers the idempotency check from a set of existing pairs. type fakeProposalWriter struct { existing map[string]bool // key: from|to|relation inserted []dbgen.InsertCurationProposalParams } func pairExistKey(from, to uuid.UUID, relation string) string { return from.String() + "|" + to.String() + "|" + relation } func (w *fakeProposalWriter) ActiveProposalExists(ctx context.Context, from, to uuid.UUID, relation string) (bool, error) { return w.existing[pairExistKey(from, to, relation)], nil } func (w *fakeProposalWriter) InsertProposal(ctx context.Context, arg dbgen.InsertCurationProposalParams) (uuid.UUID, error) { w.inserted = append(w.inserted, arg) return uuid.New(), nil } // TestWriteProposalIdempotent proves the generator does not insert a duplicate proposal for a pair that is // already pending or approved, and the model_version stamp comes from engine.ModelVersion. func TestWriteProposalIdempotent(t *testing.T) { strength := dec("0.90") plan := proposalPlan{ kind: kindSubstitutesForEdge, fromSkillID: &skillCandA, toSkillID: &skillReqA, relation: substitutionRelation, strength: &strength, observations: 4, successes: 3, } // First, with no existing proposal: it inserts once and stamps the engine model version. writer := &fakeProposalWriter{existing: map[string]bool{}} gen := NewProposalGenerator(nil, nil, writer, newSilentAuditWriter()) created, err := gen.writeProposal(context.Background(), plan) if err != nil { t.Fatalf("writeProposal: %v", err) } if !created || len(writer.inserted) != 1 { t.Fatalf("expected one insert, created=%v inserts=%d", created, len(writer.inserted)) } if writer.inserted[0].ModelVersion != engine.ModelVersion { t.Fatalf("model_version = %q, want engine.ModelVersion %q", writer.inserted[0].ModelVersion, engine.ModelVersion) } // Now with the pair already active: it suppresses the duplicate. writer2 := &fakeProposalWriter{existing: map[string]bool{ pairExistKey(skillCandA, skillReqA, substitutionRelation): true, }} gen2 := NewProposalGenerator(nil, nil, writer2, newSilentAuditWriter()) created2, err := gen2.writeProposal(context.Background(), plan) if err != nil { t.Fatalf("writeProposal (dup): %v", err) } if created2 || len(writer2.inserted) != 0 { t.Fatalf("a duplicate pair must not insert, created=%v inserts=%d", created2, len(writer2.inserted)) } }

Search equations, builds, manuscript text, and recovered sources.