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:
+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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user