diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index 26b649c54..001c80c30 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -125,7 +125,7 @@ Sources: [go-live menu](resources/js/components/profile-actions-menu.tsx), [live ### Achievement badges and XP -Profiles have **15 achievement badges**. Earned badges appear in a single row, with **+N more** when more have been earned than fit. Hover over the row on desktop or tap it on mobile to toggle a popover with every badge, including locked badges and their progress. Profiles with no earned badges show **View achievements** instead. Select a badge in the popover, or the profile's rank or unlocked count, to open the detailed achievements dialog. +Profiles have **16 achievement badges**. Earned badges appear in a single row, with **+N more** when more have been earned than fit. Hover over the row on desktop or tap it on mobile to toggle a popover with every badge, including locked badges and their progress. Profiles with no earned badges show **View achievements** instead. Select a badge in the popover, or the profile's rank or unlocked count, to open the detailed achievements dialog. | Badge | When it unlocks | | --- | --- | @@ -144,10 +144,11 @@ Profiles have **15 achievement badges**. Earned badges appear in a single row, w | **luddite** | Stop following Tom while he still follows you. This deducts **100 XP**; following him again removes the badge and penalty. Accounts Tom has never befriended do not qualify. | | **shell shocked** | “Survived the php2shell downtime of Oct '26. Earns 100 XP.” — accounts created before **October 21, 2026 at 14:00 UTC** receive this badge and **100 bonus XP**. Accounts created at or after that moment do not qualify. | | **super-saiyan** | Have **9,000 followers or more** on /dev/null. “Y—your follower count. It... it’s over 9000!!!1!” | +| **git blame** | Have **at least one commit** in the [/dev/null repository](https://github.com/dev-null-sh/dev-null.sh) on GitHub, matched by your GitHub account rather than your handle. “Landed a commit in the /dev/null repo itself. git blame now points at you.” It uses the same contributor list as the About page, cached for an hour, so it can take that hour (and however long GitHub takes to update its counts) to appear after a merge. An earned badge stays while that list is cached; it only locks when the list runs out while GitHub can't be reached, until GitHub answers again. | Commit counts include replies and quotes. Commit-based badges and XP use non-deleted commits visible to the person viewing the profile, so an author may see progress from pending or rejected commits that other viewers cannot see. Streak badges use the **longest** streak, not the current streak: missing a day does not by itself remove them. Days follow the activity graph's app-timezone grouping, not the user's selected display timezone. -Badges are calculated from current account data, not permanently recorded awards. Removing qualifying activity can reduce progress or lock a badge again; for example, unstarring a commit can remove **stargazer**. **Shell shocked** depends only on when the account was created, so deleting activity does not remove it. When a commit posted on the web unlocks a badge, a toast names it and confetti drops; clicking an unlocked badge drops confetti again. Unlocking a badge does not normally give bonus XP; **shell shocked** contributes **100 XP** once. XP otherwise comes from **10 per commit**, **15 per day in the longest streak**, **5 per star received**, **5 per reply to another developer**, and **2 per star given to another developer**. The **luddite** penalty applies once while the badge is unlocked, not once per unfollow, and total XP cannot fall below zero. A qualifying reply contributes both commit XP and reply XP; pastéis do not add XP. +Badges are calculated from current account data, not permanently recorded awards. Removing qualifying activity can reduce progress or lock a badge again; for example, unstarring a commit can remove **stargazer**. **Shell shocked** depends only on when the account was created, so deleting activity does not remove it. **Git blame** depends only on GitHub's contributor list, not on anything posted on /dev/null. When a commit posted on the web unlocks a badge, a toast names it and confetti drops; clicking an unlocked badge drops confetti again. Unlocking a badge does not normally give bonus XP; **shell shocked** contributes **100 XP** once. XP otherwise comes from **10 per commit**, **15 per day in the longest streak**, **5 per star received**, **5 per reply to another developer**, and **2 per star given to another developer**. The **luddite** penalty applies once while the badge is unlocked, not once per unfollow, and total XP cannot fall below zero. A qualifying reply contributes both commit XP and reply XP; pastéis do not add XP. XP also determines your Unix rank: **user** at 0 XP, **daemon** at 50, **operator** at 150, **maintainer** at 400, **wheel** at 1,000, and **root** at 2,500. The achievements dialog's **Ranks** tab shows the levels and progress. Level-up notifications use your public progress, so pending or rejected commits do not trigger them. Each level above the starting rank can notify you only once, even if you lose and regain the XP; jumping ahead does not send a notification for every skipped level. diff --git a/app/Enums/Achievement.php b/app/Enums/Achievement.php index 8a878196c..2359a4111 100644 --- a/app/Enums/Achievement.php +++ b/app/Enums/Achievement.php @@ -21,6 +21,7 @@ enum Achievement: string case Luddite = 'luddite'; case ShellShocked = 'shell_shocked'; case SuperSaiyan = 'super_saiyan'; + case GitBlame = 'git_blame'; public function label(): string { @@ -40,6 +41,7 @@ public function label(): string self::Luddite => 'luddite', self::ShellShocked => 'shell shocked', self::SuperSaiyan => 'super-saiyan', + self::GitBlame => 'git blame', }; } @@ -61,6 +63,7 @@ public function description(): string self::Luddite => 'Unfollowed Tom. Costs 100 XP until you follow him again.', self::ShellShocked => "Survived the php2shell downtime of Oct '26. Earns 100 XP.", self::SuperSaiyan => 'Y—your follower count. It... it’s over 9000!!!1!', + self::GitBlame => 'Landed a commit in the /dev/null repo itself. git blame now points at you.', }; } @@ -82,6 +85,7 @@ public function icon(): string self::Luddite => 'bot-off', self::ShellShocked => 'bomb', self::SuperSaiyan => 'dragon-ball', + self::GitBlame => 'git-commit-horizontal', }; } @@ -103,6 +107,7 @@ public function target(): int self::Luddite => 1, self::ShellShocked => 1, self::SuperSaiyan => 9000, + self::GitBlame => 1, }; } } diff --git a/app/Queries/ContributorsQuery.php b/app/Queries/ContributorsQuery.php index 5bbaba6d4..7123d4fcb 100644 --- a/app/Queries/ContributorsQuery.php +++ b/app/Queries/ContributorsQuery.php @@ -60,6 +60,15 @@ public function get(): ?array ], $accounts); } + /** + * How many commits the user's GitHub account has in the repository, as GitHub counts them, from the same list the + * About page shows. Zero when it has none, or GitHub didn't answer. + */ + public function commits(User $user): int + { + return array_column($this->accounts() ?? [], 'commits', 'github_id')[$user->github_id] ?? 0; + } + /** * The GitHub accounts behind the contributors. A failed read is kept for a minute, so an outage doesn't send every * visitor to GitHub. diff --git a/app/Queries/UserAchievementsQuery.php b/app/Queries/UserAchievementsQuery.php index 0c27f7ef7..2029c081d 100644 --- a/app/Queries/UserAchievementsQuery.php +++ b/app/Queries/UserAchievementsQuery.php @@ -35,7 +35,7 @@ */ final readonly class UserAchievementsQuery { - public function __construct(private UserStreakQuery $streaks) + public function __construct(private UserStreakQuery $streaks, private ContributorsQuery $contributors) { // } @@ -90,6 +90,7 @@ public function get(User $user, ?User $viewer, ?array $streaks = null): array $hasUnfollowedTom = $user->followers()->where('github_id', CreateTomFriendship::GITHUB_ID)->exists() && ! $user->following()->where('github_id', CreateTomFriendship::GITHUB_ID)->exists(); $isShellShocked = $user->created_at->lt('2026-10-21 14:00:00 UTC'); + $repositoryCommits = $this->contributors->commits($user); // XP breakdown: 10 per commit, 15 per streak day, 5 per star received, 5 per reply, 2 per star given $commitsXp = $commitsCount * 10; @@ -188,6 +189,10 @@ public function get(User $user, ?User $viewer, ?array $streaks = null): array 'progress' => min($user->followers()->count(), Achievement::SuperSaiyan->target()), 'target' => Achievement::SuperSaiyan->target(), ], + Achievement::GitBlame->value => [ + 'progress' => min($repositoryCommits, Achievement::GitBlame->target()), + 'target' => Achievement::GitBlame->target(), + ], ]; $badges = array_map(function (Achievement $achievement) use ($metrics): array { diff --git a/resources/js/components/achievements-dialog.tsx b/resources/js/components/achievements-dialog.tsx index 392a93367..84519258a 100644 --- a/resources/js/components/achievements-dialog.tsx +++ b/resources/js/components/achievements-dialog.tsx @@ -5,6 +5,7 @@ import { Cookie, FileCode, Flame, + GitCommitHorizontal, GitMerge, Key, Server, @@ -46,6 +47,7 @@ const iconMap: Record> = { 'bot-off': BotOff, bomb: Bomb, 'dragon-ball': DragonBallIcon, + 'git-commit-horizontal': GitCommitHorizontal, }; export function AchievementsDialog({ diff --git a/resources/js/components/achievements-shelf.tsx b/resources/js/components/achievements-shelf.tsx index e7e812987..2400b2819 100644 --- a/resources/js/components/achievements-shelf.tsx +++ b/resources/js/components/achievements-shelf.tsx @@ -7,6 +7,7 @@ import { Cookie, FileCode, Flame, + GitCommitHorizontal, GitMerge, Key, Server, @@ -51,6 +52,7 @@ const iconMap: Record> = { 'bot-off': BotOff, bomb: Bomb, 'dragon-ball': DragonBallIcon, + 'git-commit-horizontal': GitCommitHorizontal, }; export function AchievementsShelf({ diff --git a/tests/Feature/Controllers/AboutControllerTest.php b/tests/Feature/Controllers/AboutControllerTest.php index a4a03a0d8..a854755fb 100644 --- a/tests/Feature/Controllers/AboutControllerTest.php +++ b/tests/Feature/Controllers/AboutControllerTest.php @@ -4,6 +4,7 @@ use App\Models\User; use Illuminate\Http\Client\ConnectionException; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; it('renders the about page for guests', function (): void { @@ -55,6 +56,7 @@ }); it('leaves the contributors out while GitHub is unreachable', function (): void { + Cache::forget(gitHubContributorsCacheKey()); Http::fake(fn () => throw new ConnectionException('timeout')); $this->get(route('about.show')) diff --git a/tests/Pest.php b/tests/Pest.php index ac43ed690..8002b0065 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -15,6 +15,7 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\Client\Request; use Illuminate\Http\UploadedFile; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Process; @@ -30,6 +31,9 @@ Str::createRandomStringsNormally(); Str::createUuidsNormally(); Http::preventStrayRequests(); + // Achievements read the repository contributors, so every page that shows them would ask GitHub; + // fakeGitHubContributors() clears this to serve a list instead + Cache::put(gitHubContributorsCacheKey(), []); Process::preventStrayProcesses(); Sleep::fake(); @@ -155,6 +159,11 @@ function gitHubContributor(string $login, int $commits, string $type = 'User', ? return ['login' => $login, 'id' => $id ?? crc32($login), 'contributions' => $commits, 'type' => $type]; } +function gitHubContributorsCacheKey(): string +{ + return 'about:contributor-accounts:'.config()->string('services.github.repository'); +} + /** * Serves the contributors of the repository like GitHub does: most commits first, a page at a time. * @@ -162,6 +171,8 @@ function gitHubContributor(string $login, int $commits, string $type = 'User', ? */ function fakeGitHubContributors(array $contributors): void { + Cache::forget(gitHubContributorsCacheKey()); + Http::fake(['api.github.com/repos/'.config()->string('services.github.repository').'/contributors*' => function (Request $request) use ($contributors): PromiseInterface { $perPage = (int) $request['per_page']; diff --git a/tests/Unit/Queries/ContributorsQueryTest.php b/tests/Unit/Queries/ContributorsQueryTest.php index 0ea6058e1..2c0ac0175 100644 --- a/tests/Unit/Queries/ContributorsQueryTest.php +++ b/tests/Unit/Queries/ContributorsQueryTest.php @@ -2,11 +2,16 @@ declare(strict_types=1); +use App\Models\User; use App\Queries\ContributorsQuery; use Illuminate\Http\Client\ConnectionException; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; +beforeEach(function (): void { + Cache::forget(gitHubContributorsCacheKey()); +}); + it('lists everyone with a commit, as GitHub counts them', function (): void { fakeGitHubContributors([gitHubContributor('xHeaven', 187), gitHubContributor('jubianchi', 1)]); @@ -131,3 +136,19 @@ expect(resolve(ContributorsQuery::class)->get())->toBe([['login' => 'recovered', 'commits' => 12, 'handle' => null]]); Http::assertSentCount(3); }); + +it('counts the commits of a user by their GitHub account, and none for anyone else', function (): void { + fakeGitHubContributors([gitHubContributor('xHeaven', 187), gitHubContributor('jubianchi', 1)]); + $query = resolve(ContributorsQuery::class); + + expect($query->commits(User::factory()->make(['github_id' => (string) crc32('jubianchi')])))->toBe(1) + ->and($query->commits(User::factory()->make(['handle' => 'xHeaven'])))->toBe(0); + + Http::assertSentCount(1); +}); + +it('counts no commits while GitHub does not answer', function (): void { + Http::fake(['api.github.com/*' => Http::response(status: 500)]); + + expect(resolve(ContributorsQuery::class)->commits(User::factory()->make(['github_id' => (string) crc32('xHeaven')])))->toBe(0); +}); diff --git a/tests/Unit/Queries/UserAchievementsQueryTest.php b/tests/Unit/Queries/UserAchievementsQueryTest.php index 5200495fd..dabb106e9 100644 --- a/tests/Unit/Queries/UserAchievementsQueryTest.php +++ b/tests/Unit/Queries/UserAchievementsQueryTest.php @@ -10,6 +10,8 @@ use App\Models\SshKey; use App\Models\User; use App\Queries\UserAchievementsQuery; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Http; beforeEach(function (): void { $this->travelTo(now()->setDate(2026, 10, 22)->setTime(12, 0)); @@ -28,7 +30,7 @@ ->and($result['ranks'])->toHaveCount(6) ->and($result['xp_breakdown']['commits']['xp'])->toBe(0) ->and($result['xp_breakdown']['shell_shocked']['xp'])->toBe(0) - ->and($result['badges'])->toHaveCount(15); + ->and($result['badges'])->toHaveCount(16); foreach ($result['badges'] as $badge) { expect($badge['unlocked'])->toBeFalse() @@ -360,3 +362,34 @@ 'exactly at cutoff' => ['2026-10-21 14:00:00', false, 0, 1], 'just after cutoff' => ['2026-10-21 14:00:01', false, 0, 1], ]); + +it('unlocks git blame with a commit in the /dev/null repository, matching the GitHub account', function (): void { + $contributor = User::factory()->create(['github_id' => (string) crc32('xHeaven'), 'handle' => 'renamed']); + $other = User::factory()->create(['handle' => 'xHeaven']); + fakeGitHubContributors([gitHubContributor('xHeaven', 187)]); + + $query = resolve(UserAchievementsQuery::class); + $result = $query->get($contributor, null); + + expect(collect($result['badges'])->firstWhere('id', 'git_blame'))->toBe([ + 'id' => 'git_blame', + 'name' => 'git blame', + 'description' => 'Landed a commit in the /dev/null repo itself. git blame now points at you.', + 'icon' => 'git-commit-horizontal', + 'unlocked' => true, + 'progress' => 1, + 'target' => 1, + ])->and($result['xp'])->toBe(0) + ->and(collect($query->get($other, null)['badges'])->firstWhere('id', 'git_blame')['unlocked'])->toBeFalse(); +}); + +it('keeps git blame locked while GitHub does not answer', function (): void { + $user = User::factory()->create(['github_id' => (string) crc32('xHeaven')]); + Cache::forget(gitHubContributorsCacheKey()); + Http::fake(['api.github.com/*' => Http::response(status: 500)]); + + $badge = collect(resolve(UserAchievementsQuery::class)->get($user, null)['badges'])->firstWhere('id', 'git_blame'); + + expect($badge['unlocked'])->toBeFalse() + ->and($badge['progress'])->toBe(0); +});