Skip to content

Commit a2affbd

Browse files
authored
Merge pull request #13 from NexusForgeAI/feat/infrastructure
Feat/infrastructure
2 parents 633ad3e + 598159c commit a2affbd

7 files changed

Lines changed: 437 additions & 1 deletion

File tree

.github/workflows/build.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
test:
11+
name: Test Go Module
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Go
19+
uses: actions/setup-go@v4
20+
with:
21+
go-version: '1.23'
22+
cache: true
23+
24+
- name: Run tests
25+
run: go test -race ./...
26+
27+
28+
29+
build:
30+
name: Build Binary
31+
runs-on: ubuntu-latest
32+
needs: [test]
33+
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
37+
38+
- name: Set up Go
39+
uses: actions/setup-go@v4
40+
with:
41+
go-version: '1.23'
42+
43+
- name: Build application
44+
run: |
45+
mkdir -p bin
46+
go build -o bin/mcp-server ./cmd/mcp-server
47+
48+
- name: Upload build artifacts
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: mcp-server-binary
52+
path: bin/mcp-server
53+
54+
docker:
55+
name: Build Docker Image
56+
runs-on: ubuntu-latest
57+
needs: [test]
58+
59+
steps:
60+
- name: Checkout code
61+
uses: actions/checkout@v4
62+
63+
- name: Set up Docker Buildx
64+
uses: docker/setup-buildx-action@v2
65+
66+
- name: Build Docker image
67+
run: |
68+
docker build -t weave-toolkit/mcp-server:latest .
69+
70+
- name: Save Docker image
71+
run: |
72+
docker save weave-toolkit/mcp-server:latest -o mcp-server-image.tar
73+
74+
- name: Upload Docker image artifact
75+
uses: actions/upload-artifact@v4
76+
with:
77+
name: mcp-server-docker-image
78+
path: mcp-server-image.tar

.github/workflows/release.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
name: Build and Release
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: '1.23'
21+
cache: true
22+
23+
- name: Build
24+
run: |
25+
mkdir -p bin
26+
go build -o bin/mcp-server ./cmd/mcp-server
27+
28+
- name: Create Release
29+
uses: softprops/action-gh-release@v1
30+
with:
31+
files: bin/mcp-server
32+
uses: actions/upload-release-asset@v1
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
with:
36+
upload_url: ${{ steps.create_release.outputs.upload_url }}
37+
asset_path: ./bin/mcp-server
38+
asset_name: mcp-server-${{ github.ref_name }}
39+
asset_content_type: application/octet-stream
40+
41+
docker-release:
42+
name: Build and Push Docker Image
43+
runs-on: ubuntu-latest
44+
needs: release
45+
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v4
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v2
52+
53+
- name: Log in to Docker Hub
54+
uses: docker/login-action@v2
55+
with:
56+
username: ${{ secrets.DOCKERHUB_USERNAME }}
57+
password: ${{ secrets.DOCKERHUB_TOKEN }}
58+
59+
- name: Extract metadata
60+
id: meta
61+
uses: docker/metadata-action@v4
62+
with:
63+
images: weave-toolkit/mcp-server
64+
tags: |
65+
type=ref,event=tag
66+
type=semver,pattern={{version}}
67+
type=semver,pattern={{major}}.{{minor}}
68+
latest
69+
70+
- name: Build and push Docker image
71+
uses: docker/build-push-action@v4
72+
with:
73+
context: .
74+
push: true
75+
tags: ${{ steps.meta.outputs.tags }}
76+
labels: ${{ steps.meta.outputs.labels }}
77+
78+
- name: Docker Hub description
79+
uses: peter-evans/dockerhub-description@v3
80+
with:
81+
username: ${{ secrets.DOCKERHUB_USERNAME }}
82+
password: ${{ secrets.DOCKERHUB_TOKEN }}
83+
repository: weave-toolkit/mcp-server

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ WORKDIR /app
3232
COPY --from=builder /app/mcp-server .
3333

3434
# 复制配置文件
35-
COPY .env ./
3635
COPY tool-config.json ./
3736

3837
# 更改文件所有权

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ go 1.24.9
55
require (
66
github.com/gin-gonic/gin v1.11.0
77
github.com/rs/zerolog v1.34.0
8+
github.com/stretchr/testify v1.11.1
89
)
910

1011
require (
1112
github.com/bytedance/sonic v1.14.0 // indirect
1213
github.com/bytedance/sonic/loader v0.3.0 // indirect
1314
github.com/cloudwego/base64x v0.1.6 // indirect
15+
github.com/davecgh/go-spew v1.1.1 // indirect
1416
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
1517
github.com/gin-contrib/sse v1.1.0 // indirect
1618
github.com/go-playground/locales v0.14.1 // indirect
@@ -24,6 +26,7 @@ require (
2426
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
2527
github.com/modern-go/reflect2 v1.0.2 // indirect
2628
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
29+
github.com/pmezard/go-difflib v1.0.0 // indirect
2730
github.com/quic-go/qpack v0.5.1 // indirect
2831
github.com/quic-go/quic-go v0.54.0 // indirect
2932
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
@@ -37,6 +40,7 @@ require (
3740
golang.org/x/text v0.27.0 // indirect
3841
golang.org/x/tools v0.34.0 // indirect
3942
google.golang.org/protobuf v1.36.9 // indirect
43+
gopkg.in/yaml.v3 v3.0.1 // indirect
4044
)
4145

4246
require (

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
9696
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
9797
google.golang.org/protobuf v1.36.9 h1:w2gp2mA27hUeUzj9Ex9FBjsBm40zfaDtEWow293U7Iw=
9898
google.golang.org/protobuf v1.36.9/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
99+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
99100
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
100101
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
101102
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

test/calculator_test.go

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package test
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"testing"
7+
8+
"Weave-Toolkit/internal/tools"
9+
10+
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
func TestCalculatorTool(t *testing.T) {
15+
calculator := &tools.CalculatorTool{}
16+
17+
tests := []struct {
18+
name string
19+
args tools.CalculatorArgs
20+
expected float64
21+
hasError bool
22+
}{
23+
{
24+
name: "加法运算",
25+
args: tools.CalculatorArgs{
26+
Operation: "add",
27+
A: 10,
28+
B: 20,
29+
},
30+
expected: 30,
31+
},
32+
{
33+
name: "减法运算",
34+
args: tools.CalculatorArgs{
35+
Operation: "subtract",
36+
A: 50,
37+
B: 30,
38+
},
39+
expected: 20,
40+
},
41+
{
42+
name: "乘法运算",
43+
args: tools.CalculatorArgs{
44+
Operation: "multiply",
45+
A: 5,
46+
B: 6,
47+
},
48+
expected: 30,
49+
},
50+
{
51+
name: "除法运算",
52+
args: tools.CalculatorArgs{
53+
Operation: "divide",
54+
A: 100,
55+
B: 4,
56+
},
57+
expected: 25,
58+
},
59+
{
60+
name: "除零错误",
61+
args: tools.CalculatorArgs{
62+
Operation: "divide",
63+
A: 10,
64+
B: 0,
65+
},
66+
hasError: true,
67+
},
68+
{
69+
name: "无效操作",
70+
args: tools.CalculatorArgs{
71+
Operation: "invalid",
72+
A: 10,
73+
B: 20,
74+
},
75+
hasError: true,
76+
},
77+
}
78+
79+
for _, tt := range tests {
80+
t.Run(tt.name, func(t *testing.T) {
81+
argsJSON, err := json.Marshal(tt.args)
82+
require.NoError(t, err)
83+
84+
result, err := calculator.Execute(context.Background(), argsJSON)
85+
86+
if tt.hasError {
87+
assert.Error(t, err)
88+
return
89+
}
90+
91+
require.NoError(t, err)
92+
93+
var calcResult tools.CalculatorResult
94+
err = json.Unmarshal(result, &calcResult)
95+
require.NoError(t, err)
96+
97+
assert.Equal(t, tt.expected, calcResult.Result)
98+
})
99+
}
100+
}
101+
102+
func TestCalculatorToolWithOperands(t *testing.T) {
103+
calculator := &tools.CalculatorTool{}
104+
105+
tests := []struct {
106+
name string
107+
operands []float64
108+
operation string
109+
expected float64
110+
}{
111+
{
112+
name: "使用操作数数组进行加法",
113+
operands: []float64{15, 25},
114+
operation: "add",
115+
expected: 40,
116+
},
117+
{
118+
name: "使用操作数数组进行乘法",
119+
operands: []float64{3, 7},
120+
operation: "multiply",
121+
expected: 21,
122+
},
123+
}
124+
125+
for _, tt := range tests {
126+
t.Run(tt.name, func(t *testing.T) {
127+
args := tools.CalculatorArgs{
128+
Operation: tt.operation,
129+
Operands: tt.operands,
130+
}
131+
132+
argsJSON, err := json.Marshal(args)
133+
require.NoError(t, err)
134+
135+
result, err := calculator.Execute(context.Background(), argsJSON)
136+
require.NoError(t, err)
137+
138+
var calcResult tools.CalculatorResult
139+
err = json.Unmarshal(result, &calcResult)
140+
require.NoError(t, err)
141+
142+
assert.Equal(t, tt.expected, calcResult.Result)
143+
})
144+
}
145+
}

0 commit comments

Comments
 (0)