Files
zyt/server/tests/PrescriptionAiPipelineTest.php
T
2026-09-10 15:19:17 +08:00

50 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
namespace app\common\service\prescriptionai {
/** Only the external evidence/model boundaries are fixtures; real worker/store/API/ORM run. */
final class PrescriptionAiContext
{
public static bool $allowed = true;
public static int $builds = 0;
public static function build(array $rx, int $actor, array $info, int $decisionAt): array
{
self::$builds++;
return ['source' => ['records' => [['source_id' => 'diagnoses:1', 'data' => ['symptom' => 'fixture']]]],
'source_hash' => hash('sha256', 'pipeline evidence'), 'source_diagnosis_ids' => [1],
'source_summary' => ['source_record_count' => 1], 'source_access_manifest' => [],
'missing' => [], 'baseline_eligible' => false, 'baseline_exclusion_reasons' => ['test_nonbaseline'],
'comparison_type' => 'latest_context', 'cutoff_at' => time(), 'wait_for_transcript' => false];
}
public static function assertSnapshotAccess(array $context, int $actor, array $info): bool
{
return self::$allowed;
}
}
final class PrescriptionAiGenerator
{
public static array $inputs = [];
public static bool $revokeDuringCall = false;
public static function generate(string $model, array $context, ?callable $checkpoint = null): array
{
self::$inputs[$model] = $context;
if ($checkpoint && !$checkpoint(['stage' => 'fixture', 'steps' => [], 'usage' => []])) {
return ['ok' => false, 'error_code' => 'CHECKPOINT_REJECTED', 'retryable' => false];
}
if (self::$revokeDuringCall) {
PrescriptionAiContext::$allowed = false;
}
return ['ok' => true, 'report' => ['summary' => 'fixture report'], 'coverage' => ['status' => 'complete', 'complete' => true],
'candidate' => ['status' => 'available_for_review', 'prescription_type' => '饮片', 'dose_basis' => 'per_dose',
'herbs' => [['name' => '测试药材', 'dosage' => 10, 'unit' => 'g', 'dose_basis' => 'per_dose',
'formula_type' => '主方', 'processing' => '', 'instructions' => '']], 'usage_days' => 7, 'times_per_day' => 2],
'model_name' => 'fixture-' . $model, 'prompt_version' => 'fixture-v1'];
}
}
}
namespace {
define('PRESCRIPTION_AI_PIPELINE_FIXTURE', true);
require __DIR__ . '/PrescriptionAiQueueTest.php';
}