Files
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

47 lines
2.0 KiB
Go

package draft
import (
"strings"
"testing"
)
func TestPublicationScopeForServer(t *testing.T) {
original := Draft{Path: "/retained/draft.md", Name: "demo", Server: "ws://origin/connect", BaseVersion: 7}
same := original.ForServer(original.Server)
if same != original {
t.Fatal("same-server version guard changed", same)
}
imported := original.ForServer("ws://destination/connect")
if imported.Server != "ws://destination/connect" || imported.BaseVersion != 0 || !imported.CreateOnly || imported.Path != original.Path || imported.Name != original.Name {
t.Fatal("cross-server scope leaked or draft identity changed", imported)
}
if original.Server != "ws://origin/connect" || original.BaseVersion != 7 || original.CreateOnly {
t.Fatal("projection changed retained draft")
}
legacy := Draft{Name: "legacy", BaseVersion: 2}
bound := legacy.ForServer("ws://destination/connect")
if bound.BaseVersion != 2 || bound.CreateOnly {
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)
}
}