- A dev checkout linked at plugins/<name> with a root plugin.js: Electron's publish copied the link itself (fs.cp keeps a top-level link), so the "copy" was the checkout, the marker was written into it, and the prune (which skipped linked folders) left a ghost after the link went. Copy from the resolved folder; never keep or stamp a link at <root>/<name>; the prune follows links and drops only the link. The host twin gets the same link-target and prune handling (its copytree already copied the files). - The install dialog decided desktop success from the reconcile's touched list, which also names folders the pass deleted: a force reinstall whose new tree dropped its desktop entry read as installed. Read the folder (Electron fs bridge, or the host's /api/desktop-plugins) instead. - Re-pin consent: the desktop half is a presence surface, so moving it between plugin.js and desktop/plugin.js widens nothing.
84 lines
3.5 KiB
Python
84 lines
3.5 KiB
Python
"""A dev checkout linked into ``plugins/`` with its ``plugin.js`` at the root publishes a real copy.
|
|
|
|
The host pass shares ``<root>/desktop-plugins`` with native Desktop, whose earlier copy of such a
|
|
checkout kept the link itself (marker written into the checkout). Neither writer may stamp a folder
|
|
reached through a link, and the prune drops that leftover link once the package link is gone.
|
|
"""
|
|
|
|
import json
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from hermes_cli.desktop_plugin_halves import PACKAGE_MARKER, reconcile_desktop_halves
|
|
|
|
pytestmark = pytest.mark.platforms("posix")
|
|
|
|
|
|
def _checkout(tmp_path: Path) -> tuple[Path, Path, Path, Path]:
|
|
root = tmp_path / "hermes"
|
|
checkout = tmp_path / "src" / "radar"
|
|
checkout.mkdir(parents=True)
|
|
(checkout / "plugin.yaml").write_text("name: radar\n", encoding="utf-8")
|
|
(checkout / "plugin.js").write_text("root entry", encoding="utf-8")
|
|
(root / "plugins").mkdir(parents=True)
|
|
link = root / "plugins" / "radar"
|
|
link.symlink_to(checkout, target_is_directory=True)
|
|
return root, root / "desktop-plugins", checkout, link
|
|
|
|
|
|
def test_a_linked_root_layout_checkout_publishes_a_copy_and_leaves_with_its_link(tmp_path):
|
|
root, app_root, checkout, link = _checkout(tmp_path)
|
|
target = app_root / "radar"
|
|
|
|
assert reconcile_desktop_halves(root, app_root) == [str(target)]
|
|
assert not target.is_symlink()
|
|
assert (target / "plugin.js").read_text(encoding="utf-8") == "root entry"
|
|
marker = json.loads((target / PACKAGE_MARKER).read_text(encoding="utf-8"))
|
|
assert (marker["package"], marker["source"], marker["linked"]) == ("radar", str(link), True)
|
|
assert not (checkout / PACKAGE_MARKER).exists()
|
|
assert reconcile_desktop_halves(root, app_root) == []
|
|
|
|
link.unlink()
|
|
assert reconcile_desktop_halves(root, app_root) == [str(target)]
|
|
assert not target.exists()
|
|
assert sorted(p.name for p in checkout.iterdir()) == ["plugin.js", "plugin.yaml"]
|
|
|
|
|
|
def test_a_copy_that_kept_the_checkout_link_is_replaced_then_pruned_without_touching_the_checkout(tmp_path):
|
|
root, app_root, checkout, link = _checkout(tmp_path)
|
|
target = app_root / "radar"
|
|
ghost = {"linked": True, "package": "radar", "source": str(link), "sourceMtimeMs": 9e15}
|
|
(checkout / PACKAGE_MARKER).write_text(json.dumps(ghost), encoding="utf-8")
|
|
app_root.mkdir()
|
|
target.symlink_to(checkout, target_is_directory=True)
|
|
|
|
assert reconcile_desktop_halves(root, app_root) == [str(target)]
|
|
assert not target.is_symlink()
|
|
assert (target / "plugin.js").read_text(encoding="utf-8") == "root entry"
|
|
|
|
shutil.rmtree(target)
|
|
target.symlink_to(checkout, target_is_directory=True)
|
|
link.unlink()
|
|
assert reconcile_desktop_halves(root, app_root) == [str(target)]
|
|
assert not target.is_symlink() and not target.exists()
|
|
assert (checkout / "plugin.js").read_text(encoding="utf-8") == "root entry"
|
|
|
|
|
|
def test_a_plugin_the_user_linked_into_the_app_root_is_never_stamped(tmp_path):
|
|
root = tmp_path / "hermes"
|
|
own = tmp_path / "src" / "pkg"
|
|
own.mkdir(parents=True)
|
|
(own / "plugin.js").write_text("same", encoding="utf-8")
|
|
half = root / "plugins" / "pkg" / "desktop"
|
|
half.mkdir(parents=True)
|
|
(half / "plugin.js").write_text("same", encoding="utf-8")
|
|
app_root = root / "desktop-plugins"
|
|
app_root.mkdir()
|
|
(app_root / "pkg").symlink_to(own, target_is_directory=True)
|
|
|
|
assert reconcile_desktop_halves(root, app_root) == []
|
|
assert not (own / PACKAGE_MARKER).exists()
|
|
assert (app_root / "pkg").is_symlink()
|