diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6715bb04..33dd536a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1001,7 +1001,12 @@ jobs: mods=$(for f in $files; do printf 'tests.%s ' "${f%.py}"; done) echo "unittest suites: $mods" declared=$(cd tests && cat $files | grep -c 'def test_') - out=$(python3 -m unittest $mods 2>&1) + # Under bash -e a failing run used to end the step right here, having + # printed nothing but the list above (2026-09-23): say what failed. + out=$(python3 -m unittest $mods 2>&1) || { + echo "$out" | grep -vF ResourceWarning | tail -80 + echo "the unittest suites failed:"; echo "$out" | grep -E '^(FAIL|ERROR):' || true + exit 1; } echo "$out" | grep -vF ResourceWarning | tail -5 ran=$(echo "$out" | grep -oE '^Ran [0-9]+' | grep -oE '[0-9]+' || echo 0) echo "declared $declared, ran $ran" diff --git a/CHANGELOG.md b/CHANGELOG.md index f263248e..42cb4c9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,52 @@ # Changelog +## v1.18.4 (unreleased): a fresh box's opencode knows the box's model, and says so when it cannot + +**The case v1.18.3 missed, a DGX Spark with no opencode and no opencode config.** The +installer generates its opencode config under `~/.config/qwen38/` and nothing points +opencode there: no `OPENCODE_CONFIG`, not in `oc`, not in the Agent tab's unit. A box with +no `~/.config/opencode/opencode.json` got a printed `cp` command, so v1.18.3 installed +opencode on it and left it with no provider for the model the box serves. Reproduced in a +throwaway HOME: "Error: Provider not found: qwen38". The installer now installs its config +when the box has none; a config you already have is still never overwritten, and when it +has none of this repo's providers the installer says so. The same throwaway HOME after the +fix, with the installer's own lines and the real download: opencode 1.18.32 installed and +checked, the config in place, `qwen38/qwen3.8-27b` listed, and a real turn answered "OK" +in 7 s through the proxy, with no model named on the command line. + +**The same box, one lane later.** That copy lists the lanes the box had at its first +install. Installing the flash lane afterwards (`MODEL_CHOICE=flash ./install.sh`) left it as +it was, with no `flashnext` provider: the limits merge found nothing to merge, the default +model stayed on the 27B, and the NOTE printed said to re-run `./install.sh`, which did the +same again. The served model answers under any name, so nothing failed at first: opencode +sent the 27B's limits (700,000 on a 1M install) to a lane whose proxy refuses a prompt past +250,000 tokens, and a long session would be refused well before opencode compacted it. A +config that already has one of this repo's providers now gains the provider of each lane +installed since, by the same kind of targeted edit as the other merges (a backup first, the +file read back and compared, restored if anything else moved). A config with none of them is +still the user's own and still only gets the message. Replayed with the installer's own +lines in a throwaway HOME, the 27B then flash: before, `qwen38/qwen3.8-27b` at 700000/200000 +while flash served; after, the default on `flashnext/qwen3.8-flash-next` at 225000/32000, and +the real opencode 1.18.32 listing both and answering a turn. + +**What a missing opencode says, everywhere a first-time user meets it**: +- `install.sh` says it is installing opencode rather than naming a version, and when the + download fails, that opencode is still not installed and what to run, instead of + "opencode left as it was"; its last lines say whether opencode is there and which one. +- Those last lines name what starts it from the user's own shell: `oc`, or its full path + when `~/.local/bin` is new and not yet in that shell's PATH, or the plain opencode command + when another program owns `oc` (the launcher is not installed then, and `oc` would run that + program). The config they name is the one opencode reads, not the generated copy. +- `oc` with no opencode says so and names the command, instead of a shell error on a + path. +- The cockpit's Agent tab tells a box with no opencode (re-run `./install.sh`, which + installs the pinned one and the tab) from a box where only the tab is missing + (`dashboard/install-agent.sh`). + +**CI**: the step that runs every unittest suite of `tests/` in one process printed only +their names when one of them failed, because `bash -e` ended it on the assignment that +captured the run. It now prints the end of the run and names the failing tests. + ## v1.18.3 (2026-09-23): the same opencode on every box **Until now the repo installed no opencode at all**: it took whatever was on `PATH`, and diff --git a/dashboard/cockpit.py b/dashboard/cockpit.py index d8db8576..dd865af2 100644 --- a/dashboard/cockpit.py +++ b/dashboard/cockpit.py @@ -824,8 +824,14 @@ def opencode_pinned() -> str | None: def collect_agent(): out = {"node_id": "local", "enabled": AGENT_PORT > 0, "relay": dict(AGENT), "upstream": AGENT_UPSTREAM, "unit": None, "server": None, "binary": None, - "credentials": AGENT_ENV_FILE.is_file(), "unit_installed": AGENT_UNIT_PATH.is_file()} + "credentials": AGENT_ENV_FILE.is_file(), "unit_installed": AGENT_UNIT_PATH.is_file(), + "pinned": opencode_pinned()} if AGENT_PORT <= 0: + # Not installed: is it because this box has no opencode at all? That changes what + # to run (install.sh installs the pinned one; install-agent.sh only wires it up). + # This service's own PATH may lack ~/.opencode/bin, which is where install.sh puts it. + home_bin = Path.home() / ".opencode" / "bin" / "opencode" + out["opencode_found"] = shutil.which("opencode") or (str(home_bin) if home_bin.is_file() else None) return out raw = run(["systemctl", "show", AGENT_UNIT, "-p", "ActiveState,SubState,UnitFileState,ExecMainStartTimestamp"]) d = dict(line.split("=", 1) for line in raw.splitlines() if "=" in line) diff --git a/dashboard/static/app.js b/dashboard/static/app.js index dd3d861c..485862c6 100644 --- a/dashboard/static/app.js +++ b/dashboard/static/app.js @@ -987,8 +987,15 @@ function rAgent(d){ setText('agline', 'one install on the box adds opencode here, behind this login'); ['agopen', 'agreload', 'agrestart'].forEach(id => { $(id).hidden = true; }); $('agnote').hidden = true; - agentMessage('The Agent tab is not installed on this cockpit. On the box, with opencode on your PATH, run:', - ((F.config || {}).terminal_only || {}).install_agent || 'dashboard/install-agent.sh'); + // No opencode at all is the first-time case: install.sh installs the pinned one and + // then this tab. With opencode there, only the tab is missing. + if (d.opencode_found === null) + agentMessage(`opencode is not installed on this box, and this tab runs it. On the box, re-run the installer: ` + + `it installs the opencode this repo tests${d.pinned ? ` (${d.pinned})` : ''}, then this tab.`, + 'cd ~/dgx-spark-qwen38 && ./install.sh'); + else + agentMessage('The Agent tab is not installed on this cockpit. opencode is on the box; to add the tab, run on the box:', + ((F.config || {}).terminal_only || {}).install_agent || 'dashboard/install-agent.sh'); badge('agent', '', ''); return; } const r = d.relay || {}, sv = d.server || {}, u = d.unit || {}; diff --git a/docs/opencode.md b/docs/opencode.md index ad732a1e..568ce604 100644 --- a/docs/opencode.md +++ b/docs/opencode.md @@ -4,11 +4,17 @@ What the installer writes for [opencode](https://opencode.ai), why each piece is The installer writes a complete, ready-to-use [opencode](https://opencode.ai) config at `~/.config/qwen38/opencode.json` (the API key is referenced via `{file:...}`, no secret inside). It contains one provider per installed engine (`qwen38` for the 27B pair, `flashnext` for flash), each with `low` / `medium` / `xhigh` reasoning-effort variants (no variant = the template's own default, xhigh), and its default model follows the installed target (`./switch-model.sh` re-points it on every switch): +A box with no opencode config of its own gets this one as `~/.config/opencode/opencode.json` +(since v1.18.4: before, it was printed as a `cp` command, and a first install left opencode, +`oc` and the Agent tab with no provider for the box's own model, "Provider not found: qwen38"). +A config you already have is kept: the installer merges the served lane's limits into it, +and adds the provider of a lane installed since (the 27B first, the flash lane later) when +it already has one of this repo's providers. When it has none of them, the installer says +so and leaves it alone: merge the `qwen38` (and/or `flashnext`) block from +`~/.config/qwen38/opencode.json` into it yourself. + ```bash -# no opencode config yet? use it as-is: -mkdir -p ~/.config/opencode && cp ~/.config/qwen38/opencode.json ~/.config/opencode/opencode.json -# already have one? merge the "qwen38" (and/or "flashnext") provider block into it -opencode +oc # opencode on this box's model, with the output cap lifted (see below) ``` ## Which opencode: one pinned version, on every box @@ -50,7 +56,7 @@ install. ## Opting out -Do not want any of it? `./install.sh --no-opencode` (one-liner: `| bash -s -- --no-opencode`) installs the API only: no generated config, no `oc` launcher, and `switch-model.sh` never touches your opencode default model. The choice is remembered by later runs (marker `~/.config/qwen38/opencode.off`); `./install.sh --with-opencode` turns it back on. Your own `~/.config/opencode/opencode.json` is never rewritten in either mode: when the integration is on, the installer only merges into it the served lane's limits, its compaction block and, with the version pinned, `"autoupdate": "notify"`, each by a targeted edit that keeps your comments and your other providers, with a dated backup first. +Do not want any of it? `./install.sh --no-opencode` (one-liner: `| bash -s -- --no-opencode`) installs the API only: no generated config, no `oc` launcher, and `switch-model.sh` never touches your opencode default model. The choice is remembered by later runs (marker `~/.config/qwen38/opencode.off`); `./install.sh --with-opencode` turns it back on. Your own `~/.config/opencode/opencode.json` is never rewritten in either mode: when the integration is on, the installer only merges into it the served lane's limits, its compaction block, the provider of a lane installed since and, with the version pinned, `"autoupdate": "notify"`, each by a targeted edit that keeps your comments and your other providers, with a dated backup first. What the shipped config gets right for you: diff --git a/install.sh b/install.sh index e65dd661..c30252ec 100755 --- a/install.sh +++ b/install.sh @@ -1179,17 +1179,17 @@ OC_HOME_BIN="$HOME/.opencode/bin/opencode" OC_HOME_DIR="${OC_HOME_BIN%/opencode}" oc_version(){ { "$1" --version 2>/dev/null || true; } | tail -1 | tr -d 'v[:space:]'; } ver_lt(){ [ "$1" != "$2" ] && [ "$(printf '%s\n%s\n' "$1" "$2" | sort -V | head -1)" = "$1" ]; } -oc_fetch_pinned(){ +oc_fetch_pinned(){ # prints the cause of a failure; the caller says what it leaves behind local tmp url="https://github.com/anomalyco/opencode/releases/download/v$OPENCODE_VERSION/opencode-linux-arm64.tar.gz" tmp="$(mktemp -d)" if ! curl -fsSL --retry 3 -m 600 -o "$tmp/oc.tar.gz" "$url"; then - rm -rf "$tmp"; echo "NOTE: could not download opencode $OPENCODE_VERSION ($url); opencode left as it was"; return 1 + rm -rf "$tmp"; echo "NOTE: could not download opencode $OPENCODE_VERSION ($url)"; return 1 fi if ! printf '%s %s\n' "$OPENCODE_SHA256" "$tmp/oc.tar.gz" | sha256sum -c --quiet - >/dev/null 2>&1; then - rm -rf "$tmp"; echo "NOTE: the opencode $OPENCODE_VERSION download does not match its pinned sha256; nothing was installed"; return 1 + rm -rf "$tmp"; echo "NOTE: the opencode $OPENCODE_VERSION download does not match its pinned sha256, so it was not installed"; return 1 fi if ! tar -xzf "$tmp/oc.tar.gz" -C "$tmp" opencode; then - rm -rf "$tmp"; echo "NOTE: the opencode archive did not unpack; opencode left as it was"; return 1 + rm -rf "$tmp"; echo "NOTE: the opencode $OPENCODE_VERSION archive did not unpack"; return 1 fi mkdir -p "$OC_HOME_DIR" # a new file renamed over the old one: a server still running the old binary keeps it @@ -1208,8 +1208,20 @@ if [ "$OPENCODE_PIN" != "1" ]; then elif [ "$OC_HAVE" = "$OPENCODE_VERSION" ]; then echo "opencode $OC_HAVE: the version this repo tests" elif [ -z "$OC_FOUND" ] || { [ "$OC_FOUND" -ef "$OC_HOME_BIN" ] && ver_lt "$OC_HAVE" "$OPENCODE_VERSION"; }; then - echo "opencode ${OC_HAVE:+$OC_HAVE -> }$OPENCODE_VERSION: the release asset, checked against its pinned sha256" - if oc_fetch_pinned; then OC_FOUND="$OC_HOME_BIN"; OC_HAVE="$(oc_version "$OC_HOME_BIN")"; fi + if [ -z "$OC_FOUND" ]; then + echo "opencode is not installed: installing $OPENCODE_VERSION (the release asset, checked against its pinned sha256)" + else + echo "opencode $OC_HAVE -> $OPENCODE_VERSION: replacing it with the release asset, checked against its pinned sha256" + fi + if oc_fetch_pinned; then + OC_FOUND="$OC_HOME_BIN"; OC_HAVE="$(oc_version "$OC_HOME_BIN")" + echo "opencode $OC_HAVE installed at $OC_HOME_BIN" + elif [ -z "$OC_FOUND" ]; then + echo " opencode is still not installed, and the Agent tab and the oc launcher need it. Re-run ./install.sh" + echo " once GitHub is reachable, or install it from https://opencode.ai (this repo tests $OPENCODE_VERSION)." + else + echo " opencode stays at $OC_HAVE." + fi elif ver_lt "$OC_HAVE" "$OPENCODE_VERSION"; then echo "opencode $OC_HAVE -> $OPENCODE_VERSION through opencode's own upgrader ($OC_FOUND)" "$OC_FOUND" upgrade "$OPENCODE_VERSION" /dev/null 2>&1 \ @@ -1357,12 +1369,29 @@ print(f"wrote {cfg_dir}/opencode.json (default {default}, " PYEOF echo "opencode limits: context $OC_CTX, output $OC_OUT, port $OC_PORT" echo " compaction fires at $((OC_CTX - 20000)) tokens and keeps $OC_KEEP verbatim" -echo " no opencode config yet: mkdir -p ~/.config/opencode && cp $CONFIG_DIR/opencode.json ~/.config/opencode/opencode.json" -echo " existing config: merge the \"qwen38\" provider block into it (README, \"opencode integration\")" +OC_USER_CFG="$HOME/.config/opencode/opencode.json" +# A box with no opencode config of its own gets this one. There is nothing to merge +# into and nothing of the user's to keep, and nothing else points opencode at the file +# above: without this, a first install left opencode, oc and the Agent tab with no +# provider for the model the box serves, and a printed cp command to find. +if [ ! -e "$OC_USER_CFG" ]; then + mkdir -p "$HOME/.config/opencode" + install -m 644 "$CONFIG_DIR/opencode.json" "$OC_USER_CFG" + echo " no opencode config yet: installed this repo's at $OC_USER_CFG" +elif ! grep -qsE '"(qwen38|flashnext)"' "$OC_USER_CFG"; then + # the user's own config, with none of this repo's providers in it: theirs to merge + echo " your $OC_USER_CFG has no provider for this box: merge the \"qwen38\" (or \"flashnext\")" + echo " block from $CONFIG_DIR/opencode.json into it (docs/opencode.md)" +else + # A config set up for this box, by the copy above or by hand, lists the lanes the + # box had then. A lane installed since (the 27B first, the flash lane later) brings + # its provider in: without it the merges below find nothing to merge, and opencode + # sends the other lane's limits and label to the one that serves. + python3 "$REPO_DIR/oc-merge-limits.py" "$OC_USER_CFG" --add-providers "$CONFIG_DIR/opencode.json" || true +fi # An existing opencode.json keeps the user's other providers, but its limits for # THIS lane must follow the served engine (v1.5.2: a flash conversation allowed # to grow to 226000 tokens outgrew the 159k KV pool and wedged the scheduler). -OC_USER_CFG="$HOME/.config/opencode/opencode.json" if [ -f "$OC_USER_CFG" ] && [ "$OPENCODE_PIN" = "1" ]; then python3 "$REPO_DIR/oc-merge-limits.py" "$OC_USER_CFG" --autoupdate notify || true fi @@ -1438,6 +1467,10 @@ else export OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX="\${OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX:-$OC_OUT_CAP}" OPENCODE_BIN="\$(command -v opencode || true)" [ -n "\$OPENCODE_BIN" ] || OPENCODE_BIN="\$HOME/.opencode/bin/opencode" +if [ ! -x "\$OPENCODE_BIN" ]; then + echo "oc: opencode is not installed. Re-run ./install.sh in $REPO_DIR: it installs the opencode this repo tests ($OPENCODE_VERSION)." >&2 + exit 127 +fi # --yolo goes LAST: opencode's parser rejects global flags before a # subcommand (opencode --yolo run ... prints the help instead of running) exec "\$OPENCODE_BIN" "\$@" --yolo @@ -1446,7 +1479,8 @@ OCWRAP echo "installed the oc launcher at $OC_BIN (output ceiling $OC_OUT_CAP, this target's limit $OC_OUT)" case ":$PATH:" in *":$HOME/.local/bin:"*) ;; - *) echo "NOTE: $HOME/.local/bin is not in your PATH; add it or call $OC_BIN directly." ;; + *) echo "NOTE: $HOME/.local/bin is not in this shell's PATH: a new login has it (Ubuntu's ~/.profile" + echo " adds it once the folder exists), or call $OC_BIN directly." ;; esac fi fi @@ -1866,7 +1900,24 @@ except Exception as e: echo " Anthropic : http://:$PORT/v1/messages (Bearer auth only)" echo " API key : $CONFIG_DIR/api-key" if [ "$OPENCODE" -eq 1 ]; then - echo " opencode : provider config ready at $CONFIG_DIR/opencode.json (README, \"opencode integration\")" + OC_NOW="$( { opencode --version 2>/dev/null || true; } | tail -1 | tr -d 'v[:space:]')" + # What starts it from the user's own shell: this script's PATH is not theirs, the + # launcher is skipped when another oc exists, and ~/.local/bin may be new. + OC_START="oc" + if ! grep -qs 'dgx-spark-qwen38' "$HOME/.local/bin/oc"; then + OC_START="${OC_OUT_CAP:+OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX=$OC_OUT_CAP }opencode --yolo" + elif [ "$(command -v oc || true)" != "$HOME/.local/bin/oc" ]; then + OC_START="$HOME/.local/bin/oc" + fi + OC_READS="${OC_USER_CFG:-$HOME/.config/opencode/opencode.json}" + if [ -z "$OC_NOW" ]; then + echo " opencode : NOT installed (see step 7). Its config is ready at $OC_READS;" + echo " re-run ./install.sh to install it, or get it from https://opencode.ai" + elif [ "$OC_NOW" = "$OPENCODE_VERSION" ]; then + echo " opencode : $OC_NOW, the version this repo tests; start it with: $OC_START (config: $OC_READS)" + else + echo " opencode : $OC_NOW (this repo tests $OPENCODE_VERSION); start it with: $OC_START (config: $OC_READS)" + fi else echo " opencode : integration off (--no-opencode); ./install.sh --with-opencode turns it on" fi diff --git a/oc-merge-limits.py b/oc-merge-limits.py index 19fa21b4..9d5a7b0b 100755 --- a/oc-merge-limits.py +++ b/oc-merge-limits.py @@ -5,6 +5,7 @@ Usage: oc-merge-limits.py oc-merge-limits.py --compaction oc-merge-limits.py --add-variant oc-merge-limits.py --autoupdate notify + oc-merge-limits.py --add-providers Only the "limit" object of the named provider/model is rewritten, in place, by targeted text substitution: comments, ordering and the user's other @@ -225,11 +226,90 @@ def add_variant(path: str, provider: str, model: str, level: str) -> int: return 0 +OURS = ("qwen38", "flashnext") + + +def _added_ok(text: str, before: dict, blocks: dict) -> str: + """'' when text is the document `before` plus exactly `blocks` in its provider object.""" + try: + doc = json.loads(re.sub(r"^\s*//.*$", "", text, flags=re.M)) + except json.JSONDecodeError as e: + return f"file no longer parses: {e}" + prov = doc.get("provider") + if not isinstance(prov, dict): + return "provider object vanished" + for name, block in blocks.items(): + if prov.get(name) != block: + return f"provider {name} reads back differently" + rest = dict(doc, provider={k: v for k, v in prov.items() if k not in blocks}) + return "" if rest == before else "something else in the file changed" + + +def add_providers(path: str, source: str) -> int: + """Add this repo's providers that `source` has and the config at `path` lacks. + + install.sh gives a box with no opencode config its own, and never overwrites one + that exists. A box that installed the 27B first and the flash lane later kept the + first install's copy, with no flashnext provider: the limits merge found nothing + to merge and the default model could not follow the lane. The served model answers + under any name, so nothing failed; opencode sent the 27B's limits and label to the + flash lane. Only a config that already has one of this repo's providers gains the + others: a config with none is the user's own, and install.sh says what to merge. + """ + try: + text = open(path).read() + except OSError as e: + print(f"cannot read {path}: {e}") + return 1 + try: + doc = json.loads(re.sub(r"^\s*//.*$", "", text, flags=re.M)) + src = json.loads(open(source).read()) + except (OSError, json.JSONDecodeError) as e: + print(f"{path} or {source} is not valid JSON(C): {e}") + return 1 + have = doc.get("provider") if isinstance(doc.get("provider"), dict) else {} + if not any(p in have for p in OURS): + print(f"none of this repo's providers in {path}: nothing to add to") + return 3 + blocks = {p: b for p, b in (src.get("provider") or {}).items() if p in OURS and p not in have} + if not blocks: + print(f"{path} already lists this box's providers: unchanged") + return 0 + entry = "".join(f"\n {json.dumps(p)}: " + json.dumps(b, indent=2).replace("\n", "\n ") + "," + for p, b in blocks.items()) + # The provider object's opening brace is the first candidate that yields exactly + # the intended document: a commented-out line or a nested key cannot take it. + new_text = None + for m in re.finditer(r'"provider"\s*:\s*\{', text): + tail = text[m.end():] + cand = text[:m.end()] + entry + ("" if tail[:1].isspace() else "\n ") + tail + if not _added_ok(cand, doc, blocks): + new_text = cand + break + if new_text is None: + print(f"{path}: refused, found no place for the {', '.join(blocks)} provider; " + f"copy it by hand from {source}") + return 1 + backup = f"{path}.bak-{time.strftime('%Y%m%d-%H%M%S')}" + shutil.copy2(path, backup) + with open(path, "w") as f: + f.write(new_text) + bad = _added_ok(open(path).read(), doc, blocks) + if bad: + shutil.copy2(backup, path) + print(f"{path}: refused, {bad}; restored from {backup}.") + return 1 + print(f"{', '.join(blocks)} provider added to {path}, for the lane installed since (backup {backup})") + return 0 + + def main(argv: list[str]) -> int: if len(argv) == 4 and argv[2] == "--compaction": return merge_compaction(argv[1], int(argv[3])) if len(argv) == 4 and argv[2] == "--autoupdate": return merge_autoupdate(argv[1], argv[3]) + if len(argv) == 4 and argv[2] == "--add-providers": + return add_providers(argv[1], argv[3]) if len(argv) == 6 and argv[4] == "--add-variant": return add_variant(argv[1], argv[2], argv[3], argv[5]) if len(argv) != 6: diff --git a/tests/test_install_opencode_pin.py b/tests/test_install_opencode_pin.py index 9bb0f825..d871d7ae 100644 --- a/tests/test_install_opencode_pin.py +++ b/tests/test_install_opencode_pin.py @@ -11,6 +11,7 @@ in a throwaway HOME, against a fake curl and fake opencode binaries. """ import hashlib import io +import json import os import pathlib import subprocess @@ -103,6 +104,8 @@ class TheOpencodePin(unittest.TestCase): def test_absent_it_installs_the_release_checked_against_its_sha256(self): rc, out, calls = self.run_block() self.assertEqual(rc, 0, out) + self.assertIn(f"opencode is not installed: installing {PINNED}", out) + self.assertIn(f"opencode {PINNED} installed at {self.home_bin}", out) self.assertEqual(self.version_of(self.home_bin), PINNED) self.assertEqual(calls, [f"curl https://github.com/anomalyco/opencode/releases/download/v{PINNED}" "/opencode-linux-arm64.tar.gz"]) @@ -142,6 +145,15 @@ class TheOpencodePin(unittest.TestCase): self.assertEqual(calls, []) self.assertEqual(self.version_of(self.home_bin), "1.18.40") + def test_a_first_install_that_cannot_download_says_what_is_missing_and_what_to_run(self): + (self.bin / "curl").write_text("#!/bin/sh\nexit 22\n") + rc, out, _ = self.run_block() + self.assertEqual(rc, 0, out) + self.assertIn("could not download opencode", out) + self.assertIn("opencode is still not installed", out) + self.assertIn("Re-run ./install.sh", out) + self.assertNotIn("installed at", out) + def test_a_download_that_does_not_match_its_sha256_is_not_installed(self): self.opencode_at(self.home / ".opencode" / "bin", "1.18.27") rc, out, _ = self.run_block(sha="0" * 64) @@ -206,5 +218,144 @@ class TheCockpitNamesThePin(unittest.TestCase): self.assertIn("if (d.pinned && sv.version && sv.version !== d.pinned)", js) self.assertIn("./install.sh brings it in line", js) + +class AMissingOpencodeIsSaidPlainly(unittest.TestCase): + """A first-time user with no opencode must read what is missing and what to run, in + the installer's last lines, from the oc launcher and in the cockpit's Agent tab.""" + + def test_the_oc_launcher_says_so_instead_of_failing_on_a_path(self): + text = INSTALL.read_text() + start = text.index('cat > "$OC_BIN" < None: assert m._verify_compaction(p, 50000) == "" assert "expected 7" in m._verify_compaction(p, 7) + # 7. --add-providers: the config a box's first install wrote gains the provider of a + # lane installed since, and nothing else in it moves. The 27B first and the flash + # lane later left the copy with no flashnext: the served model answers under any + # name, so opencode sent the 27B's limits and label to the flash lane. + def add(path, source): + r = subprocess.run([sys.executable, SCRIPT, path, "--add-providers", source], + capture_output=True, text=True) + return r.returncode, (r.stdout + r.stderr).strip() + + flash = {"npm": "@ai-sdk/openai-compatible", "name": "Qwen3.8-Flash-Next (DGX Spark)", + "options": {"baseURL": "http://127.0.0.1:30001/v1", "apiKey": "{file:/k}"}, + "models": {"qwen3.8-flash-next": {"limit": {"context": 1, "input": 1, "output": 1}}}} + gen = os.path.join(tmp, "generated.json") + with open(gen, "w") as f: + json.dump({"provider": {"qwen38": {"models": {"qwen3.8-27b": {}}}, "flashnext": flash}}, f, indent=2) + # a commented-out "provider" line and a nested "provider" key come before the real one + p = write(tmp, '{\n // "provider": { a line the user commented out\n' + ' "agent": {"a": {"provider": {"z": 1}}},\n' + ' "provider": {\n // mine\n' + ' "qwen38": {"models": {"qwen3.8-27b": {"limit": {"context": 5}}}},\n' + ' "other": {}\n }\n}\n') + before = doc_of(p) + rc, out = add(p, gen) + assert rc == 0 and "flashnext provider added" in out, out + after = doc_of(p) + assert after["provider"].pop("flashnext") == flash, "the provider was not copied as generated" + assert after == before, "adding a provider moved something else" + assert "// mine" in open(p).read() and "commented out" in open(p).read(), "a comment was dropped" + rc, out = add(p, gen) + assert rc == 0 and "unchanged" in out, out + + # A config with none of this repo's providers is the user's own: exit 3, untouched. + for body in ('{"provider": {"anthropic": {}}}\n', '{"model": "x"}\n'): + p = write(tmp, body) + rc, out = add(p, gen) + assert rc == 3 and open(p).read() == body, f"{body!r}: rc={rc} {out}" + + # The check that picks the insertion point refuses anything else that moved. + base, blk = {"provider": {"qwen38": {}}, "x": 1}, {"flashnext": {"a": 1}} + assert m._added_ok('{"provider": {"flashnext": {"a": 1}, "qwen38": {}}, "x": 1}', base, blk) == "" + assert "changed" in m._added_ok('{"provider": {"flashnext": {"a": 1}, "qwen38": {}}, "x": 2}', base, blk) + assert "differently" in m._added_ok('{"provider": {"flashnext": {"a": 2}, "qwen38": {}}, "x": 1}', base, blk) + print("test_oc_merge_limits: OK")