agent, gui: an agent CLI found off the terminal's PATH says where it is (悠悠哥 on Discord)

悠悠哥 (macOS) saw "Codex 0.162.1 · 未接入" under 未设置 on the Agents
page while `which -a codex` found nothing and ~/.codex wasn't there.
Detected() is true when the agent's command is on magpie's own PATH, and
proc.UserPath adds to it the folders users' tools go in (~/.local/bin,
npm's prefixes, nvm's newest Node, bun, volta, pnpm, Homebrew), which a
desktop app launched from the Finder needs. A codex left in one of those
that the terminal's PATH no longer has (an npm install under a Node nvm
no longer uses) is found, runs, and gives its version, so the row looked
made up. Reproduced in a sandbox HOME: PATH=/usr/bin:/bin, no ~/.codex,
@openai/codex 0.162.1 under ~/.nvm/versions/node/v22.12.0; after
UserPath, Codex is detected with CLI 0.162.1. ChatGPT.app's bundled codex
(Contents/Resources/codex-cli, 0.162.0-alpha here) is never on magpie's
PATH and isn't what was found.

The agent is still listed: the CLI is real and runs (a lazy-loaded nvm
leaves the same folder off a login shell's PATH while the user does run
codex from it). What changes is that it says so. CLI gains path (the
file magpie runs) and offPath (its folder isn't in proc.LoginPath; false
when the login PATH can't be told, or for a CLI found at a fixed path
rather than through PATH). The Agents row shows "Not on your terminal's
PATH" after the version, its tip and the version's naming the file and
that it can be deleted if left from an uninstall; en/zh/zh-TW/ja/de. The
note gives way at the narrow width, where the version's tip still says
it. docs/subsystems/agent-wiring.md says how detection and the note work.

Run: TestCLIFoundOffTerminalPath (red with OffPath forced false);
agent-cli-offpath.test.cjs in Chromium and WebKit, five languages, 560
and 440px (16 failures on the old app.js), with agent-app-version,
agent-cli-missing, cli-update and agent-update-all (66 pass); go test
./internal/agent ./internal/gui; full go test -tags nogui ./...; gofmt;
GOOS=linux and GOOS=windows go vet -tags nogui on both packages.
This commit is contained in:
yetone
2026-10-11 06:03:05 +08:00
parent cb25d3861b
commit 9f407cafa1
7 changed files with 248 additions and 0 deletions
+1
View File
@@ -67,6 +67,7 @@ something else shows up as drift.
- Tuned settings are written only on the user's click, never by Sync or Connect. The value there before is stashed once (`tune.<agent>.<knob>[.<model>]` in `stash.json`), so Undo puts it back, or takes the key out (and a `modelSettings` entry left empty). A value the user changed after the click is theirs: Undo then only forgets the stash. A variable that comes before the setting (`CLAUDE_CODE_AUTO_COMPACT_WINDOW`, `FORCE_PROMPT_CACHING_5M`, `CLAUDE_CODE_PROMPT_CACHE_TTL`, `CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL`, in settings.json's `env` or magpie's own) is shown as `locked` and Apply refuses, since the setting would change nothing. Claude Code compacts at the smaller of the window set and the model's own (its `/autocompact` says "capped to 200k by model"), so advice starts from that, and a model that isn't Claude's has no window here (magpie's own compact wiring serves it). Advice changes a value only when the replay saves 3% or more, and of the windows within 1% of the cheapest takes the largest. Tokens are weighed as billed: cache reads 0.1, 5-minute writes 1.25, hour writes 2, output 5 for Claude; reads 0.1, writes 1, output 8 otherwise.
- A plugin's agent writes each key in place (JSON, YAML or env), the user's comments and other keys kept. What each key held before the first write is stashed under `plugin:<id>:<path>`, typed, and its own model or Disconnect puts every key back and takes out the ones that weren't there; the file is never written whole. A `connect` that throws or takes over a second writes nothing and says why. Its gateway key is `magpie-<id>` (`agentKeyAt`), and usage names its requests by that key or by its `ua` words (`usage.PluginAgents`).
- StepCode config root resolves to the parent of an absolute `STEP_CODING_AGENT_DIR` (agent resources directory differs from config root; relative values ignored), or `STEPCODE_CONFIG_DIR` under home when native, defaulting to `~/.stepcode` ([`stepcode.go`](../../internal/agent/stepcode.go)). Project configs override global configs in StepCode, but magpie manages global configuration only (`config.toml` and `models.json`). Detection is strictly directory-only via `agentDir`, avoiding collision with Smallstep's bare `step` command on `PATH`. Wiring performs an atomic two-file edit (`models.json` provider block and `config.toml` top-level defaults/scope) backed by `stash.json`. Custom fields within `providers.magpie` are preserved during sync, and the original provider block is restored on disconnect. Disconnect restores original defaults, preserves user native changes and custom scope edits, and removes newly created files only when empty.
- An agent is detected by its config file, its folder, or its command on magpie's PATH (`Detected`). That PATH is the login shell's plus the folders users' tools go in (`proc.UserPath`: `~/.local/bin`, npm's prefixes, nvm's newest Node, bun, Homebrew, ...), so a CLI a terminal doesn't find can still be found and listed: an npm install under a Node the terminal no longer uses. `/api/agents/cli` then gives where it is (`path`) and `offPath` when the login shell's PATH (`proc.LoginPath`) lacks its folder, and the Agents row says "Not on your terminal's PATH", its tip naming the file (悠悠哥 on Discord: Codex 0.162.1 listed with no codex on PATH and no `~/.codex`). An unknown login PATH says nothing.
- Tests never touch the real machine. `TestMain` uses `testenv`, which points HOME, USERPROFILE, the XDG folders and APPDATA into a temporary folder, clears `agentenv.Vars` and puts failing stand-ins for keychain tools and agent CLIs on PATH. Agent-specific side effects (Aside, the Zed keychain, Codex's usage check) are also stubbed in `TestMain`.
## Verification
+76
View File
@@ -0,0 +1,76 @@
package agent
import (
"os"
"path/filepath"
"testing"
)
// 悠悠哥 on Discord (macOS): the Agents page listed "Codex 0.162.1" under
// Not set up while `which -a codex` found nothing and ~/.codex wasn't
// there. magpie adds the folders users' tools go in to its own PATH
// (proc.UserPath: nvm's newest Node among them), so a codex installed with
// npm under a Node the terminal no longer uses is found, and runs, though
// no terminal finds it. It is still listed, but its CLI now says where it
// is and that a terminal's PATH doesn't have that folder.
func TestCLIFoundOffTerminalPath(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("CODEX_HOME", "")
was := appFolders
appFolders = func() []string { return nil }
t.Cleanup(func() { appFolders = was })
// npm i -g @openai/codex under nvm's v22.12.0: its bin links into the
// package, whose package.json has the version
node := filepath.Join(home, ".nvm", "versions", "node", "v22.12.0")
pkg := filepath.Join(node, "lib", "node_modules", "@openai", "codex")
if err := os.MkdirAll(filepath.Join(pkg, "bin"), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(pkg, "package.json"), []byte(`{"name":"@openai/codex","version":"0.162.1"}`), 0o644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(pkg, "bin", "codex.js"), []byte("#!/bin/sh\necho codex-cli 0.162.1\n"), 0o755); err != nil {
t.Fatal(err)
}
bindir := filepath.Join(node, "bin")
if err := os.MkdirAll(bindir, 0o755); err != nil {
t.Fatal(err)
}
bin := filepath.Join(bindir, exe("codex"))
if err := os.Symlink(filepath.Join("..", "lib", "node_modules", "@openai", "codex", "bin", "codex.js"), bin); err != nil {
t.Skipf("no symlinks here: %v", err)
}
// magpie's PATH after UserPath has nvm's folder; the terminal's hasn't
t.Setenv("PATH", bindir)
terminal := []string{filepath.Join(home, "elsewhere"), "/usr/bin", "/bin"}
wasLogin := loginPath
t.Cleanup(func() { loginPath = wasLogin })
loginPath = func() []string { return terminal }
dir := filepath.Join(home, ".codex")
codex := &Agent{ID: "codex", Name: "Codex", Bin: "codex", Dir: dir, Path: filepath.Join(dir, "config.toml")}
if !codex.Detected() {
t.Fatal("codex on magpie's PATH not detected")
}
c, ok := codex.CLI()
if !ok || c.Version != "0.162.1" {
t.Fatalf("CLI %+v, %v; want version 0.162.1", c, ok)
}
if c.Path != bin || !c.OffPath {
t.Fatalf("CLI found at %q, off the terminal's PATH %v; want %q, true", c.Path, c.OffPath, bin)
}
// the terminal has the folder: nothing more to say
terminal = append(terminal, bindir)
if c, _ := codex.CLI(); c.Path != bin || c.OffPath {
t.Fatalf("on the terminal's PATH: %+v", c)
}
// a terminal whose PATH can't be told says nothing either
terminal = nil
if c, _ := codex.CLI(); c.OffPath {
t.Fatalf("terminal's PATH unknown: %+v", c)
}
}
+39
View File
@@ -51,6 +51,18 @@ type CLI struct {
// Admin: the update needs an administrator, which Windows asks for
// first (npm's global folder under Program Files)
Admin bool `json:"admin,omitempty"`
// Path is where the CLI was found: the file magpie runs, as PATH
// reached it
Path string `json:"path,omitempty"`
// OffPath says the CLI was found in a folder magpie adds to its own
// PATH (proc.UserPath: ~/.local/bin, npm's prefixes, nvm's newest
// Node, bun, Homebrew, ...) that a terminal opened now doesn't have,
// so that `which` there doesn't find it. A row of an agent the user
// believed uninstalled, with a version and nothing to say where it
// came from, read as magpie making it up (悠悠哥 on Discord: Codex
// 0.162.1 listed with no codex on PATH and no ~/.codex). False when
// the terminal's PATH can't be told.
OffPath bool `json:"offPath,omitempty"`
}
// cliSpec is where an agent's CLI is published.
@@ -584,6 +596,31 @@ var brewLatest = func(u *updater) (string, error) {
return v, nil
}
// loginPath is the PATH a terminal opened now has (proc.LoginPath); a var
// so tests can fake it.
var loginPath = proc.LoginPath
// offPath reports whether bin's folder is none of dirs, a terminal's PATH;
// false when dirs is nil, a PATH that can't be told.
func offPath(bin string, dirs []string) bool {
if dirs == nil {
return false
}
at := filepath.Clean(filepath.Dir(bin))
for _, d := range dirs {
if d == "" {
continue
}
if abs, err := filepath.Abs(d); err == nil {
d = abs
}
if strings.EqualFold(filepath.Clean(d), at) && (runtime.GOOS == "windows" || filepath.Clean(d) == at) {
return false
}
}
return true
}
// cliBin is where the agent's CLI is, "" when it has none magpie knows or
// it isn't on PATH.
func (a *Agent) cliBin() (string, cliSpec) {
@@ -621,6 +658,8 @@ func (a *Agent) CLI() (c CLI, ok bool) {
return c, c.App != ""
}
c.Version = installedVersion(bin)
c.Path = bin
c.OffPath = a.Bin != "" && offPath(bin, loginPath())
u := howInstalled(spec, bin)
if u == nil {
return c, true
+2
View File
@@ -422,6 +422,8 @@ body.window .row.agent .who .ag-cli { flex: 0 1 auto; overflow: hidden; }
and gone where the pill keeps only its arrow */
.ag-app { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
@container (max-width: 250px) { body.window .row.agent .ag-app { display: none; } }
.ag-offpath { flex: 0 1 auto; min-width: 0; }
@container (max-width: 250px) { body.window .row.agent .ag-offpath { display: none; } }
.ag-cli { display: inline-flex; align-items: center; gap: 6px; flex: none; min-width: 0; }
.ag-cli:empty { display: none; }
.ag-missing { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default; }
+10
View File
@@ -1720,6 +1720,16 @@ function cliTag(a) {
: c.update ? t("{agent} {v} is installed · {latest} is out", { agent: a.name, v: c.version, latest: c.latest })
: t("{agent} {v} · up to date", { agent: a.name, v: c.version });
box.append(v);
// found in a folder magpie adds to its own PATH that a terminal's
// doesn't have (an npm install under a Node nvm no longer uses):
// listed though `which` finds nothing, so it says where it is
// (悠悠哥 on Discord: Codex 0.162.1 with no codex on PATH); where the
// row is too tight for the note, the version's tip says it
if (c.offPath && c.path) {
const o = el("span", "ag-missing ag-offpath", t("Not on your terminal's PATH"));
o.title = v.title = t("magpie found {agent} {v} at {path}. That folder is one magpie looks in, but your terminal's PATH doesn't have it, so a terminal won't find {agent} there. If it was left behind by an uninstall, delete it.", { agent: a.name, v: c.version, path: c.path });
box.append(o);
}
}
if (c.update || cliBusy.has(a.id)) {
const b = el("button", "ag-up");
+8
View File
@@ -604,6 +604,8 @@ const I18N = {
"{ok} of {n} agents updated: {list} · {failed} didn't: {names}": "{n} 个 Agent 中已更新 {ok} 个:{list} · {failed} 个未成功:{names}",
"Install another agent ({n})": "安装其他 Agent({n})",
"CLI not found": "未找到 CLI",
"Not on your terminal's PATH": "不在终端的 PATH 里",
"magpie found {agent} {v} at {path}. That folder is one magpie looks in, but your terminal's PATH doesn't have it, so a terminal won't find {agent} there. If it was left behind by an uninstall, delete it.": "magpie 在 {path} 找到了 {agent} {v}。这个文件夹 magpie 会去找,但终端的 PATH 里没有它,所以终端里找不到这个 {agent}。如果它是卸载时没删干净留下的,把它删掉即可。",
"{agent}'s settings are still here ({path}), but its command-line program isn't found: it may have been uninstalled. Install another agent, below the list, has its install command.": "{agent} 的配置还在({path}),但找不到它的命令行程序,可能已被卸载。列表下方的「安装其他 Agent」里有它的安装命令。",
"{agent}'s settings are still here, but its command-line program isn't found": "{agent} 的配置还在,但找不到它的命令行程序",
"Run a command in a terminal, then come back: magpie lists the agent here once it is installed. The npm commands need Node.js (nodejs.org).": "在终端运行任一命令,安装后会列在这里。npm 命令需要 Node.js(nodejs.org)。",
@@ -4817,6 +4819,8 @@ const I18N = {
"{ok} of {n} agents updated: {list} · {failed} didn't: {names}": "{n} 個 Agent 中已更新 {ok} 個:{list} · {failed} 個未成功:{names}",
"Install another agent ({n})": "安裝其他 Agent({n})",
"CLI not found": "未找到 CLI",
"Not on your terminal's PATH": "不在終端機的 PATH 裡",
"magpie found {agent} {v} at {path}. That folder is one magpie looks in, but your terminal's PATH doesn't have it, so a terminal won't find {agent} there. If it was left behind by an uninstall, delete it.": "magpie 在 {path} 找到了 {agent} {v}。這個資料夾 magpie 會去找,但終端機的 PATH 裡沒有它,所以終端機裡找不到這個 {agent}。如果它是解除安裝時沒刪乾淨留下的,把它刪掉即可。",
"{agent}'s settings are still here ({path}), but its command-line program isn't found: it may have been uninstalled. Install another agent, below the list, has its install command.": "{agent} 的設定還在({path}),但找不到它的命令列程式,可能已被解除安裝。列表下方的「安裝其他 Agent」裡有它的安裝命令。",
"{agent}'s settings are still here, but its command-line program isn't found": "{agent} 的設定還在,但找不到它的命令列程式",
"Run a command in a terminal, then come back: magpie lists the agent here once it is installed. The npm commands need Node.js (nodejs.org).": "在終端機執行任一命令,安裝後會列在這裡。npm 命令需要 Node.js(nodejs.org)。",
@@ -8995,6 +8999,8 @@ const I18N = {
"{ok} of {n} agents updated: {list} · {failed} didn't: {names}": "{n} 個中 {ok} 個のエージェントをアップデートしました:{list} · {failed} 個は失敗:{names}",
"Install another agent ({n})": "他のエージェントをインストール({n})",
"CLI not found": "CLI が見つかりません",
"Not on your terminal's PATH": "ターミナルの PATH にありません",
"magpie found {agent} {v} at {path}. That folder is one magpie looks in, but your terminal's PATH doesn't have it, so a terminal won't find {agent} there. If it was left behind by an uninstall, delete it.": "magpie は {agent} {v} を {path} で見つけました。このフォルダは magpie が探す場所ですが、ターミナルの PATH には含まれていないため、ターミナルではこの {agent} は見つかりません。アンインストール時に残ったものなら削除してください。",
"{agent}'s settings are still here ({path}), but its command-line program isn't found: it may have been uninstalled. Install another agent, below the list, has its install command.": "{agent} の設定は残っています({path})が、コマンドラインプログラムが見つかりません。アンインストールされた可能性があります。リストの下の「他のエージェントをインストール」にインストールコマンドがあります。",
"{agent}'s settings are still here, but its command-line program isn't found": "{agent} の設定は残っていますが、コマンドラインプログラムが見つかりません",
"Run a command in a terminal, then come back: magpie lists the agent here once it is installed. The npm commands need Node.js (nodejs.org).": "ターミナルでコマンドを実行してから戻ってください。インストールされると magpie がここにエージェントを表示します。npm コマンドには Node.js(nodejs.org)が必要です。",
@@ -13191,6 +13197,8 @@ const I18N = {
"{ok} of {n} agents updated: {list} · {failed} didn't: {names}": "{ok} von {n} Agenten aktualisiert: {list} · {failed} fehlgeschlagen: {names}",
"Install another agent ({n})": "Weiteren Agenten installieren ({n})",
"CLI not found": "CLI nicht gefunden",
"Not on your terminal's PATH": "Nicht im PATH des Terminals",
"magpie found {agent} {v} at {path}. That folder is one magpie looks in, but your terminal's PATH doesn't have it, so a terminal won't find {agent} there. If it was left behind by an uninstall, delete it.": "magpie hat {agent} {v} unter {path} gefunden. magpie sucht in diesem Ordner, aber der PATH deines Terminals enthält ihn nicht, daher findet ein Terminal {agent} dort nicht. Ist es ein Rest einer Deinstallation, lösche es.",
"{agent}'s settings are still here ({path}), but its command-line program isn't found: it may have been uninstalled. Install another agent, below the list, has its install command.": "Die Einstellungen von {agent} sind noch da ({path}), aber sein Kommandozeilenprogramm wird nicht gefunden: Es wurde vielleicht deinstalliert. Unter „Weiteren Agenten installieren“ unterhalb der Liste steht sein Installationsbefehl.",
"{agent}'s settings are still here, but its command-line program isn't found": "Die Einstellungen von {agent} sind noch da, aber sein Kommandozeilenprogramm wird nicht gefunden",
"Run a command in a terminal, then come back: magpie lists the agent here once it is installed. The npm commands need Node.js (nodejs.org).": "Führen Sie einen Befehl im Terminal aus und kehren Sie dann zurück: magpie listet den Agenten nach der Installation hier auf. Die npm-Befehle benötigen Node.js (nodejs.org).",
@@ -0,0 +1,112 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// 悠悠哥 on Discord (macOS): the Agents page listed "Codex 0.162.1" under Not
// set up, while `which -a codex` found nothing and ~/.codex wasn't there.
// magpie had found a codex in a folder it adds to its own PATH (an npm
// install under a Node nvm no longer uses) that the terminal's PATH lacks.
// Now a CLI found off the terminal's PATH says so beside its version, its
// tip (and the version's) naming where it is, in every language; one on the
// terminal's PATH is as it was. At the window's narrow width the name keeps
// its room and nothing scrolls sideways. No backend: the API is faked here.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const models = ["model-a", "model-b"].map((m) => ({ value: m, label: m }));
const agent = (id, name) => ({ id, name, path: "~/." + id + "/config.toml", fields: [{ key: "model", label: "model", value: "model-a", options: models }] });
const AGENTS = [agent("codex", "Codex"), agent("gemini", "Gemini CLI")];
const BIN = "/Users/u/.nvm/versions/node/v22.12.0/bin/codex";
const CLIS = {
codex: { version: "0.162.1", path: BIN, offPath: true },
gemini: { version: "0.60.0", latest: "0.60.0", via: "npm", command: "npm install -g @google/gemini-cli@latest", path: "/opt/homebrew/bin/gemini" },
};
function server(lang) {
return async (route) => {
const req = route.request(), url = new URL(req.url());
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return route.fulfill({ json: { agents: AGENTS, profiles: [], settings: { lang, theme: "light" } } });
if (url.pathname === "/api/agents/cli" && req.method() === "GET") return route.fulfill({ json: { agents: CLIS, pending: false } });
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });
if (url.pathname.startsWith("/api/")) return route.fulfill({ json: {} });
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
const row = (id) => `.row.agent[data-id="${id}"]`;
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": a CLI found off the terminal's PATH says where it is", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const errors = [];
t.after(async () => {
await browser.close();
});
const open = async (lang, width = 980) => {
const page = await (await browser.newContext({ viewport: { width, height: 640 } })).newPage();
page.setDefaultTimeout(5000);
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang));
await page.goto("http://magpie.test/");
await page.locator(`${row("codex")} .ag-ver`).first().waitFor();
return page;
};
for (const [lang, said, tip] of [
["en", "Not on your terminal's PATH", `magpie found Codex 0.162.1 at ${BIN}. That folder is one magpie looks in, but your terminal's PATH doesn't have it`],
["zh", "不在终端的 PATH 里", `magpie 在 ${BIN} 找到了 Codex 0.162.1。`],
["zh-TW", "不在終端機的 PATH 裡", `magpie 在 ${BIN} 找到了 Codex 0.162.1。`],
["ja", "ターミナルの PATH にありません", `magpie は Codex 0.162.1 を ${BIN} で見つけました。`],
["de", "Nicht im PATH des Terminals", `magpie hat Codex 0.162.1 unter ${BIN} gefunden.`],
]) {
await t.test(lang + ": the note and where, beside the version", async () => {
const page = await open(lang);
const note = page.locator(`${row("codex")} .ag-offpath`);
assert.equal(await note.textContent(), said);
assert.match(await note.getAttribute("title"), new RegExp(esc(tip)));
assert.match(await page.locator(`${row("codex")} .ag-ver`).getAttribute("title"), new RegExp(esc(tip)));
// one on the terminal's PATH: no note, its tip as before
assert.equal(await page.locator(`${row("gemini")} .ag-offpath`).count(), 0);
assert.equal(await page.locator(`${row("gemini")} .ag-ver`).textContent(), "0.60.0");
// the version, then the note, on one line with the name
const order = await page.locator(`${row("codex")} .ag-cli > *`).evaluateAll((xs) => xs.map((x) => x.classList.contains("ag-offpath") ? "note" : "ver"));
assert.deepEqual(order, ["ver", "note"]);
const mids = await page.evaluate((r) => [".name", ".ag-ver", ".ag-offpath"].map((s) => {
const b = document.querySelector(r + " " + s).getBoundingClientRect();
return b.top + b.height / 2;
}), row("codex"));
assert(Math.max(...mids) - Math.min(...mids) <= 2, `not on one line: ${mids}`);
await page.close();
});
}
for (const width of [560, 440]) {
await t.test(`at ${width}px the name keeps its room and nothing scrolls sideways`, async () => {
const page = await open("de", width);
assert(await page.locator(`${row("codex")} .name`).evaluate((n) => n.scrollWidth <= n.clientWidth + 1), "Codex's name is cut");
const note = await page.locator(`${row("codex")} .ag-offpath`).evaluate((a) => {
const box = a.closest(".ag-cli").getBoundingClientRect(), r = a.getBoundingClientRect();
return { shown: getComputedStyle(a).display !== "none", inside: r.right <= box.right + 1, ellipsis: getComputedStyle(a).textOverflow === "ellipsis" };
});
assert(!note.shown || (note.inside && note.ellipsis), `the note is cut: ${JSON.stringify(note)}`);
const side = await page.evaluate(() => document.scrollingElement.scrollWidth - document.scrollingElement.clientWidth);
assert(side <= 0, `the page scrolls ${side}px sideways`);
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-cli-offpath-${width}.png`) });
}
await page.close();
});
}
assert.deepEqual(errors, []);
});
}