@allbluecn/web-app 0.27.29 → 0.27.30

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allbluecn/web-app",
3
- "version": "0.27.29",
3
+ "version": "0.27.30",
4
4
  "license": "AGPL-3.0-or-later",
5
5
  "type": "module",
6
6
  "files": [
@@ -0,0 +1,117 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 AllBlue Contributors
3
+ //
4
+ // 档位变更接线(原 body.setSandboxPolicy=裸 useState setter,T2.4 的
5
+ // setSandboxPolicyFn 服务端零 UI 调用方——切档只改客户端状态,写操作被
6
+ // readonly→plan 全拒):hook 级断言——有线程切档调 setSandboxPolicyFn
7
+ // (confirmFull 随档);空态仅客户端状态;create 流程非只读档补施加。
8
+
9
+ import { describe, expect, it, vi, beforeEach } from 'vitest'
10
+ import { renderHook, act, waitFor } from '@testing-library/react'
11
+ import type { ReactNode } from 'react'
12
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
13
+ import { HotkeysProvider } from '@tanstack/react-hotkeys'
14
+ import { appHotkeys } from '@/lib/hotkeys/registry'
15
+
16
+ const setSandboxPolicyFnMock = vi.fn(async (_args: { data: unknown }) => 'workspace-write' as const)
17
+ const createConversationFnMock = vi.fn(async (_args: { data: unknown }) => ({
18
+ id: 'conv-new',
19
+ title: null,
20
+ engine: 'local',
21
+ localCwd: '/tmp/ws',
22
+ localAgentId: null,
23
+ userId: 'local-guest',
24
+ updatedAt: new Date().toISOString(),
25
+ }))
26
+
27
+ vi.mock('@tanstack/react-router', () => ({
28
+ useNavigate: () => vi.fn(),
29
+ useLocation: () => ({ pathname: '/harness', searchStr: '' }),
30
+ useParams: () => ({}),
31
+ Link: (props: { children?: ReactNode; to?: string }) => <a href={props.to}>{props.children}</a>,
32
+ }))
33
+ vi.mock('@/server/serverFns/harness/sandbox-policy', () => ({
34
+ setSandboxPolicyFn: (args: { data: unknown }) => setSandboxPolicyFnMock(args),
35
+ getSandboxPolicyFn: vi.fn(async () => 'readonly'),
36
+ }))
37
+ vi.mock('@/server/serverFns/chat/conversations', () => ({
38
+ createConversationFn: (args: { data: unknown }) => createConversationFnMock(args),
39
+ updateConversationFn: vi.fn(async () => ({})),
40
+ listConversationsFn: vi.fn(async () => []),
41
+ getConversationFn: vi.fn(async () => null),
42
+ }))
43
+ vi.mock('@/server/serverFns/harness/fork-thread', () => ({
44
+ forkHarnessThreadFn: vi.fn(async () => ({ id: 'fork-1' })),
45
+ }))
46
+ vi.mock('@/server/serverFns/ai-usage', () => ({ cancelRunFn: vi.fn(async () => ({})) }))
47
+
48
+ import { useWorkbenchBody, WorkbenchProvider } from '../workbench/workbench-context'
49
+
50
+ function makeWrapper() {
51
+ const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } })
52
+ return function Wrapper({ children }: { children: ReactNode }) {
53
+ return (
54
+ <QueryClientProvider client={qc}>
55
+ <HotkeysProvider appHotkeys={appHotkeys}>
56
+ <WorkbenchProvider>{children}</WorkbenchProvider>
57
+ </HotkeysProvider>
58
+ </QueryClientProvider>
59
+ )
60
+ }
61
+ }
62
+
63
+ function makeWrapperWithThread(threadId: string) {
64
+ const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } })
65
+ return function Wrapper({ children }: { children: ReactNode }) {
66
+ return (
67
+ <QueryClientProvider client={qc}>
68
+ <HotkeysProvider appHotkeys={appHotkeys}>
69
+ <WorkbenchProvider initialThreadId={threadId}>{children}</WorkbenchProvider>
70
+ </HotkeysProvider>
71
+ </QueryClientProvider>
72
+ )
73
+ }
74
+ }
75
+
76
+ describe('档位变更接线(setSandboxPolicyFn 零调用方修复)', () => {
77
+ beforeEach(() => {
78
+ setSandboxPolicyFnMock.mockClear()
79
+ createConversationFnMock.mockClear()
80
+ window.localStorage.clear()
81
+ })
82
+
83
+ it('空态切档:仅客户端状态,不调服务端(无线程可施加)', async () => {
84
+ const { result } = renderHook(() => useWorkbenchBody(), { wrapper: makeWrapper() })
85
+ act(() => {
86
+ result.current.setSandboxPolicy('workspace-write')
87
+ })
88
+ expect(setSandboxPolicyFnMock).not.toHaveBeenCalled()
89
+ expect(result.current.sandboxPolicy).toBe('workspace-write')
90
+ })
91
+ })
92
+
93
+ it('已有线程切档 → setSandboxPolicyFn 以 threadId+level+confirmFull 调用', async () => {
94
+ const { result } = renderHook(() => useWorkbenchBody(), {
95
+ wrapper: makeWrapperWithThread('t-1'),
96
+ })
97
+ await act(async () => {
98
+ result.current.setSandboxPolicy('workspace-write')
99
+ })
100
+ await waitFor(() => expect(setSandboxPolicyFnMock).toHaveBeenCalledTimes(1))
101
+ expect(setSandboxPolicyFnMock).toHaveBeenCalledWith({
102
+ data: { threadId: 't-1', level: 'workspace-write', confirmFull: false },
103
+ })
104
+ })
105
+
106
+ it('完全档 → confirmFull: true(composer 二次确认完成后才到达本 handler)', async () => {
107
+ const { result } = renderHook(() => useWorkbenchBody(), {
108
+ wrapper: makeWrapperWithThread('t-1'),
109
+ })
110
+ await act(async () => {
111
+ result.current.setSandboxPolicy('full')
112
+ })
113
+ await waitFor(() => expect(setSandboxPolicyFnMock).toHaveBeenCalledTimes(1))
114
+ expect(setSandboxPolicyFnMock).toHaveBeenCalledWith({
115
+ data: { threadId: 't-1', level: 'full', confirmFull: true },
116
+ })
117
+ })
@@ -62,6 +62,7 @@ import {
62
62
  forkConversationFn,
63
63
  } from '@/server/serverFns/chat/conversations'
64
64
  import { forkHarnessThreadFn } from '@/server/serverFns/harness/fork-thread'
65
+ import { setSandboxPolicyFn } from '@/server/serverFns/harness/sandbox-policy'
65
66
  import { isHarnessClientEnabled } from '@/lib/harness-gate'
66
67
  import { agentsQueryOptions } from '@/lib/queries/agents'
67
68
  import { useSelectedModel } from '@/lib/ai/use-selected-model'
@@ -334,6 +335,25 @@ export function WorkbenchProvider({
334
335
  const [mediaRoute, setMediaRoute] = useState<'code' | 'spec'>('code')
335
336
  const [busyPreference, setBusyPreference] = useState<BusyAction>('queue')
336
337
  const [sandboxPolicy, setSandboxPolicy] = useState<'readonly' | 'workspace-write' | 'full'>('readonly')
338
+
339
+ // 档位变更真施加(原 body.setSandboxPolicy 是裸 useState setter——T2.4 的
340
+ // setSandboxPolicyFn 零 UI 调用方,切档只改客户端状态,服务端 sandboxPolicy
341
+ // 永远 readonly → syncHarnessPermissionMode 恒施加 plan,写操作全被拒,真机
342
+ // 验收发现)。有活动线程时调服务端档位(内部同步施加 harness mode);空态
343
+ // 仅客户端状态(线程创建后由 create 流程补施加)。
344
+ const handleSandboxPolicyChange = useCallback(
345
+ (v: 'readonly' | 'workspace-write' | 'full') => {
346
+ setSandboxPolicy(v)
347
+ const threadId = activeIdRef.current
348
+ if (!threadId) return
349
+ void setSandboxPolicyFn({ data: { threadId, level: v, confirmFull: v === 'full' } }).catch(
350
+ (e: unknown) => {
351
+ console.error('[harness] 档位变更施加失败:', e)
352
+ },
353
+ )
354
+ },
355
+ [],
356
+ )
337
357
  const [handoffContext, setHandoffContext] = useState<{ board: string; entityId: string } | null>(null)
338
358
  // 会话区域根元素(中心区根 div):Esc Esc 停止序列的监听目标(F3,composer 冒泡消费)
339
359
  const [retryCount, setRetryCount] = useState(0)
@@ -817,6 +837,15 @@ export function WorkbenchProvider({
817
837
  setActiveConversationId(conv.id)
818
838
  activeIdRef.current = conv.id
819
839
  clearHarnessCitations()
840
+ // 新线程 DB 默认 readonly;composer 选了非只读档时补施加
841
+ // (否则首回合 sync 按 DB readonly 施加 plan,写请求全拒)
842
+ if (sandboxPolicy !== 'readonly') {
843
+ void setSandboxPolicyFn({ data: { threadId: conv.id, level: sandboxPolicy, confirmFull: sandboxPolicy === 'full' } }).catch(
844
+ (e: unknown) => {
845
+ console.error('[harness] 新线程档位施加失败:', e)
846
+ },
847
+ )
848
+ }
820
849
  setPendingSend({ threadId: conv.id, content, sendOptions })
821
850
  } catch (e) {
822
851
  console.error('Failed to create conversation:', e)
@@ -828,7 +857,7 @@ export function WorkbenchProvider({
828
857
  }
829
858
  chatRef.current?.sendMessage(content, sendOptions)
830
859
  },
831
- [selectedAgentId, engine, localCwd],
860
+ [selectedAgentId, engine, localCwd, sandboxPolicy],
832
861
  )
833
862
 
834
863
  const handleStop = useCallback(() => {
@@ -871,7 +900,7 @@ export function WorkbenchProvider({
871
900
  codeModeEnabled,
872
901
  setCodeModeEnabled,
873
902
  sandboxPolicy,
874
- setSandboxPolicy,
903
+ setSandboxPolicy: handleSandboxPolicyChange,
875
904
  busyPreference,
876
905
  setBusyPreference,
877
906
  dockOpen,
@@ -112,7 +112,7 @@ export const SDK_GROUPS: SdkGroup[] = [
112
112
  "items": [
113
113
  {
114
114
  "name": "@allbluecn/web-app",
115
- "version": "v0.27.29",
115
+ "version": "v0.27.30",
116
116
  "lastUpdate": "Nov 10, 2026",
117
117
  "source": "apps/web/package.json",
118
118
  "docsUrl": "https://github.com/allbluecn/allblue"