Make Pipelines Docker-only with OpenCode and Pi

Install current verified harness releases inside Docker, preserve persistent accounts and settings, and provide separate interactive and pipeline model defaults with terminal onboarding and fuzzy pickers.

Add Docker-aware authoring transport, Pi stage execution, bounded workflow controls, reliable final-result readback and usage settlement, and finite short-lived CLI pipe draining. Keep dated installation evidence and packaged authoring guidance consistent.

Verified with a real Docker installation, both harness stages and interactive authors, the built-in plan/implement/review starter, independent host race/vet checks, installer tests, and packaged skill tests. Generated release receipts stay ignored in clean checkouts.
This commit is contained in:
2026-10-11 23:00:25 +01:00
parent c42a19f7d3
commit 05ae530442
131 changed files with 9297 additions and 355 deletions
+111
View File
@@ -0,0 +1,111 @@
package opencode
import (
"context"
"errors"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
)
func writeFixture(t *testing.T, script string) string {
t.Helper()
path := filepath.Join(t.TempDir(), "opencode")
if err := os.WriteFile(path, []byte(script), 0700); err != nil {
t.Fatal(err)
}
return path
}
func waitForFile(t *testing.T, path string, watchdog time.Duration) {
t.Helper()
deadline := time.Now().Add(watchdog)
for {
if _, err := os.Stat(path); err == nil {
return
}
if time.Now().After(deadline) {
t.Fatal("fixture marker never appeared")
}
time.Sleep(5 * time.Millisecond)
}
}
func TestDetectReadsAdvertisedInterface(t *testing.T) {
cases := map[string]string{
"v2": "#!/bin/sh\necho 'opencode api --help'\n",
"v1": "#!/bin/sh\necho 'opencode serve --help'\n",
}
for want, script := range cases {
backend, err := Detect(context.Background(), writeFixture(t, script))
if err != nil || backend != want {
t.Fatalf("Detect = %q, %v; want %q", backend, err, want)
}
}
}
func TestDetectFailsWhenDescendantHoldsOutput(t *testing.T) {
// A valid api line is printed, but the parent exits 0 while a descendant
// still holds the combined-output pipe: Detect must fail rather than parse
// the partial advertisement.
script := "#!/bin/sh\necho 'opencode api --help'\n( sleep 4 ) &\nexit 0\n"
backend, err := Detect(context.Background(), writeFixture(t, script))
if err == nil || backend != "" {
t.Fatalf("partial output after ErrWaitDelay must not be parsed, got %q, %v", backend, err)
}
if !errors.Is(err, exec.ErrWaitDelay) {
t.Fatalf("expected ErrWaitDelay identity, got %v", err)
}
}
func TestDetectReturnsContextCancellation(t *testing.T) {
marker := filepath.Join(t.TempDir(), "detect-started")
t.Setenv("PIPELINES_TEST_STARTED", marker)
script := "#!/bin/sh\nprintf started > \"$PIPELINES_TEST_STARTED\"\nsleep 5\n"
bin := writeFixture(t, script)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
done := make(chan error, 1)
go func() {
_, err := Detect(ctx, bin)
done <- err
}()
waitForFile(t, marker, 2*time.Second)
start := time.Now()
cancel()
select {
case err := <-done:
if !errors.Is(err, context.Canceled) {
t.Fatalf("wanted context cancellation, got %v", err)
}
if elapsed := time.Since(start); elapsed > time.Second {
t.Fatalf("Detect waited %s for the descendant output pipes", elapsed)
}
case <-time.After(3 * time.Second):
t.Fatal("Detect cancellation watchdog expired")
}
}
func TestMessagesExportWaitDelayIsNotSuccess(t *testing.T) {
export := `{"info":{"id":"ses_old"},"messages":[{"info":{"role":"assistant"}}]}`
bin := writeFixture(t, "#!/bin/sh\n[ \"$1\" = export ] || exit 8\necho '"+export+"'\n( sleep 4 ) &\nexit 0\n")
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(400)
w.Write([]byte(`{"name":"BadRequest","data":{"message":"Expected OutputFormatJsonSchema at info.format"}}`))
}))
defer server.Close()
c := &Connection{Backend: "v1", URL: server.URL, Executable: bin}
data, err := c.Messages(context.Background(), "ses_old")
if err == nil || !errors.Is(err, exec.ErrWaitDelay) {
t.Fatalf("descendant-held export pipes must fail with ErrWaitDelay, got %v", err)
}
if strings.Contains(string(data), "messages") {
t.Fatalf("partial exported JSON must not be returned as success: %s", data)
}
}