| index e69ef70f..0337cd03 100644 |
| --- a/internal/wire/mac_engineering_test.go |
| +++ b/internal/wire/mac_engineering_test.go |
| @@ -211,6 +211,75 @@ func TestEncodeDropsMacEngineeringBelow37(t *testing.T) { |
| } |
| } |
| |
| +// A frame may carry a slice F key with an empty, zero or null value (a |
| +// peer that writes the key without omitempty, or a hand-built frame). Below |
| +// 37 the key itself must go, not only a set value: an older peer's strict |
| +// decoder refuses any key it does not know, whatever its value. |
| +func TestEncodeDropsEmptyMacEngineeringKeysBelow37(t *testing.T) { |
| + with := func(name string, at []string, extra map[string]any) wire.Frame { |
| + t.Helper() |
| + var frame map[string]any |
| + if err := json.Unmarshal(wiretest.Fixture(name), &frame); err != nil { |
| + t.Fatal(err) |
| + } |
| + obj := frame["data"].(map[string]any) |
| + for _, k := range at { |
| + obj = obj[k].(map[string]any) |
| + } |
| + for k, v := range extra { |
| + obj[k] = v |
| + } |
| + raw, _ := json.Marshal(frame) |
| + f, _, err := wire.ParseFrame(raw) |
| + if err != nil { |
| + t.Fatalf("%s with %v: %v", name, extra, err) |
| + } |
| + return f |
| + } |
| + diff, _ := wire.NewFrame("cd", wire.FrameChangeDiff, wire.ChangeDiffUpload{}) |
| + var diffFrame map[string]any |
| + raw, _ := json.Marshal(diff) |
| + _ = json.Unmarshal(raw, &diffFrame) |
| + diffFrame["data"].(map[string]any)["publication"] = "" |
| + raw, _ = json.Marshal(diffFrame) |
| + emptyDiff, _, err := wire.ParseFrame(raw) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, c := range []struct { |
| + name string |
| + frame wire.Frame |
| + keys []string |
| + }{ |
| + {"dispatch", with("frames/dispatch-needs.json", nil, map[string]any{"xcode_access": ""}), []string{"xcode_access"}}, |
| + {"step", with("frames/step-process-group.json", nil, map[string]any{"xcode_access": "", "session_id": "", "outcome_phase": ""}), []string{"xcode_access", "session_id", "outcome_phase"}}, |
| + {"publish", with("frames/publish.json", nil, map[string]any{"outcome_phase": ""}), []string{"outcome_phase"}}, |
| + {"published", with("frames/published.json", nil, map[string]any{"change_files": nil, "diff_collection": "", "outcome_phase": ""}), []string{"change_files", "diff_collection", "outcome_phase"}}, |
| + {"ask", with("frames/ask.json", nil, map[string]any{"eng_attempt": 0, "eng_account": "", "eng_session": ""}), []string{"eng_attempt", "eng_account", "eng_session"}}, |
| + {"blob", with("frames/blob.json", []string{"transfer"}, map[string]any{"kind": "", "old_base_sha": ""}), []string{"kind", "old_base_sha"}}, |
| + {"send_pack", with("frames/send_pack.json", []string{"transfer"}, map[string]any{"kind": "", "old_base_sha": ""}), []string{"kind", "old_base_sha"}}, |
| + {"hello", with("frames/hello-mac-probes.json", []string{"capabilities"}, map[string]any{"engineering": nil}), []string{"engineering"}}, |
| + {"change_diff", emptyDiff, []string{"publication"}}, |
| + } { |
| + for _, p := range []int{35, 36} { |
| + got, err := wire.Encode(c.frame, p) |
| + if err != nil { |
| + t.Errorf("%s at %d: %v", c.name, p, err) |
| + continue |
| + } |
| + for _, k := range c.keys { |
| + if bytes.Contains(got.Data, []byte(`"`+k+`"`)) { |
| + t.Errorf("%s at %d kept the empty %s: %s", c.name, p, k, got.Data) |
| + } |
| + } |
| + out, _ := json.Marshal(got) |
| + if _, _, err := wire.ParseFrame(out); err != nil { |
| + t.Errorf("%s at %d does not parse: %v", c.name, p, err) |
| + } |
| + } |
| + } |
| +} |
| + |
| // A worker's hello carries its connections and seal key only at 37: the |
| // instance ignores both from a worker below it. |
| func TestWithoutWorkerConnections(t *testing.T) { |