From b1b76cdbf9a768ef9a066ea199b67f613be0d1b2 Mon Sep 17 00:00:00 2001 From: wdawdwa <2864460459@qq.com> Date: Sat, 22 Aug 2026 18:56:32 +0800 Subject: [PATCH] test: cover chat language routing and requester context --- test/chat-language.test.ts | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/chat-language.test.ts diff --git a/test/chat-language.test.ts b/test/chat-language.test.ts new file mode 100644 index 0000000..f46bf2d --- /dev/null +++ b/test/chat-language.test.ts @@ -0,0 +1,56 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { + buildChatRequesterContext, + chatReplyLanguageInstruction, + chatToolBudgetInstruction, + containsBotMention +} from "../src/chat/processor.js"; + +test("chinese comments produce chinese reply instructions", () => { + const instruction = chatReplyLanguageInstruction("请解释这段代码的作用"); + assert.match(instruction, /Reply in Chinese/); +}); + +test("english comments produce english reply instructions", () => { + const instruction = chatReplyLanguageInstruction("What does this PR change?"); + assert.match(instruction, /Reply in English/); +}); + +test("mixed comments follow the presence of han script", () => { + assert.match(chatReplyLanguageInstruction("这个 function 是干嘛的"), /Chinese/); +}); + +test("requester context derives actor categories deterministically", () => { + assert.deepEqual( + buildChatRequesterContext({ + commenterLogin: "alice", + pullRequestAuthorLogin: "alice", + repositoryPermission: "read" + }), + { + login: "alice", + isPullRequestAuthor: true, + repositoryPermission: "read", + actorType: "repository_reader" + } + ); + assert.deepEqual( + buildChatRequesterContext({ + commenterLogin: "bob", + pullRequestAuthorLogin: "alice", + repositoryPermission: "none" + }), + { + login: "bob", + isPullRequestAuthor: false, + repositoryPermission: "none", + actorType: "outside_contributor" + } + ); +}); + +test("tool budget instruction forbids asking the user to continue", () => { + const instruction = chatToolBudgetInstruction(); + assert.match(instruction, /Do not ask the user whether to continue/); +});