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; }