mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
test: remove 54 low-value agent-hook, SSH and PTY tests
This commit is contained in:
@@ -149,7 +149,6 @@
|
||||
2 test-no-polling-loop:tests/e2e/worktree-card-downward-drag.spec.ts
|
||||
1 test-no-real-time-wait:mobile/src/terminal/terminal-webview-tap-routing.test.ts
|
||||
1 test-no-real-time-wait:src/main/agent-hooks/installation/scripts/posix-hook-json-stdin-reader.test.ts
|
||||
3 test-no-real-time-wait:src/main/agent-hooks/server/testing/transcripts/server-transcript-result-retry.test.ts
|
||||
2 test-no-real-time-wait:src/main/agent-hooks/server/testing/http/server-transport-interference.test.ts
|
||||
1 test-no-real-time-wait:src/main/agent-hooks/server/testing/main-agent/server-turn-ended-at.test.ts
|
||||
1 test-no-real-time-wait:src/main/agent-hooks/server/testing/main-agent/server-turn-started-at.test.ts
|
||||
|
||||
-200
@@ -1,200 +0,0 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { _internals } from '../../agent-hook-server'
|
||||
import { buildBody } from '../server.test-fixtures'
|
||||
|
||||
const { getCohortAtEmitMock, trackMock } = vi.hoisted(() => ({
|
||||
getCohortAtEmitMock: vi.fn(),
|
||||
trackMock: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('../../../../telemetry/client', () => ({
|
||||
track: trackMock
|
||||
}))
|
||||
|
||||
vi.mock('../../../../telemetry/cohort-classifier', () => ({
|
||||
getCohortAtEmit: getCohortAtEmitMock
|
||||
}))
|
||||
|
||||
beforeEach(() => {
|
||||
_internals.resetCachesForTests()
|
||||
trackMock.mockReset()
|
||||
getCohortAtEmitMock.mockReset()
|
||||
getCohortAtEmitMock.mockReturnValue({ nth_repo_added: 2 })
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
describe('Codex hook normalization', () => {
|
||||
it('tracks nested subagents with their role, model, and lifecycle state', () => {
|
||||
const root = _internals.normalizeHookPayload(
|
||||
'codex',
|
||||
buildBody({
|
||||
hook_event_name: 'UserPromptSubmit',
|
||||
prompt: 'Coordinate the review',
|
||||
model: 'gpt-5.4'
|
||||
}),
|
||||
'production'
|
||||
)
|
||||
expect(root?.payload.model).toBe('gpt-5.4')
|
||||
|
||||
const started = _internals.normalizeHookPayload(
|
||||
'codex',
|
||||
buildBody({
|
||||
hook_event_name: 'SubagentStart',
|
||||
session_id: 'child-session',
|
||||
agent_id: 'child-session',
|
||||
agent_type: 'reviewer',
|
||||
model: 'gpt-5.4-mini'
|
||||
}),
|
||||
'production'
|
||||
)
|
||||
expect(started?.providerSession).toBeUndefined()
|
||||
expect(started?.payload).toMatchObject({
|
||||
state: 'working',
|
||||
prompt: 'Coordinate the review',
|
||||
model: 'gpt-5.4',
|
||||
subagents: [
|
||||
{
|
||||
id: 'child-session',
|
||||
agentType: 'reviewer',
|
||||
model: 'gpt-5.4-mini',
|
||||
state: 'working'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
const waiting = _internals.normalizeHookPayload(
|
||||
'codex',
|
||||
buildBody({
|
||||
hook_event_name: 'PermissionRequest',
|
||||
agent_id: 'child-session',
|
||||
agent_type: 'reviewer',
|
||||
model: 'gpt-5.4-mini',
|
||||
tool_name: 'exec_command',
|
||||
tool_input: { cmd: 'git fetch' }
|
||||
}),
|
||||
'production'
|
||||
)
|
||||
expect(waiting?.payload.state).toBe('waiting')
|
||||
expect(waiting?.payload.subagents?.[0].state).toBe('waiting')
|
||||
|
||||
const workingAgain = _internals.normalizeHookPayload(
|
||||
'codex',
|
||||
buildBody({
|
||||
hook_event_name: 'PreToolUse',
|
||||
agent_id: 'child-session',
|
||||
agent_type: 'reviewer',
|
||||
model: 'gpt-5.4-mini',
|
||||
tool_name: 'exec_command',
|
||||
tool_input: { cmd: 'git fetch' }
|
||||
}),
|
||||
'production'
|
||||
)
|
||||
expect(workingAgain?.payload.state).toBe('working')
|
||||
expect(workingAgain?.payload.subagents?.[0].state).toBe('working')
|
||||
|
||||
const rootStop = _internals.normalizeHookPayload(
|
||||
'codex',
|
||||
buildBody({ hook_event_name: 'Stop', model: 'gpt-5.4' }),
|
||||
'production'
|
||||
)
|
||||
expect(rootStop?.payload.state).toBe('done')
|
||||
expect(rootStop?.payload.subagents).toBeUndefined()
|
||||
|
||||
const resumedChild = _internals.normalizeHookPayload(
|
||||
'codex',
|
||||
buildBody({
|
||||
hook_event_name: 'PreToolUse',
|
||||
agent_id: 'child-session',
|
||||
agent_type: 'reviewer',
|
||||
model: 'gpt-5.4-mini',
|
||||
tool_name: 'exec_command',
|
||||
tool_input: { cmd: 'pnpm test' }
|
||||
}),
|
||||
'production'
|
||||
)
|
||||
expect(resumedChild?.payload.state).toBe('working')
|
||||
expect(resumedChild?.payload.subagents?.[0]).toMatchObject({
|
||||
id: 'child-session',
|
||||
state: 'working'
|
||||
})
|
||||
|
||||
const stopped = _internals.normalizeHookPayload(
|
||||
'codex',
|
||||
buildBody({ hook_event_name: 'SubagentStop', agent_id: 'child-session' }),
|
||||
'production'
|
||||
)
|
||||
expect(stopped?.payload.state).toBe('done')
|
||||
expect(stopped?.payload.subagents).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe.each(['opencode', 'opencode2'] as const)('%s hook normalization', (source) => {
|
||||
it.each([
|
||||
['UnknownError', 'failure', undefined],
|
||||
['MessageAbortedError', 'cancellation', true]
|
||||
])('retains the reported root outcome for %s', (errorName, outcome, interrupted) => {
|
||||
const result = _internals.normalizeHookPayload(
|
||||
source,
|
||||
buildBody({
|
||||
hook_event_name: 'SessionIdle',
|
||||
root_state: 'done',
|
||||
root_turn_error_name: errorName
|
||||
}),
|
||||
'production'
|
||||
)
|
||||
expect(result?.payload.mainAgent).toMatchObject({ state: 'done', outcome })
|
||||
expect(result?.payload.interrupted).toBe(interrupted)
|
||||
})
|
||||
|
||||
it('does not infer an outcome for an older plugin', () => {
|
||||
const result = _internals.normalizeHookPayload(
|
||||
source,
|
||||
buildBody({ hook_event_name: 'SessionIdle' }),
|
||||
'production'
|
||||
)
|
||||
expect(result?.payload.mainAgent).toBeUndefined()
|
||||
})
|
||||
|
||||
it('keeps a root failure beside still-working child work', () => {
|
||||
const result = _internals.normalizeHookPayload(
|
||||
source,
|
||||
buildBody({
|
||||
hook_event_name: 'SessionBusy',
|
||||
root_state: 'done',
|
||||
root_turn_error_name: 'api'
|
||||
}),
|
||||
'production'
|
||||
)
|
||||
expect(result?.payload.state).toBe('working')
|
||||
expect(result?.payload.mainAgent).toMatchObject({ state: 'done', outcome: 'failure' })
|
||||
})
|
||||
|
||||
it('caps oversized MessagePart text from stale (pre-throttle) plugin builds', () => {
|
||||
// Older plugins resend full replies on each update; cap per-event work.
|
||||
const assistant = _internals.normalizeHookPayload(
|
||||
source,
|
||||
buildBody({
|
||||
hook_event_name: 'MessagePart',
|
||||
role: 'assistant',
|
||||
text: 'a'.repeat(500_000)
|
||||
}),
|
||||
'production'
|
||||
)
|
||||
expect(assistant?.payload.lastAssistantMessage?.length).toBe(8_000)
|
||||
|
||||
const user = _internals.normalizeHookPayload(
|
||||
source,
|
||||
buildBody({
|
||||
hook_event_name: 'MessagePart',
|
||||
role: 'user',
|
||||
text: 'u'.repeat(500_000),
|
||||
messageID: 'msg-cap'
|
||||
}),
|
||||
'production'
|
||||
)
|
||||
expect(user?.payload.prompt?.length).toBe(200)
|
||||
})
|
||||
})
|
||||
-174
@@ -1,174 +0,0 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { AgentHookServer, _internals } from '../../agent-hook-server'
|
||||
import { buildBody } from '../server.test-fixtures'
|
||||
|
||||
const { getCohortAtEmitMock, trackMock } = vi.hoisted(() => ({
|
||||
getCohortAtEmitMock: vi.fn(),
|
||||
trackMock: vi.fn()
|
||||
}))
|
||||
|
||||
vi.mock('../../../../telemetry/client', () => ({
|
||||
track: trackMock
|
||||
}))
|
||||
|
||||
vi.mock('../../../../telemetry/cohort-classifier', () => ({
|
||||
getCohortAtEmit: getCohortAtEmitMock
|
||||
}))
|
||||
|
||||
beforeEach(() => {
|
||||
_internals.resetCachesForTests()
|
||||
trackMock.mockReset()
|
||||
getCohortAtEmitMock.mockReset()
|
||||
getCohortAtEmitMock.mockReturnValue({ nth_repo_added: 2 })
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
describe('Copilot hook normalization', () => {
|
||||
it('updates Copilot Stop with final transcript text after a non-blocking retry', async () => {
|
||||
const server = new AgentHookServer()
|
||||
const tmpDir = mkdtempSync(join(tmpdir(), 'orca-copilot-transcript-retry-'))
|
||||
const transcriptPath = join(tmpDir, 'events.jsonl')
|
||||
writeFileSync(transcriptPath, '')
|
||||
await server.start({ env: 'production' })
|
||||
try {
|
||||
const env = server.buildPtyEnv()
|
||||
const listener = vi.fn()
|
||||
server.setListener(listener)
|
||||
|
||||
await fetch(`http://127.0.0.1:${env.ORCA_AGENT_HOOK_PORT}/hook/copilot`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Orca-Agent-Hook-Token': env.ORCA_AGENT_HOOK_TOKEN
|
||||
},
|
||||
body: JSON.stringify(
|
||||
buildBody({
|
||||
hook_event_name: 'PostToolUse',
|
||||
tool_result: { text_result_for_llm: 'stale tool output' }
|
||||
})
|
||||
)
|
||||
})
|
||||
const response = await fetch(`http://127.0.0.1:${env.ORCA_AGENT_HOOK_PORT}/hook/copilot`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Orca-Agent-Hook-Token': env.ORCA_AGENT_HOOK_TOKEN
|
||||
},
|
||||
body: JSON.stringify(
|
||||
buildBody({ hook_event_name: 'Stop', transcript_path: transcriptPath })
|
||||
)
|
||||
})
|
||||
|
||||
expect(response.status).toBe(204)
|
||||
await fetch(`http://127.0.0.1:${env.ORCA_AGENT_HOOK_PORT}/hook/copilot`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Orca-Agent-Hook-Token': env.ORCA_AGENT_HOOK_TOKEN
|
||||
},
|
||||
body: JSON.stringify(buildBody({ hook_event_name: 'SessionEnd', reason: 'complete' }))
|
||||
})
|
||||
expect(listener).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
payload: expect.objectContaining({
|
||||
state: 'done',
|
||||
lastAssistantMessage: undefined
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
// Let the first 50ms retry miss so continuation across SessionEnd is proven.
|
||||
await new Promise((resolve) => setTimeout(resolve, 70))
|
||||
writeFileSync(
|
||||
transcriptPath,
|
||||
`${JSON.stringify({
|
||||
type: 'assistant.message',
|
||||
data: { content: 'Done after transcript flush.' }
|
||||
})}\n`
|
||||
)
|
||||
await new Promise((resolve) => setTimeout(resolve, 120))
|
||||
|
||||
expect(listener).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
payload: expect.objectContaining({
|
||||
state: 'done',
|
||||
lastAssistantMessage: 'Done after transcript flush.'
|
||||
})
|
||||
})
|
||||
)
|
||||
} finally {
|
||||
server.stop()
|
||||
rmSync(tmpDir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('updates Grok Stop with final chat-history text after a non-blocking retry', async () => {
|
||||
const server = new AgentHookServer()
|
||||
const tmpDir = mkdtempSync(join(tmpdir(), 'orca-grok-chat-history-retry-'))
|
||||
const sessionId = '019e37f4-5135-7b63-a4ab-6d13aa6bf528'
|
||||
const cwd = join(tmpDir, 'workspace')
|
||||
const sessionDir = join(tmpDir, '.grok', 'sessions', encodeURIComponent(cwd), sessionId)
|
||||
mkdirSync(sessionDir, { recursive: true })
|
||||
writeFileSync(join(sessionDir, 'chat_history.jsonl'), '')
|
||||
vi.stubEnv('HOME', tmpDir)
|
||||
vi.stubEnv('USERPROFILE', tmpDir)
|
||||
await server.start({ env: 'production' })
|
||||
try {
|
||||
const env = server.buildPtyEnv()
|
||||
const listener = vi.fn()
|
||||
server.setListener(listener)
|
||||
|
||||
await fetch(`http://127.0.0.1:${env.ORCA_AGENT_HOOK_PORT}/hook/grok`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Orca-Agent-Hook-Token': env.ORCA_AGENT_HOOK_TOKEN
|
||||
},
|
||||
body: JSON.stringify(buildBody({ hookEventName: 'user_prompt_submit', prompt: 'hihi' }))
|
||||
})
|
||||
const response = await fetch(`http://127.0.0.1:${env.ORCA_AGENT_HOOK_PORT}/hook/grok`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Orca-Agent-Hook-Token': env.ORCA_AGENT_HOOK_TOKEN
|
||||
},
|
||||
body: JSON.stringify(buildBody({ hookEventName: 'Stop', sessionId, cwd }))
|
||||
})
|
||||
|
||||
expect(response.status).toBe(204)
|
||||
expect(listener).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
payload: expect.objectContaining({
|
||||
state: 'done',
|
||||
lastAssistantMessage: undefined
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
writeFileSync(
|
||||
join(sessionDir, 'chat_history.jsonl'),
|
||||
`${JSON.stringify({ type: 'assistant', content: 'Hi! How can I help you today?' })}\n`
|
||||
)
|
||||
await new Promise((resolve) => setTimeout(resolve, 120))
|
||||
|
||||
expect(listener).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
payload: expect.objectContaining({
|
||||
state: 'done',
|
||||
lastAssistantMessage: 'Hi! How can I help you today?'
|
||||
})
|
||||
})
|
||||
)
|
||||
} finally {
|
||||
server.stop()
|
||||
vi.unstubAllEnvs()
|
||||
rmSync(tmpDir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -49,18 +49,6 @@ describe('SshChannelMultiplexer on a transport that saturates and never drains',
|
||||
expect(mux.isDisposed()).toBe(true)
|
||||
})
|
||||
|
||||
it('fails a request parked behind saturation rather than leaving it pending forever', async () => {
|
||||
const settled = vi.fn()
|
||||
mux.request('pty.spawn', {}).then(
|
||||
() => settled('resolved'),
|
||||
() => settled('rejected')
|
||||
)
|
||||
|
||||
await vi.advanceTimersByTimeAsync(TIMEOUT_MS * 10 + KEEPALIVE_SEND_MS)
|
||||
|
||||
expect(settled).toHaveBeenCalledWith('rejected')
|
||||
})
|
||||
|
||||
it('keeps a slow-but-alive peer connected while its own keepalives arrive', async () => {
|
||||
// Outbound saturation proves nothing; inbound keepalives alone must preserve a slow live peer.
|
||||
let seq = 1
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { SshChannelMultiplexer } from './ssh-channel-multiplexer'
|
||||
import type { MultiplexerTransport } from './ssh-multiplexer-transport-writer'
|
||||
|
||||
function transportHarness(): {
|
||||
transport: MultiplexerTransport
|
||||
settlements: ((result: { ok: true } | { ok: false; error: Error }) => void)[]
|
||||
} {
|
||||
const settlements: ((result: { ok: true } | { ok: false; error: Error }) => void)[] = []
|
||||
return {
|
||||
transport: {
|
||||
write: (_data, onSettled) => {
|
||||
if (onSettled) {
|
||||
settlements.push(onSettled)
|
||||
}
|
||||
},
|
||||
supportsWriteSettlement: true,
|
||||
onData: vi.fn(),
|
||||
onClose: vi.fn()
|
||||
},
|
||||
settlements
|
||||
}
|
||||
}
|
||||
|
||||
describe('SshChannelMultiplexer notification settlement', () => {
|
||||
it('reports publication only from the transport write callback', () => {
|
||||
const harness = transportHarness()
|
||||
const mux = new SshChannelMultiplexer(harness.transport)
|
||||
const settled = vi.fn()
|
||||
|
||||
mux.notifyWithSettlement('pty.ackData', { acknowledgements: [] }, settled)
|
||||
expect(settled).not.toHaveBeenCalled()
|
||||
harness.settlements[0]({ ok: true })
|
||||
expect(settled).toHaveBeenCalledWith({ outcome: 'accepted' })
|
||||
mux.dispose()
|
||||
})
|
||||
|
||||
it('reports a synchronous write failure without publishing success', () => {
|
||||
const error = new Error('write failed')
|
||||
const mux = new SshChannelMultiplexer({
|
||||
write: () => {
|
||||
throw error
|
||||
},
|
||||
supportsWriteSettlement: true,
|
||||
onData: vi.fn(),
|
||||
onClose: vi.fn()
|
||||
})
|
||||
const settled = vi.fn()
|
||||
|
||||
mux.notifyWithSettlement('pty.ackData', { acknowledgements: [] }, settled)
|
||||
expect(settled).toHaveBeenCalledWith({
|
||||
outcome: 'unverifiable',
|
||||
reason: 'transport_settlement_lost',
|
||||
bytesHandedToTransport: true,
|
||||
error
|
||||
})
|
||||
expect(mux.isDisposed()).toBe(true)
|
||||
})
|
||||
|
||||
it('settles once when a hostile transport invokes its callback and then throws', () => {
|
||||
const mux = new SshChannelMultiplexer({
|
||||
write: (_data, onSettled) => {
|
||||
onSettled?.({ ok: true })
|
||||
throw new Error('late throw')
|
||||
},
|
||||
supportsWriteSettlement: true,
|
||||
onData: vi.fn(),
|
||||
onClose: vi.fn()
|
||||
})
|
||||
const settled = vi.fn()
|
||||
|
||||
mux.notifyWithSettlement('pty.ackData', { acknowledgements: [] }, settled)
|
||||
expect(settled).toHaveBeenCalledOnce()
|
||||
expect(settled).toHaveBeenCalledWith({ outcome: 'accepted' })
|
||||
})
|
||||
|
||||
it('fails an unsettled publication when the multiplexer is disposed', () => {
|
||||
const close = vi.fn()
|
||||
const mux = new SshChannelMultiplexer({
|
||||
write: () => false,
|
||||
supportsWriteSettlement: true,
|
||||
onDrain: vi.fn(),
|
||||
onData: vi.fn(),
|
||||
onClose: vi.fn(),
|
||||
close
|
||||
})
|
||||
const settled = vi.fn()
|
||||
|
||||
mux.notifyWithSettlement('pty.ackData', { acknowledgements: [] }, settled)
|
||||
expect(settled).not.toHaveBeenCalled()
|
||||
mux.dispose()
|
||||
|
||||
expect(settled).toHaveBeenCalledWith({
|
||||
outcome: 'unverifiable',
|
||||
reason: 'transport_settlement_lost',
|
||||
bytesHandedToTransport: true,
|
||||
error: expect.objectContaining({ code: 'DISPOSED' })
|
||||
})
|
||||
expect(close).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
@@ -5,32 +5,19 @@ import { runProcess } from '@orca/process-host'
|
||||
import { wrapRemoteCommandForPosixShell } from './ssh-posix-command-wrapper'
|
||||
import type { SshExecOptions } from '../connection/ssh-exec-options'
|
||||
import { execCommand } from './remote-exec-command'
|
||||
import {
|
||||
captureOrcadStateSnapshotCommand,
|
||||
parseOrcadSnapshotCapture
|
||||
} from '../../managed-server/host-state/orcad-state-snapshot'
|
||||
import { getRemoteHostPlatform } from '../remote-host/ssh-remote-platform'
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync, existsSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
|
||||
type HostOptions = {
|
||||
/** PATH on the host; '' leaves only shell builtins, so no base64 or gzip. */
|
||||
path?: string
|
||||
/** An SSH gateway that cuts the exec request at this many bytes and merges stderr into stdout. */
|
||||
gatewayLimitBytes?: number
|
||||
}
|
||||
|
||||
/** Exercise the actual transport wrapper through real /bin/sh. */
|
||||
function host(options: HostOptions = {}) {
|
||||
const exec = vi.fn()
|
||||
exec.mockImplementation(async (command: string, execOptions?: SshExecOptions) => {
|
||||
let remote = wrapRemoteCommandForPosixShell(command, {
|
||||
const remote = wrapRemoteCommandForPosixShell(command, {
|
||||
compress: execOptions?.compressCommand === true
|
||||
})
|
||||
if (options.gatewayLimitBytes !== undefined) {
|
||||
remote = `${Buffer.from(remote).subarray(0, options.gatewayLimitBytes).toString()} 2>&1`
|
||||
}
|
||||
const result = await runProcess({
|
||||
program: '/bin/sh',
|
||||
args: ['-c', remote],
|
||||
@@ -68,32 +55,5 @@ describe.skipIf(process.platform === 'win32')(
|
||||
false
|
||||
])
|
||||
})
|
||||
|
||||
it('captures a snapshot whole through a gateway that cuts exec requests at 6 KiB and merges stderr', async () => {
|
||||
const base = mkdtempSync(join(tmpdir(), 'orcad-gateway-capture-'))
|
||||
try {
|
||||
const root = join(base, '.orca')
|
||||
mkdirSync(join(root, 'profiles'), { recursive: true })
|
||||
writeFileSync(join(root, 'profiles', 'p.json'), 'state')
|
||||
const snapshot = join(base, '.orca-remote', 'orcad-state-snapshots', 'pre-1')
|
||||
const command = captureOrcadStateSnapshotCommand(
|
||||
getRemoteHostPlatform('linux-x64'),
|
||||
root,
|
||||
snapshot,
|
||||
join(base, '.orca-remote')
|
||||
)
|
||||
const gatewayLimitBytes = 6 * 1024
|
||||
expect(
|
||||
Buffer.byteLength(wrapRemoteCommandForPosixShell(command, { compress: false }))
|
||||
).toBeLessThan(gatewayLimitBytes)
|
||||
|
||||
const output = await execCommand(host({ gatewayLimitBytes }), command)
|
||||
|
||||
expect(parseOrcadSnapshotCapture(output)).toBe('captured')
|
||||
expect(existsSync(join(snapshot, 'state.tar'))).toBe(true)
|
||||
} finally {
|
||||
rmSync(base, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
@@ -96,18 +96,6 @@ describe('detectRemoteHostPlatform failure reporting', () => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('does not misreport a refused exec channel as an unsupported platform', async () => {
|
||||
execCommandMock.mockRejectedValue(maxSessionsError())
|
||||
|
||||
// The host is linux-x64 and fully supported; the probe never ran.
|
||||
await expect(detectRemoteHostPlatform(conn)).rejects.toThrow(/open failed/iu)
|
||||
await expect(detectRemoteHostPlatform(conn)).rejects.toMatchObject({
|
||||
cause: expect.objectContaining({ reason: 2 })
|
||||
})
|
||||
// Both probes run: the second gets a fresh session-channel retry budget.
|
||||
expect(execCommandMock).toHaveBeenCalledTimes(4)
|
||||
})
|
||||
|
||||
it('still detects Windows when the uname probe hits the session limit', async () => {
|
||||
execCommandMock
|
||||
.mockRejectedValueOnce(maxSessionsError())
|
||||
@@ -134,23 +122,6 @@ describe('detectRemoteHostPlatform failure reporting', () => {
|
||||
expect(execCommandMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('prefers a refused channel over the other probe non-zero exit', async () => {
|
||||
execCommandMock
|
||||
.mockRejectedValueOnce(new Error('Command "sh -c ..." failed (exit 127): sh: not found'))
|
||||
.mockRejectedValueOnce(maxSessionsError())
|
||||
|
||||
await expect(detectRemoteHostPlatform(conn)).rejects.toThrow(/open failed/u)
|
||||
await expect(detectRemoteHostPlatform(conn)).rejects.not.toThrow(/exit 127/u)
|
||||
})
|
||||
|
||||
it('returns null when a parsed uname is genuinely unsupported', async () => {
|
||||
execCommandMock
|
||||
.mockResolvedValueOnce('__ORCA_REMOTE_PLATFORM__ FreeBSD x86_64\n')
|
||||
.mockRejectedValueOnce(new Error('powershell.exe: not found'))
|
||||
|
||||
await expect(detectRemoteHostPlatform(conn)).resolves.toBeNull()
|
||||
})
|
||||
|
||||
it('does not call an unmappable uname unsupported when PowerShell was refused', async () => {
|
||||
// Cygwin sh on a win32-x64 host: only PowerShell can settle it, and it never ran.
|
||||
execCommandMock
|
||||
|
||||
@@ -29,12 +29,7 @@ import {
|
||||
clearWindowsRemoteWriteCapabilitiesForTests,
|
||||
getWindowsRemoteWriteCapabilities
|
||||
} from './system-ssh-windows-write-capabilities'
|
||||
import {
|
||||
explainWindowsPowerShellStdinFailure,
|
||||
WINDOWS_STDIN_WRITE_CHUNK_BYTES,
|
||||
WINDOWS_STDIN_WRITE_TIMEOUT_MS,
|
||||
writeWindowsRemoteFile
|
||||
} from './system-ssh-windows-write-strategy'
|
||||
import { WINDOWS_STDIN_WRITE_CHUNK_BYTES } from './system-ssh-windows-write-strategy'
|
||||
import type { SshTarget } from '../../../../shared/ssh-types'
|
||||
|
||||
type FakeChannel = EventEmitter & {
|
||||
@@ -91,9 +86,6 @@ const fileWrites = (): RecordedCommand[] =>
|
||||
const writtenPath = (command: RecordedCommand): string =>
|
||||
/\$path = '((?:[^']|'')*)'/.exec(command.script)?.[1]?.replace(/''/g, "'") ?? ''
|
||||
|
||||
const putLines = (): string[] =>
|
||||
sftpBatches.flatMap((batch) => batch.script.split('\n').filter((line) => line.startsWith('put ')))
|
||||
const putDestination = (line: string): string => /put "(?:[^"]*)" "([^"]*)"/.exec(line)?.[1] ?? ''
|
||||
const putSource = (line: string): string => /put "([^"]*)"/.exec(line)?.[1] ?? ''
|
||||
|
||||
function acceptSftp(): void {
|
||||
@@ -213,20 +205,6 @@ describe('Windows upload over sftp', () => {
|
||||
expect(getWindowsRemoteWriteCapabilities(target).shouldTry('sftp-subsystem')).toBe(true)
|
||||
expect(fileWrites()).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('keeps using sftp for the next file after one path it could not spell', async () => {
|
||||
writeFileSync(join(localDir, 'relay.js'), 'x')
|
||||
|
||||
await uploadFileViaSystemSsh(target, join(localDir, 'relay.js'), '//fileserver/share/a.js', {
|
||||
hostPlatform
|
||||
})
|
||||
await uploadFileViaSystemSsh(target, join(localDir, 'relay.js'), `${remoteRoot}/b.js`, {
|
||||
hostPlatform
|
||||
})
|
||||
|
||||
expect(putLines()).toHaveLength(1)
|
||||
expect(putDestination(putLines()[0]!)).toContain('/C:/Users/dev/.orca-remote/b.js')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Windows upload on a host with no sftp subsystem', () => {
|
||||
@@ -302,76 +280,4 @@ describe('Windows upload on a host with no sftp subsystem', () => {
|
||||
expect(getWindowsRemoteWriteCapabilities(target).shouldTry('pwsh')).toBe(true)
|
||||
expect(commands.some((command) => command.script.includes('::Move('))).toBe(false)
|
||||
})
|
||||
|
||||
it.each([
|
||||
'relay-CommandNotFoundException.js',
|
||||
'is not recognized as an internal or external command.js'
|
||||
])('propagates a timeout whose filename resembles a missing command: %s', async (file) => {
|
||||
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
|
||||
const remotePath = `${remoteRoot}/${file}`
|
||||
writeFileSync(join(localDir, file), 'x')
|
||||
let noteWriteStarted: () => void = () => {}
|
||||
const writeStarted = new Promise<void>((resolve) => {
|
||||
noteWriteStarted = resolve
|
||||
})
|
||||
spawnSystemSshCommandMock.mockImplementation((_target: SshTarget, command: string) => {
|
||||
const executable = command.split(' ')[0] ?? ''
|
||||
return createFakeChannel((channel) => {
|
||||
commands.push({
|
||||
script: decodePowerShellCommand(command),
|
||||
executable,
|
||||
stdin: channel.written
|
||||
})
|
||||
if (executable !== 'pwsh.exe') {
|
||||
setImmediate(() => channel.emit('close', 0, null))
|
||||
} else {
|
||||
noteWriteStarted()
|
||||
}
|
||||
})
|
||||
})
|
||||
try {
|
||||
const result = expect(
|
||||
uploadFileViaSystemSsh(target, join(localDir, file), remotePath, { hostPlatform })
|
||||
).rejects.toThrow('timed out')
|
||||
await writeStarted
|
||||
await vi.advanceTimersByTimeAsync(WINDOWS_STDIN_WRITE_TIMEOUT_MS + 1)
|
||||
await result
|
||||
|
||||
expect(fileWrites().map((write) => write.executable)).toEqual(['pwsh.exe'])
|
||||
expect(getWindowsRemoteWriteCapabilities(target).shouldTry('pwsh')).toBe(true)
|
||||
expect(commands.some((command) => command.script.includes('::Move('))).toBe(false)
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
it.each([
|
||||
'relay-CommandNotFoundException.js',
|
||||
'is not recognized as an internal or external command.js'
|
||||
])('propagates a short source whose filename resembles a missing command: %s', async (file) => {
|
||||
await expect(
|
||||
writeWindowsRemoteFile(
|
||||
target,
|
||||
`${remoteRoot}/${file}`,
|
||||
{
|
||||
totalBytes: 1,
|
||||
readChunk: async () => Buffer.alloc(0),
|
||||
withLocalFile: async (send) => send(join(localDir, file))
|
||||
},
|
||||
{}
|
||||
)
|
||||
).rejects.toThrow('Source ran short')
|
||||
|
||||
expect(fileWrites()).toHaveLength(0)
|
||||
expect(getWindowsRemoteWriteCapabilities(target).shouldTry('pwsh')).toBe(true)
|
||||
expect(commands.some((command) => command.script.includes('::Move('))).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('last-resort Windows PowerShell failure reporting', () => {
|
||||
it('leaves a real failure alone, so a permission error is not reported as a host limitation', () => {
|
||||
const denied = new Error('write C:/x at offset 0 failed (exit 1): Access to the path is denied')
|
||||
|
||||
expect(explainWindowsPowerShellStdinFailure(denied)).toBe(denied)
|
||||
})
|
||||
})
|
||||
|
||||
-369
@@ -1,369 +0,0 @@
|
||||
import { bindPtyConnectionTestMocks } from '../test-fixtures/pty-connection-mocks.spec'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { makePaneKey } from '../../../../../../shared/workspace-layout/stable-pane-id'
|
||||
import {
|
||||
AGENT_TASK_COMPLETE_NOTIFICATION_GRACE_MS,
|
||||
AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS
|
||||
} from '../test-fixtures/pty-connection-test-constants'
|
||||
import {
|
||||
LEAF_1,
|
||||
createMockTransport,
|
||||
createPane,
|
||||
createManager,
|
||||
type MockTransport
|
||||
} from '../test-fixtures/pty-connection-test-pane-fixtures'
|
||||
import {
|
||||
buildPaneConnectionDeps,
|
||||
type PtyConnectionAgentTitleMocks,
|
||||
bindPaneAgentTitleMocks
|
||||
} from '../test-fixtures/pty-connection-test-deps'
|
||||
import {
|
||||
createInitialStoreState,
|
||||
buildActiveRuntimeEnvironmentState
|
||||
} from '../test-fixtures/pty-connection-test-store-fixtures'
|
||||
import type { StoreState } from '../test-fixtures/pty-connection-test-store-state'
|
||||
import {
|
||||
installTerminalTestGlobals,
|
||||
restoreTerminalTestGlobals
|
||||
} from '../test-fixtures/pty-connection-test-environment'
|
||||
|
||||
export function registerPtyConnectionHookCompletionBellArbitrationTests(): void {
|
||||
let mockStoreState: StoreState
|
||||
let transportFactoryQueue: MockTransport[] = []
|
||||
let createdTransportOptions: Record<string, unknown>[] = []
|
||||
let storeSubscribers: ((state: StoreState) => void)[] = []
|
||||
|
||||
function createDeps(overrides: Record<string, unknown> = {}) {
|
||||
return buildPaneConnectionDeps(() => mockStoreState, overrides)
|
||||
}
|
||||
|
||||
// Why: activeRuntimeEnvironmentId exercises the remote-runtime path where the renderer still owns OSC 9999 status.
|
||||
function enableActiveRuntimeEnvironment(environmentId = 'env-1'): void {
|
||||
mockStoreState = buildActiveRuntimeEnvironmentState(mockStoreState, environmentId)
|
||||
}
|
||||
describe('connectPanePty', () => {
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks()
|
||||
transportFactoryQueue = []
|
||||
createdTransportOptions = []
|
||||
storeSubscribers = []
|
||||
mockStoreState = createInitialStoreState(() => mockStoreState)
|
||||
bindPtyConnectionTestMocks({
|
||||
getState: () => mockStoreState,
|
||||
getTransportQueue: () => transportFactoryQueue,
|
||||
getTransportOptions: () => createdTransportOptions,
|
||||
getStoreSubscribers: () => storeSubscribers,
|
||||
setStoreSubscribers: (subscribers) => {
|
||||
storeSubscribers = subscribers
|
||||
}
|
||||
})
|
||||
await installTerminalTestGlobals()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await restoreTerminalTestGlobals()
|
||||
})
|
||||
|
||||
it('lets delayed hook completion notifications win over concurrent terminal bells', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks2 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-hook')
|
||||
transportFactoryQueue.push(transport)
|
||||
enableActiveRuntimeEnvironment()
|
||||
mockStoreState.ptyIdsByTabId = { 'tab-1': ['pty-hook'] }
|
||||
mockStoreState.terminalLayoutsByTabId!['tab-1'].ptyIdsByLeafId = { [LEAF_1]: 'pty-hook' }
|
||||
|
||||
vi.useFakeTimers()
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks2)
|
||||
)
|
||||
|
||||
const statusHandler = createdTransportOptions[0]?.onAgentStatus as
|
||||
| ((payload: {
|
||||
state: 'working' | 'done'
|
||||
prompt: string
|
||||
agentType: 'codex'
|
||||
lastAssistantMessage?: string
|
||||
}) => void)
|
||||
| undefined
|
||||
const bellHandler = createdTransportOptions[0]?.onBell as (() => void) | undefined
|
||||
if (!statusHandler || !bellHandler) {
|
||||
throw new Error('Expected hook status and bell handlers to be registered')
|
||||
}
|
||||
|
||||
statusHandler({
|
||||
state: 'working',
|
||||
prompt: 'finish the implementation',
|
||||
agentType: 'codex'
|
||||
})
|
||||
statusHandler({
|
||||
state: 'done',
|
||||
prompt: 'finish the implementation',
|
||||
agentType: 'codex',
|
||||
lastAssistantMessage: 'Done.'
|
||||
})
|
||||
bellHandler()
|
||||
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_GRACE_MS)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'terminal-bell' })
|
||||
)
|
||||
|
||||
vi.advanceTimersByTime(
|
||||
AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS - AGENT_TASK_COMPLETE_NOTIFICATION_GRACE_MS
|
||||
)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'terminal-bell' })
|
||||
)
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_GRACE_MS)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
source: 'agent-task-complete',
|
||||
terminalTitle: 'codex',
|
||||
paneKey: makePaneKey('tab-1', LEAF_1),
|
||||
agentStatusSnapshot: expect.objectContaining({
|
||||
state: 'done',
|
||||
prompt: 'finish the implementation',
|
||||
agentType: 'codex',
|
||||
lastAssistantMessage: 'Done.'
|
||||
})
|
||||
})
|
||||
)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'terminal-bell' })
|
||||
)
|
||||
})
|
||||
|
||||
it('restores a suppressed terminal bell when a delayed hook completion resumes work', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks3 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('tab-pty')
|
||||
transportFactoryQueue.push(transport)
|
||||
enableActiveRuntimeEnvironment()
|
||||
mockStoreState.ptyIdsByTabId = { 'tab-1': ['tab-pty'] }
|
||||
mockStoreState.terminalLayoutsByTabId!['tab-1'].ptyIdsByLeafId = { [LEAF_1]: 'tab-pty' }
|
||||
|
||||
vi.useFakeTimers()
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks3)
|
||||
)
|
||||
|
||||
const statusHandler = createdTransportOptions[0]?.onAgentStatus as
|
||||
| ((payload: {
|
||||
state: 'working' | 'done'
|
||||
prompt: string
|
||||
agentType: 'codex'
|
||||
lastAssistantMessage?: string
|
||||
}) => void)
|
||||
| undefined
|
||||
const bellHandler = createdTransportOptions[0]?.onBell as (() => void) | undefined
|
||||
if (!statusHandler || !bellHandler) {
|
||||
throw new Error('Expected hook status and bell handlers to be registered')
|
||||
}
|
||||
|
||||
statusHandler({
|
||||
state: 'working',
|
||||
prompt: 'finish the implementation',
|
||||
agentType: 'codex'
|
||||
})
|
||||
statusHandler({
|
||||
state: 'done',
|
||||
prompt: 'finish the implementation',
|
||||
agentType: 'codex',
|
||||
lastAssistantMessage: 'Done.'
|
||||
})
|
||||
bellHandler()
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_GRACE_MS)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'terminal-bell' })
|
||||
)
|
||||
|
||||
statusHandler({
|
||||
state: 'working',
|
||||
prompt: 'finish the implementation',
|
||||
agentType: 'codex'
|
||||
})
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_GRACE_MS)
|
||||
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'terminal-bell' })
|
||||
)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'agent-task-complete' })
|
||||
)
|
||||
})
|
||||
|
||||
it('restores a suppressed terminal bell when a delayed hook completion resumes via title tracking', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks4 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-hook')
|
||||
transportFactoryQueue.push(transport)
|
||||
enableActiveRuntimeEnvironment()
|
||||
mockStoreState.ptyIdsByTabId = { 'tab-1': ['pty-hook'] }
|
||||
mockStoreState.terminalLayoutsByTabId!['tab-1'].ptyIdsByLeafId = { [LEAF_1]: 'pty-hook' }
|
||||
|
||||
vi.useFakeTimers()
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks4)
|
||||
)
|
||||
|
||||
const statusHandler = createdTransportOptions[0]?.onAgentStatus as
|
||||
| ((payload: {
|
||||
state: 'working' | 'done'
|
||||
prompt: string
|
||||
agentType: 'codex'
|
||||
lastAssistantMessage?: string
|
||||
}) => void)
|
||||
| undefined
|
||||
const bellHandler = createdTransportOptions[0]?.onBell as (() => void) | undefined
|
||||
const workingHandler = createdTransportOptions[0]?.onAgentBecameWorking as
|
||||
| (() => void)
|
||||
| undefined
|
||||
if (!statusHandler || !bellHandler || !workingHandler) {
|
||||
throw new Error('Expected hook status, bell, and working handlers to be registered')
|
||||
}
|
||||
|
||||
statusHandler({
|
||||
state: 'working',
|
||||
prompt: 'finish the implementation',
|
||||
agentType: 'codex'
|
||||
})
|
||||
statusHandler({
|
||||
state: 'done',
|
||||
prompt: 'finish the implementation',
|
||||
agentType: 'codex',
|
||||
lastAssistantMessage: 'Milestone complete.'
|
||||
})
|
||||
bellHandler()
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_GRACE_MS)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'terminal-bell' })
|
||||
)
|
||||
|
||||
workingHandler()
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_GRACE_MS)
|
||||
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'terminal-bell' })
|
||||
)
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'agent-task-complete' })
|
||||
)
|
||||
})
|
||||
|
||||
it('restores a suppressed terminal bell when the pending agent completion is canceled', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks5 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
vi.useFakeTimers()
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks5)
|
||||
)
|
||||
|
||||
const bellHandler = createdTransportOptions[0]?.onBell as (() => void) | undefined
|
||||
const idleHandler = createdTransportOptions[0]?.onAgentBecameIdle as
|
||||
| ((title: string) => void)
|
||||
| undefined
|
||||
const workingHandler = createdTransportOptions[0]?.onAgentBecameWorking as
|
||||
| (() => void)
|
||||
| undefined
|
||||
if (!bellHandler || !idleHandler || !workingHandler) {
|
||||
throw new Error('Expected bell, idle, and working handlers to be registered')
|
||||
}
|
||||
|
||||
bellHandler()
|
||||
idleHandler('* Codex done')
|
||||
workingHandler()
|
||||
vi.advanceTimersByTime(250)
|
||||
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'terminal-bell' })
|
||||
)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'agent-task-complete' })
|
||||
)
|
||||
})
|
||||
|
||||
it('cancels a title task-complete notification when the agent resumes before quiet', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks6 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
vi.useFakeTimers()
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks6)
|
||||
)
|
||||
|
||||
const idleHandler = createdTransportOptions[0]?.onAgentBecameIdle as
|
||||
| ((title: string) => void)
|
||||
| undefined
|
||||
const workingHandler = createdTransportOptions[0]?.onAgentBecameWorking as
|
||||
| (() => void)
|
||||
| undefined
|
||||
if (!idleHandler || !workingHandler) {
|
||||
throw new Error('Expected idle and working handlers to be registered')
|
||||
}
|
||||
|
||||
idleHandler('* Codex done')
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS - 1)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'agent-task-complete' })
|
||||
)
|
||||
|
||||
workingHandler()
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'agent-task-complete' })
|
||||
)
|
||||
|
||||
idleHandler('* Codex done')
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledWith({
|
||||
source: 'agent-task-complete',
|
||||
terminalTitle: '* Codex done',
|
||||
paneKey: makePaneKey('tab-1', LEAF_1),
|
||||
ptyId: 'tab-pty'
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
+1
-246
@@ -3,10 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { RESET_TERMINAL_CURSOR_STYLE } from '../../../../../../shared/terminal/protocol/input-modes/terminal-mode-reset-profiles'
|
||||
import { makePaneKey } from '../../../../../../shared/workspace-layout/stable-pane-id'
|
||||
import { flushAsyncTicks } from '../test-fixtures/pty-connection-test-async'
|
||||
import {
|
||||
AGENT_TASK_COMPLETE_NOTIFICATION_GRACE_MS,
|
||||
AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS
|
||||
} from '../test-fixtures/pty-connection-test-constants'
|
||||
import { AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS } from '../test-fixtures/pty-connection-test-constants'
|
||||
import {
|
||||
temporarilySetNavigatorUserAgent,
|
||||
sendTerminalInputThroughPane
|
||||
@@ -79,66 +76,6 @@ export function registerPtyConnectionHookCompletionSideEffectsTests(): void {
|
||||
await restoreTerminalTestGlobals()
|
||||
})
|
||||
|
||||
it('preserves permission-title cursor and cache side effects through authoritative hook done', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-hook')
|
||||
transportFactoryQueue.push(transport)
|
||||
enableActiveRuntimeEnvironment()
|
||||
const paneKey = makePaneKey('tab-1', LEAF_1)
|
||||
mockStoreState.agentStatusByPaneKey[paneKey] = {
|
||||
state: 'waiting',
|
||||
prompt: 'approve the tool call',
|
||||
updatedAt: Date.now(),
|
||||
stateStartedAt: Date.now(),
|
||||
agentType: 'claude',
|
||||
paneKey,
|
||||
stateHistory: []
|
||||
}
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks)
|
||||
)
|
||||
const idleHandler = createdTransportOptions[0]?.onAgentBecameIdle as
|
||||
| ((title: string) => void)
|
||||
| undefined
|
||||
const statusHandler = createdTransportOptions[0]?.onAgentStatus as
|
||||
| ((payload: {
|
||||
state: 'done'
|
||||
prompt: string
|
||||
agentType: 'claude'
|
||||
lastAssistantMessage: string
|
||||
}) => void)
|
||||
| undefined
|
||||
if (!idleHandler || !statusHandler) {
|
||||
throw new Error('Expected idle and hook status handlers to be registered')
|
||||
}
|
||||
|
||||
idleHandler('Claude Code permission')
|
||||
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalled()
|
||||
expect(deps.setCacheTimerStartedAt).not.toHaveBeenCalled()
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(
|
||||
RESET_TERMINAL_CURSOR_STYLE,
|
||||
expect.any(Function)
|
||||
)
|
||||
|
||||
statusHandler({
|
||||
state: 'done',
|
||||
prompt: 'approve the tool call',
|
||||
agentType: 'claude',
|
||||
lastAssistantMessage: 'Done.'
|
||||
})
|
||||
|
||||
expect(deps.setCacheTimerStartedAt).toHaveBeenCalledWith(paneKey, expect.any(Number))
|
||||
})
|
||||
|
||||
it('preserves a genuine hook completion after suppressing an earlier idle title', async () => {
|
||||
// The completion settings subscription is shared per module load.
|
||||
await loadFreshTerminalModules()
|
||||
@@ -228,98 +165,6 @@ export function registerPtyConnectionHookCompletionSideEffectsTests(): void {
|
||||
expect(storeSubscribers).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('preserves accepted hook effects and shared completion with desktop banners and attention disabled', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks3 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-hook')
|
||||
transportFactoryQueue.push(transport)
|
||||
enableActiveRuntimeEnvironment()
|
||||
mockStoreState.ptyIdsByTabId = { 'tab-1': ['pty-hook'] }
|
||||
mockStoreState.terminalLayoutsByTabId!['tab-1'].ptyIdsByLeafId = { [LEAF_1]: 'pty-hook' }
|
||||
vi.useFakeTimers()
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
experimentalTerminalAttention: false,
|
||||
notifications: {
|
||||
enabled: true,
|
||||
agentTaskComplete: false,
|
||||
terminalBell: true,
|
||||
suppressWhenFocused: false,
|
||||
customSoundPath: null
|
||||
}
|
||||
}
|
||||
const paneKey = makePaneKey('tab-1', LEAF_1)
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks3)
|
||||
)
|
||||
|
||||
const idleHandler = createdTransportOptions[0]?.onAgentBecameIdle as
|
||||
| ((title: string) => void)
|
||||
| undefined
|
||||
const statusHandler = createdTransportOptions[0]?.onAgentStatus as
|
||||
| ((payload: {
|
||||
state: 'working' | 'done'
|
||||
prompt: string
|
||||
agentType: 'claude'
|
||||
lastAssistantMessage?: string
|
||||
}) => void)
|
||||
| undefined
|
||||
if (!idleHandler || !statusHandler) {
|
||||
throw new Error('Expected idle and hook status handlers to be registered')
|
||||
}
|
||||
|
||||
statusHandler({
|
||||
state: 'working',
|
||||
prompt: 'finish the implementation',
|
||||
agentType: 'claude'
|
||||
})
|
||||
idleHandler('Claude done')
|
||||
|
||||
expect(deps.setCacheTimerStartedAt).not.toHaveBeenCalledWith(paneKey, expect.any(Number))
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(
|
||||
RESET_TERMINAL_CURSOR_STYLE,
|
||||
expect.any(Function)
|
||||
)
|
||||
|
||||
statusHandler({
|
||||
state: 'done',
|
||||
prompt: 'finish the implementation',
|
||||
agentType: 'claude',
|
||||
lastAssistantMessage: 'Done.'
|
||||
})
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalled()
|
||||
expect(deps.setCacheTimerStartedAt).toHaveBeenCalledWith(paneKey, expect.any(Number))
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(
|
||||
RESET_TERMINAL_CURSOR_STYLE,
|
||||
expect.any(Function)
|
||||
)
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_GRACE_MS - 1)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalled()
|
||||
vi.advanceTimersByTime(1)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledExactlyOnceWith(
|
||||
expect.objectContaining({
|
||||
source: 'agent-task-complete',
|
||||
paneKey,
|
||||
agentStatusSnapshot: expect.objectContaining({
|
||||
state: 'done',
|
||||
agentType: 'claude',
|
||||
lastAssistantMessage: 'Done.'
|
||||
})
|
||||
})
|
||||
)
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: 'delivers confirmed process exit despite the same stale working hook row',
|
||||
@@ -506,96 +351,6 @@ export function registerPtyConnectionHookCompletionSideEffectsTests(): void {
|
||||
)
|
||||
})
|
||||
|
||||
it('drops confirmed idle exit when a different hook owner appears between null samples', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks6 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-replaced-codex')
|
||||
transportFactoryQueue.push(transport)
|
||||
vi.useFakeTimers()
|
||||
// Why: pin poll jitter so follow-up null samples cannot overtake replacement ownership.
|
||||
const randomSpy = vi.spyOn(Math, 'random').mockReturnValue(0.5)
|
||||
try {
|
||||
const getForegroundProcess = vi.mocked(window.api.pty.getForegroundProcess)
|
||||
// Why: one timer advance can start multiple reads; gate follow-up null samples until the replacement hook owner is installed.
|
||||
let idleMode = false
|
||||
let nullSamplesStarted = 0
|
||||
let releaseConfirmingNullSample: (() => void) | undefined
|
||||
const confirmingNullSampleGate = new Promise<void>((resolve) => {
|
||||
releaseConfirmingNullSample = resolve
|
||||
})
|
||||
getForegroundProcess.mockImplementation(async () => {
|
||||
if (!idleMode) {
|
||||
return 'codex'
|
||||
}
|
||||
nullSamplesStarted += 1
|
||||
if (nullSamplesStarted >= 2) {
|
||||
await confirmingNullSampleGate
|
||||
}
|
||||
return null
|
||||
})
|
||||
const paneKey = makePaneKey('tab-1', LEAF_1)
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks6)
|
||||
)
|
||||
await flushAsyncTicks()
|
||||
const titleHandler = createdTransportOptions[0]?.onTitleChange as
|
||||
| ((title: string, rawTitle: string) => void)
|
||||
| undefined
|
||||
const idleHandler = createdTransportOptions[0]?.onAgentBecameIdle as
|
||||
| ((title: string) => void)
|
||||
| undefined
|
||||
if (!titleHandler || !idleHandler) {
|
||||
throw new Error('Expected title and idle handlers to be registered')
|
||||
}
|
||||
|
||||
titleHandler('Codex working', 'Codex working')
|
||||
await vi.advanceTimersByTimeAsync(2_500)
|
||||
idleMode = true
|
||||
for (let attempts = 0; nullSamplesStarted < 1; attempts += 1) {
|
||||
if (attempts >= 10) {
|
||||
throw new Error('Expected the first idle process inspection')
|
||||
}
|
||||
await vi.advanceTimersToNextTimerAsync()
|
||||
}
|
||||
// Why: let the first null sample record a pending process exit before the replacement owner is installed.
|
||||
await flushAsyncTicks()
|
||||
|
||||
mockStoreState.agentStatusByPaneKey[paneKey] = {
|
||||
state: 'working',
|
||||
prompt: 'replacement agent turn',
|
||||
updatedAt: Date.now(),
|
||||
stateStartedAt: Date.now(),
|
||||
agentType: 'claude',
|
||||
paneKey,
|
||||
stateHistory: []
|
||||
}
|
||||
releaseConfirmingNullSample?.()
|
||||
// Ignore cursor resets from setup so this assertion only covers the replacement idle event.
|
||||
pane.terminal.write.mockClear()
|
||||
idleHandler('Claude done')
|
||||
await vi.advanceTimersByTimeAsync(800)
|
||||
await vi.advanceTimersByTimeAsync(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'agent-task-complete' })
|
||||
)
|
||||
expect(pane.terminal.write).not.toHaveBeenCalledWith(
|
||||
RESET_TERMINAL_CURSOR_STYLE,
|
||||
expect.any(Function)
|
||||
)
|
||||
} finally {
|
||||
// Why: an assertion failure above must not leave Math.random pinned for later tests.
|
||||
randomSpy.mockRestore()
|
||||
}
|
||||
})
|
||||
|
||||
it('preserves replacement-agent title side effects through the process replacement veto', async () => {
|
||||
const { dispatchAgentHookTerminalLifecycle } =
|
||||
await import('../../agent-completion/agent-hook-terminal-lifecycle')
|
||||
|
||||
-425
@@ -125,104 +125,6 @@ export function registerPtyConnectionNotificationSettingsGatingTests(): void {
|
||||
)
|
||||
})
|
||||
|
||||
it('does not suppress terminal bell notifications when agent-complete notifications are disabled', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks2 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
vi.useFakeTimers()
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
notifications: {
|
||||
enabled: true,
|
||||
agentTaskComplete: false,
|
||||
terminalBell: true,
|
||||
suppressWhenFocused: false,
|
||||
customSoundPath: null
|
||||
}
|
||||
}
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks2)
|
||||
)
|
||||
|
||||
const bellHandler = createdTransportOptions[0]?.onBell as (() => void) | undefined
|
||||
const idleHandler = createdTransportOptions[0]?.onAgentBecameIdle as
|
||||
| ((title: string) => void)
|
||||
| undefined
|
||||
if (!bellHandler || !idleHandler) {
|
||||
throw new Error('Expected bell and idle handlers to be registered')
|
||||
}
|
||||
|
||||
bellHandler()
|
||||
idleHandler('* Codex done')
|
||||
vi.advanceTimersByTime(250)
|
||||
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ source: 'terminal-bell' })
|
||||
)
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
source: 'agent-task-complete'
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('forwards agent completion to notification policy when desktop banners are disabled', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks3 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-codex')
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
vi.useFakeTimers()
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
experimentalTerminalAttention: true,
|
||||
notifications: {
|
||||
enabled: true,
|
||||
agentTaskComplete: false,
|
||||
terminalBell: true,
|
||||
suppressWhenFocused: false,
|
||||
customSoundPath: null
|
||||
}
|
||||
}
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks3)
|
||||
)
|
||||
|
||||
const idleHandler = createdTransportOptions[0]?.onAgentBecameIdle as
|
||||
| ((title: string) => void)
|
||||
| undefined
|
||||
if (!idleHandler) {
|
||||
throw new Error('Expected idle handler to be registered')
|
||||
}
|
||||
|
||||
idleHandler('* Codex done')
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
source: 'agent-task-complete',
|
||||
paneKey: makePaneKey('tab-1', LEAF_1)
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('shares one raw store subscriber for agent-complete notification settings across panes', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks4 =
|
||||
@@ -250,65 +152,6 @@ export function registerPtyConnectionNotificationSettingsGatingTests(): void {
|
||||
expect(storeSubscribers).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('offers generic title completions while desktop completion banners are disabled', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks5 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-codex')
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
vi.useFakeTimers()
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
notifications: {
|
||||
enabled: true,
|
||||
agentTaskComplete: false,
|
||||
terminalBell: true,
|
||||
suppressWhenFocused: false,
|
||||
customSoundPath: null
|
||||
}
|
||||
}
|
||||
const api = (
|
||||
globalThis as unknown as {
|
||||
window: { api: { pty: { getForegroundProcess: ReturnType<typeof vi.fn> } } }
|
||||
}
|
||||
).window.api
|
||||
api.pty.getForegroundProcess.mockResolvedValue('codex')
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks5)
|
||||
)
|
||||
|
||||
const titleHandler = createdTransportOptions[0]?.onTitleChange as
|
||||
| ((title: string, rawTitle: string) => void)
|
||||
| undefined
|
||||
if (!titleHandler) {
|
||||
throw new Error('Expected onTitleChange to be registered')
|
||||
}
|
||||
|
||||
titleHandler('⠋ experimental-agent-observability', '⠋ experimental-agent-observability')
|
||||
titleHandler('experimental-agent-observability', 'experimental-agent-observability')
|
||||
await flushAsyncTicks()
|
||||
expect(window.api.pty.inspectProcess).toHaveBeenCalledWith('pty-codex')
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS - 1)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalled()
|
||||
vi.advanceTimersByTime(1)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledExactlyOnceWith(
|
||||
expect.objectContaining({
|
||||
source: 'agent-task-complete',
|
||||
terminalTitle: 'experimental-agent-observability',
|
||||
paneKey: makePaneKey('tab-1', LEAF_1)
|
||||
})
|
||||
)
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('keeps an in-flight generic completion when desktop completion banners are enabled', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks6 =
|
||||
@@ -380,142 +223,6 @@ export function registerPtyConnectionNotificationSettingsGatingTests(): void {
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('keeps raw title completion continuity across desktop banner changes', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks7 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-codex')
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
vi.useFakeTimers()
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
notifications: {
|
||||
enabled: true,
|
||||
agentTaskComplete: true,
|
||||
terminalBell: true,
|
||||
suppressWhenFocused: false,
|
||||
customSoundPath: null
|
||||
}
|
||||
}
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks7)
|
||||
)
|
||||
|
||||
const titleHandler = createdTransportOptions[0]?.onTitleChange as
|
||||
| ((title: string, rawTitle: string) => void)
|
||||
| undefined
|
||||
if (!titleHandler) {
|
||||
throw new Error('Expected onTitleChange to be registered')
|
||||
}
|
||||
|
||||
titleHandler('Claude working', 'Claude working')
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
notifications: {
|
||||
...mockStoreState.settings.notifications,
|
||||
agentTaskComplete: false
|
||||
}
|
||||
}
|
||||
notifyStoreSubscribers()
|
||||
titleHandler('Claude done', 'Claude done')
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
notifications: {
|
||||
...mockStoreState.settings.notifications,
|
||||
agentTaskComplete: true
|
||||
}
|
||||
}
|
||||
notifyStoreSubscribers()
|
||||
titleHandler('Claude done', 'Claude done')
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS - 1)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalled()
|
||||
vi.advanceTimersByTime(1)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledExactlyOnceWith(
|
||||
expect.objectContaining({
|
||||
source: 'agent-task-complete',
|
||||
terminalTitle: 'Claude done',
|
||||
paneKey: makePaneKey('tab-1', LEAF_1)
|
||||
})
|
||||
)
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('keeps a scheduled agent completion across desktop banner changes', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks8 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-codex')
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
vi.useFakeTimers()
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
notifications: {
|
||||
enabled: true,
|
||||
agentTaskComplete: true,
|
||||
terminalBell: true,
|
||||
suppressWhenFocused: false,
|
||||
customSoundPath: null
|
||||
}
|
||||
}
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks8)
|
||||
)
|
||||
|
||||
const idleHandler = createdTransportOptions[0]?.onAgentBecameIdle as
|
||||
| ((title: string) => void)
|
||||
| undefined
|
||||
if (!idleHandler) {
|
||||
throw new Error('Expected onAgentBecameIdle to be registered')
|
||||
}
|
||||
|
||||
idleHandler('* Codex done')
|
||||
vi.advanceTimersByTime(500)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalled()
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
notifications: {
|
||||
...mockStoreState.settings.notifications,
|
||||
agentTaskComplete: false
|
||||
}
|
||||
}
|
||||
notifyStoreSubscribers()
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
notifications: {
|
||||
...mockStoreState.settings.notifications,
|
||||
agentTaskComplete: true
|
||||
}
|
||||
}
|
||||
notifyStoreSubscribers()
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS - 500 - 1)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalled()
|
||||
vi.advanceTimersByTime(1)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledExactlyOnceWith(
|
||||
expect.objectContaining({
|
||||
source: 'agent-task-complete',
|
||||
terminalTitle: '* Codex done',
|
||||
paneKey: makePaneKey('tab-1', LEAF_1)
|
||||
})
|
||||
)
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('restores a suppressed terminal bell when disabling pending agent completion', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks9 =
|
||||
@@ -573,137 +280,5 @@ export function registerPtyConnectionNotificationSettingsGatingTests(): void {
|
||||
expect.objectContaining({ source: 'terminal-bell' })
|
||||
)
|
||||
})
|
||||
|
||||
it('delivers completion after working and desktop banner changes', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks10 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-codex')
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
vi.useFakeTimers()
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
notifications: {
|
||||
enabled: true,
|
||||
agentTaskComplete: true,
|
||||
terminalBell: true,
|
||||
suppressWhenFocused: false,
|
||||
customSoundPath: null
|
||||
}
|
||||
}
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks10)
|
||||
)
|
||||
|
||||
const workingHandler = createdTransportOptions[0]?.onAgentBecameWorking as
|
||||
| (() => void)
|
||||
| undefined
|
||||
const idleHandler = createdTransportOptions[0]?.onAgentBecameIdle as
|
||||
| ((title: string) => void)
|
||||
| undefined
|
||||
if (!workingHandler || !idleHandler) {
|
||||
throw new Error('Expected working and idle handlers to be registered')
|
||||
}
|
||||
|
||||
workingHandler()
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
notifications: {
|
||||
...mockStoreState.settings.notifications,
|
||||
agentTaskComplete: false
|
||||
}
|
||||
}
|
||||
notifyStoreSubscribers()
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
notifications: {
|
||||
...mockStoreState.settings.notifications,
|
||||
agentTaskComplete: true
|
||||
}
|
||||
}
|
||||
notifyStoreSubscribers()
|
||||
idleHandler('* Codex done')
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS - 1)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalled()
|
||||
vi.advanceTimersByTime(1)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledExactlyOnceWith(
|
||||
expect.objectContaining({
|
||||
source: 'agent-task-complete',
|
||||
terminalTitle: '* Codex done',
|
||||
paneKey: makePaneKey('tab-1', LEAF_1)
|
||||
})
|
||||
)
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('delivers completion after working starts with desktop banners disabled', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks11 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-codex')
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
vi.useFakeTimers()
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
notifications: {
|
||||
enabled: true,
|
||||
agentTaskComplete: false,
|
||||
terminalBell: true,
|
||||
suppressWhenFocused: false,
|
||||
customSoundPath: null
|
||||
}
|
||||
}
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks11)
|
||||
)
|
||||
|
||||
const workingHandler = createdTransportOptions[0]?.onAgentBecameWorking as
|
||||
| (() => void)
|
||||
| undefined
|
||||
const idleHandler = createdTransportOptions[0]?.onAgentBecameIdle as
|
||||
| ((title: string) => void)
|
||||
| undefined
|
||||
if (!workingHandler || !idleHandler) {
|
||||
throw new Error('Expected working and idle handlers to be registered')
|
||||
}
|
||||
|
||||
workingHandler()
|
||||
mockStoreState.settings = {
|
||||
...mockStoreState.settings,
|
||||
notifications: {
|
||||
...mockStoreState.settings.notifications,
|
||||
agentTaskComplete: true
|
||||
}
|
||||
}
|
||||
notifyStoreSubscribers()
|
||||
idleHandler('* Codex done')
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS - 1)
|
||||
expect(deps.dispatchNotification).not.toHaveBeenCalled()
|
||||
vi.advanceTimersByTime(1)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledExactlyOnceWith(
|
||||
expect.objectContaining({
|
||||
source: 'agent-task-complete',
|
||||
terminalTitle: '* Codex done',
|
||||
paneKey: makePaneKey('tab-1', LEAF_1)
|
||||
})
|
||||
)
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
-361
@@ -44,12 +44,6 @@ export function registerPtyConnectionTaskCompleteDispatchTests(): void {
|
||||
mockStoreState = buildActiveRuntimeEnvironmentState(mockStoreState, environmentId)
|
||||
}
|
||||
|
||||
function notifyStoreSubscribers(): void {
|
||||
for (const listener of storeSubscribers.slice()) {
|
||||
listener(mockStoreState)
|
||||
}
|
||||
}
|
||||
|
||||
describe('connectPanePty', () => {
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks()
|
||||
@@ -157,101 +151,6 @@ export function registerPtyConnectionTaskCompleteDispatchTests(): void {
|
||||
)
|
||||
})
|
||||
|
||||
it('dispatches agent-task-complete from recognized hook completion events', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks3 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-hook')
|
||||
transportFactoryQueue.push(transport)
|
||||
enableActiveRuntimeEnvironment()
|
||||
mockStoreState.ptyIdsByTabId = { 'tab-1': ['pty-hook'] }
|
||||
mockStoreState.terminalLayoutsByTabId!['tab-1'].ptyIdsByLeafId = { [LEAF_1]: 'pty-hook' }
|
||||
|
||||
vi.useFakeTimers()
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
...mockPanePtyArgs(pane, manager, bindPaneAgentTitleMocks(deps, agentTitleMocks3))
|
||||
)
|
||||
|
||||
const statusHandler = createdTransportOptions[0]?.onAgentStatus as
|
||||
| ((payload: {
|
||||
state: 'done'
|
||||
prompt: string
|
||||
agentType: 'codex'
|
||||
lastAssistantMessage: string
|
||||
}) => void)
|
||||
| undefined
|
||||
if (!statusHandler) {
|
||||
throw new Error('Expected onAgentStatus to be registered')
|
||||
}
|
||||
|
||||
statusHandler({
|
||||
state: 'done',
|
||||
prompt: 'finish the implementation',
|
||||
agentType: 'codex',
|
||||
lastAssistantMessage: 'Done.'
|
||||
})
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
|
||||
expect(deps.dispatchNotification).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
source: 'agent-task-complete',
|
||||
terminalTitle: 'codex',
|
||||
paneKey: makePaneKey('tab-1', LEAF_1)
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('preserves synthetic Codex permission titles', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks4 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-hook')
|
||||
transportFactoryQueue.push(transport)
|
||||
const paneKey = makePaneKey('tab-1', LEAF_1)
|
||||
mockStoreState.agentLaunchConfigByPaneKey[paneKey] = {
|
||||
launchConfig: {
|
||||
agentArgs: '',
|
||||
agentEnv: {}
|
||||
}
|
||||
}
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
manager.getActivePane.mockReturnValue({ id: 1 })
|
||||
const deps = createDeps({
|
||||
startup: {
|
||||
command: 'codex',
|
||||
launchConfig: {
|
||||
agentCommand: 'codex',
|
||||
agentArgs: '',
|
||||
agentEnv: {}
|
||||
},
|
||||
launchToken: 'launch-manual',
|
||||
launchAgent: 'codex'
|
||||
}
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
...mockPanePtyArgs(pane, manager, bindPaneAgentTitleMocks(deps, agentTitleMocks4))
|
||||
)
|
||||
|
||||
const titleHandler = createdTransportOptions[0]?.onTitleChange as
|
||||
| ((title: string, rawTitle: string) => void)
|
||||
| undefined
|
||||
if (!titleHandler) {
|
||||
throw new Error('Expected onTitleChange to be registered')
|
||||
}
|
||||
|
||||
titleHandler('Codex - action required', 'Codex - action required')
|
||||
|
||||
expect(deps.setRuntimePaneTitle).toHaveBeenCalledWith('tab-1', 1, 'Codex - action required')
|
||||
expect(deps.updateTabTitle).toHaveBeenCalledWith('tab-1', 'Codex - action required')
|
||||
})
|
||||
|
||||
it('normalizes Pi-compatible remote titles to authoritative OMP launch identity', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks5 =
|
||||
@@ -335,61 +234,6 @@ export function registerPtyConnectionTaskCompleteDispatchTests(): void {
|
||||
)
|
||||
})
|
||||
|
||||
it('keeps GPU rendering enabled for OMP titles whose cwd is Gemini', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks6 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-omp-gemini-cwd')
|
||||
transportFactoryQueue.push(transport)
|
||||
enableActiveRuntimeEnvironment()
|
||||
mockStoreState.tabsByWorktree = {
|
||||
'wt-1': [{ id: 'tab-1', ptyId: 'tab-pty', launchAgent: 'omp' }]
|
||||
}
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
manager.getActivePane.mockReturnValue({ id: 1 })
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
...mockPanePtyArgs(pane, manager, bindPaneAgentTitleMocks(deps, agentTitleMocks6))
|
||||
)
|
||||
|
||||
const titleHandler = createdTransportOptions[0]?.onTitleChange as
|
||||
| ((title: string, rawTitle: string) => void)
|
||||
| undefined
|
||||
if (!titleHandler) {
|
||||
throw new Error('Expected onTitleChange to be registered')
|
||||
}
|
||||
|
||||
manager.setPaneGpuRendering.mockClear()
|
||||
|
||||
titleHandler('\u280b Pi', '\u280b π: gemini')
|
||||
|
||||
expect(manager.setPaneGpuRendering).toHaveBeenCalledTimes(1)
|
||||
expect(manager.setPaneGpuRendering).toHaveBeenCalledWith(1, true)
|
||||
expect(deps.setRuntimePaneTitle).toHaveBeenCalledWith('tab-1', 1, '\u280b OMP')
|
||||
expect(deps.updateTabTitle).toHaveBeenCalledWith('tab-1', '\u280b OMP')
|
||||
})
|
||||
|
||||
it('leaves local IPC OSC 9999 status ownership in the main runtime', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks7 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport('pty-local')
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
...mockPanePtyArgs(pane, manager, bindPaneAgentTitleMocks(deps, agentTitleMocks7))
|
||||
)
|
||||
|
||||
expect(createdTransportOptions[0]?.onAgentStatus).toBeUndefined()
|
||||
})
|
||||
|
||||
it('queues the idle cursor reset behind hidden agent output', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks8 =
|
||||
@@ -431,126 +275,6 @@ export function registerPtyConnectionTaskCompleteDispatchTests(): void {
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(`\x1b[6 q${RESET_TERMINAL_CURSOR_STYLE}`)
|
||||
})
|
||||
|
||||
it('waits briefly for delayed agent status before dispatching task-complete', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks9 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const { useNotificationDispatch } = await vi.importActual<
|
||||
typeof UseNotificationDispatchModule
|
||||
>('../../notifications/use-notification-dispatch')
|
||||
const transport = createMockTransport()
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
vi.useFakeTimers()
|
||||
const dispatchNotification = useNotificationDispatch('wt-1')
|
||||
const paneKey = makePaneKey('tab-1', LEAF_1)
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({ dispatchNotification })
|
||||
|
||||
connectPanePty(
|
||||
...mockPanePtyArgs(pane, manager, bindPaneAgentTitleMocks(deps, agentTitleMocks9))
|
||||
)
|
||||
|
||||
const idleHandler = createdTransportOptions[0]?.onAgentBecameIdle as
|
||||
| ((title: string) => void)
|
||||
| undefined
|
||||
if (!idleHandler) {
|
||||
throw new Error('Expected onAgentBecameIdle to be registered')
|
||||
}
|
||||
|
||||
idleHandler('* Codex done')
|
||||
expect(window.api.notifications.dispatch).not.toHaveBeenCalled()
|
||||
|
||||
mockStoreState.agentStatusByPaneKey[paneKey] = {
|
||||
state: 'done',
|
||||
prompt: 'Use delayed hook status in notification',
|
||||
updatedAt: Date.now(),
|
||||
stateStartedAt: Date.now(),
|
||||
agentType: 'codex',
|
||||
paneKey,
|
||||
terminalTitle: '* Codex done',
|
||||
stateHistory: [],
|
||||
lastAssistantMessage: 'Delayed status arrived.'
|
||||
}
|
||||
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(window.api.notifications.dispatch).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
source: 'agent-task-complete',
|
||||
terminalTitle: '* Codex done',
|
||||
agentType: 'codex',
|
||||
agentState: 'done',
|
||||
agentPrompt: 'Use delayed hook status in notification',
|
||||
agentLastAssistantMessage: 'Delayed status arrived.'
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('waits past the grace delay when the assistant message arrives shortly after it', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks10 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const { useNotificationDispatch } = await vi.importActual<
|
||||
typeof UseNotificationDispatchModule
|
||||
>('../../notifications/use-notification-dispatch')
|
||||
const transport = createMockTransport()
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
vi.useFakeTimers()
|
||||
const dispatchNotification = useNotificationDispatch('wt-1')
|
||||
const paneKey = makePaneKey('tab-1', LEAF_1)
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({ dispatchNotification })
|
||||
|
||||
connectPanePty(
|
||||
...mockPanePtyArgs(pane, manager, bindPaneAgentTitleMocks(deps, agentTitleMocks10))
|
||||
)
|
||||
|
||||
const idleHandler = createdTransportOptions[0]?.onAgentBecameIdle as
|
||||
| ((title: string) => void)
|
||||
| undefined
|
||||
if (!idleHandler) {
|
||||
throw new Error('Expected onAgentBecameIdle to be registered')
|
||||
}
|
||||
|
||||
idleHandler('* Codex done')
|
||||
vi.advanceTimersByTime(250)
|
||||
await flushAsyncTicks()
|
||||
expect(window.api.notifications.dispatch).not.toHaveBeenCalled()
|
||||
|
||||
vi.advanceTimersByTime(100)
|
||||
mockStoreState.agentStatusByPaneKey[paneKey] = {
|
||||
state: 'done',
|
||||
prompt: 'Use the late hook status in notification',
|
||||
updatedAt: Date.now(),
|
||||
stateStartedAt: Date.now(),
|
||||
agentType: 'codex',
|
||||
paneKey,
|
||||
terminalTitle: '* Codex done',
|
||||
stateHistory: [],
|
||||
lastAssistantMessage: 'Late status arrived.'
|
||||
}
|
||||
notifyStoreSubscribers()
|
||||
await flushAsyncTicks()
|
||||
vi.advanceTimersByTime(AGENT_TASK_COMPLETE_NOTIFICATION_MAX_WAIT_MS - 350)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(window.api.notifications.dispatch).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
source: 'agent-task-complete',
|
||||
terminalTitle: '* Codex done',
|
||||
agentType: 'codex',
|
||||
agentState: 'done',
|
||||
agentPrompt: 'Use the late hook status in notification',
|
||||
agentLastAssistantMessage: 'Late status arrived.'
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('does not use stale agent status from an earlier turn in task-complete notifications', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks11 =
|
||||
@@ -610,90 +334,5 @@ export function registerPtyConnectionTaskCompleteDispatchTests(): void {
|
||||
expect('agentLastAssistantMessage' in dispatchArgs).toBe(false)
|
||||
expect('agentType' in dispatchArgs).toBe(false)
|
||||
})
|
||||
|
||||
it('does not attach agent fields to terminal-bell notifications', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks12 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const { useNotificationDispatch } = await vi.importActual<
|
||||
typeof UseNotificationDispatchModule
|
||||
>('../../notifications/use-notification-dispatch')
|
||||
const transport = createMockTransport()
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const dispatchNotification = useNotificationDispatch('wt-1')
|
||||
const paneKey = makePaneKey('tab-1', LEAF_1)
|
||||
mockStoreState.agentStatusByPaneKey[paneKey] = {
|
||||
state: 'done',
|
||||
prompt: 'Should not leak into BEL',
|
||||
updatedAt: Date.now(),
|
||||
stateStartedAt: Date.now(),
|
||||
agentType: 'codex',
|
||||
paneKey,
|
||||
stateHistory: []
|
||||
}
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps({ dispatchNotification })
|
||||
|
||||
connectPanePty(
|
||||
...mockPanePtyArgs(pane, manager, bindPaneAgentTitleMocks(deps, agentTitleMocks12))
|
||||
)
|
||||
|
||||
const bellHandler = createdTransportOptions[0]?.onBell as (() => void) | undefined
|
||||
if (!bellHandler) {
|
||||
throw new Error('Expected onBell to be registered')
|
||||
}
|
||||
|
||||
vi.useFakeTimers()
|
||||
bellHandler()
|
||||
vi.advanceTimersByTime(250)
|
||||
|
||||
const dispatchArgs = (window.api.notifications.dispatch as ReturnType<typeof vi.fn>).mock
|
||||
.calls[0]?.[0] as Record<string, unknown> | undefined
|
||||
if (!dispatchArgs) {
|
||||
throw new Error('Expected notification dispatch')
|
||||
}
|
||||
expect(dispatchArgs.source).toBe('terminal-bell')
|
||||
expect('agentType' in dispatchArgs).toBe(false)
|
||||
expect('agentState' in dispatchArgs).toBe(false)
|
||||
expect('agentPrompt' in dispatchArgs).toBe(false)
|
||||
expect('agentToolName' in dispatchArgs).toBe(false)
|
||||
expect('agentToolInput' in dispatchArgs).toBe(false)
|
||||
expect('agentLastAssistantMessage' in dispatchArgs).toBe(false)
|
||||
expect('agentTurnOutcome' in dispatchArgs).toBe(false)
|
||||
})
|
||||
|
||||
// Why: agent-row removal belongs to process/PTY lifecycle, not title reversion, so interrupts can't disappear the activity row.
|
||||
it('clears the cache timer without removing agent status when the title tracker sees exit', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks13 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
...mockPanePtyArgs(pane, manager, bindPaneAgentTitleMocks(deps, agentTitleMocks13))
|
||||
)
|
||||
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: Captured transport options expose onAgentExited as an optional zero-argument callback.
|
||||
const agentExitedHandler = createdTransportOptions[0]?.onAgentExited as
|
||||
| (() => void)
|
||||
| undefined
|
||||
if (!agentExitedHandler) {
|
||||
throw new Error('Expected onAgentExited to be registered')
|
||||
}
|
||||
|
||||
agentExitedHandler()
|
||||
|
||||
expect(deps.setCacheTimerStartedAt).toHaveBeenCalledWith(makePaneKey('tab-1', LEAF_1), null)
|
||||
expect(deps.onAgentExitedRef.current).toHaveBeenCalledWith(LEAF_1)
|
||||
expect(mockStoreState.removeAgentStatus).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
-257
@@ -1,257 +0,0 @@
|
||||
import {
|
||||
bindPtyConnectionTestMocks,
|
||||
ptyConnectionTestMocks
|
||||
} from '../test-fixtures/pty-connection-mocks.spec'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushAsyncTicks } from '../test-fixtures/pty-connection-test-async'
|
||||
import { temporarilySetNavigatorUserAgent } from '../test-fixtures/pty-connection-test-dom'
|
||||
import {
|
||||
createMockTransport,
|
||||
createPane,
|
||||
createManager,
|
||||
type ConnectCallbacks,
|
||||
type MockTransport
|
||||
} from '../test-fixtures/pty-connection-test-pane-fixtures'
|
||||
import {
|
||||
buildPaneConnectionDeps,
|
||||
type PtyConnectionAgentTitleMocks,
|
||||
bindPaneAgentTitleMocks
|
||||
} from '../test-fixtures/pty-connection-test-deps'
|
||||
import { createInitialStoreState } from '../test-fixtures/pty-connection-test-store-fixtures'
|
||||
import type { StoreState } from '../test-fixtures/pty-connection-test-store-state'
|
||||
import {
|
||||
installTerminalTestGlobals,
|
||||
loadFreshTerminalModules,
|
||||
restoreTerminalTestGlobals
|
||||
} from '../test-fixtures/pty-connection-test-environment'
|
||||
|
||||
export function registerPtyConnectionRendererRiskRepaintTests(): void {
|
||||
const { resetAndRefreshAllTerminalWebglAtlases, scheduleTerminalWebglAtlasRecovery } =
|
||||
ptyConnectionTestMocks
|
||||
|
||||
let mockStoreState: StoreState
|
||||
let transportFactoryQueue: MockTransport[] = []
|
||||
let createdTransportOptions: Record<string, unknown>[] = []
|
||||
let storeSubscribers: ((state: StoreState) => void)[] = []
|
||||
|
||||
function createDeps(overrides: Record<string, unknown> = {}) {
|
||||
return buildPaneConnectionDeps(() => mockStoreState, overrides)
|
||||
}
|
||||
|
||||
function expectNoGlobalAtlasRecovery(): void {
|
||||
// Why: the removed output path requested recovery 200ms before its global reset ran.
|
||||
expect(scheduleTerminalWebglAtlasRecovery).not.toHaveBeenCalled()
|
||||
expect(resetAndRefreshAllTerminalWebglAtlases).not.toHaveBeenCalled()
|
||||
}
|
||||
|
||||
describe('connectPanePty', () => {
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks()
|
||||
transportFactoryQueue = []
|
||||
createdTransportOptions = []
|
||||
storeSubscribers = []
|
||||
mockStoreState = createInitialStoreState(() => mockStoreState)
|
||||
bindPtyConnectionTestMocks({
|
||||
getState: () => mockStoreState,
|
||||
getTransportQueue: () => transportFactoryQueue,
|
||||
getTransportOptions: () => createdTransportOptions,
|
||||
getStoreSubscribers: () => storeSubscribers,
|
||||
setStoreSubscribers: (subscribers) => {
|
||||
storeSubscribers = subscribers
|
||||
}
|
||||
})
|
||||
await installTerminalTestGlobals()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await restoreTerminalTestGlobals()
|
||||
})
|
||||
|
||||
it('does not switch renderers for Arabic output', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks)
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
capturedDataCallback.current?.('Arabic: السلام عليكم\r\n')
|
||||
|
||||
expect(manager.markPaneHasComplexScriptOutput).not.toHaveBeenCalled()
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(
|
||||
'Arabic: السلام عليكم\r\n',
|
||||
expect.any(Function)
|
||||
)
|
||||
})
|
||||
|
||||
it('does not switch renderers across split background SGR PTY chunks', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks2 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks2)
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
capturedDataCallback.current?.('\x1b[4')
|
||||
capturedDataCallback.current?.('8;2;52')
|
||||
expect(manager.markPaneHasComplexScriptOutput).not.toHaveBeenCalled()
|
||||
|
||||
capturedDataCallback.current?.(';52;52m codex block \x1b[0m\r\n')
|
||||
|
||||
expect(manager.markPaneHasComplexScriptOutput).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('avoids atlas clears for captured redraw chunks split mid-sequence', async () => {
|
||||
const restoreNavigator = temporarilySetNavigatorUserAgent('Mozilla/5.0 (Macintosh)')
|
||||
await loadFreshTerminalModules()
|
||||
try {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks10 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
;(pane.terminal.buffer.active as { type: 'normal' | 'alternate' }).type = 'alternate'
|
||||
const refresh = vi.fn()
|
||||
let parseCallback: (() => void) | undefined
|
||||
const terminal = pane.terminal as typeof pane.terminal & {
|
||||
_core?: { refresh: typeof refresh }
|
||||
}
|
||||
terminal._core = { refresh }
|
||||
terminal.write = vi.fn((_data: string | Uint8Array, callback?: () => void) => {
|
||||
parseCallback = callback
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(createDeps() as never, agentTitleMocks10)
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
// Captured from a real vim session: a 1024-byte PTY read boundary cuts the cursor move \x1b[30;5H into "\x1b[30" + ";5H".
|
||||
capturedDataCallback.current?.('"rules": {\x1b[29;15H\x1b[K\x1b[30')
|
||||
parseCallback?.()
|
||||
|
||||
capturedDataCallback.current?.(
|
||||
';5H "js-combine-iterations": "off"\r\n }\x1b[31;6H\x1b[K\x1b[33;1H\x1b[?25h'
|
||||
)
|
||||
parseCallback?.()
|
||||
expect(refresh).toHaveBeenCalled()
|
||||
expectNoGlobalAtlasRecovery()
|
||||
} finally {
|
||||
restoreNavigator()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export function registerPtyConnectionRendererDrawingGlyphTests(): void {
|
||||
let mockStoreState: StoreState
|
||||
let transportFactoryQueue: MockTransport[] = []
|
||||
let createdTransportOptions: Record<string, unknown>[] = []
|
||||
let storeSubscribers: ((state: StoreState) => void)[] = []
|
||||
|
||||
function createDeps(overrides: Record<string, unknown> = {}) {
|
||||
return buildPaneConnectionDeps(() => mockStoreState, overrides)
|
||||
}
|
||||
describe('connectPanePty', () => {
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks()
|
||||
transportFactoryQueue = []
|
||||
createdTransportOptions = []
|
||||
storeSubscribers = []
|
||||
mockStoreState = createInitialStoreState(() => mockStoreState)
|
||||
bindPtyConnectionTestMocks({
|
||||
getState: () => mockStoreState,
|
||||
getTransportQueue: () => transportFactoryQueue,
|
||||
getTransportOptions: () => createdTransportOptions,
|
||||
getStoreSubscribers: () => storeSubscribers,
|
||||
setStoreSubscribers: (subscribers) => {
|
||||
storeSubscribers = subscribers
|
||||
}
|
||||
})
|
||||
await installTerminalTestGlobals()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await restoreTerminalTestGlobals()
|
||||
})
|
||||
|
||||
it('keeps terminal UI drawing glyphs on the active renderer', async () => {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const manager = createManager(1)
|
||||
const deps = createDeps()
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(deps as never, agentTitleMocks)
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
capturedDataCallback.current?.('⠋ Working ├─ file.ts █ progress \uE0B0 prompt\r\n')
|
||||
|
||||
expect(manager.markPaneHasComplexScriptOutput).not.toHaveBeenCalled()
|
||||
expect(pane.terminal.write).toHaveBeenCalledWith(
|
||||
'⠋ Working ├─ file.ts █ progress \uE0B0 prompt\r\n',
|
||||
expect.any(Function)
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
-382
@@ -1,382 +0,0 @@
|
||||
import {
|
||||
bindPtyConnectionTestMocks,
|
||||
ptyConnectionTestMocks
|
||||
} from '../test-fixtures/pty-connection-mocks.spec'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushAsyncTicks } from '../test-fixtures/pty-connection-test-async'
|
||||
import {
|
||||
temporarilySetNavigatorUserAgent,
|
||||
sendTerminalInputThroughPane
|
||||
} from '../test-fixtures/pty-connection-test-dom'
|
||||
import {
|
||||
createMockTransport,
|
||||
createPane,
|
||||
createManager,
|
||||
type ConnectCallbacks,
|
||||
type MockTransport
|
||||
} from '../test-fixtures/pty-connection-test-pane-fixtures'
|
||||
import {
|
||||
buildPaneConnectionDeps,
|
||||
type PtyConnectionAgentTitleMocks,
|
||||
bindPaneAgentTitleMocks
|
||||
} from '../test-fixtures/pty-connection-test-deps'
|
||||
import { createInitialStoreState } from '../test-fixtures/pty-connection-test-store-fixtures'
|
||||
import type { StoreState } from '../test-fixtures/pty-connection-test-store-state'
|
||||
import {
|
||||
installTerminalTestGlobals,
|
||||
loadFreshTerminalModules,
|
||||
restoreTerminalTestGlobals
|
||||
} from '../test-fixtures/pty-connection-test-environment'
|
||||
|
||||
export function registerPtyConnectionWindowsCjkRepaintTests(): void {
|
||||
const { resetAndRefreshAllTerminalWebglAtlases, scheduleTerminalWebglAtlasRecovery } =
|
||||
ptyConnectionTestMocks
|
||||
|
||||
let mockStoreState: StoreState
|
||||
let transportFactoryQueue: MockTransport[] = []
|
||||
let createdTransportOptions: Record<string, unknown>[] = []
|
||||
let storeSubscribers: ((state: StoreState) => void)[] = []
|
||||
|
||||
function createDeps(overrides: Record<string, unknown> = {}) {
|
||||
return buildPaneConnectionDeps(() => mockStoreState, overrides)
|
||||
}
|
||||
|
||||
function expectNoGlobalAtlasRecovery(): void {
|
||||
// Why: the removed output path requested recovery 200ms before its global reset ran.
|
||||
expect(scheduleTerminalWebglAtlasRecovery).not.toHaveBeenCalled()
|
||||
expect(resetAndRefreshAllTerminalWebglAtlases).not.toHaveBeenCalled()
|
||||
}
|
||||
|
||||
describe('connectPanePty', () => {
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks()
|
||||
transportFactoryQueue = []
|
||||
createdTransportOptions = []
|
||||
storeSubscribers = []
|
||||
mockStoreState = createInitialStoreState(() => mockStoreState)
|
||||
bindPtyConnectionTestMocks({
|
||||
getState: () => mockStoreState,
|
||||
getTransportQueue: () => transportFactoryQueue,
|
||||
getTransportOptions: () => createdTransportOptions,
|
||||
getStoreSubscribers: () => storeSubscribers,
|
||||
setStoreSubscribers: (subscribers) => {
|
||||
storeSubscribers = subscribers
|
||||
}
|
||||
})
|
||||
await installTerminalTestGlobals()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await restoreTerminalTestGlobals()
|
||||
})
|
||||
|
||||
it('does not schedule WebGL atlas recovery for plain synchronized foreground frames', async () => {
|
||||
const restoreNavigator = temporarilySetNavigatorUserAgent('Mozilla/5.0 (Macintosh)')
|
||||
await loadFreshTerminalModules()
|
||||
try {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks2 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
let parseCallback: (() => void) | undefined
|
||||
pane.terminal.write = vi.fn((_data: string | Uint8Array, callback?: () => void) => {
|
||||
parseCallback = callback
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(createDeps() as never, agentTitleMocks2)
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
capturedDataCallback.current?.('\x1b[?2026hplain claude frame\x1b[?2026l')
|
||||
parseCallback?.()
|
||||
expectNoGlobalAtlasRecovery()
|
||||
} finally {
|
||||
restoreNavigator()
|
||||
}
|
||||
})
|
||||
|
||||
it('forces a viewport refresh for native Windows CJK foreground output after terminal input', async () => {
|
||||
const restoreNavigator = temporarilySetNavigatorUserAgent(
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'
|
||||
)
|
||||
await loadFreshTerminalModules()
|
||||
try {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks6 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const refresh = vi.fn()
|
||||
const terminal = pane.terminal as typeof pane.terminal & {
|
||||
_core?: { refresh: typeof refresh }
|
||||
}
|
||||
terminal._core = { refresh }
|
||||
terminal.write = vi.fn((_data: string | Uint8Array, callback?: () => void) => {
|
||||
callback?.()
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(createDeps() as never, agentTitleMocks6)
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
sendTerminalInputThroughPane(pane, '已经安装完成,软件已更新后重启。')
|
||||
|
||||
capturedDataCallback.current?.('已经安装完成,软件已更新后重启。')
|
||||
|
||||
expect(refresh).toHaveBeenCalledWith(0, 39, true)
|
||||
} finally {
|
||||
restoreNavigator()
|
||||
}
|
||||
})
|
||||
|
||||
it('forces the native Windows CJK repaint path for foreground agent output without recent terminal input', async () => {
|
||||
const restoreNavigator = temporarilySetNavigatorUserAgent(
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'
|
||||
)
|
||||
await loadFreshTerminalModules()
|
||||
try {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks7 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const refresh = vi.fn()
|
||||
const terminal = pane.terminal as typeof pane.terminal & {
|
||||
_core?: { refresh: typeof refresh }
|
||||
}
|
||||
terminal._core = { refresh }
|
||||
terminal.write = vi.fn((_data: string | Uint8Array, callback?: () => void) => {
|
||||
callback?.()
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(createDeps() as never, agentTitleMocks7)
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
capturedDataCallback.current?.('已经安装完成,软件已更新后重启。')
|
||||
|
||||
expect(refresh).toHaveBeenCalledWith(0, 39, true)
|
||||
} finally {
|
||||
restoreNavigator()
|
||||
}
|
||||
})
|
||||
|
||||
it('does not force renderer-risk repaint for ordinary non-ASCII output', async () => {
|
||||
const restoreNavigator = temporarilySetNavigatorUserAgent(
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'
|
||||
)
|
||||
await loadFreshTerminalModules()
|
||||
try {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks8 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const refresh = vi.fn()
|
||||
const terminal = pane.terminal as typeof pane.terminal & {
|
||||
_core?: { refresh: typeof refresh }
|
||||
}
|
||||
terminal._core = { refresh }
|
||||
terminal.write = vi.fn((_data: string | Uint8Array, callback?: () => void) => {
|
||||
callback?.()
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(createDeps() as never, agentTitleMocks8)
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
sendTerminalInputThroughPane(pane, 'abc 123 ✓')
|
||||
|
||||
capturedDataCallback.current?.('abc 123 ✓')
|
||||
|
||||
expect(refresh).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
restoreNavigator()
|
||||
}
|
||||
})
|
||||
|
||||
it('does not repaint ordinary non-ASCII output on non-Windows clients', async () => {
|
||||
const restoreNavigator = temporarilySetNavigatorUserAgent('Mozilla/5.0 (Macintosh)')
|
||||
await loadFreshTerminalModules()
|
||||
try {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks9 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const refresh = vi.fn()
|
||||
const terminal = pane.terminal as typeof pane.terminal & {
|
||||
_core?: { refresh: typeof refresh }
|
||||
}
|
||||
terminal._core = { refresh }
|
||||
terminal.write = vi.fn((_data: string | Uint8Array, callback?: () => void) => {
|
||||
callback?.()
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(createDeps() as never, agentTitleMocks9)
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
capturedDataCallback.current?.('abc 123 ✓')
|
||||
|
||||
expect(refresh).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
restoreNavigator()
|
||||
}
|
||||
})
|
||||
|
||||
it('schedules a follow-up repaint for Claude-style in-place prompt redraws on native Windows', async () => {
|
||||
// Why: issue #5656/#5653 — native Windows ConPTY paints Claude's in-place prompt redraw one frame late; needs a follow-up next-frame repaint.
|
||||
const restoreNavigator = temporarilySetNavigatorUserAgent(
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'
|
||||
)
|
||||
await loadFreshTerminalModules()
|
||||
try {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks10 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const refresh = vi.fn()
|
||||
const terminal = pane.terminal as typeof pane.terminal & {
|
||||
_core?: { refresh: typeof refresh }
|
||||
}
|
||||
terminal._core = { refresh }
|
||||
terminal.write = vi.fn((_data: string | Uint8Array, callback?: () => void) => {
|
||||
callback?.()
|
||||
})
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
createManager(1) as never,
|
||||
bindPaneAgentTitleMocks(createDeps() as never, agentTitleMocks10)
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
// User typed into the prompt; Claude redraws the input line in place.
|
||||
capturedDataCallback.current?.('\r\x1b[3Gzzzx\x1b[K')
|
||||
|
||||
// One synchronous settle refresh + one follow-up next-frame refresh.
|
||||
expect(refresh).toHaveBeenCalledTimes(2)
|
||||
expect(refresh).toHaveBeenNthCalledWith(1, 0, 39, true)
|
||||
expect(refresh).toHaveBeenNthCalledWith(2, 0, 39, true)
|
||||
} finally {
|
||||
restoreNavigator()
|
||||
}
|
||||
})
|
||||
|
||||
it('coalesces forced foreground refreshes when WebGL is live', async () => {
|
||||
const restoreNavigator = temporarilySetNavigatorUserAgent('Mozilla/5.0 (Macintosh)')
|
||||
await loadFreshTerminalModules()
|
||||
try {
|
||||
const { connectPanePty } = await import('../connect-pane-pty')
|
||||
const agentTitleMocks12 =
|
||||
await vi.importMock<PtyConnectionAgentTitleMocks>('@/lib/agent-status')
|
||||
const transport = createMockTransport()
|
||||
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
|
||||
transport.connect.mockImplementation(
|
||||
async ({ callbacks }: { callbacks: ConnectCallbacks }) => {
|
||||
capturedDataCallback.current = callbacks.onData ?? null
|
||||
return 'pty-id'
|
||||
}
|
||||
)
|
||||
transportFactoryQueue.push(transport)
|
||||
|
||||
const pane = createPane(1)
|
||||
const synchronousRefresh = vi.fn()
|
||||
const debouncedRefresh = vi.fn()
|
||||
const terminal = pane.terminal as typeof pane.terminal & {
|
||||
_core?: { refresh: typeof synchronousRefresh }
|
||||
refresh: typeof debouncedRefresh
|
||||
}
|
||||
terminal._core = { refresh: synchronousRefresh }
|
||||
terminal.refresh = debouncedRefresh
|
||||
terminal.write = vi.fn((_data: string | Uint8Array, callback?: () => void) => callback?.())
|
||||
const manager = createManager(1)
|
||||
manager.hasWebglRenderer.mockReturnValue(true)
|
||||
|
||||
connectPanePty(
|
||||
pane as never,
|
||||
manager as never,
|
||||
bindPaneAgentTitleMocks(createDeps() as never, agentTitleMocks12)
|
||||
)
|
||||
await flushAsyncTicks(6)
|
||||
|
||||
capturedDataCallback.current?.('\r\x1b[3Gzzzx\x1b[K')
|
||||
|
||||
expect(debouncedRefresh).toHaveBeenCalledWith(0, 39)
|
||||
expect(synchronousRefresh).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
restoreNavigator()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
-2
@@ -1,7 +1,6 @@
|
||||
import { describe } from 'vitest'
|
||||
import { registerPtyConnectionCommandFinishedCleanupTests } from '../agent-identity/pty-connection-command-finished-cleanup.spec'
|
||||
import { registerPtyConnectionCommandFinishedInterruptArbitrationTests } from '../input/pty-connection-command-finished-interrupt-arbitration.spec'
|
||||
import { registerPtyConnectionHookCompletionBellArbitrationTests } from '../notifications/pty-connection-hook-completion-bell-arbitration.spec'
|
||||
import { registerPtyConnectionBellQueryReplyAndStaleInputTests } from '../input/pty-connection-bell-query-reply-and-stale-input.spec'
|
||||
import { registerPtyConnectionHookCompletionSideEffectsTests } from '../notifications/pty-connection-hook-completion-side-effects.spec'
|
||||
import { registerPtyConnectionMainSideEffectAuthorityTests } from '../emulation/pty-connection-main-side-effect-authority.spec'
|
||||
@@ -13,7 +12,6 @@ describe('pty-connection-command-finished-cleanup', () => {
|
||||
registerPtyConnectionCommandFinishedInterruptArbitrationTests()
|
||||
})
|
||||
describe('pty-connection-hook-completion-bell-arbitration', () => {
|
||||
registerPtyConnectionHookCompletionBellArbitrationTests()
|
||||
registerPtyConnectionBellQueryReplyAndStaleInputTests()
|
||||
})
|
||||
describe(
|
||||
|
||||
-4
@@ -15,8 +15,6 @@ import {
|
||||
registerPtyConnectionRemoteWindowsFocusReportTests,
|
||||
registerPtyConnectionWindowsFocusReportAuthorityTests
|
||||
} from '../input/pty-connection-windows-focus-report-authority.spec'
|
||||
import { registerPtyConnectionWindowsCjkRepaintTests } from '../output/pty-connection-windows-cjk-repaint.spec'
|
||||
import { registerPtyConnectionRendererRiskRepaintTests } from '../output/pty-connection-renderer-risk-repaint.spec'
|
||||
import { registerPtyConnectionTerminalInputGatingTests } from '../input/pty-connection-terminal-input-gating.spec'
|
||||
|
||||
// Main's answer to the window's layout commands, as a switch-on build sends them.
|
||||
@@ -40,6 +38,4 @@ describe('pty-connection-windows-keyboard-reset', () => {
|
||||
registerPtyConnectionWindowsFocusReportAuthorityTests()
|
||||
registerPtyConnectionWindowsCursorResetDisposalTests()
|
||||
})
|
||||
describe('pty-connection-windows-cjk-repaint', registerPtyConnectionWindowsCjkRepaintTests)
|
||||
describe('pty-connection-renderer-risk-repaint', registerPtyConnectionRendererRiskRepaintTests)
|
||||
describe('pty-connection-terminal-input-gating', registerPtyConnectionTerminalInputGatingTests)
|
||||
|
||||
-2
@@ -1,4 +1,3 @@
|
||||
import { registerPtyConnectionRendererDrawingGlyphTests } from '../output/pty-connection-renderer-risk-repaint.spec'
|
||||
import { describe } from 'vitest'
|
||||
import { registerPtyConnectionPendingSpawnTests } from '../spawn/pty-connection-pending-spawn.spec'
|
||||
import { registerPtyConnectionFreshSpawnGuardsTests } from '../spawn/pty-connection-fresh-spawn-guards.spec'
|
||||
@@ -30,7 +29,6 @@ describe('pty-connection-startup-command-delivery', () => {
|
||||
describe('pty-connection-startup-draft-delivery', registerPtyConnectionStartupDraftDeliveryTests)
|
||||
describe('pty-connection-deliberate-sleep-guard', registerPtyConnectionDeliberateSleepGuardTests)
|
||||
describe('pty-connection-remote-runtime-attach', () => {
|
||||
registerPtyConnectionRendererDrawingGlyphTests()
|
||||
registerPtyConnectionRemoteRuntimeAttachTests()
|
||||
registerPtyConnectionRuntimePaneTransportRoutingTests()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user