make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); use Illuminate\Support\Facades\{DB,Cache};use App\Models\MailMessage; if(DB::connection()->getDatabaseName()!=='fuc_xb_test'||config('queue.default')!=='redis'||config('mail.driver')!=='smtp'||App\Services\MailFlow\AutomaticMailPolicy::state()['level']!==3)throw new RuntimeException('Mail worker isolation guard failed'); $action=$argv[1]??'';$file=$dir.'/mail-queue-intent.json';$recipient='mukaitao@proton.me';$key='fuc-xb-launch-worker-20261105-notification'; if($action==='enqueue'){ if(is_file($file))throw new RuntimeException('Existing intent; inspect receipts rather than resend'); $before=MailMessage::where('email',$recipient)->pluck('id')->all();file_put_contents($file,json_encode(['recipient'=>$recipient,'before_ids'=>$before,'started_at'=>time(),'expected_messages'=>2]));chmod($file,0600); // Exercise the native verification controller -> Redis -> persistent Horizon worker. $r=Illuminate\Http\Request::create('https://fuc-xb-test.gemcook.net/api/v1/passport/comm/sendEmailVerify','POST',['email'=>$recipient],[],[],['HTTP_ACCEPT'=>'application/json','REMOTE_ADDR'=>'127.0.0.1']);app()->instance('request',$r);$response=app(Illuminate\Contracts\Http\Kernel::class)->handle($r);if($response->getStatusCode()!==200)throw new RuntimeException('Native verification enqueue failed'); App\Jobs\SendEmailJob::dispatch(['email'=>$recipient,'subject'=>'[FUC-XB 工作队列验收 20261105] 通知邮件','template_name'=>'notify','purpose'=>'admin_test','message_key'=>$key,'template_value'=>['name'=>'FUC-XB_TEST','content'=>'仅用于独立测试站真实工作队列验收;不涉及正式切换或扣款。','url'=>'https://fuc-xb-test.tomtojapan.online']]); echo json_encode(['queued'=>true,'recipient'=>$recipient,'expected_messages'=>2,'queue'=>'redis','worker'=>'persistent Horizon','mass_mail_sent'=>0]);exit; } if($action==='status'){ $s=json_decode(file_get_contents($file),true,512,JSON_THROW_ON_ERROR);$rows=MailMessage::where('email',$recipient)->whereNotIn('id',$s['before_ids'])->get();if($rows->count()>2)throw new RuntimeException('Unexpected duplicate mail; stop'); $out=[];foreach($rows as$m){$event=null;if($m->channel==='resend'&&$m->provider_id){try{$event=app(App\Services\MailFlow\ResendClient::class)->retrieve($m->provider_id)['last_event']??null;}catch(Throwable){$event='provider_status_unavailable';}} $out[]=['id'=>$m->id,'purpose'=>$m->purpose,'channel'=>$m->channel,'status'=>$m->status,'attempts'=>$m->attempts,'provider_event'=>$event];} $passed=count($out)===2&&!array_filter($out,fn($r)=>!in_array($r['status'],['submitted','delivered'],true)||$r['attempts']!==1); if($passed){Cache::forget(App\Utils\CacheKey::get('EMAIL_VERIFY_CODE',$recipient));Cache::forget(App\Utils\CacheKey::get('LAST_SEND_EMAIL_VERIFY_TIMESTAMP',$recipient));file_put_contents($dir.'/mail-queue-receipt.json',json_encode(['passed'=>true,'messages'=>$out,'recipient'=>$recipient,'queue_worker_lifecycle_verified'=>true,'verification_cache_cleared'=>true],JSON_PRETTY_PRINT));} echo json_encode(['passed'=>$passed,'messages'=>$out,'pending'=>Illuminate\Support\Facades\Queue::size('send_email'),'failed_jobs'=>DB::table('failed_jobs')->count()]);exit; } throw new RuntimeException('Unsupported mail acceptance action');