Files Branches

Comparing master ← linux-nspawn

Changes on linux-nspawn that are not yet on master (three-dot, from the merge base).

2 files changed, 106 insertions(+), 7 deletions(-)
adom-context+57−7
@@ -57,20 +57,53 @@ def probe_hydrogen():   def probe_where(hydrogen):-    """hydrogen-local: the WSL2 distro Hydrogen runs on the user's own PC.+    """hydrogen-local: the WSL2 distro Hydrogen runs on the user's own Windows PC.+    hydrogen-local-linux: the systemd-nspawn machine Hydrogen runs on the user's own Linux PC.     container: anything else (an Adom cloud container, a service box)."""     try:         wsl = "microsoft" in Path("/proc/version").read_text().lower()     except OSError:         wsl = False-    local = wsl and (os.environ.get("ADOM_DESKTOP_MODE") == "local" or hydrogen["url"] is not None)+    try:+        nspawn = Path("/run/systemd/container").read_text().strip() == "systemd-nspawn"+    except OSError:+        nspawn = False+    hydrogen_here = os.environ.get("ADOM_DESKTOP_MODE") == "local" or hydrogen["url"] is not None+    if wsl and hydrogen_here:+        kind = "hydrogen-local"+    elif nspawn and hydrogen_here:+        kind = "hydrogen-local-linux"+    else:+        kind = "container"     return {-        "kind": "hydrogen-local" if local else "container",+        "kind": kind,         "host": socket.gethostname(),-        "windows_drive": "/mnt/c" if local and Path("/mnt/c").is_dir() else None,+        "windows_drive": "/mnt/c" if kind == "hydrogen-local" and Path("/mnt/c").is_dir() else None,     }  +def here_machine(where, machines):+    """The Adom Bridge target that is the machine this workspace runs on, or None. The workspace+    carries its PC's name; on Linux an older Hydrogen left the image's name in place, so there the+    one Linux target stands in when the name matches nothing."""+    if where["kind"] == "container" or not machines:+        return None+    linux_ws = where["kind"] == "hydrogen-local-linux"+    for t in machines["machines"]:+        if (t.get("name") or "").lower() != where["host"].lower():+            continue+        # A Linux workspace that still carries the image's name ("AdomLapper", a Windows PC)+        # must never be taken for that PC: on Linux only a Linux target can be "here".+        if linux_ws and (t.get("os") or "").lower() != "linux":+            break+        return t["name"]+    if linux_ws:+        linux = [t["name"] for t in machines["machines"] if (t.get("os") or "").lower() == "linux" and t.get("name")]+        if len(linux) == 1:+            return linux[0]+    return None++ def probe_identity():     d = run_json("adom-wiki", "whoami", "--json")     user = ((d or {}).get("data") or {}).get("user") or {}@@ -154,6 +187,12 @@ def render(c):                      f"({w['host']}). {w['windows_drive'] or '/mnt/c'} is that PC's C: drive, so "                      "Windows files are reachable directly here; skills that say you run in a "                      "cloud container do not apply.")+    elif w["kind"] == "hydrogen-local-linux":+        pc = here_machine(w, c["machines"]) or w["host"]+        lines.append(f"- Where: the Hydrogen local workspace on the user's own Linux PC ({pc}), a "+                     "systemd-nspawn machine Hydrogen runs there (the Linux counterpart of the WSL2 "+                     "distro on Windows). The PC's /home and /tmp are under /mnt/host; skills that "+                     "say you run in a cloud container do not apply.")     else:         lines.append(f"- Where: a Linux container ({w['host']}), not the user's PC. Reach the "                      "user's machines only through adom-bridge.")@@ -172,15 +211,26 @@ def render(c):     else:         # In the local workspace the distro's hostname is its PC's name, so one target         # is the very machine the user is sitting at.-        here = w["host"].lower() if w["kind"] == "hydrogen-local" else None+        here_name = here_machine(w, m)+        if w["kind"] == "hydrogen-local":+            here = w["host"].lower()+        elif w["kind"] == "hydrogen-local-linux":+            here = here_name.lower() if here_name else None+        else:+            here = None         names = "; ".join(             f"{t['name']} ({t['os']}, {'reachable' if t['reachable'] is True else t['reachable'] or 'offline'}"             f"{', primary' if t['primary'] else ''}{', this PC' if (t['name'] or '').lower() == here else ''})"             for t in m["machines"]) or "none"         lines.append(f"- Adom Bridge machines: {names}.")         if len(m["machines"]) > 1 and not m["primary"]:-            lines.append("  No primary machine is set: ask the user which one to use before "-                         "driving any of them, and pass --target <name>.")+            if w["kind"] == "hydrogen-local-linux" and here_name:+                # The person is sitting at the Linux PC this workspace runs on: that is "here".+                lines.append(f"  No primary machine is set: {here_name} (this PC) is the default. "+                             f"Pass --target {here_name} unless the user names another machine.")+            else:+                lines.append("  No primary machine is set: ask the user which one to use before "+                             "driving any of them, and pass --target <name>.")     pkgs = c["packages"]     if pkgs:         lines.append(f"- Installed wiki packages ({len(pkgs)}): "
tests/test_where_linux.pyadded+49
@@ -0,0 +1,49 @@+"""adom-context on Hydrogen's Linux workspace (systemd-nspawn): which machine is "here"."""+import importlib.machinery+import importlib.util+from pathlib import Path+import unittest++PKG = Path(__file__).resolve().parents[1]+_loader = importlib.machinery.SourceFileLoader("adom_context", str(PKG / "adom-context"))+_spec = importlib.util.spec_from_loader("adom_context", _loader)+ac = importlib.util.module_from_spec(_spec)+_loader.exec_module(ac)++MACHINES = {"primary": None, "machines": [+    {"name": "AdomLapper", "os": "Windows", "reachable": True, "primary": False},+    {"name": "hl-ubuntu", "os": "Linux", "reachable": True, "primary": False},+    {"name": "arav-rog", "os": "Windows", "reachable": True, "primary": False},+]}+++def where(kind, host):+    return {"kind": kind, "host": host, "windows_drive": None}+++class HereMachineTest(unittest.TestCase):+    def test_linux_workspace_with_its_pc_name(self):+        self.assertEqual(ac.here_machine(where("hydrogen-local-linux", "hl-ubuntu"), MACHINES), "hl-ubuntu")++    def test_linux_workspace_with_the_image_name_is_never_the_windows_pc(self):+        # hl-ubuntu 2026-11-03: the image said AdomLapper; Claude told John it ran on AdomLapper.+        self.assertEqual(ac.here_machine(where("hydrogen-local-linux", "AdomLapper"), MACHINES), "hl-ubuntu")++    def test_wsl_matches_by_name(self):+        self.assertEqual(ac.here_machine(where("hydrogen-local", "arav-rog"), MACHINES), "arav-rog")++    def test_cloud_container_has_no_here(self):+        self.assertIsNone(ac.here_machine(where("container", "hl-ubuntu"), MACHINES))++    def test_linux_render_names_the_default_and_no_c_drive(self):+        out = ac.render({"where": where("hydrogen-local-linux", "AdomLapper"),+                         "hydrogen": {"url": "http://127.0.0.1:47084", "up": True},+                         "identity": None, "machines": MACHINES, "packages": [], "last_update": None})+        self.assertIn("own Linux PC (hl-ubuntu)", out)+        self.assertIn("hl-ubuntu (this PC) is the default", out)+        self.assertNotIn("/mnt/c", out)+        self.assertNotIn("AdomLapper (Windows, reachable, this PC)", out)+++if __name__ == "__main__":+    unittest.main()