37 lines
1.4 KiB
PHP
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;
|
|
}
|
|
}
|
|
}
|