更新
This commit is contained in:
@@ -41,6 +41,7 @@ $manager->setConfig(['default' => 'mysql', 'auto_timestamp' => true, 'datetime_f
|
||||
'prefix' => 'zyt_', 'fields_strict' => true]]]);
|
||||
Container::getInstance()->instance('think\DbManager', $manager);
|
||||
$config = new think\Config();
|
||||
$config->set(['default' => 'file', 'channels' => ['file' => ['type' => 'File', 'close' => true]]], 'log');
|
||||
$config->set(['enabled' => true, 'encryption_key' => str_repeat('isolated-test-', 4), 'debounce_seconds' => 0,
|
||||
'lease_seconds' => 600, 'max_attempts' => 3, 'max_manual_retries' => 2, 'max_parallel_per_model' => 1,
|
||||
'daily_model_tasks' => 200, 'transcript_wait_seconds' => 300], 'prescription_analysis');
|
||||
@@ -299,6 +300,31 @@ try {
|
||||
$statuses = Api::statuses([$rx['id']], 1, $root);
|
||||
$expect($statuses['items'][0]['models']['qwen']['score'] === 80.0, 'list returns persisted numeric score');
|
||||
$expect($statuses['items'][0]['models']['openai']['score'] === null, 'failed score is null rather than zero');
|
||||
Db::startTrans();
|
||||
$testKey = $config->get('prescription_analysis.encryption_key');
|
||||
try {
|
||||
$damagedRx = $fixture();
|
||||
$damagedBatch = $save($damagedRx);
|
||||
// A valid ciphertext authenticated for a different batch must fail verification.
|
||||
Db::name('prescription_ai_batch')->where('id', $damagedBatch)->update([
|
||||
'source_diagnosis_ids_json' => '[1]', 'access_cipher' => $stored['access_cipher'],
|
||||
]);
|
||||
$mixed = Api::statuses([$damagedRx['id'], $rx['id']], 1, $root);
|
||||
$expect(array_column($mixed['items'], 'prescription_id') === [(int) $rx['id']]
|
||||
&& $mixed['items'][0]['models']['qwen']['score'] === 80.0,
|
||||
'unreadable access snapshot is omitted and the healthy score is preserved');
|
||||
|
||||
$config->set(['encryption_key' => 'too-short'], 'prescription_analysis');
|
||||
try {
|
||||
Api::statuses([$rx['id']], 1, $root);
|
||||
$expect(false, 'invalid installation key must surface');
|
||||
} catch (RuntimeException $e) {
|
||||
$expect($e->getMessage() === 'AI_ANALYSIS_KEY_INVALID', 'systemic key failure propagates from statuses');
|
||||
}
|
||||
} finally {
|
||||
$config->set(['encryption_key' => $testKey], 'prescription_analysis');
|
||||
Db::rollback();
|
||||
}
|
||||
$detail = Api::detail($batchId, 1, $root);
|
||||
$expect($detail['models']['qwen']['report']['summary'] === 'synthetic report', 'authorized detail decrypts');
|
||||
$expect($detail['models']['qwen']['progress']['stage'] === 'completed'
|
||||
@@ -344,6 +370,45 @@ try {
|
||||
&& $hiddenDetail['models']['openai']['reason'] !== '', 'hidden metric preserves report, candidate, original, review and failure explanation');
|
||||
$denied(static fn () => Api::statistics([], 1, $root), 'root without selected grant cannot read agreement statistics');
|
||||
Api::review($batchId, 'qwen', 'not_adopted', 'test comment', 1, $root);
|
||||
Db::startTrans();
|
||||
try {
|
||||
$dailyKey = date('Y-m-d') . ':openai';
|
||||
$budget = static fn () => Db::name('prescription_ai_limit')->where('limit_key', $dailyKey);
|
||||
$retryTask = static fn () => Db::name('prescription_ai_task')->where('id', $o['id']);
|
||||
$budget()->update(['used_count' => 200]);
|
||||
$paused = Api::retry($batchId, 'openai', 1, $root);
|
||||
$deadline = strtotime('tomorrow', $paused['progress']['server_time']);
|
||||
$expect($paused['status'] === 'retry_wait' && $paused['error_code'] === 'BUDGET_PAUSED'
|
||||
&& $paused['progress']['next_run_at'] === $deadline && $paused['progress']['wait_remaining_seconds'] > 0
|
||||
&& $paused['manual_retries'] === 1 && $paused['max_manual_retries'] === 2
|
||||
&& $paused['last_error_code'] === 'UPSTREAM_TIMEOUT' && $paused['last_error_message'] !== '',
|
||||
'manual retry acknowledges the real daily budget and preserves the previous attempt cause before any worker poll');
|
||||
$expect((int) $retryTask()->value('next_run_at') === $deadline && (int) $budget()->value('used_count') === 200
|
||||
&& Store::claimTask('openai') === null && Api::retry($batchId, 'openai', 1, $root)['manual_retries'] === 1,
|
||||
'deferred manual round is persisted once without reserving or bypassing a model slot');
|
||||
// This is the shape already stored by older versions before their first post-retry worker scan.
|
||||
$retryTask()->update(['next_run_at' => time() - 5, 'error_code' => '']);
|
||||
$beforePoll = Api::detail($batchId, 1, $root);
|
||||
$waiting = $beforePoll['models']['openai'];
|
||||
$expect($waiting['error_code'] === 'BUDGET_PAUSED' && $waiting['progress']['next_run_at'] === $deadline
|
||||
&& $waiting['last_error_code'] === 'UPSTREAM_TIMEOUT' && $beforePoll['models']['qwen']['status'] === 'success'
|
||||
&& !isset($beforePoll['models']['qwen']['score']) && $retryTask()->value('error_code') === '',
|
||||
'polled legacy retry shows the current budget without writes, has independent model states and preserves metric visibility');
|
||||
$expect(Store::claimTask('openai') === null && $retryTask()->value('error_code') === 'BUDGET_PAUSED'
|
||||
&& (int) $retryTask()->value('total_attempts') === 1, 'worker enforces the same ledger even for legacy due retries');
|
||||
// Simulate the next budget window with an elapsed deadline.
|
||||
$budget()->update(['used_count' => 0]);
|
||||
$retryTask()->update(['next_run_at' => time() - 10]);
|
||||
$eligible = Api::detail($batchId, 1, $root)['models']['openai'];
|
||||
$expect($eligible['error_code'] === '' && $eligible['progress']['wait_remaining_seconds'] === 0
|
||||
&& str_contains($eligible['progress']['notice'], '等待后台领取') && $eligible['last_error_code'] === 'UPSTREAM_TIMEOUT',
|
||||
'past budget pause waits for a real claim without continuing to report yesterday\'s exhaustion');
|
||||
$resumed = Store::claimTask('openai');
|
||||
$expect((int) $resumed['total_attempts'] === 2 && (int) $budget()->value('used_count') === 1,
|
||||
'worker resumes after reset and charges one attempt');
|
||||
} finally {
|
||||
Db::rollback();
|
||||
}
|
||||
$expect(Api::retry($batchId, 'openai', 1, $root)['status'] === 'retry_wait',
|
||||
'agreement restriction does not remove independent report review/retry permission');
|
||||
Visibility::setConfig(['role_ids' => [], 'admin_ids' => [1]], 1);
|
||||
|
||||
Reference in New Issue
Block a user