mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
ddec110b0e
In order to allow Coder Agents to use AI Gateway in OSS, we need to rehome the `aibridged`\-related code into the AGPL path. The HTTP API is only registered under enterprise so will still require the AI Governance Add-on to be present in order to use it, whereas Coder Agents uses an in-memory pipe to the same handlers.
63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package aibridged
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"go.opentelemetry.io/otel"
|
|
|
|
"github.com/coder/coder/v2/coderd/aibridged/proto"
|
|
"github.com/coder/coder/v2/testutil"
|
|
)
|
|
|
|
func TestMCPRegex(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
cases := []struct {
|
|
name string
|
|
allowRegex, denyRegex string
|
|
expectedErr error
|
|
}{
|
|
{
|
|
name: "invalid allow regex",
|
|
allowRegex: `\`,
|
|
expectedErr: ErrCompileRegex,
|
|
},
|
|
{
|
|
name: "invalid deny regex",
|
|
denyRegex: `+`,
|
|
expectedErr: ErrCompileRegex,
|
|
},
|
|
{
|
|
name: "valid empty",
|
|
},
|
|
{
|
|
name: "valid",
|
|
allowRegex: "(allowed|allowed2)",
|
|
denyRegex: ".*disallowed.*",
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
logger := testutil.Logger(t)
|
|
f := NewMCPProxyFactory(logger, otel.Tracer("aibridged_test"), nil)
|
|
|
|
_, err := f.newStreamableHTTPServerProxy(&proto.MCPServerConfig{
|
|
Id: "mock",
|
|
Url: "mock/mcp",
|
|
ToolAllowRegex: tc.allowRegex,
|
|
ToolDenyRegex: tc.denyRegex,
|
|
}, "")
|
|
|
|
if tc.expectedErr == nil {
|
|
require.NoError(t, err)
|
|
} else {
|
|
require.ErrorIs(t, err, tc.expectedErr)
|
|
}
|
|
})
|
|
}
|
|
}
|