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
3 changes: 1 addition & 2 deletions app/Commands/CertifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use App\Branding;
use App\Checks\CheckInterface;
use App\Checks\CheckResult;
use App\Checks\PestSyntaxValidator;
use App\Checks\SecurityScanner;
use App\Checks\TestRunner;
Expand Down Expand Up @@ -123,7 +122,7 @@ public function handle(): int
$checksClient->postCertificationComment($checkResults);
} else {
// Post actionable prompt with fix directions on failure
$assembler = new PromptAssembler();
$assembler = new PromptAssembler;
$assembled = $assembler->assemble($rawOutputs);

if ($assembled['prompt'] !== '') {
Expand Down
5 changes: 5 additions & 0 deletions app/GitHub/ChecksClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function createCheck(string $name, string $status = 'in_progress'): ?int
return $data['id'] ?? null;
} catch (GuzzleException $e) {
$this->logError('createCheck', $e);

return null;
}
}
Expand Down Expand Up @@ -119,6 +120,7 @@ public function completeCheck(
return true;
} catch (GuzzleException $e) {
$this->logError('completeCheck', $e);

return false;
}
}
Expand Down Expand Up @@ -155,6 +157,7 @@ public function reportCheck(
return true;
} catch (GuzzleException $e) {
$this->logError('reportCheck', $e);

return false;
}
}
Expand Down Expand Up @@ -199,6 +202,7 @@ public function postCertificationComment(array $checkResults): bool
return true;
} catch (GuzzleException $e) {
$this->logError('postCertificationComment', $e);

return false;
}
}
Expand Down Expand Up @@ -234,6 +238,7 @@ public function postActionablePrompt(string $prompt): bool
return true;
} catch (GuzzleException $e) {
$this->logError('postActionablePrompt', $e);

return false;
}
}
Expand Down
8 changes: 4 additions & 4 deletions app/Services/PromptAssembler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ final class PromptAssembler
public function __construct()
{
$this->transformers = [
new PhpStanPromptTransformer(),
new TestFailurePromptTransformer(),
new PhpStanPromptTransformer,
new TestFailurePromptTransformer,
];
}

Expand Down Expand Up @@ -94,7 +94,7 @@ public function transform(string $checkName, string $output): array
private function buildCombinedPrompt(array $failedChecks): string
{
$count = count($failedChecks);
$prompt = "# 🔧 Synapse Sentinel: {$count} check" . ($count === 1 ? '' : 's') . " need attention\n\n";
$prompt = "# 🔧 Synapse Sentinel: {$count} check".($count === 1 ? '' : 's')." need attention\n\n";
$prompt .= "The following issues must be resolved before this PR can be merged:\n\n";

foreach ($failedChecks as $checkName => $section) {
Expand All @@ -117,6 +117,6 @@ private function truncate(string $text, int $maxLength = 2000): string
return $text;
}

return substr($text, 0, $maxLength) . "\n... (truncated)";
return substr($text, 0, $maxLength)."\n... (truncated)";
}
}
19 changes: 18 additions & 1 deletion app/Services/SymfonyProcessRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,31 @@

use App\Contracts\ProcessResult;
use App\Contracts\ProcessRunner;
use Symfony\Component\Process\Exception\ProcessSignaledException;
use Symfony\Component\Process\Exception\ProcessTimedOutException;
use Symfony\Component\Process\Process;

final class SymfonyProcessRunner implements ProcessRunner
{
public function run(array $command, string $workingDirectory, int $timeout = 120): ProcessResult
{
$process = new Process($command, $workingDirectory, timeout: $timeout);
$process->run();

try {
$process->run();
} catch (ProcessTimedOutException $e) {
return new ProcessResult(
successful: false,
output: "Process timed out after {$timeout} seconds: ".$e->getMessage(),
exitCode: 124,
);
} catch (ProcessSignaledException $e) {
return new ProcessResult(
successful: false,
output: 'Process killed by signal: '.$e->getMessage(),
exitCode: $e->getProcess()->getExitCode() ?? 137,
);
}

return new ProcessResult(
successful: $process->isSuccessful(),
Expand Down
2 changes: 1 addition & 1 deletion app/Transformers/PhpStanPromptTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private function buildPrompt(array $data): array
$relativePath = $this->relativePath($filePath);
$errorCount = $fileData['errors'] ?? 0;

$prompt .= "### {$relativePath} ({$errorCount} error" . ($errorCount === 1 ? '' : 's') . ")\n\n";
$prompt .= "### {$relativePath} ({$errorCount} error".($errorCount === 1 ? '' : 's').")\n\n";

foreach ($fileData['messages'] ?? [] as $index => $message) {
$prompt .= $this->formatError($index + 1, $message);
Expand Down
3 changes: 1 addition & 2 deletions app/Transformers/TestFailurePromptTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ private function parseJunitXml(string $xml): array
/**
* Extract test cases from a test suite.
*
* @param \SimpleXMLElement $suite
* @param array<array<string, mixed>> $failures
* @param array<array<string, mixed>> $errors
*/
Expand Down Expand Up @@ -246,7 +245,7 @@ private function cleanMessage(string $message): string

// Truncate if too long
if (strlen($clean) > 500) {
$clean = substr($clean, 0, 500) . '... (truncated)';
$clean = substr($clean, 0, 500).'... (truncated)';
}

return trim($clean);
Expand Down
21 changes: 21 additions & 0 deletions tests/Unit/Services/SymfonyProcessRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,26 @@

expect($result->successful)->toBeTrue();
});

it('returns failed result with exit code 124 on process timeout', function () {
$runner = new SymfonyProcessRunner;
$result = $runner->run(['sleep', '30'], sys_get_temp_dir(), timeout: 1);

expect($result)->toBeInstanceOf(ProcessResult::class);
expect($result->successful)->toBeFalse();
expect($result->exitCode)->toBe(124);
expect($result->output)->toContain('Process timed out after 1 seconds');
});

it('returns failed result when process is killed by signal', function () {
$runner = new SymfonyProcessRunner;
// bash -c that sends SIGKILL to itself
$result = $runner->run(['bash', '-c', 'kill -9 $$'], sys_get_temp_dir());

expect($result)->toBeInstanceOf(ProcessResult::class);
expect($result->successful)->toBeFalse();
expect($result->output)->toContain('Process killed by signal');
expect($result->exitCode)->toBe(137);
});
});
});
Loading