Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/missionmatch / cmd/opportunity-amendment-diff/pickpair_test.go |
| Date | Not specified in source |
| Repository | Janady13/missionmatch |
| Revision | 720d47fae476b0d38477ae4401697d372b1ea2bc |
| Branch | feature/opportunity-to-outcome |
| Path or archive member | cmd/opportunity-amendment-diff/pickpair_test.go |
| Original SHA-256 | 693f8c09ef2c009d7b44007432f56caeee30536bb2b74b1e1cd881d327fe7c8f |
| Git blob SHA | 823fd4b2f8e0ab566c8e5ec9b116858e88570363 |
| Reading-copy SHA-256 | 693f8c09ef2c009d7b44007432f56caeee30536bb2b74b1e1cd881d327fe7c8f |
Recovered source transcript
Download complete source text ↓158 lines · 7.0 KB
package main
import "testing"
// FINDING F6. The diff paired documents BY RECENCY: the first non amendment document became the baseline and
// the latest amendment became the other side. On Package B that compared the SOLICITATION against the AMENDED
// PWS, which are different documents about different things, so the five changes it reported were partly
// artifacts of comparing unlike things.
//
// The safety guarantee under test at Gate A held regardless, because acceptance item 11 is that an amendment
// FLAGS and never REWRITES an approved requirement, and that is true whichever pair is diffed. What was wrong
// was diff QUALITY, and a diff a capture team cannot trust is a diff they will stop reading.
//
// THE FIX: pair WITHIN a document type, earliest against latest, preferring the type that actually carries
// scope. Package B ships the original PWS and the amended PWS precisely so this can be got right.
// THE REAL PACKAGE B SHAPE, read back from staging rather than imagined. The classifications are the ones the
// intake actually recorded, and the important one is that 05_PWS_amended is typed AMENDMENT, not pws.
//
// THAT DETAIL BROKE THE FIRST FIX. Pairing purely within a document type looked correct against a fixture I
// wrote, where both PWS documents were typed pws. Against the real data the pws type holds ONE document, so the
// pairing fell straight through to the cross type fallback and chose the solicitation again, which is the exact
// behaviour F6 describes. A fix verified only against a fixture of my own construction is not a fix.
func packageB() []document {
return []document{
{ID: "1", FileName: "01_Solicitation_W912CN26QA031_17JUL2026.pdf", DocumentType: "solicitation"},
{ID: "2", FileName: "02_Amendment_0001_SF30.pdf", DocumentType: "amendment"},
{ID: "3", FileName: "03_Amendment_0001_Conformed_Solicitation.pdf", DocumentType: "amendment"},
{ID: "4", FileName: "04_PWS_original_10JUL26.pdf", DocumentType: "pws"},
{ID: "5", FileName: "05_PWS_amended_23JUL26.pdf", DocumentType: "amendment"},
{ID: "6", FileName: "06_RFC_Log_Government_Responses.pdf", DocumentType: "attachment"},
}
}
// The same package if a reviewer classifies the amended PWS correctly as a pws, which the Documents screen now
// nudges them to do. Both shapes must reach the same pair.
func packageBWellClassified() []document {
docs := packageB()
docs[4].DocumentType = "pws"
return docs
}
func TestPickPairComparesTheTwoPWSWhenTheAmendedOneIsTypedAmendment(t *testing.T) {
base, amend, how := pickPair(packageB())
if base.ID != "4" {
t.Errorf("baseline = %s (%s), want the ORIGINAL PWS. This is the real F6 case", base.ID, base.FileName)
}
if amend.ID != "5" {
t.Errorf("other side = %s (%s), want the AMENDED PWS", amend.ID, amend.FileName)
}
if how != pairCrossType {
t.Errorf("pairing method = %q, want %q so the report qualifies itself", how, pairCrossType)
}
}
func TestPickPairNeverPairsTwoUnrelatedAttachments(t *testing.T) {
// An earlier version ranked 'attachment' as pairable, so a package with two attachments and one PWS would
// have diffed the two attachments against each other. That is worse than the bug being fixed.
docs := []document{
{ID: "1", FileName: "01_Solicitation.pdf", DocumentType: "solicitation"},
{ID: "2", FileName: "02_Amendment_SF30.pdf", DocumentType: "amendment"},
{ID: "3", FileName: "06_RFC_Log.pdf", DocumentType: "attachment"},
{ID: "4", FileName: "07_Deliverables.pdf", DocumentType: "attachment"},
}
base, amend, _ := pickPair(docs)
if base.DocumentType == "attachment" && amend.DocumentType == "attachment" {
t.Fatalf("paired two attachments, %s against %s", base.FileName, amend.FileName)
}
}
func TestPickPairComparesTheTwoPWSDocumentsOnPackageB(t *testing.T) {
base, amend, how := pickPair(packageBWellClassified())
if base.ID != "4" {
t.Errorf("baseline = %s (%s), want the ORIGINAL PWS", base.ID, base.FileName)
}
if amend.ID != "5" {
t.Errorf("other side = %s (%s), want the AMENDED PWS", amend.ID, amend.FileName)
}
if base.DocumentType != amend.DocumentType {
t.Errorf("paired across types %q and %q, which is exactly finding F6",
base.DocumentType, amend.DocumentType)
}
if how != pairSameType {
t.Errorf("pairing method = %q, want %q", how, pairSameType)
}
}
func TestPickPairPrefersPWSOverSolicitationWhenBothHaveTwo(t *testing.T) {
docs := []document{
{ID: "1", FileName: "sol_v1.pdf", DocumentType: "solicitation"},
{ID: "2", FileName: "sol_v2.pdf", DocumentType: "solicitation"},
{ID: "3", FileName: "pws_v1.pdf", DocumentType: "pws"},
{ID: "4", FileName: "pws_v2.pdf", DocumentType: "pws"},
}
base, amend, _ := pickPair(docs)
if base.DocumentType != "pws" || amend.DocumentType != "pws" {
t.Fatalf("paired %s against %s, want the PWS pair: the PWS is the document that carries the scope a "+
"staffing requirement is derived from", base.DocumentType, amend.DocumentType)
}
}
func TestPickPairTakesEarliestAndLatestWithinTheType(t *testing.T) {
docs := []document{
{ID: "1", FileName: "pws_a.pdf", DocumentType: "pws"},
{ID: "2", FileName: "pws_b.pdf", DocumentType: "pws"},
{ID: "3", FileName: "pws_c.pdf", DocumentType: "pws"},
}
base, amend, _ := pickPair(docs)
if base.ID != "1" || amend.ID != "3" {
t.Fatalf("paired %s against %s, want earliest 1 against latest 3", base.ID, amend.ID)
}
}
// THE FALLBACK MUST STILL WORK, and must SAY it is a fallback. A package with a solicitation and a single
// SF30 amendment and nothing else has no same type pair available, and refusing to diff at all would be worse
// than a cross type diff that is labelled as one.
func TestPickPairFallsBackAcrossTypesAndLabelsIt(t *testing.T) {
docs := []document{
{ID: "1", FileName: "solicitation.pdf", DocumentType: "solicitation"},
{ID: "2", FileName: "amendment_sf30.pdf", DocumentType: "amendment"},
}
base, amend, how := pickPair(docs)
if base.ID != "1" || amend.ID != "2" {
t.Errorf("fallback paired %s against %s, want 1 against 2", base.ID, amend.ID)
}
if how != pairCrossType {
t.Errorf("pairing method = %q, want %q so the output can say the comparison is weaker", how, pairCrossType)
}
}
func TestPickPairReportsNothingToCompareOnASingleDocument(t *testing.T) {
docs := []document{{ID: "1", FileName: "only.pdf", DocumentType: "pws"}}
base, amend, how := pickPair(docs)
if how != pairNone {
t.Errorf("pairing method = %q, want %q", how, pairNone)
}
if base.ID != "" || amend.ID != "" {
t.Errorf("a single document produced a pair: %q against %q", base.ID, amend.ID)
}
}
func TestPickPairHandlesAnEmptySet(t *testing.T) {
base, amend, how := pickPair(nil)
if how != pairNone || base.ID != "" || amend.ID != "" {
t.Fatalf("empty input produced %q, %q, %q", base.ID, amend.ID, how)
}
}
func TestPickPairIsDeterministic(t *testing.T) {
for i := 0; i < 5; i++ {
b1, a1, h1 := pickPair(packageB())
b2, a2, h2 := pickPair(packageB())
if b1.ID != b2.ID || a1.ID != a2.ID || h1 != h2 {
t.Fatalf("pairing is not deterministic: %s/%s/%s then %s/%s/%s", b1.ID, a1.ID, h1, b2.ID, a2.ID, h2)
}
}
}