oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package thintest
2
3import (
4 "testing"
5
6 "amadan.net/oficina/equipo/internal/wire"
7)
8
9// TestMixedVersionsMeteredAndResearch: metered connections arrived at
10// protocol 12 and Research at 13. A primary at 12 keeps metered
11// connections (an API-key connect reaches it) but is never offered
12// Research (propose_specialist and research say it needs an update, and
13// nothing is dispatched); at 13 both work; at 11 both are refused. The
14// protocols are written as numbers, so pointing ProtocolResearch back at
15// 12 fails here.
16func TestMixedVersionsMeteredAndResearch(t *testing.T) {
17 good := wire.Connect{Provider: wire.ProviderTensorX, Kind: wire.KindAPIKey, LimitConfirmed: true, Budget: &wire.Budget{Day: wire.DefaultBudgetDay, Month: wire.DefaultBudgetMonth}}
18 for _, c := range []struct {
19 name string
20 protocol int
21 metered, research bool
22 }{
23 {"11", wire.Protocol11, false, false},
24 {"12", wire.Protocol12, true, false},
25 {"13", wire.Protocol13, true, true},
26 } {
27 t.Run(c.name, func(t *testing.T) {
28 r := newToolRigSaying(t, c.protocol, personWords)
29
30 // Metered: an API-key connect reaches the runner from 12.
31 _, err := r.client.Connect(r.ctx, good)
32 if !c.metered {
33 if Status(err) != 409 {
34 t.Fatalf("an API-key connect at %d: %v", c.protocol, err)
35 }
36 if n := r.commands(wire.FrameConnect); n != 0 {
37 t.Fatalf("%d connects queued at %d", n, c.protocol)
38 }
39 } else {
40 if err != nil {
41 t.Fatalf("an API-key connect at %d: %v", c.protocol, err)
42 }
43 f, body, err := r.runner.Expect(r.ctx, wire.FrameConnect)
44 if err != nil {
45 t.Fatal(err)
46 }
47 if cmd := body.(*wire.ConnectCommand); cmd.Kind != wire.KindAPIKey || cmd.Billing != wire.BillingMetered || cmd.Budget == nil {
48 t.Fatalf("connect at %d: %+v", c.protocol, cmd)
49 }
50 if err := r.runner.Send(r.ctx, "a-connect", wire.FrameAck, wire.Ack{ID: f.ID}); err != nil {
51 t.Fatal(err)
52 }
53 }
54
55 // Research: proposed and requested only from 13.
56 id := r.shopTask("m")
57 if !c.research {
58 res := r.call("m-p", wire.ToolProposeSpecialist, researchArgs())
59 if !res.IsError || res.Code != "research_unsupported" {
60 t.Fatalf("propose_specialist at %d: %+v", c.protocol, res)
61 }
62 res = r.research("m-r", id)
63 if !res.IsError || res.Code != "research_unsupported" {
64 t.Fatalf("research at %d: %+v", c.protocol, res)
65 }
66 r.begin("m-start", id)
67 if r.specialistCards() != 0 || len(stepsOf(r.task(id), wire.SpecialistResearch)) != 0 || r.researchDispatches() != 0 {
68 t.Fatalf("Research reached a primary at %d", c.protocol)
69 }
70 return
71 }
72 r.researchOn()
73 r.inventoryOn()
74 if res := r.research("m-r", id); res.IsError || res.Code != "requested" {
75 t.Fatalf("research at %d: %+v", c.protocol, res)
76 }
77 r.begin("m-start", id)
78 if d := r.nextDispatch(); d.Specialist != wire.SpecialistResearch || d.Research == nil {
79 t.Fatalf("dispatch at %d: %+v", c.protocol, d)
80 }
81 })
82 }
83}
84