- edge node store 및 console 업데이트 - node adapters(cli, ollama, vllm, mock) 리팩토링 - node router, run_manager, store 개선 - proto 파일(control.proto, runtime.proto) 및 생성 코드 업데이트 - config 업데이트
93 lines
2.3 KiB
Go
93 lines
2.3 KiB
Go
package router
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"go.uber.org/zap"
|
|
"iop/apps/node/internal/adapters"
|
|
"iop/apps/node/internal/runtime"
|
|
)
|
|
|
|
type stubAdapter struct{ name string }
|
|
|
|
func (s *stubAdapter) Name() string { return s.name }
|
|
func (s *stubAdapter) Capabilities(_ context.Context) (runtime.Capabilities, error) {
|
|
return runtime.Capabilities{AdapterName: s.name}, nil
|
|
}
|
|
func (s *stubAdapter) Execute(_ context.Context, _ runtime.ExecutionSpec, _ runtime.EventSink) error {
|
|
return nil
|
|
}
|
|
|
|
func TestResolve_PreservesSessionFields(t *testing.T) {
|
|
reg := adapters.NewRegistry()
|
|
reg.Register(&stubAdapter{name: "cli"})
|
|
r := New(reg, zap.NewNop())
|
|
|
|
req := runtime.RunRequest{
|
|
RunID: "run-1",
|
|
Adapter: "cli",
|
|
Target: "codex",
|
|
SessionID: "session-a",
|
|
SessionMode: runtime.SessionModeRequireExisting,
|
|
Background: true,
|
|
}
|
|
|
|
spec, err := r.Resolve(context.Background(), req)
|
|
if err != nil {
|
|
t.Fatalf("resolve: %v", err)
|
|
}
|
|
if spec.SessionID != req.SessionID {
|
|
t.Errorf("SessionID: got %q want %q", spec.SessionID, req.SessionID)
|
|
}
|
|
if spec.SessionMode != req.SessionMode {
|
|
t.Errorf("SessionMode: got %q want %q", spec.SessionMode, req.SessionMode)
|
|
}
|
|
if spec.Background != req.Background {
|
|
t.Errorf("Background: got %v want %v", spec.Background, req.Background)
|
|
}
|
|
}
|
|
|
|
func TestResolveAdapter_Found(t *testing.T) {
|
|
reg := adapters.NewRegistry()
|
|
expected := &stubAdapter{name: "cli"}
|
|
reg.Register(expected)
|
|
r := New(reg, zap.NewNop())
|
|
|
|
req := runtime.RunRequest{
|
|
RunID: "run-1",
|
|
Adapter: "cli",
|
|
Target: "codex",
|
|
}
|
|
|
|
spec, adapter, err := r.ResolveAdapter(context.Background(), req)
|
|
if err != nil {
|
|
t.Fatalf("ResolveAdapter: %v", err)
|
|
}
|
|
if spec.Adapter != "cli" {
|
|
t.Errorf("expected adapter name 'cli', got %q", spec.Adapter)
|
|
}
|
|
if adapter != expected {
|
|
t.Fatal("expected same adapter instance")
|
|
}
|
|
}
|
|
|
|
func TestResolveAdapter_NotFound(t *testing.T) {
|
|
reg := adapters.NewRegistry()
|
|
r := New(reg, zap.NewNop())
|
|
|
|
req := runtime.RunRequest{
|
|
RunID: "run-1",
|
|
Adapter: "nonexistent",
|
|
Target: "codex",
|
|
}
|
|
|
|
_, _, err := r.ResolveAdapter(context.Background(), req)
|
|
if err == nil {
|
|
t.Fatal("expected error for unregistered adapter")
|
|
}
|
|
if !strings.Contains(err.Error(), "not found") {
|
|
t.Fatalf("expected 'not found' in error, got %v", err)
|
|
}
|
|
}
|