Compare commits

..

3 commits

Author SHA1 Message Date
bf36b7621b docs: changelog entries for the dependency-hook install fixes
Some checks failed
CI / lint (pull_request) Successful in 33s
CI / test (pull_request) Successful in 1m20s
CI / validate-json (pull_request) Successful in 23s
CI / markdown-links (pull_request) Successful in 15s
CI / lint (push) Waiting to run
CI / test (push) Waiting to run
CI / validate-json (push) Waiting to run
CI / markdown-links (push) Waiting to run
Build ISO / build-iso (push) Has been cancelled
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-11 15:29:08 +02:00
c2c3cdb1ed fix(cli): fire on_install hooks on named CLI installs
`furtka app install <name>` copied app folders (install_plan) then ran a
bare reconcile, which fires on_start but never on_install — so a CLI
install of a consumer brought its provider up without ever provisioning
it (no account, empty MQTT_* in the consumer .env). Route named installs
through install_runner.run_install (writing the plan file first), the same
docker phase the API dispatches, so providers come up before consumers and
on_install hooks run. Path installs keep the copy+reconcile dev/test path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 13:03:33 +02:00
0615d92c8d fix(install): copy app subdirectories so dependency hooks ship
install_from() only copied top-level files, so an app's scripts/ folder —
where provider on_install/on_start dependency hooks live — never reached
/var/lib/furtka/apps/<app>/. Every hooked dependency therefore failed at
reconcile with "hook ... missing in provider". Copy subdirectories too
(rmtree+copytree so a reinstall drops files removed upstream).

Found during the first real end-to-end run of the mosquitto+zigbee2mqtt
dependency pair on a test VM.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 13:03:33 +02:00
5 changed files with 115 additions and 26 deletions

View file

@ -7,6 +7,26 @@ This project uses calendar versioning: `YY.N-stage` (e.g. `26.0-alpha` = 2026, r
## [Unreleased]
### Fixed
- **App installs now copy subdirectories, so dependency hooks actually
ship.** `install_from()` only copied an app's top-level files, so the
`scripts/` folder — where a provider's `on_install`/`on_start` dependency
hooks live — never reached `/var/lib/furtka/apps/<app>/`, and every hooked
dependency failed at reconcile with `hook ... missing in provider`. The
whole app folder is copied now (`rmtree` + `copytree`, so a reinstall also
drops files that were removed upstream). Found during the first real
end-to-end run of the mosquitto + zigbee2mqtt pair on a test VM.
- **`furtka app install <name>` now runs `on_install` hooks.** Named CLI
installs copied the app folders and then ran a bare reconcile, which fires
`on_start` but never `on_install` — so a CLI install of a consumer brought
its provider up without ever provisioning it (no account created, empty
`MQTT_*` values in the consumer's `.env`). Named installs now go through
`install_runner.run_install` (writing the plan file first), the same docker
phase the API dispatches, so providers come up before consumers and
`on_install` hooks run. Path-based installs keep the copy + reconcile
dev/test path.
## [26.18-alpha] - 2026-06-04
### Fixed

View file

@ -69,37 +69,62 @@ def _cmd_app_list(args: argparse.Namespace) -> int:
def _cmd_app_install(args: argparse.Namespace) -> int:
# If the user passed a path (or a path-ish thing), bypass dep resolution —
# local paths are dev/test workflows where the caller knows what they want.
# Catalog/bundled name installs go through plan_install() so transitive
# `requires` are pulled in.
# These just copy + reconcile; no `requires`/hook handling.
src_path = Path(args.source)
is_path = src_path.is_dir() or "/" in args.source or args.source.startswith(".")
try:
if is_path:
try:
src = installer.resolve_source(args.source)
target = installer.install_from(src)
except installer.InstallError as e:
print(f"error: {e}", file=sys.stderr)
return 2
print(f"installed {target.name} to {target}")
else:
actions = reconciler.reconcile(apps_dir())
for a in actions:
print(f" {a.describe()}")
return 1 if reconciler.has_errors(actions) else 0
# Catalog/bundled name install: resolve transitive `requires`, copy every
# app folder (the synchronous phase the API runs inline), then drive the
# exact same docker phase the API dispatches via systemd-run — so providers
# come up before consumers and `on_install` hooks fire to provision them.
# Going through run_install (not a bare reconcile) is what makes a CLI
# install of a consumer actually provision against its provider.
from furtka import install_runner
try:
plan = deps.plan_install(args.source)
except deps.DependencyError as e:
print(f"error: {e}", file=sys.stderr)
return 2
if not plan.to_install:
# Target is already installed — re-run as a single-app install
# to refresh files (matches reinstall semantics).
target_path = installer.install_from(installer.resolve_source(args.source))
print(f"reinstalled {target_path.name} to {target_path}")
try:
if plan.to_install:
installer.install_plan(plan)
to_install = list(plan.to_install)
else:
targets = installer.install_plan(plan)
for t in targets:
print(f"installed {t.name} to {t}")
# Target already installed — reinstall to refresh files, then still
# run the docker phase so hooks re-fire (matches API reinstall).
installer.install_from(installer.resolve_source(args.source))
to_install = [args.source]
except installer.InstallError as e:
print(f"error: {e}", file=sys.stderr)
return 2
actions = reconciler.reconcile(apps_dir())
for a in actions:
print(f" {a.describe()}")
return 1 if reconciler.has_errors(actions) else 0
# Stage the plan file run_install consumes (it removes it after reading).
install_runner.plan_path().parent.mkdir(parents=True, exist_ok=True)
install_runner.plan_path().write_text(
json.dumps({"target": args.source, "to_install": to_install})
)
try:
install_runner.run_install(args.source)
except Exception as e:
# run_install already wrote state="error"; surface it to the caller.
print(f"error: {e}", file=sys.stderr)
return 1
for name in to_install:
print(f"installed {name}")
return 0
def _cmd_app_install_bg(args: argparse.Namespace) -> int:

View file

@ -171,13 +171,22 @@ def install_from(src: Path, settings: dict[str, str] | None = None) -> Path:
target.mkdir(parents=True, exist_ok=True)
for item in src.iterdir():
dest = target / item.name
# Subdirectories (e.g. scripts/ holding a provider's on_install/on_start
# dependency hooks) must come along too — copy the whole tree, replacing
# any stale copy from a previous install so removed files don't linger.
if item.is_dir():
if dest.exists():
shutil.rmtree(dest)
shutil.copytree(item, dest)
continue
if not item.is_file():
continue
# Never overwrite an existing user .env — either settings-driven write
# or previous manual edit has authority.
if item.name == ".env" and (target / ".env").exists():
continue
shutil.copy2(item, target / item.name)
shutil.copy2(item, dest)
env = target / ".env"
env_example = target / ".env.example"

View file

@ -158,7 +158,7 @@ def test_app_install_uses_plan_for_named_install(tmp_path, monkeypatch, capsys):
_write_manifest(bundled, "mosquitto")
_write_manifest(bundled, "zigbee2mqtt", requires=[{"app": "mosquitto"}])
from furtka import installer, reconciler
from furtka import install_runner, installer
# Stub install_from so we don't actually copy files / mess with placeholders.
install_calls: list[str] = []
@ -168,12 +168,22 @@ def test_app_install_uses_plan_for_named_install(tmp_path, monkeypatch, capsys):
return tmp_path / src.name
monkeypatch.setattr(installer, "install_from", fake_install_from)
monkeypatch.setattr(reconciler, "reconcile", lambda *a, **k: [])
monkeypatch.setattr(install_runner, "_INSTALL_PLAN", tmp_path / "install-plan.json")
# Named installs drive the docker phase through run_install (so on_install
# hooks fire) — stub it and assert it's invoked with the chosen target.
run_calls: list[str] = []
monkeypatch.setattr(install_runner, "run_install", lambda name: run_calls.append(name))
rc = main(["app", "install", "zigbee2mqtt"])
assert rc == 0
# Provider installed before consumer.
assert install_calls == ["mosquitto", "zigbee2mqtt"]
# The docker phase (which fires on_install hooks) ran for the target.
assert run_calls == ["zigbee2mqtt"]
# And the plan file was staged for run_install to consume.
plan = json.loads(install_runner.plan_path().read_text())
assert plan["target"] == "zigbee2mqtt"
assert plan["to_install"] == ["mosquitto", "zigbee2mqtt"]
def test_app_install_named_with_cycle_exits_2(tmp_path, monkeypatch, capsys):

View file

@ -73,6 +73,31 @@ def test_install_from_copies_files(tmp_path, fake_dirs):
assert (target / ".env").read_text() == "A=1"
def test_install_from_copies_subdirectories(tmp_path, fake_dirs):
# Dependency hooks live under scripts/ — the whole subtree must be copied,
# not just top-level files, or providers ship without their hooks.
src = _write_app_source(tmp_path, "mosquitto", VALID_MANIFEST, env_example="A=1")
scripts = src / "scripts"
scripts.mkdir()
(scripts / "provision-client.sh").write_text("#!/bin/sh\necho hi\n")
target = installer.install_from(src)
assert (target / "scripts" / "provision-client.sh").read_text() == "#!/bin/sh\necho hi\n"
def test_install_from_reinstall_drops_stale_subdir_files(tmp_path, fake_dirs):
# A reinstall whose source renamed/removed a hook must not leave the old one.
src = _write_app_source(tmp_path, "mosquitto", VALID_MANIFEST, env_example="A=1")
scripts = src / "scripts"
scripts.mkdir()
(scripts / "old-hook.sh").write_text("old\n")
installer.install_from(src)
(scripts / "old-hook.sh").unlink()
(scripts / "new-hook.sh").write_text("new\n")
target = installer.install_from(src)
assert not (target / "scripts" / "old-hook.sh").exists()
assert (target / "scripts" / "new-hook.sh").read_text() == "new\n"
def test_install_from_preserves_existing_env(tmp_path, fake_dirs):
src = _write_app_source(tmp_path, "fileshare", VALID_MANIFEST, env_example="A=new")
target = apps_dir() / "fileshare"