test(tools): add unit tests for error handling functions
* Implement tests for error functions like errRequiredField, errInvalidField, and errEntityNotFound. * Ensure proper metadata is returned for various error scenarios. * Validate error handling in CRM, Files, and other tools. * Introduce tests for parsing stored file IDs and UUIDs. * Enhance coverage for helper functions related to project resolution and session management.
This commit is contained in:
42
internal/mcpserver/eventstore.go
Normal file
42
internal/mcpserver/eventstore.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package mcpserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"iter"
|
||||
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
)
|
||||
|
||||
type cleanupEventStore struct {
|
||||
base mcp.EventStore
|
||||
onSessionClosed func(string)
|
||||
}
|
||||
|
||||
func newCleanupEventStore(base mcp.EventStore, onSessionClosed func(string)) mcp.EventStore {
|
||||
return &cleanupEventStore{
|
||||
base: base,
|
||||
onSessionClosed: onSessionClosed,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *cleanupEventStore) Open(ctx context.Context, sessionID, streamID string) error {
|
||||
return s.base.Open(ctx, sessionID, streamID)
|
||||
}
|
||||
|
||||
func (s *cleanupEventStore) Append(ctx context.Context, sessionID, streamID string, data []byte) error {
|
||||
return s.base.Append(ctx, sessionID, streamID, data)
|
||||
}
|
||||
|
||||
func (s *cleanupEventStore) After(ctx context.Context, sessionID, streamID string, index int) iter.Seq2[[]byte, error] {
|
||||
return s.base.After(ctx, sessionID, streamID, index)
|
||||
}
|
||||
|
||||
func (s *cleanupEventStore) SessionClosed(ctx context.Context, sessionID string) error {
|
||||
if err := s.base.SessionClosed(ctx, sessionID); err != nil {
|
||||
return err
|
||||
}
|
||||
if s.onSessionClosed != nil {
|
||||
s.onSessionClosed(sessionID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user