Hand out the right opencode command: the API's public URL, and setup uses the install script

install-newt now asks for the API's public URL first (--api-url) and records it; it names
the Pangolin resource and refuses an endpoint on the same host. expose-dashboard records
only that the dashboard is public. One rule (opencode.client_targets) decides which
opencode-install.sh commands are shown -- local only without a tunnel; internet and local
with one; internet only once the dashboard is public -- and setup's closing message,
`llmhost opencode-config` and the dashboard's Connect dialog all use it.

Setup's offer to install opencode now goes through opencode-install.sh --install-only, a
new mode that only installs opencode; this machine's own provider is still configured by
llm-host, which keeps it in sync on every switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
neil 2026-11-06 18:35:41 -08:00
parent c8b70afdbf
commit 3e9ebeed42
10 changed files with 266 additions and 109 deletions

View file

@ -109,8 +109,20 @@ check("opencode block is the openai-compatible provider", blk["npm"] == "@ai-sdk
check("opencode block offers the one alias", list(blk["models"]) == [cx["model"]] == ["default"], blk["models"])
check("opencode block leaves the address to the page", "LABEL" in blk["name"] and "HOST" in blk["options"]["baseURL"], blk)
check("the key isn't inlined in the block", KEY not in json.dumps(blk))
check("installer URL is a raw file in the repo", cx["installer"].startswith("https://")
and cx["installer"].endswith("/opencode-install.sh"), cx["installer"])
check("one address before any tunnel: the LAN", len(cx["targets"]) == 1
and cx["targets"][0]["url"].endswith(f":{harness.config()['api_port']}"), cx["targets"])
check("with its opencode-install.sh command", "/opencode-install.sh)\" -- --url http://" in cx["targets"][0]["command"],
cx["targets"])
c2 = harness.config(); c2["newt"] = {"endpoint": "https://p.example.test", "id": "x", "api_url": "https://llm-api.example.test"}
paths.save_config(c2)
cx = json.loads(req(srv, "GET", "/api/connect", {"Authorization": f"Bearer {KEY}"})[2])
check("tunnel, local dashboard: internet then LAN", [t["where"] for t in cx["targets"]]
== ["from the internet", "on your local network"] and cx["targets"][0]["url"] == "https://llm-api.example.test", cx["targets"])
c2["dashboard_public"] = True
paths.save_config(c2)
cx = json.loads(req(srv, "GET", "/api/connect", {"Authorization": f"Bearer {KEY}"})[2])
check("public dashboard: the internet only", [t["url"] for t in cx["targets"]] == ["https://llm-api.example.test"], cx["targets"])
paths.save_config(harness.config())
R = web.raw_file_url
check("raw URL for a Gitea/Forgejo repo", R("https://git.example.com/pub/llm-host.git", "main", "f.sh")
== "https://git.example.com/pub/llm-host/raw/branch/main/f.sh")

View file

@ -77,7 +77,9 @@ cfg = harness.config()
paths.save_config(cfg)
paths.api_key(create=True)
NEWT_ARGS = ["install-newt", "--endpoint", "https://pangolin.example.test", "--newt-id", "site123"]
NEWT_ARGS = ["install-newt", "--api-url", "https://llm-api.example.test", "--endpoint", "https://pangolin.example.test",
"--newt-id", "site123"]
NEWT_CONF = {"endpoint": "https://pangolin.example.test", "id": "site123", "api_url": "https://llm-api.example.test"}
OIDC_ARGS = ["install-oidc", "--public-url", "https://dash.example.test", "--issuer", ISSUER,
"--client-id", "client-from-provider", "--allow-group", "llm-admins"]
@ -102,13 +104,25 @@ check("download URL is the pinned GitHub release",
fetches[-1].startswith(f"https://github.com/fosrl/newt/releases/download/{newt.VERSION}/newt_"), fetches)
print("\n3. install-newt: the API only")
print("\n3a. the client commands before the tunnel: the local network only")
code, out = run(["opencode-config"])
check("opencode-config: one command, the LAN address", code == 0 and out.count("opencode-install.sh") == 1
and f"--url http://{cli.default_host()}:{cfg['api_port']}" in out, out)
code, out = run(["install-newt", "--endpoint", "https://pangolin.example.test", "--newt-id", "x"],
{"LLMHOST_NEWT_SECRET": NEWT_SECRET})
check("the API's public URL is required", code != 0 and "--api-url" in out, out)
code, out = run(["install-newt", "--api-url", "https://pangolin.example.test", "--endpoint", "https://pangolin.example.test",
"--newt-id", "x"], {"LLMHOST_NEWT_SECRET": NEWT_SECRET})
check("API URL = Pangolin endpoint is refused", code != 0 and "can't be the same" in out, out)
code, out = run(NEWT_ARGS)
check("missing secret without a terminal -> error", code != 0 and "LLMHOST_NEWT_SECRET" in out, out)
calls.clear()
code, out = run(NEWT_ARGS, {"LLMHOST_NEWT_SECRET": NEWT_SECRET})
c = paths.load_config()
check("succeeds", code == 0, out)
check("newt config saved", c.get("newt") == {"endpoint": "https://pangolin.example.test", "id": "site123"}, c.get("newt"))
check("newt config saved, with the API's public URL", c.get("newt") == NEWT_CONF, c.get("newt"))
check("the resource is named by the API's host", f"llm-api.example.test -> http://" in out, out)
check("prints the opencode command for the public URL", "opencode-install.sh)\" -- --url https://llm-api.example.test" in out, out)
check("dashboard sign-in untouched", "dashboard_auth" not in c and not paths.OIDC_SECRET_FILE.exists())
check("newt service installed and started", ("install", "newt") in calls and ("restart", "newt") in calls, calls)
check("dashboard not restarted", ("restart", "web") not in calls, calls)
@ -119,8 +133,18 @@ check("secret saved 0600, not in config or output",
and NEWT_SECRET not in paths.CONFIG_FILE.read_text() and NEWT_SECRET not in out)
code, out = run(["install-newt", "--newt-id", "site456"])
c = paths.load_config()
check("re-run keeps what it isn't given", code == 0 and c["newt"] == {"endpoint": "https://pangolin.example.test", "id": "site456"}
check("re-run keeps what it isn't given", code == 0 and c["newt"] == {**NEWT_CONF, "id": "site456"}
and paths.NEWT_SECRET_FILE.read_text().strip() == NEWT_SECRET, out)
code, out = run(["install-newt", "--api-url", "https://llm-api.example.test/v1/"])
check("a trailing /v1 is dropped", code == 0 and paths.load_config()["newt"]["api_url"] == "https://llm-api.example.test", out)
print("\n3b. tunnel up, dashboard local: both commands")
code, out = run(["opencode-config"])
check("opencode-config: internet first, then local", code == 0 and out.count("opencode-install.sh") == 2
and out.index("--url https://llm-api.example.test") < out.index(f"--url http://{cli.default_host()}"), out)
check("by hand: for the public URL", '"baseURL": "https://llm-api.example.test/v1"' in out, out)
code, out = run(["status"])
check("status: API URL and a local dashboard", "API at https://llm-api.example.test/v1" in out and "local network only" in out, out)
print("\n4. newt starts with its credentials in the environment, not its arguments")
seen = {}
@ -141,6 +165,12 @@ check("refused when you say no", code != 0 and "Not published" in out, out)
code, out = run(["expose-dashboard", "--public-url", "https://dash.example.test", "--force"])
check("--force walks through it anyway", code == 0 and f":{paths.load_config()['web_port']}" in out
and "dash.example.test" in out, out)
c = paths.load_config()
check("records that the dashboard is public, not where", c.get("dashboard_public") is True
and "dash.example.test" not in json.dumps({k: v for k, v in c.items() if k != "dashboard_auth"}), c.get("dashboard_public"))
code, out = run(["opencode-config"])
check("dashboard public: only the internet command", code == 0 and out.count("opencode-install.sh") == 1
and "--url https://llm-api.example.test" in out and f"http://{cli.default_host()}" not in out.split("Or by hand")[0], out)
print("\n6. install-oidc")
code, out = run(OIDC_ARGS)
@ -209,6 +239,7 @@ code, out = run(["remove-newt"])
c = paths.load_config()
check("newt removed", code == 0 and ("uninstall", "newt") in calls and "newt" not in c
and not paths.NEWT_SECRET_FILE.exists() and not newt.binary().exists(), out)
check("and the dashboard no longer counts as public", "dashboard_public" not in c)
check("rest of the config untouched", c.get("api_port") == cfg.get("api_port") and c.get("models") == cfg.get("models"))
code, out = run(["expose-dashboard"])
check("expose-dashboard needs newt first", code != 0 and "install-newt" in out, out)

View file

@ -327,4 +327,10 @@ check("a non-reasoning model gets no variants", "variants" not in nr["models"]["
check("one entry only, named for the alias, so the client can't pick a model either",
list(q["models"]) == [plan.SERVED_ALIAS], list(q["models"]))
print("\nthe command handed to other machines")
cmd = opencode.remote_command("http://mybox.local:1134")
check("fetches opencode-install.sh from a repo and passes the URL",
cmd.startswith('/bin/bash -c "$(curl -fsSL https://') and '/opencode-install.sh)" -- --url http://mybox.local:1134' in cmd, cmd)
check("the script it names is in this repo", (harness.REPO / "opencode-install.sh").exists())
check.done(ROOT)

View file

@ -172,7 +172,22 @@ code, out = run(home, b, oc, "--url", URL)
check("a .jsonc is never rewritten; the block is printed", code == 0 and "by hand" in out
and (cd / "opencode.jsonc").read_text().startswith("{ // mine") and not (cd / "opencode.json").exists(), out)
print("\n5. --help works when run as `bash -c`")
print("\n5. --install-only, which `llmhost setup` uses")
home, b, oc = sandbox(with_opencode=False)
code, out = run(home, b, oc, "--install-only", key=None)
check("installs without a URL or key", code == 0 and (home / ".opencode/bin/opencode").exists(), out)
check("touches no config", not (home / ".config/opencode").exists())
code, out = run(home, b, oc, "--install-only", key=None)
check("a second run finds it", code == 0 and "already installed" in out, out)
home, b, oc = sandbox(with_opencode=False)
env = {"HOME": str(home), "PATH": f"{b}:/usr/bin:/bin", "FAKE_OPENCODE": str(oc),
"LLMHOST_HOME": str(home / "lh"), "LLMHOST_CONFIG": str(home / "lhc"), "PYTHONPATH": str(harness.REPO)}
r = subprocess.run([sys.executable, "-c", "from llmhost import opencode; print('FOUND', opencode.install(lambda *_: None))"],
env=env, capture_output=True, text=True, timeout=60, stdin=subprocess.DEVNULL, start_new_session=True)
check("llm-host's own opencode install goes through the script",
r.returncode == 0 and f"FOUND {home}/.opencode/bin/opencode" in r.stdout, r.stdout + r.stderr)
print("\n6. --help works when run as `bash -c`")
r = subprocess.run(["bash", "-c", SCRIPT.read_text(), "--", "--help"], capture_output=True, text=True)
check("prints usage", r.returncode == 0 and "--url" in r.stdout, r.stdout + r.stderr)