Repository navigation
Expand file tree
/
Copy pathapproval_test.go
More file actions
99 lines (90 loc) · 3.18 KB
/
Copy pathapproval_test.go
File metadata and controls
99 lines (90 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package remote
import (
"errors"
"testing"
"github.com/Agent-Field/codeaf/internal/session"
)
// postureAgent is an engine with the conversation's posture door on it.
type postureAgent struct {
*fakeAgent
stored, standing string
gate bool
}
func (a *postureAgent) ApprovalDial() bool { return a.gate }
func (a *postureAgent) ResolvedApprovalPosture() string {
if a.stored != "" && a.stored != session.PostureAuto {
return a.stored
}
return a.standing
}
// It takes the words the real door takes and refuses the rest with a sentence,
// which is the shape the wire carries (approval.go).
func (a *postureAgent) SetApprovalPosture(posture string) error {
for _, known := range session.ApprovalPostures {
if posture == known {
a.stored = posture
return nil
}
}
return errors.New(posture + " is not a posture")
}
func TestThePostureDialCrossesTheHostConnection(t *testing.T) {
far := &postureAgent{fakeAgent: &fakeAgent{}, standing: session.PostureAsk, gate: true}
loop, err := Loopback(Hello{Version: Version}, Options{Boot: func(Hello) (*Engine, error) {
return &Engine{Agent: far, SessionFile: "/srv/session.jsonl"}, nil
}})
if err != nil {
t.Fatal(err)
}
defer loop.Close()
agent := loop.Client.Agent()
if !agent.ApprovalDial() {
t.Fatal("host hid the posture dial")
}
// The posture a frame draws arrives with the welcome and is read from memory.
if got := agent.ResolvedApprovalPosture(); got != session.PostureAsk {
t.Fatalf("welcome carried %q rather than the engine's posture", got)
}
if err := agent.SetApprovalPosture(session.PostureAllow); err != nil {
t.Fatalf("the engine refused a posture it knows: %v", err)
}
if far.stored != session.PostureAllow {
t.Fatalf("the far conversation is still at %q", far.stored)
}
// AND THE SURFACE'S OWN COPY MOVED WITHOUT WAITING FOR THE PUSH.
if got := agent.ResolvedApprovalPosture(); got != session.PostureAllow {
t.Fatalf("the surface still draws %q after the keystroke", got)
}
// A refusal crosses as the engine's own sentence.
if err := agent.SetApprovalPosture("sideways"); err == nil {
t.Fatal("a word that is not a posture was taken")
}
}
// AN ENGINE WITH NO DOOR HAS NO DIAL, and an engine with the door and no gate
// behind it has none either: the flag is false and nothing reaches the far
// conversation.
func TestAnEngineWithoutThePostureDoorAdvertisesNoneAndTakesNothing(t *testing.T) {
for name, far := range map[string]WrappedAgent{
"no door": &fakeAgent{},
"no gate": &postureAgent{fakeAgent: &fakeAgent{}, standing: session.PostureAsk},
} {
t.Run(name, func(t *testing.T) {
loop, err := Loopback(Hello{Version: Version}, Options{Boot: func(Hello) (*Engine, error) {
return &Engine{Agent: far, SessionFile: "/srv/session.jsonl"}, nil
}})
if err != nil {
t.Fatal(err)
}
defer loop.Close()
agent := loop.Client.Agent()
if agent.ApprovalDial() {
t.Fatal("an engine with no dial advertised one")
}
if err := agent.SetApprovalPosture(session.PostureAllow); err == nil {
t.Fatal("a posture was taken by an engine that has no dial")
}
})
}
}
// The actual engine, rather than only a fixture, must expose the door.
var _ approvalDoor = (*session.Agent)(nil)