fix(opencode): handle signature writer errors

This commit is contained in:
Mr.QiuW committed 2026-04-09 01:18:10 +08:00
1 parent 1641c42269
commit adeff4ef8d
2 files changed
+44 -12

No files matched your search

+17
View File
@@ -3,6 +3,7 @@ package opencode
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
@@ -14,6 +15,12 @@ import (
"github.com/chenhg5/cc-connect/core"
)
type errWriter struct{}
func (errWriter) Write(_ []byte) (int, error) {
return 0, errors.New("write failed")
}
// writeFakeModelsBin writes a temporary shell script that acts as a fake CLI.
// When invoked with "models", it prints lines to stdout.
// When exitCode != 0, the script exits immediately with that code.
@@ -40,6 +47,16 @@ func writeFakeModelsBin(t *testing.T, lines []string, exitCode int) string {
return name
}
func TestWriteProviderSignaturePart_PropagatesWriterError(t *testing.T) {
err := writeProviderSignaturePart(errWriter{}, "name", "value")
if err == nil {
t.Fatal("writeProviderSignaturePart() error = nil, want write failure")
}
if !strings.Contains(err.Error(), "write failed") {
t.Fatalf("writeProviderSignaturePart() error = %v, want write failure", err)
}
}
func writePersistentModelCache(t *testing.T, cachePath string, models []core.ModelOption, updatedAt time.Time) string {
t.Helper()