ifnex/docs/INSTALL-3.11.1-hotfix.fa.md
Kazem Alghasi defdcc22c9 feat(core): complete phase 3.11 and prepare for production deployment
This commit marks the completion of phase 3.11 (UAT Ready) and includes
significant updates to deployment automation, testing, and documentation.

Key changes:
- Implement `ifnex:smoke-test` command for E2E post-deployment validation
- Implement `ifnex:preflight` command for environment audit before migration
- Implement `ifnex:import-fx-rates` for automated multi-source currency
  rate imports (Exir.io and FreeCurrencyAPI)
- Update `CurrencySeeder` to support base currencies (USD, AED, EUR, CNY, IRR)
- Enhance `IfnexSmokeTest` with improved environment-aware checks and
  robust HTTP mocking in tests
- Update project documentation (Roadmap, README, AGENT, Handoff) to reflect
  completed phases 3.7 through 3.11
- Add UAT checklist and installation guides for recent hotfixes
- Update project statistics (models, migrations, endpoints, and test counts)
2026-11-08 06:28:21 +03:30

5.0 KiB
Raw Blame History

🔧 هات‌فیکس ۳.۱۱.۱ — رفع ۳ تست قرمز IfnexSmokeTestTest

تاریخ: ۱۴۰۴/۰۸/۱۱ نسخه: phase-3.11.1-hotfix


🩹 مشکل

بعد از نصب فاز ۳.۱۱ و اجرای php artisan test:

Tests: 3 failed, 81 passed (209 assertions)

شکستگی‌ها (همه در IfnexSmokeTestTest):

  • ❌ it passes when everything is healthy
  • ❌ it accepts custom base url
  • ❌ it accepts 422 for tracking endpoint

این سه تا PASS scenario هستند — یعنی موفقیت تست‌ها شکست خورده.


🔍 ریشهٔ مشکل

دستور ifnex:smoke-test در checkCacheConfig() این بررسی‌ها را انجام می‌دهد:

$configCached = file_exists(base_path('bootstrap/cache/config.php'));
$this->addResult('config:cache اجرا شده', ..., $configCached);

$routeCached = file_exists(base_path('bootstrap/cache/routes-v7.php'));
$this->addResult('route:cache اجرا شده', ..., $routeCached);

این فایل‌ها در محیط local/testing اجرا نمی‌شوند (که درست هم است — نباید اجرا شوند). ولی چون smoke-test این‌ها را به‌عنوان FAIL در نظر می‌گیرد، کل command با کد 1 خارج می‌شود و PASS scenario تست‌ها شکست می‌خورد.

در محیط Production این بررسی‌ها درست است، ولی در محیط local/testing نباید اجرا شوند.


✅ راه‌حل

اضافه کردن شرط APP_ENV=production به checkCacheConfig(). در غیر Production، این بررسی‌ها به‌عنوان N/A (not applicable) ثبت می‌شوند و fail محسوب نمی‌شوند:

private function checkCacheConfig(): void
{
    $env = (string) config('app.env');

    if ($env !== 'production') {
        $this->addResult(
            'config:cache اجرا شده',
            "N/A (env={$env}) — فقط در Production",
            true   // ← fail محسوب نمی‌شود
        );
        $this->addResult(
            'route:cache اجرا شده',
            "N/A (env={$env}) — فقط در Production",
            true
        );
        return;
    }

    // در Production: بررسی واقعی وجود فایل cache
    $configCached = file_exists(base_path('bootstrap/cache/config.php'));
    // ...
}

مزایا

  • ✅ در محیط Production همچنان به‌درستی چک می‌شود (و اگر cache اجرا نشده باشد، fail می‌شود)
  • ✅ در محیط local/testing به‌عنوان N/A ثبت می‌شود و fail محسوب نمی‌شود
  • ✅ هیچ رفتار Production تغییری نکرده — فقط تست‌ها ایمن شدند

📦 محتویات بسته

ifnex-phase-3.11.1-hotfix.zip
├── 04_Laravel/
│   └── app/Console/Commands/
│       └── IfnexSmokeTest.php      ← تنها فایل تغییرکرده
└── docs/
    └── INSTALL-3.11.1-hotfix.fa.md  ← همین فایل

فقط ۱ فایل کد تغییر کرده — حجم کم، نصب سریع.


📥 نحوهٔ نصب

مرحلهٔ ۱: اکسترکت

ZIP را دانلود و محتوای آن را روی ریشه پروژه اکسترکت کنید (Replace):

C:\xampp\htdocs\IFNEX-Logistics\

این کار فایل 04_Laravel/app/Console/Commands/IfnexSmokeTest.php را overwrite می‌کند.

مرحلهٔ ۲: تست

cd C:\xampp\htdocs\IFNEX-Logistics\04_Laravel
php artisan test

انتظار

Tests: 82 passed (220+ assertions)

به‌خصوص:

PASS  Tests\Feature\Console\IfnexSmokeTestTest
  ✓ it passes when everything is healthy          ← قبلاً قرمز
  ✓ it fails when currencies table is empty
  ✓ it fails when currency rate is zero
  ✓ it fails when no admin user exists
  ✓ it fails when countries not seeded
  ✓ it fails when roles not seeded
  ✓ it fails when health endpoint returns 500
  ✓ it fails when protected endpoint allows unauthenticated access
  ✓ it accepts custom base url                     ← قبلاً قرمز
  ✓ it accepts 422 for tracking endpoint           ← قبلاً قرمز
  ✓ it fails when tracking endpoint returns 500

🚀 بعد از تست

اگر سبز بود:

cd C:\xampp\htdocs\IFNEX-Logistics
git add 04_Laravel/app/Console/Commands/IfnexSmokeTest.php
git commit -m "fix(smoke-test): skip cache checks in non-production environments (resolves 3 red PASS-scenario tests)"
git push origin main

🎯 خلاصهٔ فنی

مشکل راه‌حل
checkCacheConfig() در محیط local هم bootstrap/cache/*.php را چک می‌کرد (که اجرا نشده‌اند) اضافه شد if ($env !== 'production') return; با N/A
باعث می‌شد ۳ PASS scenario تست قرمز شوند رفع شد — ۸۲ تست سبز
رفتار Production هیچ تغییری نکرده ✅ تأیید شد