oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package equipotest
2
3import (
4 "context"
5 "os"
6 "strings"
7 "testing"
8 "time"
9
10 "amadan.net/oficina/equipo/internal/equipo"
11
12 "amadan.net/oficina/equipo/internal/equipo/team"
13 "amadan.net/oficina/equipo/internal/runnerproto"
14)
15
16func TestPublishTicketBinding(t *testing.T) {
17 now := time.Now().UTC()
18 q := runnerproto.RunnerRequest{Version: 2, RequestID: "publish", ActionID: 42, Scope: team.Scope{Account: "team", Job: 7}, Handle: team.Handle{Attempt: 3, Fence: 2, Runner: "runner"}}
19 ticket := team.AdmissionTicket{Dispatch: team.Dispatch{Action: 42}, Scope: q.Scope, Handle: q.Handle, Incarnation: 5, ExpiresAt: now.Add(5 * time.Second)}
20 for _, name := range []string{"scope", "job", "attempt", "fence", "runner", "valid"} {
21 t.Run(name, func(t *testing.T) {
22 dir := t.TempDir()
23 executionMust(t, runnerproto.JournalAdmission(dir, q))
24 changed := ticket
25 switch name {
26 case "scope":
27 changed.Scope.Account = "other"
28 case "job":
29 changed.Scope.Job++
30 case "attempt":
31 changed.Handle.Attempt++
32 case "fence":
33 changed.Handle.Fence++
34 case "runner":
35 changed.Handle.Runner = "other"
36 }
37 err := runnerproto.ConsumeTicket(dir, q.RequestID, changed, now, 5)
38 if name == "valid" {
39 executionMust(t, err)
40 } else if err == nil {
41 t.Fatal("foreign publication ticket consumed")
42 }
43 })
44 }
45}
46
47func TestPublishInstanceAdapter(t *testing.T) {
48 f := runnerFixtureNew(t, true)
49 adapter := f.s.RunnerAdapter(team.OpForgePublish)
50 if class, err := adapter.Classify(team.OpForgePublish); err != nil || class != team.ReplayReconcilable {
51 t.Fatal("forge replay class", class, err)
52 }
53 if _, err := adapter.Execute(connectionContext, team.Dispatch{}); err == nil {
54 t.Fatal("instance performed runner effect")
55 }
56 provider := f.s.RunnerAdapter(team.OpProviderCall)
57 if class, err := provider.Classify(team.OpProviderCall); err != nil || class != team.ReplayUnsafe {
58 t.Fatal("provider replay class", class, err)
59 }
60 q := f.request()
61 q.Intent = &team.IntentSpec{Key: "call", Operation: team.OpProviderCall, Payload: []byte(`{"turn":1}`), Reserve: team.Usage{InputTokens: 10, OutputTokens: 10}}
62 result, err := f.x.Mutate(connectionContext, f.principal, "intend", q)
63 executionMust(t, err)
64 q.ActionID = result.(team.ActionID)
65 q.Intent = nil
66 q.RequestID = "admit"
67 result, err = f.x.Mutate(connectionContext, f.principal, "admit", q)
68 executionMust(t, err)
69 ticket := result.(team.AdmissionTicket)
70 if ticket.Scope != q.Scope || ticket.Handle != q.Handle {
71 t.Fatal("issued ticket has no binding")
72 }
73 r, err := provider.Reconcile(connectionContext, ticket.Dispatch)
74 executionMust(t, err)
75 if r.Receipt != nil || r.Definitive {
76 t.Fatal("missing observation proved absence")
77 }
78 q.RequestID = "receipt"
79 q.Receipt = &team.Receipt{ID: "unvalidated", Outcome: team.OutcomeSuccess}
80 _, err = f.x.Mutate(connectionContext, f.principal, "receipts", q)
81 executionMust(t, err)
82 r, err = provider.Reconcile(connectionContext, ticket.Dispatch)
83 executionMust(t, err)
84 if r.Receipt != nil {
85 t.Fatal("raw runner report became receipt")
86 }
87 f.x.SetRunnerValidators(equipo.RunnerValidators{Receipt: func(context.Context, equipo.Assignment, equipo.RunnerRequest) (team.Receipt, error) {
88 return team.Receipt{ID: "verified", Outcome: team.OutcomeSuccess, Usage: &team.Usage{Calls: 1}}, nil
89 }})
90 _, err = f.x.Mutate(connectionContext, f.principal, "receipts", q)
91 executionMust(t, err)
92 r, err = provider.Reconcile(connectionContext, ticket.Dispatch)
93 executionMust(t, err)
94 if r.Receipt == nil || r.Receipt.ID != "verified" {
95 t.Fatal("verified durable observation lost")
96 }
97}
98
99func TestPublishTransportIsProduction(t *testing.T) {
100 raw, err := os.ReadFile("../runner/runtime_workflow.go")
101 executionMust(t, err)
102 source := string(raw)
103 if strings.Contains(source, "unavailableDescription") || !strings.Contains(source, "Description: forge.NewDescriptionTransport(") || !strings.Contains(source, "forge.NewCommandDescriptionWriter(r.cfg.AmadanPath, r.cfg.ScratchRoot)") {
104 t.Fatal("runtime publication still uses unavailable description transport")
105 }
106 for _, wiring := range []string{"Launchers: r.launchers", "Namespaces: r.namespaces", "Launch: r.directLaunch"} {
107 if !strings.Contains(source, wiring) {
108 t.Fatal("Task 9 direct wiring lost", wiring)
109 }
110 }
111}
112