Validate providers and retain complete run debugging context
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"git.a-wan.net/alan/pipelines/internal/cli"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProviderCheckExecutesGenerationAndReportsFailures(t *testing.T) {
|
||||
for _, fail := range []bool{false, true} {
|
||||
bin := filepath.Join(t.TempDir(), "opencode")
|
||||
script := `#!/bin/sh
|
||||
case "$*" in
|
||||
*--help*) echo 'api';;
|
||||
*'/api/session/ses_check/generate'*) ` + map[bool]string{true: `echo '{"_tag":"UnauthorizedError","message":"expired provider credentials","token":"private-token"}'; exit 7`, false: `echo '{"data":{"text":"PIPELINES_PROVIDER_OK"}}'`}[fail] + `;;
|
||||
*'/api/session/ses_check/interrupt'*) echo '{}';;
|
||||
*'/api/session'*) echo '{"data":{"id":"ses_check"}}';;
|
||||
*) exit 9;;
|
||||
esac
|
||||
`
|
||||
if err := os.WriteFile(bin, []byte(script), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("PIPELINES_OPENCODE", bin)
|
||||
var out, stderr bytes.Buffer
|
||||
app := cli.App{Out: &out, Err: &stderr, In: strings.NewReader("")}
|
||||
err := app.Run(context.Background(), []string{"provider-check", "--model", "fixture/test", "--json", "--yes"})
|
||||
if (err != nil) != fail || !strings.Contains(out.String(), "ses_check") {
|
||||
t.Fatal(err, out.String())
|
||||
}
|
||||
if fail && (!strings.Contains(out.String(), "expired provider credentials") || strings.Contains(out.String(), "private-token")) {
|
||||
t.Fatal(out.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderCheckDeclineDoesNotExecute(t *testing.T) {
|
||||
t.Setenv("PIPELINES_OPENCODE", "/does-not-exist")
|
||||
var out bytes.Buffer
|
||||
err := (cli.App{Out: &out, Err: &out, In: strings.NewReader("n\n")}).Run(context.Background(), []string{"provider-check", "--model", "fixture/test"})
|
||||
if err == nil || strings.Contains(err.Error(), "OpenCode") {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user