| 1 | package provider |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | // TestReadResultEnvelopeDoesNotAffectProviderVisibleBytes proves that the |
| 10 | // host-only read delivery envelope attached to a reader result leaves |
| 11 | // ModelMessages — and therefore provider-visible conversation bytes — unchanged. |
| 12 | func TestReadResultEnvelopeDoesNotAffectProviderVisibleBytes(t *testing.T) { |
| 13 | base := []Message{ |
| 14 | {Role: RoleUser, Content: "look at main.go"}, |
| 15 | {Role: RoleAssistant, ToolCalls: []ToolCall{{ID: "c1", Name: "read_file", Arguments: `{"path":"main.go"}`}}}, |
| 16 | {Role: RoleTool, ToolCallID: "c1", Name: "read_file", Content: " 1→package main\n"}, |
| 17 | } |
| 18 | withMeta := append([]Message(nil), base...) |
| 19 | withMeta[2].ReadResult = json.RawMessage(`{"protocol_version":1,"source":{"canonical_path":"/w/main.go","version_token":"rw1:abc"},"intent":"inspect","delivered_ranges":[{"start":0,"end":1}],"eof":true}`) |
| 20 | |
| 21 | visBase, err := json.Marshal(ModelMessages(base)) |
| 22 | if err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | visMeta, err := json.Marshal(ModelMessages(withMeta)) |
| 26 | if err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | if string(visBase) != string(visMeta) { |
| 30 | t.Fatalf("provider-visible messages diverged after local read metadata\nbase: %s\nmeta: %s", visBase, visMeta) |
| 31 | } |
| 32 | if strings.Contains(string(visMeta), "read_result") || strings.Contains(string(visMeta), "version_token") { |
| 33 | t.Fatalf("local read envelope leaked into provider-visible JSON: %s", visMeta) |
| 34 | } |
| 35 | } |
| 36 |