package wire_test import ( "bytes" "encoding/json" "strings" "testing" "amadan.net/oficina/equipo/internal/wire" ) // handoffDispatch is an Engineering or Review dispatch carrying the // task's Research findings (slice R4). func handoffDispatch(specialist string) wire.DispatchCommand { return wire.DispatchCommand{Person: "owner@example.com", TaskID: "tk1", StepID: "s_3", Attempt: 1, Specialist: specialist, Repo: "amadan.net/oficina/sample", Branch: "equipo/tk1-x", Findings: []wire.Finding{}, ResearchNote: &wire.ResearchHandoff{ Findings: json.RawMessage(`{"summary":"A barber shop.","facts":[{"label":"Colours","value":"Navy","sources":["s1"]}],"images":["img1"],"gaps":[]}`), Sources: []wire.ResearchSource{{ID: "s1", URL: "https://shop.example.com/", Origin: wire.ResearchOriginPerson}}, Images: []wire.ResearchImage{{ID: "img1", SourceID: "s1", Role: wire.ImageRoleLogo, Description: "The logo.", SHA256: strings.Repeat("a", 64), Size: 300, Width: 5, Height: 4}}, }} } // TestEncodeBelowProtocol13DropsResearchNote: Engineering's and Review's // view of the findings goes out whole at 13 and is dropped below it, // nothing else changing. func TestEncodeBelowProtocol13DropsResearchNote(t *testing.T) { for _, specialist := range []string{wire.SpecialistEngineering, wire.SpecialistReview} { d := handoffDispatch(specialist) f, _ := wire.NewFrame("d", wire.FrameDispatch, d) if same, err := wire.Encode(f, wire.ProtocolResearch); err != nil || !bytes.Equal(same.Data, f.Data) { t.Fatalf("changed at 13: %v", err) } if !strings.Contains(string(f.Data), `"research_note":{"findings":{"summary":"A barber shop."`) || !strings.Contains(string(f.Data), `"sources":[{"id":"s1","url":"https://shop.example.com/","origin":"person"}]`) { t.Fatalf("the note on the wire: %s", f.Data) } d.ResearchNote = nil plain, _ := wire.NewFrame("d", wire.FrameDispatch, d) got, err := wire.Encode(f, wire.ProtocolPreviewHost) if err != nil || strings.Contains(string(got.Data), "research_note") || !bytes.Equal(got.Data, plain.Data) { t.Fatalf("%s at 11: %s %v", specialist, got.Data, err) } } }