coolify/tests/Unit/CleanupGithubRunnerArtifactsJobTest.php
Andras Bacsai 5c50ab6162 feat(github-runners): improve runner lifecycle and GitHub sync
Add runner execution observability and lifecycle hardening for self-hosted
GitHub Actions runners, including:
- scheduled artifact cleanup job for cached runner tarballs/templates
- workflow_job in_progress handling to mark executions as running
- safer cleanup failure handling and non-functional server fallback
- persisted workflow job HTML URLs with execution "Open" links in UI
- configurable runner group name sync (UI + provisioning + GitHub API)
- webhook events persistence and auto-fix for missing required events
- strict enum/status checks and related model cast/query improvements

Also includes migrations and expanded feature/unit coverage for webhook,
provisioning, cleanup, and runner group/event sync behaviors.
2026-03-03 22:21:13 +01:00

28 lines
1.3 KiB
PHP

<?php
use App\Jobs\CleanupGithubRunnerArtifactsJob;
it('builds cleanup commands for cached runner tarballs and template directories', function () {
$commands = CleanupGithubRunnerArtifactsJob::buildCleanupCommands('/opt/github-runners');
expect($commands)->toHaveCount(3);
expect($commands[0])->toContain('.cache/actions-runner-linux-${arch}-*.tar.gz');
expect($commands[1])->toContain('.templates/runner-${arch}-*');
expect($commands[2])->toContain('.template/runner-${arch}-*');
expect($commands[0])->toContain('tail -n +3');
expect($commands[1])->toContain('tail -n +3');
expect($commands[2])->toContain('tail -n +3');
});
it('schedules github runner artifact cleanup daily at 2am', function () {
$kernelFile = file_get_contents(__DIR__.'/../../app/Console/Kernel.php');
expect($kernelFile)->toContain('use App\\Jobs\\CleanupGithubRunnerArtifactsJob;');
expect($kernelFile)->toContain("->job(new CleanupGithubRunnerArtifactsJob)->dailyAt('02:00')->onOneServer();");
});
it('updates runner cache and template timestamps during provisioning', function () {
$provisionFile = file_get_contents(__DIR__.'/../../app/Jobs/ProvisionGithubRunnerJob.php');
expect($provisionFile)->toContain('touch {$cacheDir}/{$tarball} {$templateDir}');
});