package thin import ( "encoding/json" "testing" "amadan.net/oficina/equipo/internal/wire" ) // TestExploreRefusedBelow10: an exploration is answered here on a // connection below protocol 10, before sending and in place of an older // instance's strict refusal of a call queued at 10; a change, protocol 10, // an unknown protocol and a stored success are never touched. func TestExploreRefusedBelow10(t *testing.T) { explore := wire.ToolCall{Name: wire.ToolRecordTask, Args: json.RawMessage(`{"repo":"r","title":"t","brief":"b","kind":"explore"}`)} change := wire.ToolCall{Name: wire.ToolRecordTask, Args: json.RawMessage(`{"repo":"r","title":"t","brief":"b","kind":"change"}`)} invalid := wire.ToolResult{IsError: true, Code: "invalid", Text: "bad input"} ok := wire.ToolResult{Code: "recorded", Text: "{}"} for name, c := range map[string]struct { call wire.ToolCall spoken int res *wire.ToolResult refused bool }{ "before sending at 9": {explore, wire.ProtocolPreview, nil, true}, "an older refusal at 9": {explore, wire.ProtocolPreview, &invalid, true}, "a stored success at 9": {explore, wire.ProtocolPreview, &ok, false}, "at 10": {explore, wire.ProtocolExplore, nil, false}, "protocol unknown": {explore, 0, nil, false}, "a change at 9": {change, wire.ProtocolPreview, &invalid, false}, } { res, refused := exploreRefused(c.call, c.spoken, c.res) if refused != c.refused || refused && (res.Code != "explore_unsupported" || !res.IsError || res.Text != toolExploreOld) { t.Errorf("%s: %+v %t", name, res, refused) } } }