| 1 | package wire_test |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "encoding/json" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "amadan.net/oficina/equipo/internal/wire" |
| 10 | ) |
| 11 | |
| 12 | // handoffDispatch is an Engineering or Review dispatch carrying the |
| 13 | // task's Research findings (slice R4). |
| 14 | func handoffDispatch(specialist string) wire.DispatchCommand { |
| 15 | 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{}, |
| 16 | ResearchNote: &wire.ResearchHandoff{ |
| 17 | Findings: json.RawMessage(`{"summary":"A barber shop.","facts":[{"label":"Colours","value":"Navy","sources":["s1"]}],"images":["img1"],"gaps":[]}`), |
| 18 | Sources: []wire.ResearchSource{{ID: "s1", URL: "https://shop.example.com/", Origin: wire.ResearchOriginPerson}}, |
| 19 | Images: []wire.ResearchImage{{ID: "img1", SourceID: "s1", Role: wire.ImageRoleLogo, Description: "The logo.", SHA256: strings.Repeat("a", 64), Size: 300, Width: 5, Height: 4}}, |
| 20 | }} |
| 21 | } |
| 22 | |
| 23 | // TestEncodeBelowProtocol13DropsResearchNote: Engineering's and Review's |
| 24 | // view of the findings goes out whole at 13 and is dropped below it, |
| 25 | // nothing else changing. |
| 26 | func TestEncodeBelowProtocol13DropsResearchNote(t *testing.T) { |
| 27 | for _, specialist := range []string{wire.SpecialistEngineering, wire.SpecialistReview} { |
| 28 | d := handoffDispatch(specialist) |
| 29 | f, _ := wire.NewFrame("d", wire.FrameDispatch, d) |
| 30 | if same, err := wire.Encode(f, wire.ProtocolResearch); err != nil || !bytes.Equal(same.Data, f.Data) { |
| 31 | t.Fatalf("changed at 13: %v", err) |
| 32 | } |
| 33 | 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"}]`) { |
| 34 | t.Fatalf("the note on the wire: %s", f.Data) |
| 35 | } |
| 36 | d.ResearchNote = nil |
| 37 | plain, _ := wire.NewFrame("d", wire.FrameDispatch, d) |
| 38 | got, err := wire.Encode(f, wire.ProtocolPreviewHost) |
| 39 | if err != nil || strings.Contains(string(got.Data), "research_note") || !bytes.Equal(got.Data, plain.Data) { |
| 40 | t.Fatalf("%s at 11: %s %v", specialist, got.Data, err) |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |