Skip to content

Commit e672c20

Browse files
author
Bertan Ari
committed
test(vscode-lm): cover non-marker u+hex tool names in decode round-trip
1 parent 7e1a03e commit e672c20

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎src/api/providers/__tests__/vscode-lm.spec.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,42 @@ describe("VsCodeLmHandler", () => {
397397
expect(chunks.find((chunk) => chunk.type === "tool_call")).toMatchObject({ name: "get_user" })
398398
})
399399

400+
it("preserves a tool name containing a non-marker u+hex sequence end to end", async () => {
401+
mockLanguageModelChat.sendRequest.mockImplementationOnce(async (_messages, options) => {
402+
const declaredName = options.tools[0].name
403+
return {
404+
stream: (async function* () {
405+
yield new vscode.LanguageModelToolCallPart("call-1", declaredName, {})
406+
return
407+
})(),
408+
text: (async function* () {
409+
yield ""
410+
return
411+
})(),
412+
}
413+
})
414+
415+
const chunks = []
416+
for await (const chunk of handler.createMessage(
417+
"You are a helpful assistant",
418+
[{ role: "user", content: "hi" }],
419+
{
420+
taskId: "test-task",
421+
tools: [
422+
{
423+
type: "function" as const,
424+
function: { name: "queue1234", description: "d", parameters: { type: "object" } },
425+
},
426+
],
427+
},
428+
)) {
429+
chunks.push(chunk)
430+
}
431+
432+
expect(mockLanguageModelChat.sendRequest.mock.calls[0][1].tools[0].name).toBe("queue1234")
433+
expect(chunks.find((chunk) => chunk.type === "tool_call")).toMatchObject({ name: "queue1234" })
434+
})
435+
400436
describe("system prompt sanitization", () => {
401437
it("sanitizes lone surrogates in the system prompt", async () => {
402438
mockLanguageModelChat.sendRequest.mockResolvedValueOnce({

‎src/api/transform/__tests__/vscode-lm-format.spec.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,13 @@ describe("convertToVsCodeLmMessages surrogate-safe identifiers", () => {
855855
}
856856
})
857857

858+
it("does not decode a non-marker u+hex sequence", () => {
859+
// "queue1234" has "u" followed by hex but no preceding "_", so it must survive untouched.
860+
const name = "queue1234"
861+
expect(sanitizeToolNameSurrogates(name)).toBe(name)
862+
expect(codeUnits(decodeToolNameSurrogates(name))).toEqual(codeUnits(name))
863+
})
864+
858865
it("replays a tool call in history under the same name it was declared with", () => {
859866
const originalName = `read${LONE_HIGH}file`
860867
const messages: Anthropic.Messages.MessageParam[] = [

0 commit comments

Comments
 (0)