b655278674
Stages now run on a detached Pipelines-owned opencode serve started with OPENCODE_CONFIG_CONTENT carrying stage tool_output (16384 bytes / 400 lines) and compaction.auto defaults, configurable through PIPELINES_OPENCODE_STAGE_*. Chats keep their existing service and configuration; a server-spawned chat serve can take PIPELINES_OPENCODE_CHAT_CONFIG. The service shares the user's OpenCode config, credentials and session database, keeps a stable private registration so retained references (recovery, interrupt, export) stay valid, revives on the same port after a crash, replaces itself when idle after a settings change, and is stopped on shutdown only when idle. PIPELINES_OPENCODE_STAGE_SERVICE=shared restores the previous behaviour.
70 lines
2.6 KiB
Go
70 lines
2.6 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"git.a-wan.net/alan/pipelines/internal/cli"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestProviderCheckExecutesGenerationAndReportsFailures(t *testing.T) {
|
|
fakeNativeService(t)
|
|
// Isolate harness settings so an unrelated developer profile cannot route the
|
|
// native check through Docker.
|
|
t.Setenv("PIPELINES_HARNESS_CONFIG", filepath.Join(t.TempDir(), "harnesses.json"))
|
|
for _, fail := range []bool{false, true} {
|
|
bin := filepath.Join(t.TempDir(), "opencode")
|
|
script := `#!/bin/sh
|
|
case "$*" in
|
|
*--help*) echo 'api';;
|
|
*'/api/session/ses_check/prompt'*) ` + map[bool]string{true: `echo '{"_tag":"UnauthorizedError","message":"expired provider credentials","token":"private-token"}'; exit 7`, false: `echo '{}'`}[fail] + `;;
|
|
*'/api/session/ses_check/message?'*) echo '{"data":[{"finish":"stop","content":[{"type":"text","text":"PIPELINES_PROVIDER_OK"}]}]}';;
|
|
*'/api/session/ses_check/interrupt'*) echo '{}';;
|
|
*'/api/session/active'*) echo '{"data":{}}';;
|
|
*'/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 fakeNativeService(t *testing.T) {
|
|
t.Helper()
|
|
t.Setenv("HOME", t.TempDir())
|
|
state := t.TempDir()
|
|
t.Setenv("XDG_STATE_HOME", state)
|
|
t.Setenv("PIPELINES_OPENCODE_STAGE_SERVICE", "shared") // fixture models the shared CLI-managed service
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
if err := os.Mkdir(filepath.Join(state, "opencode"), 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(state, "opencode", "service.json"), []byte(`{"url":"http://127.0.0.1:1","password":"fixture-password"}`), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|