library: the write-failure card can be hidden until a new failure (#3745)
Zachary-wW (#3745): the Library's "Some of the Library couldn't be written" card had Try again and nothing else. Their Grok Build has an AGENTS.md magpie can't stat, and every change writes every agent again, so the card stood over the page through every edit on the Instructions tab, with no way to put it away. The card has a × beside Try again now, named "Hide until something new can't be written". It hides the write failures the card lists, on every tab, and sends nothing. The page keeps what was hidden by agent and item ("grok" and "instructions"). After every answer, a read or a change, it lets go of a hidden failure that no longer stands, and a failure not hidden brings the card back with all it lists; so does a hidden one whose item was written in between and fails again. So the card stays hidden while the reporter keeps editing, though each change fails on Grok Build's file again, and a new write error shows it again. The key is not the error's text: a write goes through a temp file named anew at each try (edit.WriteAtomic), so a folder that can't be written fails with a new text at every sync, and the card would never stay hidden. Meanwhile each change's toast still names what failed, as before, and a skill that couldn't be given keeps the dot on its agent's chip. The list magpie keeps (lastProblems) is not touched. The × is named by its title, as the Library's other × buttons are. An agent's own skills in the library's way are the agent's to settle, not failures: they stay, under their own title, with no ×. The view keeps its scroll as the card goes, as render() keeps it for Try again; Chromium's scroll anchoring moved it. From the keyboard the focus goes to the card's next button, or to the tab open. On a phone the × is 44px wide and as tall as Try again. The card's title keeps its words whole: with less than 10em beside it, Try again and the × go to a line of their own (beside them, a German title at 320px broke "Bibliothek" and "geschrieben" inside). library-problems-hide.test.cjs is new. Its API answers as internal/gui/library.go does: a change's problems are its full sync's, an Instructions change keeps the rest and puts its own in, and a read gets the list with no result. Its error texts are the ones magpie's own sync gave in a sandbox HOME, through Handler in a scratch Go test (not kept): Grok Build's AGENTS.md a link into a folder magpie can't search, its folder read-only, and its skills folder read-only. Not covered: what was hidden lasts as long as the page, so a reload shows the card again. The × hides, it doesn't fold: while the card is hidden, its error texts and Try again are out of reach, though any change writes every agent again. An agent's instructions, and its whole MCP file, have no mark of their own as a skill's chip has, so with the card hidden only a change's toast names their failure (#3987). What was run (tree f98a4b99, on origin/mainf8cd964a, go1.26.8, linux/amd64, Linux 5.15), outside graftcp, umask 077: library-problems-hide.test.cjs, Node's runner with Playwright 1.58, Chromium and WebKit, three runs each: 16 of 16 pass in every run (15 cases and the file's own) Without this change (f8cd964a's client.js, i18n.js and library.css, the new test kept): 16 of 16 red in both. Broken by hand, one at a time, Chromium and WebKit unless said: any change that fails at all brings the card back (the first draft's rule): the reporter's case, the same failure under another error and a hidden failure written since, red a change's failure not hidden brings it back, nothing let go: a hidden failure written since, red a new failure never brings it back while anything is hidden: a failure not hidden, a hidden failure written since and another window's change, red the key with the error's text in it (Chromium): the same failure under another error, red the × writes every agent again (Chromium): 9 red, the reporter's case among them the view's scroll not kept as the card goes: 9 red in Chromium, green in WebKit, which keeps it without the × 44px wide on a phone taken out (Chromium): the five locales' "named and inside the card", red the head as the draft had it, no wrap and the title shrinking: de, red the focus moved without preventScroll (Chromium): green, 16 of 16; no test here tells it apart Library and siblings, Chromium and WebKit: 69 files, the Library's own tests, the skills' and market's that share its page, gui-de, gui-ja, gui-zh-tw and i18n-keys: all pass but two, red the same atf8cd964awithout this change: i18n-keys "a plugin's words are its own", fixed on main since (#3897), and title-bar-tools (Chromium de, WebKit all five locales: a locator.waitFor timeout) TestCoreScriptBudget: ok (the Library is a plugin, outside the core); on origin/mainc752082ewith this commit applied too (a scratch worktree, not this tree) On origin/maine9dd8e83with this commit applied (a scratch worktree, not this tree), Chromium and WebKit: library-problems-hide, i18n-keys, library-items and library-instr-busy, 66 of 66 pass gofmt -l of every .go file: nothing. GOOS=linux, windows and darwin go vet -tags nogui ./..., GOOS=windows go vet ./...: exit 0. GOOS=linux and darwin go build -tags nogui ./..., GOOS=windows go build ./...: exit 0. Untagged linux vet and build stop at pkg-config (no libsoup-3.0 or gio-unix-2.0 here) full suite, go test -tags nogui -count=1 -timeout 45m ./... (8m25s, load 35 at its start, Bun 1.4.2): 68 packages ok, reds in 8, none in internal/gui's library code: internal/agent TestInstalledVersion, TestZedAppPath, TestCursorFolderFromTheEditorIsNotTheCLI, TestCopilotFolderFromAnIDEPluginIsNotTheCLI, TestQoderSettingsFromAnIDEPluginIsNotTheCLI and TestOmpDetectedWithPiDir (#3141); TestCodexDriftReached (#3398); the two Reasonix tests (#3641); TestWSLColdPlaceOpensNothing (#3924, fixed on main since) internal/davsync TestSyncTeraCloudStillSeesOtherWrites (#3420) internal/edit TestWriteAtomicReadOnlyHardLink and internal/testenv TestProgram, umask 077 (#3640) internal/gateway TestPluginToldWhereTheAgentWorks (#3675) internal/gui TestGatewayHeldByAContainer and TestGatewayFixQuitsOnlyAMagpie (#3649) internal/provider TestCodexAppServersOnHome (#3906), then "fatal error: close of synctest channel from outside bubble" (#3632), which ends the package's run internal/tui TestTUIFetchesSubscriptionModels/agent (#3919) Not tried: the × in a running magpie, in macOS's or Windows' window or WebKitGTK; the page here is the test's, with magpie's own replies. Batch run, at tree 104d75f0a (the twelve coffemon ports together, on origin/main7d022bdb6), mote, macOS, go1.26.8: - go test -tags nogui -count=1 -timeout 45m on the packages the batch changes (agent, autostart, daemon, gateway, library, proc, provider, sessions, testenv, tui, gui): ok each. - GUI, node --test with Playwright 1.62.0, Chromium and WebKit: library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass. - gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same batch on origin/main00098f12bone rebase before. - The whole go test ./... at cdd7c8e46: 86 packages ok, one red, internal/cli TestEveryRouteHasACommandOrIsNamed (GET /api/context/reply has no command), red on main too (#5026). - Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch onf4c664a09): proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp) pass. - Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv, tui ok; library and agent red in the same tests as on origin/mainf4c664a09(#4115, #1827, #4786; #5068, #5069, #5070 filed now). - Rebased onto origin/mainfb1f4856a(three commits, no file in common with the batch) and run again at the pushed tree: gofmt -l nothing, go build ./... and go vet ./... ok; go test -tags nogui sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and library-* 1044 of 1044 pass. - Not run before the push: the whole GUI suite (a run at cdd7c8e46 was cut off at 1170 of ~1174 tests when mote rebooted; it runs again after the tag and any red is filed).
This commit is contained in:
@@ -30,6 +30,7 @@ magpie.plugin("library", (ctx) => {
|
||||
let autoChecked = false; // the page checked by itself, as the server said it was due (#1449)
|
||||
let regrouping = false; // the skills' repositories fetched to group them again
|
||||
let modal = null; // what the library has open in the dialog
|
||||
const hid = new Set(); // the write failures the reader hid, by agent and what (#3745)
|
||||
|
||||
const GLYPH = {
|
||||
cmd: "M3 4.5h10v7H3z M5.5 7l1.5 1.2-1.5 1.3 M8.5 9.5h2",
|
||||
@@ -445,6 +446,14 @@ magpie.plugin("library", (ctx) => {
|
||||
// removed or renamed changes what the market calls added (#300): one gone
|
||||
// from the library loses its mark at once, and the market is asked again.
|
||||
function take(v) {
|
||||
// What the reader hid stays hidden while it still fails and nothing
|
||||
// else does: every change writes every agent again, so a file magpie
|
||||
// can't stat fails at each one (#3745). A failure not hidden brings the
|
||||
// card back whole, and an item written meanwhile is new when it fails
|
||||
// again. v.problems is everything that stands, whatever answered.
|
||||
const failing = new Set((v.problems || []).filter(failure).map(problemKey));
|
||||
for (const k of hid) if (!failing.has(k)) hid.delete(k);
|
||||
if ([...failing].some((k) => !hid.has(k))) hid.clear();
|
||||
const was = lib && shelf();
|
||||
lib = v;
|
||||
taken++;
|
||||
@@ -606,7 +615,11 @@ magpie.plugin("library", (ctx) => {
|
||||
// the agent, settled together, not a write that failed: Try again, which
|
||||
// can't change them, is offered only beside a write that did fail.
|
||||
function problemsCard() {
|
||||
const list = lib.problems || [];
|
||||
// the write failures the reader hid are left out while they are all
|
||||
// that fails; an agent's own skills, still to settle, stay
|
||||
const all = lib.problems || [];
|
||||
const quiet = all.some(failure) && all.filter(failure).every((p) => hid.has(problemKey(p)));
|
||||
const list = quiet ? all.filter((p) => !failure(p)) : all;
|
||||
if (!list.length) return null;
|
||||
const here = list.filter((p) => !problemTab(p.what) || problemTab(p.what) === tab);
|
||||
const away = {};
|
||||
@@ -614,7 +627,7 @@ magpie.plugin("library", (ctx) => {
|
||||
const owns = new Map(); // agent → its own skills by the library's names
|
||||
const rest = [];
|
||||
for (const p of here) {
|
||||
if (p.own && p.what.startsWith("skill:") && p.agent) {
|
||||
if (!failure(p)) {
|
||||
if (!owns.has(p.agent)) owns.set(p.agent, []);
|
||||
owns.get(p.agent).push(p.what.slice("skill:".length));
|
||||
} else rest.push(p);
|
||||
@@ -622,12 +635,18 @@ magpie.plugin("library", (ctx) => {
|
||||
const card = el("div", "lib-problems");
|
||||
card.setAttribute("role", "status");
|
||||
const ttl = el("div", "lib-problems-head");
|
||||
const failed = rest.length || list.some((p) => !here.includes(p) && !p.own);
|
||||
ttl.append(el("span", "lib-problems-dot"), el("b", "", failed ? t("Some of the Library couldn't be written") : t("Some agents have skills of their own by the library's names")), el("span", "grow"));
|
||||
const failed = rest.length || list.some((p) => !here.includes(p) && failure(p));
|
||||
ttl.append(el("span", "lib-problems-dot"), el("b", "", failed ? t("Some of the Library couldn't be written") : t("Some agents have skills of their own by the library's names")));
|
||||
if (failed) {
|
||||
const again = button(t("Try again"), "action", () => change("all/sync", {}));
|
||||
again.title = t("Writes the library into every agent again");
|
||||
ttl.append(again);
|
||||
// the reader who can't mend it here, or won't now, puts it away; a
|
||||
// change's toast still says what failed, and something new that
|
||||
// can't be written brings it back (#3745)
|
||||
const hide = button("", "lib-x", () => hideFailed(card));
|
||||
hide.append(svg("M4.5 4.5l7 7M11.5 4.5l-7 7", 11, 1.6));
|
||||
hide.title = t("Hide until something new can't be written");
|
||||
ttl.append(again, hide);
|
||||
}
|
||||
card.append(ttl);
|
||||
const ul = el("ul");
|
||||
@@ -678,6 +697,27 @@ magpie.plugin("library", (ctx) => {
|
||||
}
|
||||
return card;
|
||||
}
|
||||
// a write that failed, as against an agent's own skill in the library's
|
||||
// way, which is the agent's to settle
|
||||
function failure(p) {
|
||||
return !(p.own && p.what.startsWith("skill:") && p.agent);
|
||||
}
|
||||
// a failure is the same from one sync to the next by its agent and its
|
||||
// item: the error can name a temp file new at each write (edit.WriteAtomic)
|
||||
function problemKey(p) {
|
||||
return p.agent + "\n" + p.what;
|
||||
}
|
||||
function hideFailed(card) {
|
||||
const focused = card.contains(document.activeElement);
|
||||
for (const p of lib.problems || []) if (failure(p)) hid.add(problemKey(p));
|
||||
// the view keeps its scroll, as render keeps it for Try again:
|
||||
// Chromium's scroll anchoring would move it as the card goes
|
||||
const top = page.scrollTop;
|
||||
syncProblems();
|
||||
page.scrollTop = top;
|
||||
// the keyboard's place: the card's next button, or the tab open
|
||||
if (focused) (page.querySelector(":scope > .lib-problems button") || page.querySelector(".lib-tabs .opt.on"))?.focus({ preventScroll: true });
|
||||
}
|
||||
// the tab a problem is about; "" is one shown on every tab
|
||||
function problemTab(what) {
|
||||
return { instructions: "instructions", mcp: "mcp", skill: "skills", skills: "skills", project: "skills", hook: "hooks", hooks: "hooks", subagent: "subagents" }[what.split(":")[0]] || "";
|
||||
|
||||
@@ -205,6 +205,7 @@ magpie.strings({
|
||||
"{agent} reads MCP servers through the {ext} extension": "{agent} 通过 {ext} 扩展读取 MCP 服务器",
|
||||
"(and {n} more)": "(另有 {n} 项)",
|
||||
"Some of the Library couldn't be written": "资源库有部分内容未能写入",
|
||||
"Hide until something new can't be written": "隐藏,直到又有新的内容未能写入",
|
||||
"Writes the library into every agent again": "把资源库重新写入每个 Agent",
|
||||
"MCP server {name}": "MCP 服务器 {name}",
|
||||
"Skill {name}": "技能 {name}",
|
||||
@@ -971,6 +972,7 @@ magpie.strings({
|
||||
"{agent} reads MCP servers through the {ext} extension": "{agent} 透過 {ext} 擴充功能讀取 MCP 伺服器",
|
||||
"(and {n} more)": "(另有 {n} 項)",
|
||||
"Some of the Library couldn't be written": "資源庫有部分內容未能寫入",
|
||||
"Hide until something new can't be written": "隱藏,直到又有新的內容未能寫入",
|
||||
"Writes the library into every agent again": "把資源庫重新寫入每個 Agent",
|
||||
"MCP server {name}": "MCP 伺服器 {name}",
|
||||
"Skill {name}": "技能 {name}",
|
||||
@@ -1732,6 +1734,7 @@ magpie.strings({
|
||||
"{agent} reads MCP servers through the {ext} extension": "{agent} は {ext} 拡張機能経由で MCP サーバーを読み込みます",
|
||||
"(and {n} more)": "(ほか {n} 件)",
|
||||
"Some of the Library couldn't be written": "ライブラリの一部を書き込めませんでした",
|
||||
"Hide until something new can't be written": "新たに書き込めないものが出るまで非表示にする",
|
||||
"Writes the library into every agent again": "ライブラリをすべてのエージェントにもう一度書き込みます",
|
||||
"MCP server {name}": "MCP サーバー {name}",
|
||||
"Skill {name}": "スキル {name}",
|
||||
@@ -2496,6 +2499,7 @@ magpie.strings({
|
||||
"{agent} reads MCP servers through the {ext} extension": "{agent} liest MCP-Server über die Erweiterung {ext}",
|
||||
"(and {n} more)": "(und {n} weitere)",
|
||||
"Some of the Library couldn't be written": "Teile der Bibliothek konnten nicht geschrieben werden",
|
||||
"Hide until something new can't be written": "Ausblenden, bis etwas Neues nicht geschrieben werden kann",
|
||||
"Writes the library into every agent again": "Schreibt die Bibliothek erneut in jeden Agenten",
|
||||
"MCP server {name}": "MCP-Server {name}",
|
||||
"Skill {name}": "Skill {name}",
|
||||
|
||||
@@ -32,6 +32,8 @@ body.window .lib-head { top: -2px; margin: -2px 0 0; padding: 8px 0 4px; --bleed
|
||||
body.web .lib-more, body.web .lib-discover, body.web .lib-backups { flex: none; }
|
||||
/* a phone's inputs are 44pt with 16px text: the search box grows round it */
|
||||
body.web .editor.lib-hubsheet label.lib-hubsearch { height: 44px; border-radius: 10px; }
|
||||
/* the card's × as big to tap as the buttons beside it */
|
||||
body.web .lib-problems-head .lib-x { width: 44px; }
|
||||
}
|
||||
/* a window too narrow for the tabs and the buttons beside them (Discover,
|
||||
Library folder, Backups) on one line has the buttons on a line of their own, at
|
||||
@@ -279,9 +281,13 @@ input.lib-setname:focus { border-color: var(--accent); box-shadow: 0 0 0 3px col
|
||||
.lib-warn .lib-path { display: inline; }
|
||||
/* what the last change couldn't write: for which agent, and why */
|
||||
.lib-problems { flex: none; margin: 8px 0 6px; padding: 9px 12px 10px; border-radius: 10px; background: var(--amber-soft); color: var(--fg); font-size: 12px; line-height: 1.45; min-width: 0; overflow-wrap: anywhere; }
|
||||
.lib-problems-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
||||
.lib-problems-head b { font-weight: 600; min-width: 0; }
|
||||
.lib-problems-head .action { flex: none; }
|
||||
/* the title keeps its words whole: with less than 10em left beside it,
|
||||
Try again and the × go to a line of their own, at its end (German on a
|
||||
320px phone broke "Bibliothek" with the × beside it) */
|
||||
.lib-problems-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
|
||||
.lib-problems-head b { flex: 1 1 10em; font-weight: 600; min-width: 0; overflow-wrap: break-word; }
|
||||
.lib-problems-head .action { flex: none; margin-left: auto; }
|
||||
.lib-problems-head .lib-x { margin: -4px -6px -4px -2px; color: var(--muted); }
|
||||
.lib-problems-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
|
||||
.lib-problems ul { list-style: none; margin: 6px 0 0; padding: 0 0 0 15px; display: grid; gap: 4px; }
|
||||
.lib-problems li { min-width: 0; }
|
||||
|
||||
@@ -1442,6 +1442,21 @@ found skill with a byte copy in another agent shows both agents' icons and
|
||||
no "differs in"; one that really differs still says so. Chromium and
|
||||
WebKit, in English and Chinese, with `/api/plugins` faked.
|
||||
|
||||
`library-problems-hide.test.cjs` opens the Library with Grok Build's
|
||||
AGENTS.md failing to stat at every sync (Zachary-wW, #3745), the API
|
||||
answering as `library.go` does, the error texts as magpie's own sync gave
|
||||
them in a sandbox. The card's × hides what it lists on every tab, sends
|
||||
nothing and moves no view; a read, and in the window an Instructions
|
||||
change and a chip's change that fail only on what was hidden, keep it
|
||||
hidden, the toast still naming the failure, and so does the same failure
|
||||
under a temp file named anew at each write. A failure not hidden, one whose item was written in
|
||||
between, or one after none stood brings the card back with all it lists.
|
||||
An agent's own skills stay, under their own title, with no ×, and the
|
||||
keyboard's focus goes to the card's next button or the tab open. The × is
|
||||
named and inside the card in English, Chinese (both), Japanese and German,
|
||||
in a browser at 980, 440 and 320px (44px wide on a phone) and in the
|
||||
window at 980 and 560px, the title's words whole. Chromium and WebKit.
|
||||
|
||||
`model-pick.test.cjs` picks Claude Code's model with the Agents page
|
||||
scrolled while a faked `/api/set` takes 2.5s to answer: the row shows the
|
||||
new model at once, in the window and in the tray panel's opened row and its
|
||||
|
||||
@@ -0,0 +1,396 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Zachary-wW (#3745): "Some of the Library couldn't be written" had only
|
||||
// Try again, and what it listed, Grok Build's AGENTS.md that magpie can't
|
||||
// stat, failed again at every change, since each one writes every agent.
|
||||
// Its × now hides what the card lists, on every tab, and sends nothing. A
|
||||
// read keeps it hidden, and so does a change that fails only on what was
|
||||
// hidden: the reporter's case, in the window, on Instructions and from a
|
||||
// chip, the toast still naming the failure. The same failure under
|
||||
// another error (a temp file's name, new at each write) stays hidden. A
|
||||
// failure not hidden brings the card back with all it lists, and so does
|
||||
// a hidden one whose item was written since and fails again. An agent's
|
||||
// own skills stay, under their own title, with no ×. From the keyboard
|
||||
// the focus goes to the card's next button, or the tab open, and neither
|
||||
// a click nor a key moves the view. The × is named in English, Chinese
|
||||
// (both), Japanese and German, inside the card in a browser at 980, 440
|
||||
// and 320px and in the window at 980 and 560px, 44px wide on a phone,
|
||||
// with the title's words whole. No backend: the API answers as
|
||||
// internal/gui/library.go does.
|
||||
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 HOME = "/Users/me";
|
||||
const agent = (id, name, file = "AGENTS.md") => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, instructions: `${HOME}/.${id}/${file}` });
|
||||
// What magpie's own sync gave for Grok Build in a sandbox HOME, moved to
|
||||
// this one: its AGENTS.md a link into a folder magpie can't search (the
|
||||
// report's), its folder read-only, where each write's temp file is named
|
||||
// anew (four writes in a row), and its skills folder read-only.
|
||||
const grok = { agent: "grok", what: "instructions", error: `stat ${HOME}/.grok/AGENTS.md: permission denied` };
|
||||
const temps = [2481177194, 3572372181, 3495008769, 1673008888];
|
||||
const grokTemp = (n) => ({ agent: "grok", what: "instructions", error: `open ${HOME}/.grok/.AGENTS.md.${temps[n % temps.length]}.tmp: permission denied` });
|
||||
const grokSkill = { agent: "grok", what: "skill:s01", error: `symlink ${HOME}/.config/magpie/library/skills/s01 ${HOME}/.grok/skills/s01: permission denied` };
|
||||
const own = { agent: "claude", what: "skill:impeccable", error: "Claude Code already has a skill of its own called impeccable", own: true };
|
||||
const names = ["impeccable", ...Array.from({ length: 12 }, (_, i) => "s" + String(i).padStart(2, "0"))];
|
||||
|
||||
// the page as magpie has it: each skill's chips carry the failures that
|
||||
// stand for it, and each read has a library folder of its own (the number
|
||||
// is the test's), which the Library folder button names on every tab, for
|
||||
// a test to wait on
|
||||
const view = (st) => ({
|
||||
dir: `${HOME}/.config/magpie/library-${st.reads}`, backups: `${HOME}/.config/magpie/backups`, home: HOME,
|
||||
agents: [agent("claude", "Claude Code", "CLAUDE.md"), agent("codex", "Codex"), agent("grok", "Grok Build")],
|
||||
instructions: {
|
||||
shared: "",
|
||||
sets: [{ id: "default", name: "", active: st.set === "default", text: "" }, { id: "work", name: "Work", active: st.set === "work", text: "Rules." }],
|
||||
agents: [{ agent: "grok", extra: "", icon: "xai", name: "Grok Build", on: true, own: 0, path: `${HOME}/.grok/AGENTS.md` }],
|
||||
},
|
||||
servers: [], foundServers: [], projects: [], foundSkills: [],
|
||||
skills: names.map((name) => {
|
||||
const m = Object.fromEntries(st.last.filter((p) => p.what === "skill:" + name).map((p) => [p.agent, p.error]));
|
||||
return { name, description: name === "impeccable" ? "Design" : "d", kind: "", agents: st.agents[name], ...(Object.keys(m).length ? { problems: m } : {}) };
|
||||
}),
|
||||
});
|
||||
// problems has omitempty: none is no key at all
|
||||
const omit = (p) => (p.length ? { problems: p } : {});
|
||||
|
||||
// As gui/library.go answers. st.last is lastProblems: a read gets it with
|
||||
// no result. Any other change is a full sync (library.change), whose
|
||||
// result holds every failure that stands, and the page's list becomes it.
|
||||
// An Instructions change writes the instructions alone: it keeps the rest
|
||||
// of the list and puts its own in (instructionsView). st.fails(n) is what
|
||||
// the n-th sync fails on.
|
||||
function server(lang, st, posts, web) {
|
||||
return async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
const post = req.method() === "POST";
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${web}};` });
|
||||
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: [], profiles: [], settings: { lang, theme: "light" } } });
|
||||
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
|
||||
if (url.pathname === "/api/library" && !post) {
|
||||
st.reads++;
|
||||
return route.fulfill({ json: { ...view(st), ...omit(st.last) } });
|
||||
}
|
||||
if (url.pathname === "/api/library/instructions/save" && post) {
|
||||
posts.push(url.pathname);
|
||||
const body = req.postDataJSON();
|
||||
if (body.activate) st.set = body.activate;
|
||||
const result = { changed: [], problems: st.fails(st.syncs++).filter((p) => p.what === "instructions") };
|
||||
st.last = [...st.last.filter((p) => p.what !== "instructions"), ...result.problems];
|
||||
return route.fulfill({ json: { part: "instructions", instructions: view(st).instructions, result, ...omit(st.last) } });
|
||||
}
|
||||
if (url.pathname.startsWith("/api/library/") && post) {
|
||||
posts.push(url.pathname);
|
||||
if (url.pathname === "/api/library/skills/agents") {
|
||||
const body = req.postDataJSON();
|
||||
st.agents[body.name] = body.agents;
|
||||
}
|
||||
const result = { changed: [], problems: st.fails(st.syncs++) };
|
||||
st.last = result.problems;
|
||||
return route.fulfill({ json: { ...view(st), result, ...omit(st.last) } });
|
||||
}
|
||||
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 } } });
|
||||
// the rest the page reads (the markets' lists) gets nothing
|
||||
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 words = {
|
||||
en: { hide: "Hide until something new can't be written", failed: "Some of the Library couldn't be written", own: "Some agents have skills of their own by the library's names", use: "Use the library's", instructions: "Instructions" },
|
||||
zh: { hide: "隐藏,直到又有新的内容未能写入", failed: "资源库有部分内容未能写入", own: "有些 Agent 已有与资源库同名的自带技能", use: "用资源库的", instructions: "指令" },
|
||||
"zh-TW": { hide: "隱藏,直到又有新的內容未能寫入" },
|
||||
ja: { hide: "新たに書き込めないものが出るまで非表示にする" },
|
||||
de: { hide: "Ausblenden, bis etwas Neues nicht geschrieben werden kann" },
|
||||
};
|
||||
const lib = "#view-library";
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": the Library's write failures can be hidden until something new can't be written", 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 () => {
|
||||
if (errors.length) console.log(errors);
|
||||
await browser.close();
|
||||
});
|
||||
// problems is what stands as the page opens, fails what each sync
|
||||
// after it fails on (the same, unless a test says otherwise)
|
||||
const open = async (lang, problems, { width = 980, tab = "skills", web = true, fails } = {}) => {
|
||||
const ctx = await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" });
|
||||
await ctx.addInitScript((tab) => { try { localStorage.setItem("magpie.libTab", tab); } catch {} }, tab);
|
||||
const page = await ctx.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(20000); // the page's first load, slow on a busy machine
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
// s01 is given to Grok Build too, which its skills folder may refuse
|
||||
const st = { last: structuredClone(problems), fails: fails || (() => structuredClone(problems)), reads: 0, syncs: 0, set: "default", agents: Object.fromEntries(names.map((n) => [n, n === "s01" ? ["claude", "codex", "grok"] : ["claude", "codex"]])) };
|
||||
const posts = [];
|
||||
await page.route("http://magpie.test/**", server(lang, st, posts, web));
|
||||
await page.goto("http://magpie.test/");
|
||||
// a fresh browser's first page, on a busy machine, can take longer to
|
||||
// show than the 5s every other wait here gets
|
||||
await page.locator('button[data-view="library"]').click({ timeout: 20000 });
|
||||
await page.locator(`${lib} .lib-body:not(.lib-skel)`).first().waitFor();
|
||||
return { page, st, posts };
|
||||
};
|
||||
const card = (page) => page.locator(`${lib} > .lib-problems`);
|
||||
const title = (page) => card(page).locator(".lib-problems-head b").textContent();
|
||||
const hideOf = (page, lang) => card(page).getByRole("button", { name: words[lang].hide, exact: true });
|
||||
// a reader's click, where the button is: no scroll of Playwright's own
|
||||
const press = async (page, loc) => {
|
||||
const b = await loc.boundingBox();
|
||||
await page.mouse.click(b.x + b.width / 2, b.y + b.height / 2);
|
||||
};
|
||||
const scrollTop = (page) => page.evaluate((v) => document.querySelector(v).scrollTop, lib);
|
||||
// the view scrolled by the reader's wheel, over the list: a scroll set
|
||||
// by code is no one's, and the page puts it back (app.js)
|
||||
const wheel = async (page, dy) => {
|
||||
const want = (await scrollTop(page)) + dy;
|
||||
const b = await page.locator(lib).boundingBox();
|
||||
await page.mouse.move(b.x + 24, b.y + b.height - 30);
|
||||
await page.mouse.wheel(0, dy);
|
||||
await page.waitForFunction(([v, want]) => document.querySelector(v).scrollTop === want, [lib, want]);
|
||||
};
|
||||
// what the next two frames do after a click (a hold, keyboardFocus)
|
||||
const settled = (page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
||||
// the page drawn from a read after the n-th: its folder is its own
|
||||
const drawnAfter = (page, n) => page.waitForFunction(([v, n]) => {
|
||||
const m = document.querySelector(v + " .lib-more")?.title.match(/library-(\d+)$/);
|
||||
return m && Number(m[1]) > n;
|
||||
}, [lib, n]);
|
||||
// the page left for another and opened again: open reads the library
|
||||
const reopen = async (page, st) => {
|
||||
const n = st.reads;
|
||||
await page.locator('button[data-view="usage"]').click();
|
||||
await page.locator('button[data-view="library"]').click();
|
||||
await drawnAfter(page, n);
|
||||
};
|
||||
// the × clicked from a view scrolled a little, where the card's going
|
||||
// could move it (Chromium anchors the scroll)
|
||||
const hidden = async (page, lang) => {
|
||||
const room = await page.evaluate((v) => { const e = document.querySelector(v); return e.scrollHeight - e.clientHeight; }, lib);
|
||||
if (room >= 12) await wheel(page, 12);
|
||||
const before = await scrollTop(page);
|
||||
await press(page, hideOf(page, lang));
|
||||
await card(page).waitFor({ state: "detached" });
|
||||
await settled(page);
|
||||
assert.equal(await scrollTop(page), before, "a click scrolls nothing");
|
||||
};
|
||||
const row = (page, name) => page.locator(`${lib} .lib-row`).filter({ has: page.locator(".name", { hasText: new RegExp("^" + name + "$") }) });
|
||||
// a chip's write, as a reader's hand makes it: the chips fan out under
|
||||
// the pointer (at once, with reduced motion) until the one wanted is
|
||||
// the one under its own middle
|
||||
const chip = async (page, name, id) => {
|
||||
const b = await row(page, name).locator(".lib-agents").boundingBox();
|
||||
await page.mouse.move(b.x + 6, b.y + b.height / 2);
|
||||
await page.waitForFunction(([v, name, id]) => {
|
||||
const c = [...document.querySelectorAll(v + " .lib-row")].find((r) => r.querySelector(".name")?.textContent === name)?.querySelector(`.lib-ag[data-agent="${id}"]`);
|
||||
const r = c?.getBoundingClientRect();
|
||||
return !!r && document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2)?.closest(".lib-ag") === c;
|
||||
}, [lib, name, id]);
|
||||
await press(page, row(page, name).locator(`.lib-ag[data-agent="${id}"]`));
|
||||
};
|
||||
// the toast a change ends with; cleared first, so the one waited for is
|
||||
// the next change's, not the last one's
|
||||
const clearToast = (page) => page.evaluate(() => { document.querySelector("#status").textContent = ""; });
|
||||
const toast = async (page, want) => {
|
||||
await page.waitForFunction((want) => document.querySelector("#status").textContent === want, want);
|
||||
assert.match(await page.locator("#status").getAttribute("class"), /\bwarn\b/);
|
||||
};
|
||||
const grokSaid = `Grok Build: ${grok.error}`;
|
||||
|
||||
for (const lang of ["en", "zh"]) {
|
||||
const w = words[lang];
|
||||
await t.test(lang + ": the × hides what couldn't be written, on every tab, and a read keeps it hidden", async () => {
|
||||
const { page, st, posts } = await open(lang, [grok, grokSkill]);
|
||||
await card(page).waitFor();
|
||||
assert.equal(await title(page), w.failed);
|
||||
const dot = row(page, "s01").locator('.lib-ag[data-agent="grok"]');
|
||||
assert.ok(await dot.evaluate((c) => c.classList.contains("warn")), "s01's Grok Build chip has its dot");
|
||||
await hidden(page, lang);
|
||||
assert.deepEqual(posts, [], "nothing is sent");
|
||||
assert.ok(await dot.evaluate((c) => c.classList.contains("warn")), "the chip keeps its dot");
|
||||
await press(page, page.locator(`${lib} .lib-tabs .opt`, { hasText: w.instructions }));
|
||||
await page.locator(`${lib} .lib-tabs .opt.on`, { hasText: w.instructions }).waitFor();
|
||||
assert.equal(await card(page).count(), 0, "nor on Instructions, where Grok Build's is");
|
||||
await reopen(page, st);
|
||||
assert.equal(await card(page).count(), 0, "nor once the library is read again");
|
||||
assert.deepEqual(posts, []);
|
||||
await page.close();
|
||||
});
|
||||
|
||||
await t.test(lang + ": an agent's own skills stay, and the keyboard's place moves to them", async () => {
|
||||
const { page } = await open(lang, [grok, grokSkill, own]);
|
||||
await card(page).waitFor();
|
||||
assert.equal(await title(page), w.failed);
|
||||
await wheel(page, 12);
|
||||
await hideOf(page, lang).focus();
|
||||
await page.keyboard.press("Enter");
|
||||
await page.waitForFunction(([v, want]) => document.querySelector(v + " > .lib-problems .lib-problems-head b")?.textContent === want, [lib, w.own]);
|
||||
assert.equal(await card(page).locator("li").count(), 1);
|
||||
assert.equal(await card(page).getByRole("button", { name: w.use }).count(), 1);
|
||||
assert.equal(await hideOf(page, lang).count(), 0, "no × beside an agent's own skills");
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.textContent), w.use);
|
||||
await settled(page);
|
||||
assert.equal(await scrollTop(page), 12, "the focus moved, the view didn't");
|
||||
await page.close();
|
||||
});
|
||||
}
|
||||
|
||||
await t.test("the reporter's case, in the window: every change fails on Grok Build's file again, and the card stays hidden", async () => {
|
||||
const { page, posts } = await open("en", [grok], { tab: "instructions", web: false });
|
||||
await card(page).waitFor();
|
||||
assert.equal(await card(page).locator("li").textContent(), "Grok Build · Instructions" + grok.error);
|
||||
await hidden(page, "en");
|
||||
// another set switched on: the instructions are written into every
|
||||
// agent, and Grok Build's still can't be stat'ed
|
||||
const saved = page.waitForResponse((r) => r.url().endsWith("/api/library/instructions/save"));
|
||||
await press(page, page.locator(`${lib} .lib-set`).nth(1).locator(".lib-radio"));
|
||||
await saved;
|
||||
await page.waitForFunction((v) => !document.querySelector(v).hasAttribute("aria-busy"), lib);
|
||||
await page.locator(`${lib} .lib-set.on`, { hasText: "Work" }).waitFor();
|
||||
assert.equal(await card(page).count(), 0, "an Instructions change that fails on it alone");
|
||||
await toast(page, grokSaid);
|
||||
// a chip on Skills: a full sync, every agent written again
|
||||
await press(page, page.locator(`${lib} .lib-tabs .opt`, { hasText: "Skills" }));
|
||||
await page.locator(`${lib} .lib-tabs .opt.on`, { hasText: "Skills" }).waitFor();
|
||||
await clearToast(page);
|
||||
await chip(page, "s05", "codex");
|
||||
await toast(page, grokSaid);
|
||||
assert.equal(await card(page).count(), 0, "a chip's change that fails on it alone");
|
||||
assert.deepEqual(posts, ["/api/library/instructions/save", "/api/library/skills/agents"]);
|
||||
await page.close();
|
||||
});
|
||||
|
||||
await t.test("a failure not hidden brings the card back with all it lists", async () => {
|
||||
let fails = [grok];
|
||||
const { page, posts } = await open("en", [grok], { fails: () => structuredClone(fails) });
|
||||
await card(page).waitFor();
|
||||
await hidden(page, "en");
|
||||
// Grok Build's skills folder can't be written now, with s01's link
|
||||
// gone from it: every sync fails to give it back
|
||||
fails = [grok, grokSkill];
|
||||
await chip(page, "s05", "codex");
|
||||
await card(page).waitFor();
|
||||
assert.deepEqual(posts, ["/api/library/skills/agents"]);
|
||||
assert.equal(await title(page), words.en.failed);
|
||||
assert.equal(await card(page).locator("li").textContent(), "Grok Build · Skill s01" + grokSkill.error);
|
||||
// Grok Build's, hidden before, is listed again, on its own tab
|
||||
assert.equal(await card(page).getByRole("button", { name: "Instructions: 1 more", exact: true }).count(), 1);
|
||||
assert.equal(await hideOf(page, "en").count(), 1);
|
||||
await page.close();
|
||||
});
|
||||
|
||||
await t.test("the same failure under another error, a temp file named anew at each write, stays hidden", async () => {
|
||||
const { page, st, posts } = await open("en", [grokTemp(0)], { tab: "instructions", fails: (n) => [grokTemp(n + 1)] });
|
||||
await card(page).waitFor();
|
||||
await hidden(page, "en");
|
||||
const saved = page.waitForResponse((r) => r.url().endsWith("/api/library/instructions/save"));
|
||||
await press(page, page.locator(`${lib} .lib-set`).nth(1).locator(".lib-radio"));
|
||||
await saved;
|
||||
await page.waitForFunction((v) => !document.querySelector(v).hasAttribute("aria-busy"), lib);
|
||||
assert.notEqual(grokTemp(1).error, grokTemp(0).error);
|
||||
await toast(page, `Grok Build: ${grokTemp(1).error}`);
|
||||
assert.equal(await card(page).count(), 0, "its temp file's name new");
|
||||
await press(page, page.locator(`${lib} .lib-tabs .opt`, { hasText: "Skills" }));
|
||||
await page.locator(`${lib} .lib-tabs .opt.on`, { hasText: "Skills" }).waitFor();
|
||||
await clearToast(page);
|
||||
await chip(page, "s05", "codex");
|
||||
await toast(page, `Grok Build: ${grokTemp(2).error}`);
|
||||
assert.equal(await card(page).count(), 0, "and again at the next");
|
||||
assert.deepEqual(st.last, [grokTemp(2)]);
|
||||
assert.deepEqual(posts, ["/api/library/instructions/save", "/api/library/skills/agents"]);
|
||||
await page.close();
|
||||
});
|
||||
|
||||
await t.test("a hidden failure whose item was written since is new when it fails again", async () => {
|
||||
let fails = [grok, grokSkill];
|
||||
const { page } = await open("en", [grok, grokSkill], { fails: () => structuredClone(fails) });
|
||||
await card(page).waitFor();
|
||||
await hidden(page, "en");
|
||||
fails = [grok]; // Grok Build's skills folder writable again: s01 is given
|
||||
await clearToast(page);
|
||||
await chip(page, "s05", "codex");
|
||||
await toast(page, grokSaid);
|
||||
assert.equal(await card(page).count(), 0, "its AGENTS.md alone, still hidden");
|
||||
fails = [grok, grokSkill]; // and not, s01's link gone again
|
||||
await chip(page, "s06", "codex");
|
||||
await card(page).waitFor();
|
||||
assert.equal(await card(page).locator("li").textContent(), "Grok Build · Skill s01" + grokSkill.error);
|
||||
await page.close();
|
||||
});
|
||||
|
||||
await t.test("what another window's change left brings it back too: a failure not hidden, or one after none stood", async () => {
|
||||
const { page, st } = await open("en", [grok]);
|
||||
await card(page).waitFor();
|
||||
await hidden(page, "en");
|
||||
st.last = [grok, grokSkill];
|
||||
await reopen(page, st);
|
||||
await card(page).waitFor();
|
||||
assert.equal(await title(page), words.en.failed);
|
||||
await hidden(page, "en");
|
||||
st.last = [];
|
||||
await reopen(page, st);
|
||||
assert.equal(await card(page).count(), 0);
|
||||
st.last = [grok];
|
||||
await reopen(page, st);
|
||||
await card(page).waitFor();
|
||||
assert.equal(await title(page), words.en.failed);
|
||||
await page.close();
|
||||
});
|
||||
|
||||
await t.test("from the keyboard, with nothing left, the focus goes to the tab open", async () => {
|
||||
const { page } = await open("en", [grok, grokSkill]);
|
||||
await card(page).waitFor();
|
||||
await wheel(page, 12);
|
||||
await hideOf(page, "en").focus();
|
||||
await page.keyboard.press(" ");
|
||||
await card(page).waitFor({ state: "detached" });
|
||||
assert.ok(await page.evaluate(() => document.activeElement?.matches("#view-library .lib-tabs .opt.on")), "the focus is on the tab open");
|
||||
await settled(page);
|
||||
assert.equal(await scrollTop(page), 12, "the focus moved, the view didn't");
|
||||
await page.close();
|
||||
});
|
||||
|
||||
for (const lang of Object.keys(words)) {
|
||||
await t.test(lang + ": the × is named and inside the card, in a browser and in the window, the title's words whole", async () => {
|
||||
for (const [web, width] of [[true, 980], [true, 440], [true, 320], [false, 980], [false, 560]]) {
|
||||
const where = `${web ? "browser" : "window"} ${width}px`;
|
||||
const { page } = await open(lang, [grok, grokSkill], { width, web });
|
||||
await card(page).waitFor();
|
||||
assert.equal(await hideOf(page, lang).count(), 1, where);
|
||||
const fit = await card(page).evaluate((c) => {
|
||||
const box = c.getBoundingClientRect(), x = c.querySelector(".lib-x").getBoundingClientRect(), again = c.querySelector(".lib-problems-head .action").getBoundingClientRect();
|
||||
// a word too long for the title's width shows as overflow once
|
||||
// it may no longer break inside
|
||||
const b = c.querySelector(".lib-problems-head b");
|
||||
b.style.overflowWrap = "normal";
|
||||
const whole = b.scrollWidth <= b.clientWidth;
|
||||
b.style.overflowWrap = "";
|
||||
return {
|
||||
inside: x.left >= box.left && x.right <= box.right && x.top >= box.top && x.bottom <= box.bottom,
|
||||
apart: x.left >= again.right || x.right <= again.left || x.top >= again.bottom || x.bottom <= again.top,
|
||||
wide: c.scrollWidth > c.clientWidth + 1,
|
||||
whole,
|
||||
size: [Math.round(x.width), Math.round(x.height) === Math.round(again.height)],
|
||||
};
|
||||
});
|
||||
// a phone's: as big to tap as Try again beside it
|
||||
const size = web && width <= 760 ? [44, true] : fit.size;
|
||||
assert.deepEqual(fit, { inside: true, apart: true, wide: false, whole: true, size }, where);
|
||||
await page.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user