Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / internal/platform/sourcing/ingest_bench_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | internal/platform/sourcing/ingest_bench_test.go |
| Original SHA-256 | db00aafb1712e81914fc46de2feb57cd8403512b519f81bafc2eafe3674237ba |
| Git blob SHA | 8f55d586c591f20d2eac36188dc0534386c922ee |
| Reading-copy SHA-256 | db00aafb1712e81914fc46de2feb57cd8403512b519f81bafc2eafe3674237ba |
Every recorded occurrence
These 13 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/platform/sourcing/ingest_bench_test.go | feature/opportunity-to-outcome | 720d47fae476b0d38477ae4401697d372b1ea2bc | Open original |
| Janady13/missionmatch / internal/platform/sourcing/ingest_bench_test.go | collision-deconfliction | 4ee5a09972608ed89f8377c6665542d5f450f0a6 | Open original |
| Janady13/missionmatch / internal/platform/sourcing/ingest_bench_test.go | m5-price-to-win | 41000ad30fff4129fdaf5ec84e15ba14c27d4890 | Open original |
| Janady13/missionmatch / internal/platform/sourcing/ingest_bench_test.go | master | 1e9249840a4302ec82e123b9c9cb6f75badea3e4 | Open original |
| Janady13/missionmatch / internal/platform/sourcing/ingest_bench_test.go | mag-substrate | b82c7100a492dec67dfd1eda6b3f53def859be35 | Open original |
| Janady13/missionmatch / internal/platform/sourcing/ingest_bench_test.go | time-to-fill-survival | b66e1e505863d4f17741a4b9ede73509e45bd6c6 | Open original |
| Janady13/missionmatch / internal/platform/sourcing/ingest_bench_test.go | graphrag-foundation | b0ddeb9f633fd138d09309d1a17b7d13bc3a67f7 | Open original |
| Janady13/missionmatch / internal/platform/sourcing/ingest_bench_test.go | ws9-bench-ingestion | f585a9ef32fa554663ce1fba9a414a54b6e49cf0 | Open original |
| Janady13/missionmatch / internal/platform/sourcing/ingest_bench_test.go | presentation-readiness | eb574acaa29d71ce4d0f852572e87c275c79fdb7 | Open original |
| Janady13/missionmatch / internal/platform/sourcing/ingest_bench_test.go | vendor-intelligence | fe9796a19c261951d3f2565206c0c1b5ac294465 | Open original |
| Janady13/missionmatch / internal/platform/sourcing/ingest_bench_test.go | phase2-connectors | e038d4c687aec16f8bd9bc4d907eea14d91f8704 | Open original |
| Janady13/missionmatch / internal/platform/sourcing/ingest_bench_test.go | feature/aioe-upgrade | 2178e7298d0e5d9af83afa12402fd587f0ba6ed8 | Open original |
| Janady13/missionmatch / internal/platform/sourcing/ingest_bench_test.go | capture-readiness | bae6af7cb2997e819174a9e9cfff5e16067a1975 | Open original |
Recovered source transcript
Download complete source text ↓296 lines · 10.8 KB
package sourcing
// WS9 bench ingest unit tests. No database: a fake DBTX records every query the ingest path runs and a
// fake extractor stands in for the deterministic extraction port, so the embed skip path, the clearance
// stays unknown invariant, and the application role tag classification are proven with no DB connection.
import (
"context"
"strings"
"testing"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
pgvector "github.com/pgvector/pgvector-go"
"github.com/missionworkforce/missionmatch/internal/platform/database/dbgen"
"github.com/missionworkforce/missionmatch/internal/platform/extraction"
"github.com/missionworkforce/missionmatch/internal/platform/missionclass"
"github.com/missionworkforce/missionmatch/internal/platform/tenant"
)
// recordedCall captures one query the ingest path ran, by SQL text and arguments, so a test can assert
// what was sent to the database without a database.
type recordedCall struct {
sql string
args []any
}
// fakeRow is a pgx.Row that scans canned values into the caller's destinations. It dispatches on the SQL
// so UpsertExternalCandidate and FindCandidateByEmail get a uuid and UpsertSkill gets a Skill, matching
// the dbgen scan shapes.
type fakeRow struct {
id uuid.UUID
skill bool
noRows bool
skillID uuid.UUID
name string
}
func (r fakeRow) Scan(dest ...any) error {
if r.noRows {
return pgx.ErrNoRows
}
if r.skill {
// dbgen UpsertSkill scans id, name, category, embedding, created_at, source, soc_code in order; the
// test only needs id and name to be populated, the rest stay zero values.
if len(dest) > 0 {
if p, ok := dest[0].(*uuid.UUID); ok {
*p = r.skillID
}
}
if len(dest) > 1 {
if p, ok := dest[1].(*string); ok {
*p = r.name
}
}
return nil
}
if len(dest) > 0 {
if p, ok := dest[0].(*uuid.UUID); ok {
*p = r.id
}
}
return nil
}
// fakeDBTX is a dbgen.DBTX that records every Exec and QueryRow and returns canned rows. A new candidate is
// always created (FindCandidateByEmail and FindCandidateByNameLocation return no rows), then the upsert
// returns candID, each UpsertSkill returns a fresh skill id, and every Exec is recorded.
type fakeDBTX struct {
candID uuid.UUID
calls []recordedCall
queryRows []recordedCall
}
func (f *fakeDBTX) Exec(_ context.Context, sql string, args ...any) (pgconn.CommandTag, error) {
f.calls = append(f.calls, recordedCall{sql: sql, args: args})
return pgconn.CommandTag{}, nil
}
func (f *fakeDBTX) Query(_ context.Context, _ string, _ ...any) (pgx.Rows, error) {
return nil, nil
}
func (f *fakeDBTX) QueryRow(_ context.Context, sql string, args ...any) pgx.Row {
f.queryRows = append(f.queryRows, recordedCall{sql: sql, args: args})
switch {
case strings.Contains(sql, "name: FindCandidateByEmail"), strings.Contains(sql, "name: FindCandidateByNameLocation"):
return fakeRow{noRows: true} // force the new insert path
case strings.Contains(sql, "name: UpsertExternalCandidate"):
return fakeRow{id: f.candID}
case strings.Contains(sql, "name: UpsertSkill"):
return fakeRow{skill: true, skillID: uuid.New(), name: "skill"}
default:
return fakeRow{noRows: true}
}
}
// allArgsContain reports whether any recorded Exec or QueryRow argument, stringified, contains needle. The
// clearance invariant test uses this to prove the extracted clearance code never reached any query arg.
func allArgsContain(f *fakeDBTX, needle string) bool {
check := func(calls []recordedCall) bool {
for _, c := range calls {
for _, a := range c.args {
if s, ok := a.(string); ok && strings.Contains(strings.ToLower(s), strings.ToLower(needle)) {
return true
}
if s, ok := a.(*string); ok && s != nil && strings.Contains(strings.ToLower(*s), strings.ToLower(needle)) {
return true
}
}
}
return false
}
return check(f.calls) || check(f.queryRows)
}
// fakeExtractor returns a fixed RawExtraction. It carries a clearance code so the test can prove that even
// when the extractor reports a held clearance, the ingest path never threads it to any clearance column.
type fakeExtractor struct{ rx extraction.RawExtraction }
func (e fakeExtractor) ExtractResume(_ context.Context, _ string) (extraction.RawExtraction, error) {
return e.rx, nil
}
func (e fakeExtractor) ExtractRequirement(_ context.Context, _ string) (extraction.RawExtraction, error) {
return e.rx, nil
}
func benchPerson() SourcedPerson {
return SourcedPerson{
ExternalID: "bench-1",
FullName: "Pat Cleared",
JobTitle: "Signals Intelligence Analyst",
Location: "Honolulu, HI",
Skills: []string{"SIGINT", "RMF"},
Years: 8,
Emails: []string{"pat@example.com"},
}
}
// TestIngestBenchRecordEmbedSkip proves invariant 6: a nil vector commits the candidate WITHOUT an
// embedding write, and a non nil vector writes exactly one UpdateCandidateEmbedding.
func TestIngestBenchRecordEmbedSkip(t *testing.T) {
const upd = "name: UpdateCandidateEmbedding"
// nil vector: no embedding write at all.
f := &fakeDBTX{candID: uuid.New()}
ext := fakeExtractor{rx: extraction.RawExtraction{Certifications: []string{"Security+"}, Agencies: []string{"NSA"}}}
res, err := IngestBenchRecord(context.Background(), dbgen.New(f), uuid.New(), benchPerson(), ext, nil, "bench_file", "resume.pdf", "client provided cleared bench")
if err != nil {
t.Fatalf("ingest (nil vector): %v", err)
}
if !res.New {
t.Fatalf("expected a new candidate insert, got enrich")
}
for _, c := range f.calls {
if strings.Contains(c.sql, upd) {
t.Fatalf("nil vector must NOT write an embedding, but UpdateCandidateEmbedding ran")
}
}
// non nil vector: exactly one embedding write.
f2 := &fakeDBTX{candID: uuid.New()}
vec := pgvector.NewVector(make([]float32, 384))
if _, err := IngestBenchRecord(context.Background(), dbgen.New(f2), uuid.New(), benchPerson(), ext, &vec, "bench_file", "resume.pdf", "client provided cleared bench"); err != nil {
t.Fatalf("ingest (vector): %v", err)
}
embedWrites := 0
for _, c := range f2.calls {
if strings.Contains(c.sql, upd) {
embedWrites++
}
}
if embedWrites != 1 {
t.Fatalf("non nil vector must write exactly one embedding, got %d", embedWrites)
}
}
// TestIngestBenchRecordClearanceStaysUnknown proves invariant 3: even when the extractor reports a held
// ts_sci clearance, the ingest path threads it to NO query argument, and the candidate upsert is the
// hardcoded UpsertExternalCandidate path (whose SQL literally writes clearance_level 'unknown'). The
// extracted clearance code can therefore never feed scoreClearance.
func TestIngestBenchRecordClearanceStaysUnknown(t *testing.T) {
f := &fakeDBTX{candID: uuid.New()}
// The extractor reports an ACTIVE ts_sci clearance with a full scope poly; the ingest path must ignore it.
ext := fakeExtractor{rx: extraction.RawExtraction{
ClearanceLevel: "ts_sci",
ClearancePoly: "full_scope",
ClearanceActive: true,
Certifications: []string{"CISSP"},
}}
if _, err := IngestBenchRecord(context.Background(), dbgen.New(f), uuid.New(), benchPerson(), ext, nil, "bench_file", "resume.pdf", "client provided cleared bench"); err != nil {
t.Fatalf("ingest: %v", err)
}
// Structural proof 1: the candidate was written through the hardcoded upsert, which writes 'unknown'.
wroteThroughUpsert := false
for _, c := range f.queryRows {
if strings.Contains(c.sql, "name: UpsertExternalCandidate") {
wroteThroughUpsert = true
}
}
if !wroteThroughUpsert {
t.Fatalf("candidate must be written through UpsertExternalCandidate (clearance hardcoded 'unknown')")
}
// Structural proof 2: the extracted clearance code reached NO query argument anywhere.
if allArgsContain(f, "ts_sci") {
t.Fatalf("extracted clearance code ts_sci must never reach a query argument")
}
if allArgsContain(f, "full_scope") {
t.Fatalf("extracted clearance poly full_scope must never reach a query argument")
}
// Structural proof 3: no clearance-setting query ran at all in the bench ingest path.
for _, c := range append(append([]recordedCall{}, f.calls...), f.queryRows...) {
if strings.Contains(c.sql, "name: SetCandidateClearanceProvenance") {
t.Fatalf("the bench ingest path must never set a clearance provenance")
}
}
}
// fakeTagWriter records the candidate_mission_tags upsert params the tag path produced, so the
// classification is asserted with no DB.
type fakeTagWriter struct {
tags []dbgen.UpsertCandidateMissionTagParams
calls int
}
func (w *fakeTagWriter) upsertCandidateMissionTags(_ context.Context, tags []dbgen.UpsertCandidateMissionTagParams) error {
w.calls++
w.tags = append(w.tags, tags...)
return nil
}
// TestTagCandidateMissionsClassifiesRLSScoped proves the tag path: the org is read from the GUC context
// (never an argument), the headline and skill names are classified with a fixed AliasIndex, and the
// expected candidate_mission_tag upsert params are produced. The writer is faked, so there is no DB.
func TestTagCandidateMissionsClassifiesRLSScoped(t *testing.T) {
orgID := uuid.New()
candID := uuid.New()
// A fixed AliasIndex maps the curated alias "ew" to the EW mission code, in addition to the keyword
// gazetteer that already classifies "signals intelligence" as SIGINT.
idx := missionclass.NewAliasIndex(map[string]string{"ew": "EW"})
ctx := tenant.WithOrg(context.Background(), orgID.String())
w := &fakeTagWriter{}
err := tagCandidateMissions(ctx, w, candID, "Signals Intelligence Analyst", []string{"electronic warfare", "rmf"}, idx)
if err != nil {
t.Fatalf("tag: %v", err)
}
if w.calls != 1 {
t.Fatalf("expected one tag write call, got %d", w.calls)
}
got := map[string]dbgen.UpsertCandidateMissionTagParams{}
for _, p := range w.tags {
if p.OrganizationID != orgID {
t.Fatalf("tag org must come from the GUC context, got %v want %v", p.OrganizationID, orgID)
}
if p.CandidateID != candID {
t.Fatalf("tag candidate id wrong: %v", p.CandidateID)
}
got[p.MissionCode] = p
}
if _, ok := got["SIGINT"]; !ok {
t.Fatalf("headline 'Signals Intelligence Analyst' must classify as SIGINT, got %v", keys(got))
}
if _, ok := got["EW"]; !ok {
t.Fatalf("skill 'electronic warfare' must classify as EW, got %v", keys(got))
}
}
// TestTagCandidateMissionsRefusesUnscoped proves the tag path is fail closed: with no org in the context it
// refuses to run, mirroring RunInTenantTx, so a tag can never be written unscoped.
func TestTagCandidateMissionsRefusesUnscoped(t *testing.T) {
w := &fakeTagWriter{}
err := tagCandidateMissions(context.Background(), w, uuid.New(), "Signals Intelligence Analyst", nil, missionclass.AliasIndex{})
if err == nil {
t.Fatalf("tagging with no org in context must fail closed")
}
if w.calls != 0 {
t.Fatalf("no tag write may run when unscoped, got %d calls", w.calls)
}
}
func keys(m map[string]dbgen.UpsertCandidateMissionTagParams) []string {
out := make([]string, 0, len(m))
for k := range m {
out = append(out, k)
}
return out
}