picker_composition_external_test.go RawHistoryFolder
1package client_test
2
3import (
4 "testing"
5 "time"
6
7 "github.com/stretchr/testify/require"
8
9 "github.com/bnema/vev/internal/domain"
10 "github.com/bnema/vev/internal/domain/terminalcap"
11 "github.com/bnema/vev/internal/ports"
12 "github.com/bnema/vev/internal/protocol"
13 "github.com/bnema/vev/internal/protocol/catalogue"
14 "github.com/bnema/vev/internal/usecase/client"
15)
16
17// TestCompositionOutsideThePackageCanBuildThePicker proves the composition seam
18// works from outside the package. Without it a composition could build the
19// supervisor and subscribe to broker publications, but never hand it a picker,
20// so it could never resolve a selection into an attachment.
21func TestCompositionOutsideThePackageCanBuildThePicker(t *testing.T) {
22 geometry := domain.Size{Cols: 80, Rows: 24}
23 picker := client.NewPicker(nil, 0, terminalcap.ColorCapabilities{Mode: terminalcap.TrueColor})
24 require.NotNil(t, picker)
25
26 // The exact assignment an app composition performs.
27 cfg := client.SupervisorConfig{Picker: picker}
28 require.Same(t, picker, cfg.Picker)
29
30 // Exercise a real local-only publication through the exported facade.
31 picker.ApplySnapshot(ports.BrokerSnapshot{
32 Epoch: 1,
33 Revision: 1,
34 Daemons: []ports.BrokerDaemonObservation{{
35 Local: true,
36 DisplayOrigin: "local",
37 Policy: validExternalPickerPolicy(),
38 Identity: "local-daemon",
39 Incarnation: ports.BrokerDaemonIncarnation{1},
40 ProtocolVersion: protocol.Version,
41 Availability: domain.RemoteAvailabilityReachable,
42 LastSuccess: time.Now(),
43 InventoryKnown: true,
44 Sessions: []catalogue.RemoteCatalogSession{{
45 LifecycleID: domain.SessionLifecycleID{1},
46 Name: "work",
47 State: catalogue.RemoteCatalogSessionUp,
48 }},
49 }},
50 })
51 require.NotEmpty(t, picker.Render(geometry))
52 require.Empty(t, picker.RenderNotice(geometry))
53}
54
55func TestPickerZeroValueIsInertOutsideThePackage(t *testing.T) {
56 geometry := domain.Size{Cols: 80, Rows: 24}
57 zero := &client.Picker{}
58
59 require.NotPanics(t, func() {
60 zero.ApplySnapshot(ports.BrokerSnapshot{Epoch: 1, Revision: 1})
61 zero.SetOwnsInput(true)
62 })
63 require.Nil(t, zero.OpsReady())
64 require.Empty(t, zero.Render(geometry))
65 require.Empty(t, zero.RenderNotice(geometry))
66
67 // An absent optional picker is inert too.
68 var absent *client.Picker
69 require.Empty(t, absent.Render(geometry))
70 require.Empty(t, absent.RenderNotice(geometry))
71}
72
73func validExternalPickerPolicy() ports.BrokerPolicy {
74 return ports.BrokerPolicy{
75 ProtocolVersion: protocol.Version,
76 CatalogSchemaVersion: catalogue.RemoteCatalogSchemaVersion,
77 EnvironmentPolicy: protocol.EnvironmentPolicyDaemonOwned,
78 Transport: "quic",
79 Trust: "trust",
80 Launch: "launch",
81 Isolation: "user",
82 }
83}