From ba4b7b05458c80e63e454fbe2ff359e21f28fd34 Mon Sep 17 00:00:00 2001 From: YangHonghang <60209620+YangHonghang@users.noreply.github.com> Date: Thu, 5 Nov 2026 14:56:39 +0800 Subject: [PATCH] window-warmup 0.1.3: a task's editor opens under its own row, and the footer link no longer restyles the editor's buttons (#752) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit renderList used to append the task editor after every row, so opening a task that wasn't the last one, or starting a new task while saved ones were listed, put the editor at the bottom of the list. Now the editor follows the row it opened: under the clicked task, or under the new row at the top. The footer's 反馈问题 button had reused the `.link` class, so its 11.5px faint rule restyled the editor's 立即发送一次 and 重试 buttons. The footer now has its own `.foot-link`. window-warmup goes 0.1.2 -> 0.1.3. The browser smoke test (Chromium and WebKit) checks three things. Opening the first of two saved tasks puts the editor right under that row and not last in the list. Clicking 新建任务 then puts it right under the new top row, with one editor and not last. 立即发送一次 computes to 12px while the footer computes to 11.5px. Run at the reviewed head b5787fee (on mote, macOS, Bun 1.4.2, Playwright 1.62.0 Chromium + WebKit): - package `bun test`: 265 pass, 0 fail, browser smoke included in both engines. The browser file ran again on its own: 6 pass, 0 fail. - `tsc --noEmit` (typescript 5.9.3, @types/bun 1.4.4): exit 0. - `bun scripts/build.ts` rebuilds `dist/` byte for byte. - `bun scripts/check.mjs`: window-warmup passes. - repo root `HOME=$(mktemp -d) bun test`: 5926 tests, 0 fail. Browser tests skip at the root because bun test doesn't read NODE_PATH. - merges cleanly onto main f2dc68c1. PR CI (test, on-npm) green. Broken by hand, rebuilt into dist/, browser file run again each time: - Only the new-task branch put back (editor appended after the loop): red in both engines. The wait for the editor under the top row times out after 15s. - Footer back on `.link` in index.html and style.css: red in both engines, with run 11.5px instead of 12px. - The whole old renderList: red in both engines, with editorIsLast true and prevIsOpenRow false. - Head restored: green in both engines. Not tried: the page inside a real magpie window. --- packages/window-warmup/dist/plugin.js | 2 +- packages/window-warmup/dist/ui/app.js | 6 +- packages/window-warmup/dist/ui/index.html | 2 +- packages/window-warmup/dist/ui/style.css | 4 +- packages/window-warmup/package.json | 2 +- packages/window-warmup/tests/browser.test.ts | 78 ++++++++++++++++++++ packages/window-warmup/web/app.ts | 5 +- packages/window-warmup/web/index.html | 2 +- packages/window-warmup/web/style.css | 4 +- 9 files changed, 92 insertions(+), 13 deletions(-) diff --git a/packages/window-warmup/dist/plugin.js b/packages/window-warmup/dist/plugin.js index 082a6be..a0a0654 100644 --- a/packages/window-warmup/dist/plugin.js +++ b/packages/window-warmup/dist/plugin.js @@ -963,7 +963,7 @@ import { randomBytes, timingSafeEqual } from "crypto"; import { readFile as readFile3 } from "fs/promises"; import path2, { basename, extname, join as join3, resolve as resolve2 } from "path"; // package.json -var version = "0.1.2"; +var version = "0.1.3"; // src/diagnostics.ts var DIAGNOSTICS_SCHEMA = "window-warmup-diagnostics/1"; diff --git a/packages/window-warmup/dist/ui/app.js b/packages/window-warmup/dist/ui/app.js index c891f0a..1652fad 100644 --- a/packages/window-warmup/dist/ui/app.js +++ b/packages/window-warmup/dist/ui/app.js @@ -1718,13 +1718,13 @@ function renderList() { return nodes; } if (isNew && draft) - nodes.push(rowEl(draft, null, true)); + nodes.push(rowEl(draft, null, true), buildEditor()); for (const t of tasks) { const open = openId === t.id; nodes.push(rowEl(open && draft ? draft : t, t, open)); + if (open && draft) + nodes.push(buildEditor()); } - if (openId && draft) - nodes.push(buildEditor()); return nodes; }); restoreFocus(list, focus); diff --git a/packages/window-warmup/dist/ui/index.html b/packages/window-warmup/dist/ui/index.html index 4556998..af4c62f 100644 --- a/packages/window-warmup/dist/ui/index.html +++ b/packages/window-warmup/dist/ui/index.html @@ -17,7 +17,7 @@
-
+
diff --git a/packages/window-warmup/dist/ui/style.css b/packages/window-warmup/dist/ui/style.css index 0b6885d..dd3bffd 100644 --- a/packages/window-warmup/dist/ui/style.css +++ b/packages/window-warmup/dist/ui/style.css @@ -149,8 +149,8 @@ input.text::placeholder { color:var(--faint); } /* 反馈问题:页脚的低调文字入口 + 两步复制面板(沙箱里打不开外链,只能复制) */ .foot { display:flex; justify-content:flex-end; margin-top:10px; } -.link { color:var(--faint); font-size:11.5px; padding:2px 4px; } -.link:hover { color:var(--fg-2); text-decoration:underline; } +.foot-link { color:var(--faint); font-size:11.5px; padding:2px 4px; } +.foot-link:hover { color:var(--fg-2); text-decoration:underline; } .fb { margin-top:6px; background:var(--card); border:1px solid var(--line); border-radius:10px; padding:10px 12px; display:flex; flex-direction:column; gap:8px; } .fb .hint { margin-top:0; } .fb-row { display:flex; align-items:center; gap:8px; flex-wrap:wrap; } diff --git a/packages/window-warmup/package.json b/packages/window-warmup/package.json index 61a254c..365893a 100644 --- a/packages/window-warmup/package.json +++ b/packages/window-warmup/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/page-window-warmup", - "version": "0.1.2", + "version": "0.1.3", "description": "窗口预热 Window Warmup:定时消息插件,定时给指定供应商/账号/模型发一条短消息,在额度窗口重置后、每天定时或每隔几小时自动预热保活,提前开启5小时/每周订阅额度(配额)窗口,适用 Codex、Claude、GLM 智谱、ZCode 等。Scheduled keep-alive message to warm up quota / usage / rate limit windows after reset (cron-like).", "author": "YangHonghang (https://github.com/YangHonghang)", "type": "module", diff --git a/packages/window-warmup/tests/browser.test.ts b/packages/window-warmup/tests/browser.test.ts index d9a586f..e2bc173 100644 --- a/packages/window-warmup/tests/browser.test.ts +++ b/packages/window-warmup/tests/browser.test.ts @@ -30,6 +30,8 @@ interface FrameLocator { } interface Page { frameLocator(selector: string): FrameLocator; + evaluate(fn: () => T): Promise; + waitForFunction(fn: () => boolean, arg?: unknown, o?: { timeout?: number }): Promise; } interface Browser { newPage(): Promise; @@ -162,3 +164,79 @@ for (const [name, engine] of ENGINES) { 90_000, ); } + +for (const [name, engine] of ENGINES) { + testBrowser( + `${name}:编辑区原地展开在所点的行(含新建任务的新行)下面;页脚链接样式不串到编辑区按钮`, + async () => { + // 经服务 API 先建两个任务(口令取自首页 boot 数据块) + const base = `http://127.0.0.1:${svc.port}`; + const html = await (await fetch(base)).text(); + const token = String(JSON.parse(/id="boot"[^>]*>([\s\S]*?)<\/script>/.exec(html)![1]).token); + const ids: string[] = []; + for (const taskName of ["原地展开甲", "原地展开乙"]) { + const res = await fetch(`${base}/api/tasks`, { + method: "POST", + headers: { "x-window-warmup-token": token, "content-type": "application/json" }, + body: JSON.stringify({ + name: taskName, enabled: false, provider: "acme", account: "me@x.com", model: "", message: "hi", + trigger: { kind: "daily", time: "06:00", timeZone: "Asia/Shanghai" }, + }), + }); + ids.push(((await res.json()) as { id: string }).id); + } + const browser = await engine.launch(); + try { + const page = await browser.newPage(); + await page.goto(`${base}/?lang=zh`); + await page.getByText("原地展开甲").first().click(); + await page.getByPlaceholder("给任务起个名字").waitFor({ timeout: 15_000 }); + // 编辑区的前一个兄弟就是展开的那一行,且那一行不是列表最后一行 + const layout = await page.evaluate(() => { + const ed = document.querySelector("#list .editor"); + const prev = ed?.previousElementSibling; + return { + prevIsOpenRow: !!prev?.classList.contains("open"), + prevName: prev?.textContent?.includes("原地展开甲") ?? false, + editorIsLast: ed === document.querySelector("#list")?.lastElementChild, + }; + }); + expect(layout).toEqual({ prevIsOpenRow: true, prevName: true, editorIsLast: false }); + // 编辑区的「立即发送一次」走 .link 自己的 12px;页脚「反馈问题」是独立的 .foot-link(11.5px), + // 两者共用类名时页脚规则会覆盖编辑区按钮 + const sizes = await page.evaluate(() => { + const run = [...document.querySelectorAll("#list .editor button")].find((b) => b.textContent === "立即发送一次"); + const foot = document.getElementById("feedback"); + return { + run: run ? getComputedStyle(run).fontSize : null, + foot: foot ? getComputedStyle(foot).fontSize : null, + }; + }); + expect(sizes).toEqual({ run: "12px", foot: "11.5px" }); + + // 列表里已有任务时新建:编辑区紧跟顶部的新行,不跑到列表末尾 + await page.getByRole("button", { name: "新建任务" }).click(); + await page.waitForFunction(() => { + const ed = document.querySelector("#list .editor"); + return !!ed && ed.previousElementSibling === document.querySelector("#list")?.firstElementChild; + }, undefined, { timeout: 15_000 }); + const added = await page.evaluate(() => { + const list = document.querySelector("#list"); + const ed = list?.querySelector(".editor"); + return { + editors: list?.querySelectorAll(".editor").length ?? 0, + prevIsOpenRow: !!ed?.previousElementSibling?.classList.contains("open"), + editorIsLast: ed === list?.lastElementChild, + }; + }); + expect(added).toEqual({ editors: 1, prevIsOpenRow: true, editorIsLast: false }); + } finally { + await browser.close(); + for (const id of ids) { + await fetch(`${base}/api/tasks/${id}`, { method: "DELETE", headers: { "x-window-warmup-token": token } }); + } + } + }, + 90_000, + ); +} diff --git a/packages/window-warmup/web/app.ts b/packages/window-warmup/web/app.ts index 0d47c7c..f31e569 100644 --- a/packages/window-warmup/web/app.ts +++ b/packages/window-warmup/web/app.ts @@ -1352,12 +1352,13 @@ function renderList(): void { nodes.push(e); return nodes; } - if (isNew && draft) nodes.push(rowEl(draft, null, true)); + // 编辑区紧跟在展开的那一行下面(原地展开),不是列表末尾 + if (isNew && draft) nodes.push(rowEl(draft, null, true), buildEditor()); for (const t of tasks) { const open = openId === t.id; nodes.push(rowEl(open && draft ? draft : t, t, open)); + if (open && draft) nodes.push(buildEditor()); } - if (openId && draft) nodes.push(buildEditor()); return nodes; }); restoreFocus(list, focus); diff --git a/packages/window-warmup/web/index.html b/packages/window-warmup/web/index.html index 4556998..af4c62f 100644 --- a/packages/window-warmup/web/index.html +++ b/packages/window-warmup/web/index.html @@ -17,7 +17,7 @@
-
+
diff --git a/packages/window-warmup/web/style.css b/packages/window-warmup/web/style.css index 0b6885d..dd3bffd 100644 --- a/packages/window-warmup/web/style.css +++ b/packages/window-warmup/web/style.css @@ -149,8 +149,8 @@ input.text::placeholder { color:var(--faint); } /* 反馈问题:页脚的低调文字入口 + 两步复制面板(沙箱里打不开外链,只能复制) */ .foot { display:flex; justify-content:flex-end; margin-top:10px; } -.link { color:var(--faint); font-size:11.5px; padding:2px 4px; } -.link:hover { color:var(--fg-2); text-decoration:underline; } +.foot-link { color:var(--faint); font-size:11.5px; padding:2px 4px; } +.foot-link:hover { color:var(--fg-2); text-decoration:underline; } .fb { margin-top:6px; background:var(--card); border:1px solid var(--line); border-radius:10px; padding:10px 12px; display:flex; flex-direction:column; gap:8px; } .fb .hint { margin-top:0; } .fb-row { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }