oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package wire_test
2
3import (
4 "amadan.net/oficina/equipo/internal/wire"
5 "strings"
6 "testing"
7)
8
9func TestInjectionProtocolDowngrade(t *testing.T) {
10 if wire.ProtocolInjectionDefences != 28 || wire.ProtocolCurrent != 38 {
11 t.Fatal("injection guarantees require protocol 28")
12 }
13 for version, want := range map[int]int{26: 26, 27: 27, 28: 28, 29: 29, 30: 30, 31: 31, 32: 32, 33: 33, 34: 34, 35: 35, 36: 36, 37: 37, 38: 38, 99: 38} {
14 if got := wire.Spoken(version); got != want {
15 t.Fatalf("negotiated %d as %d, want %d", version, got, want)
16 }
17 }
18 for _, tc := range []struct {
19 kind string
20 body any
21 keys []string
22 }{
23 {wire.FrameStep, wire.StepReport{BaseChecks: wire.ChecksFailed, BaseChecksSHA: strings.Repeat("a", 40), Change: &wire.ChangeFacts{GateFilesChanged: true, ReviewTruncated: true}}, []string{"base_checks", "base_checks_sha", "gate_files_changed", "review_truncated"}},
24 {wire.FrameDispatch, wire.DispatchCommand{PersonWords: []string{"Don't publish"}}, []string{"person_words"}},
25 } {
26 f, err := wire.NewFrame("test", tc.kind, tc.body)
27 if err != nil {
28 t.Fatal(err)
29 }
30 for _, protocol := range []int{wire.Protocol27, wire.Protocol26, wire.Protocol21, wire.Protocol1} {
31 old, err := wire.Encode(f, protocol)
32 if err != nil {
33 t.Fatal(err)
34 }
35 for _, key := range tc.keys {
36 if strings.Contains(string(old.Data), key) {
37 t.Fatalf("protocol %d retained %s: %s", protocol, key, old.Data)
38 }
39 }
40 }
41 current, err := wire.Encode(f, wire.ProtocolInjectionDefences)
42 if err != nil {
43 t.Fatal(err)
44 }
45 for _, key := range tc.keys {
46 if !strings.Contains(string(current.Data), key) {
47 t.Fatalf("current protocol lost %s", key)
48 }
49 }
50 }
51}
52