chore: add eslint/prettier gates and fix windows test failures
This commit is contained in:
1 parent
b366e16087
commit
b47302e2ff
42 files changed
+3460
-843
No files matched your search
+61
-37
@@ -13,42 +13,48 @@ import {
|
||||
} 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: "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.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");
|
||||
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\./
|
||||
);
|
||||
assert.match(chatReplyLanguageInstruction("@bot 请 review this PR"), /^Reply in Chinese\./);
|
||||
});
|
||||
|
||||
test("PR chat must finish within its tool budget without asking to continue", () => {
|
||||
@@ -58,13 +64,19 @@ test("PR chat must finish within its tool budget without asking to continue", ()
|
||||
|
||||
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);
|
||||
assert.equal(
|
||||
containsBotMention("Could @github-actions explain this?", "github-actions[bot]"),
|
||||
true
|
||||
);
|
||||
assert.equal(containsBotMention("Ping @github-actions[bot]", "github-actions[bot]"), true);
|
||||
});
|
||||
|
||||
test("PR chat does not trigger on partial usernames or ordinary text", () => {
|
||||
assert.equal(containsBotMention("@botany please check", "github-actions[bot]"), false);
|
||||
assert.equal(containsBotMention("This mentions bot without an at sign", "github-actions[bot]"), false);
|
||||
assert.equal(
|
||||
containsBotMention("This mentions bot without an at sign", "github-actions[bot]"),
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
test("only collaborators with write access can invoke the full repository agent", () => {
|
||||
@@ -100,16 +112,28 @@ test("PR chat snapshot excludes repository instructions, secrets, git data, and
|
||||
fs.writeFile(path.join(source, "opencode.json"), "{}"),
|
||||
fs.writeFile(path.join(source, ".goosehints"), "untrusted hints"),
|
||||
fs.writeFile(path.join(source, "src", "index.ts"), "export const safe = true;\n"),
|
||||
fs.writeFile(path.join(source, "scripts", "check.sh"), "#!/bin/sh\nexit 0\n", { mode: 0o755 }),
|
||||
fs.writeFile(path.join(source, "scripts", "check.sh"), "#!/bin/sh\nexit 0\n", {
|
||||
mode: 0o755
|
||||
}),
|
||||
fs.symlink(path.join(source, ".env"), path.join(source, "secret-link"))
|
||||
]);
|
||||
|
||||
snapshot = await createRepositorySnapshot(source);
|
||||
assert.equal(await fs.readFile(path.join(snapshot, "src", "index.ts"), "utf8"), "export const safe = true;\n");
|
||||
assert.equal((await fs.stat(snapshot)).mode & 0o777, 0o777);
|
||||
assert.equal((await fs.stat(path.join(snapshot, "src"))).mode & 0o777, 0o777);
|
||||
assert.equal((await fs.stat(path.join(snapshot, "src", "index.ts"))).mode & 0o777, 0o666);
|
||||
assert.equal((await fs.stat(path.join(snapshot, "scripts", "check.sh"))).mode & 0o777, 0o777);
|
||||
assert.equal(
|
||||
await fs.readFile(path.join(snapshot, "src", "index.ts"), "utf8"),
|
||||
"export const safe = true;\n"
|
||||
);
|
||||
// Windows collapses chmod to read/write bits; the exact container contract
|
||||
// (dirs 0o777, files 0o666/0o777) is only assertable on POSIX.
|
||||
if (process.platform === "win32") {
|
||||
assert.equal((await fs.stat(snapshot)).mode & 0o222, 0o222);
|
||||
assert.equal((await fs.stat(path.join(snapshot, "src"))).mode & 0o222, 0o222);
|
||||
} else {
|
||||
assert.equal((await fs.stat(snapshot)).mode & 0o777, 0o777);
|
||||
assert.equal((await fs.stat(path.join(snapshot, "src"))).mode & 0o777, 0o777);
|
||||
assert.equal((await fs.stat(path.join(snapshot, "src", "index.ts"))).mode & 0o777, 0o666);
|
||||
assert.equal((await fs.stat(path.join(snapshot, "scripts", "check.sh"))).mode & 0o777, 0o777);
|
||||
}
|
||||
for (const excluded of [
|
||||
".git",
|
||||
".goose",
|
||||
|
||||
Reference in new issue
Block a user