Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,19 @@ func TestContentModerationRuntimeSnapshotRefreshFailureKeepsStaleConfig(t *testi
SettingKeyRiskControlEnabled: "true",
SettingKeyContentModerationConfig: runtimeCacheTestConfig(t, "blocked"),
}}
svc := runtimeCacheTestService(repo, time.Nanosecond)
svc := runtimeCacheTestService(repo, time.Minute)
input := runtimeCacheTestInput("blocked")

decision, err := svc.Check(context.Background(), input)
require.NoError(t, err)
require.True(t, decision.Blocked)

current := svc.runtimeSnapshot.Load()
require.NotNil(t, current)
expired := *current
expired.loadedAt = time.Now().Add(-2 * time.Minute)
svc.runtimeSnapshot.Store(&expired)

repo.failMultiple(errors.New("database unavailable"))
decision, err = svc.Check(context.Background(), input)
require.NoError(t, err)
Expand Down
10 changes: 9 additions & 1 deletion backend/internal/service/plugin_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ func (i *PluginPackageInstaller) Install(ctx context.Context, reader io.Reader,
if err != nil {
return nil, fmt.Errorf("插件包不是有效的 ZIP: %w", err)
}
defer func() { _ = archive.Close() }()
defer func() {
if archive != nil {
_ = archive.Close()
}
}()
manifest, _, signatureStatus, err := i.inspectArchive(&archive.Reader)
if err != nil {
return nil, err
Expand Down Expand Up @@ -137,6 +141,10 @@ func (i *PluginPackageInstaller) Install(ctx context.Context, reader io.Reader,
if err := i.extractArchive(ctx, &archive.Reader, manifest, extractPath); err != nil {
return nil, err
}
if err := archive.Close(); err != nil {
return nil, fmt.Errorf("关闭插件归档: %w", err)
}
archive = nil
if err := os.Rename(extractPath, installPath); err != nil {
return nil, fmt.Errorf("提交插件安装目录: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion backend/internal/service/plugin_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"encoding/json"
"os"
"path/filepath"
"runtime"
"testing"

"github.com/Wei-Shaw/sub2api/internal/config"
Expand All @@ -33,7 +34,10 @@ func TestPluginPackageInstallerInstallUnsignedDevelopmentPackage(t *testing.T) {
assert.FileExists(t, installation.ArtifactPath)
info, statErr := os.Stat(installation.BinaryPath)
require.NoError(t, statErr)
assert.NotZero(t, info.Mode()&0o100)
assert.True(t, info.Mode().IsRegular())
if runtime.GOOS != "windows" {
assert.NotZero(t, info.Mode()&0o100)
}
assert.Contains(t, installation.InstallPath, filepath.Join("installed", "com.example.openai-transport"))
}

Expand Down
Loading