Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/app/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func BuildRuntime(ctx context.Context, opts BootstrapOptions) (RuntimeBundle, er
providerRegistry,
contextBuilder,
)
runtimeSvc.SetSessionAssetStore(sessionStore)
runtimeSvc.SetSkillsRegistry(buildSkillsRegistry(ctx, loader.BaseDir()))
runtimeSvc.SetAutoCompactThresholdResolver(runtimeAutoCompactThresholdResolverFunc(
func(ctx context.Context, cfg config.Config) (int, error) {
Expand Down
41 changes: 35 additions & 6 deletions internal/config/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1050,9 +1050,13 @@ func TestLoadCustomProvidersReadDirAndStatErrors(t *testing.T) {
t.Fatalf("WriteFile() error = %v", err)
}

if _, err := loadCustomProviders(baseDir); err == nil {
_, err := loadCustomProviders(baseDir)
if err == nil {
t.Fatal("expected read providers dir error")
}
if !strings.Contains(err.Error(), "read providers dir") {
t.Fatalf("expected read providers dir error, got %v", err)
}
})

t.Run("provider yaml stat error", func(t *testing.T) {
Expand All @@ -1061,17 +1065,42 @@ func TestLoadCustomProvidersReadDirAndStatErrors(t *testing.T) {
if err := os.MkdirAll(providerDir, 0o755); err != nil {
t.Fatalf("MkdirAll() error = %v", err)
}
if err := os.Chmod(providerDir, 0o000); err != nil {
t.Fatalf("Chmod() error = %v", err)
// Windows 上 chmod(000) 不一定阻断访问,这里改为稳定的“provider.yaml 是目录”场景触发读取错误。
if err := os.MkdirAll(filepath.Join(providerDir, customProviderConfigName), 0o755); err != nil {
t.Fatalf("MkdirAll(provider.yaml dir) error = %v", err)
}
defer func() { _ = os.Chmod(providerDir, 0o755) }()

if _, err := loadCustomProviders(baseDir); err == nil {
t.Fatal("expected stat error")
_, err := loadCustomProviders(baseDir)
if err == nil {
t.Fatal("expected custom provider read error")
}
if !strings.Contains(err.Error(), "read") {
t.Fatalf("expected read error, got %v", err)
}
})
}

func TestLoadCustomProvidersReturnsEmptyWhenProvidersDirMissing(t *testing.T) {
t.Parallel()

baseDir := t.TempDir()
providersPath := filepath.Join(baseDir, providersDirName)
if _, err := os.Stat(providersPath); !os.IsNotExist(err) {
t.Fatalf("expected providers dir to be missing, got %v", err)
}

providers, err := loadCustomProviders(baseDir)
if err != nil {
t.Fatalf("loadCustomProviders() error = %v", err)
}
if len(providers) != 0 {
t.Fatalf("expected no custom providers, got %d", len(providers))
}
if _, err := os.Stat(providersPath); !os.IsNotExist(err) {
t.Fatalf("expected providers dir to remain missing, got %v", err)
}
}

func TestLoadCustomProviderReadErrors(t *testing.T) {
t.Run("missing provider yaml", func(t *testing.T) {
providerDir := t.TempDir()
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/openaicompat/chatcompletions/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func New(cfg provider.RuntimeConfig, client *http.Client) (*Provider, error) {
// Generate 发起 SSE 流式生成请求。
// 流中途断连或协议错误时直接返回错误,由上层调用方决定重试策略。
func (p *Provider) Generate(ctx context.Context, req providertypes.GenerateRequest, events chan<- providertypes.StreamEvent) error {
payload, err := BuildRequest(p.cfg, req)
payload, err := BuildRequest(ctx, p.cfg, req)
if err != nil {
return err
}
Expand Down
Loading
Loading