MCPcopy Create free account
hub / github.com/diillson/chatcli / TestLocalHubPollingPicksUpExternalAppend

Function TestLocalHubPollingPicksUpExternalAppend

cli/hub_local_test.go:47–88  ·  view source on GitHub ↗

TestLocalHubPollingPicksUpExternalAppend proves the realtime path: a turn written by another process (a second handle on the same db, standing in for the gateway) surfaces through the polling subscription.

(t *testing.T)

Source from the content-addressed store, hash-verified

45// written by another process (a second handle on the same db, standing in for
46// the gateway) surfaces through the polling subscription.
47func TestLocalHubPollingPicksUpExternalAppend(t *testing.T) {
48 path := filepath.Join(t.TempDir(), "hub.db")
49 ctx, cancel := context.WithCancel(context.Background())
50 defer cancel()
51
52 cliStore, err := hub.OpenSQLiteStore(ctx, path, nil)
53 if err != nil {
54 t.Fatalf("open cli store: %v", err)
55 }
56 t.Cleanup(func() { _ = cliStore.Close() })
57 gwStore, err := hub.OpenSQLiteStore(ctx, path, nil)
58 if err != nil {
59 t.Fatalf("open gw store: %v", err)
60 }
61 t.Cleanup(func() { _ = gwStore.Close() })
62
63 c := newLocalHubClient(cliStore, "edilson")
64 c.poll = 50 * time.Millisecond // snappy for the test
65
66 conv, _, err := c.ResolveActiveConversation(ctx, "")
67 if err != nil {
68 t.Fatalf("resolve: %v", err)
69 }
70 stream, err := c.SubscribeConversation(ctx, conv, 0)
71 if err != nil {
72 t.Fatalf("subscribe: %v", err)
73 }
74
75 // The "gateway" process appends a Telegram turn on the shared conversation.
76 if _, err := gwStore.Append(ctx, models.ConversationEvent{ConvID: conv, Principal: "edilson", Channel: "telegram", Role: models.ConvRoleUser, Content: "from phone"}); err != nil {
77 t.Fatalf("gw append: %v", err)
78 }
79
80 select {
81 case ev := <-stream:
82 if ev.Content != "from phone" || ev.Channel != "telegram" {
83 t.Fatalf("unexpected polled event: %+v", ev)
84 }
85 case <-time.After(3 * time.Second):
86 t.Fatal("polling did not pick up the external append")
87 }
88}
89
90// TestGatewayPrincipalCollapseSingleUser checks that, with CHATCLI_HUB_PRINCIPAL
91// set, an unbound gateway sender and the local CLI resolve to the same shared

Callers

nothing calls this directly

Calls 7

OpenSQLiteStoreFunction · 0.92
newLocalHubClientFunction · 0.85
CloseMethod · 0.65
SubscribeConversationMethod · 0.65
AppendMethod · 0.65
CleanupMethod · 0.45

Tested by

no test coverage detected