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:
@@ -1,4 +1,5 @@
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
@@ -358,6 +359,87 @@ class SetupNativeTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, "no local Pipelines image"):
|
||||
installer.migrate_docker(prefix, replace=False)
|
||||
|
||||
def test_configure_harnesses_writes_host_profiles_for_detected_harness(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
recorder = Recorder()
|
||||
installer = self.installer(directory, recorder)
|
||||
prefix = Path(directory) / "prefix"
|
||||
installer.configure_harnesses({"opencode": "/usr/bin/opencode", "pi": ""}, "fixture/harness")
|
||||
path = installer.harness_config_path()
|
||||
self.assertEqual(path, Path(directory) / "config/pipelines/harnesses.json")
|
||||
config = json.loads(path.read_text())
|
||||
self.assertEqual(config["default"], "opencode")
|
||||
profile = config["profiles"]["opencode"]
|
||||
self.assertEqual(profile["executable"], "/usr/bin/opencode")
|
||||
self.assertNotIn("docker_directory", profile)
|
||||
self.assertTrue(installer._valid_model(profile["model"]))
|
||||
self.assertTrue(installer._valid_model(profile["pipeline_model"]))
|
||||
self.assertEqual(profile["model"], "fixture/harness")
|
||||
# Detection-only: no harness install/upgrade/download was invoked.
|
||||
self.assertFalse(any("opencode" in part for call in recorder.calls for part in call))
|
||||
|
||||
def test_configure_harnesses_skips_without_a_valid_model(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
installer = self.installer(directory, Recorder())
|
||||
path = installer.harness_config_path()
|
||||
result = installer.configure_harnesses({"opencode": "/usr/bin/opencode", "pi": ""})
|
||||
self.assertIsNone(result)
|
||||
self.assertFalse(path.exists(), "an invalid profile was written")
|
||||
|
||||
def test_configure_harnesses_migrates_stale_docker_link_and_default(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
installer = self.installer(directory, Recorder())
|
||||
path = installer.harness_config_path()
|
||||
path.parent.mkdir(parents=True)
|
||||
path.write_text(json.dumps({
|
||||
"default": "pi",
|
||||
"future": "preserve",
|
||||
"profiles": {
|
||||
"opencode": {"docker_directory": "/checkout", "executable": "opencode",
|
||||
"model": "fixture/interactive", "pipeline_model": "fixture/stages"},
|
||||
"pi": {"docker_directory": "/checkout", "executable": "pi",
|
||||
"model": "provider/interactive", "pipeline_model": "provider/stages"},
|
||||
},
|
||||
}))
|
||||
installer.configure_harnesses({"opencode": "/usr/bin/opencode", "pi": "/usr/bin/pi"})
|
||||
saved = json.loads(path.read_text())
|
||||
self.assertEqual(saved["default"], "opencode")
|
||||
self.assertEqual(saved["future"], "preserve")
|
||||
for name in ("opencode", "pi"):
|
||||
self.assertNotIn("docker_directory", saved["profiles"][name], name)
|
||||
self.assertTrue(installer._valid_model(saved["profiles"][name]["model"]))
|
||||
self.assertEqual(saved["profiles"]["opencode"]["executable"], "/usr/bin/opencode")
|
||||
|
||||
def test_full_run_migrates_docker_harness_config_to_host(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
recorder = Recorder()
|
||||
installer = self.installer(directory, recorder)
|
||||
prefix = Path(directory) / "prefix"
|
||||
path = installer.harness_config_path()
|
||||
path.parent.mkdir(parents=True)
|
||||
path.write_text(json.dumps({
|
||||
"default": "pi",
|
||||
"profiles": {
|
||||
"opencode": {"docker_directory": "/checkout", "executable": "opencode",
|
||||
"model": "fixture/interactive", "pipeline_model": "fixture/stages"},
|
||||
"pi": {"docker_directory": "/checkout", "executable": "pi",
|
||||
"model": "provider/interactive", "pipeline_model": "provider/stages"},
|
||||
},
|
||||
}))
|
||||
with patch.object(setup_native.shutil, "which", side_effect=self.which_all(opencode="/usr/bin/opencode", pi="/usr/bin/pi")), \
|
||||
patch.object(setup_native.lan, "detect_lan", return_value="192.168.1.20"), \
|
||||
patch.object(setup_native.configure, "host_timezone", return_value="Europe/London"):
|
||||
installer.run(setup_native.arguments([]))
|
||||
saved = json.loads(path.read_text())
|
||||
self.assertEqual(saved["default"], "opencode", "stale Docker-era pi default survived")
|
||||
self.assertNotIn("docker_directory", saved["profiles"]["opencode"])
|
||||
self.assertTrue(saved["profiles"]["opencode"]["executable"].endswith("opencode"))
|
||||
self.assertTrue(installer._valid_model(saved["profiles"]["opencode"]["model"]))
|
||||
# Detection-only: no harness install/upgrade/download command recorded.
|
||||
self.assertFalse(any("opencode" in part for call in recorder.calls for part in call))
|
||||
self.assertFalse(any(part == "pi" for call in recorder.calls for part in call))
|
||||
self.assertFalse(any("npm" == part for call in recorder.calls for part in call))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user