Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions KNOWLEDGE_BASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,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 |
| --- | --- |
Expand All @@ -132,6 +132,7 @@ Profiles have **15 achievement badges**. Earned badges appear in a single row, w
| **pipe** | Write **5 replies to other developers' commits**, excluding self-replies. Replies still count when their parent commit is soft-deleted. |
| **authorized_keys** | Have at least one public SSH key linked from GitHub. |
| **sweet tooth** | Receive **100 pastéis across your account**, not on a single commit. Pastéis mode does not need to be enabled, and the total survives deletion of the awarded commits. |
| **upstream** | Have a commit on /dev/null's own production branch, which is where every merged pull request lands. GitHub's contributor list is checked by account ID, so a renamed username keeps it, and refreshed at most once an hour. |
| **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!” |
Expand All @@ -142,7 +143,7 @@ Badges are calculated from current account data, not permanently recorded awards

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.

Sources: [badge definitions](app/Enums/Achievement.php), [unlock conditions and XP calculation](app/Queries/UserAchievementsQuery.php), [streak calculation](app/Queries/UserStreakQuery.php), [Unix ranks](app/Enums/UnixRank.php), [level-up notifications](app/Actions/CreateLevelNotification.php), [achievements dialog](resources/js/components/achievements-dialog.tsx).
Sources: [badge definitions](app/Enums/Achievement.php), [unlock conditions and XP calculation](app/Queries/UserAchievementsQuery.php), [streak calculation](app/Queries/UserStreakQuery.php), [Unix ranks](app/Enums/UnixRank.php), [level-up notifications](app/Actions/CreateLevelNotification.php), [upstream contributors](app/Queries/UpstreamContributorsQuery.php), [achievements dialog](resources/js/components/achievements-dialog.tsx).

### Following developers and suggestions

Expand Down
5 changes: 5 additions & 0 deletions app/Enums/Achievement.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum Achievement: string
case Luddite = 'luddite';
case ShellShocked = 'shell_shocked';
case SuperSaiyan = 'super_saiyan';
case Upstream = 'upstream';

public function label(): string
{
Expand All @@ -40,6 +41,7 @@ public function label(): string
self::Luddite => 'luddite',
self::ShellShocked => 'shell shocked',
self::SuperSaiyan => 'super-saiyan',
self::Upstream => 'upstream',
};
}

Expand All @@ -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::Upstream => 'Got a pull request merged into /dev/null itself.',
};
}

Expand All @@ -82,6 +85,7 @@ public function icon(): string
self::Luddite => 'bot-off',
self::ShellShocked => 'bomb',
self::SuperSaiyan => 'dragon-ball',
self::Upstream => 'git-pull-request',
};
}

Expand All @@ -103,6 +107,7 @@ public function target(): int
self::Luddite => 1,
self::ShellShocked => 1,
self::SuperSaiyan => 9000,
self::Upstream => 1,
};
}
}
93 changes: 93 additions & 0 deletions app/Queries/UpstreamContributorsQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

declare(strict_types=1);

namespace App\Queries;

use App\Models\User;
use App\Services\GitHub;
use Illuminate\Support\Facades\Cache;
use Throwable;

/**
* Who has a commit on /dev/null's production branch, which is where every merged pull request lands. GitHub counts it
* under the author's account, matched by its immutable ID so a renamed username keeps the badge.
*/
final readonly class UpstreamContributorsQuery
{
private const string Key = 'upstream-contributors';

private const int MaxPages = 10;

/**
* Longer than a refresh can take: up to ten pages, each request given five seconds, with room to spare. A lock that
* ran out mid-refresh would let a second one start alongside it.
*/
private const int RefreshLockSeconds = 120;

public function __construct(private GitHub $github)
{
//
}

public function includes(User $user): bool
{
return in_array($user->github_id, $this->ids(), true);
}

/**
* Cached for an hour. When GitHub doesn't answer, the last list it gave is used, and asked for again a minute later.
* Only one request refreshes the list at a time: the others keep the last list meanwhile instead of all asking
* GitHub at once.
*
* @return list<string>
*/
private function ids(): array
{
/** @var list<string>|null $ids */
$ids = Cache::get(self::Key);

if ($ids !== null) {
return $ids;
}

/** @var list<string>|false $refreshed */
Comment thread
coderabbitai[bot] marked this conversation as resolved.
$refreshed = Cache::lock(self::Key.':refresh', self::RefreshLockSeconds)->get($this->refresh(...));

if ($refreshed !== false) {
return $refreshed;
}

/** @var list<string> $last */
$last = Cache::get(self::Key.':last', []);

return $last;
}

/**
* Another request may have refreshed the list while this one waited for its turn, so the cache is read again first.
*
* @return list<string>
*/
private function refresh(): array
{
/** @var list<string>|null $ids */
$ids = Cache::get(self::Key);

if ($ids !== null) {
return $ids;
}

try {
$ids = $this->github->accountIds('repos/'.config()->string('services.github.repository').'/contributors', self::MaxPages);
Cache::put(self::Key.':last', $ids);
Cache::put(self::Key, $ids, now()->addHour());
} catch (Throwable) {
/** @var list<string> $ids */
$ids = Cache::get(self::Key.':last', []);
Cache::put(self::Key, $ids, now()->addMinute());
}

return $ids;
}
}
6 changes: 5 additions & 1 deletion app/Queries/UserAchievementsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
final readonly class UserAchievementsQuery
{
public function __construct(private UserStreakQuery $streaks)
public function __construct(private UserStreakQuery $streaks, private UpstreamContributorsQuery $upstream)
{
//
}
Expand Down Expand Up @@ -188,6 +188,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::Upstream->value => [
'progress' => $this->upstream->includes($user) ? 1 : 0,
'target' => Achievement::Upstream->target(),
],
];

$badges = array_map(function (Achievement $achievement) use ($metrics): array {
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/achievements-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FileCode,
Flame,
GitMerge,
GitPullRequest,
Key,
Server,
Shield,
Expand Down Expand Up @@ -46,6 +47,7 @@ const iconMap: Record<string, React.ComponentType<{ className?: string }>> = {
'bot-off': BotOff,
bomb: Bomb,
'dragon-ball': DragonBallIcon,
'git-pull-request': GitPullRequest,
};

export function AchievementsDialog({
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/achievements-shelf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
FileCode,
Flame,
GitMerge,
GitPullRequest,
Key,
Server,
Shield,
Expand Down Expand Up @@ -51,6 +52,7 @@ const iconMap: Record<string, React.ComponentType<{ className?: string }>> = {
'bot-off': BotOff,
bomb: Bomb,
'dragon-ball': DragonBallIcon,
'git-pull-request': GitPullRequest,
};

export function AchievementsShelf({
Expand Down
113 changes: 113 additions & 0 deletions tests/Unit/Queries/UpstreamContributorsQueryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

declare(strict_types=1);

use App\Models\User;
use App\Queries\UpstreamContributorsQuery;
use Illuminate\Cache\Events\CacheMissed;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Http;

/**
* @param list<int> $ids
* @return list<array{id: int, login: string, type: string}>
*/
function contributorsResponse(array $ids): array
{
return array_map(fn (int $id): array => ['id' => $id, 'login' => "contributor-{$id}", 'type' => 'User'], $ids);
}

it('finds contributors by their github account id, not their username', function (): void {
$contributor = User::factory()->create(['github_id' => '123', 'username' => 'renamed-since']);
$other = User::factory()->create(['github_id' => '456']);

Http::fake([
'api.github.com/repos/dev-null-sh/dev-null.sh/contributors*' => Http::response(contributorsResponse([123, 789])),
]);

$query = resolve(UpstreamContributorsQuery::class);

expect($query->includes($contributor))->toBeTrue()
->and($query->includes($other))->toBeFalse();

Http::assertSentCount(1);
});

it('reads every page of contributors and keeps them for an hour', function (): void {
$lastPage = User::factory()->create(['github_id' => '1000']);

Http::fake([
'api.github.com/repos/dev-null-sh/dev-null.sh/contributors*' => Http::sequence()
->push(contributorsResponse(range(1, 100)))
->push(contributorsResponse([1000])),
]);

$query = resolve(UpstreamContributorsQuery::class);

expect($query->includes($lastPage))->toBeTrue();

$this->travel(59)->minutes();

expect($query->includes($lastPage))->toBeTrue();

Http::assertSentCount(2);
});

it('keeps the last known contributors while github does not answer', function (): void {
$contributor = User::factory()->create(['github_id' => '123']);

Http::fake([
'api.github.com/repos/dev-null-sh/dev-null.sh/contributors*' => Http::sequence()
->push(contributorsResponse([123]))
->push('Unavailable', 503)
->push(contributorsResponse([])),
]);

$query = resolve(UpstreamContributorsQuery::class);

expect($query->includes($contributor))->toBeTrue();

$this->travel(61)->minutes();

expect($query->includes($contributor))->toBeTrue();

$this->travel(2)->minutes();

expect($query->includes($contributor))->toBeFalse();

Http::assertSentCount(3);
});

it('has nobody when github has never answered', function (): void {
Http::fake([
'api.github.com/repos/dev-null-sh/dev-null.sh/contributors*' => Http::response('Unavailable', 503),
]);

expect(resolve(UpstreamContributorsQuery::class)->includes(User::factory()->create()))->toBeFalse();
});

it('keeps the last known contributors without asking github while another request refreshes them', function (): void {
$contributor = User::factory()->create(['github_id' => '123']);
Cache::put('upstream-contributors:last', ['123']);
Cache::lock('upstream-contributors:refresh', 30)->get();
Http::fake();

expect(resolve(UpstreamContributorsQuery::class)->includes($contributor))->toBeTrue();

Http::assertNothingSent();
});

it('uses the list another request refreshed while it waited for its turn', function (): void {
$contributor = User::factory()->create(['github_id' => '123']);
Http::fake();

// Another request finishes its refresh just after this one found the list missing.
Event::listen(CacheMissed::class, function (CacheMissed $event): void {
Cache::put($event->key, ['123'], 60);
});

expect(resolve(UpstreamContributorsQuery::class)->includes($contributor))->toBeTrue();

Http::assertNothingSent();
});
20 changes: 19 additions & 1 deletion tests/Unit/Queries/UserAchievementsQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Models\SshKey;
use App\Models\User;
use App\Queries\UserAchievementsQuery;
use Illuminate\Support\Facades\Http;

beforeEach(function (): void {
$this->travelTo(now()->setDate(2026, 10, 22)->setTime(12, 0));
Expand All @@ -28,7 +29,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()
Expand Down Expand Up @@ -66,6 +67,23 @@
->and($badge['progress'])->toBe(1);
});

it('unlocks upstream badge for developers with a commit on /dev/null itself', function (): void {
$contributor = User::factory()->create(['github_id' => '123']);
$user = User::factory()->create(['github_id' => '456']);

Http::fake([
'api.github.com/repos/dev-null-sh/dev-null.sh/contributors*' => Http::response([['id' => 123, 'login' => 'octocat', 'type' => 'User']]),
]);

$badge = fn (User $user): array => collect(resolve(UserAchievementsQuery::class)->get($user, $user)['badges'])
->firstWhere('id', Achievement::Upstream->value);

expect($badge($contributor)['unlocked'])->toBeTrue()
->and($badge($contributor)['icon'])->toBe('git-pull-request')
->and($badge($user)['unlocked'])->toBeFalse()
->and($badge($user)['progress'])->toBe(0);
});

it('tracks stars given to other developers and excludes self-starring', function (): void {
$user = User::factory()->create();
$other = User::factory()->create();
Expand Down