fix: clarify application retry prompts

This commit is contained in:
鲨鱼辣椒 committed 2026-10-13 17:19:36 +08:00
1 parent 1a496dd4fb
commit 5a8b8d75e5
12 files changed
+150 -29

No files matched your search

@@ -8,15 +8,15 @@
- Worktree: /Users/chillishark/Makelore 麦洛/.codex-worktrees/makelore/20261013-publish-pending-explain-5dd70a31
- Base commit: 2899009215b1de8e28b84fc108e880c6e68a6098
- Owner: codex
- Status: Ready for Integration
- Status: Planning
## Scope
- Explain the screenshot's pending publication record, its appearance on the WeChat page, and retry/dismiss semantics. Read current recovery metadata and revision state if available; no business operation or source fix.
- Diagnose publication reminders and implement the latest explicitly approved simple application/retry copy. Own only relevant Renderer publication/recovery messages and focused verification.
## Intent And Constraints
- User requests an explanation. Preserve the pending record, publication state, bindings, current UI/route/focus/runtime and credentials. Do not retry/discard/publish or change product source.
- User now explicitly authorizes changing the prompt to 「网络可能不稳定,请再点一次「应用」。」. Preserve original-operation retry identity, other recovery types, field/conflict messages, real pending records, cloud data, runtime, credentials and peer source. No real apply/retry/discard/publish, backend release, merge or push.
## Project Context Loaded
@@ -56,3 +56,19 @@
- The Main route maps non-CloudAgentsError exceptions to 502. The service also synthesizes 502 for invalid/oversized upstream data, session metadata or projection failures, while preserving status when fetchJson receives a non-success JSON response. Thus transport, parsing/projection, service response and gateway causes require further correlation; no single-party backend fault is established.
- Client repair ownership: known-failure/uncertain publication classification and reminder context are client behavior. Query availability/contract is an integration investigation involving the desktop client and Yuxi backend; the exact failing layer is still unverified. The supplied backend chat is titled YUXI-智能体后端 and was only read, not messaged.
- Verification: re-inspected route/service operation sources and the existing read-only diagnostic result. No live action retried, no raw errors or credentials inspected, and no source edits/tests/build required.
## Implementation planning: approved simple application copy
- Same task resumes; task ID/mode/worktree/branch/base verified. Latest user approval narrows the change to understandable application prompt/action wording; the earlier multi-part recovery redesign is not included.
- Reused unchanged project positioning, integrated snapshot, accepted personal-cloud ADR, architecture/domain and evidence/reflection/commitment context read on prior same-task turns; re-read current entry/own record and all peer Scope/Intent/Promotion sections. Integrated docs remain historical. Current runtime still Renderer289/Main7c; no fresh runtime operation is necessary for source editing.
- Active draft-conflict diagnosis is read-only; subagent-selector owns another configuration component; completed channel/recovery tasks have no semantic conflict for publish-only copy. Unknown legacy scopes have no concrete dependency.
- Project goal is a understandable Chinese personal-Agent UI; Main owns credential/transport/journal, Yuxi owns immutable published configuration. Relevant files are CloudRecovery and publication entry callbacks. Network remains a possible cause, not a confirmed diagnosis.
- Planning Gate Passed. Plan: inspect all user-visible publish errors/recovery wording and existing button retry; change only unknown publication prompt/action to the approved wording while preserving original ID/revision and explicit error causes; run existing relevant regression/type/lint/build checks, independent review, then document and commit.
## Approved copy implementation outcome
- Publication recovery now uses 「应用设置」, the approved message 「网络可能不稳定,请再点一次「应用」。」 and a matching 「应用」 action. In-editor/access-panel retries also say 「应用」. Successful recovered application says 「设置已应用。」 without exposing internal version JSON.
- The application hook translates only network/timeout/generic unavailable errors; explicit 4xx and definitive rejections retain their actual safe causes. Initial unknown-history publication records use the user's possible-network wording; after a record returns a concrete error, its initial speculative help is hidden and the actual error is shown. Access-state reads and other recovery types retain their current messages.
- Original operation IDs, expected revisions, journal state, explicit retry/discard and duplicate-click guards are unchanged. There are no Main/shared/backend changes or real cloud apply/retry/discard. README reflects current application copy.
- Pinned corepack pnpm10.33.4 verification: 98 unit tests across 5 focused suites passed; Renderer typecheck passed; 10 changed source/test files ESLint passed; build:vite passed. Updated browser Host-IPC fixture E2E passed (1); the 375px screenshot was reviewed and the modal fits. Tests verify original ID reuse after network failure and preserve 401/403/409/422/429 explanations.
- Compared all 66 Main/preload/utility/resources/package artifact files to immutable live Main7c: exact hash equality, with no missing/extra files. This enables a Renderer-only temporary-app update. That update is the next authorized step; current inputs and UI remain protected, with no reuse of previous one-time input-discard approvals.
+1 -1
View File
@@ -14,7 +14,7 @@ Makelore 是一个面向软件、视觉创作、智能机器人与个人云智
会话工作台采用浅蓝项目栏、彩色通用手柄图标与卡片选中态;中间对话/作品使用圆角标签,作品预览的后退、前进、刷新与网址输入统一放在标签右侧;只在作品页显示,窄窗口自动换行。右侧智能体咨询使用奶油色标题区。沿用真实项目和会话入口、侧栏伸缩与账户菜单,样式只作用于 Code 会话工作台。可编辑的空对话在输入区上方的可用区域中央显示童趣欢迎语;「去作品广场逛逛」入口紧贴输入框上方,两者一起位于底部。老师介绍以固定宽度浮在右上角,不占用中间布局;欢迎语和底部输入区始终相对项目栏右侧的整个内容区域居中;小窗口的欢迎内容独立滚动;发送首条消息后收起欢迎区。侧栏保留「作品广场」入口,只有点击后才在系统浏览器打开公共广场,不请求、摘取或内嵌展示广场作品。打开广场保留当前项目、对话、草稿和附件,不自动发送消息;老师求助按钮保留临时应用的最新文案「帮我整体看🧠」。
- `Makelore Agents|AI 智能体`:从模块首页进入时先打开“我的智能体”卡片列表,保留此前对话与操作恢复记录;返回首页箭头与侧栏折叠按钮同排,折叠后仍可返回;智能体模块的侧栏只通过按钮点击或键盘激活展开,鼠标经过左侧、收纳按钮或顶栏不会展开,切换模块不沿用旧悬停预览;其他模块仍保留原预览方式。“我的智能体”使用浅紫对话机器人图标,“渠道”使用浅蓝连接节点图标。macOS 原生窗口按钮留出安全空间。首页围绕自己的智能体和创建入口,显示童趣问候“Hi,今天想创造还是想聊聊?”,不再显示更多、收到的分享、活动或归档筛选。卡片恢复原有尺寸与留白,显示名称、可为空的一句话介绍及状态,支持聊天、调整、继续制作和确认删除;删除沿用云端归档机制,移出列表并停用新调用,历史和费用保留。创建先填写名称并选择平台像素头像或上传头像,下一步进入独立配置。顶部名称有编辑图标,头像可点击修改;未设置头像时使用同一张默认像素头像,从创建到配置、改名、保存和重新打开保持一致。基础页为“介绍与提示词”,一句话介绍可留空,完整提示词保留原始文本;模型作为高级设置第一项必选,未选择时不能开始使用,草稿可分步保存,不自动选模型。介绍与提示词采用浅蓝介绍卡和浅紫提示词卡;高级设置按模型、工具箱(Tool)、做事手册(Skill)、MCP 服务、子智能体和知识库纵向呈现,不再设内部分类切换;不展示 Tool/Skill 解释、资源开放规则提示、云端能力管理、费用上限或运行限制卡片,保存其他配置时保留既有运行限制,费用规则不变。顶层页签切换保留搜索、资源选择、知识表单及未保存输入。配置页移除聊天、自动任务和使用与接入导航,独立聊天仍从卡片进入,微信账号仍在侧栏渠道管理。草稿明确保存(Ctrl/⌘+S);保存只更新草稿,“应用最新修改”使新配置生效,失败重试保持原操作身份;点击“开始使用”完成必要的私有启用后直接打开聊天,不再展示二次确认页;未保存修改、缺少模型、冲突或尚未确认的请求会留在配置页处理,打开聊天不自动发送消息。独立对话沿用奶油底色和浅蓝、浅紫、薄荷色:顶部展示返回、只读头像和名称;有附件时在同一行右侧显示回形针“附件”入口和文件数量,不展示调整、保存/应用状态、客户端/微信来源、费用/版本说明或历史/新对话图标;配置由列表卡片的“调整”进入。空对话展示当前智能体头像与名称,示例只填入草稿;用户消息使用浅紫圆角气泡,助手 Markdown、表格和代码在消息区内滚动。文件或图片从输入框内添加,上传成功后以待发送卡片呈现,可移除本次携带;移除不会删除云端文件,添加不会自动发送。确认失败沿用同一文件和对话重试,发送前需完成或取消添加;支持仅发送附件,使用明确的附件提问。输入框的“+”添加文件或图片;右上角“附件”打开右侧面板,按“你上传的”和“助手生成的”分组,支持再次选用已上传附件及保存明确交付的生成文件。生成文件仅取当前对话已保存助手回复中的本地文件链接(含图片与引用式链接),核对实际文件后展示和计数;只读取链接所在的文件夹,不遍历全部工作文件。未交付的脚本、缓存和工具记录不展示、不计数,明确交付的代码照常展示;仅写了路径的旧成果可能暂时隐藏,后续接入 Yuxi 的正式交付记录。没有文件时隐藏入口;打开、关闭面板保留聊天与输入,Escape 关闭并返回入口焦点;最近对话自动恢复、审批、停止和未发送内容的离开保护保留。模型返回的思考按消息独立于正文展示;正文到来后或完成时折叠,可手动展开;无思考或工具内容时不显示过程区。重连事件去重并隔离当前运行与主对话,终态历史未到达时保留已收到的片段并有限补读;服务端返回的最终回答思考可在历史中回看,不进入后续提问。历史回看需要配套 Yuxi API 的思考和工具记录投影;实时过程沿用既有事件流。平台工具和内置做事手册使用 Yuxi 下发的通俗名称与说明;逐条消息的思考、工具输入/结果/失败独立于 Markdown 正文,实时与历史工具卡片共用展示文案,展开可查看原始工具标识。个人上传手册保留作者文案,资源选择仍保存原始标识。头像上传、Main-owned Host API、访问隔离、费用与不可变版本规则保持;介绍留空需要配Line truncated
历史待确认记录收起在智能体列表标题区的「创建记录/待处理记录」入口,只有点击后才打开记录窗口;配置、聊天和创建页不再置顶这些旧提醒。记录保留智能体名称和原请求身份,用户可明确「再试一次」或「不再提醒」,不会自动重试或清除。当前创建失败继续在创建表单内提示;关闭记录窗口保留已收到的结果和密钥,切换配置、聊天或创建页后可返回列表继续查看。密钥须明确关闭结果后,才可处理其他记录。
历史待确认记录收起在智能体列表标题区的「创建记录/待处理记录」入口,只有点击后才打开记录窗口;配置、聊天和创建页不再置顶这些旧提醒。记录保留智能体名称和原请求身份;应用设置的待确认记录显示“网络可能不稳定,请再点一次「应用」。”,点击「应用」继续原来的提交,成功后显示“设置已应用。”。其他记录仍可明确「再试一次」或「不再提醒」,不会自动重试或清除。当前创建失败继续在创建表单内提示;关闭记录窗口保留已收到的结果和密钥,切换配置、聊天或创建页后可返回列表继续查看。密钥须明确关闭结果后,才可处理其他记录。
高级配置的知识库支持下拉多选,分为「MakeLore知识」和「我的知识库」,已选项可单独移除。MakeLore知识来自当前账号有权读取的 Yuxi 共享目录,只显示名称与简介;移除仅取消当前智能体选用,不删除原库。知识库区域上方左右分区,两张卡片在并排时保持等高:左侧「上传自己的文件」仅放「新建知识库」入口及展开的创建表单,右侧「查看我的知识库」通过下拉框查看本人知识库、从电脑追加资料和管理文件;下方独立「选择知识库」,选择智能体使用的「MakeLore知识」和「我的知识库」。小窗口按新建、查看、选用顺序纵向排列。创建成功后在右侧打开新库;新建和查看均不会自动加入智能体配置,选用上限不影响管理与新建。仅提供「从电脑上传」作为添加文件入口,未选择管理目标时上传按钮置灰;聊天文件导入入口已移除。上传后自动解析、建立索引并持续显示真实处理状态;失败可重试且保留已有可用内容。暂不可选用的个人库仍可管理文件,已有绑定保留并提示不可用;未确认请求在当前库保留同一操作身份供重试。知识库选择只改草稿,显式保存/应用后生效;个人云端执行已自动接入所选知识库的检索,无需另外勾选 knowledge-base Skill。此交互复用现有接口,无需新增后端补丁。
+1 -1
View File
@@ -47,7 +47,7 @@ export function CloudAccessPanel({ slug, revision, publication, onChanged, activ
<h2 className="font-medium">{access?.published_version ? '助手已准备好' : '准备好使用自己的助手了吗?'}</h2>
<p className="mt-2 text-sm text-muted-foreground">{access?.published_version ? '应用最新修改后,新的对话会使用这次保存的要求。已有对话保留原来的版本。' : '开始使用后,只有你自己能用。以后还可以回来修改要求。'}</p>
<p className="mt-2 text-xs text-muted-foreground">微信渠道和应用接入需要单独配置。</p>
</div><Button disabled={busy || !access || (!publication.pending && publication.appliedRevision === revision)} onClick={() => void publish()}>{publication.busy ? '正在应用…' : publication.pending ? '重试本次发布' : publication.appliedRevision === revision ? '已应用最新修改' : access?.published_version ? '应用最新修改' : '确认开始使用'}</Button></div>
</div><Button disabled={busy || !access || (!publication.pending && publication.appliedRevision === revision)} onClick={() => void publish()}>{publication.busy ? '正在应用…' : publication.pending ? '应用' : publication.appliedRevision === revision ? '已应用最新修改' : access?.published_version ? '应用最新修改' : '确认开始使用'}</Button></div>
<p className="mt-4 text-sm leading-6">自己使用、API 调用、自动任务和个人微信渠道产生的费用,均从你的个人词元点数扣除。你可以随时停用智能体或撤销应用凭据。</p>
{access?.published_version && <div className="mt-4 flex items-center gap-3 text-sm"><span>{access.enabled ? '智能体已启用' : '智能体已停用'}</span>
<Button variant="outline" size="sm" disabled={busy} onClick={() => void act(() => cloudAgentsApi.call('setEnabled', { slug, enabled: !access.enabled }))}>
+12 -5
View File
@@ -6,9 +6,10 @@ import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, D
import { cloudAgentsApi } from '@/lib/cloud-agents-api';
import { AppError } from '@/lib/error-model';
import type { CloudPendingOperation } from '../../../shared/cloud-agents';
import { APPLICATION_RETRY_MESSAGE, applicationErrorMessage } from './application-message';
const labels: Record<string, string> = {
createAgent: '创建智能体', submit: '发送消息', preview: '预览草稿', resume: '继续任务', publish: '发布版本',
createAgent: '创建智能体', submit: '发送消息', preview: '预览草稿', resume: '继续任务', publish: '应用设置',
createApplication: '创建应用', createKey: '创建密钥', createKnowledge: '创建知识库', processKnowledge: '处理文档',
createSchedule: '创建自动任务', runSchedule: '立即运行任务',
importKnowledgeAttachment: '导入附件到知识库', createChild: '创建子智能体',
@@ -23,6 +24,7 @@ export function CloudRecovery({ pending, onResolved, triggerContainer }: { pendi
const [open, setOpen] = useState(false);
const [busy, setBusy] = useState('');
const [error, setError] = useState('');
const [errorRecord, setErrorRecord] = useState('');
const [notice, setNotice] = useState('');
const [result, setResult] = useState<{ operation: string; name?: string; value: unknown } | null>(null);
const inFlight = useRef(false);
@@ -36,7 +38,7 @@ export function CloudRecovery({ pending, onResolved, triggerContainer }: { pendi
const resolve = async (item: CloudPendingOperation, discard = false) => {
if (inFlight.current || awaitingKeyClose.current) return;
inFlight.current = true;
setBusy(item.id); setError(''); setNotice('');
setBusy(item.id); setError(''); setErrorRecord(''); setNotice('');
try {
const response = await cloudAgentsApi.resolvePending(item.id, discard);
if (!alive.current) return;
@@ -54,7 +56,9 @@ export function CloudRecovery({ pending, onResolved, triggerContainer }: { pendi
onResolved();
} catch (e) {
if (!alive.current) return;
const message = e instanceof Error ? e.message : '这次没能完成,请稍后再试。';
setErrorRecord(item.id);
const message = item.operation === 'publish' && !discard ? applicationErrorMessage(e)
: e instanceof Error ? e.message : '这次没能完成,请稍后再试。';
if (e instanceof AppError && e.details?.commandOutcome === 'definitive_failure') {
setError(`${labels[item.operation] ?? '操作'}失败:${message}`);
onResolved();
@@ -84,16 +88,19 @@ export function CloudRecovery({ pending, onResolved, triggerContainer }: { pendi
: retiredChannelOperations.has(item.operation) ? '旧版联系人权限操作(已移除)' : labels[item.operation] ?? '待处理记录'}</h3>
<p className="agent-recovery-time">{new Date(item.created_at).toLocaleString()}</p>
{item.operation === 'createAgent' && <p className="agent-recovery-record-help">还不确定有没有创建成功,先看看列表里有没有它。</p>}
{item.operation === 'publish' && errorRecord !== item.id && <p className="agent-recovery-record-help">{APPLICATION_RETRY_MESSAGE}</p>}
{typeof item.input.query === 'string' && <p className="mt-1 line-clamp-2 text-muted-foreground">{item.input.query}</p>}</div>
{retiredChannelOperations.has(item.operation)
? <Button size="sm" variant="ghost" disabled={actionsDisabled} onClick={() => void resolve(item)}>{busy === item.id ? '正在丢弃…' : '丢弃旧记录'}</Button>
: <div className="agent-recovery-record-actions"><Button size="sm" disabled={actionsDisabled} onClick={() => void resolve(item)}>{busy === item.id ? '正在处理…' : '再试一次'}</Button>
: <div className="agent-recovery-record-actions"><Button size="sm" disabled={actionsDisabled} onClick={() => void resolve(item)}>{item.operation === 'publish'
? busy === item.id ? '正在应用…' : '应用' : busy === item.id ? '正在处理…' : '再试一次'}</Button>
<Button size="sm" variant="ghost" disabled={actionsDisabled} onClick={() => void resolve(item, true)}>不再提醒</Button></div>}
</article>)}
{result && <div className="agent-recovery-result space-y-2"><p>{result.operation === 'createAgent'
? `「${result.name || '智能体'}」创建成功,可以回到列表继续设置。`
: result.operation === 'publish' ? '设置已应用。'
: `${labels[result.operation] ?? '操作'}的结果已确认。`}{result.operation === 'createKey' && '请保存下面的密钥。关闭结果后将无法再次查看。'}</p>
{result.operation !== 'createAgent' && <>
{result.operation !== 'createAgent' && result.operation !== 'publish' && <>
<details open={result.operation === 'createKey'}><summary className="cursor-pointer">查看结果</summary>
<pre className="max-h-48 overflow-auto whitespace-pre-wrap break-all p-2 text-xs">{JSON.stringify(result.value, null, 2)}</pre></details>
</>}
+2 -2
View File
@@ -154,11 +154,11 @@ export function DraftEditor({ initial, recent, onBack, onSaved, startingPrompt,
title={dirty ? '请先保存草稿,再应用修改' : '将已保存的修改应用到正在使用的助手'}
onClick={() => void publication.publish()}>
{publication.busy && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
{publication.busy ? '正在应用…' : publication.pending ? '重试本次应用' : !dirty && publication.appliedRevision === saved.draft_revision ? '已应用' : '应用最新修改'}
{publication.busy ? '正在应用…' : publication.pending ? '应用' : !dirty && publication.appliedRevision === saved.draft_revision ? '已应用' : '应用最新修改'}
</Button>}
{!saved.published_version && <Button className="min-h-10" variant="outline" disabled={busy || remote !== null || !publication.access} onClick={startUsing}>
{publication.busy && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
{publication.busy ? '正在开始…' : publication.pending ? '重试开始使用' : '开始使用'}
{publication.busy ? '正在开始…' : publication.pending ? '应用' : '开始使用'}
</Button>}
</>}
</header>
@@ -0,0 +1,16 @@
import { AppError } from '@/lib/error-model';
export const APPLICATION_RETRY_MESSAGE = '网络可能不稳定,请再点一次「应用」。';
export function applicationErrorMessage(error: unknown): string {
if (error instanceof AppError) {
const status = error.details?.status;
const rejected = error.details?.commandOutcome === 'definitive_failure'
|| (typeof status === 'number' && status >= 400 && status < 500);
if (!rejected && (error.code === 'NETWORK' || error.code === 'TIMEOUT'
|| error.details?.backendCode === 'cloud_service_unavailable')) {
return APPLICATION_RETRY_MESSAGE;
}
}
return error instanceof Error ? error.message : '操作失败,请重试';
}
+2 -1
View File
@@ -1,6 +1,7 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { cloudAgentsApi } from '@/lib/cloud-agents-api';
import type { CloudAccess, CloudAgentOperations } from '../../../shared/cloud-agents';
import { applicationErrorMessage } from './application-message';
type Publication = CloudAgentOperations['publish']['output'];
type PublishInput = { operation_id: string; expected_revision: number };
@@ -52,7 +53,7 @@ export function useCloudPublication(slug: string, revision: number, onPublished:
onPublished(result);
await refresh();
} catch (failure) {
if (alive.current) setError(errorText(failure));
if (alive.current) setError(applicationErrorMessage(failure));
} finally {
publishing.current = false;
if (alive.current) setBusy(false);
+31 -3
View File
@@ -83,7 +83,7 @@ type FixtureCall = { path: string; method: string; input: Record<string, unknown
type RecoveryFixture = { agents: CloudAgentDraft[]; pending: CloudPendingOperation[]; retry: 'fail' | 'success'; calls: FixtureCall[] };
type FixtureWindow = Window & { __recoveryFixture: RecoveryFixture };
async function installFixture(page: Page, count = 2) {
async function installFixture(page: Page, count = 2, publication = false) {
page.on('pageerror', error => { throw error; });
await page.addInitScript(({ agent, records, retryError }) => {
const scope = window as unknown as FixtureWindow;
@@ -104,7 +104,12 @@ async function installFixture(page: Page, count = 2) {
const record = state.pending.find(item => item.id === input?.id);
if (!record) throw new Error('Recovery must keep the original pending id');
if (input?.discard) { state.pending = state.pending.filter(item => item.id !== record.id); return result({ discarded: true }); }
if (state.retry === 'fail') return { ok: true, data: { status: 503, ok: false, json: { error: retryError } } };
if (state.retry === 'fail') return { ok: true, data: { status: 503, ok: false, json: { error: retryError,
...(record.operation === 'publish' ? { code: 'cloud_service_unavailable', commandOutcome: 'unknown' } : {}) } } };
if (record.operation === 'publish') {
state.pending = state.pending.filter(item => item.id !== record.id);
return result({ operation: 'publish', result: { version: 1, draft_revision: record.input.expected_revision } });
}
const created = { ...agent, slug: 'ml-' + 'b'.repeat(32), name: String(record.input.name), published_version: null };
state.agents.push(created); state.pending = state.pending.filter(item => item.id !== record.id);
return result({ operation: 'createAgent', result: created });
@@ -124,7 +129,9 @@ async function installFixture(page: Page, count = 2) {
}
},
} } });
}, { agent, records: records.slice(0, count), retryError });
}, { agent, records: publication ? [{ id: 'e2e-publish-original', operation: 'publish',
input: { slug: agent.slug, operation_id: 'e2e-publish-original', expected_revision: 1 }, created_at: records[0].created_at }]
: records.slice(0, count), retryError });
}
async function recoveryCalls(page: Page) {
@@ -192,6 +199,27 @@ test('retry keeps the same pending identity and errors remain inside the modal',
expect(await recoveryCalls(page)).toHaveLength(2);
});
test('an application reminder gives a simple action and reuses its record after a network failure', async ({ page }) => {
await page.setViewportSize({ width: 375, height: 850 }); await installFixture(page, 1, true); await page.goto(baseUrl);
await page.getByRole('button', { name: /^待处理记录/ }).click();
const dialog = page.getByRole('dialog', { name: '待处理记录', exact: true });
await expect(dialog.getByRole('heading', { name: '应用设置', exact: true })).toBeVisible();
await expect(dialog.getByText('网络可能不稳定,请再点一次「应用」。', { exact: true })).toBeVisible();
expect(await recoveryCalls(page)).toEqual([]);
const apply = dialog.getByRole('button', { name: '应用', exact: true });
await apply.click();
await expect(dialog.getByRole('alert')).toHaveText('网络可能不稳定,请再点一次「应用」。');
await expect(apply).toBeEnabled(); await expectModalFits(dialog);
await page.screenshot({ path: test.info().outputPath('application-message-375.png'), animations: 'disabled' });
await page.evaluate(() => { (window as unknown as FixtureWindow).__recoveryFixture.retry = 'success'; });
await apply.click();
await expect(dialog.getByText('设置已应用。', { exact: true })).toBeVisible();
await expect(dialog.getByText('查看结果', { exact: true })).toHaveCount(0);
expect((await recoveryCalls(page)).map(call => call.input)).toEqual([
{ id: 'e2e-publish-original', discard: false }, { id: 'e2e-publish-original', discard: false },
]);
});
test('discard is explicit and reminders do not follow into configuration, chat or creation', async ({ page }) => {
await page.setViewportSize({ width: 375, height: 850 }); await installFixture(page); await page.goto(baseUrl);
const trigger = page.getByRole('button', { name: /^创建记录/ });
+8 -7
View File
@@ -1,6 +1,7 @@
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
import { createMemoryRouter, RouterProvider } from 'react-router-dom';
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
import { AppError } from '@/lib/error-model';
import CloudAgents from '@/pages/CloudAgents';
import { EMPTY_CLOUD_CONFIGURATION } from '../../shared/cloud-agents';
@@ -149,17 +150,17 @@ it('retries an uncertain activation with the original operation and keeps pendin
const base = api.call.getMockImplementation()!;
let attempts = 0;
api.call.mockImplementation(async (operation, input) => {
if (operation === 'publish' && ++attempts === 1) throw new Error('连接中断');
if (operation === 'publish' && ++attempts === 1) throw new AppError('NETWORK', '连接中断', undefined, { commandOutcome: 'unknown' });
return base(operation, input);
});
await openConfiguration();
fireEvent.click(screen.getByRole('button', { name: '开始使用', exact: true }));
await screen.findByText(/连接中断/);
await screen.findByText(/网络可能不稳定,请再点一次「应用」。/);
expect(screen.queryByRole('region', { name: '智能体对话' })).not.toBeInTheDocument();
const unload = new Event('beforeunload', { cancelable: true });
window.dispatchEvent(unload);
expect(unload.defaultPrevented).toBe(true);
fireEvent.click(screen.getByRole('button', { name: '重试开始使用', exact: true }));
fireEvent.click(screen.getByRole('button', { name: '应用', exact: true }));
expect(await screen.findByRole('region', { name: '智能体对话' })).toBeVisible();
expect(publications()).toHaveLength(2);
expect(publications()[1][1]).toEqual(publications()[0][1]);
@@ -180,7 +181,7 @@ it('keeps a newer saved revision unapplied when retry resolves the original unce
versions: activated ? [{ version: 1, draft_revision: 3, created_at: '' }] : [],
};
if (operation === 'publish') {
if (++attempts === 1) throw new Error('连接中断');
if (++attempts === 1) throw new AppError('NETWORK', '连接中断', undefined, { commandOutcome: 'unknown' });
activated = true;
current = { ...current, published_version: 1 };
return { version: 1, draft_revision: input.expected_revision };
@@ -189,11 +190,11 @@ it('keeps a newer saved revision unapplied when retry resolves the original unce
});
await openConfiguration();
fireEvent.click(screen.getByRole('button', { name: '开始使用', exact: true }));
await screen.findByText(/连接中断/);
await screen.findByText(/网络可能不稳定,请再点一次「应用」。/);
fireEvent.change(screen.getByLabelText('提示词'), { target: { value: '这次新保存的要求' } });
fireEvent.click(screen.getByRole('button', { name: '保存草稿', exact: true }));
await waitFor(() => expect(screen.getByRole('button', { name: '已保存', exact: true })).toBeDisabled());
fireEvent.click(screen.getByRole('button', { name: '重试开始使用', exact: true }));
fireEvent.click(screen.getByRole('button', { name: '应用', exact: true }));
expect(await screen.findByRole('region', { name: '智能体对话' })).toBeVisible();
expect(screen.queryByRole('button', { name: '应用最新修改', exact: true })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '返回智能体列表', exact: true }));
@@ -225,7 +226,7 @@ it('keeps successful activation and conversation when the following status read
expect(await screen.findByRole('region', { name: '智能体对话' })).toBeVisible();
await waitFor(() => expect(api.call.mock.calls.filter(([operation]) => operation === 'access')).toHaveLength(2));
expect(screen.queryByRole('button', { name: '已应用', exact: true })).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: '重试开始使用', exact: true })).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: '应用', exact: true })).not.toBeInTheDocument();
expect(screen.queryByText(/状态刷新失败/)).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '返回智能体列表', exact: true }));
fireEvent.click(await screen.findByRole('button', { name: '调整', exact: true }));
+22 -3
View File
@@ -5,6 +5,7 @@ import { CloudApproval, CloudChat } from '@/pages/CloudAgents/CloudChat';
import { AgentRequirements } from '@/pages/CloudAgents/AgentRequirements';
import { CloudAccessPanel as AccessPanel } from '@/pages/CloudAgents/CloudAccess';
import { AppError } from '@/lib/error-model';
import { useCloudPublication } from '@/pages/CloudAgents/useCloudPublication';
function CloudAccessPanel(props: { slug: string; revision: number; onPublished: () => void }) {
@@ -43,7 +44,7 @@ it('starts private use through the existing publication action and retains its i
let attempts = 0;
api.call.mockImplementation(async (operation, input) => {
if (operation === 'access') return { published_version: published ? 1 : null, enabled: true, versions: [], grants: [], applications: [] };
if (operation === 'publish') { if (++attempts === 1) throw new Error('连接中断'); published = true; return { version: 1, draft_revision: input.expected_revision }; }
if (operation === 'publish') { if (++attempts === 1) throw new AppError('NETWORK', '连接中断', undefined, { commandOutcome: 'unknown' }); published = true; return { version: 1, draft_revision: input.expected_revision }; }
if (operation === 'costs') return { items: [], next_offset: null, summary: {} };
if (operation === 'channelBindings') return { items: [] };
return base(operation, input);
@@ -53,9 +54,9 @@ it('starts private use through the existing publication action and retains its i
await waitFor(() => expect(screen.getByRole('button', { name: '确认开始使用' })).toBeEnabled());
expect(screen.queryByLabelText('应用名称')).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '确认开始使用' }));
await screen.findByText(/连接中断/);
await screen.findByText(/网络可能不稳定,请再点一次「应用」。/);
view.rerender(<CloudAccessPanel slug={slug} revision={3} onPublished={onPublished} />);
fireEvent.click(screen.getByRole('button', { name: '重试本次发布' }));
fireEvent.click(screen.getByRole('button', { name: '应用' }));
await screen.findByText('助手已准备好');
const publications = api.call.mock.calls.filter(([operation]) => operation === 'publish');
expect(publications).toHaveLength(2);
@@ -65,6 +66,24 @@ it('starts private use through the existing publication action and retains its i
expect(api.call.mock.calls.some(([operation]) => operation === 'share' || operation === 'createApplication')).toBe(false);
});
it.each([
{ status: 401, code: 'session_expired', message: '请重新登录' },
{ status: 403, code: 'access_revoked', message: '无权使用这个智能体' },
{ status: 409, code: 'draft_revision_conflict', message: '云端草稿已更新' },
{ status: 422, code: 'invalid_input', message: '请选择模型' },
{ status: 429, code: 'cloud_service_unavailable', message: '请求过于频繁,请稍后再试' },
])('keeps the actual application rejection for HTTP $status', async ({ status, code, message }) => {
api.call.mockImplementation(async operation => {
if (operation === 'access') return { published_version: null, enabled: true, versions: [], grants: [], applications: [] };
throw new AppError('UNKNOWN', message, undefined, { status, backendCode: code, commandOutcome: 'unknown' });
});
render(<CloudAccessPanel slug={slug} revision={2} onPublished={vi.fn()} />);
await waitFor(() => expect(screen.getByRole('button', { name: '确认开始使用' })).toBeEnabled());
fireEvent.click(screen.getByRole('button', { name: '确认开始使用' }));
expect(await screen.findByRole('alert')).toHaveTextContent(message);
expect(screen.getByRole('alert')).not.toHaveTextContent('网络可能不稳定');
});
it('preserves the entire prompt when displaying and editing former style instruction lines', () => {
const initial = '我的规则\n\n 保留缩进和解释。\n使用简单易懂的语言,遇到新词先解释。\n把任务拆成小步骤,一次引导我完成一步。\n先给我提示和思考问题,让我尝试后再补充答案。\n';
const edited = '先给我提示和思考问题,让我尝试后再补充答案。\n\n 我的新规则\n使用简单易懂的语言,遇到新词先解释。\n把任务拆成小步骤,一次引导我完成一步。\n\n';
+3 -3
View File
@@ -145,8 +145,8 @@ it('retries a failed application from the header using the original publication
await screen.findByText('修改已保存,尚未应用');
fireEvent.click(screen.getByRole('button', { name: '应用最新修改', exact: true }));
await screen.findByText(/连接中断/);
expect(screen.getByRole('button', { name: '重试本次应用' })).toBeEnabled();
fireEvent.click(screen.getByRole('button', { name: '重试本次应用' }));
expect(screen.getByRole('button', { name: '应用' })).toBeEnabled();
fireEvent.click(screen.getByRole('button', { name: '应用' }));
await waitFor(() => expect(screen.getByRole('button', { name: '已应用', exact: true })).toBeDisabled());
const calls = api.call.mock.calls.filter(([operation]) => operation === 'publish');
expect(calls).toHaveLength(2);
@@ -187,7 +187,7 @@ it('keeps a successful application confirmed when its following status refresh f
fireEvent.click(screen.getByRole('button', { name: '应用最新修改', exact: true }));
await screen.findByText(/状态刷新失败/);
expect(screen.getByRole('button', { name: '已应用', exact: true })).toBeDisabled();
expect(screen.queryByRole('button', { name: '重试本次应用' })).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: '应用' })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '刷新应用状态' }));
await waitFor(() => expect(api.call.mock.calls.filter(([operation]) => operation === 'access')).toHaveLength(3));
expect(api.call.mock.calls.filter(([operation]) => operation === 'publish')).toHaveLength(1);
+33
View File
@@ -47,6 +47,39 @@ it('uses a general records entry for mixed operations and keeps the original mes
expect(api.resolvePending).not.toHaveBeenCalled();
});
it('explains a pending application in simple language and retries only its original record', async () => {
const publication: CloudPendingOperation = { ...first, id: 'publish:original', operation: 'publish',
input: { slug: 'ml-' + 'a'.repeat(32), operation_id: 'original-publication', expected_revision: 3 } };
api.resolvePending.mockRejectedValueOnce(new AppError('UNKNOWN', '智能体服务暂时不可用,请重试', undefined,
{ status: 502, backendCode: 'cloud_service_unavailable', commandOutcome: 'unknown' }))
.mockResolvedValueOnce({ result: { version: 2, draft_revision: 3 } });
render(<CloudRecovery pending={[publication]} onResolved={resolved} />);
await openRecords();
const row = screen.getByRole('article', { name: '应用设置' });
expect(within(row).getByText('网络可能不稳定,请再点一次「应用」。')).toBeVisible();
expect(screen.queryByText('发布版本')).not.toBeInTheDocument();
expect(api.resolvePending).not.toHaveBeenCalled();
fireEvent.click(within(row).getByRole('button', { name: '应用', exact: true }));
expect(await screen.findByRole('alert')).toHaveTextContent('网络可能不稳定,请再点一次「应用」。');
expect(resolved).not.toHaveBeenCalled();
fireEvent.click(within(row).getByRole('button', { name: '应用', exact: true }));
expect(await screen.findByText('设置已应用。')).toBeVisible();
expect(api.resolvePending.mock.calls).toEqual([[publication.id, false], [publication.id, false]]);
expect(screen.queryByText('查看结果')).not.toBeInTheDocument();
});
it('keeps a publication conflict explicit instead of calling it a network failure', async () => {
const publication: CloudPendingOperation = { ...first, id: 'publish:conflict', operation: 'publish' };
api.resolvePending.mockRejectedValue(new AppError('UNKNOWN', '云端草稿已更新,请重新读取后再保存', undefined,
{ status: 409, backendCode: 'draft_revision_conflict', commandOutcome: 'unknown' }));
render(<CloudRecovery pending={[publication]} onResolved={resolved} />);
await openRecords(); fireEvent.click(screen.getByRole('button', { name: '应用', exact: true }));
expect(await screen.findByRole('alert')).toHaveTextContent('云端草稿已更新,请重新读取后再保存');
expect(screen.getByRole('alert')).not.toHaveTextContent('网络可能不稳定');
expect(screen.queryByText('网络可能不稳定,请再点一次「应用」。')).not.toBeInTheDocument();
expect(api.resolvePending).toHaveBeenCalledWith(publication.id, false);
});
it('keeps failed records and retries the same record ID after closing and reopening the dialog', async () => {
api.resolvePending.mockRejectedValueOnce(new Error('原操作仍未确认')).mockResolvedValueOnce({ result: { slug: 'original-agent' } });
render(<CloudRecovery pending={[first]} onResolved={resolved} />);