Skip to content

Commit 6861246

Browse files
committed
Merge branch 'feat/prometheus' of https://github.com/CutebreadCat/fzuhelper-server into feat/prometheus
2 parents bb89f57 + 397d2ad commit 6861246

50 files changed

Lines changed: 1072 additions & 224 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818
name: Format
1919
runs-on: ubuntu-22.04
2020
steps:
21-
- uses: actions/checkout@v6
22-
- uses: actions/setup-go@v6
21+
- uses: actions/checkout@v7
22+
- uses: actions/setup-go@v7
2323
with:
2424
go-version-file: go.mod
2525
cache: false
@@ -38,8 +38,8 @@ jobs:
3838
name: Vet
3939
runs-on: ubuntu-22.04
4040
steps:
41-
- uses: actions/checkout@v6
42-
- uses: actions/setup-go@v6
41+
- uses: actions/checkout@v7
42+
- uses: actions/setup-go@v7
4343
with:
4444
go-version-file: go.mod
4545
cache: false
@@ -52,8 +52,8 @@ jobs:
5252
name: lint
5353
runs-on: ubuntu-latest
5454
steps:
55-
- uses: actions/checkout@v6
56-
- uses: actions/setup-go@v6
55+
- uses: actions/checkout@v7
56+
- uses: actions/setup-go@v7
5757
with:
5858
go-version: '1.26'
5959
cache: false
@@ -67,11 +67,11 @@ jobs:
6767
runs-on: ubuntu-latest
6868
steps:
6969
- name: Checkout
70-
uses: actions/checkout@v6
70+
uses: actions/checkout@v7
7171
with:
7272
fetch-depth: 0
7373
- name: Set up Go
74-
uses: actions/setup-go@v6
74+
uses: actions/setup-go@v7
7575
with:
7676
go-version: '1.26'
7777
cache: false
@@ -91,7 +91,7 @@ jobs:
9191
fi
9292
- name: Upload results to Codecov
9393
if: ${{ (env.NEED_TO_CHECK == 'true') || (github.event_name != 'pull_request') }}
94-
uses: codecov/codecov-action@v6
94+
uses: codecov/codecov-action@v7
9595
with:
9696
flags: unittest
9797
token: ${{ secrets.CODECOV_TOKEN }}
@@ -103,7 +103,7 @@ jobs:
103103
name: License
104104
runs-on: ubuntu-22.04
105105
steps:
106-
- uses: actions/checkout@v6
106+
- uses: actions/checkout@v7
107107
- name: Check license header
108108
run: |
109109
make license && git add pkg cmd &&

.github/workflows/codeql.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727

2828
steps:
2929
- name: Checkout repository
30-
uses: actions/checkout@v6
30+
uses: actions/checkout@v7
3131

3232
- name: Initialize CodeQL
3333
uses: github/codeql-action/init@v4

.github/workflows/deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595

9696
steps:
9797
- name: Check out the code
98-
uses: actions/checkout@v6
98+
uses: actions/checkout@v7
9999

100100
- name: Log in to Alibaba Cloud Docker Registry
101101
uses: docker/login-action@v4

.github/workflows/vulncheck.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
GO111MODULE: on
2020
steps:
2121
- name: Fetch Repository
22-
uses: actions/checkout@v6
22+
uses: actions/checkout@v7
2323

2424
- name: Install Go
25-
uses: actions/setup-go@v6
25+
uses: actions/setup-go@v7
2626
with:
2727
go-version: stable
2828
check-latest: true

api/handler/api/common_service.go

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/handler/api/common_service_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package api
1818

1919
import (
2020
"context"
21+
"strings"
2122
"testing"
2223

2324
"github.com/bytedance/mockey"
@@ -591,3 +592,56 @@ func TestGetTermsList(t *testing.T) {
591592
})
592593
}
593594
}
595+
596+
func TestGetSignedLocationApiUrl(t *testing.T) {
597+
type testCase struct {
598+
name string
599+
mockSignedURL string
600+
mockHeaders map[string]string
601+
mockErr error
602+
body *ut.Body
603+
expectContains string
604+
}
605+
606+
validBody := `{"location":"119.262647,26.106131"}`
607+
608+
testCases := []testCase{
609+
{
610+
name: "success",
611+
mockSignedURL: "https://restapi.amap.com/v3/place/around?key=xxx&scode=abc",
612+
mockHeaders: map[string]string{"User-Agent": "AMAP_Location_SDK_Android"},
613+
body: &ut.Body{Body: strings.NewReader(validBody), Len: len(validBody)},
614+
expectContains: `{"code":"10000","message":"Success","data":`,
615+
},
616+
{
617+
name: "rpc error",
618+
mockErr: errno.InternalServiceError,
619+
body: &ut.Body{Body: strings.NewReader(validBody), Len: len(validBody)},
620+
expectContains: `{"code":"50001","message":"内部服务错误"`,
621+
},
622+
{
623+
name: "bind error",
624+
body: nil,
625+
expectContains: `{"code":"20001","message":"参数错误`,
626+
},
627+
}
628+
629+
router := route.NewEngine(&config.Options{})
630+
router.POST("/api/v1/common/signed-location-api-url", GetSignedLocationApiUrl)
631+
632+
defer mockey.UnPatchAll()
633+
for _, tc := range testCases {
634+
mockey.PatchConvey(tc.name, t, func() {
635+
if tc.name != "bind error" {
636+
mockey.Mock(rpc.GetSignedLocationApiUrlRPC).To(func(ctx context.Context, req *common.GetSignedLocationApiUrlRequest) (string, map[string]string, error) {
637+
return tc.mockSignedURL, tc.mockHeaders, tc.mockErr
638+
}).Build()
639+
}
640+
641+
res := ut.PerformRequest(router, consts.MethodPost, "/api/v1/common/signed-location-api-url", tc.body,
642+
ut.Header{Key: "Content-Type", Value: "application/json"})
643+
assert.Equal(t, consts.StatusOK, res.Result().StatusCode())
644+
assert.Contains(t, string(res.Result().Body()), tc.expectContains)
645+
})
646+
}
647+
}

api/mcp/academic.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,48 @@ import (
2929

3030
func GetScoresTool() mcpgoserver.ServerTool {
3131
return mcpgoserver.ServerTool{
32-
Tool: mcp.NewTool("get_scores",
32+
Tool: mcp.NewTool(
33+
"get_scores",
3334
mcp.WithDescription(
3435
"Fetch the user's score records for a given academic term. "+
3536
"Use this when the user asks to view grades/scores for a specific term. "+
36-
"Returns the score list for the given term."),
37+
"Returns the score list for the given term.",
38+
),
3739
mcp.WithString("user_id",
3840
mcp.Required(),
3941
mcp.Description(
40-
"user_id data comes from the login method response (user_id field).")),
42+
"user_id data comes from the login method response (user_id field).",
43+
)),
4144
mcp.WithString("user_cookies",
4245
mcp.Required(),
4346
mcp.Description(
44-
"user_cookies data comes from the login method response (user_cookies field).")),
47+
"user_cookies data comes from the login method response (user_cookies field).",
48+
)),
4549
),
4650
Handler: handleGetScores,
4751
}
4852
}
4953

5054
func GetGPATool() mcpgoserver.ServerTool {
5155
return mcpgoserver.ServerTool{
52-
Tool: mcp.NewTool("get_gpa",
56+
Tool: mcp.NewTool(
57+
"get_gpa",
5358
mcp.WithDescription(
5459
"Fetch the user's GPA (Grade Point Average) information for a given academic term. "+
5560
"Use this when the user asks to view GPA or grade point information. "+
5661
"Returns the GPA data including overall and term-specific GPA. "+
57-
"Note: This feature is only available for undergraduate students. Graduate students should use get_scores instead."),
62+
"Note: This feature is only available for undergraduate students. Graduate students should use get_scores instead.",
63+
),
5864
mcp.WithString("user_id",
5965
mcp.Required(),
6066
mcp.Description(
61-
"user_id data comes from the login method response (user_id field).")),
67+
"user_id data comes from the login method response (user_id field).",
68+
)),
6269
mcp.WithString("user_cookies",
6370
mcp.Required(),
6471
mcp.Description(
65-
"user_cookies data comes from the login method response (user_cookies field).")),
72+
"user_cookies data comes from the login method response (user_cookies field).",
73+
)),
6674
),
6775
Handler: handleGetGPA,
6876
}

api/mcp/auth.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,25 @@ type IdentifierData struct {
3737

3838
func LoginTool() mcpgoserver.ServerTool {
3939
return mcpgoserver.ServerTool{
40-
Tool: mcp.NewTool("login",
40+
Tool: mcp.NewTool(
41+
"login",
4142
mcp.WithDescription("Use this tool when the user wants to log into the educational system. "+
4243
"Call this when: user mentions logging in, needs to authenticate, "+
4344
"or when other tools fail due to no active session. "+
4445
"If JWCH_STUDENT_ID and JWCH_PASSWORD environment variables are set, "+
4546
"this happens automatically on startup. Returns success message on successful login."),
46-
mcp.WithString("student_id",
47+
mcp.WithString(
48+
"student_id",
4749
mcp.Required(),
4850
mcp.Description("Student ID for authentication (optional if FZUHELPER_STUDENT_ID env var is set)"),
4951
),
50-
mcp.WithString("password",
52+
mcp.WithString(
53+
"password",
5154
mcp.Required(),
5255
mcp.Description("Password for authentication (optional if FZUHELPER_STUDENT_PASSWORD env var is set)"),
5356
),
54-
mcp.WithString("student_type",
57+
mcp.WithString(
58+
"student_type",
5559
mcp.Description("StudentType for authentication. Defaults to \"1\" (Undergraduate student). "+
5660
"Set \"2\" for Postgraduate(optional if FZUHELPER_STUDENT_TYPE env var is set)"),
5761
),
@@ -62,15 +66,18 @@ func LoginTool() mcpgoserver.ServerTool {
6266

6367
func CheckSessionTool() mcpgoserver.ServerTool {
6468
return mcpgoserver.ServerTool{
65-
Tool: mcp.NewTool("check_session",
69+
Tool: mcp.NewTool(
70+
"check_session",
6671
mcp.WithDescription("Use this tool to verify if the current login session is still valid. "+
6772
"Call this when: user asks about connection status, before performing operations after a long idle "+
6873
"period, or to troubleshoot authentication issues. Returns session validity status."),
69-
mcp.WithString("user_id",
74+
mcp.WithString(
75+
"user_id",
7076
mcp.Required(),
7177
mcp.Description("user_id data comes from login method response, (user_cookies field)"),
7278
),
73-
mcp.WithString("user_cookies",
79+
mcp.WithString(
80+
"user_cookies",
7481
mcp.Required(),
7582
mcp.Description("user_cookies data comes from login method response, (user_cookies field)"),
7683
),

api/mcp/calendar.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,24 @@ import (
2929

3030
func GetCalendarTool() mcpgoserver.ServerTool {
3131
return mcpgoserver.ServerTool{
32-
Tool: mcp.NewTool("get_calendar",
32+
Tool: mcp.NewTool(
33+
"get_calendar",
3334
mcp.WithDescription(
3435
"Fetch the academic calendar in ICS format for the current term. "+
3536
"Use this when the user asks to view the academic calendar, course schedule in calendar format, "+
3637
"or wants to import course schedule into calendar applications. "+
37-
"Returns the calendar data in ICS format (base64 encoded)."),
38+
"Returns the calendar data in ICS format (base64 encoded).",
39+
),
3840
mcp.WithString("user_id",
3941
mcp.Required(),
4042
mcp.Description(
41-
"user_id data comes from the login method response (user_id field).")),
43+
"user_id data comes from the login method response (user_id field).",
44+
)),
4245
mcp.WithString("user_cookies",
4346
mcp.Required(),
4447
mcp.Description(
45-
"user_cookies data comes from the login method response (user_cookies field).")),
48+
"user_cookies data comes from the login method response (user_cookies field).",
49+
)),
4650
),
4751
Handler: handleGetCalendar,
4852
}

api/mcp/classroom.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,29 @@ import (
2929

3030
func GetExamRoomTool() mcpgoserver.ServerTool {
3131
return mcpgoserver.ServerTool{
32-
Tool: mcp.NewTool("get_exam_room",
32+
Tool: mcp.NewTool(
33+
"get_exam_room",
3334
mcp.WithDescription(
3435
"Fetch the user's exam room information and schedule. "+
3536
"Use this when the user asks to view exam locations, exam schedule, or examination room details. "+
36-
"Returns exam room information including location, time, seat number, and course details."),
37+
"Returns exam room information including location, time, seat number, and course details.",
38+
),
3739
mcp.WithString("user_id",
3840
mcp.Required(),
3941
mcp.Description(
40-
"user_id data comes from the login method response (user_id field).")),
42+
"user_id data comes from the login method response (user_id field).",
43+
)),
4144
mcp.WithString("user_cookies",
4245
mcp.Required(),
4346
mcp.Description(
44-
"user_cookies data comes from the login method response (user_cookies field).")),
47+
"user_cookies data comes from the login method response (user_cookies field).",
48+
)),
4549
mcp.WithString("term",
4650
mcp.Description(
4751
"Academic term code in the form yyyymm. "+
4852
"Examples: 202401 means 2024 Autumn term, 202402 means 2025 Spring term. "+
49-
"Optional: defaults to current term")),
53+
"Optional: defaults to current term",
54+
)),
5055
),
5156
Handler: handleGetExamRoom,
5257
}

0 commit comments

Comments
 (0)