A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 技能没有导出成时,原因留在发问的那一行下面,不再只活六秒
lmlihenga0435b97c952
diff --git a/changelog/unreleased/2026-11-08-skill-export-refusal.md b/changelog/unreleased/2026-11-08-skill-export-refusal.mdnew file mode 100644index 00000000..b47c70ec--- /dev/null+++ b/changelog/unreleased/2026-11-08-skill-export-refusal.md@@ -0,0 +1,55 @@+# A skill that failed to export says why under the row that asked++- **Date:** 2026-11-08+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文](2026-11-08-skill-export-refusal.zh.md)++Every row of Agent settings → Skills has an "Export as zip": it fetches the installed directory as a+zip and hands it to the browser through a temporary object URL. When the server refused that+download, the skill was still installed, the row was still on screen, and even the button that was+pressed was still there — but the only account of why was a notification that dismissed itself after+six seconds, floating above the list while the reader's eyes were on a row below it.++That is the shape 7.19 bans. A failed export is the one moment a reader wonders whether the installed+copy was touched, so the sentence says the skill is still installed on the Agent as well as why the+export did not land.++The reason now renders under the row that asked (`role="alert"`, the danger tone, two lines at most,+the whole sentence on hover) until the next attempt begins; pressing the same export button is the+retry. Which row draws it is decided by the skill's name, one at a time, and no other row changes by+a character.++## Details++- `packages/web/src/features/agents/skill-export-refusal.ts` (new): `skillExportRefused(skill, error)`+ builds the sentence (the reason goes through `refusalText`, the one rule every refusal in the app+ follows), and `skillExportRefusalFor(refusal, skill)` decides which row this refusal belongs to.+- `packages/web/src/features/agents/skills-tab.tsx`: `exportSkill` no longer posts a toast on failure;+ it keeps `{ skill, text }` and hands it to that row, and the start of every attempt clears the+ previous sentence (it belonged to the attempt before). The list row goes from a single flex line to+ "row + optional reason line"; the hover background and the divider stay on the outer element, and+ nothing else about the layout moves.+- `packages/web/src/lib/strings{,-en}.ts`: one new sentence, `skills.exportRefused(skill, reason)`.++## Tests++- `packages/web/test/skill-export-refusal.test.ts` (new, 9 cases): the server's reason read through+ its code (never the wire message), a sentence this codebase raised itself kept as written, the+ generic text when nothing was said, the skill named, the installed copy called out, and the English+ sentence; plus three on "a refusal belongs only to its own row".+- `packages/web/e2e/skill-export-refusal.spec.mjs` (new, real server + real browser): the export+ button of a skill that really is installed, with the archive route refused at `page.route` with a+ 500. The sentence appears exactly once, under that row, word for word in the interface's own+ language; the notification region does not carry it; the row's own line reads exactly as it did+ before the attempt; it is **still there seven seconds later**; and the server's installed list is+ unchanged. Allowed, the same button pressed again makes the sentence go and really hands the zip to+ the browser as a download.++## Compatibility++No interface change, no new dependency, no Project config change. The rest of the Skills tab — the two+import paths (chat and zip upload), the uninstall confirmation and its own refusal line, the+prompt-injection controls — is unchanged.diff --git a/changelog/unreleased/2026-11-08-skill-export-refusal.zh.md b/changelog/unreleased/2026-11-08-skill-export-refusal.zh.mdnew file mode 100644index 00000000..b73ba124--- /dev/null+++ b/changelog/unreleased/2026-11-08-skill-export-refusal.zh.md@@ -0,0 +1,43 @@+# 技能没有导出成时,原因留在发问的那一行下面++- **日期:** 2026-11-08+- **类型:** 修复+- **范围:** `web`+- **破坏性变更:** 无++[English](2026-11-08-skill-export-refusal.md)++Agent 设置 → 技能页每一行都有「打包导出」:它拉一次那棵已安装目录的 zip,再用一个临时的对象地址把它交给浏览器。+服务端拒了这次下载时,技能还在、那一行还在、连按下去的按钮都还在原地,可唯一解释原因的那句话是一条六秒后自己+消失的通知 —— 它浮在列表上方,而读者视线落在下面某一行上。++这正是 7.19 禁止的形状。导出失败是唯一会让人担心「已安装的那份是不是被动了」的时刻,所以句子除了念原因,还+明说技能仍然装在这个 Agent 上。++原因现在画在发问的那一行下面(`role="alert"`、危险色、最多两行、整句挂悬停),留到下一次尝试开始为止;再按+一次那颗导出按钮就是重试。哪一行读这句话由技能名决定,同一时刻只有一条,别的行一个字都不变。++## 细节++- 新增 `packages/web/src/features/agents/skill-export-refusal.ts`:`skillExportRefused(skill, error)` 造句+ (原因走 `refusalText`,与全应用每一个拒绝同一个规则),`skillExportRefusalFor(refusal, skill)` 决定这次+ 拒绝归哪一行。+- `packages/web/src/features/agents/skills-tab.tsx`:`exportSkill` 失败时不再弹通知,而是记下 `{ skill, text }`+ 并交给那一行;每次尝试开始先清掉上一句(它属于上一次尝试)。列表行从单行 flex 改成「行 + 可选的拒绝行」,+ 悬停背景与分隔线留在外层,其余排版不动。+- `packages/web/src/lib/strings{,-en}.ts`:新增一句 `skills.exportRefused(skill, reason)`。++## 测试++- `packages/web/test/skill-export-refusal.test.ts`(新增,9 条):服务端的原因按错误码念(绝不念线上原文)、+ 界面自己抛出的句子原样保留、什么都没说时落到通用文案、念出技能名、点明它仍装在这个 Agent 上、英文那一句;+ 以及「这条拒绝只归它自己那一行」的三条。+- `packages/web/e2e/skill-export-refusal.spec.mjs`(新增,真服务端 + 真浏览器):从一个真装着的技能行点导出,+ 归档路由被 `page.route` 拒成 500;断言句子只出现一次、就在那一行下面、逐字是界面自己的话、通知区里没有它、+ 那一行自己的文字与尝试前一模一样、**七秒之后**还在,并且服务端那份已安装列表没有变化。放行后同一颗按钮再按+ 一次:句子消失,zip 真的作为下载交到浏览器手上。++## 兼容性++不改接口、不引入新依赖、不改 Project 配置。技能页的其它行为 —— 导入(对话 / zip 两条路)、卸载确认框与其+拒绝行、提示词注入开关 —— 原样不变。diff --git a/packages/web/e2e/skill-export-refusal.spec.mjs b/packages/web/e2e/skill-export-refusal.spec.mjsnew file mode 100644index 00000000..348141ac--- /dev/null+++ b/packages/web/e2e/skill-export-refusal.spec.mjs@@ -0,0 +1,161 @@+/**+ * Regression: a skill's "Export as zip" that the download refused leaves its reason under the row+ * that asked, instead of only in a notification that dismisses itself after six seconds.+ *+ * The export is a plain fetch of the installed directory (`archive-download.ts`): nothing is+ * written on the server and no client state moves, so a refusal leaves the row, the installed+ * skill and the same button on screen. That is exactly where the reason belongs (7.19's rule) —+ * before this, `exportSkill` answered with `toastError`, and a reader who looked away had no zip+ * file and nothing saying why.+ *+ * The skill is one the base ships with `default_agent` (read from the API, not spelled out here),+ * and the refused download is the page's own request as seen by `page.route` — both halves are the+ * page's contract with the server.+ */+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";+const AGENT = "default_agent";++/** The refused archive: its code's own localized sentence is what the row has to draw. */+const REFUSAL = { code: "internal", message: "the archive could not be read" };+/** S.errors.byCode.internal — the copy that code stands for in a zh-CN interface. */+const REASON = "服务器内部错误,请稍后重试。";++/**+ * Provision the user, give the Project a model (the onboarding overlay covers the page without+ * one), and return the first skill the Agent already has — the row under test — plus a reader for+ * the server's installed list, so "still installed" is checked on both sides.+ */+async function agentWithSkill(page, user) {+ await provisionAndLogin(page.request, user, P);+ const projectId = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0]+ .projectId;+ const models = 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-mock",+ baseUrl: MOCK,+ contextWindow: 200000,+ },+ ],+ },+ });+ expect(models.ok(), "put models").toBeTruthy();++ const installed = async () =>+ (+ await (+ await page.request.get(`${BASE}/api/projects/${projectId}/agents/${AGENT}/skills`)+ ).json()+ ).skills.map((s) => s.name);++ const names = await installed();+ expect(names.length, "default_agent ships skills to export").toBeGreaterThan(0);+ return { projectId, name: names[0], installed };+}++/**+ * Take over the archive download: every GET is kept in `seen`, and while `state.refuse` is set it+ * is answered with the server's refusal instead of reaching the real route.+ */+async function interceptExport(page, state) {+ await page.route("**/api/projects/*/agents/*/skills/*/archive", async (route) => {+ state.seen.push(new URL(route.request().url()).pathname.split("/").at(-2));+ if (!state.refuse) return route.fallback();+ await route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: REFUSAL }),+ });+ });+}++/** The row's own export button (its accessible name is the verb plus the skill's name). */+const rowButton = (page, name) =>+ page.getByRole("button", { name: `打包导出 ${name}`, exact: true });++/** The reason line under that row. */+const refusalLine = (page) => page.getByTestId("export-refusal");++/** The notification region: a refusal must not be announced there (that is the old toast). */+const notifications = (page) => page.getByRole("region", { name: "通知" });++/** The row's line (everything but the reason): the only thing a refusal may change. */+const rowLine = (page, name) => rowButton(page, name).locator("xpath=../..").locator("div").first();++test("a refused export keeps its reason under the row, and nothing else changes", async ({+ page,+}) => {+ const { name, installed } = await agentWithSkill(page, "r212exportrefuse");+ const before = await installed();+ expect(before).toContain(name);++ const state = { seen: [], refuse: true };+ await interceptExport(page, state);++ await page.goto(`/agents/${AGENT}?tab=skills`);+ await expect(rowButton(page, name)).toBeVisible();+ const line = await rowLine(page, name).innerText();+ const rows = await page.getByRole("button", { name: /^打包导出 / }).count();+ await expect(refusalLine(page)).toHaveCount(0);++ await rowButton(page, name).click();++ // The reason is in the row that asked, and it is not a toast: the notification region holds no+ // dismissible button, and the row's own line reads exactly as it did before the attempt.+ await expect(refusalLine(page)).toHaveCount(1);+ await expect(refusalLine(page)).toHaveText(+ `技能 ${name} 没有导出成 zip,它仍然装在这个 Agent 上:${REASON}`,+ );+ expect(await rowLine(page, name).innerText()).toBe(line);+ await expect(notifications(page).getByRole("button")).toHaveCount(0);+ expect(state.seen).toEqual([name]);++ // One row, one sentence: no other skill's row grew one.+ await expect(page.getByTestId("export-refusal")).toHaveCount(1);+ expect(await page.getByRole("button", { name: /^打包导出 / }).count()).toBe(rows);++ // Six seconds is where the old toast gave up; the sentence is still there.+ await page.waitForTimeout(7000);+ await expect(refusalLine(page)).toHaveCount(1);++ // Nothing was exported, and the installed copy was not touched.+ expect(await installed()).toEqual(before);+});++test("the retry after a refused export lands, and only a new attempt clears the reason", async ({+ page,+}) => {+ const { name, installed } = await agentWithSkill(page, "r212exportretry");++ const state = { seen: [], refuse: true };+ await interceptExport(page, state);++ await page.goto(`/agents/${AGENT}?tab=skills`);+ await expect(rowButton(page, name)).toBeVisible();+ await rowButton(page, name).click();+ await expect(refusalLine(page)).toHaveCount(1);+ expect(state.seen).toEqual([name]);++ // The retry is the same row; this time the archive really comes back: the sentence goes, and the+ // file is handed to the browser as a download.+ state.refuse = false;+ const download = page.waitForEvent("download");+ await rowButton(page, name).click();+ await expect(refusalLine(page)).toHaveCount(0);+ expect(state.seen).toEqual([name, name]);+ const file = await download;+ expect(file.suggestedFilename()).toMatch(/\.zip$/);++ // A refused export changes neither side: the skill is still installed and still listed.+ expect(await installed()).toContain(name);+ await expect(rowButton(page, name)).toBeVisible();+});diff --git a/packages/web/src/features/agents/skill-export-refusal.ts b/packages/web/src/features/agents/skill-export-refusal.tsnew file mode 100644index 00000000..72033c39--- /dev/null+++ b/packages/web/src/features/agents/skill-export-refusal.ts@@ -0,0 +1,47 @@+/**+ * A skill's "Export as zip" button on the Agent's Skills tab (`skills-tab.tsx`), and the sentence+ * one refused export leaves behind.+ *+ * The export is a plain fetch of the installed directory through the shared archive download+ * (`archive-download.ts`): nothing is written on the server, the skill stays installed either way,+ * and no client state moves while the request is out — so when the request is refused the row that+ * sent it is still on screen, a line above, with the very button that retries it. The reason used+ * to arrive only as a notification: it dismissed itself after six seconds, sat above the list, and+ * a reader who had looked away was left with no zip file and nothing saying why (7.19's rule,+ * app-wide — the sentence belongs where the attempt was made).+ *+ * Which words: `refusalText`, the rule every refusal in the app follows — an answer the server+ * gave is read through its code's own localized sentence, and a value this codebase raised itself+ * is shown as it wrote it. The sentence says the skill was not exported *and* that it is still+ * installed, because a failed export is the one moment a reader wonders whether the installed copy+ * was touched.+ */+import { refusalText } from "../../lib/api-error";+import { S } from "../../lib/strings";++/** The sentence one refused export left, and the skill it was for. */+export interface SkillExportRefusal {+ readonly skill: string;+ readonly text: string;+}++/** The sentence: which skill was not exported, and why. */+export function skillExportRefused(skill: string, error: unknown): string {+ return S.skills.exportRefused(skill, refusalText(error));+}++/**+ * What this row draws for a refusal, if anything.+ *+ * The tab keeps one refusal at a time — the page's actions are serialized by `busy`, and an+ * attempt supersedes the reason of the attempt before it — so a refusal belongs to the row whose+ * name it carries and no other row may read it. Rows for other skills in the same list must stay+ * exactly as they were.+ */+export function skillExportRefusalFor(+ refusal: SkillExportRefusal | null,+ skill: string,+): string | undefined {+ if (refusal === null || refusal.skill !== skill) return undefined;+ return refusal.text;+}diff --git a/packages/web/src/features/agents/skills-tab.tsx b/packages/web/src/features/agents/skills-tab.tsxindex 2c17a05d..aca78c71 100644--- a/packages/web/src/features/agents/skills-tab.tsx+++ b/packages/web/src/features/agents/skills-tab.tsx@@ -38,7 +38,6 @@ import {SkeletonList,Textarea,buttonClass,- toastError,toastSuccess,useCopied,} from "@adelie/ui";@@ -46,12 +45,15 @@ import * as api from "../../api/endpoints";import { ApiError } from "../../api/client";import { S } from "../../lib/strings";import { apiErrorText } from "../../lib/api-error";+import { toneInk } from "../../lib/tone";import { useLocale } from "../../state/locale";import { agentDisplayName, useProject } from "../../state/project";import { SkillTile } from "../skills/skill-icon-view";import { localizedShortText } from "../chat/skill-use";import { useAiBridge } from "../ai-create";import { downloadArchive } from "./archive-download";+import { skillExportRefusalFor, skillExportRefused } from "./skill-export-refusal";+import type { SkillExportRefusal } from "./skill-export-refusal";import { buildImportPrompt } from "./skill-import-source";import { usePromptInjection } from "./prompt-injection-controls";@@ -95,6 +97,9 @@ export function SkillsTab({// The words for an uninstall the server refused, drawn inside the confirmation that asked for// it (see confirmRemove): retrying is the next thing the person does, and the button is in there.const [removeRefusal, setRemoveRefusal] = useState<string | null>(null);+ // The words for an export that did not land, drawn in the row that asked (skill-export-refusal.ts):+ // the row, the skill and the same button are still there, which a six-second toast is not.+ const [exportRefusal, setExportRefusal] = useState<SkillExportRefusal | null>(null);// Import modal: the source for the chat-install prompt + upload state travel with the modal.const [importOpen, setImportOpen] = useState(false);const [source, setSource] = useState("");@@ -128,13 +133,20 @@ export function SkillsTab({const agent = agents.find((a) => a.agentId === agentId);const agentName = agent ? agentDisplayName(agent) : agentId;- /** "Export as zip": the shared archive download (archive-download.ts); a failure surfaces as a toast. */+ /**+ * "Export as zip": the shared archive download (archive-download.ts). A refused one leaves its+ * reason in the row that asked (skill-export-refusal.ts) — the row, the skill and the same+ * button are all still there, so a toast that dismisses itself after six seconds is the one+ * thing that would carry that reason away. Starting an attempt clears the previous sentence:+ * it belonged to the attempt before, not to the skill this one is about.+ */const exportSkill = async (name: string) => {if (!projectId) return;+ setExportRefusal(null);try {await downloadArchive(api.agentSkillArchiveUrl(projectId, agentId, name), name);} catch (e) {- toastError(apiErrorText(e));+ setExportRefusal({ skill: name, text: skillExportRefused(name, e) });}};@@ -279,60 +291,82 @@ export function SkillsTab({<SettingsEmpty>{S.skills.agentTabEmpty}</SettingsEmpty>) : (<Card padding="none">- {skills.map((skill) => (- <div- key={skill.name}- className="flex items-center gap-3 border-b border-gray-100 px-3 py-2.5 transition-colors duration-150 last:border-b-0 hover:bg-gray-50 dark:border-gray-800/60 dark:hover:bg-gray-800/40"- >- <SkillTile icon={skill.icon} name={skill.name} size={36} glyph={20} />- <div className="min-w-0 flex-1">- <span- className="block truncate font-mono text-[length:var(--ui-text-code-size)] font-semibold"- data-tooltip={skill.name}- data-tooltip-content="code"- >- {skill.name}- </span>- {/* Short description truncates to one line (full description goes into title for hover reading). */}- <p- className="mt-0.5 truncate text-xs text-gray-500 dark:text-gray-400"- data-tooltip={skill.description}- data-tooltip-content="text"- data-tooltip-extra={skill.description !== localizedShortText(locale, skill)}- >- {localizedShortText(locale, skill)}- </p>- </div>- {metaLine(skill) !== "" && (- <span- className="hidden shrink-0 text-xs text-gray-400 sm:block dark:text-gray-500"- data-tooltip={metaLine(skill)}- >- {metaLine(skill)}- </span>- )}- {/* Icon-only row actions (same affordance as the agents page cards: neutral- bordered icon for export, danger variant with red text/hover for delete);- the tooltip + aria-label carry the wording. */}- <IconButton- label={`${S.skills.exportSkill} ${skill.name}`}- title={S.skills.exportSkill}- disabled={busy}- onClick={() => void exportSkill(skill.name)}- >- <DownloadIcon size={14} className="text-gray-600 dark:text-gray-300" />- </IconButton>- <IconButton- variant="danger"- label={`${S.skills.uninstall} ${skill.name}`}- title={S.skills.uninstall}- disabled={busy}- onClick={() => askRemove(skill.name)}+ {skills.map((skill) => {+ // One refusal, one row: an attempt supersedes the reason of the attempt before it.+ const refusal = skillExportRefusalFor(exportRefusal, skill.name);+ return (+ // The row is a column so a refused export can put its reason under the line that+ // asked for it, without pushing any other row sideways.+ <div+ key={skill.name}+ className="border-b border-gray-100 last:border-b-0 dark:border-gray-800/60">- <GlyphIcon d={ICONS.trash} size={14} />- </IconButton>- </div>- ))}+ <div className="flex items-center gap-3 px-3 py-2.5 transition-colors duration-150 hover:bg-gray-50 dark:hover:bg-gray-800/40">+ <SkillTile icon={skill.icon} name={skill.name} size={36} glyph={20} />+ <div className="min-w-0 flex-1">+ <span+ className="block truncate font-mono text-[length:var(--ui-text-code-size)] font-semibold"+ data-tooltip={skill.name}+ data-tooltip-content="code"+ >+ {skill.name}+ </span>+ {/* Short description truncates to one line (full description goes into title for hover reading). */}+ <p+ className="mt-0.5 truncate text-xs text-gray-500 dark:text-gray-400"+ data-tooltip={skill.description}+ data-tooltip-content="text"+ data-tooltip-extra={skill.description !== localizedShortText(locale, skill)}+ >+ {localizedShortText(locale, skill)}+ </p>+ </div>+ {metaLine(skill) !== "" && (+ <span+ className="hidden shrink-0 text-xs text-gray-400 sm:block dark:text-gray-500"+ data-tooltip={metaLine(skill)}+ >+ {metaLine(skill)}+ </span>+ )}+ {/* Icon-only row actions (same affordance as the agents page cards: neutral+ bordered icon for export, danger variant with red text/hover for delete);+ the tooltip + aria-label carry the wording. */}+ <IconButton+ label={`${S.skills.exportSkill} ${skill.name}`}+ title={S.skills.exportSkill}+ disabled={busy}+ onClick={() => void exportSkill(skill.name)}+ >+ <DownloadIcon size={14} className="text-gray-600 dark:text-gray-300" />+ </IconButton>+ <IconButton+ variant="danger"+ label={`${S.skills.uninstall} ${skill.name}`}+ title={S.skills.uninstall}+ disabled={busy}+ onClick={() => askRemove(skill.name)}+ >+ <GlyphIcon d={ICONS.trash} size={14} />+ </IconButton>+ </div>+ {/* An export that did not land: this row still holds the button that retries it,+ so the reason sits under it rather than in a notification that dismisses+ itself (skill-export-refusal.ts). */}+ {refusal !== undefined && (+ <p+ role="alert"+ data-testid="export-refusal"+ data-tooltip={refusal}+ data-tooltip-content="text"+ className={`px-3 pb-2.5 line-clamp-2 break-words text-xs ${toneInk.danger}`}+ >+ {refusal}+ </p>+ )}+ </div>+ );+ })}</Card>)}diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.tsindex d681356f..76a68b5d 100644--- a/packages/web/src/lib/strings-en.ts+++ b/packages/web/src/lib/strings-en.ts@@ -3200,6 +3200,9 @@ export const en: Strings = {"Skills installed on this agent (agent_state/skills/ — the files are the source of truth): metadata is injected into the system prompt and the body is read by the model on demand; uninstalling deletes the whole skill directory.",agentTabEmpty: "No skills installed yet",exportSkill: "Export",+ /** An export the download refused (skill-export-refusal.ts), drawn under the row that asked. */+ exportRefused: (skill: string, reason: string): string =>+ `The skill ${skill} was not exported as a zip — it is still installed on this Agent: ${reason}`,importSkill: "Import skill",importChatTitle: "Recommended: install by chatting with the agent",importChatWhy:diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.tsindex 3d163c62..663f057a 100644--- a/packages/web/src/lib/strings.ts+++ b/packages/web/src/lib/strings.ts@@ -3243,6 +3243,13 @@ export const zh = {"该 Agent 已安装的技能(agent_state/skills/,文件即事实来源):元数据注入系统提示词,正文由模型按需读取;卸载会删除整个技能目录。",agentTabEmpty: "尚未安装任何技能",exportSkill: "打包导出",+ /**+ * An export the download refused (skill-export-refusal.ts), drawn under the row that asked:+ * the file was not saved and the installed copy was not touched, which is what the second+ * half says; the reason goes last, as in every other refusal sentence.+ */+ exportRefused: (skill: string, reason: string): string =>+ `技能 ${skill} 没有导出成 zip,它仍然装在这个 Agent 上:${reason}`,importSkill: "导入技能",importChatTitle: "推荐:让 Agent 在对话中安装",importChatWhy: "Agent 能完整阅读、审查并按需调整技能内容,比直接上传更可靠。",diff --git a/packages/web/test/skill-export-refusal.test.ts b/packages/web/test/skill-export-refusal.test.tsnew file mode 100644index 00000000..cf5cc538--- /dev/null+++ b/packages/web/test/skill-export-refusal.test.ts@@ -0,0 +1,74 @@+/**+ * A skill's export that did not land (src/features/agents/skill-export-refusal.ts): which words+ * the row that asked draws, and which row draws them.+ *+ * The export writes nothing on the server and moves no client state, so a refusal leaves the row,+ * the installed skill and the same button on screen — the sentence is the only thing saying the zip+ * was not saved. Three things it has to get right: an answer the server gave speaks the interface's+ * own language rather than the wire message (7.19's rule), a failure this codebase raised itself+ * keeps what it knows, and a skill's refusal never shows up under another skill's row.+ */+import { afterEach, describe, expect, it } from "vitest";+import { ApiError } from "../src/api/client";+import { S, setActiveStrings, zh as ZH } from "../src/lib/strings";+import { en as EN } from "../src/lib/strings-en";+import {+ skillExportRefusalFor,+ skillExportRefused,+} from "../src/features/agents/skill-export-refusal";++afterEach(() => {+ setActiveStrings(ZH);+});++describe("skillExportRefused", () => {+ it("reads a refusal through the code's own sentence, not the wire message", () => {+ const line = skillExportRefused("pdf-tools", new ApiError(500, "internal", "RAW ENGLISH"));+ expect(line).not.toContain("RAW ENGLISH");+ expect(line).toBe(S.skills.exportRefused("pdf-tools", S.errors.byCode.internal as string));+ });++ it("keeps what a failure that never reached the route has to say", () => {+ expect(skillExportRefused("pdf-tools", new Error("Failed to fetch"))).toBe(+ S.skills.exportRefused("pdf-tools", "Failed to fetch"),+ );+ });++ it("falls back to the generic text when the value has nothing to say", () => {+ expect(skillExportRefused("pdf-tools", undefined)).toBe(+ S.skills.exportRefused("pdf-tools", S.common.unknownError),+ );+ });++ it("names the skill that was not exported", () => {+ expect(skillExportRefused("pdf-tools", new Error("boom"))).toContain("pdf-tools");+ });++ it("says the skill is still installed on the Agent", () => {+ expect(skillExportRefused("pdf-tools", new Error("boom"))).toContain("仍然装在这个 Agent 上");+ });++ it("speaks the active language", () => {+ setActiveStrings(EN);+ expect(skillExportRefused("pdf-tools", new ApiError(500, "internal", "RAW"))).toBe(+ EN.skills.exportRefused("pdf-tools", EN.errors.byCode.internal as string),+ );+ expect(skillExportRefused("pdf-tools", new Error("boom"))).toContain("still installed");+ });+});++describe("skillExportRefusalFor", () => {+ const refusal = { skill: "pdf-tools", text: "the sentence" };++ it("gives the refusal to the row whose skill it carries", () => {+ expect(skillExportRefusalFor(refusal, "pdf-tools")).toBe("the sentence");+ });++ it("leaves every other row alone", () => {+ expect(skillExportRefusalFor(refusal, "web-search")).toBeUndefined();+ });++ it("draws nothing when the last attempt landed or none was made", () => {+ expect(skillExportRefusalFor(null, "pdf-tools")).toBeUndefined();+ });+});