fix(wecom): initialize context in constructors to prevent nil panic in tests

The ctx field was only set in Start(), so tests calling handleMessageCallback
without Start() caused a nil pointer dereference in MessageBus.PublishInbound.
This commit is contained in:
Hoshina
2026-02-28 21:45:05 +08:00
parent 62f59f76e3
commit 8e06e2adbd
2 changed files with 6 additions and 0 deletions
+3
View File
@@ -129,9 +129,12 @@ func NewWeComAppChannel(cfg config.WeComAppConfig, messageBus *bus.MessageBus) (
channels.WithReasoningChannelID(cfg.ReasoningChannelID),
)
ctx, cancel := context.WithCancel(context.Background())
return &WeComAppChannel{
BaseChannel: base,
config: cfg,
ctx: ctx,
cancel: cancel,
processedMsgs: make(map[string]bool),
}, nil
}
+3
View File
@@ -93,9 +93,12 @@ func NewWeComBotChannel(cfg config.WeComConfig, messageBus *bus.MessageBus) (*We
channels.WithReasoningChannelID(cfg.ReasoningChannelID),
)
ctx, cancel := context.WithCancel(context.Background())
return &WeComBotChannel{
BaseChannel: base,
config: cfg,
ctx: ctx,
cancel: cancel,
processedMsgs: make(map[string]bool),
}, nil
}