fix(settings): preserve preset agents when saving custom agents#1908
fix(settings): preserve preset agents when saving custom agents#1908
Conversation
The old CustomAcpAgent component loaded only non-preset agents into its local state, then wrote that subset back to acp.customAgents on save — silently deleting all preset assistants from the config array. This fix integrates InlineAgentEditor into LocalAgents and ensures every save/delete/toggle operation reads the full config (including presets) before writing back, preventing data loss.
Code Review:fix(settings): preserve preset agents when saving custom agents (#1908)变更概述本 PR 修复了 方案评估结论:✅ 方案合理 根本原因分析准确,修复直接。"先读全量 config、再追加/更新/删除、再写回"的模式能可靠防止 preset 数据丢失,且与项目现有 ConfigStorage 用法一致。将 问题清单🟡 MEDIUM — 关键测试用例未实际验证 preset 保留逻辑文件: 问题代码: it('saves custom agent while preserving preset agents in config', async () => {
// ...
// Click add button
const addButton = screen.getByText('settings.addCustomAgentTitle');
await act(async () => {
fireEvent.click(addButton);
});
// The critical assertion is in the save callback logic:
// ...
expect(mockConfigGet).toHaveBeenCalledWith('acp.customAgents');
});问题说明:测试名称声称验证"保存时保留 preset agents",但实际断言 修复建议:通过触发 it('saves custom agent while preserving preset agents in config', async () => {
const presetAgent = { id: 'cowork', name: 'Cowork', isPreset: true, enabled: true, context: 'test' };
mockConfigGet.mockResolvedValue([presetAgent]);
await act(async () => {
render(<LocalAgents />);
});
// Click add to show InlineAgentEditor, fill fields, submit
// ...
// Core assertion: ConfigStorage.set must be called with presets preserved
expect(mockConfigSet).toHaveBeenCalledWith(
'acp.customAgents',
expect.arrayContaining([
expect.objectContaining({ id: 'cowork', isPreset: true }),
expect.objectContaining({ name: 'New Agent' }),
])
);
});🔵 LOW — Oxlint
|
| # | 严重级别 | 文件 | 问题 |
|---|---|---|---|
| 1 | 🟡 MEDIUM | tests/unit/LocalAgents.dom.test.tsx:210 |
关键测试用例未实际验证 preset 保留逻辑,断言恒真 |
| 2 | 🔵 LOW | src/renderer/pages/settings/AgentSettings/LocalAgents.tsx:119 |
no-map-spread lint 警告与不可变性原则冲突,需对齐配置 |
结论
本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。
CONCLUSION: CONDITIONAL
IS_CRITICAL_PATH: false
PR_NUMBER: 1908
- Replace weak indirect assertion in preset-preservation test with a direct save trigger via mocked InlineAgentEditor, asserting that ConfigStorage.set receives both the existing preset agent and the new custom agent in the written array - Apply oxlint autofix: use Array.toSorted() instead of sort() in SpeechToTextService Review follow-up for #1908
PR Fix 验证报告原始 PR: #1908
总结: ✅ 已修复 1 个 | 🔵 LOW 问题已跳过
|
Hide the Custom Agents section (header, add button, list, InlineAgentEditor) and all related state/handlers that were introduced in #1908. Update the LocalAgents test suite to remove tests covering the removed UI.
Hide the Custom Agents section (header, add button, list, InlineAgentEditor) and all related state/handlers that were introduced in #1908. Update the LocalAgents test suite to remove tests covering the removed UI. Co-authored-by: zynx <>
Summary
acp.customAgentsconfigInlineAgentEditorintoLocalAgentstab with add/edit/delete/toggle supportRelated Issues
Closes #1898
Root Cause
The old
CustomAcpAgentcomponent loaded agents withagents.filter(!isPreset), then wrote[...customAgents, newAgent]back toacp.customAgents— silently deleting all preset assistants from the config. After a page refresh, the assistant list appeared empty because all preset entries were gone.Test Plan