Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/**
* Covers the BYOK provider/model synthesis the launcher feeds into
* `createSession` / `resumeSession`. The first four tests pin the gating and
* graceful-degradation branches plus the exact SDK config shape using a real
* {@link ByokLmBridgeRegistry} and a counting proxy thunk (no real proxy). The
* last test wires the synthesized config straight into a live
* {@link ByokLmProxyService} and POSTs at it, proving the launcher's output is
* consumable end-to-end: provider `baseUrl` + `Bearer <nonce>.<sessionId>` +
* `model = id` route through the proxy to the renderer bridge.
*/
suite
(
'resolveByokSessionConfig'
,
(
)
=>
{
const
=
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
const
=
'sess-1'
;
const
=
new
NullLogService
(
)
;
/**
* A bridge connection that pushes `models` as its snapshot synchronously when
* the registry subscribes; `chat` is scripted (unused by most tests).
*/
function
connectionOf
(
:
[
]
,
:
[
'chat'
]
=
async
(
)
=>
(
{
:
[
]
}
)
)
:
{
const
=
.
add
(
new
Emitter<IByokLmModelInfo[]>
(
{
onDidAddFirstListener
:
(
)
=>
.
fire
(
)
,
}
)
)
;
return
{
,
:
.
}
;
}
/** A fake proxy handle plus a `startProxy` thunk that records its call count. */
function
countingProxy
(
)
{
let
=
0
;
const
:
=
{
:
'http://127.0.0.1:1'
,
:
'NONCE'
,
providerBaseUrl
:
=>
`http://127.0.0.1:1/v/${vendor}`
,
dispose
:
(
)
=>
{
}
,
}
;
return
{
get
starts
(
)
{
return
;
}
,
startProxy
:
async
(
)
=>
{
++
;
return
;
}
,
}
;
}
test
(
'returns empty and never starts the proxy when no bridge is active'
,
async
(
)
=>
{
const
=
new
ByokLmBridgeRegistry
(
)
;
const
=
countingProxy
(
)
;
const
=
await
resolveByokSessionConfig
(
,
,
.
,
)
;
.
deepStrictEqual
(
,
{
}
)
;
.
strictEqual
(
.
,
0
)
;
}
)
;
test
(
'returns empty and never starts the proxy when the bridge reports no models'
,
async
(
)
=>
{
const
=
new
ByokLmBridgeRegistry
(
)
;
const
=
.
register
(
'client-1'
,
connectionOf
(
[
]
)
)
;
const
=
countingProxy
(
)
;
const
=
await
resolveByokSessionConfig
(
,
,
.
,
)
;
.
dispose
(
)
;
.
deepStrictEqual
(
,
{
}
)
;
.
strictEqual
(
.
,
0
)
;
}
)
;
test
(
'returns empty and never starts the proxy for a window that never pushes a snapshot'
,
async
(
)
=>
{
const
=
new
ByokLmBridgeRegistry
(
)
;
// A window connected without a BYOK handler never pushes, so it stays
// non-serving and contributes no models.
const
=
.
register
(
'client-1'
,
{
:
async
(
)
:
Promise
<
>
=>
(
{
:
[
]
}
)
,
:
.
}
)
;
const
=
countingProxy
(
)
;
const
=
await
resolveByokSessionConfig
(
,
,
.
,
)
;
.
dispose
(
)
;
.
deepStrictEqual
(
,
{
}
)
;
.
strictEqual
(
.
,
0
)
;
}
)
;
test
(
'synthesizes deduped providers and per-model config from the active bridge'
,
async
(
)
=>
{
const
=
new
ByokLmBridgeRegistry
(
)
;
const
=
.
register
(
'client-1'
,
connectionOf
(
[
{
:
'acme'
,
:
'claude'
,
:
'Acme Claude'
,
:
200000
}
,
{
:
'acme'
,
:
'gpt'
,
:
undefined
,
:
undefined
}
,
{
:
'globex'
,
:
'llama'
,
:
'Globex Llama'
}
,
]
)
)
;
const
=
countingProxy
(
)
;
const
=
await
resolveByokSessionConfig
(
,
,
.
,
)
;
.
dispose
(
)
;
.
strictEqual
(
.
,
1
)
;
.
deepStrictEqual
(
,
{
:
[
{
:
'acme'
,
:
'openai'
,
:
'responses'
,
:
'http://127.0.0.1:1/v/acme'
,
:
'NONCE.sess-1'
}
,
{
:
'globex'
,
:
'openai'
,
:
'responses'
,
:
'http://127.0.0.1:1/v/globex'
,
:
'NONCE.sess-1'
}
,
]
,
:
[
{
:
'claude'
,
:
'acme'
,
:
'Acme Claude'
,
:
200000
}
,
{
:
'gpt'
,
:
'acme'
}
,
{
:
'llama'
,
:
'globex'
,
:
'Globex Llama'
}
,
]
,
}
)
;
}
)
;
test
(
'preserves provider groups when models share a vendor and id'
,
async
(
)
=>
{
const
=
new
ByokLmBridgeRegistry
(
)
;
const
=
.
register
(
'client-1'
,
connectionOf
(
[
{
:
'google'
,
:
'gemini-2.5-pro'
,
:
'google/Gemini Personal/gemini-2.5-pro'
}
,
{
:
'google'
,
:
'gemini-2.5-pro'
,
:
'google/Gemini Work/gemini-2.5-pro'
}
,
]
)
)
;
const
=
countingProxy
(
)
;
const
=
await
resolveByokSessionConfig
(
,
,
.
,
)
;
.
dispose
(
)
;
.
deepStrictEqual
(
.
,
[
{
:
'Gemini Personal/gemini-2.5-pro'
,
:
'google'
}
,
{
:
'Gemini Work/gemini-2.5-pro'
,
:
'google'
}
,
]
)
;
}
)
;
test
(
'synthesized provider config routes through a live proxy to the bridge'
,
async
(
)
=>
{
const
=
new
ByokLmBridgeRegistry
(
)
;
let
:
|
undefined
;
const
=
.
register
(
'client-1'
,
connectionOf
(
[
{
:
'acme'
,
:
'claude'
}
]
,
async
(
)
=>
{
=
;
return
{
:
[
{
:
'message'
,
:
[
{
:
'text'
,
:
'hello from byok'
}
]
}
]
}
;
}
,
)
)
;
const
=
new
ByokLmProxyService
(
,
)
;
let
:
|
undefined
;
const
=
await
resolveByokSessionConfig
(
,
,
async
(
)
=>
(
=
await
.
start
(
)
)
,
)
;
const
=
.
!
[
0
]
;
const
=
.
!
[
0
]
;
try
{
const
=
await
fetch
(
`${provider.baseUrl}/responses`
,
{
:
'POST'
,
:
{
'Content-Type'
:
'application/json'
,
'Authorization'
:
`Bearer ${provider.bearerToken}`
}
,
:
JSON
.
stringify
(
{
:
.
,
:
[
{
:
'message'
,
:
'user'
,
:
[
{
:
'input_text'
,
:
'hi'
}
]
}
]
}
)
,
}
)
;
.
strictEqual
(
.
,
200
)
;
const
=
await
.
text
(
)
;
.
ok
(
.
includes
(
'hello from byok'
)
,
`expected content in SSE: ${text}`
)
;
}
finally
{
?.
dispose
(
)
;
.
dispose
(
)
;
.
dispose
(
)
;
}
.
strictEqual
(
?.
,
'acme'
)
;
.
strictEqual
(
?.
,
'claude'
)
;
}
)
;
test
(
'reads the latest pushed snapshot from the registry cache'
,
async
(
)
=>
{
const
=
new
ByokLmBridgeRegistry
(
)
;
const
=
.
add
(
new
Emitter<IByokLmModelInfo[]>
(
)
)
;
const
=
.
register
(
'client-1'
,
{
:
async
(
)
:
Promise
<
>
=>
(
{
:
[
]
}
)
,
:
.
,
}
)
;
const
=
countingProxy
(
)
;
// The window starts serving-but-empty, then pushes a model; the resolved
// config reflects the latest cached push with no renderer round-trip.
.
fire
(
[
]
)
;
.
fire
(
[
{
:
'acme'
,
:
'claude'
,
:
'Acme Claude'
}
]
)
;
const
=
await
resolveByokSessionConfig
(
,
,
.
,
)
;
.
dispose
(
)
;
.
deepStrictEqual
(
.
,
[
{
:
'claude'
,
:
'acme'
,
:
'Acme Claude'
}
]
)
;
}
)
;
}
)
;
/**
* Covers the launcher's lazy memoization and disposal of the shared BYOK proxy
* handle: concurrent launches share one bind, and
* {@link CopilotSessionLauncher.disposeByokProxyHandle} (called by the agent
* after the runtime subprocess stops) releases it so the next launch mints a
* fresh nonce.
*/
suite
(
'CopilotSessionLauncher BYOK proxy lifecycle'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
const
=
'sess-1'
;
/**
* A bridge connection that pushes `models` as its snapshot synchronously when
* the registry subscribes; the backing emitter is owned by `store`.
*/
function
connectionOf
(
:
,
:
[
]
)
:
{
const
=
.
add
(
new
Emitter<IByokLmModelInfo[]>
(
{
onDidAddFirstListener
:
(
)
=>
.
fire
(
)
,
}
)
)
;
return
{
:
async
(
)
:
Promise
<
>
=>
(
{
:
[
]
}
)
,
:
.
}
;
}
/** A fake proxy service whose handles carry a unique nonce per `start()`. */
function
fakeProxyService
(
)
{
let
=
0
;
let
=
0
;
const
:
=
{
:
undefined
,
:
async
(
)
:
Promise
<
>
=>
{
const
=
`NONCE-${++starts}`
;
return
{
:
'http://127.0.0.1:1'
,
,
providerBaseUrl
:
=>
`http://127.0.0.1:1/v/${vendor}`
,
dispose
:
(
)
=>
{
++
;
}
,
}
;
}
,
dispose
:
(
)
=>
{
}
,
}
;
return
{
,
get
starts
(
)
{
return
;
}
,
get
disposes
(
)
{
return
;
}
}
;
}
function
createLauncher
(
:
,
:
,
:
,
=
true
)
:
{
const
=
new
ServiceCollection
(
)
;
.
set
(
,
new
NullLogService
(
)
)
;
.
set
(
,
)
;
.
set
(
,
)
;
.
set
(
,
{
:
undefined
,
getRootValue
:
(
:
unknown
,
:
string
)
=>
===
?
:
undefined
,
}
as
unknown
as
)
;
// The launcher's other dependencies are unused by the BYOK path and
// resolve to `undefined` under the non-strict InstantiationService.
const
=
.
add
(
new
InstantiationService
(
)
)
;
return
.
createInstance
(
)
;
}
test
(
'memoizes the handle, and disposeByokProxyHandle releases it so the next launch mints a fresh nonce'
,
async
(
)
=>
{
const
=
new
DisposableStore
(
)
;
const
=
fakeProxyService
(
)
;
const
=
new
ByokLmBridgeRegistry
(
)
;
.
add
(
.
register
(
'client-1'
,
connectionOf
(
,
[
{
:
'acme'
,
:
'claude'
}
]
)
)
)
;
const
=
createLauncher
(
,
.
,
)
;
const
resolve
=
(
)
=>
(
as
unknown
as
{
_resolveByokSessionConfig
(
:
string
)
:
Promise
<
{
?
:
{
:
string
}
[
]
}
>
}
)
.
_resolveByokSessionConfig
(
)
;
const
=
await
resolve
(
)
;
const
=
await
resolve
(
)
;
.
strictEqual
(
.
,
1
,
'subsequent launches share the memoized bind'
)
;
.
strictEqual
(
.
!
[
0
]
.
,
.
!
[
0
]
.
,
'the shared bind reuses one nonce'
)
;
await
.
disposeByokProxyHandle
(
)
;
await
.
disposeByokProxyHandle
(
)
;
.
strictEqual
(
.
,
1
,
'the handle is released exactly once and disposal is idempotent'
)
;
const
=
await
resolve
(
)
;
.
strictEqual
(
.
,
2
,
'a fresh bind is minted after disposal'
)
;
.
notStrictEqual
(
.
!
[
0
]
.
,
.
!
[
0
]
.
,
'the fresh bind carries a new nonce'
)
;
.
dispose
(
)
;
}
)
;
test
(
'does not synthesize BYOK session config while root configuration disables it'
,
async
(
)
=>
{
const
=
new
DisposableStore
(
)
;
const
=
fakeProxyService
(
)
;
const
=
new
ByokLmBridgeRegistry
(
)
;
.
add
(
.
register
(
'client-1'
,
connectionOf
(
,
[
{
:
'acme'
,
:
'claude'
}
]
)
)
)
;
const
=
createLauncher
(
,
.
,
,
false
)
;
try
{
const
=
await
(
as
unknown
as
{
_resolveByokSessionConfig
(
:
string
)
:
Promise
<
{
?
:
{
:
string
}
[
]
}
>
}
)
.
_resolveByokSessionConfig
(
)
;
.
deepStrictEqual
(
{
,
:
.
}
,
{
:
{
}
,
:
0
}
)
;
}
finally
{
.
dispose
(
)
;
}
}
)
;
}
)
;
suite
(
'CopilotSessionLauncher shared session config'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'derives explicit MCP registration from client metadata rather than cwd equality'
,
(
)
=>
{
const
=
URI
.
file
(
'/tmp/plugin'
)
;
const
=
URI
.
file
(
'/workspace'
)
;
const
:
=
{
:
'server'
,
:
{
:
.
REMOTE
,
:
'https://example.com/mcp'
}
,
:
,
:
URI
.
joinPath
(
,
'.mcp.json'
)
,
:
{
:
.
,
:
'server'
,
:
URI
.
joinPath
(
,
'.mcp.json'
)
.
toString
(
)
,
:
'server'
,
:
{
:
.
}
,
}
,
}
;
const
=
(
:
<
string
,
unknown
>
)
:
=>
(
{
:
.
,
:
'plugin'
,
:
'file:///plugin'
,
:
'Plugin'
,
:
,
}
)
;
.
deepStrictEqual
(
[
resolveCopilotMcpServerInfo
(
,
)
,
resolveCopilotMcpServerInfo
(
,
,
input
(
toClientPluginMcpDefaultCwdsMeta
(
{
:
null
}
)
)
,
)
,
resolveCopilotMcpServerInfo
(
,
,
input
(
{
:
{
:
42
}
}
)
,
)
,
resolveCopilotMcpServerInfo
(
,
undefined
)
,
]
.
map
(
=>
(
{
:
.
?.
toString
(
)
,
:
.
,
}
)
)
,
[
{
:
.
toString
(
)
,
:
'pluginDiscovery'
}
,
{
:
.
toString
(
)
,
:
'sessionConfig'
}
,
{
:
.
toString
(
)
,
:
'pluginDiscovery'
}
,
{
:
.
toString
(
)
,
:
'sessionConfig'
}
,
]
)
;
}
)
;
test
(
'passes Agent Host defaults, managed permissions, and exit-plan handler to create and resume'
,
async
(
)
=>
{
const
:
<
[
'createSession'
]
>
[
0
]
[
]
=
[
]
;
const
:
<
[
'resumeSession'
]
>
[
1
]
[
]
=
[
]
;
const
=
{
:
'session-1'
,
on
:
(
)
=>
(
)
=>
{
}
,
disconnect
:
async
(
)
=>
{
}
,
:
{
:
{
update
:
async
(
)
=>
(
{
:
true
}
)
}
}
,
}
as
unknown
as
;
const
=
{
:
async
(
:
<
[
'createSession'
]
>
[
0
]
)
=>
{
.
push
(
)
;
return
;
}
,
:
async
(
:
string
,
:
<
[
'resumeSession'
]
>
[
1
]
)
=>
{
.
push
(
)
;
return
;
}
,
}
;
const
:
=
{
:
'disable'
,
:
[
'Shell'
]
,
}
;
const
=
new
CapturingLogService
(
)
;
const
=
createTestLauncher
(
,
{
}
,
)
;
const
=
URI
.
file
(
'/tmp/synced-customizations'
)
;
const
=
URI
.
file
(
'/tmp/vscode-synced-customizations'
)
;
const
=
URI
.
joinPath
(
,
'skills'
,
'user-skill'
,
'SKILL.md'
)
;
const
=
URI
.
joinPath
(
,
'rules'
,
'user.instructions.md'
)
;
const
:
=
{
:
.
,
:
[
]
,
:
[
{
:
'native-plugin-server'
,
:
URI
.
joinPath
(
,
'.mcp.json'
)
,
:
,
:
'pluginDiscovery'
,
:
{
:
.
LOCAL
,
:
'/sensitive/plugin-command'
,
:
{
API_TOKEN
:
'sensitive-plugin-env'
}
}
,
:
{
:
.
,
:
'native-plugin-server'
,
:
URI
.
joinPath
(
,
'.mcp.json'
)
.
toString
(
)
,
:
'native-plugin-server'
,
:
{
:
.
}
,
}
,
}
]
,
:
[
'azure'
,
'azure'
,
'disabled-workspace-server'
]
,
:
[
]
,
:
[
{
:
,
:
'user-skill'
,
:
{
:
.
,
:
.
toString
(
)
,
:
.
toString
(
)
,
:
'user-skill'
}
,
}
]
,
:
[
{
:
,
:
'user'
,
:
{
:
.
,
:
.
toString
(
)
,
:
.
toString
(
)
,
:
'user'
,
:
true
}
,
}
]
,
,
}
;
const
:
=
{
:
.
,
:
[
]
,
:
[
{
:
'synced-server'
,
:
URI
.
joinPath
(
,
'.mcp.json'
)
,
:
,
:
'sessionConfig'
,
:
{
:
.
REMOTE
,
:
'https://sensitive.example/mcp'
,
:
{
:
'sensitive-header'
}
}
,
:
{
:
.
,
:
'synced-server'
,
:
URI
.
joinPath
(
,
'.mcp.json'
)
.
toString
(
)
,
:
'synced-server'
,
:
{
:
.
}
,
}
,
}
]
,
:
[
]
,
:
[
]
,
:
[
]
,
:
,
}
;
const
=
{
,
:
'session-1'
,
:
,
:
undefined
,
:
{
:
[
]
,
:
[
,
]
,
:
{
}
}
,
:
[
'github'
,
'azure'
]
,
:
new
ActiveClientToolSet
(
)
,
:
undefined
,
:
undefined
,
}
;
const
:
=
{
...
,
:
'create'
,
:
undefined
,
}
;
const
:
=
{
...
,
:
'resume'
,
:
{
:
undefined
}
,
}
;
const
=
new
DisposableStore
(
)
;
try
{
.
add
(
await
.
launch
(
,
)
)
;
.
add
(
await
.
launch
(
,
)
)
;
.
add
(
await
.
launch
(
{
...
,
:
true
}
,
)
)
;
.
deepStrictEqual
(
{
:
[
0
]
.
,
:
[
0
]
.
,
:
[
0
]
.
,
:
[
0
]
.
,
:
[
0
]
.
,
:
[
0
]
.
,
:
[
0
]
.
,
:
typeof
[
0
]
.
===
'function'
,
:
[
0
]
.
,
:
[
0
]
.
,
:
[
0
]
.
,
:
[
0
]
.
,
:
[
0
]
.
,
:
[
0
]
.
,
:
[
0
]
.
,
:
[
0
]
.
,
:
[
0
]
.
,
:
typeof
[
0
]
.
===
'function'
,
:
[
0
]
.
,
:
[
0
]
.
,
:
[
1
]
.
,
:
[
1
]
.
,
:
[
1
]
.
,
:
.
.
filter
(
=>
.
includes
(
'MCP launch projection:'
)
)
.
map
(
=>
JSON
.
parse
(
.
slice
(
.
indexOf
(
'{'
)
)
)
)
,
:
[
'/sensitive/plugin-command'
,
'sensitive-plugin-env'
,
'https://sensitive.example/mcp'
,
'sensitive-header'
,
.
,
.
,
.
,
]
.
filter
(
=>
.
.
some
(
=>
.
includes
(
'MCP launch projection:'
)
&&
.
includes
(
)
)
)
,
}
,
{
:
'vscode-agent-host'
,
:
{
:
true
}
,
:
[
.
,
.
]
,
:
{
'synced-server'
:
{
:
'http'
,
:
'https://sensitive.example/mcp'
,
:
[
'*'
]
,
:
{
:
'sensitive-header'
}
,
}
,
}
,
:
[
]
,
:
[
URI
.
joinPath
(
,
'rules'
)
.
]
,
:
[
'azure'
,
'disabled-workspace-server'
,
'github'
]
,
:
true
,
:
{
:
8192
}
,
:
{
:
}
,
:
'vscode-agent-host'
,
:
{
:
true
}
,
:
[
.
,
.
]
,
:
{
'synced-server'
:
{
:
'http'
,
:
'https://sensitive.example/mcp'
,
:
[
'*'
]
,
:
{
:
'sensitive-header'
}
,
}
,
}
,
:
[
]
,
:
[
URI
.
joinPath
(
,
'rules'
)
.
]
,
:
[
'azure'
,
'disabled-workspace-server'
,
'github'
]
,
:
true
,
:
{
:
8192
}
,
:
{
:
}
,
:
{
}
,
:
[
'azure'
,
'disabled-workspace-server'
,
'github'
,
'native-plugin-server'
,
'synced-server'
]
,
:
[
'task'
,
`builtin:${SEMANTIC_SEARCH_TOOL_NAME}`
]
,
:
[
{
:
false
,
:
[
'native-plugin-server'
]
,
:
[
'synced-server'
]
,
:
[
]
,
:
[
'azure'
,
'disabled-workspace-server'
,
'github'
]
,
:
[
'synced-server'
]
,
}
,
{
:
false
,
:
[
'native-plugin-server'
]
,
:
[
'synced-server'
]
,
:
[
]
,
:
[
'azure'
,
'disabled-workspace-server'
,
'github'
]
,
:
[
'synced-server'
]
,
}
,
{
:
true
,
:
[
'native-plugin-server'
]
,
:
[
'synced-server'
]
,
:
[
]
,
:
[
'azure'
,
'disabled-workspace-server'
,
'github'
,
'native-plugin-server'
,
'synced-server'
]
,
:
[
]
,
}
,
]
,
:
[
]
,
}
)
;
}
finally
{
.
dispose
(
)
;
await
.
disposeByokProxyHandle
(
)
;
}
}
)
;
}
)
;
suite
(
'CopilotSessionLauncher resume fallback'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
class
TestSdkError
extends
Error
{
constructor
(
:
string
,
readonly
:
number
)
{
super
(
)
;
}
}
function
createResumeFailingLaunch
(
:
string
,
=
-
32603
,
:
=
)
:
{
readonly
:
;
readonly
:
;
readonly
getCreateSessionCalls
:
(
)
=>
number
}
{
let
=
0
;
const
=
{
:
'session-1'
,
on
:
(
)
=>
(
)
=>
{
}
,
disconnect
:
async
(
)
=>
{
}
,
:
{
:
{
update
:
async
(
)
=>
(
{
:
true
}
)
}
}
,
}
as
unknown
as
;
const
=
{
createSession
:
async
(
)
=>
{
++
;
return
;
}
,
resumeSession
:
async
(
)
=>
{
throw
new
TestSdkError
(
,
)
;
}
,
}
;
return
{
:
createTestLauncher
(
undefined
,
{
}
,
new
NullLogService
(
)
,
)
,
:
{
,
:
'session-1'
,
:
,
:
undefined
,
:
{
:
[
]
,
:
[
]
,
:
{
}
}
,
:
new
ActiveClientToolSet
(
)
,
:
undefined
,
:
undefined
,
:
'resume'
,
:
{
:
undefined
}
,
}
,
getCreateSessionCalls
:
(
)
=>
,
}
;
}
test
(
'falls back to createSession after a Start Over truncate leaves the session empty'
,
async
(
)
=>
{
const
{
,
,
}
=
createResumeFailingLaunch
(
`Request session.resume failed with message: LocalRpcSession: 'session.getMessages' returned no events for session session-1`
)
;
const
=
new
DisposableStore
(
)
;
try
{
.
add
(
await
.
launch
(
,
)
)
;
.
strictEqual
(
getCreateSessionCalls
(
)
,
1
)
;
}
finally
{
.
dispose
(
)
;
await
.
disposeByokProxyHandle
(
)
;
}
}
)
;
test
(
'reports SDK resume failure and fallback creation milestones'
,
async
(
)
=>
{
const
:
string
[
]
=
[
]
;
const
:
=
{
...
,
withSdkResume
:
async
(
,
)
=>
{
.
push
(
`start:${session.scheme}`
)
;
try
{
const
=
await
operation
(
)
;
.
push
(
'complete:success'
)
;
return
;
}
catch
(
)
{
.
push
(
'complete:failure'
)
;
throw
;
}
}
,
sdkResumeFallbackCreated
:
(
)
=>
.
push
(
'complete:fallbackCreate'
)
,
}
;
const
{
,
}
=
createResumeFailingLaunch
(
`Request session.resume failed with message: LocalRpcSession: 'session.getMessages' returned no events for session session-1`
,
-
32603
,
)
;
const
=
new
DisposableStore
(
)
;
try
{
.
add
(
await
.
launch
(
,
)
)
;
.
deepStrictEqual
(
,
[
'start:copilotcli'
,
'complete:failure'
,
'complete:fallbackCreate'
,
]
)
;
}
finally
{
.
dispose
(
)
;
await
.
disposeByokProxyHandle
(
)
;
}
}
)
;
test
(
'falls back to createSession when the SDK reports the session was not found'
,
async
(
)
=>
{
const
{
,
,
}
=
createResumeFailingLaunch
(
'Request session.resume failed with message: Session not found: session-1'
)
;
const
=
new
DisposableStore
(
)
;
try
{
.
add
(
await
.
launch
(
,
)
)
;
.
strictEqual
(
getCreateSessionCalls
(
)
,
1
)
;
}
finally
{
.
dispose
(
)
;
await
.
disposeByokProxyHandle
(
)
;
}
}
)
;
test
(
'does not replace a session with an empty one after a transient network failure'
,
async
(
)
=>
{
// Regression: this used to fall through to `createSession`, presenting a
// session with real history as having zero turns — which the empty-session
// GC then deleted along with its worktree.
const
{
,
,
}
=
createResumeFailingLaunch
(
'Request session.resume failed with message: network fetch failed: request failed: error sending request for url (https://api.github.com/copilot_internal/user)'
)
;
try
{
await
.
rejects
(
(
)
=>
.
launch
(
,
)
,
/network fetch failed/
)
;
.
strictEqual
(
getCreateSessionCalls
(
)
,
0
)
;
}
finally
{
await
.
disposeByokProxyHandle
(
)
;
}
}
)
;
test
(
'does not replace a session with an empty one for an unrecognized -32603'
,
async
(
)
=>
{
const
{
,
,
}
=
createResumeFailingLaunch
(
'Request session.resume failed: something went wrong'
)
;
try
{
await
.
rejects
(
(
)
=>
.
launch
(
,
)
,
/something went wrong/
)
;
.
strictEqual
(
getCreateSessionCalls
(
)
,
0
)
;
}
finally
{
await
.
disposeByokProxyHandle
(
)
;
}
}
)
;
test
(
'does not replace a corrupted session file with an empty session'
,
async
(
)
=>
{
const
{
,
,
}
=
createResumeFailingLaunch
(
'Request session.resume failed with message: Session file is corrupted (line 19567: data.compactionTokensUsed.copilotUsage.tokenDetails.0.batchSize: Number must be greater than 0)'
)
;
try
{
await
.
rejects
(
(
)
=>
.
launch
(
,
)
,
/Session file is corrupted/
)
;
.
strictEqual
(
getCreateSessionCalls
(
)
,
0
)
;
}
finally
{
await
.
disposeByokProxyHandle
(
)
;
}
}
)
;
}
)
;
suite
(
'CopilotSessionLauncher verbosity'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
function
applyVerbosity
(
:
)
:
Promise
<
void
>
{
const
=
createTestLauncher
(
)
as
unknown
as
{
_applyVerbosity
(
:
,
:
,
:
string
)
:
Promise
<
void
>
;
}
;
const
=
{
:
{
:
{
update
:
async
(
:
unknown
)
=>
{
.
push
(
)
;
return
{
:
true
}
;
}
,
}
,
}
,
}
as
unknown
as
;
return
.
_applyVerbosity
(
,
,
'session-1'
)
;
}
const
:
unknown
[
]
=
[
]
;
setup
(
(
)
=>
.
=
0
)
;
test
(
'forwards the requested verbosity'
,
async
(
)
=>
{
await
applyVerbosity
(
'high'
)
;
.
deepStrictEqual
(
,
[
{
:
'high'
}
]
)
;
}
)
;
}
)
;
suite
(
'CopilotSessionLauncher reasoning summary'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
function
applyReasoningSummary
(
:
)
:
Promise
<
void
>
{
const
=
createTestLauncher
(
)
as
unknown
as
{
_applyReasoningSummary
(
:
,
:
,
:
string
)
:
Promise
<
void
>
;
}
;
const
=
{
:
{
:
{
update
:
async
(
:
unknown
)
=>
{
.
push
(
)
;
return
{
:
true
}
;
}
,
}
,
}
,
}
as
unknown
as
;
return
.
_applyReasoningSummary
(
,
,
'session-1'
)
;
}
const
:
unknown
[
]
=
[
]
;
setup
(
(
)
=>
.
=
0
)
;
test
(
'forwards the requested reasoning summary'
,
async
(
)
=>
{
await
applyReasoningSummary
(
'detailed'
)
;
.
deepStrictEqual
(
,
[
{
:
'detailed'
}
]
)
;
}
)
;
}
)
;
suite
(
'CopilotSessionLauncher GPT-5.6 customizations'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'applies verbosity and concise reasoning summary when enabled by experiment'
,
async
(
)
=>
{
const
:
unknown
[
]
=
[
]
;
const
=
createTestLauncher
(
undefined
,
{
[
.
]
:
true
}
)
as
unknown
as
{
_applyGpt56Customizations
(
:
,
:
string
)
:
Promise
<
void
>
;
}
;
const
=
{
:
{
:
{
update
:
async
(
:
unknown
)
=>
{
.
push
(
)
;
return
{
:
true
}
;
}
,
}
,
}
,
}
as
unknown
as
;
await
.
_applyGpt56Customizations
(
,
'session-1'
)
;
.
deepStrictEqual
(
,
[
{
:
'medium'
}
,
{
:
'concise'
}
,
]
)
;
}
)
;
test
(
'does not apply reasoning summary when the experiment is unset or disabled'
,
async
(
)
=>
{
for
(
const
of
[
undefined
,
false
]
)
{
const
:
unknown
[
]
=
[
]
;
const
=
createTestLauncher
(
undefined
,
{
[
.
]
:
}
)
as
unknown
as
{
_applyGpt56Customizations
(
:
,
:
string
)
:
Promise
<
void
>
;
}
;
const
=
{
:
{
:
{
update
:
async
(
:
unknown
)
=>
{
.
push
(
)
;
return
{
:
true
}
;
}
}
}
,
}
as
unknown
as
;
await
.
_applyGpt56Customizations
(
,
'session-1'
)
;
.
deepStrictEqual
(
,
[
{
:
'medium'
}
]
)
;
}
}
)
;
test
(
'enables script safety on a non-GPT-5.6 created session so managed permissions govern shell paths'
,
async
(
)
=>
{
const
:
unknown
[
]
=
[
]
;
const
=
{
:
'session-1'
,
on
:
(
)
=>
(
)
=>
{
}
,
disconnect
:
async
(
)
=>
{
}
,
:
{
:
{
update
:
async
(
:
unknown
)
=>
{
.
push
(
)
;
return
{
:
true
}
;
}
}
}
,
}
as
unknown
as
;
// Enablement is required for every session regardless of managed rules, so
// anything short of success would fail the launch — the success path is what
// is asserted here.
const
=
createTestLauncher
(
)
;
const
:
=
{
:
'create'
,
:
{
createSession
:
async
(
)
=>
}
as
unknown
as
,
:
'session-1'
,
:
,
:
undefined
,
:
{
:
[
]
,
:
[
]
,
:
{
}
}
,
:
new
ActiveClientToolSet
(
)
,
:
undefined
,
:
undefined
,
:
{
:
'claude-sonnet-4.5'
,
:
{
}
}
,
}
;
const
=
await
.
launch
(
,
)
;
try
{
.
deepStrictEqual
(
,
[
{
:
true
}
]
)
;
}
finally
{
.
dispose
(
)
;
await
.
disposeByokProxyHandle
(
)
;
}
}
)
;
test
(
'fails the launch closed and disconnects when script safety cannot be enabled'
,
async
(
)
=>
{
let
=
false
;
const
=
{
:
'session-1'
,
on
:
(
)
=>
(
)
=>
{
}
,
disconnect
:
async
(
)
=>
{
=
true
;
}
,
:
{
:
{
update
:
async
(
)
=>
(
{
:
false
}
)
}
}
,
}
as
unknown
as
;
const
=
createTestLauncher
(
{
:
[
'Shell(rm -rf *)'
]
}
)
;
const
:
=
{
:
'create'
,
:
{
createSession
:
async
(
)
=>
}
as
unknown
as
,
:
'session-1'
,
:
,
:
undefined
,
:
{
:
[
]
,
:
[
]
,
:
{
}
}
,
:
new
ActiveClientToolSet
(
)
,
:
undefined
,
:
undefined
,
:
{
:
'claude-sonnet-4.5'
,
:
{
}
}
,
}
;
await
.
rejects
(
(
)
=>
.
launch
(
,
)
,
/script safety/
)
;
.
strictEqual
(
,
true
,
'expected the orphaned session to be disconnected'
)
;
await
.
disposeByokProxyHandle
(
)
;
}
)
;
test
(
'fails closed even when the host sees no managed rules, since server and MDM policy is invisible to it'
,
async
(
)
=>
{
let
=
false
;
const
=
{
:
'session-1'
,
on
:
(
)
=>
(
)
=>
{
}
,
disconnect
:
async
(
)
=>
{
=
true
;
}
,
:
{
:
{
update
:
async
(
)
=>
(
{
:
false
}
)
}
}
,
}
as
unknown
as
;
// No client-bridged rules. `IAgentHostManagedSettingsService` only carries the
// legacy VS Code settings bridge, so an enterprise session governed solely by
// GitHub or MDM policy looks exactly like this one from the host's side.
const
=
createTestLauncher
(
)
;
const
:
=
{
:
'create'
,
:
{
createSession
:
async
(
)
=>
}
as
unknown
as
,
:
'session-1'
,
:
,
:
undefined
,
:
{
:
[
]
,
:
[
]
,
:
{
}
}
,
:
new
ActiveClientToolSet
(
)
,
:
undefined
,
:
undefined
,
:
{
:
'claude-sonnet-4.5'
,
:
{
}
}
,
}
;
await
.
rejects
(
(
)
=>
.
launch
(
,
)
,
/script safety/
)
;
.
strictEqual
(
,
true
,
'expected the orphaned session to be disconnected'
)
;
await
.
disposeByokProxyHandle
(
)
;
}
)
;
// The runtime reports success for any patch it accepts and signals real problems by
// failing the request, so a rejected RPC — not a `success: false` body — is the path
// a genuine enablement failure takes.
test
(
'fails the launch closed and disconnects when the script safety request itself fails'
,
async
(
)
=>
{
let
=
false
;
const
=
{
:
'session-1'
,
on
:
(
)
=>
(
)
=>
{
}
,
disconnect
:
async
(
)
=>
{
=
true
;
}
,
:
{
:
{
update
:
async
(
)
=>
{
throw
new
Error
(
'connection closed'
)
;
}
}
}
,
}
as
unknown
as
;
const
=
createTestLauncher
(
)
;
const
:
=
{
:
'create'
,
:
{
createSession
:
async
(
)
=>
}
as
unknown
as
,
:
'session-1'
,
:
,
:
undefined
,
:
{
:
[
]
,
:
[
]
,
:
{
}
}
,
:
new
ActiveClientToolSet
(
)
,
:
undefined
,
:
undefined
,
:
{
:
'claude-sonnet-4.5'
,
:
{
}
}
,
}
;
await
.
rejects
(
(
)
=>
.
launch
(
,
)
,
/connection closed/
)
;
.
strictEqual
(
,
true
,
'expected the orphaned session to be disconnected'
)
;
await
.
disposeByokProxyHandle
(
)
;
}
)
;
test
(
'applies GPT-5.6 customizations when resuming an existing session'
,
async
(
)
=>
{
const
:
unknown
[
]
=
[
]
;
const
=
{
:
'session-1'
,
on
:
(
)
=>
(
)
=>
{
}
,
disconnect
:
async
(
)
=>
{
}
,
:
{
:
{
update
:
async
(
:
unknown
)
=>
{
.
push
(
)
;
return
{
:
true
}
;
}
}
}
,
}
as
unknown
as
;
const
=
createTestLauncher
(
undefined
,
{
[
.
]
:
true
}
)
;
const
:
=
{
:
'resume'
,
:
{
resumeSession
:
async
(
)
=>
}
as
unknown
as
,
:
'session-1'
,
:
,
:
undefined
,
:
{
:
[
]
,
:
[
]
,
:
{
}
}
,
:
new
ActiveClientToolSet
(
)
,
:
undefined
,
:
undefined
,
:
{
:
{
:
'gpt-5.6-sol'
,
:
{
}
}
}
,
}
;
const
=
await
.
launch
(
,
)
;
try
{
.
deepStrictEqual
(
,
[
{
:
true
}
,
{
:
'medium'
}
,
{
:
'concise'
}
,
]
)
;
}
finally
{
.
dispose
(
)
;
await
.
disposeByokProxyHandle
(
)
;
}
}
)
;
}
)
;
/**
* Covers the reasoning-effort resolution fed into `createSession` and
* `CopilotAgent._changeModel`: a valid capability override wins over the model
* picker's thinking level, and degrades to the picker value otherwise.
*/
suite
(
'getCopilotReasoningEffort'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'a valid override wins over the picker value; an invalid or absent override falls back'
,
(
)
=>
{
const
:
=
{
:
'gpt-5'
,
:
{
:
'medium'
}
}
;
.
deepStrictEqual
(
[
getCopilotReasoningEffort
(
)
,
getCopilotReasoningEffort
(
,
'xhigh'
)
,
getCopilotReasoningEffort
(
,
'turbo'
)
,
getCopilotReasoningEffort
(
undefined
,
'high'
)
,
getCopilotReasoningEffort
(
undefined
)
,
]
,
[
'medium'
,
'xhigh'
,
'medium'
,
'high'
,
undefined
]
)
;
}
)
;
// The model picker's options are `supportedReasoningEfforts.filter(isCopilotReasoningEffort)`,
// so any tier this guard rejects silently disappears from the picker — that is how `'max'`
// went missing. The guard must therefore recognize every canonical tier; re-introducing a
// narrower private allow-list here has to fail.
test
(
'recognizes every canonical reasoning-effort tier so none is dropped from the picker'
,
(
)
=>
{
.
deepStrictEqual
(
{
:
.
filter
(
)
,
:
isCopilotReasoningEffort
(
'turbo'
)
,
}
,
{
:
[
...
]
,
:
false
,
}
)
;
}
)
;
}
)
;
/** A specific entry wins over `*`, which wins over the picker; invalid falls through. */
suite
(
'resolveCopilotReasoningEffort'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
/** Stubs the config service with a fixed root-value bag. */
function
configOf
(
:
<
typeof
.
>
)
:
<
,
'getRootValue'
>
{
// `never` satisfies the generic return type without widening to `any`.
return
{
getRootValue
:
(
,
)
=>
[
as
keyof
typeof
]
as
never
}
;
}
test
(
'a specific entry beats the wildcard beats the picker; invalid values fall through'
,
(
)
=>
{
const
=
new
NullLogService
(
)
;
const
:
=
{
:
'gpt-5'
,
:
{
:
'medium'
}
}
;
.
deepStrictEqual
(
[
// a specific entry wins over the picker
resolveCopilotReasoningEffort
(
,
configOf
(
{
:
{
'gpt-5'
:
{
:
'low'
}
}
}
)
,
,
's1'
)
,
// the wildcard applies to any model; a specific entry wins over it
resolveCopilotReasoningEffort
(
,
configOf
(
{
:
{
'*'
:
{
:
'high'
}
}
}
)
,
,
's1'
)
,
resolveCopilotReasoningEffort
(
,
configOf
(
{
:
{
'*'
:
{
:
'high'
}
,
'gpt-5'
:
{
:
'low'
}
}
}
)
,
,
's1'
)
,
// an invalid specific value is ignored, so it cannot mask the wildcard
resolveCopilotReasoningEffort
(
,
configOf
(
{
:
{
'*'
:
{
:
'high'
}
,
'gpt-5'
:
{
:
'turbo'
}
}
}
)
,
,
's1'
)
,
// an invalid value falls through to the picker
resolveCopilotReasoningEffort
(
,
configOf
(
{
:
{
'gpt-5'
:
{
:
'turbo'
}
}
}
)
,
,
's1'
)
,
// nothing configured → picker value
resolveCopilotReasoningEffort
(
,
configOf
(
{
}
)
,
,
's1'
)
,
// no model (server-side "Auto"): the `*` entry still matches, but a
// model-id entry cannot
resolveCopilotReasoningEffort
(
undefined
,
configOf
(
{
:
{
'*'
:
{
:
'low'
}
}
}
)
,
,
's1'
)
,
resolveCopilotReasoningEffort
(
undefined
,
configOf
(
{
:
{
'gpt-5'
:
{
:
'low'
}
}
}
)
,
,
's1'
)
,
]
,
[
'low'
,
'high'
,
'low'
,
'high'
,
'medium'
,
'medium'
,
'low'
,
undefined
]
)
;
}
)
;
test
(
'resolveConfiguredReasoningEffortOverride reports only the configured override, never the picker value'
,
(
)
=>
{
const
=
new
NullLogService
(
)
;
const
:
=
{
:
'gpt-5'
,
:
{
:
'medium'
}
}
;
.
deepStrictEqual
(
[
// same resolution as above...
resolveConfiguredReasoningEffortOverride
(
,
configOf
(
{
:
{
'gpt-5'
:
{
:
'low'
}
}
}
)
,
,
's1'
)
,
resolveConfiguredReasoningEffortOverride
(
,
configOf
(
{
:
{
'*'
:
{
:
'high'
}
}
}
)
,
,
's1'
)
,
// ...but no picker fallback: unconfigured or invalid means "leave it alone"
resolveConfiguredReasoningEffortOverride
(
,
configOf
(
{
:
{
'gpt-5'
:
{
:
'turbo'
}
}
}
)
,
,
's1'
)
,
resolveConfiguredReasoningEffortOverride
(
,
configOf
(
{
}
)
,
,
's1'
)
,
]
,
[
'low'
,
'high'
,
undefined
,
undefined
]
)
;
}
)
;
}
)
;
/**
* The Auto model's routing profile ("Optimize for"): only the `auto` entry routes per turn, and the
* host's `autoModeTiers` gate decides whether the profile ever reaches the runtime.
*/
suite
(
'getCopilotAutoTier'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'reads a valid profile from the Auto model only'
,
(
)
=>
{
.
deepStrictEqual
(
[
getCopilotAutoTier
(
{
:
'auto'
,
:
{
:
'intelligence'
}
}
)
,
// The picker's default is a real selection, forwarded like any other.
getCopilotAutoTier
(
{
:
'auto'
,
:
{
:
'balance'
}
}
)
,
// A retired tier name is not a runtime wire value, so sending it would be rejected.
getCopilotAutoTier
(
{
:
'auto'
,
:
{
:
'max'
}
}
)
,
getCopilotAutoTier
(
{
:
'auto'
}
)
,
// A profile left on a concrete model by an earlier Auto selection.
getCopilotAutoTier
(
{
:
'gpt-5'
,
:
{
:
'efficiency'
}
}
)
,
getCopilotAutoTier
(
undefined
)
,
]
,
[
'intelligence'
,
'balance'
,
undefined
,
undefined
,
undefined
,
undefined
]
)
;
}
)
;
// The picker offers `autoModeTiers` verbatim, so a value this guard rejects would render as a
// selectable profile that the runtime then refuses.
test
(
'accepts every profile the picker offers'
,
(
)
=>
{
.
deepStrictEqual
(
.
map
(
=>
getCopilotAutoTier
(
{
:
'auto'
,
:
{
}
}
)
)
,
[
...
]
)
;
}
)
;
test
(
'only forwards a profile while the gate is on'
,
(
)
=>
{
const
=
new
NullLogService
(
)
;
const
:
=
{
:
'auto'
,
:
{
:
'efficiency'
}
}
;
const
=
(
:
boolean
|
undefined
)
:
<
,
'getRootValue'
>
=>
(
{
getRootValue
:
(
,
)
=>
(
===
.
?
:
undefined
)
as
never
}
)
;
.
deepStrictEqual
(
[
resolveCopilotAutoTier
(
,
configOf
(
true
)
,
,
's1'
)
,
// A profile persisted while the gate was on must not survive turning it off: the runtime
// rejects unknown `capi` fields, so an older runtime would fail the session outright.
resolveCopilotAutoTier
(
,
configOf
(
false
)
,
,
's1'
)
,
resolveCopilotAutoTier
(
,
configOf
(
undefined
)
,
,
's1'
)
,
resolveCopilotAutoTier
(
{
:
'gpt-5'
,
:
{
:
'efficiency'
}
}
,
configOf
(
true
)
,
,
's1'
)
,
]
,
[
'efficiency'
,
undefined
,
undefined
,
undefined
]
)
;
}
)
;
}
)
;
/**
* Client tools are all `custom:`-source, so only a bare name, `custom:<name>` or
* `custom:*` matches, and `excludedTools` wins — mirroring the SDK.
*/
suite
(
'filterClientToolNames'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'applies allow/deny patterns with excludedTools winning; other sources never match'
,
(
)
=>
{
const
=
new
Set
(
[
'openBrowserPage'
,
'readPage'
,
'runTask'
]
)
;
const
resolve
=
(
?
:
string
[
]
,
?
:
string
[
]
)
=>
[
...
filterClientToolNames
(
,
,
)
]
.
sort
(
)
;
.
deepStrictEqual
(
[
// no filters → same set (and same instance semantics: everything survives)
resolve
(
undefined
,
undefined
)
,
// bare-name, source-qualified, and source-wildcard exclusion
resolve
(
undefined
,
[
'openBrowserPage'
]
)
,
resolve
(
undefined
,
[
'custom:readPage'
]
)
,
resolve
(
undefined
,
[
'custom:*'
]
)
,
// builtin/mcp patterns never match client tools
resolve
(
undefined
,
[
'builtin:*'
,
'mcp:*'
,
'bash'
]
)
,
// allowlist keeps only matches; excludedTools wins over availableTools
resolve
(
[
'openBrowserPage'
,
'custom:readPage'
]
,
undefined
)
,
resolve
(
[
'custom:*'
]
,
[
'openBrowserPage'
]
)
,
]
,
[
[
'openBrowserPage'
,
'readPage'
,
'runTask'
]
,
[
'readPage'
,
'runTask'
]
,
[
'openBrowserPage'
,
'runTask'
]
,
[
]
,
[
'openBrowserPage'
,
'readPage'
,
'runTask'
]
,
[
'openBrowserPage'
,
'readPage'
]
,
[
'readPage'
,
'runTask'
]
,
]
)
;
const
=
new
Set
(
[
CLIENT_TOOL_SEARCH_REFERENCE_NAME
,
'runTask'
]
)
;
const
resolveSearch
=
(
:
string
[
]
)
=>
[
...
filterClientToolNames
(
,
undefined
,
)
]
.
sort
(
)
;
.
deepStrictEqual
(
[
resolveSearch
(
[
`builtin:${RUNTIME_TOOL_SEARCH_TOOL_NAME}`
]
)
,
resolveSearch
(
[
'builtin:*'
]
)
,
resolveSearch
(
[
RUNTIME_TOOL_SEARCH_TOOL_NAME
]
)
,
// Client tools are custom-source even when they override a built-in.
[
...
filterClientToolNames
(
,
[
'builtin:*'
]
,
undefined
)
]
,
]
,
[
[
'runTask'
,
'toolSearch'
]
,
[
'runTask'
,
'toolSearch'
]
,
[
'runTask'
]
,
[
]
,
]
)
;
}
)
;
test
(
'keeps Agent Host and SDK tool-search names consistent'
,
(
)
=>
{
const
=
new
Set
(
[
CLIENT_TOOL_SEARCH_REFERENCE_NAME
]
)
;
.
deepStrictEqual
(
[
[
...
filterClientToolNames
(
,
[
CLIENT_TOOL_SEARCH_REFERENCE_NAME
]
,
undefined
)
]
,
[
...
filterClientToolNames
(
,
[
RUNTIME_TOOL_SEARCH_TOOL_NAME
]
,
undefined
)
]
,
[
...
filterClientToolNames
(
,
undefined
,
[
`custom:${RUNTIME_TOOL_SEARCH_TOOL_NAME}`
]
)
]
,
toSdkToolFilterPatterns
(
[
CLIENT_TOOL_SEARCH_REFERENCE_NAME
,
`custom:${CLIENT_TOOL_SEARCH_REFERENCE_NAME}`
,
'builtin:*'
]
)
,
]
,
[
[
CLIENT_TOOL_SEARCH_REFERENCE_NAME
]
,
[
CLIENT_TOOL_SEARCH_REFERENCE_NAME
]
,
[
]
,
[
RUNTIME_TOOL_SEARCH_TOOL_NAME
,
`custom:${RUNTIME_TOOL_SEARCH_TOOL_NAME}`
,
'builtin:*'
]
,
]
)
;
}
)
;
}
)
;
/**
* A resumed session keeps the effort the runtime journaled unless an override is
* configured; `_createSession` resolves the full effort for a create.
*/
suite
(
'normalizeToolFilterPatterns'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
test
(
'expands a bare wildcard and coerces a lone string; unusable values read as unset'
,
(
)
=>
{
.
deepStrictEqual
(
[
// a bare '*' is expanded, not dropped — an "exclude everything"
// denylist must not degrade into "exclude nothing"
normalizeToolFilterPatterns
(
[
'*'
]
)
,
normalizeToolFilterPatterns
(
[
'mcp:*'
,
'*'
]
)
,
// a lone string reads as a one-element list
normalizeToolFilterPatterns
(
'mcp:*'
)
,
// an empty allowlist means "no tools", so it must not read as unset
normalizeToolFilterPatterns
(
[
]
)
,
// not a list at all → unusable
normalizeToolFilterPatterns
(
undefined
)
,
normalizeToolFilterPatterns
(
42
)
,
normalizeToolFilterPatterns
(
[
'ok'
,
7
]
)
,
]
,
[
[
'builtin:*'
,
'mcp:*'
,
'custom:*'
]
,
[
'mcp:*'
,
'builtin:*'
,
'custom:*'
]
,
[
'mcp:*'
]
,
[
]
,
undefined
,
undefined
,
undefined
,
]
)
;
}
)
;
}
)
;
suite
(
'CopilotSessionLauncher resume config'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
/** Builds a launcher over a config service stubbed with a fixed root-value bag. */
function
createLauncher
(
:
,
:
<
typeof
.
>
)
:
{
const
=
new
ServiceCollection
(
)
;
.
set
(
,
new
NullLogService
(
)
)
;
.
set
(
,
new
ByokLmBridgeRegistry
(
)
)
;
.
set
(
,
.
add
(
new
AgentHostManagedSettingsService
(
)
)
)
;
.
set
(
,
{
:
undefined
,
getRootValue
:
(
:
unknown
,
:
string
)
=>
[
as
keyof
typeof
]
,
}
as
unknown
as
)
;
// The launcher's other dependencies are unused by this path and resolve
// to `undefined` under the non-strict InstantiationService.
const
=
.
add
(
new
InstantiationService
(
)
)
;
return
.
createInstance
(
)
;
}
/** Invokes the private config builder with a minimal resume plan. */
function
buildResumeConfig
(
:
,
:
|
undefined
,
:
[
'snapshot'
]
=
{
:
[
]
,
:
[
]
,
:
{
}
}
,
:
[
'createClientSdkTools'
]
=
(
)
=>
[
]
,
)
:
Promise
<
{
?
:
string
;
?
:
string
;
?
:
string
;
?
:
string
[
]
;
?
:
string
[
]
;
?
:
<
string
,
unknown
>
;
?
:
{
:
boolean
}
}
>
{
const
=
{
:
'resume'
,
:
{
createSession
:
async
(
)
=>
{
throw
new
Error
(
'unused'
)
;
}
,
resumeSession
:
async
(
)
=>
{
throw
new
Error
(
'unused'
)
;
}
}
,
:
'sess-1'
,
:
URI
.
file
(
'/workspace'
)
,
:
undefined
,
,
:
new
ActiveClientToolSet
(
)
,
:
undefined
,
:
'token'
,
:
{
}
,
}
;
const
=
{
,
createServerSdkTools
:
(
)
=>
[
]
}
;
return
(
as
unknown
as
{
_buildSessionConfig
(
:
unknown
,
:
unknown
)
:
Promise
<
{
?
:
string
;
?
:
string
;
?
:
string
;
?
:
string
[
]
;
?
:
string
[
]
;
?
:
<
string
,
unknown
>
;
?
:
{
:
boolean
}
}
>
}
)
.
_buildSessionConfig
(
,
)
;
}
test
(
'exposes only the client semantic-search override'
,
async
(
)
=>
{
const
=
new
DisposableStore
(
)
;
const
=
{
:
[
{
:
SEMANTIC_SEARCH_TOOL_NAME
}
]
,
:
[
]
,
:
{
}
}
;
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
}
)
,
undefined
,
{
:
[
]
,
:
[
]
,
:
{
}
}
)
;
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
}
)
,
undefined
,
)
;
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
:
{
'*'
:
{
:
[
`custom:${SEMANTIC_SEARCH_TOOL_NAME}`
]
}
}
}
)
,
undefined
,
,
)
;
.
deepStrictEqual
(
[
.
,
.
,
.
]
,
[
[
`builtin:${SEMANTIC_SEARCH_TOOL_NAME}`
]
,
undefined
,
[
`custom:${SEMANTIC_SEARCH_TOOL_NAME}`
,
`builtin:${SEMANTIC_SEARCH_TOOL_NAME}`
]
]
,
)
;
.
dispose
(
)
;
}
)
;
test
(
'forwards a configured override on resume and leaves the effort untouched otherwise'
,
async
(
)
=>
{
const
=
new
DisposableStore
(
)
;
const
:
=
{
:
'gpt-5'
,
:
{
:
'medium'
}
}
;
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
:
{
'gpt-5'
:
{
:
'low'
}
}
}
)
,
)
;
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
:
{
'*'
:
{
:
'xhigh'
}
}
}
)
,
)
;
// The picker value is NOT re-sent: without an override the resumed
// session keeps whatever effort the runtime persisted for it.
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
}
)
,
)
;
.
deepStrictEqual
(
[
.
,
.
,
.
]
,
[
'low'
,
'xhigh'
,
undefined
]
)
;
.
dispose
(
)
;
}
)
;
test
(
'never sends the model or context tier on resume, aliased or not'
,
async
(
)
=>
{
const
=
new
DisposableStore
(
)
;
const
:
=
{
:
'preview-model'
,
:
{
:
'medium'
}
}
;
// A `family` alias routes the host prompt only, so the resumed session keeps
// the model and tier the runtime journaled for it.
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
:
{
'preview-model'
:
{
:
'claude-opus-4.8'
}
}
}
)
,
)
;
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
}
)
,
)
;
.
deepStrictEqual
(
[
.
,
.
,
.
,
.
]
,
[
undefined
,
undefined
,
undefined
,
undefined
]
)
;
.
dispose
(
)
;
}
)
;
test
(
'a session with no stored model still gets the wildcard entry effort and tool filters'
,
async
(
)
=>
{
const
=
new
DisposableStore
(
)
;
// Sessions created without an explicit model (server-side "Auto") resume
// with `fallback.model === undefined`; `*` means every session, so
// exempting them would make the entry mean "every model except Auto".
const
=
createLauncher
(
,
{
:
{
'*'
:
{
:
'high'
,
:
[
'mcp:*'
]
}
,
'gpt-5'
:
{
:
'low'
}
}
}
)
;
const
=
await
buildResumeConfig
(
,
undefined
)
;
.
deepStrictEqual
(
[
.
,
.
]
,
[
'high'
,
[
'mcp:*'
,
`builtin:${SEMANTIC_SEARCH_TOOL_NAME}`
]
]
)
;
.
dispose
(
)
;
}
)
;
test
(
'forwards a configured modelCapabilities override and ignores a non-object one'
,
async
(
)
=>
{
const
=
new
DisposableStore
(
)
;
const
:
=
{
:
'gpt-5'
,
:
{
:
'medium'
}
}
;
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
:
{
'gpt-5'
:
{
:
{
:
{
:
false
}
}
}
}
}
)
,
)
;
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
:
{
'gpt-5'
:
{
:
'oops'
as
never
}
}
}
)
,
)
;
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
:
{
'*'
:
{
:
[
'custom:*'
]
,
:
[
'mcp:*'
]
,
:
{
:
{
:
true
}
}
,
}
,
'gpt-5'
:
{
:
42
as
never
,
:
42
as
never
,
:
'oops'
as
never
,
}
,
}
,
}
)
,
)
;
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
}
)
,
)
;
.
deepStrictEqual
(
[
.
,
.
,
{
:
.
,
:
.
,
:
.
,
}
,
.
,
]
,
[
{
:
{
:
false
}
}
,
undefined
,
{
:
[
'custom:*'
]
,
:
[
'mcp:*'
,
`builtin:${SEMANTIC_SEARCH_TOOL_NAME}`
]
,
:
{
:
{
:
true
}
}
,
}
,
undefined
,
]
)
;
.
dispose
(
)
;
}
)
;
test
(
'maps tool-search reference names to the SDK runtime name'
,
async
(
)
=>
{
const
=
new
DisposableStore
(
)
;
const
:
=
{
:
'gpt-5'
,
:
{
:
'medium'
}
}
;
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
:
{
'gpt-5'
:
{
:
[
CLIENT_TOOL_SEARCH_REFERENCE_NAME
]
,
:
[
`custom:${CLIENT_TOOL_SEARCH_REFERENCE_NAME}`
]
,
}
,
}
,
}
)
,
)
;
.
deepStrictEqual
(
[
.
,
.
]
,
[
[
RUNTIME_TOOL_SEARCH_TOOL_NAME
]
,
[
`custom:${RUNTIME_TOOL_SEARCH_TOOL_NAME}`
,
`builtin:${SEMANTIC_SEARCH_TOOL_NAME}`
]
]
)
;
.
dispose
(
)
;
}
)
;
test
(
'tool search gates on the flag, model support, and the family alias'
,
async
(
)
=>
{
const
=
new
DisposableStore
(
)
;
const
=
{
:
[
{
:
CLIENT_TOOL_SEARCH_REFERENCE_NAME
,
:
'Search tools'
,
:
{
:
'object'
as
const
,
:
{
}
}
}
]
,
:
[
]
,
:
{
}
,
}
;
const
toolSearchOf
=
async
(
:
<
typeof
.
>
,
:
)
=>
(
await
buildResumeConfig
(
createLauncher
(
,
)
,
,
)
)
.
;
.
deepStrictEqual
(
[
// flag off → disabled even on a supported model
await
toolSearchOf
(
{
:
false
}
,
{
:
'claude-opus-4.8'
}
)
,
// unsupported model → disabled even with the flag on
await
toolSearchOf
(
{
:
true
}
,
{
:
'preview-model-x'
}
)
,
// a family alias makes an unsupported preview model tool-search-capable
await
toolSearchOf
(
{
:
true
,
:
{
'preview-model-x'
:
{
:
'claude-opus-4.8'
}
}
}
,
{
:
'preview-model-x'
}
)
,
]
,
[
{
:
false
}
,
{
:
false
}
,
{
:
true
,
:
1
}
,
]
)
;
.
dispose
(
)
;
}
)
;
test
(
'uses one launch-time tool-search decision for the config and client tools'
,
async
(
)
=>
{
const
=
new
DisposableStore
(
)
;
const
:
boolean
[
]
=
[
]
;
const
:
=
{
:
'claude-opus-4.8'
,
:
{
:
'medium'
}
}
;
const
=
await
buildResumeConfig
(
createLauncher
(
,
{
:
true
,
:
{
'claude-opus-4.8'
:
{
:
[
'custom:*'
]
}
}
,
}
)
,
,
{
:
[
{
:
CLIENT_TOOL_SEARCH_REFERENCE_NAME
,
:
'Search tools'
,
:
{
:
'object'
,
:
{
}
}
}
]
,
:
[
]
,
:
{
}
,
}
,
=>
{
.
push
(
)
;
return
[
]
;
}
,
)
;
.
deepStrictEqual
(
{
:
.
,
}
,
{
:
{
:
true
,
:
1
}
,
:
[
true
]
,
}
)
;
.
dispose
(
)
;
}
)
;
}
)
;
/**
* The routing profile is a create-time option: the runtime fixes it for the session's lifetime and
* restores it on cold resume, so re-sending it on resume would collide with the resident one.
*/
suite
(
'CopilotSessionLauncher auto tier'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
/** Launches a session and returns the `capi` options the SDK was called with. */
async
function
capiOptionsFor
(
:
'create'
|
'resume'
,
:
|
undefined
,
:
<
<
,
unknown
>>
)
:
Promise
<
unknown
>
{
let
:
unknown
=
'not-called'
;
const
=
{
:
'session-1'
,
on
:
(
)
=>
(
)
=>
{
}
,
disconnect
:
async
(
)
=>
{
}
,
:
{
:
{
update
:
async
(
)
=>
(
{
:
true
}
)
}
}
,
}
as
unknown
as
;
const
=
{
createSession
:
async
(
:
{
?
:
unknown
}
)
=>
{
=
.
;
return
;
}
,
resumeSession
:
async
(
:
string
,
:
{
?
:
unknown
}
)
=>
{
=
.
;
return
;
}
,
}
as
unknown
as
<
,
'createSession'
|
'resumeSession'
>
;
const
=
createTestLauncher
(
undefined
,
)
;
const
=
{
,
:
'session-1'
,
:
,
:
undefined
,
:
{
:
[
]
,
:
[
]
,
:
{
}
}
,
:
new
ActiveClientToolSet
(
)
,
:
undefined
,
:
undefined
,
}
;
const
:
=
===
'create'
?
{
...
,
:
'create'
,
}
:
{
...
,
:
'resume'
,
:
{
}
}
;
const
=
new
DisposableStore
(
)
;
try
{
.
add
(
await
.
launch
(
,
)
)
;
}
finally
{
.
dispose
(
)
;
await
.
disposeByokProxyHandle
(
)
;
}
return
;
}
test
(
'sends the profile on create only, and only while the gate is on'
,
async
(
)
=>
{
const
:
=
{
:
'auto'
,
:
{
:
'intelligence'
}
}
;
.
deepStrictEqual
(
[
await
capiOptionsFor
(
'create'
,
,
{
[
.
]
:
true
}
)
,
// Gate off: omitted entirely, so a runtime without the contract never sees the field.
await
capiOptionsFor
(
'create'
,
,
{
}
)
,
// No selection, and a profile left on a concrete model, both leave routing alone.
await
capiOptionsFor
(
'create'
,
{
:
'auto'
}
,
{
[
.
]
:
true
}
)
,
await
capiOptionsFor
(
'create'
,
{
:
'gpt-5'
,
:
{
:
'intelligence'
}
}
,
{
[
.
]
:
true
}
)
,
// Resume keeps whatever profile the runtime journaled for the session.