MCPcopy Create free account
hub / github.com/astercloud/aster / TestPythonRuntimeToolInjection

Function TestPythonRuntimeToolInjection

pkg/tools/bridge/ptc_integration_test.go:185–219  ·  view source on GitHub ↗

TestPythonRuntimeToolInjection 测试 Python 运行时工具注入

(t *testing.T)

Source from the content-addressed store, hash-verified

183
184// TestPythonRuntimeToolInjection 测试 Python 运行时工具注入
185func TestPythonRuntimeToolInjection(t *testing.T) {
186 runtime := NewPythonRuntime(nil)
187
188 // 测试无工具的简单模式
189 t.Run("NoToolsMode", func(t *testing.T) {
190 code := "print('Hello World')"
191 result, err := runtime.Execute(context.Background(), code, map[string]any{})
192 if err != nil {
193 t.Fatalf("Failed to execute: %v", err)
194 }
195 if !result.Success {
196 t.Error("Expected success")
197 }
198 })
199
200 // 测试带工具的 PTC 模式
201 t.Run("PTCMode", func(t *testing.T) {
202 runtime.SetTools([]string{"Read", "Write"})
203 runtime.SetBridgeURL("http://localhost:8080")
204
205 // 验证生成的代码包含工具注入
206 wrappedCode := runtime.wrapCode("print('test')", map[string]any{})
207
208 // 检查是否包含关键组件
209 if !contains(wrappedCode, "_AsterBridge") {
210 t.Error("Expected _AsterBridge class in wrapped code")
211 }
212 if !contains(wrappedCode, "async def _user_main()") {
213 t.Error("Expected async main wrapper")
214 }
215 if !contains(wrappedCode, "Read") {
216 t.Error("Expected Read tool in injected tools")
217 }
218 })
219}
220
221// contains 检查字符串是否包含子串
222func contains(s, substr string) bool {

Callers

nothing calls this directly

Calls 8

ExecuteMethod · 0.95
SetToolsMethod · 0.95
SetBridgeURLMethod · 0.95
wrapCodeMethod · 0.95
NewPythonRuntimeFunction · 0.85
containsFunction · 0.70
ErrorMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected