@steerable/agent-shell-web 0.6.15 → 0.6.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +19 -12
- package/vite.base.d.ts +7 -0
- package/vite.base.js +83 -0
- package/src/brand.test.ts +0 -22
- package/src/components/AgentSidebar.test.tsx +0 -127
- package/src/components/ChatHeader.test.tsx +0 -230
- package/src/components/LocalLlmSettingsModal.test.tsx +0 -372
- package/src/components/chat/ApprovalModal.test.tsx +0 -83
- package/src/components/chat/AskUserModalHost.test.tsx +0 -176
- package/src/components/chat/AssistantMessage.test.tsx +0 -68
- package/src/components/chat/ChatInput.test.tsx +0 -609
- package/src/components/chat/ExecPolicyPicker.test.tsx +0 -26
- package/src/components/chat/Markdown.test.tsx +0 -170
- package/src/components/chat/ModelPicker.test.tsx +0 -149
- package/src/components/chat/SessionTreeModal.test.tsx +0 -161
- package/src/components/chat/TaskOutcomeCards.test.tsx +0 -97
- package/src/components/chat/TaskPanelModal.test.tsx +0 -198
- package/src/components/chat/TaskProcessPanel.test.tsx +0 -111
- package/src/components/chat/TurnProcessGroup.test.tsx +0 -161
- package/src/components/chat/elapsed.test.ts +0 -42
- package/src/components/chat/executed-actions-model.test.ts +0 -134
- package/src/components/chat/orchestration-children-model.test.ts +0 -115
- package/src/components/chat/turn-timeline.test.ts +0 -97
- package/src/components/chat/useChatTasks.test.ts +0 -136
- package/src/components/settings/AgentsSettingsPanel.test.tsx +0 -229
- package/src/components/settings/InsightsSettingsPanel.test.tsx +0 -132
- package/src/components/settings/ModelIdCombobox.test.tsx +0 -88
- package/src/components/settings/SecuritySettingsPanel.test.tsx +0 -122
- package/src/components/settings/SkillsSettingsPanel.test.tsx +0 -62
- package/src/components/settings/WebSearchSettingsPanel.test.tsx +0 -90
- package/src/components/settings/compat-flags-model.test.ts +0 -71
- package/src/components/settings/llm-vendors.test.ts +0 -171
- package/src/components/settings/model-capabilities.test.ts +0 -88
- package/src/components/settings/preset-choice-model.test.ts +0 -96
- package/src/lib/pending-first-message.test.ts +0 -17
- package/src/pages/SettingsPage.test.tsx +0 -102
- package/vite.base.ts +0 -94
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steerable/agent-shell-web",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Steerable framework — product-neutral renderer SPA source for @steerable/agent-shell (React + Vite). Consumed by product web entry points via the `@/` alias (anchored at this package's src/) and the createProductViteConfig factory. Published as a source package (src/ + vite.base.ts), not a build artifact.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -14,13 +14,19 @@
|
|
|
14
14
|
"url": "https://github.com/pathlyapp/steerable-framework/issues"
|
|
15
15
|
},
|
|
16
16
|
"exports": {
|
|
17
|
-
"./vite.base":
|
|
17
|
+
"./vite.base": {
|
|
18
|
+
"types": "./vite.base.d.ts",
|
|
19
|
+
"default": "./vite.base.js"
|
|
20
|
+
},
|
|
18
21
|
"./package.json": "./package.json"
|
|
19
22
|
},
|
|
20
23
|
"files": [
|
|
21
24
|
"src",
|
|
25
|
+
"!src/**/*.test.ts",
|
|
26
|
+
"!src/**/*.test.tsx",
|
|
22
27
|
"public",
|
|
23
|
-
"vite.base.
|
|
28
|
+
"vite.base.js",
|
|
29
|
+
"vite.base.d.ts",
|
|
24
30
|
"README.md"
|
|
25
31
|
],
|
|
26
32
|
"publishConfig": {
|
|
@@ -28,6 +34,8 @@
|
|
|
28
34
|
"provenance": true
|
|
29
35
|
},
|
|
30
36
|
"dependencies": {
|
|
37
|
+
"@tailwindcss/vite": "^4.3.0",
|
|
38
|
+
"@vitejs/plugin-react": "^4.7.0",
|
|
31
39
|
"@xterm/addon-fit": "^0.11.0",
|
|
32
40
|
"@xterm/addon-web-links": "^0.12.0",
|
|
33
41
|
"@xterm/xterm": "^6.0.0",
|
|
@@ -39,25 +47,24 @@
|
|
|
39
47
|
"react-router-dom": "^6.30.0",
|
|
40
48
|
"rehype-raw": "^7.0.0",
|
|
41
49
|
"remark-gfm": "^4.0.1",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
50
|
+
"tailwindcss": "^4.3.0",
|
|
51
|
+
"vite": "^5.4.21",
|
|
52
|
+
"@steerable/agent-protocol": "0.6.17",
|
|
53
|
+
"@steerable/agent-ui": "0.6.17",
|
|
54
|
+
"@steerable/pack-sdk": "0.6.17"
|
|
44
55
|
},
|
|
45
56
|
"devDependencies": {
|
|
46
|
-
"@tailwindcss/vite": "^4.3.0",
|
|
47
57
|
"@testing-library/react": "^16.1.0",
|
|
48
58
|
"@types/react": "^18.3.12",
|
|
49
59
|
"@types/react-dom": "^18.3.1",
|
|
50
|
-
"@vitejs/plugin-react": "^4.7.0",
|
|
51
60
|
"happy-dom": "^15.11.7",
|
|
52
|
-
"tailwindcss": "^4.3.0",
|
|
53
61
|
"typescript": "^5.8.3",
|
|
54
|
-
"
|
|
55
|
-
"vitest": "^3.2.4",
|
|
56
|
-
"@steerable/pack-sdk": "0.6.15"
|
|
62
|
+
"vitest": "^3.2.4"
|
|
57
63
|
},
|
|
58
64
|
"scripts": {
|
|
59
65
|
"gen": "echo agent-shell-web",
|
|
60
|
-
"build": "tsc --noEmit",
|
|
66
|
+
"build": "tsc --noEmit && npm run build:vite-base",
|
|
67
|
+
"build:vite-base": "tsc vite.base.ts --module esnext --target es2022 --moduleResolution bundler --declaration --skipLibCheck --outDir .",
|
|
61
68
|
"typecheck": "tsc --noEmit",
|
|
62
69
|
"test": "vitest run",
|
|
63
70
|
"lint": "tsc --noEmit",
|
package/vite.base.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface ProductViteConfigOptions {
|
|
2
|
+
/** 产品目录(products/<id>/web 的上一级…即 products/<id>)。 */
|
|
3
|
+
productDir: string;
|
|
4
|
+
/** 产品 flavor(决定品牌 define 与激活包集合)。 */
|
|
5
|
+
flavor: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function createProductViteConfig(options: ProductViteConfigOptions): import("vite").UserConfig;
|
package/vite.base.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 产品 web 构建的共享 vite 配置工厂(2.3)。
|
|
3
|
+
*
|
|
4
|
+
* 每个产品(products/<id>/web/)有自己的 vite 入口:index.html +
|
|
5
|
+
* main.tsx(静态注册本产品的包渲染层贡献)+ vite.config.ts(调本工厂)。
|
|
6
|
+
* 产品的编译单元只含自己的包——未激活包代码不进 bundle,不依赖树摇
|
|
7
|
+
* 正确性(物理隔离与 node 侧对称)。
|
|
8
|
+
*
|
|
9
|
+
* Electron 加载产物时走 file:// 协议,必须用相对路径,否则资源 404。
|
|
10
|
+
* dev server 跑在固定端口,主进程的 IS_DEV 分支 loadURL('http://localhost:5173')。
|
|
11
|
+
*/
|
|
12
|
+
import { defineConfig } from 'vite';
|
|
13
|
+
import react from '@vitejs/plugin-react';
|
|
14
|
+
import tailwindcss from '@tailwindcss/vite';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
18
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
export function createProductViteConfig(options) {
|
|
20
|
+
const { productDir, flavor } = options;
|
|
21
|
+
const repoRoot = path.resolve(productDir, '../..');
|
|
22
|
+
// shell 渲染层源码锚到本包自身(3.2 起住在框架仓库
|
|
23
|
+
// packages/agent-shell/web/src),产品经 `@/` 别名引用。
|
|
24
|
+
const webSrcDir = path.resolve(HERE, 'src');
|
|
25
|
+
const readJson = (p) => JSON.parse(readFileSync(p, 'utf8'));
|
|
26
|
+
// 产品品牌(3.1):product.json 的 brand 字段优先(无包产品的品牌
|
|
27
|
+
// 来源);否则取激活包 pack.json 的 brand(0.3g 机制,读
|
|
28
|
+
// products/manifest.json 的 flavor→包映射,第一个带 brand 的包)。
|
|
29
|
+
// 都没有则用 shell 中性默认(Agent Shell)。
|
|
30
|
+
const productJsonPath = path.join(productDir, 'product.json');
|
|
31
|
+
const product = existsSync(productJsonPath) ? readJson(productJsonPath) : {};
|
|
32
|
+
const manifest = readJson(path.join(repoRoot, 'products/manifest.json'));
|
|
33
|
+
let packBrand = null;
|
|
34
|
+
for (const packId of manifest.flavors?.[flavor] ?? []) {
|
|
35
|
+
const pack = readJson(path.join(repoRoot, 'packages', `pack-${packId}`, 'pack.json'));
|
|
36
|
+
if (pack.brand) {
|
|
37
|
+
packBrand = pack.brand;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const brand = product.brand ?? packBrand;
|
|
42
|
+
return defineConfig({
|
|
43
|
+
// root 默认取 config 文件所在目录(products/<id>/web)。
|
|
44
|
+
base: './',
|
|
45
|
+
plugins: [react(), tailwindcss()],
|
|
46
|
+
define: {
|
|
47
|
+
// 显式 define 让 flavor 条件在构建期可静态折叠。
|
|
48
|
+
'import.meta.env.VITE_APP_FLAVOR': JSON.stringify(flavor),
|
|
49
|
+
// 品牌 define:产品/包声明覆盖 shell 中性默认(Agent Shell)。
|
|
50
|
+
// logo 不走 define——资产必须静态 import 才进 bundle,由包 web 模块
|
|
51
|
+
// 在注册时经 setBrandLogoUrl 注入(本包 src/brand.ts)。
|
|
52
|
+
'import.meta.env.VITE_BRAND_NAME': JSON.stringify(brand?.displayName ?? 'Steerable Shell'),
|
|
53
|
+
'import.meta.env.VITE_BRAND_TAGLINE': JSON.stringify(brand?.tagline ?? '一款本地桌面 AI 伙伴'),
|
|
54
|
+
'import.meta.env.VITE_DEFAULT_AGENT_ID': JSON.stringify(brand?.defaultAgentId ?? 'local-assistant'),
|
|
55
|
+
},
|
|
56
|
+
resolve: {
|
|
57
|
+
alias: {
|
|
58
|
+
// shell 渲染层源码(产品入口与包 web 模块都以 `@/` 引用它)。
|
|
59
|
+
'@': webSrcDir,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
// 静态资产(favicon 等中性默认)随 shell web 包分发;产品可在自己的
|
|
63
|
+
// web root 放 public/ 覆盖(vite 不合并双 publicDir——需要产品级资产
|
|
64
|
+
// 时在产品 vite.config 里显式覆盖本字段)。
|
|
65
|
+
publicDir: path.resolve(HERE, 'public'),
|
|
66
|
+
server: {
|
|
67
|
+
port: 5173,
|
|
68
|
+
strictPort: true,
|
|
69
|
+
host: '127.0.0.1',
|
|
70
|
+
// 产品 root 在 products/<id>/web;shell 渲染层源码在框架仓库
|
|
71
|
+
// (3.2 起经 file: 依赖符号链接)——两个根都放行。
|
|
72
|
+
fs: { allow: [repoRoot, path.resolve(webSrcDir, '..')] },
|
|
73
|
+
},
|
|
74
|
+
build: {
|
|
75
|
+
// 产物落在产品目录:products/<id>/web/dist(打包期被 electron-builder
|
|
76
|
+
// 映射为包内 web-dist/)。
|
|
77
|
+
outDir: 'dist',
|
|
78
|
+
emptyOutDir: true,
|
|
79
|
+
sourcemap: true,
|
|
80
|
+
target: 'chrome120',
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
package/src/brand.test.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { LOCAL_ASSISTANT_AGENT_ID, pickDefaultAgentId } from './brand';
|
|
3
|
-
|
|
4
|
-
describe('pickDefaultAgentId', () => {
|
|
5
|
-
const catalog = [
|
|
6
|
-
{ id: LOCAL_ASSISTANT_AGENT_ID },
|
|
7
|
-
{ id: 'data-analyst' },
|
|
8
|
-
{ id: 'all-round-assistant' },
|
|
9
|
-
];
|
|
10
|
-
|
|
11
|
-
it('returns null when the catalog is empty', () => {
|
|
12
|
-
expect(pickDefaultAgentId([])).toBeNull();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('prefers the build-time default (shell: 电脑操作员) even when it is not first', () => {
|
|
16
|
-
expect(pickDefaultAgentId(catalog)).toBe(LOCAL_ASSISTANT_AGENT_ID);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('falls back to the first visible agent when the build default is absent', () => {
|
|
20
|
-
expect(pickDefaultAgentId([{ id: 'writer' }, { id: 'reader' }])).toBe('writer');
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
|
|
2
|
-
import { MemoryRouter, Outlet, Route, Routes, useLocation } from 'react-router-dom';
|
|
3
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
import type { UseChatsAndAgentsResult } from '@/hooks/useChatsAndAgents';
|
|
5
|
-
import type { LocalChat, LocalChatAgent } from '@/lib/local-api';
|
|
6
|
-
|
|
7
|
-
vi.mock('@/lib/electron-bridge', () => ({
|
|
8
|
-
isElectron: () => false,
|
|
9
|
-
getElectronBridge: () => null,
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
vi.mock('@/brand', () => ({
|
|
13
|
-
BRAND_NAME: '测试助手',
|
|
14
|
-
getBrandLogoUrl: () => 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"/>',
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
const { AgentSidebar } = await import('./AgentSidebar');
|
|
18
|
-
|
|
19
|
-
afterEach(() => cleanup());
|
|
20
|
-
|
|
21
|
-
const agent: LocalChatAgent = {
|
|
22
|
-
id: 'local-assistant',
|
|
23
|
-
slug: 'local-assistant',
|
|
24
|
-
name: '电脑操作员',
|
|
25
|
-
icon: null,
|
|
26
|
-
color: '#4f46e5',
|
|
27
|
-
description: null,
|
|
28
|
-
rolePrompt: null,
|
|
29
|
-
isBuiltin: true,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const existingChat: LocalChat = {
|
|
33
|
-
id: 'chat-with-content',
|
|
34
|
-
projectId: null,
|
|
35
|
-
userId: 'local',
|
|
36
|
-
title: '已经聊过的对话',
|
|
37
|
-
agentId: agent.id,
|
|
38
|
-
createdAt: '2026-01-01T00:00:00.000Z',
|
|
39
|
-
updatedAt: '2026-01-01T00:01:00.000Z',
|
|
40
|
-
isPinned: false,
|
|
41
|
-
systemPrompt: null,
|
|
42
|
-
pinnedRefs: null,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
function LocationProbe() {
|
|
46
|
-
const loc = useLocation();
|
|
47
|
-
return (
|
|
48
|
-
<div data-testid="loc">
|
|
49
|
-
{loc.pathname}
|
|
50
|
-
{loc.search}
|
|
51
|
-
</div>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function renderSidebar(
|
|
56
|
-
initialEntry: string,
|
|
57
|
-
createChat = vi.fn(),
|
|
58
|
-
) {
|
|
59
|
-
const data: UseChatsAndAgentsResult = {
|
|
60
|
-
chats: [existingChat],
|
|
61
|
-
agents: [agent],
|
|
62
|
-
isLoading: false,
|
|
63
|
-
error: null,
|
|
64
|
-
selectedAgentId: agent.id,
|
|
65
|
-
setSelectedAgentId: vi.fn(),
|
|
66
|
-
refreshChats: vi.fn(async () => {}),
|
|
67
|
-
refreshAgents: vi.fn(async () => {}),
|
|
68
|
-
createChat,
|
|
69
|
-
deleteChat: vi.fn(async () => true),
|
|
70
|
-
patchChatTitle: vi.fn(),
|
|
71
|
-
isLoadingMoreChats: false,
|
|
72
|
-
hasMoreChats: false,
|
|
73
|
-
loadMoreChats: vi.fn(async () => {}),
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
render(
|
|
77
|
-
<MemoryRouter initialEntries={[initialEntry]}>
|
|
78
|
-
<Routes>
|
|
79
|
-
<Route
|
|
80
|
-
element={
|
|
81
|
-
<>
|
|
82
|
-
<AgentSidebar
|
|
83
|
-
data={data}
|
|
84
|
-
rightPanel={null}
|
|
85
|
-
onToggleRightPanel={() => {}}
|
|
86
|
-
chatSlots={[]}
|
|
87
|
-
onCollapse={() => {}}
|
|
88
|
-
/>
|
|
89
|
-
<LocationProbe />
|
|
90
|
-
<Outlet />
|
|
91
|
-
</>
|
|
92
|
-
}
|
|
93
|
-
>
|
|
94
|
-
<Route path="/" element={<div />} />
|
|
95
|
-
<Route path="/agent" element={<div />} />
|
|
96
|
-
<Route path="/agent/:chatId" element={<div />} />
|
|
97
|
-
<Route path="/settings" element={<div />} />
|
|
98
|
-
</Route>
|
|
99
|
-
</Routes>
|
|
100
|
-
</MemoryRouter>,
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
return { createChat };
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
describe('AgentSidebar 新对话不落库', () => {
|
|
107
|
-
it('打开落地页且不调用 createChat', () => {
|
|
108
|
-
const { createChat } = renderSidebar('/agent/chat-with-content');
|
|
109
|
-
fireEvent.click(screen.getByTestId('sidebar-new-chat'));
|
|
110
|
-
expect(createChat).not.toHaveBeenCalled();
|
|
111
|
-
expect(screen.getByTestId('loc').textContent).toBe('/agent');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('连点两次也不会多出侧栏行', () => {
|
|
115
|
-
renderSidebar('/agent');
|
|
116
|
-
const before = screen.getAllByTestId('sidebar-chat-row').length;
|
|
117
|
-
fireEvent.click(screen.getByTestId('sidebar-new-chat'));
|
|
118
|
-
fireEvent.click(screen.getByTestId('sidebar-new-chat'));
|
|
119
|
-
expect(screen.getAllByTestId('sidebar-chat-row')).toHaveLength(before);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('打开智能体管理页', () => {
|
|
123
|
-
renderSidebar('/agent');
|
|
124
|
-
fireEvent.click(screen.getByTestId('sidebar-agent-settings'));
|
|
125
|
-
expect(screen.getByTestId('loc').textContent).toBe('/settings?section=agents');
|
|
126
|
-
});
|
|
127
|
-
});
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ChatHeader 任务角标契约:后台任务在面板关着的时候也要能被看见,
|
|
3
|
-
* 且只有一件事等着处理时点角标要能跳过任务列表这一层。
|
|
4
|
-
* - 无任务 → 按钮保持素净,不显示计数;
|
|
5
|
-
* - 有任务 → 按钮上色 + 计数,配色按「该不该现在看一眼」取最高优先级
|
|
6
|
-
* (运行中 > 待合并 > 失败 > 全部跑完);
|
|
7
|
-
* - 唯一失败任务 → 点角标直接开推理过程,不经弹层;
|
|
8
|
-
* - 唯一待合并任务 → 点角标开弹层并展开该行(合并/丢弃按钮在那儿);
|
|
9
|
-
* - 有任务在跑或多件待处理 → 仍然先给列表,用户得先挑。
|
|
10
|
-
* 列表本身的订阅与刷新归 useChatTasks,见 chat/useChatTasks.test.ts。
|
|
11
|
-
*/
|
|
12
|
-
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
13
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
14
|
-
import type { LocalChat, LocalTask } from '@/lib/local-api';
|
|
15
|
-
import { ChatHeader } from './ChatHeader';
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
cleanup();
|
|
19
|
-
delete (window as { electron?: unknown }).electron;
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const CHAT: LocalChat = {
|
|
23
|
-
id: 'chat_1',
|
|
24
|
-
projectId: null,
|
|
25
|
-
userId: 'u1',
|
|
26
|
-
title: '循环任务',
|
|
27
|
-
agentId: null,
|
|
28
|
-
createdAt: '2026-09-13T01:00:00.000Z',
|
|
29
|
-
updatedAt: '2026-09-13T01:00:00.000Z',
|
|
30
|
-
isPinned: false,
|
|
31
|
-
systemPrompt: null,
|
|
32
|
-
pinnedRefs: null,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
function makeTask(overrides: Partial<LocalTask> = {}): LocalTask {
|
|
36
|
-
return {
|
|
37
|
-
id: 'task-1',
|
|
38
|
-
chatId: 'chat_1',
|
|
39
|
-
task: '每 5 分钟问好',
|
|
40
|
-
status: 'completed',
|
|
41
|
-
answer: '你好',
|
|
42
|
-
error: null,
|
|
43
|
-
worktreePath: null,
|
|
44
|
-
worktreeBranch: null,
|
|
45
|
-
worktreeState: null,
|
|
46
|
-
createdAt: '2026-09-13T01:00:00.000Z',
|
|
47
|
-
updatedAt: '2026-09-13T01:01:00.000Z',
|
|
48
|
-
...overrides,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** 弹层自带订阅:展开它的用例需要一个能应答 GET /tasks 的 bridge。 */
|
|
53
|
-
function installBridge(tasks: LocalTask[]) {
|
|
54
|
-
(window as { electron?: unknown }).electron = {
|
|
55
|
-
localBackend: {
|
|
56
|
-
request: vi.fn((input: { method: string; path: string }) => {
|
|
57
|
-
if (input.method === 'GET' && input.path.endsWith('/tasks')) {
|
|
58
|
-
return Promise.resolve({ tasks });
|
|
59
|
-
}
|
|
60
|
-
return Promise.reject(new Error(`unexpected request: ${input.path}`));
|
|
61
|
-
}),
|
|
62
|
-
},
|
|
63
|
-
onTaskUpdated: () => () => {},
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function taskButton() {
|
|
68
|
-
return screen.getByRole('button', { name: /后台任务/ });
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
describe('ChatHeader 后台任务角标', () => {
|
|
72
|
-
it('没有任务时不显示计数', () => {
|
|
73
|
-
render(<ChatHeader chat={CHAT} agent={null} tasks={[]} />);
|
|
74
|
-
|
|
75
|
-
expect(taskButton().getAttribute('data-task-state')).toBeNull();
|
|
76
|
-
expect(taskButton().textContent).toBe('');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('有运行中的任务时显示运行中计数并标成 running', () => {
|
|
80
|
-
render(
|
|
81
|
-
<ChatHeader
|
|
82
|
-
chat={CHAT}
|
|
83
|
-
agent={null}
|
|
84
|
-
tasks={[
|
|
85
|
-
makeTask({ id: 'a', status: 'running' }),
|
|
86
|
-
makeTask({ id: 'b', status: 'running' }),
|
|
87
|
-
makeTask({ id: 'c', status: 'completed' }),
|
|
88
|
-
]}
|
|
89
|
-
/>,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
expect(taskButton().getAttribute('data-task-state')).toBe('running');
|
|
93
|
-
expect(taskButton().textContent).toBe('2');
|
|
94
|
-
expect(taskButton().getAttribute('title')).toBe('共 3 个后台任务(2 个运行中)');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('等依赖的任务也算在推进中', () => {
|
|
98
|
-
render(
|
|
99
|
-
<ChatHeader chat={CHAT} agent={null} tasks={[makeTask({ id: 'a', status: 'blocked' })]} />,
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
expect(taskButton().getAttribute('data-task-state')).toBe('running');
|
|
103
|
-
expect(taskButton().getAttribute('title')).toBe('共 1 个后台任务(1 个等依赖)');
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('待合并的 worktree 任务优先于失败任务上色', () => {
|
|
107
|
-
render(
|
|
108
|
-
<ChatHeader
|
|
109
|
-
chat={CHAT}
|
|
110
|
-
agent={null}
|
|
111
|
-
tasks={[
|
|
112
|
-
makeTask({ id: 'a', status: 'completed', worktreeState: 'pending' }),
|
|
113
|
-
makeTask({ id: 'b', status: 'failed', error: '炸了' }),
|
|
114
|
-
]}
|
|
115
|
-
/>,
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
expect(taskButton().getAttribute('data-task-state')).toBe('review');
|
|
119
|
-
expect(taskButton().textContent).toBe('1');
|
|
120
|
-
expect(taskButton().getAttribute('title')).toBe('共 2 个后台任务(1 个待合并,1 个失败)');
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('只有失败任务时标成 failed', () => {
|
|
124
|
-
render(
|
|
125
|
-
<ChatHeader
|
|
126
|
-
chat={CHAT}
|
|
127
|
-
agent={null}
|
|
128
|
-
tasks={[makeTask({ id: 'a', status: 'failed', error: '炸了' })]}
|
|
129
|
-
/>,
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
expect(taskButton().getAttribute('data-task-state')).toBe('failed');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('全部跑完时显示总数,不再抢注意力', () => {
|
|
136
|
-
render(
|
|
137
|
-
<ChatHeader chat={CHAT} agent={null} tasks={[makeTask({ id: 'a' }), makeTask({ id: 'b' })]} />,
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
expect(taskButton().getAttribute('data-task-state')).toBe('idle');
|
|
141
|
-
expect(taskButton().textContent).toBe('2');
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
describe('ChatHeader 角标直达', () => {
|
|
146
|
-
it('唯一失败任务:点角标直接开推理过程,不开弹层', () => {
|
|
147
|
-
const onInspectTask = vi.fn();
|
|
148
|
-
render(
|
|
149
|
-
<ChatHeader
|
|
150
|
-
chat={CHAT}
|
|
151
|
-
agent={null}
|
|
152
|
-
onInspectTask={onInspectTask}
|
|
153
|
-
tasks={[makeTask({ id: 'a', status: 'failed', task: '跑测试', error: '炸了' })]}
|
|
154
|
-
/>,
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
expect(taskButton().getAttribute('data-task-shortcut')).toBe('process');
|
|
158
|
-
expect(taskButton().getAttribute('title')).toContain('点击查看推理过程');
|
|
159
|
-
|
|
160
|
-
fireEvent.click(taskButton());
|
|
161
|
-
|
|
162
|
-
expect(onInspectTask).toHaveBeenCalledWith({
|
|
163
|
-
id: 'a',
|
|
164
|
-
chatId: 'chat_1',
|
|
165
|
-
title: '跑测试',
|
|
166
|
-
});
|
|
167
|
-
expect(document.querySelector('[data-task-panel-modal]')).toBeNull();
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('唯一待合并任务:点角标开弹层并展开该行', async () => {
|
|
171
|
-
const task = makeTask({
|
|
172
|
-
id: 'a',
|
|
173
|
-
status: 'completed',
|
|
174
|
-
worktreeState: 'pending',
|
|
175
|
-
worktreePath: '/tmp/wt',
|
|
176
|
-
worktreeBranch: 'steerable/a',
|
|
177
|
-
});
|
|
178
|
-
installBridge([task]);
|
|
179
|
-
render(<ChatHeader chat={CHAT} agent={null} onInspectTask={vi.fn()} tasks={[task]} />);
|
|
180
|
-
|
|
181
|
-
expect(taskButton().getAttribute('data-task-shortcut')).toBe('expand');
|
|
182
|
-
expect(taskButton().getAttribute('title')).toContain('点击处理 worktree');
|
|
183
|
-
|
|
184
|
-
fireEvent.click(taskButton());
|
|
185
|
-
|
|
186
|
-
// 展开态的标志:worktree 的「合并到主仓」按钮直接可见,不用再点一次。
|
|
187
|
-
await waitFor(() => expect(document.querySelector('[data-task-merge]')).not.toBeNull());
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('有任务在跑时不直达——先给列表', () => {
|
|
191
|
-
const onInspectTask = vi.fn();
|
|
192
|
-
render(
|
|
193
|
-
<ChatHeader
|
|
194
|
-
chat={CHAT}
|
|
195
|
-
agent={null}
|
|
196
|
-
onInspectTask={onInspectTask}
|
|
197
|
-
tasks={[
|
|
198
|
-
makeTask({ id: 'a', status: 'failed', error: '炸了' }),
|
|
199
|
-
makeTask({ id: 'b', status: 'running' }),
|
|
200
|
-
]}
|
|
201
|
-
/>,
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
expect(taskButton().getAttribute('data-task-shortcut')).toBeNull();
|
|
205
|
-
expect(taskButton().getAttribute('title')).not.toContain('点击');
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('多件待处理时不直达——用户得先挑', () => {
|
|
209
|
-
const onInspectTask = vi.fn();
|
|
210
|
-
installBridge([]);
|
|
211
|
-
render(
|
|
212
|
-
<ChatHeader
|
|
213
|
-
chat={CHAT}
|
|
214
|
-
agent={null}
|
|
215
|
-
onInspectTask={onInspectTask}
|
|
216
|
-
tasks={[
|
|
217
|
-
makeTask({ id: 'a', status: 'failed', error: '炸了' }),
|
|
218
|
-
makeTask({ id: 'b', status: 'failed', error: '也炸了' }),
|
|
219
|
-
]}
|
|
220
|
-
/>,
|
|
221
|
-
);
|
|
222
|
-
|
|
223
|
-
expect(taskButton().getAttribute('data-task-shortcut')).toBeNull();
|
|
224
|
-
|
|
225
|
-
fireEvent.click(taskButton());
|
|
226
|
-
|
|
227
|
-
expect(onInspectTask).not.toHaveBeenCalled();
|
|
228
|
-
expect(document.querySelector('[data-task-panel-modal]')).not.toBeNull();
|
|
229
|
-
});
|
|
230
|
-
});
|