A local-first multi-agent app development platform, built on PenguinHarness
test(e2e): 成本中心「标记已读」有了真浏览器用例(条目 7.7)
lmliheng122f56d05323
diff --git a/docs/FORK-PROGRESS.md b/docs/FORK-PROGRESS.mdindex c72f6c75..25544c8e 100644--- a/docs/FORK-PROGRESS.md+++ b/docs/FORK-PROGRESS.md@@ -1094,6 +1094,19 @@ mock 路由导入序、`chat-page.tsx` 的旧探针体),自带 4 份用例**为什么不悬停实时那一行**:活动分组在流式视图里持续重渲染,`hover()` 的稳定性检查永远等不到,重载后从 Trace 读回来的卡片才是读者真会遇到的形态。反证(两处标记删掉 / 提示规则不认 `extra`)与实测见该节。+- [x] **7.7 成本中心「标记已读」的两半有了真浏览器用例(5.40)**(**2026-10-19 第八十四轮**落地,提交见+ 该节;1 个新文件 `packages/web/e2e/cost-center-read.spec.mjs`,两条用例,**无源码改动、无新依赖**):+ 第六十二轮把 5.40 修好时(加载时刷新探针 + 写入成功后才收起),证据只有一次性探针+ (`r62/probe.mjs`),套件里没有一条用例钉住它,而它的两半都只在「页面早就打开了」这一种情形下+ 才暴露。两条用例:① 先在应用打开**之前**造一条未预期错误(mock 的 401 分支进来,`error_records`+ 里是 `llm_fatal` / `unexpected`),打开应用时抓住它自己那次探针请求(记下启动时的 `total`),+ **过了记录器的 2 秒去重窗口**再造第二条(403 配额分支),然后用侧栏链接在应用内进成本中心 ——+ 必须看到一次新的探针请求(`total` 变大)、提醒写的是新数字、窗口标记还在(证明没有整页重载),+ 点「标记为已读」之后存下的是**最新那条错误的 `ts`**,重载后提醒不再回来;② 用 `page.route` 把+ `PUT /api/me/prefs` 拒成 400 —— 提醒留着、弹出服务端那句话、存下的标记一个字没动;放行后重试+ 才真正收起。**为什么用真错误、不写库**:spec 拿不到 `run.sh` 的 `mktemp` 数据根,而两条失败都是+ 产品自己的路径。反证(拿掉加载时那次刷新 → 用例①红在「探针没有重读」;把 `dismissTodo` 换回+ 乐观写 → 用例②红在「没有提示、提醒当场消失」)与实测见该节。## 发布 v0.2.0(2026-10-05)@@ -1699,6 +1712,7 @@ v0.2.2」——它只加台账里 v0.2.2 那一节与两行表格,**跟本轮| 2026-10-18 | 7.4 | **结束的定时任务从列表里消失有了真浏览器用例**(不是移植,是补本仓自己的测试设施;1 个新文件 `packages/web/e2e/schedule-settled.spec.mjs`,94 行,**无源码改动**):5.48 把已结算(`done` / `missed` / `expired`)的定时任务文件移进 `schedule/expired/`,服务端用例钉住了文件移动,用户看得见的那一半(列表上那一行自己消失、筛选条里不再有「已完成」)此前只有一次性探针。这条用例建一条 `startAt = now + 8s`、绑在一个真会话上的一次性任务,打开 `/schedules` 断言行在、三个筛选都在而「已完成」不是按钮,然后**不点不动**等调度器在 30 s 的那一拍里触发它 —— 归档发生在 `schedule_fired` 之前,这条事件触发的重读因此不再列出它,行自己消失;再逐个点过三个筛选都不会把它带回来。夹具幂等(先 DELETE 同名的残留、创建 / 绑定会话都容忍既有),单跑一条也成立 | 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 报 **`src/ifaces.json unchanged`**,192 接口 / 587 类型 —— 本笔不碰源码)· `npx oxlint` **0 警告 0 错误**(2214 文件)· 新文件 `prettier --check` 干净 · `git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**:core **1399** / 6 跳过 · ui **1043** · cli **561** · web **3202** / 2 跳过 · server **201 文件 / 2946 通过 / 4 跳过** · hmr 无测试文件 · **真服务 + 真浏览器整套 e2e**(一次性数据根 `/root/adelie-fork-data/r81-e2e`、`localhost:8936`,自带 `mock-llm.mjs` 起在 `8937`、`ADELIE_SEED_ADMIN_PASSWORD=penguin-2026`):`npx playwright test -c e2e/playwright.config.mjs` → **80 passed(6.4m)、0 failed**(原 79 条 + 本笔 1 条;本笔单跑 28.1s)· **反证(旧行为)**:把三处归档调用(`send` 里 `markFired` 之后、`listAgent`、对账)全部注释掉、重建服务端、同一数据根重启 —— 同一条用例 **1 failed**,`expect(locator).toHaveCount(0)` 75 s 内拿到 **1**(那一行作为 `done` 一直留在列表里);还原源码、重建、重启后 **1 passed**。**过程中量到的一件事**:只关 `send` 与 `listAgent` 两处时用例**仍然是绿的** —— 下一拍的对账会归档,三个归档点互为兜底,所以反证要三处一起关 · 归档实测:`schedule/` 里没有任务文件了,`schedule/expired/` 里 5 份 `settle_probe*.toml` 各 130 字节、内容与写入时逐字相同(第一份无后缀,之后按 UTC 戳加后缀,正是同名不覆盖的规则)· 端口只用 8936 / 8937(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在 `/root/adelie-fork-data/r81{,-sched,-e2e}`,一个字节没往 `~/.penguin` / `~/.adelie` 里写(`packages/*/dist` 是构建产物,未 `git add`) | 见本行提交 || 2026-10-18 | 7.5 | **悬停提示的两条规则有了真浏览器用例**(不是移植,是补本仓自己的测试设施;1 个新文件 `packages/web/e2e/tooltip.spec.mjs`,163 行 / 三条用例,**无源码改动、无新依赖**):5.35(底部工具条上的提示改向上弹出,`belowTrigger(rect, viewport, height)`)、5.44(`data-tooltip-extra` 让补充信息的提示在完整可见的文字上也弹,只复述可见文字的不弹)、5.46(被省略号 / 行钳截断的一行悬停即得全文,`shortenedLines()` 兜底)三笔落地时证据都在 `packages/ui` 的单测与一次性探针里,套件里没有一条用例听过应用根部那一个 `TooltipLayer` 的真实指针事件。三条用例分治,且每条先量前提再断言结果:① `/agents` 上一张卡片的名字被省略号截断(`scrollWidth 1024 > clientWidth 369`),悬停后提示面板弹出、文字是完整的名字;② 真会话的输入框工具条上那枚上下文圆环贴着窗口底边(720 高的视口里圆环底边在 699、下方余量 5 px 小于面板实测高度 26 px),悬停后面板内联样式是 `bottom: 61px` 而 `top` 为空、面板矩形 633–659 整块落在圆环(684)之上;③ 同一页「最后修改」的可见文字是「今天」,悬停后面板带出「最后修改」加完整时间;移开指针面板消失,再悬停只重复可见数字的「N 个 Session」,等 800 ms(开门延迟 400 ms)仍是 0 个面板 | 六包 `typecheck` **`EXIT=0`**(core / server / web / ui / cli / hmr 六个 `Done`;`gen:ifaces` 报 `src/ifaces.json unchanged`,192 接口 / 587 类型 —— 本笔不碰源码)· `npx oxlint` **0 警告 0 错误**(2215 文件)· 新文件 `prettier --check` 干净 · `git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**:core **1399** / 6 跳过 · ui **1043** · cli **561** · web **260 文件 / 3202 通过 / 2 跳过** · server **201 文件 / 2946 通过 / 4 跳过**(hmr 无测试文件)· **真服务 + 真浏览器整套 e2e**(一次性数据根 `/root/adelie-fork-data/r82-tooltip`、`localhost:8936`,自带 `mock-llm.mjs` 起在 `8937`、`ADELIE_SEED_ADMIN_PASSWORD=penguin-2026`):`npx playwright test -c e2e/playwright.config.mjs` → **83 passed(6.7m)、0 failed**(原 80 条 + 本笔 3 条;本笔单跑 7.3s)· **反证(三处规则一起改坏,重建 web)**:`shortenedLines()` 开头 `return null`、`belowTrigger` 的竖向判定改成恒为「下方」、`hintAllowedFor` 传 `extra && false` → **3 failed**,三条各自死在自己的断言(面板不出现 / `inlineBottom` 是空串 / 面板不出现);还原源码、重建、再跑 → **3 passed** · **真看一眼**(管理员登录,console **0 error**、**无一条 ≥400**):截图 `r82/{agents-truncated-hover,agents-extra-hover,composer-ring-hover}.png` 在 scratchpad · 端口只用 8936 / 8937(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在 `/root/adelie-fork-data/r82-tooltip`,一个字节没往 `~/.penguin` / `~/.adelie` 里写 | 见本行提交 || 2026-10-19 | 7.6 | **5.46 的另一半有了真浏览器用例:工具卡副标题与工作区分组表头的完整路径**(不是移植,是补本仓自己的测试设施;1 个新文件 `packages/web/e2e/path-hints.spec.mjs`,138 行 / 两条用例,外加 `mock-llm.mjs` 一条 `read deep path test <path>` 分支,**无源码改动、无新依赖**):5.46 给 `ToolCallCard` 的 `subtitleFull`(`…/父目录/文件`)与 `GroupHeader.title`(工作区完整路径,标记 `data-tooltip-extra`)挂了提示,落在 `ui`/`web` 的单测与第七十轮一次性探针里,套件里没有一条用例让应用根部那一个 `TooltipLayer` 真收到指针。用例①:mock 回一个 `read_file`(路径抄自提示词,`read deep path test <abs>`;标题请求靠 `!isTitle` 挡住)→ 等收尾行、**重载**、点开折叠的活动分组、悬停副标题(`…/three/deep-notes.txt`)→ 属性 `data-tooltip` 是完整路径、`content=code`、`extra=true`,面板文字是完整路径且等宽;用例②:深路径 + 短基名工作区 `…/projects/alpha/beta/brief` → 侧栏表头标签`brief` 放得下(先断言 `scrollWidth <= clientWidth`),悬停 → 面板是完整路径、非等宽(`content=text`)。**为什么不悬停流式那一行**:活动分组在实时视图里持续重渲染,`hover()` 的稳定性检查等不到(实测 90 s 超时,元素不断被替换),重载后从 Trace 读回的卡片才是读者真会遇到的形态。正则的停字符集是`[^"\s\\]`:提示词在 JSON 里,`\S+` 会把收尾引号与括号一起吞进参数(首跑就是这么坏的,副标题显示成`…/deep-notes.txt"}]}`) | 六包 `typecheck` **`EXIT=0`**(core / server / web / ui / cli / hmr 六个 `Done`;`gen:ifaces` 报 `src/ifaces.json unchanged`,192 接口 / 587 类型)· `npx oxlint` **0 警告 0 错误**(2216 文件)· 两个改动的文件 `prettier --check` 干净(`mock-llm.mjs` 首跑一条,`--write` 后复检)· `git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**:core **1399 / 6 跳过**(68 文件)· ui **1043**(129)· cli **561**(38)· server **201 文件 / 2946 通过 / 4 跳过** · web **260 文件 / 3202 通过 / 2 跳过**(hmr 无测试文件)· **真服务 + 真浏览器整套 e2e**(一次性数据根 `/root/adelie-fork-data/r83-e2e`、`localhost:8942`,自带 `mock-llm.mjs` 起在 `8943`、`ADELIE_SEED_ADMIN_PASSWORD=penguin-2026`):`npx playwright test -c e2e/playwright.config.mjs` → **85 passed(6.4m)、0 failed**(原 83 条 + 本笔 2 条;本笔单跑 5.8s)· **反证一(两处标记删掉,重建 web)**:`subtitleFull={null}`、`GroupHeader` 去掉 `data-tooltip-extra` → **2 failed**(各自的属性断言)· **反证二(提示规则不认 `extra`)**:`hintAllowedFor` 传 `false && extra` → **2 failed,都死在面板不出现**(属性都还在,钉住的正是「应用根部那一个层真听见指针」)· **真看一眼**(`pathhints` 普通用户、1280×900,探针 `r83/look.cjs`):工具卡副标题显示 `…/three/deep-notes.txt`,面板 `/tmp/penguin-pathhint-lPBEbL/one/two/three/deep-notes.txt`、字体 `JetBrains Mono Variable`;工作区表头标签 `brief`(`fits: true`),面板完整路径、字体 Mona Sans;截图 `r83/{tool-subtitle-hover,workspace-header-hover}.png`;console 只有两条已知的、普通用户按设计拿不到的 `/api/projects/…/machines` 403(第七十九 / 八十二轮记过),**无其它 error、无其它 ≥400** · 端口只用 8940 / 8941(迭代)与 8942 / 8943(整套,跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在 `/root/adelie-fork-data/r83{,-hints,-e2e}`,一个字节没往 `~/.penguin` / `~/.adelie` 里写(`packages/*/dist` 与 `test-results/` 都是产物,未 `git add`) | 见本行提交 |+| 2026-10-19 | 7.7 | **成本中心「标记已读」的两半有了真浏览器用例**(不是移植,是补本仓自己的测试设施;1 个新文件 `packages/web/e2e/cost-center-read.spec.mjs`,174 行 / 两条用例,**无源码改动、无新依赖**):5.40(第六十二轮)修的两件事——成本中心加载时重读未预期错误探针、`dismissTodo` 在写入成功之后才收起——此前只有第六十二轮的一次性探针,而两半都只在「页面早就打开、新的错误在打开之后才到」这种情形下才暴露。用例①:先用 mock 的 401 分支造一条未预期错误(`error_records` 里是 `llm_fatal` / `unexpected`),打开 `/chat/<会话>` 并**抓住应用自己那次探针请求**(记下启动时的 `total`),**等过记录器 2 秒去重窗口**再用第二个会话走 403 配额分支造第二条,然后点侧栏的「成本中心」在应用内换页 —— `page.on("response")` 收到的新探针 `total` 必须变大、页面提醒写的就是这个数字、换页前写到 `window` 上的标记还在(证明没有整页重载);点「标记为已读」后 `ui_prefs.todoDismissed[项目].errors` 必须是**最新那条错误的 `ts`**,重载后提醒不回来。用例②:`page.route` 把 `PUT /api/me/prefs` 拒成 400 —— 提醒留着、弹出服务端那句话、存下的标记与点之前逐字相同;`unroute` 后重试才收起。**为什么用真错误、不直接写库**:spec 拿不到 `run.sh` 的 `mktemp` 数据根,两条失败又都是产品自己的路径(401 认证 / 403 配额),真跑一遍反而更接近读者遇到的形态;断言里的数字全部取自页面自己收到的响应,所以在同一个数据根上重跑也成立 | 六包 `typecheck` **`EXIT=0`**(`pnpm typecheck` 十四个 `Done`,含 core / server / web / ui / cli / hmr;`gen:ifaces` 报 **`src/ifaces.json unchanged`(192 接口 / 587 类型)** —— 本笔不碰源码)· `npx oxlint` **0 警告 0 错误**(2217 文件)· 新文件 `prettier --check` 干净 · `git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**:core **1399 / 6 跳过**(68 文件)· ui **1043**(129)· cli **561**(38)· web **260 文件 / 3202 通过 / 2 跳过** · server **201 文件 / 2946 通过 / 4 跳过**(hmr 无测试文件)· **真服务 + 真浏览器整套 e2e**(`SKIP_BUILD=1 pnpm -C packages/web test:e2e`,自带 `mktemp` 数据根、mock 在 8931、服务端在 8930):**87 passed(6.5m)、0 failed**(原 85 条 + 本笔 2 条;本笔单跑 6.1s)· **反证一(拿掉加载时那次刷新,重建 web)**:`usage-page.tsx` 的 `refreshProjectTodos(projectId)` 注释掉 → 用例①**红**在「探针 `total` 没有变大」(`Expected: > 9, Received: 9`,15 s 内一直停在启动时那个数)· **反证二(`dismissTodo` 换回乐观写)**:本地状态先落、PUT fire-and-forget、失败吞掉 → 用例②**红**在「没有那句提示」(提醒当场消失、用户以为存住了)· 还原两份源码、重建、再跑 → **2 passed** · **真看一眼**(`costread` 普通用户、1280×900,探针 `r84/look.mjs`):提醒是「15 条未预期错误」(数据根上累积的),按钮 `aria-label` 为「标记已读 · 15 条未预期错误」;点掉并重载后提醒计数 **0**;console 只有两条**按设计**的 `GET …/machines` **403**(第七十九 / 八十二 / 八十三轮记过,端点只给管理员),无其它 error、无其它 ≥400;截图 `r84/shots/{usage-notice,usage-notice-hover,usage-after-read}.png` 在 scratchpad · 端口只用 8944 / 8945(探针与迭代)与 8930 / 8931(整套,跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在 `/root/adelie-fork-data/r84{,-run,-probe}`,一个字节没往 `~/.penguin` / `~/.adelie` 里写(`packages/*/dist` 与 `test-results/` 都是产物,未 `git add`) | 见本行提交 |> **2026-10-11 与另一条线的交汇(第三十七轮)**:定时任务触发时(07:00)`git status --short` **不干净**> —— 另一条线(会话 `session-2026-10-05-20-32-50-2ee69aba`)正在做**用户点单**的「回复能复制成纯文本」@@ -10990,3 +11004,87 @@ Escape 再来一次,四次的预算。连跑三次稳定。用例** —— 今天只有真浏览器两态探针(第六十二轮),套件里没有;或者 **5.35 的另一半**(提示在竖栏里向右展开,`belowTrigger` 的 `right` 分支)—— 今天只有单测。- 卡点原地:**2.2c**、**3.5**、**3.6**、**4.2** / **4.3**、**5.6** / **5.10**。++## 第八十四轮:成本中心「标记已读」的两半有了真浏览器用例(2026-10-19,条目 7.7)++### 开工自检与选活理由++- 同步:开工时 `git status --short` 干净,`main` 停在 `87cc898f`(第八十三轮那笔),+ `git fetch origin && git merge --ff-only origin/main` = Already up to date(没切分支、没碰 `legacy/main`、+ 没推 upstream、没改 remote 配置)。+- 上游:`/root/penguin-harness` 仍不在(`git fetch upstream` 报 `does not appear to be a git repository`),+ 按第八十二 / 八十三轮记的纪律没改 remote;仓库里现存的探针引用最新是 `refs/adelie-tmp/upstream-main-r83`+ = **`e32ca1ea`**(第八十一轮量过的 `#1160`,压在要本树没有六个文件的 `#1152` 上),这一轮没有新的上游小件。+- 待办里最靠前的未勾选条目仍是 **2.2c**(剩下的活全在桌面壳一侧与既有部署单元里,本轮纪律不许碰 desktop),+ 其后 **3.5**(要拍板取哪个桌面壳)、**3.6**(模型 key)、**4.1–4.3**(明令不动)、**5.6** / **5.10**+ (要拍板 / 要新依赖)同样不可动;7.1–7.6 已勾掉。于是照第八十三轮末尾写下的建议做 7.7:+ 5.40 今天只有第六十二轮的一次性探针,套件里没有一条用例钉住它。++### 先量清楚「能不能用真错误造出那两行」(都不是推测)++- **401 认证失败**:`POST /api/sessions/<id>/tasks` 发 `auth dead test` → mock 回 401 →+ Trace 里 `request_end(status: fatal, error_code: "auth")`,`error_records` 里一条+ `kind=unexpected / source=llm / code=llm_fatal`(`1|…|unexpected|llm|llm_fatal|…`,sqlite 直查)。+- **403 配额失败**:同一个 mock 分支表里 `quota fatal test` → Trace 是 `error_code: "rejected"`,+ 记录器归到**同一个** `llm_fatal` —— 于是 `(source, code, Project)` 的三元组相同,撞上+ `DEDUP_WINDOW_MS = 2000` 的去重:**两条错误隔得太近时后一条根本不会落库**(本轮实测第一次跑就撞上,+ 两条只落了一条)。用例因此在两条之间等 2.5 s,并把这件事写进注释。+- **成本中心的提醒**就是 `use-project-todos.ts` 的那一次一行读取(`limit=1&kind=unexpected`、7 天窗),+ 签名是最新一条的 `ts`;标记存在 `ui_prefs.todoDismissed[项目].errors`。+- **为什么不让 spec 直接写库**:`run.sh` 的数据根是 `mktemp -d`,只交给服务端进程,spec 看不到;+ 给它加一个新环境变量等于把「测试即读者的路径」换成「测试知道内部布局」,两条失败又恰好都是产品自己的+ 路径,所以走真接口造数。++### 改了什么(1 个新文件,两条用例,无源码改动)++- `packages/web/e2e/cost-center-read.spec.mjs`(174 行):+ 1. **「打开之后到的错误要算进来,标记已读后重载不再回来」** —— 应用打开**之前**造第一条(401),+ `page.waitForResponse` 抓住应用自己那次探针请求并记下启动时的 `total`;等 2.5 s、用**第二个会话**+ 造第二条(403。**每个提示词一个会话**:mock 按整个请求体挑分支,跟进消息里带着上一轮的词,+ 同一会话里发第二条会被 401 分支抢走 —— 首跑就是这么坏的);再 `page.on("response")` 收后续探针,+ 点侧栏「成本中心」在应用内换页,`expect.poll` 等 `total` 变大(这就是「加载时重读」那一半),+ 换页前写进 `window` 的标记还在(证明没有整页重载,模块级缓存没被重建),页面提醒写的正是那个数字;+ 点「标记为已读」,轮询 `ui_prefs` 断言存下的是 **最新一条的 `ts`**(不是启动时那条),重载后提醒不回来。+ 2. **「写入被拒就留着提醒、说一句、什么都不存」** —— `page.route` 把 `PUT /api/me/prefs` 拒成 400+ (带一句 `prefs store is closed`):提醒还在、那句话弹出来、`ui_prefs` 里那条与点之前逐字相同;+ `unroute` 后重试才收起。+- **断言里的数字都取自页面自己收到的响应**(启动时那次探针、换页后那次探针),不写死条数,+ 所以在同一个数据根上重跑也成立(本轮就是在 `r84-run` 这个被前面几次试跑弄脏的根上反复跑通的)。+- **没有 changelog**:本笔没有源码改动(与 7.3–7.6 同一口径)。++### 验证++- `pnpm typecheck`:**`EXIT=0`**,十四个 `Done`(core / server / web / ui / cli / hmr / docs / ui-gallery /+ desktop / amsp 与四个 sandbox 插件);`gen:ifaces` 报 **`src/ifaces.json unchanged`(192 接口 / 587 类型)**。+- `npx oxlint`:**0 警告 0 错误**(2217 文件);新文件 `prettier --check` 干净;`git diff --check` 干净。+- 逐包 test:全部 `EXIT=0`、**0 失败** —— core **1399 通过 / 6 跳过**(68 文件)· ui **1043**(129)·+ cli **561**(38)· web **260 文件 / 3202 通过 / 2 跳过** · server **201 文件 / 2946 通过 / 4 跳过**。+- **真服务 + 真浏览器整套 e2e**(`SKIP_BUILD=1 pnpm -C packages/web test:e2e`:脚本自己的 `mktemp` 数据根、+ mock 在 8931、服务端在 8930):**87 passed(6.5m)、0 failed**(原 85 条 + 本笔 2 条)。+ 本笔单跑(迭代时在 8944 的干净数据根 `r84-run` 上)**6.1s**。+- **反证一(拿掉「加载时刷新探针」这一半)**:`usage-page.tsx` 里 `refreshProjectTodos(projectId)` 注释掉、+ 重建 web、同一条命令 → 用例①**红**:`expect.poll(() => latest?.total).toBeGreaterThan(atStartup)` 15 s+ 内一直停在启动时那个数(`Expected: > 9, Received: 9`),也就是「打开之后到的错误从来没被算进来」。+- **反证二(`dismissTodo` 换回乐观写)**:本地状态先落、`putPrefs` fire-and-forget、失败吞掉+ (第六十二轮改掉的样子)、重建 web → 用例②**红**在「没有那句提示」(提醒当场消失、`ui_prefs` 一个字没写,+ 用户以为存住了)。两处源码从 scratchpad 的留底 `cp` 回来、`git diff` 为空、重建后 **2 passed**。+- **真看一眼**(`costread` 普通用户、1280×900、`r84/look.mjs`):成本中心标题下的提醒是+ 「15 条未预期错误」(这个数据根上累积的),按钮 `aria-label` 是「标记已读 · 15 条未预期错误」,+ 侧栏「成本中心」带红点;点掉之后重载,提醒计数 **0**。console 只有两条**按设计**的+ `GET /api/projects/…/machines` **403**(第七十九 / 八十二 / 八十三轮记过:端点只给管理员),+ 无其它 error、无其它 ≥400。截图 `r84/shots/{usage-notice,usage-notice-hover,usage-after-read}.png`、+ 探针 `r84/look.mjs` 在 scratchpad。+- 端口只用 8944 / 8945(迭代与探针)与 8930 / 8931(整套,跑完都已停),3003 / 3004 / 4000 / 7364 / 7369+ 一个没碰;数据只落在 `/root/adelie-fork-data/r84{,-run,-probe}`,一个字节没往 `~/.penguin` / `~/.adelie`+ 里写(`packages/*/dist` 与 `test-results/` 都是产物,未 `git add`)。+- 没有切版本号、没发 npm、没发安装包、没发发布汇总。++### 下一轮从这里接++- **待办里仍没有可做的一轮内条目**:2.2c(桌面壳 / 部署单元)、3.5(拍板)、3.6(模型 key)、+ 4.1–4.3(明令不动)、5.6 / 5.10(拍板 / 新依赖);7.7 本轮勾掉。+- **上游**:先看 `/root/penguin-harness` 在不在;不在就按 URL 路子拉一次,尖端仍是 `e32ca1ea` 的话没有新小件。+- 若还从「本仓自己的验证设施」里挑,下一件建议是 **5.35 的另一半**(提示在竖栏里向右展开,+ `belowTrigger` 的 `right` 分支 / `besideTrigger`)—— 今天只有 `packages/ui` 的单测;+ 之后可以考虑 **成本中心「清空错误」的确认与写入顺序**(第六十二轮那条队列的第三种形态)。+- 卡点原地:**2.2c**、**3.5**、**3.6**、**4.2** / **4.3**、**5.6** / **5.10**。diff --git a/packages/web/e2e/cost-center-read.spec.mjs b/packages/web/e2e/cost-center-read.spec.mjsnew file mode 100644index 00000000..23ce1baa--- /dev/null+++ b/packages/web/e2e/cost-center-read.spec.mjs@@ -0,0 +1,191 @@+/**+ * Regression: the cost center's "N 条未预期错误" notice counts the errors THIS page load can+ * see, and "mark read" remembers exactly what the reader was shown (upstream #1118, landed in+ * this fork as the 62nd round; `docs/FORK-PROGRESS.md` §5.40).+ *+ * The old behaviour was one defect with two halves, both invisible until a reload: the notice+ * read the error probe cached when the app STARTED (so an error that arrived while the tab was+ * open was never counted — the notice and the table right below it disagreed), and "mark read"+ * stamped that same start-up signature (so the newer error was unread again after the reload,+ * and the dot came back). The fix refreshes the probe when the page loads+ * (`usage-page.tsx`) and writes the marker only after a successful PUT+ * (`todo-dismissals.ts`, serialized so an older write cannot land on top of a newer one).+ *+ * The rows are real server-side surprises rather than inserted ones: the mock rejects the auth+ * prompt with 401 (`unexpected`, source `llm` — only a human can replace the key) and the quota+ * prompt with 403 (`unexpected`, a fatal turn). A turn BEFORE the app opens, then a second one+ * after, is exactly the shape the defect hides in. Every number this spec asserts comes out of+ * a response the page itself received, so a rerun on a data root that is not fresh still+ * distinguishes "what the app was told at start-up" from "what is there now".+ */+import { test, expect } from "@playwright/test";+import { provisionAndLogin } from "./auth.mjs";++const BASE = process.env.BASE_URL;+const MOCK = process.env.MOCK_URL;+const P = "password123";++/** The badge's own one-row read; the app makes this request on load and on the cost center. */+const isErrorProbe = (r) => r.url().includes("/usage/errors") && r.request().method() === "GET";++/** Provision the user, point the Project at the mock (a key the mock rejects), open one Session. */+async function prepare(page, userId) {+ await provisionAndLogin(page.request, userId, P);+ const { projects } = await (await page.request.get(`${BASE}/api/projects`)).json();+ const projectId = projects[0].projectId;+ const put = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {+ data: {+ defaultModel: { provider: "custom", modelId: "claude-4-8" },+ models: [+ {+ provider: "custom",+ modelId: "claude-4-8",+ apiKey: "sk-auth-bad",+ baseUrl: MOCK,+ contextWindow: 200000,+ },+ ],+ },+ });+ expect(put.ok(), "put models").toBeTruthy();+ return { projectId, sessionId: await newSession(page, projectId) };+}++/** One more Session on the same Project — each failure below gets its own, see `failedTurn`. */+async function newSession(page, projectId) {+ const sess = await page.request.post(+ `${BASE}/api/projects/${projectId}/agents/default_agent/sessions`,+ { data: { provider: "custom", modelId: "claude-4-8" } },+ );+ expect(sess.ok(), "create session").toBeTruthy();+ return (await sess.json()).session.sessionId;+}++/**+ * One failed turn through the API; resolves once the Trace holds its terminal `request_end`.+ *+ * **One Session per prompt**: the mock picks its branch off the whole request body, so a+ * prompt sent as a follow-up rides on top of the previous turn's words — a second Session in+ * the same Project keeps each request's context to the prompt it was meant to match.+ *+ * Both failures reach `error_records` as `llm_fatal`, and the recorder drops a repeat of the+ * same `(source, code, Project)` inside its 2 s window — hence the gap the caller keeps.+ */+async function failedTurn(page, sessionId, text, code) {+ const res = await page.request.post(`${BASE}/api/sessions/${sessionId}/tasks`, {+ data: { input: [{ type: "text", text }] },+ });+ expect(res.status(), "start task").toBe(202);+ await expect+ .poll(+ async () => {+ const { messages } = await (+ await page.request.get(`${BASE}/api/sessions/${sessionId}/messages`)+ ).json();+ return messages.some(+ (m) => m.payload.type === "request_end" && m.payload.error_code === code,+ );+ },+ { timeout: 30_000 },+ )+ .toBe(true);+}++/** The marker the cost center's "mark read" stores for one Project's error trail, as stored. */+async function storedErrorsMarker(page, projectId) {+ const { prefs } = await (await page.request.get(`${BASE}/api/me/prefs`)).json();+ return prefs.todoDismissed?.[projectId]?.errors;+}++test("the notice counts an error that arrived after the app opened, and marking it read keeps it down after a reload", async ({+ page,+}) => {+ test.setTimeout(120_000);+ const { projectId, sessionId } = await prepare(page, "costread");++ // One error on the books BEFORE the shell loads: this is what the start-up probe caches.+ await failedTurn(page, sessionId, "auth dead test", "auth");++ // Open the app while catching the badge's own probe: from here on the client's answer is+ // the start-up one, which is what the old cost center kept showing. Every later probe the+ // page makes lands in `latest`, so "did the cost center re-read?" is an observable fact+ // rather than a guess about when a request should have gone out.+ let latest = null;+ page.on("response", (r) => {+ if (!isErrorProbe(r)) return;+ void r+ .json()+ .then((body) => {+ latest = body;+ })+ .catch(() => {});+ });+ const probed = page.waitForResponse(isErrorProbe);+ await page.goto(`/chat/${sessionId}`);+ const atStartup = (await (await probed).json()).total;++ // Past the recorder's dedup window, then a second, different surprise while the tab stays+ // open: a fresh client would see it too, this one would not — until the cost center+ // refreshes its probe on load.+ await page.waitForTimeout(2_500);+ await failedTurn(page, await newSession(page, projectId), "quota fatal test", "rejected");++ // In-app navigation (a document reload would rebuild the cache and hide the defect): mark+ // the window, follow the sidebar's own link, and check the mark survived.+ await page.evaluate(() => {+ window.__costCenterNoReload = 1;+ });+ await page.getByRole("link", { name: "成本中心" }).click();+ await expect.poll(() => latest?.total, { timeout: 15_000 }).toBeGreaterThan(atStartup);+ expect(await page.evaluate(() => window.__costCenterNoReload)).toBe(1);+ const fresh = latest;+ await expect(page.getByText(`${fresh.total} 条未预期错误`)).toBeVisible();++ // "Mark read" remembers the newest error the reader was just shown — not the start-up one.+ await page.getByRole("button", { name: /^标记为已读/ }).click();+ await expect(page.getByText(/条未预期错误/)).toHaveCount(0);+ await expect+ .poll(async () => {+ const { prefs } = await (await page.request.get(`${BASE}/api/me/prefs`)).json();+ return prefs.todoDismissed?.[projectId]?.errors;+ })+ .toBe(fresh.items[0].ts);++ // Reload: the probe now starts from the same newest error the marker was stamped with, so+ // the notice stays down (before the fix it came back, because the marker was the older ts).+ await page.reload();+ await expect(page.getByText(/条未预期错误/)).toHaveCount(0);+});++test("a refused write leaves the notice up, says so, and stores nothing", async ({ page }) => {+ test.setTimeout(120_000);+ const { projectId, sessionId } = await prepare(page, "costrefuse");++ await failedTurn(page, sessionId, "auth dead test", "auth");++ // The write is refused at the network edge: the user must not be told "done" for a marker+ // that never landed (that was the old behaviour — the notice vanished, nothing was stored).+ await page.route("**/api/me/prefs", async (route) => {+ if (route.request().method() !== "PUT") return route.fallback();+ await route.fulfill({+ status: 400,+ contentType: "application/json",+ body: JSON.stringify({ error: { code: "bad_request", message: "prefs store is closed" } }),+ });+ });+ await page.goto("/usage");+ const notice = page.getByText(/^\d+ 条未预期错误$/);+ await expect(notice).toBeVisible();+ // Whatever a previous run on this data root left behind, a refused write must not move it.+ const before = await storedErrorsMarker(page, projectId);+ await page.getByRole("button", { name: /^标记为已读/ }).click();++ await expect(page.getByText(/prefs store is closed/)).toBeVisible();+ await expect(notice).toBeVisible();+ expect(await storedErrorsMarker(page, projectId)).toBe(before);++ // Let the write through: the retry dismisses for real.+ await page.unroute("**/api/me/prefs");+ await page.getByRole("button", { name: /^标记为已读/ }).click();+ await expect(notice).toHaveCount(0);+});