| 1 | package wire |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/copydesk" |
| 5 | "bytes" |
| 6 | "encoding/json" |
| 7 | "errors" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | func TestCopyMixedVersions(t *testing.T) { |
| 12 | raw, _ := json.Marshal(DispatchCommand{Specialist: SpecialistCopy, Copy: &CopyDispatch{Delegation: 1, Owner: "paul"}}) |
| 13 | f := Frame{ID: "copy-test", Type: FrameDispatch, Data: raw} |
| 14 | if _, err := Encode(f, ProtocolCopy-1); !errors.Is(err, ErrProtocol) { |
| 15 | t.Fatalf("old peer got Copy: %v", err) |
| 16 | } |
| 17 | if _, err := Encode(f, ProtocolCopy); err != nil { |
| 18 | t.Fatal(err) |
| 19 | } |
| 20 | raw, _ = json.Marshal(DispatchCommand{Specialist: SpecialistEngineering}) |
| 21 | f.Data = raw |
| 22 | if _, err := Encode(f, ProtocolCopy-1); err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | func TestCopyFailureEvidenceDowngrade(t *testing.T) { |
| 28 | f, err := NewFrame("copy-check", FrameStep, StepReport{TaskID: "t", StepID: "s", Attempt: 1, State: StepDone, Failure: ©desk.Signature{Version: 1}}) |
| 29 | if err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | old, err := Encode(f, ProtocolCopy-1) |
| 33 | if err != nil { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | if bytes.Contains(old.Data, []byte(`"failure"`)) { |
| 37 | t.Fatal("old peer received unrecognised failure evidence") |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | func TestCopyReviewProtocol20(t *testing.T) { |
| 42 | f, err := NewFrame("review", FrameDispatch, DispatchCommand{Specialist: SpecialistReview, AvoidFamilies: []string{"claude", "glm"}}) |
| 43 | if err != nil { |
| 44 | t.Fatal(err) |
| 45 | } |
| 46 | out, err := Encode(f, Protocol20) |
| 47 | if err != nil { |
| 48 | t.Fatal("old Review runner refused:", err) |
| 49 | } |
| 50 | if bytes.Contains(out.Data, []byte("avoid_families")) { |
| 51 | t.Fatal("old peer got unknown field") |
| 52 | } |
| 53 | out, err = Encode(f, ProtocolCopy) |
| 54 | if err != nil || !bytes.Contains(out.Data, []byte("avoid_families")) { |
| 55 | t.Fatal("new peer lost editor families") |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func TestCopyReviewProtocol19(t *testing.T) { |
| 60 | f, err := NewFrame("review", FrameDispatch, DispatchCommand{Specialist: SpecialistReview, AvoidFamilies: []string{"claude"}}) |
| 61 | if err != nil { |
| 62 | t.Fatal(err) |
| 63 | } |
| 64 | out, err := Encode(f, Protocol19) |
| 65 | if err != nil || bytes.Contains(out.Data, []byte("avoid_families")) { |
| 66 | t.Fatalf("older downgrade lost Copy field removal: %s %v", out.Data, err) |
| 67 | } |
| 68 | } |
| 69 | |