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

Function TestFullStack_Integration

pkg/middleware/integration_test.go:121–178  ·  view source on GitHub ↗

TestFullStack_Integration 集成测试: 完整 Middleware Stack

(t *testing.T)

Source from the content-addressed store, hash-verified

119
120// TestFullStack_Integration 集成测试: 完整 Middleware Stack
121func TestFullStack_Integration(t *testing.T) {
122 ctx := context.Background()
123
124 // 1. 创建 Backend
125 backend := backends.NewStateBackend()
126
127 // 2. 创建 FilesystemMiddleware
128 fsMiddleware := NewFilesystemMiddleware(&FilesystemMiddlewareConfig{
129 Backend: backend,
130 })
131
132 // 3. 创建 SubAgentMiddleware
133 subagentMiddleware, err := NewSubAgentMiddleware(&SubAgentMiddlewareConfig{
134 Specs: []SubAgentSpec{
135 {Name: "researcher", Description: "Research agent"},
136 {Name: "coder", Description: "Coding agent"},
137 },
138 Factory: func(ctx context.Context, spec SubAgentSpec) (SubAgent, error) {
139 return NewSimpleSubAgent(spec.Name, spec.Prompt, nil), nil
140 },
141 })
142 if err != nil {
143 t.Fatalf("Failed to create SubAgentMiddleware: %v", err)
144 }
145
146 // 4. 创建 Stack
147 stack := NewStack([]Middleware{
148 fsMiddleware,
149 subagentMiddleware,
150 })
151
152 // 5. 验证工具总数 (6 个文件工具 + 1 个 task 工具)
153 tools := stack.Tools()
154 if len(tools) != 7 {
155 t.Errorf("Expected 7 tools, got %d", len(tools))
156 }
157
158 // 6. 验证中间件顺序(按优先级)
159 middlewares := stack.Middlewares()
160 if len(middlewares) != 2 {
161 t.Fatalf("Expected 2 middlewares, got %d", len(middlewares))
162 }
163
164 // FilesystemMiddleware (priority: 100) 应该在前
165 if middlewares[0].Name() != "filesystem" {
166 t.Errorf("First middleware should be 'filesystem', got '%s'", middlewares[0].Name())
167 }
168
169 // SubAgentMiddleware (priority: 200) 应该在后
170 if middlewares[1].Name() != "subagent" {
171 t.Errorf("Second middleware should be 'subagent', got '%s'", middlewares[1].Name())
172 }
173
174 // 7. 清理
175 if err := stack.OnAgentStop(ctx, "test"); err != nil {
176 t.Errorf("Stack cleanup failed: %v", err)
177 }
178}

Callers

nothing calls this directly

Calls 9

ToolsMethod · 0.95
MiddlewaresMethod · 0.95
OnAgentStopMethod · 0.95
NewStateBackendFunction · 0.92
NewFilesystemMiddlewareFunction · 0.85
NewSubAgentMiddlewareFunction · 0.85
NewSimpleSubAgentFunction · 0.85
NewStackFunction · 0.85
NameMethod · 0.65

Tested by

no test coverage detected