feat: localize PR chat replies

This commit is contained in:
lezi-fun committed 2026-08-14 10:18:36 +08:00
1 parent 3647944ad7
commit 087b19e705
4 files changed
+88

No files matched your search

+41
View File
@@ -4,11 +4,52 @@ import os from "node:os";
import path from "node:path";
import test from "node:test";
import {
buildChatRequesterContext,
chatReplyLanguageInstruction,
containsBotMention,
createRepositorySnapshot,
isTrustedChatPermission
} from "../src/chat/processor.js";
test("PR chat receives host-verified requester role context", () => {
assert.deepEqual(buildChatRequesterContext({
commenterLogin: "maintainer",
pullRequestAuthorLogin: "contributor",
repositoryPermission: "admin"
}), {
login: "maintainer",
isPullRequestAuthor: false,
repositoryPermission: "admin",
actorType: "repository_admin"
});
assert.deepEqual(buildChatRequesterContext({
commenterLogin: "Contributor",
pullRequestAuthorLogin: "contributor",
repositoryPermission: "none"
}), {
login: "Contributor",
isPullRequestAuthor: true,
repositoryPermission: "none",
actorType: "outside_pull_request_author"
});
assert.equal(buildChatRequesterContext({
commenterLogin: "visitor",
pullRequestAuthorLogin: "contributor",
repositoryPermission: "none"
}).actorType, "outside_contributor");
});
test("PR chat replies in the language of the latest user comment", () => {
assert.match(chatReplyLanguageInstruction("@bot Introduce it"), /^Reply in English\./);
assert.match(chatReplyLanguageInstruction("@bot 请介绍一下这个 PR"), /^Reply in Chinese\./);
assert.match(
chatReplyLanguageInstruction("@bot 请 review this PR"),
/^Reply in Chinese\./
);
});
test("PR chat recognizes @bot and the configured bot login", () => {
assert.equal(containsBotMention("@bot can this merge?", "github-actions[bot]"), true);
assert.equal(containsBotMention("Could @github-actions explain this?", "github-actions[bot]"), true);