소스 검색

ability to force deploy

Johan Le Baut 1 주 전
부모
커밋
814dceb529
4개의 변경된 파일과 109개의 추가작업 그리고 13개의 파일을 삭제
  1. 2 0
      README.md
  2. 40 10
      scripts/deploy.py
  3. 8 3
      scripts/deploy.sh
  4. 59 0
      tests/test_deploy.py

+ 2 - 0
README.md

@@ -152,6 +152,8 @@ Remove the service with `./scripts/deploy.sh uninstall sooperlooper`.
 
 On each system boot, `rigforge-mod-ui.service` now runs `scripts/prepare_mod_ui_pedalboard.py` before launching mod-ui. It regenerates and validates the content-addressed reference bundle from the checkout, replaces the mutable `default.pedalboard` with that clean board, and moves any previous default and last-state file to boot-ID-suffixed backups. A marker under the user runtime directory makes this happen only once per boot; a mod-ui service restart during the same boot preserves in-session changes. If generation or validation fails, mod-ui does not start with a blank board. This startup behavior is covered by repository tests but has not yet been deployed or verified on the target.
 
+If `install mod-ui` refuses a changed but registry-managed reference bundle, first inspect why it differs. To explicitly replace only that bundle while preserving its current contents, use `./scripts/deploy.sh install mod-ui --force-reference`; the old bundle is retained in an adjacent `.rigforge-force-backup` path. This flag does not override local edits to the systemd unit, model files, or other managed paths.
+
 The mod-host unit runs `pw-jack mod-host -n -p 5555 -f 5556`; it no longer runs `configure_mod_host.py`. The mod-ui service starts under `pw-jack`, opens a persistent local WebSocket session so the board loads even before a browser connects, and is the sole control/feedback client for mod-host. Its boundary bridge maps four visible input/output pairs to PipeWire and applies only explicit UI Connect/Disconnect operations. Install the ARM64 artifacts, NAM/LSP bundles, and declared audio assets before activation. Sustained audio and recovery after a service restart still require on-target verification; external UMC/boundary/mixer/looper links remain observable by the graph observer.
 
 Both mod-host TCP ports currently listen on all interfaces without authentication, retained by owner request. The mod-ui HTTP/WebSocket server is also reachable on the LAN for the browser UI. Restrict these endpoints before treating the setup as hardened. Keep the repository checkout at its installed path, since the user units refer to it.

+ 40 - 10
scripts/deploy.py

@@ -1558,7 +1558,7 @@ def manage_mod_ui_nam_models(action, config, registry, state):
     write_registry(registry)
 
 
-def deploy_mod_ui(action, config, registry):
+def deploy_mod_ui(action, config, registry, force_reference=False):
     if action == "install":
         if "mod_host_ports" not in registry:
             raise RuntimeError("install mod-host-ports before installing mod-ui")
@@ -1597,8 +1597,17 @@ def deploy_mod_ui(action, config, registry):
         trusted_reference_sha256 = None
         if reference_record.get("destination") == str(unit["reference_bundle"]):
             trusted_reference_sha256 = reference_record.get("installed_sha256")
+        if force_reference and (
+            not isinstance(trusted_reference_sha256, str)
+            or not trusted_reference_sha256
+        ):
+            raise RuntimeError(
+                "--force-reference requires a registry-managed reference bundle at the generated path"
+            )
         reference_sha256 = prepare_mod_ui_reference_bundle(
-            unit, trusted_existing_sha256=trusted_reference_sha256
+            unit,
+            trusted_existing_sha256=trusted_reference_sha256,
+            force_reference=force_reference,
         )
         if "mod_ui" in registry:
             registry["mod_ui"]["reference_bundle"] = {
@@ -1635,8 +1644,9 @@ def next_reset_backup_path(path):
     return candidate
 
 
-def next_mod_ui_reference_backup_path(destination):
-    base = destination.with_name(destination.name + ".rigforge-corrupt-backup")
+def next_mod_ui_reference_backup_path(destination, forced=False):
+    suffix = "force-backup" if forced else "corrupt-backup"
+    base = destination.with_name(destination.name + f".rigforge-{suffix}")
     candidate = base
     suffix = 2
     while candidate.exists() or candidate.is_symlink():
@@ -1646,7 +1656,9 @@ def next_mod_ui_reference_backup_path(destination):
     return candidate
 
 
-def prepare_mod_ui_reference_bundle(unit, trusted_existing_sha256=None):
+def prepare_mod_ui_reference_bundle(
+    unit, trusted_existing_sha256=None, force_reference=False
+):
     destination = unit["reference_bundle"]
     files = unit["reference_files"]
     validate_user_destination(destination)
@@ -1661,9 +1673,12 @@ def prepare_mod_ui_reference_bundle(unit, trusted_existing_sha256=None):
                 current_files[path.relative_to(destination).as_posix()] = path.read_bytes()
         if current_files != files:
             current_sha256 = tree_sha256(destination)
-            if (
-                trusted_existing_sha256 is None
-                or current_sha256 != trusted_existing_sha256
+            matches_registry = (
+                trusted_existing_sha256 is not None
+                and current_sha256 == trusted_existing_sha256
+            )
+            if not matches_registry and not (
+                force_reference and trusted_existing_sha256 is not None
             ):
                 raise RuntimeError(f"generated mod-ui reference changed locally: {destination}")
             destination.parent.mkdir(parents=True, exist_ok=True)
@@ -1679,8 +1694,11 @@ def prepare_mod_ui_reference_bundle(unit, trusted_existing_sha256=None):
                     raise RuntimeError(
                         f"regenerated mod-ui reference unexpectedly matches corrupted data: {destination}"
                     )
-                backup = next_mod_ui_reference_backup_path(destination)
+                backup = next_mod_ui_reference_backup_path(
+                    destination, forced=force_reference and not matches_registry
+                )
                 os.replace(destination, backup)
+                print(f"Preserved previous mod-ui reference bundle at {backup}")
                 try:
                     os.replace(staged, destination)
                 except OSError:
@@ -2324,9 +2342,16 @@ def main(argv=None):
             "sooperlooper",
         ),
     )
+    parser.add_argument(
+        "--force-reference",
+        action="store_true",
+        help="replace a changed registry-managed mod-ui reference after preserving it",
+    )
     args = parser.parse_args(argv)
     if args.action == "reset" and args.target != "mod-ui":
         parser.error("reset is only supported for mod-ui")
+    if args.force_reference and (args.action != "install" or args.target != "mod-ui"):
+        parser.error("--force-reference is only valid with install mod-ui")
     try:
         state = yaml.safe_load((ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8"))
         deployment = load_deployment()
@@ -2343,7 +2368,12 @@ def main(argv=None):
         elif args.target == "mod-host-ports":
             deploy_mod_host_ports(args.action, deployment["mod_host_ports"], registry)
         elif args.target == "mod-ui":
-            deploy_mod_ui(args.action, deployment["mod_ui"], registry)
+            deploy_mod_ui(
+                args.action,
+                deployment["mod_ui"],
+                registry,
+                force_reference=args.force_reference,
+            )
         elif args.target == "reconcile":
             deploy_reconcile(args.action, deployment["reconcile"], registry)
         elif args.target == "midi-bridge":

+ 8 - 3
scripts/deploy.sh

@@ -2,11 +2,16 @@
 set -u
 
 usage() {
-    printf 'Usage: %s install|uninstall|reload|reset all|namlv2|lsp|dragonfly-reverb|pipewire|mod-host-ports|mod-host|mod-ui|reconcile|midi-bridge|sooperlooper\n' "$0" >&2
+    printf 'Usage: %s install|uninstall|reload|reset all|namlv2|lsp|dragonfly-reverb|pipewire|mod-host-ports|mod-host|mod-ui|reconcile|midi-bridge|sooperlooper [--force-reference (install mod-ui only)]\n' "$0" >&2
     exit 2
 }
 
-[[ $# -eq 2 ]] || usage
+force_args=()
+if [[ $# -eq 3 && "$3" == "--force-reference" && "$1" == "install" && "$2" == "mod-ui" ]]; then
+    force_args=(--force-reference)
+elif [[ $# -ne 2 ]]; then
+    usage
+fi
 action=$1
 target=$2
 case "$action" in
@@ -26,7 +31,7 @@ script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
 status=0
 for component in "${targets[@]}"; do
     printf '%s\n' "== $action $component =="
-    if ! python3 "$script_dir/deploy.py" "$action" "$component"; then
+    if ! python3 "$script_dir/deploy.py" "$action" "$component" "${force_args[@]}"; then
         status=1
     fi
 done

+ 59 - 0
tests/test_deploy.py

@@ -757,6 +757,65 @@ class DeploymentTests(unittest.TestCase):
             deploy.tree_sha256(repaired_reference),
         )
 
+    def test_mod_ui_force_install_backs_up_and_replaces_registry_hash_mismatch(self):
+        config = deploy.load_deployment()["mod_ui"]
+        registry = {
+            "mod_host_ports": {},
+            "mod_host": {},
+        }
+        deploy.deploy_mod_ui("install", config, registry)
+        registry = deploy.read_registry()
+        reference = Path(registry["mod_ui"]["reference_bundle"]["destination"])
+        graph = reference / "rigforge-guitar.ttl"
+        graph.write_bytes(b"changed outside deploy\n")
+        original = graph.read_bytes()
+
+        with self.assertRaisesRegex(RuntimeError, "changed locally"):
+            deploy.deploy_mod_ui("install", config, deploy.read_registry())
+        self.assertEqual(graph.read_bytes(), original)
+
+        deploy.deploy_mod_ui(
+            "install", config, deploy.read_registry(), force_reference=True
+        )
+
+        repaired_registry = deploy.read_registry()
+        repaired_reference = Path(
+            repaired_registry["mod_ui"]["reference_bundle"]["destination"]
+        )
+        backup = repaired_reference.with_name(
+            repaired_reference.name + ".rigforge-force-backup"
+        )
+        self.assertEqual((backup / "rigforge-guitar.ttl").read_bytes(), original)
+        self.assertGreater((repaired_reference / "rigforge-guitar.ttl").stat().st_size, 0)
+        self.assertEqual(
+            repaired_registry["mod_ui"]["reference_bundle"]["installed_sha256"],
+            deploy.tree_sha256(repaired_reference),
+        )
+
+    def test_mod_ui_force_install_requires_a_registered_reference_bundle(self):
+        config = deploy.load_deployment()["mod_ui"]
+        registry = {
+            "mod_host_ports": {},
+            "mod_host": {},
+        }
+        state = deploy.yaml.safe_load(
+            (ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8")
+        )
+        deploy.manage_mod_ui_nam_models("install", config, registry, state)
+        reference = Path(deploy.render_mod_ui_service(config)["reference_bundle"])
+        reference.mkdir(parents=True)
+        (reference / "local-file").write_text("do not replace", encoding="utf-8")
+
+        with self.assertRaisesRegex(RuntimeError, "requires a registry-managed"):
+            deploy.deploy_mod_ui(
+                "install", config, registry, force_reference=True
+            )
+
+        self.assertEqual(
+            (reference / "local-file").read_text(encoding="utf-8"),
+            "do not replace",
+        )
+
     def test_mod_ui_reset_restores_reference_and_backs_up_user_state(self):
         registry = {
             "mod_host_ports": {},