Files
compras/app/Console/Commands/SgcAiAssess.php
T
nala c6373365bf
tests / ci (push) Canceled after 0s
commit9
2026-10-30 20:02:30 +02:00

37 lines
1.4 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Services\SyntheticAiAssessment;
use Illuminate\Console\Command;
use Throwable;
class SgcAiAssess extends Command
{
protected $signature = 'sgc:ai-assess {result : Ficheiro JSON UTF-8 do ensaio fictício}';
protected $description = 'Conferir localmente cobertura e referências de um resultado do ensaio, sem rede';
public function handle(SyntheticAiAssessment $assessment): int
{
try {
$path = realpath((string) $this->argument('result'));
if ($path === false || ! is_file($path) || filesize($path) > 100000) {
throw new \RuntimeException('Local result file required.');
}
$input = json_decode((string) file_get_contents($path), true, 16, JSON_THROW_ON_ERROR);
if (! is_array($input) || ($input['synthetic_only'] ?? null) !== true || ! is_array($input['claims'] ?? null)) {
throw new \RuntimeException('Synthetic result required.');
}
$result = $assessment->assess($input['claims']);
$this->line(json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR));
return self::SUCCESS;
} catch (Throwable) {
$this->error('Não foi possível conferir o resultado fictício. Verifique o ficheiro e as referências; nenhum pedido externo foi efectuado.');
return self::FAILURE;
}
}
}