diff --git a/site/contributors-exclude.txt b/site/contributors-exclude.txt new file mode 100644 index 000000000..8bff9962f --- /dev/null +++ b/site/contributors-exclude.txt @@ -0,0 +1,7 @@ +# People who asked not to be named in magpie's release notes or on the +# contributors page (usemagpie.ai/docs/contributors). One name or GitHub +# login a line, as it is credited; case doesn't matter. Lines after # are +# comments. +# +# To be left off: say so on Discord, open an issue, or send a pull request +# adding your name here. diff --git a/site/credits-cli.mjs b/site/credits-cli.mjs new file mode 100644 index 000000000..3d942daf9 --- /dev/null +++ b/site/credits-cli.mjs @@ -0,0 +1,108 @@ +#!/usr/bin/env node +// The people magpie's history credits (credits.mjs), from git and GitHub. +// +// node site/credits-cli.mjs thanks .. +// the thanks line for a release's notes: English on the first line, +// Chinese on the second, nothing when no one is credited. yetone/ +// magpie-releases' release run calls it for the commits since the last +// tag. +// +// The issue and PR authors a subject's "(#N)" names are asked of GitHub's +// GraphQL API with GH_TOKEN, GITHUB_TOKEN or `gh auth token`. When that +// can't be read, those people are left out; the rest still goes out. Names in +// contributors-exclude.txt are never given. +import { execFileSync } from "node:child_process"; +import { readFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; +import { credit, everyone, thanks, refKey, parse } from "./credits.mjs"; + +const here = dirname(fileURLToPath(import.meta.url)); +const warn = (m) => process.stderr.write(`credits: ${m}\n`); + +const SEP = "\x1f", END = "\x1e"; +function log(args) { + const out = execFileSync("git", ["log", `--format=%H${SEP}%P${SEP}%an${SEP}%ae${SEP}%s${SEP}%(trailers:key=Co-authored-by,valueonly,separator=%x1d)${SEP}%D${END}`, ...args], { encoding: "utf8", maxBuffer: 1 << 30 }); + return out.split(END).map((r) => r.replace(/^\n/, "")).filter(Boolean).map((r) => { + const [sha, parents, author, email, subject, co, refs] = r.split(SEP); + return { + sha, author, email, subject, + parents: parents.trim() ? parents.trim().split(" ").length : 0, + // the address only tells an agent from a person; it is never written out + coauthors: (co || "").split("\x1d").map((s) => s.trim()).filter(Boolean).map((s) => { + const m = s.match(/^(.*?)\s*<([^>]*)>$/); + return m ? { name: m[1].trim(), email: m[2].trim() } : { name: s, email: "" }; + }), + tags: (refs || "").split(", ").map((s) => s.replace(/^tag: /, "")).filter((t) => /^v\d+\.\d+\.\d+$/.test(t)), + }; + }); +} + +export function excluded(file = join(here, "contributors-exclude.txt")) { + try { + return readFileSync(file, "utf8").split("\n").map((l) => l.replace(/#.*/, "").trim()).filter(Boolean); + } catch { return []; } +} + +function token() { + if (process.env.GH_TOKEN) return process.env.GH_TOKEN; + if (process.env.GITHUB_TOKEN) return process.env.GITHUB_TOKEN; + try { return execFileSync("gh", ["auth", "token"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim(); } catch { return ""; } +} + +// "repo#n" → login (a bot's with "[bot]"), "" for no author; refs it +// couldn't read are left out of the map +export async function authors(refs, { known = {}, fetchImpl = globalThis.fetch, tok = token() } = {}) { + const got = { ...known }; + const want = new Map(); + for (const r of refs) if (!(refKey(r) in got)) want.set(refKey(r), r); + if (!want.size) return got; + if (!tok) { warn(`no GitHub token: ${want.size} issue authors left out`); return got; } + const byRepo = new Map(); + for (const r of want.values()) (byRepo.get(r.repo) || byRepo.set(r.repo, []).get(r.repo)).push(r.n); + for (const [repo, ns] of byRepo) { + const [owner, name] = repo.split("/"); + for (let i = 0; i < ns.length; i += 100) { + const chunk = ns.slice(i, i + 100); + const who = "author { login __typename }"; + const q = `query { repository(owner: ${JSON.stringify(owner)}, name: ${JSON.stringify(name)}) { ${chunk.map((n) => `i${n}: issueOrPullRequest(number: ${n}) { ... on Issue { ${who} } ... on PullRequest { ${who} } }`).join(" ")} } }`; + try { + const res = await fetchImpl("https://api.github.com/graphql", { + method: "POST", + headers: { Authorization: `bearer ${tok}`, "Content-Type": "application/json", "User-Agent": "magpie-credits" }, + body: JSON.stringify({ query: q }), + signal: AbortSignal.timeout(30000), + }); + if (!res.ok) throw new Error(`HTTP ${res.status}`); + const body = await res.json(); + const repoData = body && body.data && body.data.repository; + if (!repoData) throw new Error(JSON.stringify(body.errors || body).slice(0, 300)); + for (const n of chunk) { + const item = repoData[`i${n}`]; + if (item === undefined) continue; // not answered: unknown, asked again next time + const a = item && item.author; + got[`${repo}#${n}`] = a ? (a.__typename === "Bot" ? `${a.login}[bot]` : a.login) : ""; + } + } catch (e) { + warn(`${repo}: issue authors not read (${e.message}); those people are left out`); + } + } + } + return got; +} + +async function cmdThanks(range) { + if (!range) throw new Error("usage: credits-cli.mjs thanks .."); + const commits = log(["--no-merges", range]); + const refs = commits.flatMap((c) => parse(c.subject).refs); + const issueAuthors = await authors(refs); + const people = everyone(credit(commits, { issueAuthors, exclude: excluded() })); + const en = thanks(people, "en"); + if (en) process.stdout.write(en + "\n" + thanks(people, "zh") + "\n"); +} + +if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) { + const [cmd, arg] = process.argv.slice(2); + const run = cmd === "thanks" ? cmdThanks(arg) : Promise.reject(new Error("usage: credits-cli.mjs thanks ..")); + run.catch((e) => { warn(e.message); process.exit(1); }); +} diff --git a/site/credits.mjs b/site/credits.mjs new file mode 100644 index 000000000..be177856d --- /dev/null +++ b/site/credits.mjs @@ -0,0 +1,213 @@ +// Who magpie's releases came from: the people a commit credits, read from +// what is already public in yetone/magpie's history. Nothing here is made up +// and no email is ever given out: +// +// - a subject's parenthesised credit: "(hoobnn on Discord)", +// "(qikamatata on X: …)", "(#2356, detail47)", "(willz, Discord)", +// "(TJHHHH, luci on Discord)", a lone "(mrwl666)"; +// - the author of an issue or PR such a group names, "(#4532)" (looked up +// by credits-cli.mjs; a lookup that fails names nobody); +// - a commit's GitHub author and Co-authored-by names other than the +// maintainer's and bots'. +// +// A lone word in brackets is often code ("(nogui)", "(P3)", "(Codex)"), so it +// counts only when it is shaped like a handle with digits ("mrwl666") or the +// same name is credited plainly somewhere else ("axelburks on Discord"). +// +// Used by credits-cli.mjs for the release notes' thanks line. It imports +// nothing, so the site's worker can use it too. + +export const MAINTAINERS = ["yetone"]; +// agents and bots that author or co-author commits +const BOT = /\[bot\]$|^(claude( code| opus.*| sonnet.*| haiku.*)?|amp|codex|copilot|github copilot|cursor( agent)?|devin( ai)?|gemini|opencode|droid|factory-droid|dependabot|github-actions|renovate|jev)$/i; +// agents and machine accounts that co-author commits: "Instinct Agent +// ", "glm-5.3-flash", "magpie-fix " +const AGENT_MAIL = /@(anthropic\.com|cursor\.com|openai\.com|instinct\.com|multica\.ai|factory\.ai|ampcode\.com|google\.com|localhost)$|^(noreply|agent|bot)@/i; +const MODEL = /^(claude|gpt|glm|qwen|kimi|deepseek|gemini|grok|minimax|doubao|o\d)\b.*\d|\bagent$|^(admin|root|user|ubuntu|runner|test)$/i; +const PLATFORMS = { discord: "Discord", x: "X", twitter: "X", github: "GitHub", v2ex: "V2EX", wechat: "WeChat", 微信: "WeChat", telegram: "Telegram", reddit: "Reddit", "linux.do": "LINUX DO", 即刻: "Jike", 小红书: "Xiaohongshu" }; +// words that sit in brackets beside an issue number and aren't people +const STOP = new Set(("discord x github zh en ja de zh-tw zh-cn high low medium ultra xhigh max min mini pro plus free " + + "model models folder download review fixes fixed see also and or not windows linux macos mac wsl ios android ci " + + "main red green beta alpha stable new old test tests api cli gui tui web site docs owner user users the pi spelled " + + "plugin plugins provider providers agent agents gateway routing usage settings panel tray").split(" ")); +const LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){2,38}$/; +// a Discord-style handle ending in its number: tjhhhh_84378 +const NUMBERED = /^_?[A-Za-z][A-Za-z0-9]*(?:_[A-Za-z0-9]+)*_\d{3,}$/; +// a lone bracketed word taken without anything else naming it: mrwl666 +const DIGITED = /^[A-Za-z]{3,}\d{2,}$/; + +const lower = (s) => s.toLowerCase(); + +// a word next to an issue number or another credit that may be a person +function handle(w) { + if (STOP.has(lower(w))) return false; + if (/^\d+$/.test(w) || /^[0-9a-f]{7,40}$/.test(w) || /^v?\d+(\.\d+)+/.test(w)) return false; + return LOGIN.test(w) || NUMBERED.test(w); +} + +// someone named in front of a platform, "Benjie Zhou on Discord" +function personName(s) { + s = s.trim().replace(/^@/, ""); + if (!s || s.length > 40 || /[#()\[\]{}<>"“”]/.test(s) || s.split(/\s+/).length > 3) return ""; + if (/^(the|a|an)\s/i.test(s) || STOP.has(lower(s))) return ""; + // who someone is, not their name: "Docker user", "𝕏 user", "𝕏" + if (/(^|\s)(user|users|someone|reporter|people)$/i.test(s) || !/[\p{L}\p{N}]/u.test(s.replace(/𝕏/gu, ""))) return ""; + return s; +} + +// The credits in one subject: names (sure, or to be taken only if seen +// elsewhere) and the issues or PRs its brackets name. +export function parse(subject) { + // older subjects carry their whole body after " — "; credits come before + const head = String(subject).split(" — ")[0]; + const out = { names: [], refs: [] }; + for (const m of head.matchAll(/\(([^()]*)\)/g)) group(m[1], out); + return out; +} + +function group(text, out) { + const bare = []; + let parts = 0; + for (let piece of text.split(/;\s*/)) { + // a quote after the name: "NAME on X: 打开页面很卡", "#538: …" + const colon = piece.search(/:(\s|["“「]|$)/); + if (colon >= 0) piece = piece.slice(0, colon); + // a piece names someone only when its own words do: "(#615: …; Neon, + // Notion and Supabase stay)" doesn't + let context = false; + const mine = []; + for (let p of piece.split(/,\s*/)) { + p = p.trim(); + if (!p) continue; + parts++; + // "spotted by @hezhizhen in #103" + const by = p.match(/(?:^|\s)by @([A-Za-z0-9-]{1,39})\b/); + if (by) { out.names.push({ name: by[1], via: "GitHub", sure: true }); context = true; } + // "#12", "plugins#12", "plugins #12", "magpie-community/plugins#12" + p = p.replace(/(?:\b(plugins)\s+|([\w.-]+\/)?([\w.-]+))?#(\d+)\b/g, (_, spaced, owner, repo, n) => { + const r = spaced || (!repo ? "yetone/magpie" : `${owner || ""}${repo}`); + const known = { "yetone/magpie": "yetone/magpie", magpie: "yetone/magpie", plugins: "magpie-community/plugins", "magpie-community/plugins": "magpie-community/plugins" }[r]; + if (known) out.refs.push({ repo: known, n: +n }); + context = true; + return " "; + }).trim(); + if (!p || by) continue; + const plat = PLATFORMS[lower(p)]; + if (plat) { // "willz, Discord" + if (mine.length) { out.names.push({ name: mine.pop(), via: plat, sure: true }); context = true; } + continue; + } + const on = p.match(/^(.+?)\s+on\s+(\S+)$/); + if (on && PLATFORMS[lower(on[2])]) { + for (const n of on[1].split(/\s+(?:and|&)\s+/)) { + const name = personName(n); + if (name) out.names.push({ name, via: PLATFORMS[lower(on[2])], sure: true }); + } + context = true; + continue; + } + if (/^@?\S+$/.test(p)) mine.push(p.replace(/^@/, "")); + } + for (const b of mine) bare.push({ b, context }); + } + // a lone word, or one beside a credit or a number ("July, LCorleone", + // "memory, Osal on Discord", "#860 flake", "#2606 fatcutegg"), is a person + // only if named plainly elsewhere or shaped like a handle with digits: + // credit() decides + for (const { b, context } of bare) { + if (context ? handle(b) : parts === 1 && (LOGIN.test(b) || NUMBERED.test(b))) out.names.push({ name: b, via: null, sure: false }); + } +} + +// the GitHub login in a noreply address; the address itself is never kept +function noreply(email) { + const m = String(email || "").match(/^(?:\d+\+)?([A-Za-z0-9-]+)@users\.noreply\.github\.com$/i); + return m ? m[1] : ""; +} + +export function refKey(r) { return `${r.repo}#${r.n}`; } + +// excluded: maintainer, bots, the people who asked to be left off +function left(name, exclude) { + const k = lower(name); + return !k || MAINTAINERS.includes(k) || BOT.test(name) || exclude.has(k) || /^(the |a )?(owner|user|users|maintainer)$/.test(k); +} + +// a co-author or commit author who is a person, not an agent or machine +function human(name, email) { + if (!name || BOT.test(name) || MODEL.test(name) || !/^[\p{L}\p{N}]/u.test(name)) return false; + return !email || !AGENT_MAIL.test(email) || /@users\.noreply\.github\.com$/i.test(email); +} +const coName = (c) => (typeof c === "string" ? { name: c, email: "" } : c); + +// Each commit's people. commits: [{ subject, author, email, parents, +// coauthors: [{ name, email }] }] +// issueAuthors: Map or object of "repo#n" → login (a bot's ends in "[bot]"). +// Returns an array beside commits, each [{ key, name, via, github }]. +export function credit(commits, { issueAuthors = {}, exclude = [] } = {}) { + const authorOf = issueAuthors instanceof Map ? (k) => issueAuthors.get(k) : (k) => issueAuthors[k]; + const ex = new Set([...exclude].map((s) => lower(String(s).trim())).filter(Boolean)); + const parsed = commits.map((c) => parse(c.subject)); + // names credited plainly anywhere, so a lone bracketed one can be trusted + const known = new Set(); + commits.forEach((c, i) => { + for (const n of parsed[i].names) if (n.sure) known.add(lower(n.name)); + for (const r of parsed[i].refs) { const a = authorOf(refKey(r)); if (a) known.add(lower(a)); } + if (human(c.author, c.email)) known.add(lower(c.author)); + const gh = noreply(c.email); + if (gh) known.add(lower(gh)); + for (const co of (c.coauthors || []).map(coName)) if (human(co.name, co.email)) known.add(lower(co.name)); + }); + return commits.map((c, i) => { + const people = new Map(); + const add = (name, via, github) => { + name = String(name || "").trim(); + if (left(name, ex) || (github && left(github, ex))) return; + const key = lower(github || name); + const had = people.get(key); + if (had) { if (via && !had.via.includes(via)) had.via.push(via); if (github) had.github = github; return; } + people.set(key, { key, name, via: via ? [via] : [], github: github || "" }); + }; + for (const n of parsed[i].names) { + if (n.sure || known.has(lower(n.name)) || (DIGITED.test(n.name) && !/^[0-9a-f]+$/i.test(n.name)) || NUMBERED.test(n.name)) add(n.name, n.via, ""); + } + for (const r of parsed[i].refs) { + const a = authorOf(refKey(r)); + if (a && !BOT.test(a)) add(a, "GitHub", a); + } + if (c.parents == null || c.parents < 2) { + if (human(c.author, c.email)) add(c.author, "GitHub", noreply(c.email)); + for (const co of (c.coauthors || []).map(coName)) if (human(co.name, co.email)) add(co.name, "GitHub", noreply(co.email)); + } + return [...people.values()]; + }); +} + +// every person across commits, merged by key +export function everyone(perCommit) { + const all = new Map(); + for (const list of perCommit) for (const p of list) { + const had = all.get(p.key); + if (!had) { all.set(p.key, { ...p, via: [...p.via] }); continue; } + for (const v of p.via) if (!had.via.includes(v)) had.via.push(v); + if (p.github && !had.github) had.github = p.github; + } + return [...all.values()]; +} + +// markdown that shows a name as written: tjhhhh_84378, not tjhhhh84378 in italics +const md = (s) => s.replace(/([\\`*_{}\[\]<>()#+!|~])/g, "\\$1"); + +export const WALL = { en: "https://usemagpie.ai/docs/contributors", zh: "https://usemagpie.ai/docs/zh/contributors" }; + +// the release notes' last line, or "" when nobody is credited +export function thanks(people, lang) { + const names = people.map((p) => md(p.name)); + if (!names.length) return ""; + if (lang === "zh") { + const list = names.length > 1 ? names.slice(0, -1).join("、") + " 和 " + names.at(-1) : names[0]; + return `感谢 ${list}:这次更新里有${names.length > 1 ? "你们" : "你"}的反馈与代码。所有贡献者见[贡献墙](${WALL.zh})。`; + } + const list = names.length > 1 ? names.slice(0, -1).join(", ") + " and " + names.at(-1) : names[0]; + return `Thanks to ${list}, whose reports and code went into this release. Everyone who helped: [contributors](${WALL.en}).`; +} diff --git a/site/credits.test.mjs b/site/credits.test.mjs new file mode 100644 index 000000000..b040bac17 --- /dev/null +++ b/site/credits.test.mjs @@ -0,0 +1,128 @@ +// The credits read from commit subjects (credits.mjs). Every subject here is +// one from yetone/magpie's own history, word for word. +import test from "node:test"; +import assert from "node:assert/strict"; +import { parse, credit, everyone, thanks } from "./credits.mjs"; +import { authors, excluded } from "./credits-cli.mjs"; +import { mkdtempSync, writeFileSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; + +const names = (subject, opts) => credit([{ subject, author: "yetone", email: "yetoneful@gmail.com" }], opts)[0].map((p) => p.name); +const via = (subject) => credit([{ subject, author: "yetone", email: "yetoneful@gmail.com" }])[0].map((p) => `${p.name}/${p.via.join("+")}`); + +test("a reporter named on Discord or X is credited, with where", () => { + assert.deepEqual(via("library: an MCP router says which computer it is, so an agent can pick between two (packinggoodsllc_07668 on Discord)"), ["packinggoodsllc_07668/Discord"]); + assert.deepEqual(via("gateway: a HEIC photo goes to the vendor as JPEG, or PNG with alpha (qikamatata on X)"), ["qikamatata/X"]); + assert.deepEqual(via("redact: a decimal's digits are not masked as a number of their own (willz, Discord)"), ["willz/Discord"]); +}); + +test("several people in one bracket are each credited", () => { + assert.deepEqual(names("masking: a record names the provider the request went to, not the group's first member (Max You and Linka on Discord)"), ["Max You", "Linka"]); + // the first is bare, so it needs naming elsewhere: here a commit that + // credits TJHHHH on Discord + const commits = [ + { subject: "codex: the restart advice after a model or catalog change names the app-server codex sessions share (\"codex app-server daemon restart\"), on Windows and WSL too (TJHHHH, luci on Discord)" }, + { subject: "codex: a model picked in the Codex app is the one it runs (TJHHHH on Discord)" }, + ]; + assert.deepEqual(credit(commits)[0].map((p) => p.name).sort(), ["TJHHHH", "luci"]); + assert.deepEqual(credit(commits.slice(0, 1))[0].map((p) => p.name), ["luci"]); +}); + +test("a lone bracketed handle is credited when shaped like one or named elsewhere", () => { + assert.deepEqual(names("guard: the local masking model reads text a third faster on amd64 (mrwl666)"), ["mrwl666"]); + const lone = { subject: "gui: Busy models last takes a custom threshold, 1 to 9999 (axelburks)" }; + assert.deepEqual(credit([lone])[0], []); + const both = credit([lone, { subject: "search: searchers picked to follow the one named, tried in their order when it fails (axelburks on Discord)" }]); + assert.deepEqual(both[0].map((p) => p.name), ["axelburks"]); +}); + +test("a quote after the name is not part of it", () => { + assert.deepEqual(names("zen: Test with the public key asks each API for a free model Zen serves on it, and leaves out an API no free model is on (z'x on Discord; #2385)"), ["z'x"]); + assert.deepEqual(parse("zen: Test with the public key asks each API for a free model Zen serves on it, and leaves out an API no free model is on (z'x on Discord; #2385)").refs, [{ repo: "yetone/magpie", n: 2385 }]); +}); + +test("the maintainer, the owner and descriptions of someone are nobody", () => { + assert.deepEqual(names("plugins: the GitHub list waits up to 3s for a repository's https icon fetched the first time (yetone: 非官方插件显示不出来 logo)"), []); + assert.deepEqual(names("tray: with the menu bar's magpie icon off, a click opens the panel on the tab left last, not Allowances (the owner: 每次都会自动跳转到 allowances,我记得之前是可以的)"), []); + assert.deepEqual(names("gui: a Claude account saved in magpie can be removed while Claude Code is signed out (𝕏 user on Discord: a banned account logged out, and its line in Providers had nothing to remove it with) — saved accounts are listed"), []); +}); + +test("code, labels and words beside an issue number are not people", () => { + for (const s of [ + "plugin: gateway key limits are the Key limits plugin on the gateway's budget point (P3)", + "routing: picking Live or a day keeps the page where it is, and a list with no requests says what it is for (Image #59) — a day or Live picked", + "gui tests: the Routing page's tests pick a day from the date bar, not the By request button (#860 flake) — remote-group-served's zh case", + "mcpauth: a sign-in asks for offline_access when the authorization server offers it, so Vercel's MCP stays signed in (#615: \"vercel老是掉\"; Neon, Notion and Supabase stay) — mcp.vercel.com's", + "codex: a client's access_programs and the account's extraBody reach the ChatGPT backend, and its refusal comes back as it said it (magpie-releases#18)", + "efd1b697e sessions: a cached file's calls are read into a slice made for them", + ]) assert.deepEqual(names(s), [], s); + // a word beside a credit is a person only when named somewhere else + assert.deepEqual(names("agent: Claude Desktop on magpie keeps the language picked signed in with Anthropic (memory, Osal on Discord)"), ["Osal"]); +}); + +test("issue and PR numbers are kept for their authors, in either repository", () => { + assert.deepEqual(parse("redact: a file named like an address (…@2x.jpg) is not masked as an email (#3029)").refs, [{ repo: "yetone/magpie", n: 3029 }]); + assert.deepEqual(parse("redact: Codex's tool server names, stream_options and snake_case words go as written (#3143, #3144)").refs.map((r) => r.n), [3143, 3144]); + assert.deepEqual(parse("provider: Devin's plugin min is 0.1.30, its opt-in cache keepalive (plugins#592)").refs, [{ repo: "magpie-community/plugins", n: 592 }]); + assert.deepEqual(parse("provider: WorkBuddy's mover asks for opencode-workbuddy-auth 0.2.9, whose declared models take images (plugins #572)").refs, [{ repo: "magpie-community/plugins", n: 572 }]); + const s = "redact: Codex's tool server names, stream_options and snake_case words go as written (#3143, #3144)"; + const issueAuthors = { "yetone/magpie#3143": "hhh2210", "yetone/magpie#3144": "dependabot[bot]" }; + const got = credit([{ subject: s, author: "yetone" }], { issueAuthors })[0]; + assert.deepEqual(got.map((p) => [p.name, p.github]), [["hhh2210", "hhh2210"]]); + // a name and an issue in one bracket: both + assert.deepEqual(names("provider: a Max output kept for a model no longer listed doesn't block the editor's Save (#3305, LoKi)", { issueAuthors: { "yetone/magpie#3305": "LoKi" } }), ["LoKi"]); + assert.deepEqual(names("sessions: Terminal is opened through proc.Command, as every command magpie runs is (spotted by @hezhizhen in #103)"), ["hezhizhen"]); +}); + +test("commit authors and co-authors are credited, agents and machines not, and no email is given", () => { + const per = credit([ + { subject: "gui: a group's Save no longer leaves the Routing page blank (#884)", author: "wizzy-yang", email: "244719629+wizzy-yang@users.noreply.github.com", coauthors: [{ name: "magpie-fix", email: "fix@localhost" }] }, + { subject: "gateway: count usage from multiline and final SSE events (#94)", author: "Charan Rathore", email: "charan-rathore@users.noreply.github.com", coauthors: [{ name: "Instinct Agent", email: "agent@instinct.com" }, { name: "Claude Opus 5.5", email: "noreply@anthropic.com" }] }, + { subject: "docker: a server image and a multi-arch build workflow (#245)", author: "Shelken", email: "shelken@example.com", coauthors: [{ name: "glm-5.3-flash", email: "hakase@ooooo.space" }, { name: "yetone", email: "yetoneful@gmail.com" }] }, + { subject: "Merge pull request #1 from someone/branch", author: "ggbdpq", email: "x@y", parents: 2 }, + ]); + assert.deepEqual(per.map((l) => l.map((p) => p.name)), [["wizzy-yang"], ["Charan Rathore"], ["Shelken"], []]); + assert.equal(per[0][0].github, "wizzy-yang"); + assert.equal(per[2][0].github, ""); + assert.doesNotMatch(JSON.stringify(per), /@/); +}); + +test("the exclusion list leaves a person out everywhere", () => { + const s = "library: an MCP router says which computer it is, so an agent can pick between two (packinggoodsllc_07668 on Discord)"; + assert.deepEqual(names(s, { exclude: ["PackingGoodsLLC_07668"] }), []); + assert.deepEqual(excluded(), []); // the checked-in list has comments only + const dir = mkdtempSync(join(tmpdir(), "credits-")); + try { + writeFileSync(join(dir, "x.txt"), "# comment\nPackingGoodsLLC_07668 # asked on Discord\n\n"); + assert.deepEqual(names(s, { exclude: excluded(join(dir, "x.txt")) }), []); + } finally { rmSync(dir, { recursive: true, force: true }); } +}); + +test("the release notes' thanks line, in English and Chinese", () => { + const people = everyone(credit([ + { subject: "library: an MCP router says which computer it is, so an agent can pick between two (packinggoodsllc_07668 on Discord)" }, + { subject: "gateway: a HEIC photo goes to the vendor as JPEG, or PNG with alpha (qikamatata on X)" }, + { subject: "guard: the local masking model reads text a third faster on amd64 (mrwl666)" }, + { subject: "gateway: a HEIC photo is sent once (qikamatata on X)" }, + ])); + assert.equal(thanks(people, "en"), "Thanks to packinggoodsllc\\_07668, qikamatata and mrwl666, whose reports and code went into this release. Everyone who helped: [contributors](https://usemagpie.ai/docs/contributors)."); + assert.equal(thanks(people, "zh"), "感谢 packinggoodsllc\\_07668、qikamatata 和 mrwl666:这次更新里有你们的反馈与代码。所有贡献者见[贡献墙](https://usemagpie.ai/docs/zh/contributors)。"); + assert.equal(thanks(people.slice(0, 1), "en").startsWith("Thanks to packinggoodsllc\\_07668, whose"), true); + assert.match(thanks(people.slice(0, 1), "zh"), /里有你的/); + assert.equal(thanks([], "en"), ""); +}); + +test("issue authors GitHub can't give are left out, not guessed", async () => { + const refs = [{ repo: "yetone/magpie", n: 1 }, { repo: "yetone/magpie", n: 2 }]; + const ok = async () => ({ ok: true, json: async () => ({ data: { repository: { i1: { author: { login: "alice", __typename: "User" } }, i2: { author: { login: "dependabot", __typename: "Bot" } } } } }) }); + assert.deepEqual(await authors(refs, { fetchImpl: ok, tok: "t" }), { "yetone/magpie#1": "alice", "yetone/magpie#2": "dependabot[bot]" }); + const down = async () => ({ ok: false, status: 502 }); + const err = process.stderr.write; + process.stderr.write = () => true; + try { + assert.deepEqual(await authors(refs, { fetchImpl: down, tok: "t" }), {}); + assert.deepEqual(await authors(refs, { fetchImpl: down, tok: "t", known: { "yetone/magpie#1": "alice" } }), { "yetone/magpie#1": "alice" }); + assert.deepEqual(await authors(refs, { fetchImpl: ok, tok: "" }), {}); + } finally { process.stderr.write = err; } +});