Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
// Minimal shapes for types coming from the Copilot SDK we interact with
interface
MockSdkEventHandler
{
(
:
unknown
)
:
void
}
type
MockSdkEventMap
=
<
string
,
<
>>
;
class
MockSdkSession
{
:
=
new
Map
(
)
;
public
=
'mock-session-id'
;
public
:
string
|
undefined
=
'modelA'
;
public
:
unknown
;
private
=
new
Map<string,{resolve:(result:unknown)=>
void
}
>
(
)
;
private
=
0
;
private
=
new
Map<string,{resolve:(result:unknown)=>
void
}
>
(
)
;
private
=
0
;
private
=
new
Map<string,{resolve:(result:unknown)=>
void
}
>
(
)
;
private
=
0
;
public
=
false
;
on
(
:
string
,
:
)
{
if
(
!
this
.
.
has
(
)
)
{
this
.
.
set
(
,
new
Set
(
)
)
;
}
this
.
.
get
(
)
!
.
add
(
)
;
return
(
)
=>
this
.
.
get
(
)
!
.
delete
(
)
;
}
emit
(
:
string
,
:
unknown
)
{
this
.
.
get
(
)
?.
forEach
(
=>
h
(
{
}
)
)
;
}
/**
* Simulate the SDK emitting a permission.requested event and await the response.
* The session's event handler will call respondToPermission() which resolves the returned promise.
*/
async
emitPermissionRequest
(
:
)
:
Promise
<
unknown
>
{
const
=
`perm-${++this._permissionCounter}`
;
return
new
Promise
(
=>
{
this
.
.
set
(
,
{
}
)
;
this
.
emit
(
'permission.requested'
,
{
,
}
)
;
}
)
;
}
respondToPermission
(
:
string
,
:
unknown
)
{
const
=
this
.
.
get
(
)
;
if
(
)
{
.
resolve
(
)
;
this
.
.
delete
(
)
;
}
}
async
emitUserInputRequest
(
:
{
:
string
;
?
:
string
[
]
;
?
:
boolean
;
?
:
string
}
)
:
Promise
<
unknown
>
{
const
=
`user-input-${++this._userInputCounter}`
;
return
new
Promise
(
=>
{
this
.
.
set
(
,
{
}
)
;
this
.
emit
(
'user_input.requested'
,
{
,
...
}
)
;
}
)
;
}
/**
* Simulate the SDK emitting an exit_plan_mode.requested event and await the response.
* The session's event handler will call respondToExitPlanMode() which resolves the returned promise.
*/
async
emitExitPlanModeRequest
(
:
{
:
string
;
?
:
string
[
]
}
)
:
Promise
<
unknown
>
{
const
=
`exit-plan-${++this._exitPlanModeCounter}`
;
return
new
Promise
(
=>
{
this
.
.
set
(
,
{
}
)
;
this
.
emit
(
'exit_plan_mode.requested'
,
{
,
...
}
)
;
}
)
;
}
respondToExitPlanMode
(
:
string
,
:
unknown
)
{
const
=
this
.
.
get
(
)
;
if
(
)
{
.
resolve
(
)
;
this
.
.
delete
(
)
;
}
}
respondToUserInput
(
:
string
,
:
unknown
)
{
const
=
this
.
.
get
(
)
;
if
(
)
{
.
resolve
(
)
;
this
.
.
delete
(
)
;
}
}
public
:
{
:
string
;
?
:
string
;
?
:
string
;
?
:
string
}
|
undefined
;
public
:
string
|
undefined
;
async
send
(
:
{
:
string
;
?
:
string
;
?
:
string
;
?
:
string
}
)
{
this
.
=
;
// Simulate a normal successful turn with a message
this
.
emit
(
'user.message'
,
{
:
.
}
)
;
this
.
emit
(
'assistant.turn_start'
,
{
}
)
;
this
.
emit
(
'assistant.message'
,
{
:
`msg_${Date.now()}`
,
:
`Echo: ${options.prompt}`
}
)
;
this
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
async
compactHistory
(
)
{
return
{
:
true
}
;
}
async
abort
(
)
{
this
.
=
true
;
}
isAbortable
(
)
:
boolean
{
return
true
;
}
async
initializeAndValidateTools
(
)
{
}
getCurrentToolMetadata
(
)
:
unknown
[
]
|
undefined
{
return
this
.
;
}
private
:
unknown
[
]
|
undefined
;
set
toolMetadata
(
:
unknown
[
]
|
undefined
)
{
this
.
=
;
}
setAuthInfo
(
:
any
)
{
this
.
=
;
}
public
:
unknown
;
public
:
unknown
[
]
=
[
]
;
updateOptions
(
:
{
?
:
unknown
;
?
:
unknown
}
)
{
if
(
.
!==
undefined
)
{
this
.
=
.
;
}
if
(
.
!==
undefined
)
{
this
.
=
.
;
this
.
.
push
(
.
)
;
}
}
async
getSelectedModel
(
)
{
return
this
.
;
}
async
setSelectedModel
(
:
string
,
?
:
string
)
{
this
.
=
;
}
getReasoningEffort
(
)
:
string
|
undefined
{
return
undefined
;
}
async
getEvents
(
)
{
return
[
]
;
}
getPlanPath
(
)
:
string
|
null
{
return
null
;
}
=
{
getMetrics
:
async
(
)
=>
(
{
:
100
,
:
50
,
:
0
,
:
1
,
:
1000
,
:
.
now
(
)
,
:
{
:
0
,
:
0
,
:
0
}
,
:
{
}
,
:
this
.
,
}
)
,
}
;
}
function
createWorkspaceService
(
:
string
)
:
{
const
=
.
file
(
)
;
return
new
class
extends
TestWorkspaceService
{
getWorkspaceFolders
(
)
{
return
[
]
;
}
getWorkspaceFolder
(
:
)
{
return
.
.
startsWith
(
.
)
?
:
undefined
;
}
}
;
}
function
workspaceInfoFor
(
:
|
undefined
)
:
{
return
{
:
,
:
undefined
,
:
undefined
,
:
undefined
,
}
;
}
class
UsageCapturingStream
extends
MockChatResponseStream
{
public
readonly
:
import
(
'vscode'
)
.
[
]
=
[
]
;
constructor
(
)
{
super
(
)
;
}
usage
(
:
import
(
'vscode'
)
.
)
:
void
{
this
.
.
push
(
)
;
}
}
describe
(
'CopilotCLISession'
,
(
)
=>
{
const
=
new
DisposableStore
(
)
;
let
:
;
let
:
;
let
:
;
let
:
;
let
:
string
|
undefined
;
let
:
;
let
:
;
let
:
;
let
:
;
let
:
;
let
:
<
[
'authInfo'
]
>
;
let
:
|
undefined
;
let
:
;
let
:
[
]
;
beforeEach
(
async
(
)
=>
{
const
=
.
add
(
createExtensionUnitTestingServices
(
)
)
;
const
=
.
createTestingAccessor
(
)
;
=
.
get
(
)
;
=
new
NullRequestLogger
(
)
;
=
{
:
'token'
,
:
''
,
:
'https://github.com'
}
;
=
new
MockChatSessionMetadataStore
(
)
;
=
new
MockSdkSession
(
)
;
=
createWorkspaceService
(
'/workspace'
)
;
=
workspaceInfoFor
(
.
getWorkspaceFolders
(
)
!
[
0
]
)
;
=
undefined
;
=
.
get
(
)
;
await
.
setConfig
(
.
.
,
true
)
;
=
.
seal
(
)
;
=
new
FakeToolsService
(
)
;
=
undefined
;
=
new
NullTelemetryService
(
)
;
=
[
]
;
}
)
;
afterEach
(
(
)
=>
{
.
restoreAllMocks
(
)
;
.
clear
(
)
;
}
)
;
async
function
createSession
(
?
:
{
?
:
boolean
}
)
:
Promise
<
>
{
return
createSessionWith
(
new
NoopOTelService
(
resolveOTelConfig
(
{
:
{
}
,
:
'0.0.0'
,
:
'test'
}
)
)
,
?.
??
false
)
;
}
async
function
createSessionWith
(
:
,
=
false
)
:
Promise
<
>
{
class
FakeUserQuestionHandler
implements
IUserQuestionHandler
{
:
undefined
;
async
askUserQuestion
(
:
,
:
,
:
,
?
:
string
)
:
Promise
<
|
undefined
>
{
return
;
}
}
const
=
?
{
:
true
as
const
,
:
{
:
{
}
,
:
{
:
false
}
}
}
:
undefined
;
return
.
add
(
new
CopilotCLISession
(
,
,
as
unknown
as
,
[
]
,
as
any
,
,
,
,
,
,
new
NullICopilotCLIImageSupport
(
)
,
,
new
FakeUserQuestionHandler
(
)
,
,
,
new
MockGitService
(
)
,
{
:
undefined
}
as
any
,
{
:
undefined
,
resetTurnCredits
(
)
{
}
,
getCreditsForTurn
(
)
{
return
undefined
;
}
,
setLastCopilotUsage
(
)
{
}
,
processQuotaSnapshots
(
:
)
{
.
push
(
)
;
}
}
as
any
,
)
)
;
}
it
(
'handles a successful request and streams assistant output'
,
async
(
)
=>
{
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
// Attach stream first, then invoke with new signature (no stream param)
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Hello'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
.
)
.
toBe
(
.
)
;
expect
(
.
.
join
(
'\n'
)
)
.
toContain
(
'Echo: Hello'
)
;
// Listeners are disposed after completion, so we only assert original streamed content.
}
)
;
it
(
'synthesizes chat and execute_tool spans for the in-process CLI turn'
,
async
(
)
=>
{
.
send
=
async
(
{
}
)
=>
{
.
emit
(
'user.message'
,
{
:
}
)
;
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'tool.execution_start'
,
{
:
'tc1'
,
:
'bash'
,
:
{
:
'ls'
}
}
)
;
.
emit
(
'tool.execution_complete'
,
{
:
'tc1'
,
:
true
,
:
{
:
'file.txt'
}
}
)
;
.
emit
(
'assistant.usage'
,
{
:
'claude-x'
,
:
100
,
:
20
,
:
5
}
)
;
.
emit
(
'assistant.message'
,
{
:
'm1'
,
:
'Done!'
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
new
CapturingOTelService
(
)
;
const
=
await
createSessionWith
(
)
;
.
attachStream
(
new
MockChatResponseStream
(
)
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Run ls'
}
,
[
]
,
undefined
,
,
.
)
;
const
[
]
=
.
findSpans
(
'chat'
)
;
const
[
]
=
.
findSpans
(
'execute_tool'
)
;
expect
(
{
:
{
:
?.
,
:
?.
,
:
?.
[
.
REQUEST_MODEL
]
,
:
?.
[
.
USAGE_INPUT_TOKENS
]
,
:
?.
[
.
USAGE_OUTPUT_TOKENS
]
,
:
?.
[
.
USAGE_CACHE_READ_INPUT_TOKENS
]
,
:
?.
[
.
OUTPUT_MESSAGES
]
,
:
?.
!==
undefined
,
}
,
:
{
:
?.
,
:
?.
,
:
?.
[
.
TOOL_NAME
]
,
:
?.
[
.
TOOL_CALL_RESULT
]
,
:
?.
!==
undefined
,
}
,
}
)
.
toEqual
(
{
:
{
:
'chat claude-x'
,
:
.
CLIENT
,
:
'claude-x'
,
:
100
,
:
20
,
:
5
,
:
JSON
.
stringify
(
[
{
:
'assistant'
,
:
[
{
:
'text'
,
:
'Done!'
}
]
}
]
)
,
:
true
,
}
,
:
{
:
'execute_tool bash'
,
:
.
INTERNAL
,
:
'bash'
,
:
'file.txt'
,
:
true
,
}
,
}
)
;
}
)
;
it
(
'routes in-flight output to the latest attached stream'
,
async
(
)
=>
{
let
!
:
(
)
=>
void
;
let
!
:
(
)
=>
void
;
const
=
new
Promise<void>
(
=>
{
=
;
}
)
;
.
send
=
async
(
{
}
)
=>
{
.
emit
(
'user.message'
,
{
:
}
)
;
markSendStarted
(
)
;
await
new
Promise<void>
(
=>
{
=
;
}
)
;
.
emit
(
'assistant.message'
,
{
:
'after-reattach'
,
:
'After reattach'
}
)
;
}
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
const
=
.
add
(
.
attachStream
(
)
)
;
const
=
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Hello'
}
,
[
]
,
undefined
,
,
.
)
;
await
;
const
=
new
MockChatResponseStream
(
)
;
.
add
(
.
attachStream
(
)
)
;
.
dispose
(
)
;
continueSend
(
)
;
await
;
expect
(
.
.
join
(
'\n'
)
)
.
.
toContain
(
'After reattach'
)
;
expect
(
.
.
join
(
'\n'
)
)
.
toContain
(
'After reattach'
)
;
}
)
;
it
(
'routed response stream is not thenable'
,
async
(
)
=>
{
const
=
await
createSession
(
)
;
const
=
(
as
unknown
as
{
readonly
:
unknown
}
)
.
;
await
expect
(
Promise
.
race
(
[
Promise
.
resolve
(
)
.
then
(
=>
===
)
,
new
Promise<boolean>
(
=>
setTimeout
(
(
)
=>
resolve
(
false
)
,
10
)
)
,
]
)
)
.
.
toBe
(
true
)
;
}
)
;
it
(
'drops writes to a closed attached stream'
,
async
(
)
=>
{
class
ClosedChatResponseStream
extends
MockChatResponseStream
{
markdown
(
)
:
void
{
throw
new
Error
(
'Response stream has been closed'
)
;
}
}
.
send
=
async
(
)
=>
{
.
emit
(
'assistant.message'
,
{
:
'closed-stream'
,
:
'Dropped'
}
)
;
}
;
const
=
await
createSession
(
)
;
.
add
(
.
attachStream
(
new
ClosedChatResponseStream
(
)
)
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Hello'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
.
)
.
toBe
(
.
)
;
}
)
;
it
(
'falls back when async stream methods reject as closed'
,
async
(
)
=>
{
class
ClosedExternalEditStream
extends
MockChatResponseStream
{
externalEdit
(
)
:
Promise
<
string
>
{
return
Promise
.
reject
(
new
Error
(
'Response stream has been closed'
)
)
;
}
}
const
=
await
createSession
(
)
;
.
add
(
.
attachStream
(
new
ClosedExternalEditStream
(
)
)
)
;
const
=
(
as
unknown
as
{
readonly
:
}
)
.
;
let
=
false
;
await
expect
(
.
externalEdit
(
.
file
(
'/workspace/file.ts'
)
,
async
(
)
=>
{
=
true
;
}
)
)
.
.
toBe
(
''
)
;
expect
(
)
.
toBe
(
true
)
;
}
)
;
it
(
'does not re-invoke externalEdit callback when the underlying call already started it'
,
async
(
)
=>
{
class
MidFlightCloseStream
extends
MockChatResponseStream
{
async
externalEdit
(
:
|
[
]
,
callback
:
(
)
=>
<
unknown
>
)
:
Promise
<
string
>
{
await
callback
(
)
;
throw
new
Error
(
'Response stream has been closed'
)
;
}
}
const
=
await
createSession
(
)
;
.
add
(
.
attachStream
(
new
MidFlightCloseStream
(
)
)
)
;
const
=
(
as
unknown
as
{
readonly
:
}
)
.
;
let
=
0
;
await
expect
(
.
externalEdit
(
.
file
(
'/workspace/file.ts'
)
,
async
(
)
=>
{
++
;
}
)
)
.
.
toBe
(
''
)
;
expect
(
)
.
toBe
(
1
)
;
}
)
;
it
(
'switches model when different modelId provided'
,
async
(
)
=>
{
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Hi'
}
,
[
]
,
{
:
'modelB'
}
,
,
.
)
;
expect
(
.
)
.
toBe
(
'modelB'
)
;
}
)
;
it
(
'fails request when underlying send throws'
,
async
(
)
=>
{
// Force send to throw
.
send
=
async
(
)
=>
{
throw
new
Error
(
'network'
)
;
}
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Boom'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
.
)
.
toBe
(
.
)
;
expect
(
.
.
join
(
'\n'
)
)
.
toContain
(
'Error: network'
)
;
}
)
;
it
(
'emits status events on successful request'
,
async
(
)
=>
{
const
=
await
createSession
(
)
;
const
:
(
|
undefined
)
[
]
=
[
]
;
const
=
.
add
(
.
onDidChangeStatus
(
=>
.
push
(
)
)
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Status OK'
}
,
[
]
,
{
:
'modelA'
}
,
,
.
)
;
.
?.
(
)
;
expect
(
)
.
toEqual
(
[
.
,
.
]
)
;
expect
(
.
)
.
toBe
(
.
)
;
}
)
;
it
(
'emits status events on failed request'
,
async
(
)
=>
{
// Force failure
.
send
=
async
(
)
=>
{
throw
new
Error
(
'boom'
)
;
}
;
const
=
await
createSession
(
)
;
const
:
(
|
undefined
)
[
]
=
[
]
;
const
=
.
add
(
.
onDidChangeStatus
(
=>
.
push
(
)
)
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Will Fail'
}
,
[
]
,
undefined
,
,
.
)
;
.
?.
(
)
;
expect
(
.
.
join
(
'\n'
)
)
.
toContain
(
'Error: boom'
)
;
}
)
;
it
(
'auto-approves read permission inside workspace without external handler'
,
async
(
)
=>
{
let
:
unknown
;
.
send
=
async
(
{
}
:
any
)
=>
{
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'assistant.message'
,
{
:
`Echo: ${prompt}`
}
)
;
// Mid way through, make it look like the sdk requested permission while emitting other messages.
=
await
.
emitPermissionRequest
(
{
:
'read'
,
:
.
join
(
'/workspace'
,
'file.ts'
)
,
:
'Read file'
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
// Path must be absolute within workspace, should auto-approve
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Test'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
)
.
toEqual
(
{
:
'approve-once'
}
)
;
}
)
;
it
(
'auto-approves read permission for files in session state directory'
,
async
(
)
=>
{
let
:
unknown
;
const
=
.
join
(
'/mock-session-state'
,
'mock-session-id'
,
'plan.md'
)
;
.
send
=
async
(
{
}
:
any
)
=>
{
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'assistant.message'
,
{
:
`Echo: ${prompt}`
}
)
;
=
await
.
emitPermissionRequest
(
{
:
'read'
,
:
,
:
'Read plan'
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Test'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
)
.
toEqual
(
{
:
'approve-once'
}
)
;
}
)
;
it
(
'auto-approves write permission for files in session state directory'
,
async
(
)
=>
{
let
:
unknown
;
const
=
.
join
(
'/mock-session-state'
,
'mock-session-id'
,
'plan.md'
)
;
.
send
=
async
(
{
}
:
any
)
=>
{
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'assistant.message'
,
{
:
`Echo: ${prompt}`
}
)
;
=
await
.
emitPermissionRequest
(
{
:
'write'
,
:
,
:
'Write plan'
,
:
''
,
:
false
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Test'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
)
.
toEqual
(
{
:
'approve-once'
}
)
;
}
)
;
it
(
'auto-approves read permission for attached files outside workspace'
,
async
(
)
=>
{
let
:
unknown
;
const
=
'/outside-workspace/attached-file.ts'
;
.
send
=
async
(
{
}
:
any
)
=>
{
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'assistant.message'
,
{
:
`Echo: ${prompt}`
}
)
;
=
await
.
emitPermissionRequest
(
{
:
'read'
,
:
,
:
'Read file'
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
const
=
[
{
:
'file'
as
const
,
:
,
:
'attached-file.ts'
}
]
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Test'
}
,
as
any
,
undefined
,
,
.
)
;
expect
(
)
.
toEqual
(
{
:
'approve-once'
}
)
;
}
)
;
it
(
'does not auto-approve read permission for non-attached files outside workspace'
,
async
(
)
=>
{
let
:
unknown
;
const
=
'/outside-workspace/other-file.ts'
;
const
=
'/outside-workspace/attached-file.ts'
;
.
setConfirmationResult
(
'no'
)
;
.
send
=
async
(
{
}
:
any
)
=>
{
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'assistant.message'
,
{
:
`Echo: ${prompt}`
}
)
;
=
await
.
emitPermissionRequest
(
{
:
'read'
,
:
,
:
'Read file'
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
const
=
[
{
:
'file'
as
const
,
:
,
:
'attached-file.ts'
}
]
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Test'
}
,
as
any
,
undefined
,
,
.
)
;
expect
(
)
.
toEqual
(
{
:
'denied-interactively-by-user'
}
)
;
expect
(
.
)
.
toHaveLength
(
2
)
;
}
)
;
it
(
'auto-approves read permission inside working directory without external handler'
,
async
(
)
=>
{
let
:
unknown
;
=
workspaceInfoFor
(
URI
.
file
(
'/workingDirectory'
)
)
;
.
send
=
async
(
{
}
:
any
)
=>
{
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'assistant.message'
,
{
:
`Echo: ${prompt}`
}
)
;
// Mid way through, make it look like the sdk requested permission while emitting other messages.
=
await
.
emitPermissionRequest
(
{
:
'read'
,
:
.
join
(
'/workingDirectory'
,
'file.ts'
)
,
:
'Read file'
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
// Path must be absolute within workspace, should auto-approve
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Test'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
)
.
toEqual
(
{
:
'approve-once'
}
)
;
}
)
;
it
(
'auto-approves read permission for files in workspace folder when worktree is the working directory'
,
async
(
)
=>
{
let
:
unknown
;
const
=
URI
.
file
(
'/worktrees/session1'
)
;
const
=
URI
.
file
(
'/original-repo'
)
;
=
{
:
,
:
,
:
,
:
{
:
1
,
:
false
,
:
'abc'
,
:
'main'
,
:
'/original-repo'
,
:
'/worktrees/session1'
}
,
}
;
.
send
=
async
(
{
}
:
any
)
=>
{
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'assistant.message'
,
{
:
`Echo: ${prompt}`
}
)
;
// File is in workspace.folder (/original-repo), not in the worktree which is the working directory
=
await
.
emitPermissionRequest
(
{
:
'read'
,
:
.
join
(
'/original-repo'
,
'src/main.ts'
)
,
:
'Read file'
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Test'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
)
.
toEqual
(
{
:
'approve-once'
}
)
;
}
)
;
it
(
'auto-approves read permission for files in the worktree when workspace has both worktree and repository'
,
async
(
)
=>
{
let
:
unknown
;
const
=
URI
.
file
(
'/worktrees/session1'
)
;
const
=
URI
.
file
(
'/original-repo'
)
;
=
{
:
,
:
,
:
,
:
{
:
1
,
:
false
,
:
'abc'
,
:
'main'
,
:
'/original-repo'
,
:
'/worktrees/session1'
}
,
}
;
.
send
=
async
(
{
}
:
any
)
=>
{
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'assistant.message'
,
{
:
`Echo: ${prompt}`
}
)
;
// File is in the worktree which is also the working directory
=
await
.
emitPermissionRequest
(
{
:
'read'
,
:
.
join
(
'/worktrees/session1'
,
'src/main.ts'
)
,
:
'Read file'
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Test'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
)
.
toEqual
(
{
:
'approve-once'
}
)
;
}
)
;
it
(
'requires read permission outside workspace and working directory'
,
async
(
)
=>
{
let
:
unknown
;
.
setConfirmationResult
(
'no'
)
;
.
send
=
async
(
{
}
:
any
)
=>
{
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'assistant.message'
,
{
:
`Echo: ${prompt}`
}
)
;
// Mid way through, make it look like the sdk requested permission while emitting other messages.
=
await
.
emitPermissionRequest
(
{
:
'read'
,
:
.
join
(
'/workingDirectory'
,
'file.ts'
)
,
:
'Read file'
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
// Path must be absolute within workspace, should auto-approve
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Test'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
)
.
toEqual
(
{
:
'denied-interactively-by-user'
}
)
;
expect
(
.
)
.
toHaveLength
(
2
)
;
expect
(
.
[
1
]
.
)
.
toMatchObject
(
{
:
'Read file(s)'
,
:
'Read file'
}
)
;
}
)
;
it
(
'approves write permission when handler returns true'
,
async
(
)
=>
{
let
:
unknown
;
const
=
await
createSession
(
)
;
.
setConfirmationResult
(
'yes'
)
;
.
send
=
async
(
{
}
:
any
)
=>
{
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'assistant.message'
,
{
:
`Echo: ${prompt}`
}
)
;
// Mid way through, make it look like the sdk requested permission while emitting other messages.
=
await
.
emitPermissionRequest
(
{
:
'write'
,
:
'a.ts'
,
:
'Update file'
,
:
''
,
:
false
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Write'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
)
.
toEqual
(
{
:
'approve-once'
}
)
;
}
)
;
it
(
'denies write permission when handler returns false'
,
async
(
)
=>
{
let
:
unknown
;
const
=
await
createSession
(
)
;
.
setConfirmationResult
(
'no'
)
;
.
send
=
async
(
{
}
:
any
)
=>
{
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'assistant.message'
,
{
:
`Echo: ${prompt}`
}
)
;
// Mid way through, make it look like the sdk requested permission while emitting other messages.
=
await
.
emitPermissionRequest
(
{
:
'write'
,
:
'b.ts'
,
:
'Update file'
,
:
''
,
:
false
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Write'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
)
.
toEqual
(
{
:
'denied-interactively-by-user'
}
)
;
}
)
;
it
(
'denies write permission when handler throws'
,
async
(
)
=>
{
let
:
unknown
;
const
=
await
createSession
(
)
;
.
=
.
fn
(
async
(
)
=>
{
throw
new
Error
(
'oops'
)
;
}
)
;
.
send
=
async
(
{
}
:
any
)
=>
{
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'assistant.message'
,
{
:
`Echo: ${prompt}`
}
)
;
// Mid way through, make it look like the sdk requested permission while emitting other messages.
=
await
.
emitPermissionRequest
(
{
:
'write'
,
:
'err.ts'
,
:
'Update file'
,
:
''
,
:
false
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Write'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
)
.
toEqual
(
{
:
'denied-interactively-by-user'
}
)
;
}
)
;
it
(
'preserves order of edit toolCallIds and permissions for multiple pending edits'
,
async
(
)
=>
{
// Arrange a deferred send so we can emit tool events before request finishes
let
resolveSend
:
(
)
=>
void
;
.
send
=
async
(
)
=>
new
Promise<void>
(
=>
{
=
;
}
)
;
const
=
await
createSession
(
)
;
.
setConfirmationResult
(
'yes'
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
// Spy on trackEdit to capture ordering (we don't want to depend on externalEdit mechanics here)
const
:
string
[
]
=
[
]
;
const
=
.
spyOn
(
.
,
'trackEdit'
)
.
mockImplementation
(
async
function
(
this
:
any
,
:
string
)
{
.
push
(
)
;
// Immediately resolve to avoid hanging on externalEdit lifecycle
return
Promise
.
resolve
(
)
;
}
)
;
// Act: start handling request (do not await yet)
const
=
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Edits'
}
,
[
]
,
undefined
,
,
.
)
;
// Wait a tick to ensure event listeners are registered inside handleRequest
await
new
Promise
(
=>
setTimeout
(
,
0
)
)
;
// Emit 10 edit tool start events in rapid succession for the same file
const
=
'/workspace/abc.py'
;
for
(
let
=
1
;
<=
10
;
++
)
{
const
:
=
{
:
'edit'
,
:
String
(
)
,
:
{
:
,
:
'new content'
}
,
}
;
.
emit
(
'tool.execution_start'
,
)
;
}
// Now request permissions sequentially AFTER all tool calls have been emitted
const
:
any
[
]
=
[
]
;
for
(
let
=
1
;
<=
10
;
++
)
{
// Each permission request should dequeue the next toolCallId for the file
const
=
await
.
emitPermissionRequest
(
{
:
'write'
,
:
,
:
'Apply edit'
,
:
''
,
:
String
(
)
,
:
false
}
)
;
.
push
(
)
;
// Complete the edit so the tracker (if it were real) would finish; emit completion event
.
emit
(
'tool.execution_complete'
,
{
:
String
(
)
,
:
'str_replace_editor'
,
:
{
:
'str_replace'
,
:
}
,
:
true
,
:
{
:
''
}
}
)
;
}
// Allow the request to finish
!
(
)
;
await
;
// Assert ordering of trackEdit invocations exactly matches toolCallIds 1..10
expect
(
)
.
toEqual
(
Array
.
from
(
{
:
10
}
,
(
,
)
=>
String
(
+
1
)
)
)
;
expect
(
.
every
(
=>
.
===
'approve-once'
)
)
.
toBe
(
true
)
;
expect
(
)
.
toHaveBeenCalledTimes
(
10
)
;
.
mockRestore
(
)
;
}
)
;
it
(
'delays tool invocation messages for permission-requiring tools until permission is resolved'
,
async
(
)
=>
{
let
resolveSend
:
(
)
=>
void
;
.
send
=
async
(
)
=>
new
Promise<void>
(
=>
{
=
;
}
)
;
const
=
await
createSession
(
)
;
const
:
unknown
[
]
=
[
]
;
const
=
new
MockChatResponseStream
(
=>
.
push
(
)
)
;
.
attachStream
(
)
;
.
setConfirmationResult
(
'yes'
)
;
const
=
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Run bash'
}
,
[
]
,
undefined
,
,
.
)
;
await
new
Promise
(
=>
setTimeout
(
,
0
)
)
;
// Emit a bash tool start - this should be delayed
const
:
=
{
:
'bash'
,
:
'bash-delay-1'
,
:
{
:
'echo hi'
,
:
'Echo test'
}
}
;
.
emit
(
'tool.execution_start'
,
)
;
await
new
Promise
(
=>
setTimeout
(
,
0
)
)
;
// No ChatToolInvocationPart should be pushed yet for the bash tool
const
=
.
filter
(
=>
instanceof
ChatToolInvocationPart
)
;
expect
(
)
.
toHaveLength
(
0
)
;
// When permission is requested, the pending messages should be flushed
await
.
emitPermissionRequest
(
{
:
'shell'
,
:
[
{
:
'echo hi'
,
:
false
}
]
,
:
'Run command'
,
:
'echo hi'
,
:
[
]
,
:
[
]
,
:
false
,
:
false
}
)
;
await
new
Promise
(
=>
setTimeout
(
,
0
)
)
;
const
=
.
filter
(
=>
instanceof
ChatToolInvocationPart
)
;
expect
(
.
)
.
toBeGreaterThanOrEqual
(
1
)
;
.
emit
(
'tool.execution_complete'
,
{
:
'bash-delay-1'
,
:
'bash'
,
:
true
,
:
{
:
'hi'
}
}
)
;
!
(
)
;
await
;
}
)
;
it
(
'auto-approves an ordinary shell command when the sandbox is enabled'
,
async
(
)
=>
{
let
:
unknown
;
.
send
=
async
(
)
=>
{
=
await
.
emitPermissionRequest
(
{
:
'shell'
,
:
'sandboxed-tool'
,
:
[
{
:
'ls'
,
:
true
}
]
,
:
'List files'
,
:
'ls'
,
:
[
]
,
:
[
]
,
:
false
,
:
false
,
}
)
;
}
;
const
=
await
createSession
(
{
:
true
}
)
;
.
attachStream
(
new
MockChatResponseStream
(
)
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Run bash'
}
,
[
]
,
undefined
,
,
.
)
;
// The sandbox contains the command, so it is auto-approved without a prompt.
expect
(
)
.
toEqual
(
{
:
'approve-once'
}
)
;
expect
(
.
.
filter
(
=>
.
===
'vscode_get_terminal_confirmation'
)
)
.
toHaveLength
(
0
)
;
}
)
;
it
(
'does not auto-approve a sandbox-bypass shell command and flags it runs outside the sandbox'
,
async
(
)
=>
{
let
:
unknown
;
.
send
=
async
(
)
=>
{
=
await
.
emitPermissionRequest
(
{
:
'shell'
,
:
'bypass-tool'
,
:
[
{
:
'cat ~/secret'
,
:
true
}
]
,
:
'Read secret'
,
:
'cat ~/secret'
,
:
[
]
,
:
[
]
,
:
false
,
:
false
,
:
true
,
:
'Needs access outside the workspace'
,
}
)
;
}
;
.
setConfirmationResult
(
'yes'
)
;
const
=
await
createSession
(
{
:
true
}
)
;
.
attachStream
(
new
MockChatResponseStream
(
)
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Run bash'
}
,
[
]
,
undefined
,
,
.
)
;
// Opting out of the sandbox is an elevation of privilege, so it must fall
// through to the confirmation prompt rather than being auto-approved, and
// the confirmation must be flagged as running outside the sandbox.
const
=
.
.
filter
(
=>
.
===
'vscode_get_terminal_confirmation'
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
[
0
]
.
as
{
?
:
boolean
;
?
:
string
}
)
.
toMatchObject
(
{
:
true
,
:
'Needs access outside the workspace'
,
}
)
;
expect
(
)
.
toEqual
(
{
:
'approve-once'
}
)
;
}
)
;
it
(
'applies the configured sandbox for a request running with default permissions'
,
async
(
)
=>
{
const
=
await
createSession
(
{
:
true
}
)
;
.
attachStream
(
new
MockChatResponseStream
(
)
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Run'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
.
)
.
toEqual
(
{
:
true
,
:
{
:
{
}
,
:
{
:
false
}
}
}
)
;
}
)
;
it
(
'applies the configured sandbox for a request running with bypass approvals'
,
async
(
)
=>
{
for
(
const
of
[
'autopilot'
,
'autoApprove'
]
as
const
)
{
=
new
MockSdkSession
(
)
;
const
=
await
createSession
(
{
:
true
}
)
;
.
setPermissionLevel
(
)
;
.
attachStream
(
new
MockChatResponseStream
(
)
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Run'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
.
,
)
.
toEqual
(
{
:
true
,
:
{
:
{
}
,
:
{
:
false
}
}
}
)
;
}
}
)
;
it
(
'explicitly disables the sandbox when the session has no sandbox configured'
,
async
(
)
=>
{
const
=
await
createSession
(
{
:
false
}
)
;
.
attachStream
(
new
MockChatResponseStream
(
)
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Run'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
.
)
.
toEqual
(
{
:
false
}
)
;
}
)
;
it
(
'emits languageModelToolInvoked telemetry for each completed tool invocation'
,
async
(
)
=>
{
class
RecordingTelemetryService
extends
NullTelemetryService
{
readonly
:
{
:
string
;
?
:
;
?
:
}
[
]
=
[
]
;
sendMSFTTelemetryEvent
(
:
string
,
?
:
,
?
:
)
:
void
{
this
.
.
push
(
{
,
,
}
)
;
}
}
const
=
new
RecordingTelemetryService
(
)
;
=
;
let
resolveSend
:
(
)
=>
void
;
.
send
=
async
(
)
=>
new
Promise<void>
(
=>
{
=
;
}
)
;
const
=
await
createSession
(
)
;
.
attachStream
(
new
MockChatResponseStream
(
)
)
;
const
=
.
parse
(
'copilotcli:/test-session'
)
;
const
=
.
handleRequest
(
{
:
'req-1'
,
:
undefined
as
never
,
}
,
{
:
'Run tools'
}
,
[
]
,
undefined
,
,
.
)
;
await
new
Promise
(
=>
setTimeout
(
,
0
)
)
;
// Native CLI tool: success
.
emit
(
'tool.execution_start'
,
{
:
'bash'
,
:
't-success'
,
:
{
}
}
)
;
.
emit
(
'tool.execution_complete'
,
{
:
't-success'
,
:
'completion_bash'
,
:
true
,
:
{
:
'ok'
}
}
)
;
// MCP tool: failure
.
emit
(
'tool.execution_start'
,
{
:
'mcp_tool'
,
:
't-mcp'
,
:
'srv'
,
:
'mt'
,
:
{
}
}
)
;
.
emit
(
'tool.execution_complete'
,
{
:
't-mcp'
,
:
'mcp_tool'
,
:
false
,
:
{
:
'tool_error'
,
:
'boom'
}
}
)
;
// User-denied permission: userCancelled
.
emit
(
'tool.execution_start'
,
{
:
'bash'
,
:
't-denied'
,
:
{
}
}
)
;
.
emit
(
'tool.execution_complete'
,
{
:
't-denied'
,
:
'bash'
,
:
false
,
:
{
:
'denied'
,
:
'no'
}
}
)
;
// Completion-only event: fallback to toolName from the completion event
.
emit
(
'tool.execution_complete'
,
{
:
't-complete-only'
,
:
'completion_tool'
,
:
true
,
:
{
:
'ok'
}
}
)
;
!
(
)
;
await
;
const
=
.
.
filter
(
=>
.
===
'languageModelToolInvoked'
)
;
const
=
.
map
(
=>
(
{
:
.
?.
,
:
.
?.
,
:
.
?.
,
:
.
?.
,
:
.
?.
,
:
typeof
.
?.
===
'number'
,
}
)
)
;
expect
(
)
.
toEqual
(
[
{
:
'success'
,
:
'copilotcli:/test-session'
,
:
'bash'
,
:
undefined
,
:
'copilotCli'
,
:
true
}
,
{
:
'error'
,
:
'copilotcli:/test-session'
,
:
'mcp_tool'
,
:
undefined
,
:
'mcp'
,
:
true
}
,
{
:
'userCancelled'
,
:
'copilotcli:/test-session'
,
:
'bash'
,
:
undefined
,
:
'copilotCli'
,
:
true
}
,
{
:
'success'
,
:
'copilotcli:/test-session'
,
:
'completion_tool'
,
:
undefined
,
:
'copilotCli'
,
:
false
}
,
]
)
;
}
)
;
it
(
'uses remote permission responses when Mission Control is active'
,
async
(
)
=>
{
let
:
unknown
;
.
send
=
async
(
)
=>
{
=
await
.
emitPermissionRequest
(
{
:
'shell'
,
:
'remote-permission-tool'
,
:
[
{
:
'echo "Hello world"'
,
:
false
}
]
,
:
'Run command'
,
:
'echo "Hello world"'
,
:
[
]
,
:
[
]
,
:
false
,
:
false
}
)
;
}
;
const
=
await
createSession
(
)
;
let
:
|
undefined
;
const
=
.
spyOn
(
,
'invokeTool'
)
.
mockImplementation
(
(
async
(
:
string
,
:
unknown
,
?
:
)
=>
{
if
(
===
'vscode_get_confirmation'
||
===
'vscode_get_terminal_confirmation'
)
{
=
;
return
await
new
Promise
(
=>
{
?.
onCancellationRequested
(
(
)
=>
resolve
(
{
:
[
new
LanguageModelTextPart
(
'no'
)
]
}
)
)
;
}
)
;
}
return
{
:
[
]
}
;
}
)
as
typeof
.
)
;
const
=
{
:
'mc-session'
,
:
undefined
as
string
|
undefined
,
:
[
]
,
:
[
]
,
:
new
Map
(
)
,
:
undefined
,
:
undefined
,
:
null
,
:
.
now
(
)
,
:
new
Set<string>
(
)
,
:
as
unknown
as
,
:
undefined
,
:
.
file
(
'/workspace'
)
as
unknown
as
import
(
'vscode'
)
.
,
}
;
.
defineProperty
(
,
'_mcState'
,
{
:
,
:
true
}
)
;
const
=
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Run bash'
}
,
[
]
,
undefined
,
,
.
)
;
await
new
Promise
(
=>
setTimeout
(
,
0
)
)
;
await
(
as
any
)
.
_pollMcCommandsStatic
(
.
,
,
{
getPendingCommands
:
async
(
)
=>
[
{
:
'mc-command-1'
,
:
JSON
.
stringify
(
{
:
'remote-permission-tool'
,
:
true
,
:
'once'
}
)
,
:
'in_progress'
,
:
'permission_response'
,
}
]
,
}
,
,
)
;
await
;
expect
(
)
.
toEqual
(
{
:
'approve-once'
}
)
;
const
=
.
.
.
filter
(
=>
[
0
]
===
'vscode_get_confirmation'
||
[
0
]
===
'vscode_get_terminal_confirmation'
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
?.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toEqual
(
[
'mc-command-1'
]
)
;
}
)
;
it
(
'uses local permission responses when Mission Control is active'
,
async
(
)
=>
{
let
:
unknown
;
.
send
=
async
(
)
=>
{
=
await
.
emitPermissionRequest
(
{
:
'shell'
,
:
'local-permission-tool'
,
:
[
{
:
'echo "Hello world"'
,
:
false
}
]
,
:
'Run command'
,
:
'echo "Hello world"'
,
:
[
]
,
:
[
]
,
:
false
,
:
false
}
)
;
}
;
.
setConfirmationResult
(
'yes'
)
;
const
=
await
createSession
(
)
;
const
=
.
spyOn
(
,
'invokeTool'
)
;
const
=
{
:
'mc-session'
,
:
undefined
as
string
|
undefined
,
:
[
]
,
:
[
]
,
:
new
Map
(
)
,
:
undefined
,
:
undefined
,
:
null
,
:
.
now
(
)
,
:
new
Set<string>
(
)
,
:
as
unknown
as
,
:
undefined
,
:
.
file
(
'/workspace'
)
as
unknown
as
import
(
'vscode'
)
.
,
}
;
.
defineProperty
(
,
'_mcState'
,
{
:
,
:
true
}
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'Run bash'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
)
.
toEqual
(
{
:
'approve-once'
}
)
;
const
=
.
.
.
filter
(
=>
[
0
]
===
'vscode_get_confirmation'
||
[
0
]
===
'vscode_get_terminal_confirmation'
)
;
expect
(
)
.
toHaveLength
(
1
)
;
expect
(
.
.
)
.
toBe
(
0
)
;
}
)
;
it
(
'uses remote ask user responses when Mission Control is active'
,
async
(
)
=>
{
let
:
unknown
;
const
:
Array
<
{
:
string
;
:
;
:
}
>
=
[
]
;
.
send
=
async
(
)
=>
{
=
await
.
emitUserInputRequest
(
{
:
'What is your favorite VS Code feature or extension?'
,
:
true
,
:
'ask-user-tool'
,
}
)
;
}
;
const
=
await
createSession
(
)
;
let
:
|
undefined
;
.
defineProperty
(
,
'_userQuestionHandler'
,
{
:
{
:
undefined
,
async
askUserQuestion
(
:
,
:
,
:
,
?
:
string
)
:
Promise
<
|
undefined
>
{
=
;
return
await
new
Promise<IQuestionAnswer |undefined>
(
=>
{
.
onCancellationRequested
(
(
)
=>
resolve
(
undefined
)
)
;
}
)
;
}
,
async
notifyQuestionCarouselAnswer
(
:
string
,
:
,
:
)
:
Promise
<
void
>
{
.
push
(
{
,
,
}
)
;
}
,
}
,
:
true
,
}
)
;
const
=
{
:
'mc-session'
,
:
[
]
,
:
[
]
,
:
new
Map
(
)
,
:
undefined
,
:
undefined
,
:
null
,
:
.
now
(
)
,
:
new
Set<string>
(
)
,
:
as
unknown
as
,
:
undefined
,
:
.
file
(
'/workspace'
)
as
unknown
as
import
(
'vscode'
)
.
,
}
;
.
defineProperty
(
,
'_mcState'
,
{
:
,
:
true
}
)
;
const
=
.
handleRequest
(
{
:
''
,
:
{
}
as
never
}
,
{
:
'Ask me about VS Code'
}
,
[
]
,
undefined
,
,
.
)
;
await
new
Promise
(
=>
setTimeout
(
,
0
)
)
;
await
(
as
any
)
.
_pollMcCommandsStatic
(
.
,
,
{
getPendingCommands
:
async
(
)
=>
[
{
:
'mc-command-ask-user'
,
:
JSON
.
stringify
(
{
:
'user-input-1'
,
:
'none'
,
:
true
}
)
,
:
'in_progress'
,
:
'ask_user_response'
,
}
]
,
}
,
,
)
;
await
;
expect
(
)
.
toEqual
(
{
:
'none'
,
:
true
}
)
;
expect
(
)
.
toEqual
(
[
{
:
'ask-user-tool'
,
:
{
:
'What is your favorite VS Code feature or extension?'
,
:
[
]
,
:
true
,
:
'What is your favorite VS Code feature or extension?'
,
}
,
:
{
:
'none'
,
:
true
}
,
}
]
)
;
expect
(
?.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toEqual
(
[
'mc-command-ask-user'
]
)
;
}
)
;
it
(
'aborts pending remote ask user requests when Mission Control stop is requested'
,
async
(
)
=>
{
let
:
unknown
;
.
send
=
async
(
)
=>
{
=
await
.
emitUserInputRequest
(
{
:
'What is your favorite VS Code feature or extension?'
,
:
true
,
:
'ask-user-tool'
,
}
)
;
if
(
.
)
{
return
;
}
.
emit
(
'assistant.turn_start'
,
{
}
)
;
.
emit
(
'assistant.turn_end'
,
{
}
)
;
}
;
const
=
await
createSession
(
)
;
let
:
|
undefined
;
.
defineProperty
(
,
'_userQuestionHandler'
,
{
:
{
:
undefined
,
async
askUserQuestion
(
:
,
:
,
:
)
:
Promise
<
|
undefined
>
{
=
;
return
await
new
Promise<IQuestionAnswer |undefined>
(
=>
{
.
onCancellationRequested
(
(
)
=>
resolve
(
undefined
)
)
;
}
)
;
}
,
}
,
:
true
,
}
)
;
const
=
{
:
'mc-session'
,
:
[
]
,
:
[
]
,
:
new
Map
(
)
,
:
undefined
,
:
undefined
,
:
null
,
:
.
now
(
)
,
:
new
Set<string>
(
)
,
:
as
unknown
as
,
:
undefined
,
:
.
file
(
'/workspace'
)
as
unknown
as
import
(
'vscode'
)
.
,
}
;
.
defineProperty
(
,
'_mcState'
,
{
:
,
:
true
}
)
;
const
=
.
handleRequest
(
{
:
''
,
:
{
}
as
never
}
,
{
:
'Ask me about VS Code'
}
,
[
]
,
undefined
,
,
.
)
;
await
new
Promise
(
=>
setTimeout
(
,
0
)
)
;
await
(
as
any
)
.
_pollMcCommandsStatic
(
.
,
,
{
getPendingCommands
:
async
(
)
=>
[
{
:
'mc-command-abort'
,
:
''
,
:
'in_progress'
,
:
'abort'
,
}
]
,
}
,
,
)
;
await
;
expect
(
.
)
.
toBe
(
true
)
;
expect
(
)
.
toEqual
(
{
:
''
,
:
false
}
)
;
expect
(
?.
)
.
toBe
(
true
)
;
expect
(
.
)
.
toEqual
(
[
'mc-command-abort'
]
)
;
}
)
;
it
(
'reports remote control status when /remote is invoked without arguments'
,
async
(
)
=>
{
await
.
setConfig
(
.
.
,
true
)
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'remote'
,
:
''
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
.
.
join
(
'\n'
)
)
.
toContain
(
'Remote control is disabled. Use /remote on to enable it.'
)
;
}
)
;
it
(
'reports enabled remote control status when /remote is invoked without arguments'
,
async
(
)
=>
{
await
.
setConfig
(
.
.
,
true
)
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
const
=
{
:
'mc-session'
,
:
'https://github.com/microsoft/vscode/tasks/123'
,
:
[
]
,
:
[
]
,
:
new
Map
(
)
,
:
undefined
,
:
undefined
,
:
null
,
:
.
now
(
)
,
:
new
Set<string>
(
)
,
:
as
unknown
as
,
:
undefined
,
:
.
file
(
'/workspace'
)
as
unknown
as
import
(
'vscode'
)
.
,
}
;
.
defineProperty
(
,
'_mcState'
,
{
:
,
:
true
}
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'remote'
,
:
''
}
,
[
]
,
undefined
,
,
.
)
;
const
=
.
.
join
(
'\n'
)
;
expect
(
)
.
toContain
(
'Remote control is enabled.'
)
;
expect
(
)
.
toContain
(
'Use the button below to open in your browser, or scan to steer from the GitHub mobile app.'
)
;
expect
(
)
.
.
toContain
(
'Scan with GitHub mobile:'
)
;
expect
(
)
.
toContain
(
'QR code to open this remote session in GitHub mobile'
)
;
expect
(
)
.
toContain
(
'data:image/svg+xml;base64,'
)
;
expect
(
)
.
.
toContain
(
'```'
)
;
}
)
;
it
(
'shows /remote usage for unsupported arguments'
,
async
(
)
=>
{
await
.
setConfig
(
.
.
,
true
)
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'remote'
,
:
'wat'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
.
.
join
(
'\n'
)
)
.
toContain
(
'Usage: /remote, /remote on, /remote off'
)
;
}
)
;
it
(
'accepts /remote arguments when the prompt includes the slash command text'
,
async
(
)
=>
{
await
.
setConfig
(
.
.
,
true
)
;
const
=
await
createSession
(
)
;
const
=
new
MockChatResponseStream
(
)
;
.
attachStream
(
)
;
const
=
{
:
'mc-session'
,
:
[
]
,
:
[
]
,
:
new
Map
(
)
,
:
undefined
,
:
undefined
,
:
null
,
:
.
now
(
)
,
:
new
Set<string>
(
)
,
:
as
unknown
as
,
:
undefined
,
:
.
file
(
'/workspace'
)
as
unknown
as
import
(
'vscode'
)
.
,
}
;
.
defineProperty
(
,
'_mcState'
,
{
:
,
:
true
}
)
;
.
defineProperty
(
,
'_missionControlApiClient'
,
{
:
{
:
.
fn
(
async
(
)
=>
true
)
,
:
.
fn
(
async
(
)
=>
undefined
)
}
,
:
true
,
}
)
;
await
.
handleRequest
(
{
:
''
,
:
undefined
as
never
}
,
{
:
'remote'
,
:
'/remote off'
}
,
[
]
,
undefined
,
,
.
)
;
expect
(
.
.
join
(
'\n'
)
)
.
toContain
(
'Remote control disabled.'
)
;
}
)
;
it
(
'forwards session.idle to Mission Control so remote running state clears'
,
async
(
)
=>
{
const
=
await
createSession
(
)
;
const
=
{
:
'mc-session'
,
:
[
]
,
:
[
]
,
:
new
Map
(
)
,
:
undefined
,
:
undefined
,
:
null
,
:
.
now
(
)
,
:
new
Set<string>
(
)
,
:
as
unknown
as
,
:
undefined
,
:
.
file
(
'/workspace'
)
as
unknown
as
import
(
'vscode'
)
.
,
}
;
.
defineProperty
(
,
'_mcState'
,
{
:
,
:
true
}
)
;
(
as
any
)
.
_bufferMcEvent
(
{
:
'session.idle'
,
:
{
}
}
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
(
.
[
0
]
as
{
:
string
}
)
.
)
.
toBe
(
'session.idle'
)
;
}
)
;
it
(
'forwards session.title_changed to Mission Control as an ephemeral event'
,
async
(
)
=>
{
const
=
await
createSession
(
)
;
const
=
{
:
'mc-session'
,
:
[
]
,
:
[
]
,
:
new
Map
(
)
,
:
undefined
,
:
undefined
,
:
null
,
:
.
now
(
)
,
:
new
Set<string>
(
)
,
:
as
unknown
as
,
:
undefined
,
:
.
file
(
'/workspace'
)
as
unknown
as
import
(
'vscode'
)
.
,
}
;
.
defineProperty
(
,
'_mcState'
,
{
:
,
:
true
}
)
;
(
as
any
)
.
_bufferMcEvent
(
{
:
'session.title_changed'
,
:
'title-change-1'
,
:
'2026-01-01T00:00:00.000Z'
,
:
'visible-root-message'
,
:
true
,
:
{
:
'Remote Session Title'
}
,
}
)
;
expect
(
.
)
.
toHaveLength
(
1
)
;
expect
(
(
.
[
0
]
as
{
:
string
;
?
:
true
}
)
.
)
.
toBe
(
'session.title_changed'
)
;
expect
(
(
.
[
0
]
as
{
?
:
true
}
)
.
)
.
toBe
(
true
)
;
expect
(
(
.
[
0
]
as
{
:
{
:
string
}
}
)
.
.
)
.
toBe
(
'Remote Session Title'
)
;
}
)
;
it
(
'prefers existing session history over the current /remote prompt when deriving the Mission Control title'
,
async
(
)
=>
{
const
=
await
createSession
(
)
;
.
spyOn
(
,
'getEvents'
)
.
mockReturnValue
(
[
{
:
'user.message'
,
:
{
:
'hey'
}
}
,
]
as
any
)
;
(
as
any
)
.
=
'/remote'
;
await
expect
(
(
as
any
)
.
_getMissionControlSessionTitle
(
)
)
.
.
toBe
(
'hey'
)
;
}
)
;
it
(
'sanitizes hidden prompt markup when deriving the Mission Control title'