Skip to content
110 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import type { Commit, EmailOwner } from "@g1t/contracts";
5
6import { addressesToMatch, coAuthorsOf, contributorPerson, personFor, profileHref, showCommit, shownName } from "./commit-people.ts";
7
8const syntaqx: EmailOwner = { id: "usr_01hx", username: "syntaqx", avatar: "f00d" };
9
10/**
11 * What `email_owners` answers (services/identity/src/emails.rs): confirmed
12 * addresses and noreply addresses only, so an unconfirmed address, or a
13 * noreply address whose id does not match, is simply missing.
14 */
15const owners: Record<string, EmailOwner> = {
16 "syntaqx@gmail.com": syntaqx,
17 "01hx0000+syntaqx@users.noreply.g1t.sh": syntaqx,
18 "1234abcd+gone@users.noreply.g1t.sh": { id: "usr_ghost", username: "ghost", avatar: null },
19};
20
21function commit(name: string, email: string, message = "Change something"): Commit {
22 return { hash: "a".repeat(40), treeHash: "b".repeat(40), message, author: { name, email }, parents: [], authoredAt: "2026-10-08T12:00:00Z" };
23}
24
25test("a confirmed address is the account, whatever name the commit carries", () => {
26 const person = personFor("Chase Pierce", "Syntaqx@Gmail.com ", owners);
27 assert.deepEqual(person, { kind: "user", name: "Chase Pierce", username: "syntaqx", avatar: "f00d" });
28 assert.equal(shownName(person), "syntaqx");
29 assert.equal(profileHref(person), "/u/syntaqx");
30});
31
32test("an unconfirmed address matches nobody: the name on the commit, no link", () => {
33 // email_owners leaves unconfirmed addresses out of its answer.
34 const person = personFor("Chase Pierce", "unconfirmed@example.com", owners);
35 assert.deepEqual(person, { kind: "author", name: "Chase Pierce", username: null, avatar: null });
36 assert.equal(shownName(person), "Chase Pierce");
37 assert.equal(profileHref(person), null);
38});
39
40test("the noreply address is the account", () => {
41 assert.equal(personFor("syntaqx", "01hx0000+syntaqx@users.noreply.g1t.sh", owners).username, "syntaqx");
42});
43
44test("a deleted account's commits are ghost's, with no profile", () => {
45 const person = personFor("Gone", "1234abcd+gone@users.noreply.g1t.sh", owners);
46 assert.equal(person.kind, "ghost");
47 assert.equal(shownName(person), "ghost");
48 assert.equal(profileHref(person), null);
49});
50
51test("g1t's commits, now and as its agents and queue made them before, are g1t", () => {
52 for (const [name, email] of [
53 ["g1t", "g1t@users.noreply.g1t.sh"],
54 ["g1t agent", "agent@g1t.sh"],
55 ["g1t merge queue", "queue@g1t.sh"],
56 ["g1t", "mergecheck@g1t.sh"],
57 ]) {
58 const person = personFor(name, email, {});
59 assert.equal(person.kind, "g1t", email);
60 assert.equal(shownName(person), "g1t");
61 assert.equal(profileHref(person), null);
62 }
63 // Only g1t's own addresses: a name alone is not enough.
64 assert.equal(personFor("g1t agent", "someone@example.com", {}).kind, "author");
65});
66
67test("a commit sent to the page carries no address at all", () => {
68 const shown = showCommit(
69 commit("Chase Pierce", "syntaqx@gmail.com", "Fix it\n\nCo-authored-by: Ada <ada@private.example>\nCo-authored-by: Sam <syntaqx@gmail.com>"),
70 owners,
71 );
72 const sent = JSON.stringify(shown.author) + JSON.stringify(shown.coAuthors);
73 assert.ok(!sent.includes("@"), sent);
74 assert.equal("email" in shown.author, false);
75 assert.deepEqual(
76 shown.coAuthors.map((person) => [person.kind, shownName(person)]),
77 [
78 ["author", "Ada"],
79 ["user", "syntaqx"],
80 ],
81 );
82});
83
84test("one question per page: every distinct address, g1t's left out", () => {
85 const asked = addressesToMatch([
86 commit("A", "Ada@Example.com"),
87 commit("A", "ada@example.com", "x\n\nCo-Authored-By: Grace <grace@example.com>"),
88 commit("g1t", "g1t@users.noreply.g1t.sh"),
89 commit("g1t agent", "agent@g1t.sh"),
90 commit("Nobody", ""),
91 ]);
92 assert.deepEqual(asked.sort(), ["ada@example.com", "grace@example.com"]);
93});
94
95test("co-authors are read from the trailers only", () => {
96 assert.deepEqual(coAuthorsOf("Subject\n\nCo-authored-by: Ada <ada@x.io>\n"), [{ name: "Ada", email: "ada@x.io" }]);
97 assert.deepEqual(coAuthorsOf("Subject\n\nCo-authored-by: Ada <ada@x.io> said hi\n\nThe end."), []);
98});
99
100test("contributors and commits show one person the same way", () => {
101 const base = { name: "syntaqx", commits: 361, firstAt: "", lastAt: "", weeks: [] };
102 const fromTally = contributorPerson({ ...base, kind: "user", username: "syntaqx", avatar: "f00d" });
103 const fromCommit = personFor("Chase Pierce", "syntaqx@gmail.com", owners);
104 assert.equal(shownName(fromTally), shownName(fromCommit));
105 assert.equal(fromTally.avatar, fromCommit.avatar);
106 assert.equal(profileHref(fromTally), profileHref(fromCommit));
107 assert.equal(contributorPerson({ ...base, kind: "g1t", name: "g1t" }).kind, "g1t");
108 assert.equal(contributorPerson({ ...base, kind: "user", username: "ghost" }).kind, "ghost");
109 assert.deepEqual(contributorPerson({ ...base, kind: "author", name: "Sam" }), { kind: "author", name: "Sam", username: null, avatar: null });
110});