Move harness profiles between host and Docker and stop silent draft retargeting
Native installs left Docker-era harness profiles in harnesses.json, so every authoring launch failed trying to reach a Docker service, and a retained draft bound to the old Docker server was silently projected onto the configured one. - harness: add Profile.Mode and VerifyDockerLink as the single mode/verification helpers. `harness setup --host` configures or converts a host profile and clears docker_directory; reconfiguring a Docker-linked profile re-verifies the recorded directory still owns compose.yaml and fails naming it instead of saving a link that cannot launch. Setup's summary and `harness list` (via the new List/ListView shape) report the resulting mode and, for Docker, the directory, without changing the stored Config schema. - setup-native.py: after build/install-skill it writes host (no docker_directory) profiles for the detected harnesses, defaulting to the detected OpenCode profile rather than a stale pi default, taking models from --model or the existing valid profile and never inventing one; it clears a stale Docker link and preserves unrelated keys/profiles. Detection-only: no harness install, upgrade or download. - draft: add Draft.Resolve, the shared mismatch helper, which projects a draft onto the configured server and returns a dual-URL notice. CLI validate/submit and the TUI draft browser use it so a foreign draft is never silently retargeted; the TUI pre-wraps the notice to the panel width. - Tests cover the Docker->host and host->host transitions, the missing-directory failure, installer write/migration (Python), and the CLI/TUI notice, using the real config file path in a temp dir. - Update help text, README, docs and the packaged authoring skill reference to describe host as the default and the Docker-linked case.
This commit is contained in:
@@ -65,7 +65,10 @@ the last verified Dockerfile fallback pins); they never guess, fall back to a ho
|
||||
runtime or install a stale pin.
|
||||
Without a Docker installation, `./install --opencode`/`--pi` stop and require an
|
||||
existing Docker setup; the native installation reuses the host OpenCode
|
||||
configuration. Container and host credentials and accounts remain independent and
|
||||
configuration, writes **host** (non-Docker) profiles for the harnesses it detects
|
||||
into XDG config home's `pipelines/harnesses.json`, and clears a stale Docker link
|
||||
so a Docker-era profile is not left Docker-linked. It never installs, upgrades or
|
||||
downloads a harness. Container and host credentials and accounts remain independent and
|
||||
are reused on reinstall/reconfigure. `./install` installs natively by default
|
||||
(`--native` is equivalent); explicit `./install --docker` selects the Docker
|
||||
server + ntfy installation.
|
||||
@@ -74,7 +77,14 @@ login. Existing setup can configure either harness independently. Pi setup does
|
||||
not run a generation check; `provider-check --harness pi --model PROVIDER/MODEL`
|
||||
is a separate confirmed, potentially chargeable check.
|
||||
Profiles live in XDG config home's `pipelines/harnesses.json`, store preferences
|
||||
only, and preserve unrelated configuration. Harness CLI setup/default commands
|
||||
only, and preserve unrelated configuration. A profile launches a native host
|
||||
harness unless it records a Docker checkout directory, in which case it launches
|
||||
through that installation's Compose service. `harness setup <opencode|pi> --host`
|
||||
configures or converts a host profile and clears any Docker link; without
|
||||
`--host`, reconfiguring a Docker-linked profile re-verifies that the recorded
|
||||
directory still has `compose.yaml` and fails naming it rather than saving a link
|
||||
that cannot launch. Setup's summary and `harness list` report the resulting mode
|
||||
(and, for Docker, the directory). Harness CLI setup/default commands
|
||||
always configure the local execution user, not a remote `--url` server.
|
||||
OpenCode interactive launch uses
|
||||
`mini --model`: verified V2 full CLI lacks a model flag. Pi uses its CLI with the
|
||||
|
||||
+16
-1
@@ -561,7 +561,14 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
}
|
||||
origin := d
|
||||
crossServer := d.Server != "" && d.Server != o.url
|
||||
d = d.ForServer(o.url)
|
||||
d, notice := d.Resolve(o.url)
|
||||
if notice != "" {
|
||||
if o.json {
|
||||
fmt.Fprintln(a.Err, notice)
|
||||
} else {
|
||||
fmt.Fprintln(a.Out, notice)
|
||||
}
|
||||
}
|
||||
name := o.name
|
||||
if name == "" {
|
||||
name = d.Name
|
||||
@@ -586,6 +593,14 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
if err := a.confirmAction("Publish "+name+" to "+o.url+" as an immutable version? Included schedules activate on acceptance.", o.yes); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if d, metaErr := draft.Load(path); metaErr == nil {
|
||||
if _, notice := d.Resolve(o.url); notice != "" {
|
||||
if o.json {
|
||||
fmt.Fprintln(a.Err, notice)
|
||||
} else {
|
||||
fmt.Fprintln(a.Out, notice)
|
||||
}
|
||||
}
|
||||
}
|
||||
r, err := call(request)
|
||||
if err != nil {
|
||||
|
||||
@@ -47,7 +47,7 @@ var notes = map[string]string{
|
||||
}
|
||||
|
||||
var serviceHelp = map[string]string{
|
||||
"harness": "pipelines harness launches the configured default. harness setup opencode|pi offers fuzzy model selection; --login reopens login, --default chooses the default harness, --model and --pipeline-model set separate defaults explicitly. harness list prints non-secret settings. Only configured harnesses are offered.",
|
||||
"harness": "pipelines harness launches the configured default. harness setup opencode|pi offers fuzzy model selection; --host configures a native host harness and clears any Docker link, --login reopens login, --default chooses the default harness, --model and --pipeline-model set separate defaults explicitly. harness list prints non-secret settings, including each profile's launch mode. Only configured harnesses are offered.",
|
||||
"skill": "pipelines skill install installs/updates the bundled global OpenCode skill without changing login/config or user-modified skills. ./install includes this step.",
|
||||
"service": "Configure per-user OS autostart: pipelines service enable. Runs use the directory you invoke pipelines run from. Use --print to preview, service status to inspect, and service disable before uninstalling. Linux uses systemd; macOS uses launchd. No sudo.",
|
||||
"serve": "Run the native server in the foreground. Its flags are documented by pipelines serve --help. Installation never starts it automatically.",
|
||||
|
||||
+20
-6
@@ -17,11 +17,11 @@ import (
|
||||
|
||||
func (a App) harness(ctx context.Context, args []string) error {
|
||||
if len(args) > 0 && args[0] == "list" {
|
||||
c, err := harness.Load()
|
||||
list, err := harness.List()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return a.output(c)
|
||||
return a.output(list)
|
||||
}
|
||||
if len(args) > 0 && args[0] == "default" {
|
||||
c, err := harness.Load()
|
||||
@@ -66,7 +66,7 @@ func (a App) harness(ctx context.Context, args []string) error {
|
||||
if err != nil || *directory == "" {
|
||||
return fmt.Errorf("Docker installation directory is required")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(absolute, "compose.yaml")); err != nil {
|
||||
if err := harness.VerifyDockerLink(absolute); err != nil {
|
||||
return err
|
||||
}
|
||||
c, err := harness.Load()
|
||||
@@ -88,12 +88,13 @@ func (a App) harness(ctx context.Context, args []string) error {
|
||||
executable := f.String("executable", "", "Harness executable (defaults to its name)")
|
||||
login := f.Bool("login", false, "Open the harness login without deleting credentials")
|
||||
makeDefault := f.Bool("default", false, "Use this harness by default")
|
||||
host := f.Bool("host", false, "Configure a native host harness and clear any Docker link")
|
||||
versions := f.String("versions", "", "Verified Docker harness versions to display (from the in-image probe)")
|
||||
if err := parse(f, args[1:]); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(f.Args()) > 1 {
|
||||
return fmt.Errorf("usage: pipelines harness setup [opencode|pi] [--login] [--model P/M] [--pipeline-model P/M] [--default]")
|
||||
return fmt.Errorf("usage: pipelines harness setup [opencode|pi] [--login] [--host] [--model P/M] [--pipeline-model P/M] [--default]")
|
||||
}
|
||||
name := ""
|
||||
if len(f.Args()) == 1 {
|
||||
@@ -131,9 +132,19 @@ func (a App) harness(ctx context.Context, args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
existing, exists := c.Profiles[name]
|
||||
// A profile can move between Docker and host. Without an explicit
|
||||
// --host selection a Docker-linked profile is only reconfigured when its
|
||||
// recorded installation is still verifiable; otherwise setup fails
|
||||
// naming the directory instead of saving a link that cannot launch.
|
||||
if !*host && exists && existing.DockerDirectory != "" {
|
||||
if err := harness.VerifyDockerLink(existing.DockerDirectory); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
onboarding := harness.NewOnboarding(a.Out)
|
||||
action := "Configure"
|
||||
if _, ok := c.Profiles[name]; ok {
|
||||
if exists {
|
||||
action = "Reconfigure"
|
||||
}
|
||||
onboarding.Header(name, action)
|
||||
@@ -211,6 +222,9 @@ func (a App) harness(ctx context.Context, args []string) error {
|
||||
}
|
||||
profile := c.Profiles[name]
|
||||
profile.Executable, profile.Model, profile.PipelineModel = *executable, *model, *pipelineModel
|
||||
if *host {
|
||||
profile.DockerDirectory = ""
|
||||
}
|
||||
c.Profiles[name] = profile
|
||||
if *makeDefault || c.Default == "" {
|
||||
c.Default = name
|
||||
@@ -218,7 +232,7 @@ func (a App) harness(ctx context.Context, args []string) error {
|
||||
if err = harness.Save(c); err != nil {
|
||||
return err
|
||||
}
|
||||
onboarding.Summary(name, *model, *pipelineModel, c.Default)
|
||||
onboarding.Summary(name, *model, *pipelineModel, c.Default, c.Profiles[name].Mode())
|
||||
return nil
|
||||
}
|
||||
name := ""
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// fixtureOpencode writes a fake opencode executable that answers the bounded
|
||||
// model-discovery calls harness setup makes, so setup can run without a real
|
||||
// harness or any network access.
|
||||
func fixtureOpencode(t *testing.T, root string) string {
|
||||
t.Helper()
|
||||
script := filepath.Join(root, "opencode")
|
||||
body := "#!/bin/sh\ncase \"$*\" in\n'api get /api/integration') echo '{}' ;;\nmodels) printf '%s\\n' fixture/harness fixture/stages ;;\n'auth list --format json') echo '[{\"id\":\"fixture\",\"connections\":[{}]}]' ;;\n*) exit 91;;\nesac\n"
|
||||
if err := os.WriteFile(script, []byte(body), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return script
|
||||
}
|
||||
|
||||
func writeHarnessConfig(t *testing.T, path, body string) {
|
||||
t.Helper()
|
||||
if err := os.WriteFile(path, []byte(body), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestHarnessSetupHostModeClearsDockerLinkDrivesTheRealConfigFile covers the
|
||||
// Docker-linked -> host transition and host -> host idempotence by reading the
|
||||
// saved JSON, not a private helper.
|
||||
func TestHarnessSetupHostModeClearsDockerLinkDrivesTheRealConfigFile(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
configPath := filepath.Join(root, "harnesses.json")
|
||||
t.Setenv("PIPELINES_HARNESS_CONFIG", configPath)
|
||||
script := fixtureOpencode(t, root)
|
||||
writeHarnessConfig(t, configPath, `{"default":"opencode","profiles":{"opencode":{"docker_directory":"/checkout","executable":"opencode","model":"fixture/harness","pipeline_model":"fixture/stages"}}}`)
|
||||
|
||||
var out bytes.Buffer
|
||||
app := App{In: bytes.NewBuffer(nil), Out: &out, Err: &out}
|
||||
if err := app.Run(context.Background(), []string{"harness", "setup", "opencode", "--host", "--executable", script, "--model", "fixture/harness", "--pipeline-model", "fixture/stages"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
saved, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(saved), "docker_directory") {
|
||||
t.Fatalf("host setup kept a Docker link:\n%s", saved)
|
||||
}
|
||||
if text := out.String(); !strings.Contains(text, "Launch mode:") || !strings.Contains(text, "host") {
|
||||
t.Fatalf("summary did not report host mode:\n%s", text)
|
||||
}
|
||||
|
||||
// host -> host leaves it absent and unchanged in mode.
|
||||
if err := app.Run(context.Background(), []string{"harness", "setup", "opencode", "--host", "--executable", script, "--model", "fixture/harness", "--pipeline-model", "fixture/stages"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
again, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(string(again), "docker_directory") {
|
||||
t.Fatalf("host -> host reintroduced a Docker link:\n%s", again)
|
||||
}
|
||||
}
|
||||
|
||||
// TestHarnessSetupReverifiesDockerLinkBeforeSaving fails a reconfigure whose
|
||||
// recorded installation no longer has compose.yaml, names the directory, and
|
||||
// leaves the file byte-identical.
|
||||
func TestHarnessSetupReverifiesDockerLinkBeforeSaving(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
configPath := filepath.Join(root, "harnesses.json")
|
||||
t.Setenv("PIPELINES_HARNESS_CONFIG", configPath)
|
||||
script := fixtureOpencode(t, root)
|
||||
// The directory exists but has no compose.yaml, so the link is unusable.
|
||||
checkout := filepath.Join(root, "checkout")
|
||||
if err := os.Mkdir(checkout, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeHarnessConfig(t, configPath, `{"default":"opencode","profiles":{"opencode":{"docker_directory":"`+checkout+`","executable":"opencode","model":"fixture/harness","pipeline_model":"fixture/stages"}}}`)
|
||||
before, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
app := App{In: bytes.NewBuffer(nil), Out: &out, Err: &out}
|
||||
err = app.Run(context.Background(), []string{"harness", "setup", "opencode", "--executable", script, "--model", "fixture/harness", "--pipeline-model", "fixture/stages"})
|
||||
if err == nil {
|
||||
t.Fatal("setup reported success for an unverifiable Docker link")
|
||||
}
|
||||
if !strings.Contains(err.Error(), checkout) {
|
||||
t.Fatalf("error does not name the directory: %v", err)
|
||||
}
|
||||
after, readErr := os.ReadFile(configPath)
|
||||
if readErr != nil {
|
||||
t.Fatal(readErr)
|
||||
}
|
||||
if !bytes.Equal(before, after) {
|
||||
t.Fatalf("failed setup rewrote the config:\nbefore %s\nafter %s", before, after)
|
||||
}
|
||||
}
|
||||
|
||||
// TestHarnessSetupKeepsVerifiedDockerLink confirms a still-verifiable Docker
|
||||
// installation is preserved and its directory reported.
|
||||
func TestHarnessSetupKeepsVerifiedDockerLink(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
configPath := filepath.Join(root, "harnesses.json")
|
||||
t.Setenv("PIPELINES_HARNESS_CONFIG", configPath)
|
||||
script := fixtureOpencode(t, root)
|
||||
checkout := filepath.Join(root, "checkout")
|
||||
if err := os.Mkdir(checkout, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(checkout, "compose.yaml"), []byte("services: {}\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeHarnessConfig(t, configPath, `{"default":"opencode","profiles":{"opencode":{"docker_directory":"`+checkout+`","executable":"opencode","model":"fixture/harness","pipeline_model":"fixture/stages"}}}`)
|
||||
|
||||
var out bytes.Buffer
|
||||
app := App{In: bytes.NewBuffer(nil), Out: &out, Err: &out}
|
||||
if err := app.Run(context.Background(), []string{"harness", "setup", "opencode", "--executable", script, "--model", "fixture/harness", "--pipeline-model", "fixture/stages"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
saved, err := os.ReadFile(configPath)
|
||||
if err != nil || !strings.Contains(string(saved), checkout) {
|
||||
t.Fatalf("verified Docker link was not preserved: %s %v", saved, err)
|
||||
}
|
||||
if text := out.String(); !strings.Contains(text, "Docker-linked") || !strings.Contains(text, checkout) {
|
||||
t.Fatalf("summary did not report Docker mode and directory:\n%s", text)
|
||||
}
|
||||
}
|
||||
|
||||
// TestHarnessListReportsModeAndKeepsModelFields keeps the JSON compatible with
|
||||
// scripts/setup-docker.py's link_host parsing (default, model, pipeline_model)
|
||||
// while exposing an explicit per-profile mode.
|
||||
func TestHarnessListReportsModeAndKeepsModelFields(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
configPath := filepath.Join(root, "harnesses.json")
|
||||
t.Setenv("PIPELINES_HARNESS_CONFIG", configPath)
|
||||
writeHarnessConfig(t, configPath, `{"default":"opencode","profiles":{"opencode":{"docker_directory":"/checkout","executable":"opencode","model":"fixture/harness","pipeline_model":"fixture/stages"},"pi":{"executable":"pi","model":"provider/interactive","pipeline_model":"provider/stages"}}}`)
|
||||
var out bytes.Buffer
|
||||
app := App{In: bytes.NewBuffer(nil), Out: &out, Err: &out}
|
||||
if err := app.Run(context.Background(), []string{"harness", "list", "--json"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var view struct {
|
||||
Default string `json:"default"`
|
||||
Profiles map[string]struct {
|
||||
Model string `json:"model"`
|
||||
PipelineModel string `json:"pipeline_model"`
|
||||
Mode string `json:"mode"`
|
||||
DockerDirectory string `json:"docker_directory"`
|
||||
} `json:"profiles"`
|
||||
}
|
||||
if err := json.Unmarshal(out.Bytes(), &view); err != nil {
|
||||
t.Fatalf("harness list --json is not valid JSON: %v\n%s", err, out.String())
|
||||
}
|
||||
if view.Default != "opencode" {
|
||||
t.Fatalf("default = %q", view.Default)
|
||||
}
|
||||
opencode := view.Profiles["opencode"]
|
||||
if opencode.Model != "fixture/harness" || opencode.PipelineModel != "fixture/stages" || opencode.Mode != "Docker-linked (/checkout)" {
|
||||
t.Fatalf("opencode profile changed shape: %+v", opencode)
|
||||
}
|
||||
pi := view.Profiles["pi"]
|
||||
if pi.Mode != "host" || pi.DockerDirectory != "" || pi.Model != "provider/interactive" {
|
||||
t.Fatalf("pi profile did not report host mode: %+v", pi)
|
||||
}
|
||||
}
|
||||
@@ -60,9 +60,9 @@ Examples:
|
||||
pipelines submit /path/to/draft.md
|
||||
pipelines run "bug fix" "Fix the layout" --json
|
||||
|
||||
Draft-first: the configured harness (Pi/OpenCode, Docker-linked by default) edits a
|
||||
private draft; non-Docker installs use a native harness and nvim remains a client
|
||||
editor. Nothing is published automatically.
|
||||
Draft-first: the configured harness (Pi/OpenCode; host by default, or Docker-linked
|
||||
when a checkout is linked) edits a private draft; nvim remains a client editor.
|
||||
Nothing is published automatically.
|
||||
Every submission is validated server-side. Submission activates any schedules.
|
||||
JSON mode never launches an editor or picker; supply explicit arguments.
|
||||
`
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
@@ -80,3 +81,42 @@ func TestCLIEditDraftCanPublishToAnotherServerWithoutOriginVersion(t *testing.T)
|
||||
t.Fatal("publication changed retained source", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCLIForeignDraftNoticeNamesBothServersAndTargetsConfigured covers the stale
|
||||
// 8081-draft case: validate and submit emit a dual-URL notice and only the
|
||||
// configured server receives the submission, while the retained draft is not
|
||||
// rewritten.
|
||||
func TestCLIForeignDraftNoticeNamesBothServersAndTargetsConfigured(t *testing.T) {
|
||||
run, destination, configured := setup(t)
|
||||
foreign := "ws://127.0.0.1:8081/connect"
|
||||
d, err := draft.Create("mismatch", pipeline.Template([]string{"worker"}, true), foreign, true, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
metadata, err := os.ReadFile(d.Path + ".json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
validated, err := run("validate", d.Path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(validated, foreign) || !strings.Contains(validated, configured) {
|
||||
t.Fatalf("validate notice did not name both servers:\n%s", validated)
|
||||
}
|
||||
submitted, err := run("submit", d.Path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(submitted, foreign) || !strings.Contains(submitted, configured) {
|
||||
t.Fatalf("submit notice did not name both servers:\n%s", submitted)
|
||||
}
|
||||
items, err := destination.List(context.Background())
|
||||
if err != nil || len(items) != 1 || items[0].Version != 1 {
|
||||
t.Fatalf("submission did not target the configured server: %v %v", items, err)
|
||||
}
|
||||
retained, err := os.ReadFile(d.Path + ".json")
|
||||
if err != nil || string(retained) != string(metadata) {
|
||||
t.Fatalf("foreign draft metadata was rewritten: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,22 @@ func (d Draft) ForServer(server string) Draft {
|
||||
return d
|
||||
}
|
||||
|
||||
// Resolve projects this retained draft onto the configured server and reports a
|
||||
// user-visible notice when the draft was created against a different server.
|
||||
// The projection through ForServer keeps cross-server publication create-only,
|
||||
// so the original version never leaks; the notice names both URLs so neither the
|
||||
// CLI nor the TUI silently retargets a foreign draft. The returned notice is
|
||||
// empty when the draft already matches (or records no server).
|
||||
func (d Draft) Resolve(configured string) (Draft, string) {
|
||||
resolved := d.ForServer(configured)
|
||||
if d.Server == "" || d.Server == configured {
|
||||
return resolved, ""
|
||||
}
|
||||
return resolved, fmt.Sprintf(
|
||||
"draft was created against %s but this client is configured for %s; publishing to %s as a new pipeline (version numbers do not carry over)",
|
||||
d.Server, configured, configured)
|
||||
}
|
||||
|
||||
func Directory() (string, error) {
|
||||
if dir := os.Getenv("PIPELINES_DRAFT_DIR"); dir != "" {
|
||||
return filepath.Abs(dir)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package draft
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPublicationScopeForServer(t *testing.T) {
|
||||
original := Draft{Path: "/retained/draft.md", Name: "demo", Server: "ws://origin/connect", BaseVersion: 7}
|
||||
@@ -21,3 +24,23 @@ func TestPublicationScopeForServer(t *testing.T) {
|
||||
t.Fatal("unbound legacy draft lost its version guard", bound)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveReportsForeignServerAndKeepsMatchSilent(t *testing.T) {
|
||||
configured := "ws://127.0.0.1:8080/connect"
|
||||
foreign := Draft{Name: "stale", Server: "ws://127.0.0.1:8081/connect", BaseVersion: 4}
|
||||
resolved, notice := foreign.Resolve(configured)
|
||||
if notice == "" || !strings.Contains(notice, foreign.Server) || !strings.Contains(notice, configured) {
|
||||
t.Fatalf("foreign notice did not name both servers: %q", notice)
|
||||
}
|
||||
if resolved.Server != configured || !resolved.CreateOnly || resolved.BaseVersion != 0 {
|
||||
t.Fatalf("foreign draft not projected create-only: %+v", resolved)
|
||||
}
|
||||
match := Draft{Name: "current", Server: configured, BaseVersion: 4}
|
||||
resolvedMatch, matchNotice := match.Resolve(configured)
|
||||
if matchNotice != "" || resolvedMatch.CreateOnly || resolvedMatch.BaseVersion != 4 {
|
||||
t.Fatalf("matching draft produced a notice or lost its guard: %q %+v", matchNotice, resolvedMatch)
|
||||
}
|
||||
if _, unboundNotice := (Draft{Name: "legacy"}).Resolve(configured); unboundNotice != "" {
|
||||
t.Fatalf("unbound draft produced a notice: %q", unboundNotice)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,31 @@ func Path() (string, error) {
|
||||
return filepath.Join(root, "pipelines", "harnesses.json"), nil
|
||||
}
|
||||
|
||||
// Mode returns the profile's launch mode. A profile with a recorded Docker
|
||||
// directory launches through that Compose installation; every other profile
|
||||
// launches the host executable. It is the single mode label shared by setup's
|
||||
// summary and any caller that reports where a harness runs.
|
||||
func (p Profile) Mode() string {
|
||||
if p.DockerDirectory == "" {
|
||||
return "host"
|
||||
}
|
||||
return "Docker-linked (" + p.DockerDirectory + ")"
|
||||
}
|
||||
|
||||
// VerifyDockerLink re-checks that a recorded Docker installation still owns a
|
||||
// compose.yaml, the same requirement `harness link` enforces when first
|
||||
// linking. It is the single re-verification used before a Docker-linked profile
|
||||
// is reconfigured or reported as usable, so a stale link is never silently kept.
|
||||
func VerifyDockerLink(directory string) error {
|
||||
if directory == "" {
|
||||
return fmt.Errorf("no Docker installation directory is recorded; run pipelines harness setup <opencode|pi> --host for a native harness")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(directory, "compose.yaml")); err != nil {
|
||||
return fmt.Errorf("recorded Docker installation %s is no longer usable: %w; relink with pipelines harness link <opencode|pi> --docker-directory <checkout>, or switch to a host harness with pipelines harness setup <opencode|pi> --host", directory, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidModel(value string) bool {
|
||||
provider, model, ok := strings.Cut(value, "/")
|
||||
if !ok || provider == "" || model == "" || len(value) > 501 {
|
||||
@@ -134,6 +159,34 @@ func Save(c Config) error {
|
||||
return os.Rename(file.Name(), path)
|
||||
}
|
||||
|
||||
// ListView is the JSON shape `harness list` emits. It mirrors Config and adds a
|
||||
// computed per-profile Mode so callers and scripts can read the launch mode
|
||||
// without inferring it from docker_directory. The embedded Profile keeps every
|
||||
// stored field (executable/model/pipeline_model/docker_directory) at the same
|
||||
// level, so existing consumers such as setup-docker.py's link_host are unaffected.
|
||||
type ListView struct {
|
||||
Default string `json:"default"`
|
||||
Profiles map[string]ProfileView `json:"profiles"`
|
||||
}
|
||||
|
||||
type ProfileView struct {
|
||||
Profile
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
|
||||
// List returns the configured profiles with an explicit launch mode.
|
||||
func List() (ListView, error) {
|
||||
c, err := Load()
|
||||
if err != nil {
|
||||
return ListView{}, err
|
||||
}
|
||||
view := ListView{Default: c.Default, Profiles: map[string]ProfileView{}}
|
||||
for name, p := range c.Profiles {
|
||||
view.Profiles[name] = ProfileView{Profile: p, Mode: p.Mode()}
|
||||
}
|
||||
return view, nil
|
||||
}
|
||||
|
||||
func Choices() ([]string, string, error) {
|
||||
c, err := Load()
|
||||
if err != nil {
|
||||
|
||||
@@ -59,14 +59,17 @@ func (o Onboarding) AuthHandoff() {
|
||||
}
|
||||
}
|
||||
|
||||
// Summary reports the saved choices without implying inference.
|
||||
func (o Onboarding) Summary(name, harnessModel, pipelineModel, defaultHarness string) {
|
||||
// Summary reports the saved choices without implying inference. Mode is the
|
||||
// resulting launch mode ("host" or "Docker-linked (<directory>)") so a setup run
|
||||
// always states where the harness will actually run.
|
||||
func (o Onboarding) Summary(name, harnessModel, pipelineModel, defaultHarness, mode string) {
|
||||
s := o.styles()
|
||||
fmt.Fprintln(o.out)
|
||||
fmt.Fprintln(o.out, s.title("Configuration complete"))
|
||||
fmt.Fprintf(o.out, " %s %s\n", s.muted("Interactive "+DisplayName(name)+" model:"), s.step(harnessModel))
|
||||
fmt.Fprintf(o.out, " %s %s\n", s.muted("New "+DisplayName(name)+" pipeline model:"), s.step(pipelineModel))
|
||||
fmt.Fprintf(o.out, " %s %s\n", s.muted("Default harness:"), s.step(defaultHarness))
|
||||
fmt.Fprintf(o.out, " %s %s\n", s.muted("Launch mode:"), s.step(mode))
|
||||
fmt.Fprintln(o.out, s.muted(" No inference was performed; published workflows and drafts were not rewritten."))
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ func TestOnboardingPlainOutputHasHandoffAndSummary(t *testing.T) {
|
||||
o.Header("pi", "Configure")
|
||||
o.Versions("OpenCode 2.0.26 · Pi 1.1.0 · Node 22.19.0")
|
||||
o.AuthHandoff()
|
||||
o.Summary("pi", "provider/interactive", "provider/stages", "pi")
|
||||
o.Summary("pi", "provider/interactive", "provider/stages", "pi", "host")
|
||||
text := out.String()
|
||||
if strings.Contains(text, "\x1b[") {
|
||||
t.Fatalf("non-terminal onboarding emitted ANSI: %q", text)
|
||||
|
||||
+29
-11
@@ -38,28 +38,38 @@ func (m Model) openDrafts() (tea.Model, tea.Cmd) {
|
||||
func (m *Model) loadDraftPreview() {
|
||||
m.draftTop = 0
|
||||
m.draftSource = ""
|
||||
m.draftNotice = ""
|
||||
if len(m.draftItems) == 0 {
|
||||
return
|
||||
}
|
||||
source, err := draft.Read(m.draftItems[m.draftIndex].Path)
|
||||
_, source, notice, err := m.readDraft(m.draftIndex)
|
||||
if err != nil {
|
||||
m.draftError = err.Error()
|
||||
return
|
||||
}
|
||||
m.draftSource = source
|
||||
m.draftNotice = notice
|
||||
}
|
||||
|
||||
func (m Model) selectedDraft() (draft.Draft, string, error) {
|
||||
if len(m.draftItems) == 0 {
|
||||
return draft.Draft{}, "", fmt.Errorf("no drafts")
|
||||
}
|
||||
d, err := draft.Load(m.draftItems[m.draftIndex].Path)
|
||||
// readDraft loads one retained draft's metadata and source once, projecting it
|
||||
// onto the configured server. It returns the shared dual-URL notice when the
|
||||
// draft was created against a different server so no caller silently retargets
|
||||
// a foreign draft.
|
||||
func (m *Model) readDraft(index int) (draft.Draft, string, string, error) {
|
||||
d, err := draft.Load(m.draftItems[index].Path)
|
||||
if err != nil {
|
||||
return d, "", err
|
||||
return d, "", "", err
|
||||
}
|
||||
d = d.ForServer(m.url)
|
||||
d, notice := d.Resolve(m.url)
|
||||
source, err := draft.Read(d.Path)
|
||||
return d, source, err
|
||||
return d, source, notice, err
|
||||
}
|
||||
|
||||
func (m Model) selectedDraft() (draft.Draft, string, string, error) {
|
||||
if len(m.draftItems) == 0 {
|
||||
return draft.Draft{}, "", "", fmt.Errorf("no drafts")
|
||||
}
|
||||
return m.readDraft(m.draftIndex)
|
||||
}
|
||||
|
||||
func (m Model) updateDrafts(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
@@ -123,11 +133,12 @@ func (m Model) updateDrafts(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
case "k", "up":
|
||||
m.draftTop = max(0, m.draftTop-1)
|
||||
case "enter", "e", "s", "v":
|
||||
d, source, err := m.selectedDraft()
|
||||
d, source, notice, err := m.selectedDraft()
|
||||
if err != nil {
|
||||
m.draftError = err.Error()
|
||||
return m, nil
|
||||
}
|
||||
m.draftNotice = notice
|
||||
switch msg.String() {
|
||||
case "enter", "e":
|
||||
return m.confirmMutation("Edit retained draft?", func() tea.Cmd { return editDraftMode(d.Name, source, true, d.CreateOnly, d) })
|
||||
@@ -173,7 +184,14 @@ func (m Model) draftsView(height int) string {
|
||||
if name == "" {
|
||||
name = "Unnamed draft"
|
||||
}
|
||||
lines := []string{fmt.Sprintf("Drafts · %d/%d · %s", m.draftIndex+1, len(m.draftItems), name), d.Path, fmt.Sprintf("Create-only: %t · Base version: %d", d.CreateOnly, d.BaseVersion), m.draftError, ""}
|
||||
lines := []string{fmt.Sprintf("Drafts · %d/%d · %s", m.draftIndex+1, len(m.draftItems), name), d.Path, fmt.Sprintf("Create-only: %t · Base version: %d", d.CreateOnly, d.BaseVersion)}
|
||||
if m.draftNotice != "" {
|
||||
// Pre-wrap the dual-URL notice to the panel width: fitBlock truncates a
|
||||
// single long line, so an unwrapped notice would cut off the configured
|
||||
// endpoint and the TUI would not actually name both servers.
|
||||
lines = append(lines, strings.Split(ansi.Wrap("Warning: "+m.draftNotice, max(1, m.width), ""), "\n")...)
|
||||
}
|
||||
lines = append(lines, m.draftError, "")
|
||||
source := strings.Split(m.draftSource, "\n")
|
||||
rows := max(0, height-len(lines)-1)
|
||||
top := min(m.draftTop, max(0, len(source)-rows))
|
||||
|
||||
@@ -191,3 +191,42 @@ func TestDraftBrowserAcceptsOtherServerAndKeepsUnnamedDraft(t *testing.T) {
|
||||
t.Fatal("unnamed draft submitted")
|
||||
}
|
||||
}
|
||||
|
||||
// TestDraftBrowserNoticeNamesBothServersForForeignDraft covers the stale 8081
|
||||
// draft case in the TUI: the selected foreign draft is projected onto the
|
||||
// configured server (create-only) and a notice names both endpoints instead of
|
||||
// silently retargeting it.
|
||||
func TestDraftBrowserNoticeNamesBothServersForForeignDraft(t *testing.T) {
|
||||
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
|
||||
foreign := "ws://127.0.0.1:8081/connect"
|
||||
configured := "ws://127.0.0.1:8080/connect"
|
||||
d, err := draft.Create("wrong", "source", foreign, true, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m := New(context.Background(), configured)
|
||||
updated, _ := m.openDrafts()
|
||||
m = updated.(Model)
|
||||
if !strings.Contains(m.draftNotice, foreign) || !strings.Contains(m.draftNotice, configured) {
|
||||
t.Fatalf("preview notice did not name both servers: %q", m.draftNotice)
|
||||
}
|
||||
// The notice must name both endpoints at any realistic panel width: an
|
||||
// unwrapped line is truncated by fitBlock and loses the configured URL.
|
||||
for _, width := range []int{60, 100} {
|
||||
view := m
|
||||
view.width, view.height = width, 24
|
||||
rendered := view.View()
|
||||
if !strings.Contains(rendered, foreign) || !strings.Contains(rendered, configured) {
|
||||
t.Fatalf("notice at width %d did not name both servers:\n%s", width, rendered)
|
||||
}
|
||||
}
|
||||
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'s'}})
|
||||
m = updated.(Model)
|
||||
if !m.confirmOpen || m.pendingDraft == nil || !m.pendingDraft.createOnly || m.pendingDraft.baseVersion != 0 {
|
||||
t.Fatalf("foreign draft was not projected as create-only: %+v", m.pendingDraft)
|
||||
}
|
||||
if !strings.Contains(m.draftNotice, foreign) || !strings.Contains(m.draftNotice, configured) {
|
||||
t.Fatalf("submit lost the dual-URL notice: %q", m.draftNotice)
|
||||
}
|
||||
_ = d
|
||||
}
|
||||
|
||||
+104
-104
@@ -95,110 +95,110 @@ func (k keyMap) ShortHelp() []key.Binding {
|
||||
func (k keyMap) FullHelp() [][]key.Binding { return [][]key.Binding{k.ShortHelp()} }
|
||||
|
||||
type Model struct {
|
||||
editorCheckGeneration uint64
|
||||
editorChecking bool
|
||||
statusOpen bool
|
||||
statusTop int
|
||||
statusRequest, statusError string
|
||||
systemStatus *protocol.SystemStatus
|
||||
usage *protocol.UsageStats
|
||||
draftOpen bool
|
||||
draftItems []draft.Draft
|
||||
draftIndex, draftTop int
|
||||
draftError, draftSource string
|
||||
ctx context.Context
|
||||
url string
|
||||
conn *websocket.Conn
|
||||
status string
|
||||
nextID uint64
|
||||
lines []string
|
||||
width int
|
||||
height int
|
||||
help help.Model
|
||||
keys keyMap
|
||||
pipelines []protocol.PipelineSummary
|
||||
loaded bool
|
||||
notificationEndpoints []protocol.NotificationEndpoint
|
||||
logSeen []bool
|
||||
unread int
|
||||
logOpen bool
|
||||
logTop int
|
||||
logPan int
|
||||
paletteOpen bool
|
||||
commandInput textinput.Model
|
||||
commandIndex int
|
||||
homeTop int
|
||||
searchOpen bool
|
||||
detail *protocol.PipelineDetail
|
||||
detailRequest string
|
||||
detailLoading bool
|
||||
detailError string
|
||||
pipelineTop int
|
||||
graphPan int
|
||||
versionsOpen bool
|
||||
versionIndex int
|
||||
confirmOpen bool
|
||||
actionConfirm *protocol.Message
|
||||
actionConfirmTop int
|
||||
actionApproved bool
|
||||
defaultModel string
|
||||
defaultHarness string
|
||||
editorDebugRunID int64
|
||||
mutationTitle string
|
||||
mutationCommand func() tea.Cmd
|
||||
mutationTop int
|
||||
pendingDraft *editedMsg
|
||||
draftNameInput textinput.Model
|
||||
submitID string
|
||||
submitNotice string
|
||||
stageIndex int
|
||||
stageTop int
|
||||
stageFocus bool
|
||||
stageConfigExpanded bool
|
||||
reconnecting bool
|
||||
requestedPipelineID int64
|
||||
requestedVersion int
|
||||
runs []protocol.RunSummary
|
||||
runDetail *protocol.RunDetail
|
||||
runOpen bool
|
||||
runForm int
|
||||
runInput textinput.Model
|
||||
runPrompt textarea.Model
|
||||
runWorkspace string
|
||||
cliRun, cliStarted, runPicker bool
|
||||
cliOptions RunOptions
|
||||
runPickerIndex int
|
||||
runPickerInput textinput.Model
|
||||
runTask string
|
||||
runPaths []string
|
||||
runIndex, runTop int
|
||||
requestedRunID int64
|
||||
runStartRequest string
|
||||
runStepIndex int
|
||||
runDetailFocus bool
|
||||
runCollapsed map[string]bool
|
||||
runError string
|
||||
runPipelineID int64
|
||||
runFailedOnly bool
|
||||
runSearch textinput.Model
|
||||
runSearchOpen bool
|
||||
runGraphFocus bool
|
||||
runGraphTop int
|
||||
runGraphPan int
|
||||
editorOpen bool
|
||||
editorInput textinput.Model
|
||||
editorIndex int
|
||||
editorDraft *editedMsg
|
||||
draftDeletingPath string
|
||||
draftDeletingTop int
|
||||
runSpinner spinner.Model
|
||||
templates []protocol.Template
|
||||
templateOpen, templateRaw bool
|
||||
templateGraphFocus, templateConfirm bool
|
||||
templateGraphTop, templateGraphPan int
|
||||
templateIndex, templateTop int
|
||||
templateLines []string
|
||||
templateRequest, templateError string
|
||||
editorCheckGeneration uint64
|
||||
editorChecking bool
|
||||
statusOpen bool
|
||||
statusTop int
|
||||
statusRequest, statusError string
|
||||
systemStatus *protocol.SystemStatus
|
||||
usage *protocol.UsageStats
|
||||
draftOpen bool
|
||||
draftItems []draft.Draft
|
||||
draftIndex, draftTop int
|
||||
draftError, draftSource, draftNotice string
|
||||
ctx context.Context
|
||||
url string
|
||||
conn *websocket.Conn
|
||||
status string
|
||||
nextID uint64
|
||||
lines []string
|
||||
width int
|
||||
height int
|
||||
help help.Model
|
||||
keys keyMap
|
||||
pipelines []protocol.PipelineSummary
|
||||
loaded bool
|
||||
notificationEndpoints []protocol.NotificationEndpoint
|
||||
logSeen []bool
|
||||
unread int
|
||||
logOpen bool
|
||||
logTop int
|
||||
logPan int
|
||||
paletteOpen bool
|
||||
commandInput textinput.Model
|
||||
commandIndex int
|
||||
homeTop int
|
||||
searchOpen bool
|
||||
detail *protocol.PipelineDetail
|
||||
detailRequest string
|
||||
detailLoading bool
|
||||
detailError string
|
||||
pipelineTop int
|
||||
graphPan int
|
||||
versionsOpen bool
|
||||
versionIndex int
|
||||
confirmOpen bool
|
||||
actionConfirm *protocol.Message
|
||||
actionConfirmTop int
|
||||
actionApproved bool
|
||||
defaultModel string
|
||||
defaultHarness string
|
||||
editorDebugRunID int64
|
||||
mutationTitle string
|
||||
mutationCommand func() tea.Cmd
|
||||
mutationTop int
|
||||
pendingDraft *editedMsg
|
||||
draftNameInput textinput.Model
|
||||
submitID string
|
||||
submitNotice string
|
||||
stageIndex int
|
||||
stageTop int
|
||||
stageFocus bool
|
||||
stageConfigExpanded bool
|
||||
reconnecting bool
|
||||
requestedPipelineID int64
|
||||
requestedVersion int
|
||||
runs []protocol.RunSummary
|
||||
runDetail *protocol.RunDetail
|
||||
runOpen bool
|
||||
runForm int
|
||||
runInput textinput.Model
|
||||
runPrompt textarea.Model
|
||||
runWorkspace string
|
||||
cliRun, cliStarted, runPicker bool
|
||||
cliOptions RunOptions
|
||||
runPickerIndex int
|
||||
runPickerInput textinput.Model
|
||||
runTask string
|
||||
runPaths []string
|
||||
runIndex, runTop int
|
||||
requestedRunID int64
|
||||
runStartRequest string
|
||||
runStepIndex int
|
||||
runDetailFocus bool
|
||||
runCollapsed map[string]bool
|
||||
runError string
|
||||
runPipelineID int64
|
||||
runFailedOnly bool
|
||||
runSearch textinput.Model
|
||||
runSearchOpen bool
|
||||
runGraphFocus bool
|
||||
runGraphTop int
|
||||
runGraphPan int
|
||||
editorOpen bool
|
||||
editorInput textinput.Model
|
||||
editorIndex int
|
||||
editorDraft *editedMsg
|
||||
draftDeletingPath string
|
||||
draftDeletingTop int
|
||||
runSpinner spinner.Model
|
||||
templates []protocol.Template
|
||||
templateOpen, templateRaw bool
|
||||
templateGraphFocus, templateConfirm bool
|
||||
templateGraphTop, templateGraphPan int
|
||||
templateIndex, templateTop int
|
||||
templateLines []string
|
||||
templateRequest, templateError string
|
||||
}
|
||||
|
||||
func New(ctx context.Context, url string) Model {
|
||||
|
||||
Reference in New Issue
Block a user