Files
pipelines/internal/cli/portable_draft_test.go
T
alan 914345cb31 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.
2026-10-15 19:53:10 +01:00

123 lines
4.1 KiB
Go

package cli_test
import (
"context"
"fmt"
"os"
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/draft"
"git.a-wan.net/alan/pipelines/internal/pipeline"
)
func TestCLIEditDraftCanPublishToAnotherServerWithoutOriginVersion(t *testing.T) {
_, origin, originURL := setup(t)
run, destination, _ := setup(t)
ctx := context.Background()
source := pipeline.Template([]string{"worker"}, true)
for i := 0; i < 7; i++ {
if _, err := origin.Submit(ctx, "portable", pipeline.Template([]string{fmt.Sprintf("origin_v%d", i+1)}, true)); err != nil {
t.Fatal(err)
}
}
d, err := draft.Create("portable", source, originURL, false, 7)
if err != nil {
t.Fatal(err)
}
metadata, err := os.ReadFile(d.Path + ".json")
if err != nil {
t.Fatal(err)
}
if _, err := run("submit", d.Path); err != nil {
t.Fatal("cross-server publication blocked", err)
}
items, err := destination.List(ctx)
if err != nil || len(items) != 1 || items[0].Version != 1 {
t.Fatal("origin base version leaked to destination", items, err)
}
updated := pipeline.Template([]string{"worker", "reviewer"}, true)
if err := os.WriteFile(d.Path, []byte(updated), 0600); err != nil {
t.Fatal(err)
}
if _, err := run("submit", d.Path); err == nil {
t.Fatal("import overwrote existing destination name without approval")
}
items, _ = destination.List(ctx)
if items[0].Version != 1 {
t.Fatal("destination collision changed published history")
}
if _, err := run("submit", d.Path, "--expected-version", "1"); err != nil {
t.Fatal("explicit destination version update blocked", err)
}
items, _ = destination.List(ctx)
if items[0].Version != 2 {
t.Fatal("explicit destination update did not publish a version", items)
}
updated = pipeline.Template([]string{"worker", "reviewer", "publisher"}, true)
if err := os.WriteFile(d.Path, []byte(updated), 0600); err != nil {
t.Fatal(err)
}
if _, err := run("submit", d.Path, "--expected-version", "99"); err == nil {
t.Fatal("wrong explicit destination version accepted")
}
if _, err := run("submit", d.Path, "--force"); err != nil {
t.Fatal("explicit forced destination update blocked", err)
}
items, _ = destination.List(ctx)
if items[0].Version != 3 {
t.Fatal("forced destination update did not publish a version", items)
}
items, _ = origin.List(ctx)
if len(items) != 1 || items[0].Version != 7 {
t.Fatal("origin pipeline was modified", items)
}
retained, err := os.ReadFile(d.Path + ".json")
if err != nil || string(retained) != string(metadata) {
t.Fatal("import rewrote original draft metadata", err)
}
text, err := draft.Read(d.Path)
if err != nil || text != updated {
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)
}
}