Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/en/wework/developer-guide/wework-e2e-automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ CODEX_BIN=/absolute/path/to/codex pnpm --filter wework e2e:desktop

Optional `WEWORK_E2E_EXECUTOR_BIN` and `WEWORK_E2E_APP_BIN` reuse already-built real Executor and Electron application binaries. A supplied application must be built with the desktop E2E Vite environment variables. The lifecycle scenarios share one application launch to control CI duration. Test artifacts, captured model requests, and failure diagnostics are stored in `wework/test-results/desktop-e2e/`.

Before launching Electron, desktop E2E removes inherited task, IPC, Node, and Harness runtime variables so a development Wework or Codex session cannot leak personal runtime paths into the test application. To select a Core DSH runtime explicitly for focused diagnosis, set `WEWORK_E2E_HARNESS_RUNTIME_ROOT`; the runner validates that directory and passes it to the test application as `WEWORK_HARNESS_RUNTIME_ROOT`. Do not pass `WEWORK_HARNESS_RUNTIME_ROOT` directly to the test command.

On macOS, desktop E2E launches a temporary `.app` bundle in the background through `open -g`. The test-only `WEWORK_E2E_BACKGROUND_WINDOW=1` setting keeps the Electron main window hidden, prohibits application activation, and hides its Dock icon. Background throttling is disabled for the hidden WebView, so DOM control, timers, and snapshots continue to work. After the controller connects, the runner also asserts that the test application is not the current foreground process, preventing focus-stealing regressions. Only the desktop E2E runner injects this variable; normal development and production launches are unchanged.

The cloud-project scenario starts a real Backend, Redis, and a real Executor registered as a remote device. It exercises real authentication, device RPC, task persistence, and project deletion while covering project creation, task execution, conversation restoration, follow-up, and project removal. The scenario also verifies all three model protocols through the Backend proxy for cloud Model CRDs, plus local-executor use of Codex and cloud models under the same connected account. Only provider model endpoints are simulated; Backend HTTP and WebSocket APIs must not be mocked. To shorten cold startup, the Executor build runs in parallel with Backend, Redis, and database preparation, while remote Executor registration runs in parallel with the Electron application build. Application startup still waits for both prerequisite groups to finish. Project cleanup must wait until the task is no longer running; rendered assistant text does not mean the final task state has been persisted. Python 3.11, `uv`, and `redis-server` are required to run this scenario.
Expand Down
2 changes: 2 additions & 0 deletions docs/zh/wework/developer-guide/wework-e2e-automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ CODEX_BIN=/absolute/path/to/codex pnpm --filter wework e2e:desktop

可选的 `WEWORK_E2E_EXECUTOR_BIN` 和 `WEWORK_E2E_APP_BIN` 分别允许复用已经构建的真实 Executor 和真实 Electron 应用。传入的应用必须使用桌面 E2E 的 Vite 环境变量构建。各生命周期场景复用一次应用启动以控制 CI 时长;测试过程、捕获的模型请求和失败诊断会保存在 `wework/test-results/desktop-e2e/`。

桌面 E2E 启动 Electron 前会移除父进程中的任务、IPC、Node 和 Harness runtime 环境变量,避免从开发中的 Wework 或 Codex 会话继承个人运行时路径。需要为聚焦排查显式指定 Core DSH runtime 时,使用 `WEWORK_E2E_HARNESS_RUNTIME_ROOT`;runner 会校验该目录并将其作为测试应用的 `WEWORK_HARNESS_RUNTIME_ROOT`。不要直接向测试命令传递 `WEWORK_HARNESS_RUNTIME_ROOT`。

在 macOS 上,桌面 E2E 会通过临时 `.app` bundle 和 `open -g` 在后台启动。测试专用的 `WEWORK_E2E_BACKGROUND_WINDOW=1` 会让 Electron 保持主窗口隐藏、禁止应用激活并隐藏 Dock 图标;隐藏 WebView 会关闭后台节流,因此 DOM 控制、计时器和截图仍正常工作。runner 在连接控制器后还会断言测试应用不是当前前台进程,防止窗口抢焦点行为回归。该环境变量只由桌面 E2E runner 注入,不改变正常开发或生产启动行为。

云端项目场景会启动真实 Backend、Redis 和一个注册为远端设备的真实 Executor,通过真实鉴权、设备 RPC、任务持久化和项目删除接口完成创建项目、执行任务、恢复会话、连续追问与删除项目验证。场景同时验证云端 Model CRD 经 backend 代理转发三种模型协议,以及同一云端账号下的 Codex/云端模型在本机 executor 中执行。测试只模拟 provider 模型端点;不得模拟 Backend HTTP 或 WebSocket 接口。为缩短冷启动时间,Executor 构建与 Backend/Redis/数据库准备并行,远端 Executor 注册与 Electron 应用构建并行;应用启动前仍必须同时等待两组前置任务完成。清理项目之前必须等待任务的运行状态结束;助手文本已经渲染并不代表任务状态已经完成持久化。运行该场景需要 Python 3.11、`uv` 和 `redis-server`。
Expand Down
1 change: 1 addition & 0 deletions wework/e2e/desktop/modules/desktop-build-flows.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ async function cloneMacElectronApp(binaryPath, appIdentifier, codexBinary) {
`Set :CFBundleIdentifier ${appIdentifier}`,
join(appBundlePath, 'Contents', 'Info.plist'),
])
await runChecked('codesign', ['--force', '--deep', '--sign', '-', appBundlePath])
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
commandOutput(MACOS_LAUNCH_SERVICES_REGISTER, ['-f', appBundlePath])
return {
Expand Down
42 changes: 28 additions & 14 deletions wework/e2e/desktop/modules/task-flow-main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,11 +1084,11 @@ async function main() {
const harnessRuntimes = needsPackagedHarnessRuntime
? await prepareHarnessRuntimeRoots(appBinary)
: null
const configuredElectronCoreRuntimeRoot =
process.env.WEWORK_E2E_HARNESS_RUNTIME_ROOT?.trim() || null
const electronCoreRuntimeRoot =
harnessRuntimes?.harnessRuntimeRoot ||
(usesReleasePackageRuntimeAssets
? null
: process.env.WEWORK_HARNESS_RUNTIME_ROOT?.trim() || null)
(usesReleasePackageRuntimeAssets ? null : configuredElectronCoreRuntimeRoot)
if (electronCoreRuntimeRoot) {
assert.equal(
await pathExists(electronCoreRuntimeRoot),
Expand Down Expand Up @@ -1137,16 +1137,9 @@ async function main() {
WEWORK_DESKTOP_RUNTIME: 'electron',
WEWORK_EXECUTOR_PATH: executorBinary,
WEWORK_USER_DATA_DIR: electronUserDataDirectory,
...(electronCoreRuntimeRoot ? { WEWORK_HARNESS_RUNTIME_ROOT: electronCoreRuntimeRoot } : {}),
...(RUNS_PLUGIN_E2E && shouldRunPluginSegment('core-dsh-ui-plugin-composition')
? { WEWORK_E2E_EMPTY_CORE_DSH_UI_PROFILE: '1' }
: {}),
...(harnessRuntimes
? {
WEWORK_HARNESS_RUNTIME_ROOT: harnessRuntimes.harnessRuntimeRoot,
}
: {}),
...(desktopScenario?.appEnvironment ?? {}),
...(RUNS_PLUGIN_E2E
? {
GIT_CONFIG_COUNT: '1',
Expand All @@ -1156,11 +1149,32 @@ async function main() {
}
: {}),
}
if (usesReleasePackageRuntimeAssets) {
delete appEnvironment.WEWORK_HARNESS_RUNTIME_ROOT
delete appEnvironment.WEWORK_NODE_PATH
for (const key of [
'ELECTRON_RUN_AS_NODE',
'WEGENT_APP_IPC_DEVICE_ID',
'WEGENT_APP_IPC_ENDPOINT',
'WEGENT_APP_IPC_OWNER_TOKEN',
'WEGENT_APP_IPC_TOKEN',
'WEGENT_APP_LIFECYCLE_FD',
'WEGENT_EXECUTOR_BINARY',
'WEGENT_RUNTIME_AUTH_TOKEN',
'WEGENT_TASK_ID',
'WEGENT_TASK_WORKSPACE',
'WEWORK_CORE_DSH_COMMAND',
'WEWORK_CORE_DSH_URL',
'WEWORK_CORE_PLUGIN_ROOT',
'WEWORK_HARNESS_RESOURCE_ROOT',
'WEWORK_HARNESS_RUNTIME_ROOT',
'WEWORK_NODE_BIN',
'WEWORK_NODE_PATH',
'WEWORK_NODE_RUNTIME_ROOT',
]) {
delete appEnvironment[key]
}
if (electronCoreRuntimeRoot) {
appEnvironment.WEWORK_HARNESS_RUNTIME_ROOT = electronCoreRuntimeRoot
}
delete appEnvironment.WEGENT_APP_IPC_DEVICE_ID
Object.assign(appEnvironment, desktopScenario?.appEnvironment ?? {})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const electronLaunchArguments =
process.platform === 'linux' && typeof process.getuid === 'function' && process.getuid() === 0
? (() => {
Expand Down
64 changes: 63 additions & 1 deletion wework/e2e/desktop/scenarios/split-workbench.scenario.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,73 @@ export function createDesktopScenario({ captureScreenshot, uiTimeoutMs, workspac
await control.command('waitFor', COMPOSER, { timeoutMs: uiTimeoutMs })
await verifyMultilineComposerCaret(control, captureScreenshot)
const firstTaskRow = await createTask(control, FIRST_PROMPT, taskTimeoutMs)
const firstTaskId = firstTaskRow.replace('runtime-local-task-row-', '')
const completedTaskSnapshot = await waitForWorkbenchDebugState(
control,
snapshot =>
snapshot.workbench?.currentRuntimeTask?.taskId === firstTaskId &&
snapshot.workbench?.isBootstrapping === false,
'The completed task did not expose its runtime address',
uiTimeoutMs
)
const firstTaskDeviceId = completedTaskSnapshot.workbench.currentRuntimeTask.deviceId

await control.command('click', '[data-testid="new-chat-button"]')
await control.command('waitFor', COMPOSER, { stableMs: 500, timeoutMs: uiTimeoutMs })
const restoredPaneId = 'pane-e2e-completed-task'
const restoredPaneKey = `runtime:${firstTaskDeviceId}:${firstTaskId}`
const restoredSplitState = JSON.stringify({
version: 3,
state: {
version: 3,
groups: [],
activeView: {
type: 'single',
layout: {
version: 2,
root: {
id: restoredPaneId,
type: 'pane',
paneKey: restoredPaneKey,
},
focusedPaneId: restoredPaneId,
},
},
},
})
assert.equal(
await control.command('setLocalStorageItem', 'body', {
value: JSON.stringify({
key: 'wework:workbench-split-groups:v3:fixed-task',
value: restoredSplitState,
}),
}),
restoredSplitState,
'The completed task pane state could not be persisted before reload'
)

const readyCountBeforeCompletedTaskReload = control.readyCount
await control.command('reloadMainWindow', 'body')
await control.awaitReadyAfter(readyCountBeforeCompletedTaskReload)
await waitForWorkbenchDebugState(
control,
snapshot =>
snapshot.workbench?.isBootstrapping === false &&
Number(snapshot.workbench?.runtimeWorkSummary?.totalTasks ?? 0) >= 1,
'Reloading did not finish hydrating the completed task',
uiTimeoutMs
)
await assertPaneConversation(control, PANE_SELECTOR, `${FIRST_PROMPT}_COMPLETE`)
assert.equal(
Number(await control.command('getElementCount', COMPOSER)),
0,
'The startup blank pane replaced the persisted completed task'
)
await captureScreenshot(control, '00a-completed-task-restored-from-blank-startup.png', 'body')

await control.command('click', '[data-testid="new-chat-button"]')
await control.command('waitFor', COMPOSER, { stableMs: 500 })
const secondTaskRow = await createTask(control, SECOND_PROMPT, taskTimeoutMs)
const firstTaskId = firstTaskRow.replace('runtime-local-task-row-', '')
const secondTaskId = secondTaskRow.replace('runtime-local-task-row-', '')

await expandProject(control, uiTimeoutMs)
Expand Down
17 changes: 13 additions & 4 deletions wework/src/components/layout/DesktopWorkbenchLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ export function DesktopWorkbenchLayout({
[state.currentProject, state.currentRuntimeTask, state.standaloneChatKey]
)
const activePaneKey = getWorkbenchPaneKey(activePane)
const blankPaneKey = getWorkbenchPaneKey({
currentRuntimeTask: null,
currentProject: null,
standaloneChatKey: state.standaloneChatKey,
})
const runtimePaneKeys = useMemo(
() => getRuntimeWorkbenchPaneKeys(state.runtimeWork),
[state.runtimeWork]
Expand Down Expand Up @@ -365,25 +370,29 @@ export function DesktopWorkbenchLayout({
const taskReminders = runtimeTaskReminders ?? EMPTY_RUNTIME_TASK_REMINDERS
const startNewChatOutsideHarness = useCallback(() => {
setActiveLocalHarnessSessionId(null)
activateSplitPane(blankPaneKey)
onNewChat()
}, [onNewChat])
}, [activateSplitPane, blankPaneKey, onNewChat])
const startStandaloneChatOutsideHarness = useCallback(() => {
setActiveLocalHarnessSessionId(null)
activateSplitPane(blankPaneKey)
onStartStandaloneChat()
}, [onStartStandaloneChat])
}, [activateSplitPane, blankPaneKey, onStartStandaloneChat])
const selectProjectOutsideHarness = useCallback(
(projectId: number) => {
setActiveLocalHarnessSessionId(null)
activateSplitPane(blankPaneKey)
onSelectProject(projectId)
},
[onSelectProject]
[activateSplitPane, blankPaneKey, onSelectProject]
)
const startNewProjectChatOutsideHarness = useCallback(
(projectId: number) => {
setActiveLocalHarnessSessionId(null)
activateSplitPane(blankPaneKey)
onStartNewProjectChat(projectId)
},
[onStartNewProjectChat]
[activateSplitPane, blankPaneKey, onStartNewProjectChat]
)
const openRuntimeTaskOutsideHarness = useCallback(
async (address: RuntimeTaskAddress) => {
Expand Down
138 changes: 138 additions & 0 deletions wework/src/components/layout/useWorkbenchSplitGroups.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import { act, renderHook, waitFor } from '@testing-library/react'
import { beforeEach, describe, expect, it } from 'vitest'
import {
createWorkbenchSplitGroupsState,
getActiveWorkbenchLayout,
serializeWorkbenchSplitGroups,
} from './workbenchSplitGroups'
import { collectWorkbenchPaneKeys } from './workbenchSplitLayout'
import { useWorkbenchSplitGroups } from './useWorkbenchSplitGroups'

const storageKey = 'workbench-split-groups-test'
const legacyStorageKey = 'workbench-split-layout-test'
const restoredRuntimePaneKey = 'runtime:device:finished-task'

function activePaneKeys(state: ReturnType<typeof useWorkbenchSplitGroups>['state']) {
return collectWorkbenchPaneKeys(getActiveWorkbenchLayout(state).root)
}

describe('useWorkbenchSplitGroups', () => {
beforeEach(() => {
localStorage.clear()
localStorage.setItem(
storageKey,
serializeWorkbenchSplitGroups(createWorkbenchSplitGroupsState(restoredRuntimePaneKey))
)
})

it('keeps a restored runtime pane while the startup active pane is still blank', async () => {
const { result, rerender } = renderHook(
({ activePaneKey, runtimeKeysReady }) =>
useWorkbenchSplitGroups({
storageKey,
legacyStorageKey,
activePaneKey,
validRuntimeKeys: runtimeKeysReady ? [restoredRuntimePaneKey] : [],
runtimeKeysReady,
}),
{
initialProps: {
activePaneKey: 'blank:0',
runtimeKeysReady: false,
},
}
)

expect(activePaneKeys(result.current.state)).toEqual([restoredRuntimePaneKey])

rerender({
activePaneKey: 'blank:0',
runtimeKeysReady: true,
})

await waitFor(() =>
expect(activePaneKeys(result.current.state)).toEqual([restoredRuntimePaneKey])
)
})

it('replaces a stale persisted blank pane with the current startup blank pane', async () => {
localStorage.setItem(
storageKey,
serializeWorkbenchSplitGroups(createWorkbenchSplitGroupsState('blank:1'))
)

const { result } = renderHook(() =>
useWorkbenchSplitGroups({
storageKey,
legacyStorageKey,
activePaneKey: 'blank:2',
validRuntimeKeys: [restoredRuntimePaneKey],
runtimeKeysReady: true,
})
)

await waitFor(() => expect(activePaneKeys(result.current.state)).toEqual(['blank:2']))
})

it('activates an initial runtime pane over a different persisted runtime pane', async () => {
const currentRuntimePaneKey = 'runtime:device:current-task'

const { result } = renderHook(() =>
useWorkbenchSplitGroups({
storageKey,
legacyStorageKey,
activePaneKey: currentRuntimePaneKey,
validRuntimeKeys: [restoredRuntimePaneKey, currentRuntimePaneKey],
runtimeKeysReady: true,
})
)

await waitFor(() =>
expect(activePaneKeys(result.current.state)).toEqual([currentRuntimePaneKey])
)
})

it('opens the current blank pane after explicit navigation', async () => {
const { result } = renderHook(() =>
useWorkbenchSplitGroups({
storageKey,
legacyStorageKey,
activePaneKey: 'blank:0',
validRuntimeKeys: [restoredRuntimePaneKey],
runtimeKeysReady: true,
})
)

act(() => {
result.current.activatePane('blank:0')
})

await waitFor(() => expect(activePaneKeys(result.current.state)).toEqual(['blank:0']))
})

it('removes a restored runtime pane after the loaded task list proves it is invalid', async () => {
const { result, rerender } = renderHook(
({ runtimeKeysReady }) =>
useWorkbenchSplitGroups({
storageKey,
legacyStorageKey,
activePaneKey: 'blank:0',
validRuntimeKeys: [],
runtimeKeysReady,
}),
{
initialProps: {
runtimeKeysReady: false,
},
}
)

rerender({ runtimeKeysReady: true })

await waitFor(() => expect(activePaneKeys(result.current.state)).toEqual(['blank:0']))

act(() => {
expect(localStorage.getItem(storageKey)).toContain('blank:0')
})
})
})
15 changes: 14 additions & 1 deletion wework/src/components/layout/useWorkbenchSplitGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
updateActiveWorkbenchSplitSizes,
type WorkbenchSplitGroupsState,
} from './workbenchSplitGroups'
import type { WorkbenchSplitDirection } from './workbenchSplitLayout'
import { collectWorkbenchPaneKeys, type WorkbenchSplitDirection } from './workbenchSplitLayout'

interface UseWorkbenchSplitGroupsOptions {
storageKey: string
Expand Down Expand Up @@ -51,6 +51,7 @@ export function useWorkbenchSplitGroups({
)
})
const stateRef = useRef(state)
const previousActivePaneKeyRef = useRef<string | null>(null)
useLayoutEffect(() => {
stateRef.current = state
}, [state])
Expand All @@ -74,6 +75,18 @@ export function useWorkbenchSplitGroups({
}, [state, storageKey])

useEffect(() => {
if (activePaneKey === previousActivePaneKeyRef.current) return
const isInitialActivation = previousActivePaneKeyRef.current === null
previousActivePaneKeyRef.current = activePaneKey
if (
isInitialActivation &&
activePaneKey.startsWith('blank:') &&
collectWorkbenchPaneKeys(getActiveWorkbenchLayout(stateRef.current).root).some(key =>
key.startsWith('runtime:')
)
) {
return
}
commit(current => activateWorkbenchPane(current, activePaneKey))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}, [activePaneKey, commit])

Expand Down
Loading
Loading