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