Files
coolify/tests/Support/RemoteProcessTestHelpers.php
T
Andras Bacsai 8d083deffb fix(storage): stop syncing file storages on every compose parse
The compose parser queued ServerFilesFromServerJob for every volume on
each parse, and pages that only show data parse the Compose file. Each
sync also sent two SSH commands for each file.

- Queue the sync only for a compose deployment, and for each service
  resource with file storages when the service starts or deploys.
- Read the compose service names without a parse on the Domains and
  scheduled task pages.
- Check all file storages with one remote command, and stop when a
  symbolic link, a special file, or an unknown state is at a file path.
- Keep the application path in a file storage when a pull request
  preview is parsed. Preview deployments of the current parser write
  their `-pr-<id>` copies through LocalFileVolume::forPullRequest().
- Remove the unreachable file sync from the service resource page.
2026-10-27 12:04:37 +01:00

45 lines
1.5 KiB
PHP

<?php
use Illuminate\Process\PendingProcess;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Str;
/**
* The text of a faked process: its command line and its stdin. SSH command batches go to the
* server on stdin, so assertions on remote commands must read both.
*/
function remoteProcessScript(PendingProcess $process): string
{
$command = is_array($process->command) ? implode(' ', $process->command) : (string) $process->command;
return is_string($process->input) && $process->input !== '' ? $command."\n".$process->input : $command;
}
/**
* Process::fake() with command patterns that also match the SSH command batch on stdin.
* Unmatched processes get an empty successful result.
*
* @param array<string, mixed> $handlers pattern => result or closure, as for Process::fake()
*/
function fakeRemoteProcesses(array $handlers): void
{
Process::fake(function (PendingProcess $process) use ($handlers) {
$script = remoteProcessScript($process);
foreach ($handlers as $pattern => $handler) {
if (is_numeric($pattern) || $pattern === '*' || Str::is($pattern, $script)) {
return $handler instanceof Closure ? $handler($process) : $handler;
}
}
return Process::result();
});
}
/**
* The output of LocalFileVolume::remoteFileStateCommand() when every checked path has the same state.
*/
function remoteFileStatesOutput(string $state, int $paths = 20): string
{
return implode("\n", array_map(fn (int $index) => "{$index}:{$state}", range(1, $paths)));
}