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:
parent
c8b70afdbf
commit
3e9ebeed42
10 changed files with 266 additions and 109 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue