package thintest import ( "testing" "amadan.net/oficina/equipo/internal/wire" ) // TestMixedVersionsMeteredAndResearch: metered connections arrived at // protocol 12 and Research at 13. A primary at 12 keeps metered // connections (an API-key connect reaches it) but is never offered // Research (propose_specialist and research say it needs an update, and // nothing is dispatched); at 13 both work; at 11 both are refused. The // protocols are written as numbers, so pointing ProtocolResearch back at // 12 fails here. func TestMixedVersionsMeteredAndResearch(t *testing.T) { good := wire.Connect{Provider: wire.ProviderTensorX, Kind: wire.KindAPIKey, LimitConfirmed: true, Budget: &wire.Budget{Day: wire.DefaultBudgetDay, Month: wire.DefaultBudgetMonth}} for _, c := range []struct { name string protocol int metered, research bool }{ {"11", wire.Protocol11, false, false}, {"12", wire.Protocol12, true, false}, {"13", wire.Protocol13, true, true}, } { t.Run(c.name, func(t *testing.T) { r := newToolRigSaying(t, c.protocol, personWords) // Metered: an API-key connect reaches the runner from 12. _, err := r.client.Connect(r.ctx, good) if !c.metered { if Status(err) != 409 { t.Fatalf("an API-key connect at %d: %v", c.protocol, err) } if n := r.commands(wire.FrameConnect); n != 0 { t.Fatalf("%d connects queued at %d", n, c.protocol) } } else { if err != nil { t.Fatalf("an API-key connect at %d: %v", c.protocol, err) } f, body, err := r.runner.Expect(r.ctx, wire.FrameConnect) if err != nil { t.Fatal(err) } if cmd := body.(*wire.ConnectCommand); cmd.Kind != wire.KindAPIKey || cmd.Billing != wire.BillingMetered || cmd.Budget == nil { t.Fatalf("connect at %d: %+v", c.protocol, cmd) } if err := r.runner.Send(r.ctx, "a-connect", wire.FrameAck, wire.Ack{ID: f.ID}); err != nil { t.Fatal(err) } } // Research: proposed and requested only from 13. id := r.shopTask("m") if !c.research { res := r.call("m-p", wire.ToolProposeSpecialist, researchArgs()) if !res.IsError || res.Code != "research_unsupported" { t.Fatalf("propose_specialist at %d: %+v", c.protocol, res) } res = r.research("m-r", id) if !res.IsError || res.Code != "research_unsupported" { t.Fatalf("research at %d: %+v", c.protocol, res) } r.begin("m-start", id) if r.specialistCards() != 0 || len(stepsOf(r.task(id), wire.SpecialistResearch)) != 0 || r.researchDispatches() != 0 { t.Fatalf("Research reached a primary at %d", c.protocol) } return } r.researchOn() r.inventoryOn() if res := r.research("m-r", id); res.IsError || res.Code != "requested" { t.Fatalf("research at %d: %+v", c.protocol, res) } r.begin("m-start", id) if d := r.nextDispatch(); d.Specialist != wire.SpecialistResearch || d.Research == nil { t.Fatalf("dispatch at %d: %+v", c.protocol, d) } }) } }