utils_test.go
1 // Copyright (c) 2024-2026 Tencent Zhuque Lab. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // Requirement: Any integration or derivative work must explicitly attribute 16 // Tencent Zhuque Lab (https://github.com/Tencent/AI-Infra-Guard) in its 17 // documentation or user interface, as detailed in the NOTICE file. 18 19 package utils 20 21 import ( 22 "github.com/stretchr/testify/assert" 23 "testing" 24 ) 25 26 func TestListDir(t *testing.T) { 27 sb, err := ListDir("/mcp-server", -1, "") 28 assert.NoError(t, err) 29 t.Log(sb) 30 } 31 32 func TestGrepFile(t *testing.T) { 33 sb, err := Grep("/mcp-server/src/mcp_server/server.py", "@mcp\\.tool.*\n.*def", 3) 34 assert.NoError(t, err) 35 t.Log(sb) 36 } 37 38 func TestGrepDirectory(t *testing.T) { 39 sb, err := Grep("/mcp-server", "AppConfig", 3) 40 assert.NoError(t, err) 41 t.Log(sb) 42 p := "SSE|streamable-http|EventSource" 43 sb, err = Grep("/mcp-server", p, 3) 44 assert.NoError(t, err) 45 t.Log(sb) 46 } 47 48 func TestReadBigFile(t *testing.T) { 49 sb, err := ReadFileChunk("/mcp-server/src/mcp_server/server.py", 0, 0, 10*1024) 50 assert.NoError(t, err) 51 t.Log(sb) 52 53 sb, err = ReadFileChunk("/mcp-server/src/mcp_server/server.py", 0, 2, 10*1024) 54 assert.NoError(t, err) 55 t.Log(sb) 56 } 57 58 func TestReadSmallFile(t *testing.T) { 59 sb, err := ReadFileChunk("/mcp-server/src/mcp_server/app_config.py", 0, 0, 10*1024) 60 assert.NoError(t, err) 61 t.Log(sb) 62 }