mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 11:54:46 +00:00
test: remove low-value messaging simulator and editor suites (#40363)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -6448,7 +6448,6 @@
|
||||
"src/renderer/src/lib/clipboard-image-copy.test.ts": 243,
|
||||
"src/renderer/src/lib/cmd-j-host-qualified-candidate-ownership.test.ts": 526,
|
||||
"src/renderer/src/lib/cmd-j-linear-issue-intent.test.ts": 42,
|
||||
"src/renderer/src/lib/editor/appearance/code-editor-theme.test.ts": 101,
|
||||
"src/renderer/src/lib/code-host-error-copy.test.ts": 297,
|
||||
"src/renderer/src/lib/codex-pane-selection-lane.test.ts": 543,
|
||||
"src/renderer/src/lib/agent-session/accounts/codex/codex-session-restart-shell-flap.test.ts": 1745,
|
||||
@@ -6471,7 +6470,6 @@
|
||||
"src/renderer/src/lib/emulator-error-copy.test.ts": 415,
|
||||
"src/renderer/src/lib/ensure-hooks-confirmed.test.ts": 799,
|
||||
"src/renderer/src/lib/simulator/tabs/ensure-simulator-tab-behavior.test.ts": 3601,
|
||||
"src/renderer/src/lib/editor/file-operations/execute-open-editor-path-move.test.ts": 2458,
|
||||
"src/renderer/src/runtime/hosts/platform/execution-host-facts.test.ts": 1796,
|
||||
"src/renderer/src/lib/feature-education-telemetry.test.ts": 52,
|
||||
"src/renderer/src/lib/feedback-image-attachments.test.ts": 557,
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
import { beforeEach, expect, it, vi } from 'vitest'
|
||||
import { listIssues } from './linear-issue-listing'
|
||||
|
||||
const { getClients, rawRequest } = vi.hoisted(() => ({
|
||||
getClients: vi.fn(),
|
||||
rawRequest: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('./client', () => ({ getClients, isAuthError: () => false }))
|
||||
vi.mock('./linear-token-store', () => ({ clearToken: vi.fn() }))
|
||||
vi.mock('./linear-request-concurrency', () => ({ acquire: vi.fn(), release: vi.fn() }))
|
||||
|
||||
const issue = {
|
||||
id: 'issue-1',
|
||||
identifier: 'ENG-1',
|
||||
title: 'Task',
|
||||
url: 'https://linear.app/acme/issue/ENG-1/task',
|
||||
priority: 0,
|
||||
updatedAt: '2026-11-09T00:00:00.000Z',
|
||||
state: { name: 'In Progress', type: 'started', color: '#f2c94c' },
|
||||
team: { id: 'team-1', name: 'Engineering', key: 'ENG' },
|
||||
project: { id: 'project-1', name: 'Hardware verification', url: null, color: '#f7c8c1' }
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
getClients.mockReturnValue([
|
||||
{
|
||||
workspace: { id: 'workspace-1', organizationName: 'Workspace' },
|
||||
client: { client: { rawRequest } }
|
||||
}
|
||||
])
|
||||
rawRequest.mockResolvedValue({
|
||||
data: { issues: { nodes: [issue], pageInfo: { hasNextPage: false } } }
|
||||
})
|
||||
})
|
||||
|
||||
it('requests and preserves the project on open issue rows', async () => {
|
||||
const result = await listIssues('open', 20, 'workspace-1')
|
||||
|
||||
expect(result.items).toHaveLength(1)
|
||||
expect(result.items[0].project).toStrictEqual({
|
||||
id: 'project-1',
|
||||
name: 'Hardware verification',
|
||||
url: undefined,
|
||||
color: '#f7c8c1'
|
||||
})
|
||||
expect(rawRequest.mock.calls[0][0]).toMatch(/project \{\s*id\s+name\s+url\s+color\s*\}/)
|
||||
})
|
||||
@@ -1,90 +0,0 @@
|
||||
import { beforeEach, expect, it, vi } from 'vitest'
|
||||
import { sendMessageToAgent } from './agent-message-send'
|
||||
|
||||
const mocks = vi.hoisted(() => {
|
||||
const launch: { lifecycle: string | null } = { lifecycle: null }
|
||||
return {
|
||||
send: vi.fn(),
|
||||
relaunch: vi.fn((): Promise<{ delivered: boolean; unconfirmed?: true }> | null => null),
|
||||
launch
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('@/store/index', () => ({
|
||||
useAppStore: {
|
||||
getState: () => ({
|
||||
unifiedTabsByWorktree: {
|
||||
'wt-1': [{ contentType: 'agent-session', entityId: 'session-1' }]
|
||||
}
|
||||
})
|
||||
}
|
||||
}))
|
||||
vi.mock('@/runtime/native-chat/session-ownership/structured-agent-session-owner', () => ({
|
||||
structuredAgentSessionTargetForTab: () => ({ kind: 'local' })
|
||||
}))
|
||||
vi.mock('../launch/structured-agent-session-launch-message', () => ({
|
||||
relaunchFailedStructuredAgentSessionWithMessage: mocks.relaunch
|
||||
}))
|
||||
vi.mock('../launch/structured-agent-session-launch-registry', () => ({
|
||||
getStructuredAgentSessionLaunchLifecycle: () => mocks.launch.lifecycle
|
||||
}))
|
||||
vi.mock('../launch/structured-agent-session-launch-input', () => ({
|
||||
structuredAgentSessionLaunchHasRetainedInput: () => false
|
||||
}))
|
||||
vi.mock('./terminal/active-agent-note-send', () => ({ sendNotesToActiveAgentSession: vi.fn() }))
|
||||
vi.mock(
|
||||
'@/components/native-chat/session/structured/delivery/structured-agent-session-message-sender',
|
||||
() => ({
|
||||
sendStructuredAgentSessionMessage: mocks.send
|
||||
})
|
||||
)
|
||||
|
||||
function sendNotes() {
|
||||
return sendMessageToAgent({
|
||||
worktreeId: 'wt-1',
|
||||
target: { kind: 'structured-session', sessionId: 'session-1' },
|
||||
prompt: 'the notes'
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.send.mockReset()
|
||||
mocks.relaunch.mockClear()
|
||||
mocks.launch.lifecycle = null
|
||||
})
|
||||
|
||||
// Notes clear only when their message is recorded; any other end keeps them with the caller.
|
||||
it.each([
|
||||
['recorded', { status: 'sent' }],
|
||||
['returned', { status: 'not-writable', code: 'session-send-refused' }],
|
||||
// The host may hold it: the notes stay, worded as unconfirmed, never as refused.
|
||||
['unconfirmed', { status: 'unconfirmed', code: 'runtime-unverifiable' }],
|
||||
['dropped', { status: 'not-writable', code: 'session-send-refused' }]
|
||||
] as const)('reports notes whose message was %s', async (outcome, result) => {
|
||||
mocks.send.mockReturnValue({ clientMessageId: 'm', outcome: Promise.resolve(outcome) })
|
||||
await expect(sendNotes()).resolves.toEqual(result)
|
||||
expect(mocks.send).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ sessionId: 'session-1', text: 'the notes', callerKeepsText: true })
|
||||
)
|
||||
})
|
||||
|
||||
it.each(['pending', 'visibility-unknown'])(
|
||||
'keeps the notes while the chat is %s',
|
||||
async (lifecycle) => {
|
||||
mocks.launch.lifecycle = lifecycle
|
||||
await expect(sendNotes()).resolves.toEqual({
|
||||
status: 'not-ready',
|
||||
code: 'session-send-refused'
|
||||
})
|
||||
expect(mocks.send).not.toHaveBeenCalled()
|
||||
}
|
||||
)
|
||||
|
||||
it('says a restart that carried the notes could not be confirmed, never that it refused them', async () => {
|
||||
mocks.launch.lifecycle = 'failed'
|
||||
mocks.relaunch.mockReturnValue(Promise.resolve({ delivered: false, unconfirmed: true }))
|
||||
await expect(sendNotes()).resolves.toEqual({
|
||||
status: 'unconfirmed',
|
||||
code: 'runtime-unverifiable'
|
||||
})
|
||||
})
|
||||
-18
@@ -130,26 +130,8 @@ describe('post-paste submit retry Enter', () => {
|
||||
expect(writes.slice(0, 3)).toEqual([PASTED_ISSUE_URL, '\r', '\r'])
|
||||
expect(writes.at(3)).toBe('\x1b[200~')
|
||||
})
|
||||
|
||||
it('keeps a successful submit successful when the retry Enter is rejected', async () => {
|
||||
testState.sendRuntimePtyInputVerified
|
||||
.mockResolvedValueOnce(true)
|
||||
.mockResolvedValueOnce(true)
|
||||
.mockRejectedValueOnce(new Error('terminal_not_writable'))
|
||||
|
||||
const promise = startCodexSubmit()
|
||||
await signalCodexComposerReady()
|
||||
await vi.advanceTimersByTimeAsync(POST_PASTE_SUBMIT_DELAY_MS + CODEX_SUBMIT_RETRY_DELAY_MS)
|
||||
|
||||
await expect(promise).resolves.toBe(true)
|
||||
expect(enterWrites()).toHaveLength(2)
|
||||
})
|
||||
})
|
||||
|
||||
function enterWrites(): unknown[][] {
|
||||
return testState.sendRuntimePtyInputVerified.mock.calls.filter((call) => call[1] === '\r')
|
||||
}
|
||||
|
||||
function startCodexSubmit(): Promise<boolean> {
|
||||
return pasteDraftWhenAgentReady({
|
||||
tabId: 'tab-1',
|
||||
|
||||
-150
@@ -1,150 +0,0 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { sendNotesToActiveAgentSession } from './active-agent-note-send'
|
||||
import {
|
||||
createNoteSendAppState,
|
||||
OTHER_LEAF_ID,
|
||||
type NoteSendAppState
|
||||
} from './active-agent-note-send-test-harness'
|
||||
|
||||
const testState = vi.hoisted(() => ({
|
||||
appState: null as unknown as NoteSendAppState,
|
||||
callRuntimeRpc: vi.fn(),
|
||||
RuntimeRpcCallError: class RuntimeRpcCallError extends Error {
|
||||
readonly code: string
|
||||
readonly response: unknown
|
||||
|
||||
constructor(response: { error: { code: string; message: string } }) {
|
||||
super(response.error.message)
|
||||
this.name = 'RuntimeRpcCallError'
|
||||
this.code = response.error.code
|
||||
this.response = response
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
vi.mock('@/store/index', () => ({
|
||||
useAppStore: Object.assign(
|
||||
(selector: (state: NoteSendAppState) => unknown) => selector(testState.appState),
|
||||
{
|
||||
getState: () => testState.appState
|
||||
}
|
||||
)
|
||||
}))
|
||||
|
||||
vi.mock('@/runtime/rpc/calls/runtime-rpc-call', () => ({
|
||||
callRuntimeRpc: testState.callRuntimeRpc
|
||||
}))
|
||||
vi.mock('@/runtime/rpc/calls/runtime-rpc-result', () => ({
|
||||
RuntimeRpcCallError: testState.RuntimeRpcCallError
|
||||
}))
|
||||
|
||||
describe('active agent note send', () => {
|
||||
beforeEach(() => {
|
||||
testState.appState = createNoteSendAppState()
|
||||
testState.callRuntimeRpc.mockReset()
|
||||
})
|
||||
|
||||
it('refuses explicit targets when an older runtime cannot verify agent status', async () => {
|
||||
const methods: string[] = []
|
||||
testState.callRuntimeRpc.mockImplementation(async (_target, method) => {
|
||||
methods.push(method)
|
||||
if (method === 'terminal.list') {
|
||||
return {
|
||||
terminals: [
|
||||
{
|
||||
handle: 'term-2',
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/repo',
|
||||
branch: 'main',
|
||||
tabId: 'tab-9',
|
||||
leafId: OTHER_LEAF_ID,
|
||||
title: 'Codex',
|
||||
connected: true,
|
||||
writable: true,
|
||||
lastOutputAt: 1,
|
||||
preview: ''
|
||||
}
|
||||
],
|
||||
totalCount: 1,
|
||||
truncated: false
|
||||
}
|
||||
}
|
||||
if (method === 'terminal.agentStatus') {
|
||||
throw new testState.RuntimeRpcCallError({
|
||||
error: { code: 'method_not_found', message: 'Unknown method: terminal.agentStatus' }
|
||||
})
|
||||
}
|
||||
throw new Error(`unexpected method ${method}`)
|
||||
})
|
||||
|
||||
await expect(
|
||||
sendNotesToActiveAgentSession({
|
||||
worktreeId: 'wt-1',
|
||||
prompt: 'notes',
|
||||
noteTarget: { tabId: 'tab-9', leafId: OTHER_LEAF_ID }
|
||||
})
|
||||
).resolves.toEqual({ status: 'status-unavailable', code: 'status-unavailable' })
|
||||
|
||||
expect(methods).toEqual(['terminal.list', 'terminal.agentStatus'])
|
||||
expect(testState.callRuntimeRpc).not.toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
'terminal.send',
|
||||
expect.anything(),
|
||||
expect.anything()
|
||||
)
|
||||
})
|
||||
|
||||
it('maps explicit target permission or unavailable state before Enter to partial-submit-failed', async () => {
|
||||
let statusChecks = 0
|
||||
testState.callRuntimeRpc.mockImplementation(async (_target, method, params) => {
|
||||
if (method === 'terminal.list') {
|
||||
return {
|
||||
terminals: [
|
||||
{
|
||||
handle: 'term-2',
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/repo',
|
||||
branch: 'main',
|
||||
tabId: 'tab-9',
|
||||
leafId: OTHER_LEAF_ID,
|
||||
title: 'Codex',
|
||||
connected: true,
|
||||
writable: true,
|
||||
lastOutputAt: 1,
|
||||
preview: ''
|
||||
}
|
||||
],
|
||||
totalCount: 1,
|
||||
truncated: false
|
||||
}
|
||||
}
|
||||
if (method === 'terminal.agentStatus') {
|
||||
statusChecks += 1
|
||||
return {
|
||||
agentStatus: {
|
||||
handle: 'term-2',
|
||||
isRunningAgent: true,
|
||||
status: statusChecks === 1 ? 'working' : 'permission'
|
||||
}
|
||||
}
|
||||
}
|
||||
if (method === 'terminal.send') {
|
||||
return { send: { handle: 'term-2', accepted: true, bytesWritten: params.text.length } }
|
||||
}
|
||||
throw new Error(`unexpected method ${method}`)
|
||||
})
|
||||
|
||||
await expect(
|
||||
sendNotesToActiveAgentSession({
|
||||
worktreeId: 'wt-1',
|
||||
prompt: 'notes',
|
||||
noteTarget: { tabId: 'tab-9', leafId: OTHER_LEAF_ID }
|
||||
})
|
||||
).resolves.toEqual({ status: 'partial-submit-failed', code: 'submit-readiness-lost' })
|
||||
|
||||
const sendCalls = testState.callRuntimeRpc.mock.calls.filter(
|
||||
(call) => call[1] === 'terminal.send'
|
||||
)
|
||||
expect(sendCalls).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
-183
@@ -1,183 +0,0 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { sendNotesToActiveAgentSession } from './active-agent-note-send'
|
||||
import {
|
||||
createNoteSendAppState,
|
||||
LEAF_ID,
|
||||
type NoteSendAppState
|
||||
} from './active-agent-note-send-test-harness'
|
||||
|
||||
const testState = vi.hoisted(() => ({
|
||||
appState: null as unknown as NoteSendAppState,
|
||||
callRuntimeRpc: vi.fn(),
|
||||
RuntimeRpcCallError: class RuntimeRpcCallError extends Error {
|
||||
readonly code: string
|
||||
readonly response: unknown
|
||||
|
||||
constructor(response: { error: { code: string; message: string } }) {
|
||||
super(response.error.message)
|
||||
this.name = 'RuntimeRpcCallError'
|
||||
this.code = response.error.code
|
||||
this.response = response
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
vi.mock('@/store/index', () => ({
|
||||
useAppStore: Object.assign(
|
||||
(selector: (state: NoteSendAppState) => unknown) => selector(testState.appState),
|
||||
{
|
||||
getState: () => testState.appState
|
||||
}
|
||||
)
|
||||
}))
|
||||
|
||||
vi.mock('@/runtime/rpc/calls/runtime-rpc-call', () => ({
|
||||
callRuntimeRpc: testState.callRuntimeRpc
|
||||
}))
|
||||
vi.mock('@/runtime/rpc/calls/runtime-rpc-result', () => ({
|
||||
RuntimeRpcCallError: testState.RuntimeRpcCallError
|
||||
}))
|
||||
|
||||
describe('active agent note send', () => {
|
||||
beforeEach(() => {
|
||||
testState.appState = createNoteSendAppState()
|
||||
testState.callRuntimeRpc.mockReset()
|
||||
})
|
||||
|
||||
it('keeps active-focused sends compatible when an older runtime lacks agentStatus', async () => {
|
||||
const methods: string[] = []
|
||||
testState.callRuntimeRpc.mockImplementation(async (_target, method, params) => {
|
||||
methods.push(method)
|
||||
if (method === 'terminal.list') {
|
||||
return {
|
||||
terminals: [
|
||||
{
|
||||
handle: 'term-1',
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/repo',
|
||||
branch: 'main',
|
||||
tabId: 'tab-1',
|
||||
leafId: LEAF_ID,
|
||||
title: 'Codex',
|
||||
connected: true,
|
||||
writable: true,
|
||||
lastOutputAt: 1,
|
||||
preview: ''
|
||||
}
|
||||
],
|
||||
totalCount: 1,
|
||||
truncated: false
|
||||
}
|
||||
}
|
||||
if (method === 'terminal.agentStatus') {
|
||||
throw new testState.RuntimeRpcCallError({
|
||||
error: { code: 'method_not_found', message: 'Unknown method: terminal.agentStatus' }
|
||||
})
|
||||
}
|
||||
if (method === 'terminal.isRunningAgent') {
|
||||
return { isRunningAgent: true }
|
||||
}
|
||||
if (method === 'terminal.wait') {
|
||||
return {
|
||||
wait: {
|
||||
handle: 'term-1',
|
||||
condition: 'tui-idle',
|
||||
satisfied: true,
|
||||
status: 'running',
|
||||
exitCode: null
|
||||
}
|
||||
}
|
||||
}
|
||||
if (method === 'terminal.send') {
|
||||
return { send: { handle: 'term-1', accepted: true, bytesWritten: params.text.length } }
|
||||
}
|
||||
throw new Error(`unexpected method ${method}`)
|
||||
})
|
||||
|
||||
await expect(
|
||||
sendNotesToActiveAgentSession({ worktreeId: 'wt-1', prompt: 'File: src/app.ts' })
|
||||
).resolves.toEqual({ status: 'sent' })
|
||||
|
||||
expect(methods).toEqual([
|
||||
'terminal.list',
|
||||
'terminal.agentStatus',
|
||||
'terminal.isRunningAgent',
|
||||
'terminal.wait',
|
||||
'terminal.agentStatus',
|
||||
'terminal.isRunningAgent',
|
||||
'terminal.send'
|
||||
])
|
||||
expect(testState.callRuntimeRpc).toHaveBeenLastCalledWith(
|
||||
{ kind: 'local' },
|
||||
'terminal.send',
|
||||
{
|
||||
terminal: 'term-1',
|
||||
text: 'File: src/app.ts',
|
||||
enter: true,
|
||||
client: { id: 'orca-desktop', type: 'desktop' }
|
||||
},
|
||||
{ timeoutMs: 15000 }
|
||||
)
|
||||
})
|
||||
|
||||
it('rechecks active-focused permission after idle wait succeeds before writing', async () => {
|
||||
let statusChecks = 0
|
||||
testState.callRuntimeRpc.mockImplementation(async (_target, method) => {
|
||||
if (method === 'terminal.list') {
|
||||
return {
|
||||
terminals: [
|
||||
{
|
||||
handle: 'term-1',
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/repo',
|
||||
branch: 'main',
|
||||
tabId: 'tab-1',
|
||||
leafId: LEAF_ID,
|
||||
title: 'Codex',
|
||||
connected: true,
|
||||
writable: true,
|
||||
lastOutputAt: 1,
|
||||
preview: ''
|
||||
}
|
||||
],
|
||||
totalCount: 1,
|
||||
truncated: false
|
||||
}
|
||||
}
|
||||
if (method === 'terminal.agentStatus') {
|
||||
statusChecks += 1
|
||||
return {
|
||||
agentStatus: {
|
||||
handle: 'term-1',
|
||||
isRunningAgent: true,
|
||||
status: statusChecks === 1 ? 'idle' : 'permission'
|
||||
}
|
||||
}
|
||||
}
|
||||
if (method === 'terminal.wait') {
|
||||
return {
|
||||
wait: {
|
||||
handle: 'term-1',
|
||||
condition: 'tui-idle',
|
||||
satisfied: true,
|
||||
status: 'running',
|
||||
exitCode: null
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error(`unexpected method ${method}`)
|
||||
})
|
||||
|
||||
await expect(
|
||||
sendNotesToActiveAgentSession({ worktreeId: 'wt-1', prompt: 'notes' })
|
||||
).resolves.toEqual({ status: 'permission', code: 'agent-permission' })
|
||||
|
||||
expect(statusChecks).toBe(2)
|
||||
expect(testState.callRuntimeRpc).not.toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
'terminal.send',
|
||||
expect.anything(),
|
||||
expect.anything()
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -1,123 +0,0 @@
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { AgentResumeLaunchTargetArgs } from './agent-resume-launch-target'
|
||||
|
||||
function setNavigatorUserAgent(userAgent: string): () => void {
|
||||
const original = Object.getOwnPropertyDescriptor(globalThis, 'navigator')
|
||||
Object.defineProperty(globalThis, 'navigator', {
|
||||
configurable: true,
|
||||
value: {
|
||||
platform: userAgent.includes('Windows') ? 'Win32' : 'MacIntel',
|
||||
userAgent
|
||||
}
|
||||
})
|
||||
return () => {
|
||||
if (original) {
|
||||
Object.defineProperty(globalThis, 'navigator', original)
|
||||
} else {
|
||||
delete (globalThis as { navigator?: Navigator }).navigator
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const LOCAL_WINDOWS_ARGS: AgentResumeLaunchTargetArgs = {
|
||||
projectRuntime: undefined,
|
||||
connectionId: null,
|
||||
executionHostId: 'local',
|
||||
worktreePath: 'C:\\Users\\neil\\orca\\workspaces\\orca\\feature',
|
||||
terminalWindowsShell: null
|
||||
}
|
||||
|
||||
async function resolveWith(
|
||||
overrides: Partial<AgentResumeLaunchTargetArgs>
|
||||
): Promise<{ platform: NodeJS.Platform; shell: string | undefined }> {
|
||||
const { resolveAgentResumeLaunchTarget } = await import('./agent-resume-launch-target')
|
||||
const { platform, shell } = resolveAgentResumeLaunchTarget({
|
||||
...LOCAL_WINDOWS_ARGS,
|
||||
...overrides
|
||||
})
|
||||
return { platform, shell }
|
||||
}
|
||||
|
||||
describe('resolveAgentResumeLaunchTarget on a Windows client', () => {
|
||||
let restoreNavigator = (): void => {}
|
||||
|
||||
beforeAll(() => {
|
||||
vi.resetModules()
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
restoreNavigator = setNavigatorUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64)')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
restoreNavigator()
|
||||
})
|
||||
|
||||
// Why: an older server omits its OS, but its drive-letter workspace path still proves Windows.
|
||||
it('keeps Windows quoting for an older Windows server that does not report its OS', async () => {
|
||||
await expect(
|
||||
resolveWith({ executionHostId: 'runtime:prod-box', worktreePath: 'C:\\srv\\repo' })
|
||||
).resolves.toEqual({ platform: 'win32', shell: undefined })
|
||||
})
|
||||
})
|
||||
|
||||
describe('resolveAgentResumeLaunchTarget off Windows', () => {
|
||||
let restoreNavigator = (): void => {}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
restoreNavigator = setNavigatorUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
restoreNavigator()
|
||||
})
|
||||
|
||||
it('quotes a nested SSH target on a Windows paired server for that target, not the server', async () => {
|
||||
await expect(
|
||||
resolveWith({
|
||||
connectionId: 'ssh-nested',
|
||||
executionHostId: 'runtime:prod-box',
|
||||
worktreePath: '/home/neil/repo',
|
||||
runtimeHostPlatform: 'win32'
|
||||
})
|
||||
).resolves.toEqual({ platform: 'linux', shell: undefined })
|
||||
})
|
||||
})
|
||||
|
||||
// Why: a paired server's nested SSH target runs the command, so its own reported OS decides quoting.
|
||||
describe('resolveSshHostReportedPlatform for a nested SSH target', () => {
|
||||
it('reads the target the server reaches, not the server', async () => {
|
||||
const { resolveSshHostReportedPlatform } = await import('./agent-resume-launch-target')
|
||||
const state = {
|
||||
sshConnectionStates: new Map(),
|
||||
sshStateByEnvironment: new Map([
|
||||
[
|
||||
'prod-box',
|
||||
{
|
||||
connectionStates: new Map([
|
||||
[
|
||||
'ssh-nested',
|
||||
{
|
||||
targetId: 'ssh-nested',
|
||||
status: 'connected' as const,
|
||||
error: null,
|
||||
reconnectAttempt: 0,
|
||||
remotePlatform: 'win32' as const
|
||||
}
|
||||
]
|
||||
]),
|
||||
targetLabels: new Map(),
|
||||
targetGenerations: new Map(),
|
||||
removedTargetLabels: new Map(),
|
||||
targetsHydrated: true
|
||||
}
|
||||
]
|
||||
])
|
||||
}
|
||||
expect(resolveSshHostReportedPlatform(state, 'runtime:prod-box', null, 'ssh-nested')).toBe(
|
||||
'win32'
|
||||
)
|
||||
expect(resolveSshHostReportedPlatform(state, 'runtime:prod-box', null, null)).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -1,91 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { PluginThemeRegistration } from '../../../../../shared/plugins/artifacts/plugin-theme-artifact'
|
||||
import { resolveCodeEditorTheme } from './code-editor-theme'
|
||||
import type { ColorProbe } from '../../plugin-theme-tokens'
|
||||
|
||||
// Parses #rrggbb, which is all these tests feed it.
|
||||
const probe: ColorProbe = (value) => {
|
||||
const hex = /^#([0-9a-f]{6})$/i.exec(value.trim())?.[1]
|
||||
if (!hex) {
|
||||
return null
|
||||
}
|
||||
const channel = (offset: number): number => Number.parseInt(hex.slice(offset, offset + 2), 16)
|
||||
return [channel(0), channel(2), channel(4), 1]
|
||||
}
|
||||
|
||||
function theme(
|
||||
id: string,
|
||||
base: 'light' | 'dark',
|
||||
tokens: Record<string, string>
|
||||
): PluginThemeRegistration {
|
||||
return {
|
||||
id: `plugin:samples.themes/${id}`,
|
||||
base,
|
||||
tokens,
|
||||
revision: '1',
|
||||
pluginKey: 'samples.themes',
|
||||
pluginName: 'Samples',
|
||||
label: id
|
||||
}
|
||||
}
|
||||
|
||||
const dusk = theme('dusk', 'dark', {
|
||||
'--background': '#1b1430',
|
||||
'--editor-surface': '#120d22',
|
||||
'--foreground': '#e8e0ff',
|
||||
'--muted-foreground': '#b9add6',
|
||||
'--border': '#5b3f9c'
|
||||
})
|
||||
const dawn = theme('dawn', 'light', { '--background': '#fdf6e3', '--foreground': '#3b3226' })
|
||||
const murk = theme('murk', 'dark', { '--background': '#202020', '--foreground': '#303030' })
|
||||
|
||||
function resolve(
|
||||
selected: Parameters<typeof resolveCodeEditorTheme>[0]['selected'],
|
||||
appTheme: PluginThemeRegistration | null = null
|
||||
) {
|
||||
return resolveCodeEditorTheme({
|
||||
dark: false,
|
||||
appTheme,
|
||||
selected,
|
||||
appPainted: appTheme?.tokens ?? {},
|
||||
readDocument: (token) => dawn.tokens[token] ?? '',
|
||||
probe
|
||||
})
|
||||
}
|
||||
|
||||
describe('resolveCodeEditorTheme', () => {
|
||||
it("paints a dark plugin editor in a light app from that theme's own tokens", () => {
|
||||
const result = resolve(dusk, dawn)
|
||||
expect(result.monaco?.data.base).toBe('vs-dark')
|
||||
expect(result.override).toEqual({
|
||||
base: 'dark',
|
||||
colors: {
|
||||
background: '#120d22',
|
||||
foreground: '#e8e0ff',
|
||||
mutedForeground: '#b9add6',
|
||||
border: '#5b3f9c'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it("uses Monaco's built-in colors for a built-in choice or an unreadable theme", () => {
|
||||
expect(resolve('dark')).toMatchObject({ monaco: null, override: { base: 'dark' } })
|
||||
// A built-in light editor still overrides a plugin app theme of the same mode.
|
||||
expect(resolve('light', dawn)).toMatchObject({ monaco: null, override: { base: 'light' } })
|
||||
// An unreadable caret drops to the theme's foreground, as for an app theme.
|
||||
const hidden = resolve(
|
||||
theme('ink', 'dark', {
|
||||
'--background': '#000000',
|
||||
'--editor-surface': '#000000',
|
||||
'--foreground': '#ffffff',
|
||||
'--muted-foreground': '#aaaaaa',
|
||||
'--ring': '#000000'
|
||||
})
|
||||
)
|
||||
expect(hidden.monaco?.data.colors['editorCursor.foreground']).toBe('#ffffff')
|
||||
expect(resolve(murk)).toMatchObject({
|
||||
monaco: null,
|
||||
override: { base: 'dark', colors: { background: '#1e1e1e' } }
|
||||
})
|
||||
})
|
||||
})
|
||||
-230
@@ -1,230 +0,0 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { useAppStore } from '@/store/index'
|
||||
import { resolveEditorModelOwner } from '@/components/editor/model-lifetime/identity/editor-model-owner'
|
||||
import { folderWorkspaceKey } from '../../../../../shared/workspace-scope'
|
||||
import { makeDetectedResult } from '@/store/slices/worktrees/listing/worktrees-detected-listing-fixtures'
|
||||
import { makeFolderWorkspace } from '@/components/sidebar/workspace-creation/folder/folder-workspace-composer-submit-fixtures'
|
||||
import { makeWorktree } from '@/store/slices/worktrees/worktree.test-fixture'
|
||||
import { TEST_REPO } from '@/store/repos/repo.test-fixture'
|
||||
import './editor-file-operation-owner'
|
||||
import {
|
||||
assertEditorFileOperationCurrent,
|
||||
captureEditorFileOperationProvenance
|
||||
} from './editor-file-operation-provenance'
|
||||
|
||||
const worktreeId = 'repo::/remote/repo'
|
||||
|
||||
export function runtimeEnvironment(id: string, pairingRevision: number) {
|
||||
return {
|
||||
id,
|
||||
name: id,
|
||||
createdAt: 1,
|
||||
updatedAt: pairingRevision,
|
||||
pairingRevision,
|
||||
lastUsedAt: null,
|
||||
runtimeId: id,
|
||||
preferredEndpointId: 'endpoint',
|
||||
endpoints: [{ id: 'endpoint', kind: 'websocket' as const, label: id, endpoint: 'ws://host' }]
|
||||
}
|
||||
}
|
||||
|
||||
export function registerEditorOwnerInterpretationContracts(): void {
|
||||
describe('shared editor owner interpretation', () => {
|
||||
it.each([100, 1_000])(
|
||||
'does not walk %i unrelated runtimes on legacy editor triggers',
|
||||
(size) => {
|
||||
let reads = 0
|
||||
const state = {
|
||||
...useAppStore.getState(),
|
||||
repos: [{ ...TEST_REPO, id: 'repo' }],
|
||||
worktreesByRepo: { repo: [makeWorktree({ id: worktreeId, repoId: 'repo' })] },
|
||||
runtimeEnvironments: Array.from({ length: size }, (_, index) => ({
|
||||
...runtimeEnvironment(`unrelated-${index}`, 1),
|
||||
get id() {
|
||||
reads += 1
|
||||
return `unrelated-${index}`
|
||||
}
|
||||
}))
|
||||
}
|
||||
const counts = { capture: 0, assert: 0, model: 0 }
|
||||
const route = { executionHostId: 'local', runtimeEnvironmentId: null }
|
||||
for (let index = 0; index < 20; index += 1) {
|
||||
const provenance = captureEditorFileOperationProvenance(state, worktreeId, null, true)
|
||||
expect(provenance.generation.route).toEqual(route)
|
||||
counts.capture += reads
|
||||
reads = 0
|
||||
expect(assertEditorFileOperationCurrent(state, worktreeId, provenance)).toEqual(route)
|
||||
counts.assert += reads
|
||||
reads = 0
|
||||
expect(resolveEditorModelOwner({ worktreeId }, state)).toEqual({
|
||||
environmentId: null,
|
||||
hostId: 'local'
|
||||
})
|
||||
counts.model += reads
|
||||
reads = 0
|
||||
}
|
||||
expect(counts).toEqual({ capture: 0, assert: 0, model: 0 })
|
||||
const provenance = captureEditorFileOperationProvenance(state, worktreeId, null, true)
|
||||
const removed = { ...state, repos: [], worktreesByRepo: {} }
|
||||
expect(() => assertEditorFileOperationCurrent(removed, worktreeId, provenance)).toThrow(
|
||||
'Reopen the file'
|
||||
)
|
||||
expect(() => captureEditorFileOperationProvenance(removed, worktreeId, null, true)).toThrow(
|
||||
'Reopen the file'
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
it.each([100, 1_000])('skips %i unrelated catalog rows on folder editor triggers', (size) => {
|
||||
const counts = { worktree: 0, detected: 0, repo: 0 }
|
||||
function counted<T extends { id: string }>(row: T, kind: keyof typeof counts): T {
|
||||
return {
|
||||
...row,
|
||||
get id() {
|
||||
counts[kind] += 1
|
||||
return row.id
|
||||
}
|
||||
}
|
||||
}
|
||||
const workspace = folderWorkspaceKey('docs')
|
||||
const base = {
|
||||
...useAppStore.getState(),
|
||||
folderWorkspaces: [makeFolderWorkspace({ id: 'docs', executionHostId: 'local' })],
|
||||
projectGroups: [],
|
||||
restoredRuntimeHostIdByWorkspaceSessionKey: {}
|
||||
}
|
||||
const provenance = captureEditorFileOperationProvenance(base, workspace, undefined, false)
|
||||
for (let generation = 0; generation < 20; generation += 1) {
|
||||
const detected = makeDetectedResult(
|
||||
'unrelated',
|
||||
Array.from({ length: size }, (_, index) =>
|
||||
makeWorktree({ id: `detected-${index}`, repoId: 'unrelated' })
|
||||
)
|
||||
)
|
||||
const state = {
|
||||
...base,
|
||||
worktreesByRepo: {
|
||||
unrelated: Array.from({ length: size }, (_, index) =>
|
||||
counted(makeWorktree({ id: `wt-${index}`, repoId: 'unrelated' }), 'worktree')
|
||||
)
|
||||
},
|
||||
detectedWorktreesByRepo: {
|
||||
unrelated: {
|
||||
...detected,
|
||||
worktrees: detected.worktrees.map((row) => counted(row, 'detected'))
|
||||
}
|
||||
},
|
||||
repos: Array.from({ length: size }, (_, index) =>
|
||||
counted({ ...TEST_REPO, id: `repo-${index}` }, 'repo')
|
||||
)
|
||||
}
|
||||
// Model lookup runs first on cold catalog identities, then all three paths reuse them.
|
||||
for (let repeat = 0; repeat < 2; repeat += 1) {
|
||||
expect(resolveEditorModelOwner({ worktreeId: workspace }, state)).toEqual({
|
||||
environmentId: null,
|
||||
hostId: 'local'
|
||||
})
|
||||
expect(
|
||||
captureEditorFileOperationProvenance(state, workspace, undefined, false).generation
|
||||
.route
|
||||
).toEqual(provenance.generation.route)
|
||||
expect(assertEditorFileOperationCurrent(state, workspace, provenance)).toEqual(
|
||||
provenance.generation.route
|
||||
)
|
||||
}
|
||||
}
|
||||
expect(counts).toEqual({ worktree: 0, detected: 0, repo: 0 })
|
||||
const moved = {
|
||||
...base,
|
||||
folderWorkspaces: [makeFolderWorkspace({ id: 'docs', executionHostId: 'runtime:hub-a' })]
|
||||
}
|
||||
expect(resolveEditorModelOwner({ worktreeId: workspace }, moved)).toEqual({
|
||||
environmentId: 'hub-a',
|
||||
hostId: 'runtime:hub-a'
|
||||
})
|
||||
for (const state of [moved, { ...base, folderWorkspaces: [] }]) {
|
||||
expect(() => assertEditorFileOperationCurrent(state, workspace, provenance)).toThrow(
|
||||
'Reopen the file'
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it.each(['runtime:hub-a', 'ssh:private'] as const)(
|
||||
'keeps uncaptured models and operations on stamped paired owner %s',
|
||||
(hostId) => {
|
||||
vi.stubGlobal('__ORCA_WEB_CLIENT__', true)
|
||||
useAppStore.setState({
|
||||
worktreesByRepo: {
|
||||
repo: [
|
||||
makeWorktree({
|
||||
id: worktreeId,
|
||||
repoId: 'repo',
|
||||
hostId,
|
||||
runtimeOwnerEnvironmentId: 'hub-a'
|
||||
})
|
||||
]
|
||||
}
|
||||
})
|
||||
const state = useAppStore.getState()
|
||||
const provenance = captureEditorFileOperationProvenance(state, worktreeId, undefined, false)
|
||||
const route = assertEditorFileOperationCurrent(state, worktreeId, provenance)
|
||||
expect(resolveEditorModelOwner({ worktreeId }, state)).toEqual({
|
||||
environmentId: route.runtimeEnvironmentId,
|
||||
hostId: route.executionHostId
|
||||
})
|
||||
expect(route).toEqual({ executionHostId: hostId, runtimeEnvironmentId: 'hub-a' })
|
||||
}
|
||||
)
|
||||
|
||||
it('qualifies a same-id folder at capture without letting later focus change model identity', () => {
|
||||
const workspace = folderWorkspaceKey('twin')
|
||||
useAppStore.setState({
|
||||
folderWorkspaces: [
|
||||
makeFolderWorkspace({ id: 'twin', executionHostId: 'local' }),
|
||||
makeFolderWorkspace({ id: 'twin', executionHostId: 'runtime:hub-a' })
|
||||
],
|
||||
activeWorktreeId: workspace,
|
||||
activeWorkspaceExecutionHostId: 'local'
|
||||
})
|
||||
const provenance = captureEditorFileOperationProvenance(
|
||||
useAppStore.getState(),
|
||||
workspace,
|
||||
undefined,
|
||||
false
|
||||
)
|
||||
for (const host of ['local', 'runtime:hub-a'] as const) {
|
||||
useAppStore.setState({ activeWorkspaceExecutionHostId: host })
|
||||
const state = useAppStore.getState()
|
||||
expect(resolveEditorModelOwner({ worktreeId: workspace }, state).hostId).toBeNull()
|
||||
expect(
|
||||
resolveEditorModelOwner({ worktreeId: workspace, operationProvenance: provenance }, state)
|
||||
).toEqual({ environmentId: null, hostId: 'local' })
|
||||
expect(assertEditorFileOperationCurrent(state, workspace, provenance).executionHostId).toBe(
|
||||
'local'
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('retains captured model identity while refusing vanished or ambiguous mutation owners', () => {
|
||||
const owner = makeWorktree({ id: worktreeId, repoId: 'repo', hostId: 'local' })
|
||||
useAppStore.setState({ worktreesByRepo: { repo: [owner] } })
|
||||
const provenance = captureEditorFileOperationProvenance(
|
||||
useAppStore.getState(),
|
||||
worktreeId,
|
||||
undefined,
|
||||
false
|
||||
)
|
||||
for (const worktrees of [[], [owner, { ...owner, hostId: 'runtime:hub-a' as const }]]) {
|
||||
useAppStore.setState({ worktreesByRepo: { repo: worktrees } })
|
||||
const state = useAppStore.getState()
|
||||
expect(() => assertEditorFileOperationCurrent(state, worktreeId, provenance)).toThrow(
|
||||
'Reopen the file'
|
||||
)
|
||||
expect(
|
||||
resolveEditorModelOwner({ worktreeId, operationProvenance: provenance }, state).hostId
|
||||
).toBe('local')
|
||||
expect(resolveEditorModelOwner({ worktreeId }, state).hostId).toBeNull()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,16 +1,8 @@
|
||||
import {
|
||||
registerEditorOwnerInterpretationContracts,
|
||||
runtimeEnvironment
|
||||
} from './editor-file-operation-owner-interpretation.spec'
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
// @vitest-environment happy-dom
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { useAppStore } from '@/store/index'
|
||||
import {
|
||||
assertEditorFileOperationCurrent,
|
||||
captureEditorFileOperationProvenance
|
||||
} from './editor-file-operation-provenance'
|
||||
import { getEditorFileOperationContext } from './editor-file-operation-owner'
|
||||
|
||||
vi.mock('../../../../../shared/layout-owner-switch', () => ({ ORCA_LAYOUT_OWNER_IS_MAIN: true }))
|
||||
@@ -33,108 +25,6 @@ beforeEach(() => {
|
||||
})
|
||||
|
||||
describe('editor file operation owner', () => {
|
||||
it('rejects an open tab after the same environment id is re-paired', () => {
|
||||
useAppStore.getState().setRuntimeEnvironments([runtimeEnvironment('hub-a', 1)])
|
||||
useAppStore.setState({
|
||||
worktreesByRepo: {
|
||||
repo: [
|
||||
{
|
||||
id: worktreeId,
|
||||
repoId: 'repo',
|
||||
path: '/remote/repo',
|
||||
hostId: 'runtime:hub-a',
|
||||
runtimeOwnerEnvironmentId: 'hub-a'
|
||||
} as never
|
||||
]
|
||||
}
|
||||
})
|
||||
const provenance = captureEditorFileOperationProvenance(
|
||||
useAppStore.getState(),
|
||||
worktreeId,
|
||||
undefined,
|
||||
false
|
||||
)
|
||||
|
||||
useAppStore.getState().setRuntimeEnvironments([runtimeEnvironment('hub-a', 2)])
|
||||
|
||||
expect(() =>
|
||||
assertEditorFileOperationCurrent(useAppStore.getState(), worktreeId, provenance)
|
||||
).toThrow('Reopen the file')
|
||||
})
|
||||
|
||||
it('captures and rejects replacement nested SSH connection generations', () => {
|
||||
useAppStore.setState({
|
||||
worktreesByRepo: {
|
||||
repo: [
|
||||
{
|
||||
id: worktreeId,
|
||||
repoId: 'repo',
|
||||
path: '/remote/repo',
|
||||
hostId: 'ssh:private',
|
||||
runtimeOwnerEnvironmentId: 'hub-a'
|
||||
} as never
|
||||
]
|
||||
},
|
||||
sshStateByEnvironment: new Map([
|
||||
[
|
||||
'hub-a',
|
||||
{
|
||||
targetsHydrated: true,
|
||||
targetGenerations: new Map(),
|
||||
targetLabels: new Map([['private', 'private']]),
|
||||
removedTargetLabels: new Map(),
|
||||
connectionStates: new Map([
|
||||
[
|
||||
'private',
|
||||
{
|
||||
targetId: 'private',
|
||||
status: 'connected',
|
||||
error: null,
|
||||
reconnectAttempt: 0,
|
||||
connectionGeneration: 7
|
||||
}
|
||||
]
|
||||
])
|
||||
}
|
||||
]
|
||||
])
|
||||
})
|
||||
const provenance = captureEditorFileOperationProvenance(
|
||||
useAppStore.getState(),
|
||||
worktreeId,
|
||||
undefined,
|
||||
false
|
||||
)
|
||||
expect(provenance.expectedSshConnectionGeneration).toBe(7)
|
||||
|
||||
useAppStore.setState((state) => ({
|
||||
sshStateByEnvironment: new Map([
|
||||
[
|
||||
'hub-a',
|
||||
{
|
||||
...state.sshStateByEnvironment.get('hub-a')!,
|
||||
connectionStates: new Map([
|
||||
[
|
||||
'private',
|
||||
{
|
||||
targetId: 'private',
|
||||
status: 'connected',
|
||||
error: null,
|
||||
reconnectAttempt: 0,
|
||||
connectionGeneration: 8
|
||||
}
|
||||
]
|
||||
])
|
||||
}
|
||||
]
|
||||
])
|
||||
}))
|
||||
|
||||
expect(() =>
|
||||
assertEditorFileOperationCurrent(useAppStore.getState(), worktreeId, provenance)
|
||||
).toThrow('Reopen the file')
|
||||
})
|
||||
|
||||
it('rejects a restored external SSH file after its target changes', () => {
|
||||
useAppStore.setState({
|
||||
repos: [{ id: 'repo', connectionId: 'ssh-replacement' } as never],
|
||||
@@ -163,45 +53,6 @@ describe('editor file operation owner', () => {
|
||||
)
|
||||
).toThrow('Reopen the file')
|
||||
})
|
||||
|
||||
describe('folder workspaces', () => {
|
||||
const folderWorkspaceId = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
|
||||
const folderKey = `folder:${folderWorkspaceId}`
|
||||
|
||||
beforeEach(() => {
|
||||
useAppStore.setState({
|
||||
folderWorkspaces: [
|
||||
{
|
||||
id: folderWorkspaceId,
|
||||
projectGroupId: 'group-1',
|
||||
connectionId: null,
|
||||
folderPath: '/workspace/folder'
|
||||
} as never
|
||||
],
|
||||
projectGroups: [{ id: 'group-1', connectionId: null, executionHostId: null } as never],
|
||||
restoredRuntimeHostIdByWorkspaceSessionKey: {}
|
||||
})
|
||||
})
|
||||
|
||||
it('fails closed when folder ownership changes between capture and assert', () => {
|
||||
const provenance = captureEditorFileOperationProvenance(
|
||||
useAppStore.getState(),
|
||||
folderKey,
|
||||
undefined,
|
||||
false
|
||||
)
|
||||
useAppStore.setState({
|
||||
projectGroups: [
|
||||
{ id: 'group-1', connectionId: null, executionHostId: 'runtime:hub-a' } as never
|
||||
]
|
||||
})
|
||||
expect(() =>
|
||||
assertEditorFileOperationCurrent(useAppStore.getState(), folderKey, provenance)
|
||||
).toThrow('Reopen the file')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
|
||||
registerEditorOwnerInterpretationContracts()
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type * as RuntimeFileMutationClient from '@/runtime/files/mutations/runtime-file-mutation-client'
|
||||
import type * as EditorAutosave from '@/components/editor/autosave/editor-autosave'
|
||||
|
||||
const mocks = vi.hoisted(() => ({ renameRuntimePath: vi.fn() }))
|
||||
vi.mock('@/runtime/files/mutations/runtime-file-mutation-client', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof RuntimeFileMutationClient>()
|
||||
return { ...actual, renameRuntimePath: mocks.renameRuntimePath }
|
||||
})
|
||||
vi.mock('@/runtime/rpc/calls/runtime-rpc-call', async (importOriginal) =>
|
||||
(
|
||||
await import('@/runtime/workspace-layout/testing/layout-apply-test-transport.test-fixture')
|
||||
).runtimeRpcClientWithLayoutApply(await importOriginal())
|
||||
)
|
||||
vi.mock('@/runtime/workspace-layout/frames/runtime-layout-client', async (importOriginal) =>
|
||||
(
|
||||
await import('@/runtime/workspace-layout/testing/layout-apply-test-transport.test-fixture')
|
||||
).runtimeLayoutClientWithTestFrames(await importOriginal())
|
||||
)
|
||||
vi.mock('@/components/editor/autosave/editor-autosave', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof EditorAutosave>()
|
||||
return { ...actual, requestEditorSaveQuiesce: vi.fn().mockResolvedValue(undefined) }
|
||||
})
|
||||
|
||||
import { useAppStore } from '@/store/index'
|
||||
import { executeOpenEditorPathMove } from './execute-open-editor-path-move'
|
||||
|
||||
import { captureWorktreeOperationGenerationSnapshot } from '../../workspace/ownership/worktree-operation-generation'
|
||||
|
||||
import {
|
||||
drawTabsFromMain,
|
||||
type TabsDrawnFromMain
|
||||
} from '@/store/slices/tabs/tabs-drawn-from-main.test-fixture'
|
||||
|
||||
let main: TabsDrawnFromMain
|
||||
|
||||
const CONTEXT = {
|
||||
target: { kind: 'local' as const },
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/repo',
|
||||
connectionId: undefined
|
||||
}
|
||||
|
||||
function openDirtyTab(): string {
|
||||
const state = useAppStore.getState()
|
||||
state.openFile(
|
||||
{
|
||||
filePath: '/repo/a.md',
|
||||
relativePath: 'a.md',
|
||||
worktreeId: 'wt-1',
|
||||
runtimeEnvironmentId: null,
|
||||
language: 'markdown',
|
||||
mode: 'edit'
|
||||
},
|
||||
{ suppressActiveRuntimeFallback: true }
|
||||
)
|
||||
const id = useAppStore.getState().openFiles[0]!.id
|
||||
state.setEditorDraft(id, 'unsaved work')
|
||||
state.markFileDirty(id, true)
|
||||
state.setLastKnownDiskSignature(id, 'sig-a')
|
||||
return id
|
||||
}
|
||||
|
||||
describe('executeOpenEditorPathMove', () => {
|
||||
beforeEach(async () => {
|
||||
useAppStore.setState(useAppStore.getInitialState(), true)
|
||||
mocks.renameRuntimePath.mockReset().mockResolvedValue(undefined)
|
||||
main = await drawTabsFromMain(useAppStore)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
main.close()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
it('never retargets the same path open from a same-id workspace on a server', async () => {
|
||||
const localId = openDirtyTab()
|
||||
const state = useAppStore.getState()
|
||||
state.openFile({
|
||||
filePath: '/repo/a.md',
|
||||
relativePath: 'a.md',
|
||||
worktreeId: 'wt-1',
|
||||
runtimeEnvironmentId: 'env-server',
|
||||
language: 'markdown',
|
||||
mode: 'edit'
|
||||
})
|
||||
const remote = useAppStore
|
||||
.getState()
|
||||
.openFiles.find((file) => file.runtimeEnvironmentId === 'env-server')!
|
||||
state.setEditorDraft(remote.id, 'server draft')
|
||||
state.markFileDirty(remote.id, true)
|
||||
useAppStore.setState((current) => ({
|
||||
openFiles: current.openFiles.map((file) =>
|
||||
file.id === remote.id
|
||||
? {
|
||||
...file,
|
||||
operationProvenance: {
|
||||
ownershipProjection: 'explicit',
|
||||
generation: captureWorktreeOperationGenerationSnapshot(
|
||||
{ runtimeEnvironmentId: 'env-server', executionHostId: 'runtime:env-server' },
|
||||
{ endpoint: { kind: 'environment', environmentId: 'env-server' }, at: 'ssh:box' }
|
||||
)
|
||||
}
|
||||
}
|
||||
: file
|
||||
)
|
||||
}))
|
||||
await executeOpenEditorPathMove({
|
||||
context: {
|
||||
...CONTEXT,
|
||||
target: { kind: 'environment', environmentId: 'env-server' },
|
||||
expectedExecutionHostId: 'ssh:other'
|
||||
},
|
||||
fromPath: '/repo/a.md',
|
||||
toPath: '/repo/other.md',
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/repo'
|
||||
})
|
||||
expect(useAppStore.getState().openFiles.every((file) => file.filePath === '/repo/a.md')).toBe(
|
||||
true
|
||||
)
|
||||
expect(useAppStore.getState().editorDrafts[remote.id]).toBe('server draft')
|
||||
|
||||
await executeOpenEditorPathMove({
|
||||
context: { ...CONTEXT, expectedExecutionHostId: 'local' },
|
||||
fromPath: '/repo/a.md',
|
||||
toPath: '/repo/b.md',
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/repo'
|
||||
})
|
||||
|
||||
const files = useAppStore.getState().openFiles
|
||||
expect(files.find((file) => file.runtimeEnvironmentId !== 'env-server')!.filePath).toBe(
|
||||
'/repo/b.md'
|
||||
)
|
||||
expect(files.find((file) => file.id === remote.id)).toMatchObject({
|
||||
filePath: '/repo/a.md',
|
||||
isDirty: true
|
||||
})
|
||||
expect(useAppStore.getState().editorDrafts[remote.id]).toBe('server draft')
|
||||
expect(useAppStore.getState().editorDrafts[localId]).toBeUndefined()
|
||||
})
|
||||
|
||||
it('still moves its own tab when the workspace host focus changes while the rename runs', async () => {
|
||||
openDirtyTab()
|
||||
mocks.renameRuntimePath.mockImplementation(async () => {
|
||||
useAppStore.setState({
|
||||
activeWorktreeId: 'wt-1',
|
||||
activeWorkspaceExecutionHostId: 'runtime:env-other'
|
||||
})
|
||||
})
|
||||
|
||||
await executeOpenEditorPathMove({
|
||||
context: { ...CONTEXT, expectedExecutionHostId: 'local' },
|
||||
fromPath: '/repo/a.md',
|
||||
toPath: '/repo/b.md',
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/repo'
|
||||
})
|
||||
|
||||
expect(useAppStore.getState().openFiles[0]!.filePath).toBe('/repo/b.md')
|
||||
})
|
||||
|
||||
it('undoes the on-disk rename when the editor rekey collides', async () => {
|
||||
openDirtyTab()
|
||||
useAppStore.getState().openFile(
|
||||
{
|
||||
filePath: '/repo/sub/a.md',
|
||||
relativePath: 'sub/a.md',
|
||||
worktreeId: 'wt-1',
|
||||
runtimeEnvironmentId: null,
|
||||
language: 'markdown',
|
||||
mode: 'edit'
|
||||
},
|
||||
{ suppressActiveRuntimeFallback: true }
|
||||
)
|
||||
const before = useAppStore.getState().openFiles.map((f) => f.id)
|
||||
|
||||
await expect(
|
||||
executeOpenEditorPathMove({
|
||||
context: CONTEXT,
|
||||
fromPath: '/repo/a.md',
|
||||
toPath: '/repo/sub/a.md',
|
||||
worktreeId: 'wt-1',
|
||||
worktreePath: '/repo'
|
||||
})
|
||||
).rejects.toThrow(/retarget/)
|
||||
|
||||
expect(mocks.renameRuntimePath).toHaveBeenCalledWith(
|
||||
CONTEXT,
|
||||
'/repo/a.md',
|
||||
'/repo/sub/a.md',
|
||||
undefined
|
||||
)
|
||||
expect(mocks.renameRuntimePath).toHaveBeenCalledWith(
|
||||
CONTEXT,
|
||||
'/repo/sub/a.md',
|
||||
'/repo/a.md',
|
||||
undefined
|
||||
)
|
||||
expect(useAppStore.getState().openFiles.map((f) => f.id)).toEqual(before)
|
||||
})
|
||||
})
|
||||
-36
@@ -250,40 +250,4 @@ describe('remapOpenEditorTabsForPathChange', () => {
|
||||
|
||||
expect(useAppStore.getState().openFiles[0]!.filePath).toBe('/repo/dst/a\\b.txt')
|
||||
})
|
||||
|
||||
it('carries the disk baseline and live conflict state onto the re-homed tab', async () => {
|
||||
const state = useAppStore.getState()
|
||||
const oldPath = '/repo/notes.md'
|
||||
const newPath = '/repo/archive/notes.md'
|
||||
state.openFile(
|
||||
{
|
||||
filePath: oldPath,
|
||||
relativePath: 'notes.md',
|
||||
worktreeId: 'wt-1',
|
||||
runtimeEnvironmentId: null,
|
||||
language: 'markdown',
|
||||
mode: 'edit'
|
||||
},
|
||||
{ suppressActiveRuntimeFallback: true }
|
||||
)
|
||||
const oldId = useAppStore.getState().openFiles[0]!.id
|
||||
state.setEditorDraft(oldId, 'unsaved work')
|
||||
state.markFileDirty(oldId, true)
|
||||
state.setLastKnownDiskSignature(oldId, 'sig-abc')
|
||||
state.setExternalMutation(oldId, 'changed')
|
||||
|
||||
await remap({
|
||||
fromPath: oldPath,
|
||||
toPath: newPath,
|
||||
worktreePath: '/repo',
|
||||
owner: localMoveOwner(undefined)
|
||||
})
|
||||
|
||||
const moved = useAppStore.getState().openFiles.find((f) => f.filePath === newPath)
|
||||
expect(moved).toBeTruthy()
|
||||
// Preserve move-echo identity and existing conflict so watchers distinguish rename from external writes.
|
||||
expect(moved?.lastKnownDiskSignature).toBe('sig-abc')
|
||||
expect(moved?.externalMutation).toBe('changed')
|
||||
expect(moved?.isDirty).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { EmulatorStreamInfo } from '@/components/emulator-pane/emulator-pane-types'
|
||||
import {
|
||||
consumePrelaunchedSimulatorSession,
|
||||
rememberPrelaunchedSimulatorSession,
|
||||
resetSimulatorLaunchCoordinationForTests
|
||||
} from './simulator-launch-coordination'
|
||||
|
||||
function streamInfo(id: string): EmulatorStreamInfo {
|
||||
return {
|
||||
deviceUdid: id,
|
||||
streamUrl: `http://127.0.0.1:3100/${id}/stream.mjpeg`,
|
||||
wsUrl: `ws://127.0.0.1:3100/${id}/ws`
|
||||
}
|
||||
}
|
||||
|
||||
describe('simulator-launch-coordination', () => {
|
||||
beforeEach(() => {
|
||||
resetSimulatorLaunchCoordinationForTests()
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(1_000)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
resetSimulatorLaunchCoordinationForTests()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('measures handoff age independently of wall-clock corrections', () => {
|
||||
vi.setSystemTime(100_000)
|
||||
rememberPrelaunchedSimulatorSession('wt-rollback', streamInfo('device-rollback'))
|
||||
|
||||
vi.setSystemTime(0)
|
||||
vi.advanceTimersByTime(30_000)
|
||||
|
||||
expect(consumePrelaunchedSimulatorSession('wt-rollback')).toBeNull()
|
||||
|
||||
rememberPrelaunchedSimulatorSession('wt-forward', streamInfo('device-forward'))
|
||||
vi.setSystemTime(1_000_000)
|
||||
|
||||
expect(consumePrelaunchedSimulatorSession('wt-forward')).toMatchObject({
|
||||
deviceUdid: 'device-forward'
|
||||
})
|
||||
})
|
||||
|
||||
it('treats a refreshed worktree key as the most recently remembered', () => {
|
||||
for (let index = 0; index < 16; index += 1) {
|
||||
rememberPrelaunchedSimulatorSession(`wt-${index}`, streamInfo(`device-${index}`))
|
||||
}
|
||||
|
||||
rememberPrelaunchedSimulatorSession('wt-0', streamInfo('device-refreshed'))
|
||||
rememberPrelaunchedSimulatorSession('wt-16', streamInfo('device-16'))
|
||||
|
||||
expect(consumePrelaunchedSimulatorSession('wt-1')).toBeNull()
|
||||
expect(consumePrelaunchedSimulatorSession('wt-0')).toMatchObject({
|
||||
deviceUdid: 'device-refreshed'
|
||||
})
|
||||
expect(consumePrelaunchedSimulatorSession('wt-16')).toMatchObject({
|
||||
deviceUdid: 'device-16'
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -2,16 +2,9 @@ import { describe, expect, it } from 'vitest'
|
||||
import type { Tab } from '../../../../../shared/tab-types'
|
||||
import type { Worktree } from '../../../../../shared/worktree/types'
|
||||
import { getWorktreeHostIdentity } from '../../../../../shared/worktree/host-qualified-identity'
|
||||
import { buildPaletteTabDocument } from '../../../../../shared/palette-match/tab-document'
|
||||
import '../../../../../shared/palette-match/palette-query'
|
||||
|
||||
import {
|
||||
SIMULATOR_PALETTE_QUERY_MAX_BYTES,
|
||||
SIMULATOR_TYPE_SEARCH_ALIASES,
|
||||
buildSearchableSimulatorTabs,
|
||||
searchSimulatorTabs
|
||||
} from './simulator-palette-search'
|
||||
import type { SearchableSimulatorTab } from './simulator-palette-search-types'
|
||||
import { buildSearchableSimulatorTabs, searchSimulatorTabs } from './simulator-palette-search'
|
||||
|
||||
function makeWorktree(overrides: Partial<Worktree> = {}): Worktree {
|
||||
return {
|
||||
@@ -52,8 +45,6 @@ function makeTab(overrides: Partial<Tab> = {}): Tab {
|
||||
}
|
||||
}
|
||||
|
||||
/** Mirrors buildSearchableSimulatorTabs so hand-built rows index the same fields. */
|
||||
|
||||
describe('simulator-palette-search', () => {
|
||||
it('keeps same-id simulator tabs isolated by execution host', () => {
|
||||
const sharedId = 'repo-shared::/workspace'
|
||||
@@ -127,29 +118,4 @@ describe('simulator-palette-search', () => {
|
||||
|
||||
expect(entries).toEqual([])
|
||||
})
|
||||
|
||||
it('rejects oversized pasted queries before scanning simulator tabs', () => {
|
||||
const oversizedQuery = 'secret-simulator-palette'.repeat(SIMULATOR_PALETTE_QUERY_MAX_BYTES)
|
||||
const entry = {
|
||||
get tab(): Tab {
|
||||
throw new Error('oversized simulator palette queries must not scan tabs')
|
||||
},
|
||||
worktree: makeWorktree(),
|
||||
repoName: 'repo/mobile',
|
||||
worktreeSortIndex: 0,
|
||||
isCurrentTab: false,
|
||||
isCurrentWorktree: false,
|
||||
document: buildPaletteTabDocument({
|
||||
id: 'sim-1',
|
||||
title: 'Mobile Emulator',
|
||||
secondaryTexts: [],
|
||||
worktreeName: 'Mobile Worktree',
|
||||
branch: 'feature/mobile-emulator',
|
||||
repoName: 'repo/mobile',
|
||||
typeAliases: SIMULATOR_TYPE_SEARCH_ALIASES
|
||||
})
|
||||
} as SearchableSimulatorTab
|
||||
|
||||
expect(searchSimulatorTabs([entry], oversizedQuery)).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
cancelPendingSimulatorPaneShutdown,
|
||||
scheduleSimulatorPaneManagedShutdown
|
||||
} from './simulator-pane-shutdown-scheduler'
|
||||
|
||||
type TestTab = {
|
||||
id: string
|
||||
contentType: string
|
||||
}
|
||||
|
||||
describe('scheduleSimulatorPaneManagedShutdown', () => {
|
||||
let tabsByWorktree: Record<string, TestTab[]>
|
||||
const shutdownManagedSimulator = vi.fn()
|
||||
|
||||
const getTabsForWorktree = (worktreeId: string): TestTab[] => tabsByWorktree[worktreeId] ?? []
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
shutdownManagedSimulator.mockReset()
|
||||
tabsByWorktree = {}
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
cancelPendingSimulatorPaneShutdown('wt-1')
|
||||
cancelPendingSimulatorPaneShutdown('wt-2')
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('shuts down the managed simulator after the final pane stays closed', async () => {
|
||||
tabsByWorktree = { 'wt-1': [{ id: 'terminal-1', contentType: 'terminal' }] }
|
||||
|
||||
expect(
|
||||
scheduleSimulatorPaneManagedShutdown('wt-1', 'sim-1', {
|
||||
delayMs: 100,
|
||||
getTabsForWorktree,
|
||||
shutdownManagedSimulator
|
||||
})
|
||||
).toBe(true)
|
||||
|
||||
await vi.advanceTimersByTimeAsync(99)
|
||||
expect(shutdownManagedSimulator).not.toHaveBeenCalled()
|
||||
|
||||
await vi.advanceTimersByTimeAsync(1)
|
||||
expect(shutdownManagedSimulator).toHaveBeenCalledTimes(1)
|
||||
expect(shutdownManagedSimulator).toHaveBeenCalledWith('wt-1')
|
||||
})
|
||||
|
||||
it('does not schedule shutdown for a remount while the same tab still exists', () => {
|
||||
tabsByWorktree = { 'wt-1': [{ id: 'sim-1', contentType: 'simulator' }] }
|
||||
|
||||
expect(
|
||||
scheduleSimulatorPaneManagedShutdown('wt-1', 'sim-1', {
|
||||
delayMs: 100,
|
||||
getTabsForWorktree,
|
||||
shutdownManagedSimulator
|
||||
})
|
||||
).toBe(false)
|
||||
|
||||
vi.advanceTimersByTime(100)
|
||||
expect(shutdownManagedSimulator).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('keeps the managed simulator running when another simulator tab appears before the grace expires', async () => {
|
||||
tabsByWorktree = { 'wt-1': [{ id: 'terminal-1', contentType: 'terminal' }] }
|
||||
|
||||
expect(
|
||||
scheduleSimulatorPaneManagedShutdown('wt-1', 'sim-1', {
|
||||
delayMs: 100,
|
||||
getTabsForWorktree,
|
||||
shutdownManagedSimulator
|
||||
})
|
||||
).toBe(true)
|
||||
|
||||
tabsByWorktree = { 'wt-1': [{ id: 'sim-2', contentType: 'simulator' }] }
|
||||
await vi.advanceTimersByTimeAsync(100)
|
||||
|
||||
expect(shutdownManagedSimulator).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('cancels a pending shutdown when a replacement pane claims the worktree', async () => {
|
||||
tabsByWorktree = { 'wt-1': [{ id: 'terminal-1', contentType: 'terminal' }] }
|
||||
|
||||
expect(
|
||||
scheduleSimulatorPaneManagedShutdown('wt-1', 'sim-1', {
|
||||
delayMs: 100,
|
||||
getTabsForWorktree,
|
||||
shutdownManagedSimulator
|
||||
})
|
||||
).toBe(true)
|
||||
|
||||
cancelPendingSimulatorPaneShutdown('wt-1')
|
||||
await vi.advanceTimersByTimeAsync(100)
|
||||
|
||||
expect(shutdownManagedSimulator).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('isolates pending shutdowns by worktree', async () => {
|
||||
tabsByWorktree = {
|
||||
'wt-1': [{ id: 'terminal-1', contentType: 'terminal' }],
|
||||
'wt-2': [{ id: 'terminal-2', contentType: 'terminal' }]
|
||||
}
|
||||
|
||||
expect(
|
||||
scheduleSimulatorPaneManagedShutdown('wt-1', 'sim-1', {
|
||||
delayMs: 100,
|
||||
getTabsForWorktree,
|
||||
shutdownManagedSimulator
|
||||
})
|
||||
).toBe(true)
|
||||
expect(
|
||||
scheduleSimulatorPaneManagedShutdown('wt-2', 'sim-2', {
|
||||
delayMs: 100,
|
||||
getTabsForWorktree,
|
||||
shutdownManagedSimulator
|
||||
})
|
||||
).toBe(true)
|
||||
|
||||
cancelPendingSimulatorPaneShutdown('wt-1')
|
||||
await vi.advanceTimersByTimeAsync(100)
|
||||
|
||||
expect(shutdownManagedSimulator).toHaveBeenCalledTimes(1)
|
||||
expect(shutdownManagedSimulator).toHaveBeenCalledWith('wt-2')
|
||||
})
|
||||
})
|
||||
@@ -1,287 +0,0 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
// With ORCA_LAYOUT_OWNER=main, a simulator tab's open and close reach main as commands first and
|
||||
// the window draws them from main's frames, so its next save changes nothing in main's model.
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { LOCAL_EXECUTION_HOST_ID } from '../../../../../shared/execution-host'
|
||||
import type { Tab, TabGroup, TabGroupLayoutNode } from '../../../../../shared/tab-types'
|
||||
import type { LayoutCommand } from '../../../../../shared/workspace-layout/workspace-layout-command-types'
|
||||
import { loadWorkspaceLayoutWithoutReport } from '../../../../../shared/workspace-layout/workspace-layout-load'
|
||||
import { nameBasedLoadContext } from '../../../../../shared/workspace-layout/workspace-layout-minted-ids'
|
||||
import type { WorkspaceLayout } from '../../../../../shared/workspace-layout/workspace-layout-model'
|
||||
import { buildWorkspaceSessionPayload } from '@/lib/workspace/persistence/workspace-session'
|
||||
import { createTestStore, seedStore } from '@/store/testing/app-store-test-fixture'
|
||||
import { makeRuntimeOwnedWorktree } from '@/store/slices/worktrees/worktree-owner.test-fixture'
|
||||
import { makeWorktree } from '@/store/slices/worktrees/worktree.test-fixture'
|
||||
import { runtimeOwnedRepoState } from '@/store/repos/repo.test-fixture'
|
||||
import { createStoreCascadesMockApi } from '@/store/testing/app-store-cascade-api.test-fixture'
|
||||
import { layoutApplyTestTransport } from '@/runtime/workspace-layout/testing/layout-apply-test-transport.test-fixture'
|
||||
import {
|
||||
drawTabsFromMain,
|
||||
type TabsDrawnFromMain
|
||||
} from '@/store/slices/tabs/tabs-drawn-from-main.test-fixture'
|
||||
|
||||
type LayoutLoad = ReturnType<typeof loadWorkspaceLayoutWithoutReport>
|
||||
|
||||
type Mocks = {
|
||||
layoutOwnerIsMain: boolean
|
||||
store: ReturnType<typeof createTestStore> | null
|
||||
}
|
||||
|
||||
const mocks = vi.hoisted((): Mocks => ({ layoutOwnerIsMain: true, store: null }))
|
||||
let main: TabsDrawnFromMain
|
||||
|
||||
vi.mock('../../../../../shared/layout-owner-switch', () => ({
|
||||
get ORCA_LAYOUT_OWNER_IS_MAIN() {
|
||||
return mocks.layoutOwnerIsMain
|
||||
}
|
||||
}))
|
||||
vi.mock('@/store/index', () => ({
|
||||
get useAppStore() {
|
||||
return mocks.store
|
||||
}
|
||||
}))
|
||||
vi.mock('sonner', () => ({
|
||||
toast: { info: vi.fn(), success: vi.fn(), error: vi.fn(), warning: vi.fn() }
|
||||
}))
|
||||
vi.mock('@/runtime/rpc/calls/runtime-rpc-call', async (importOriginal) =>
|
||||
(
|
||||
await import('@/runtime/workspace-layout/testing/layout-apply-test-transport.test-fixture')
|
||||
).runtimeRpcClientWithLayoutApply(await importOriginal())
|
||||
)
|
||||
vi.mock('@/runtime/workspace-layout/frames/runtime-layout-client', async (importOriginal) =>
|
||||
(
|
||||
await import('@/runtime/workspace-layout/testing/layout-apply-test-transport.test-fixture')
|
||||
).runtimeLayoutClientWithTestFrames(await importOriginal())
|
||||
)
|
||||
|
||||
createStoreCascadesMockApi()
|
||||
|
||||
import { ensureSimulatorTab } from './ensure-simulator-tab'
|
||||
|
||||
const WORKTREE = 'repo1::/path/wt'
|
||||
const TERMINAL = 'terminal-1'
|
||||
const GROUP = 'group-1'
|
||||
|
||||
function store(): ReturnType<typeof createTestStore> {
|
||||
if (!mocks.store) {
|
||||
throw new Error('store not seeded')
|
||||
}
|
||||
return mocks.store
|
||||
}
|
||||
|
||||
function sent(): readonly LayoutCommand[] {
|
||||
return layoutApplyTestTransport.sent
|
||||
}
|
||||
|
||||
function loadWindowSave(): LayoutLoad {
|
||||
return loadWorkspaceLayoutWithoutReport(
|
||||
LOCAL_EXECUTION_HOST_ID,
|
||||
buildWorkspaceSessionPayload(store().getState()),
|
||||
nameBasedLoadContext()
|
||||
)
|
||||
}
|
||||
|
||||
/** The workspace as the window's save would give it to main, beside main's stored copy. */
|
||||
function expectSaveTeachesMainNothing(worktreeId = WORKTREE): void {
|
||||
// A lone group's tree is implied: the window may store its leaf, main none.
|
||||
const withoutLoneLeaf = (workspace: WorkspaceLayout | undefined) =>
|
||||
workspace && { ...workspace, groupLayout: split(workspace.groupLayout) }
|
||||
const split = (tree: TabGroupLayoutNode | undefined) => (tree?.type === 'split' ? tree : null)
|
||||
expect(withoutLoneLeaf(loadWindowSave().layout.workspaces[worktreeId])).toEqual(
|
||||
withoutLoneLeaf(layoutApplyTestTransport.mainModel!.workspaces[worktreeId])
|
||||
)
|
||||
}
|
||||
|
||||
async function settled(): Promise<void> {
|
||||
await main.settle()
|
||||
}
|
||||
|
||||
function terminalTab(id: string, groupId: string, worktreeId = WORKTREE): Tab {
|
||||
return {
|
||||
id,
|
||||
entityId: id,
|
||||
groupId,
|
||||
worktreeId,
|
||||
contentType: 'terminal',
|
||||
label: 'Terminal 1',
|
||||
customLabel: null,
|
||||
color: null,
|
||||
sortOrder: 0,
|
||||
createdAt: 1
|
||||
}
|
||||
}
|
||||
|
||||
function seed(groups: TabGroup[], layout: TabGroupLayoutNode): void {
|
||||
const terminals = groups.flatMap((group) => group.tabOrder)
|
||||
seedStore(store(), {
|
||||
worktreesByRepo: { repo1: [makeWorktree({ id: WORKTREE, repoId: 'repo1', path: '/path/wt' })] },
|
||||
activeWorktreeId: WORKTREE,
|
||||
tabsByWorktree: {
|
||||
[WORKTREE]: terminals.map((id, index) => ({
|
||||
id,
|
||||
ptyId: null,
|
||||
worktreeId: WORKTREE,
|
||||
title: 'Terminal 1',
|
||||
customTitle: null,
|
||||
color: null,
|
||||
sortOrder: index,
|
||||
createdAt: 1
|
||||
}))
|
||||
},
|
||||
unifiedTabsByWorktree: {
|
||||
[WORKTREE]: groups.flatMap((group) => group.tabOrder.map((id) => terminalTab(id, group.id)))
|
||||
},
|
||||
groupsByWorktree: { [WORKTREE]: groups },
|
||||
activeGroupIdByWorktree: { [WORKTREE]: groups[0]!.id },
|
||||
layoutByWorktree: { [WORKTREE]: layout }
|
||||
})
|
||||
}
|
||||
|
||||
/** Main takes the window's layout and draws it from here on. */
|
||||
async function seedDrawnFromMain(groups: TabGroup[], layout: TabGroupLayoutNode): Promise<void> {
|
||||
main?.close()
|
||||
seed(groups, layout)
|
||||
main = await drawTabsFromMain(store())
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
mocks.layoutOwnerIsMain = true
|
||||
vi.spyOn(console, 'warn').mockImplementation(() => {})
|
||||
mocks.store = createTestStore()
|
||||
await seedDrawnFromMain(
|
||||
[{ id: GROUP, worktreeId: WORKTREE, activeTabId: TERMINAL, tabOrder: [TERMINAL] }],
|
||||
{ type: 'leaf', groupId: GROUP }
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
main.close()
|
||||
})
|
||||
|
||||
function sentTypes(): string[] {
|
||||
return sent().map((command) => command.type)
|
||||
}
|
||||
|
||||
describe('simulator tabs in a layout-owner build', () => {
|
||||
it('opens a simulator tab in the active group through main, and closes it there', async () => {
|
||||
const tabId = ensureSimulatorTab(WORKTREE, { placement: 'activeGroup' })
|
||||
expect(tabId).toBeTruthy()
|
||||
await settled()
|
||||
expectSaveTeachesMainNothing()
|
||||
|
||||
store().getState().closeUnifiedTab(tabId!)
|
||||
await settled()
|
||||
expectSaveTeachesMainNothing()
|
||||
expect(sentTypes()).toEqual(['openSimulatorTab', 'closeTabs'])
|
||||
})
|
||||
|
||||
it('makes the right split with the tab in main, and collapses it on close', async () => {
|
||||
const tabId = ensureSimulatorTab(WORKTREE, { placement: 'rightSplit' })
|
||||
await settled()
|
||||
expect(store().getState().groupsByWorktree[WORKTREE]).toHaveLength(2)
|
||||
expectSaveTeachesMainNothing()
|
||||
expect(layoutApplyTestTransport.mainModel!.workspaces[WORKTREE]?.groupLayout).toMatchObject({
|
||||
type: 'split',
|
||||
direction: 'horizontal',
|
||||
first: { type: 'leaf', groupId: GROUP }
|
||||
})
|
||||
|
||||
store().getState().closeUnifiedTab(tabId!)
|
||||
await settled()
|
||||
expect(store().getState().groupsByWorktree[WORKTREE]).toHaveLength(1)
|
||||
expectSaveTeachesMainNothing()
|
||||
})
|
||||
|
||||
it('opens a right-side tab into the right group the workspace already has', async () => {
|
||||
const right = 'group-2'
|
||||
await seedDrawnFromMain(
|
||||
[
|
||||
{ id: GROUP, worktreeId: WORKTREE, activeTabId: TERMINAL, tabOrder: [TERMINAL] },
|
||||
{ id: right, worktreeId: WORKTREE, activeTabId: 'terminal-2', tabOrder: ['terminal-2'] }
|
||||
],
|
||||
{
|
||||
type: 'split',
|
||||
direction: 'horizontal',
|
||||
first: { type: 'leaf', groupId: GROUP },
|
||||
second: { type: 'leaf', groupId: right }
|
||||
}
|
||||
)
|
||||
const tabId = ensureSimulatorTab(WORKTREE, { placement: 'rightSplit' })
|
||||
await settled()
|
||||
expect(store().getState().getTab(tabId!)?.groupId).toBe(right)
|
||||
expectSaveTeachesMainNothing()
|
||||
})
|
||||
|
||||
it('opens into the root group of a workspace whose tabs all closed', async () => {
|
||||
await seedDrawnFromMain(
|
||||
[{ id: GROUP, worktreeId: WORKTREE, activeTabId: null, tabOrder: [] }],
|
||||
{
|
||||
type: 'leaf',
|
||||
groupId: GROUP
|
||||
}
|
||||
)
|
||||
// Main keeps no empty group, so its frame drops GROUP; the open makes the root group again.
|
||||
expect(store().getState().groupsByWorktree[WORKTREE] ?? []).toEqual([])
|
||||
const tabId = ensureSimulatorTab(WORKTREE, { placement: 'activeGroup' })
|
||||
await settled()
|
||||
const groups = store().getState().groupsByWorktree[WORKTREE] ?? []
|
||||
expect(groups).toHaveLength(1)
|
||||
expect(store().getState().getTab(tabId!)?.groupId).toBe(groups[0]!.id)
|
||||
expect(groups[0]!.tabOrder).toEqual([tabId])
|
||||
expect(sent()).toMatchObject([{ type: 'openSimulatorTab', tabId, groupId: groups[0]!.id }])
|
||||
expectSaveTeachesMainNothing()
|
||||
})
|
||||
|
||||
it('sends nothing when the workspace already has its simulator tab', async () => {
|
||||
const tabId = ensureSimulatorTab(WORKTREE)
|
||||
await settled()
|
||||
const before = sent().length
|
||||
expect(ensureSimulatorTab(WORKTREE)).toBe(tabId)
|
||||
await settled()
|
||||
expect(sent()).toHaveLength(before)
|
||||
})
|
||||
|
||||
it('leaves a paired server’s simulator tab to that server', async () => {
|
||||
const remote = 'repo2::/path/remote'
|
||||
const remoteGroup = 'group-remote'
|
||||
seedStore(
|
||||
store(),
|
||||
runtimeOwnedRepoState('env-1', 'repo2', '/path/remote', {
|
||||
worktreesByRepo: {
|
||||
repo1: [makeWorktree({ id: WORKTREE, repoId: 'repo1', path: '/path/wt' })],
|
||||
repo2: [makeRuntimeOwnedWorktree({ id: remote, repoId: 'repo2' }, 'env-1')]
|
||||
},
|
||||
activeWorktreeId: remote,
|
||||
unifiedTabsByWorktree: { [remote]: [terminalTab('terminal-r', remoteGroup, remote)] },
|
||||
groupsByWorktree: {
|
||||
[remote]: [
|
||||
{
|
||||
id: remoteGroup,
|
||||
worktreeId: remote,
|
||||
activeTabId: 'terminal-r',
|
||||
tabOrder: ['terminal-r']
|
||||
}
|
||||
]
|
||||
},
|
||||
activeGroupIdByWorktree: { [remote]: remoteGroup },
|
||||
layoutByWorktree: { [remote]: { type: 'leaf', groupId: remoteGroup } }
|
||||
})
|
||||
)
|
||||
const tabId = ensureSimulatorTab(remote, { placement: 'rightSplit' })
|
||||
expect(tabId).toBeTruthy()
|
||||
store().getState().closeUnifiedTab(tabId!)
|
||||
await settled()
|
||||
expect(sent()).toEqual([])
|
||||
})
|
||||
|
||||
it('sends nothing with the switch off', async () => {
|
||||
mocks.layoutOwnerIsMain = false
|
||||
const inGroup = ensureSimulatorTab(WORKTREE, { placement: 'activeGroup' })
|
||||
store().getState().closeUnifiedTab(inGroup!)
|
||||
const split = ensureSimulatorTab(WORKTREE, { placement: 'rightSplit' })
|
||||
store().getState().closeUnifiedTab(split!)
|
||||
await settled()
|
||||
expect(sent()).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -89,27 +89,6 @@ describe('activateSimulatorTabPaletteResult', () => {
|
||||
seedStore()
|
||||
})
|
||||
|
||||
it('activates an SSH worktree through its paired-runtime owner alias', () => {
|
||||
seedStore({
|
||||
worktreesByRepo: {
|
||||
'repo-1': [
|
||||
makeWorktree({
|
||||
hostId: 'ssh:private-target',
|
||||
runtimeOwnerEnvironmentId: 'paired-host'
|
||||
})
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
expect(
|
||||
activateSimulatorTabPaletteResult({ ...target, executionHostId: 'runtime:paired-host' })
|
||||
.status
|
||||
).toBe('activated')
|
||||
expect(mocks.activateAndRevealWorkspace).toHaveBeenCalledWith('wt-1', {
|
||||
executionHostId: 'runtime:paired-host'
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects colliding child ids before mutating either host', () => {
|
||||
seedStore({
|
||||
worktreesByRepo: {
|
||||
|
||||
Reference in New Issue
Block a user