---
name: markest-test-update
description: Use when updating the Markest Laravel project from the local workspace to the isolated test site at test.markest.com.tr, including safe backup, deploy, Laravel cache/migration handling, API checks, tender/listing checks, homepage template checks, and rollback discipline. Trigger this before any Markest test-server update, deployment, hotfix, API change, tender module change, admin dashboard change, or public website template change.
---

# Markest Test Update

Use this skill as the fixed road map for updating the Markest test environment from the local workspace. The live production system must remain untouched.

## Red Lines

- Work from local workspace: `C:\Users\Fatih\Desktop\new\markest-local\propturk`.
- Deploy only to the test app path: `/var/www/html/markest-test`.
- Never write to live app path: `/var/www/html/propturk`.
- Never use the live database for test work.
- Never store server passwords, API tokens, or newly generated API tokens in files.
- Before a broad deploy, take test-site file and DB backups.
- If an HTTP 500, missing asset, empty listing, or migration issue appears after deploy, pause and diagnose before continuing.

## Known Test/Live Separation

Test site:
- Domain: `https://test.markest.com.tr`
- App path: `/var/www/html/markest-test`
- Env: `APP_ENV=staging`
- URL: `APP_URL=https://test.markest.com.tr`
- DB: `markest_test`
- DB user: `markest_test_user`
- PHP runtime: `php8.2`
- Apache vhost: `/etc/apache2/sites-enabled/000-test.markest.com.tr.conf`
- PHP-FPM socket: `/run/php/php8.2-fpm.sock`

Live site:
- Domain: `https://markest.com.tr`
- App path: `/var/www/html/propturk`
- Env: `APP_ENV=production`
- DB: `propturk`
- Do not modify this path or database during test updates.

Important behavior:
- `test.markest.com.tr` must behave like a platform test domain, not like a bank subdomain.
- In `DetectSubDomain`, `test` and `www` should resolve to no bank subdomain.
- Bank-specific subdomain filtering should still work for real bank subdomains.

## Local Preflight

Run these before deploy:

```powershell
git status --short
php -l app\Http\Middleware\DetectSubDomain.php
php artisan route:list
php artisan migrate:status
vendor\bin\phpunit --filter ExternalListingApiTest
vendor\bin\phpunit --filter LocalBaselinePageTest
```

For frontend/template changes, also check the target pages locally when possible:
- `/`
- `/search?tender_status=2`
- `/search?tender_status=1`
- `/login`
- relevant admin page

## Backup Before Broad Deploy

Create a timestamped folder under:

```bash
/home/propturk/markest-backups/pre-deploy-YYYYMMDD-HHMMSS
```

Back up only the test app and test DB:

```bash
tar -czf /home/propturk/markest-backups/pre-deploy-YYYYMMDD-HHMMSS/markest-test-files.tar.gz -C /var/www/html markest-test
mysqldump --single-transaction markest_test | gzip > /home/propturk/markest-backups/pre-deploy-YYYYMMDD-HHMMSS/markest-test-db.sql.gz
```

Do not back up or dump live DB unless the user explicitly asks for live backup.

## Deploy Strategy

Prefer release-folder deployment for broad changes:

1. Create local tarball excluding:
   - `.git`
   - `.env`
   - `vendor`
   - `node_modules`
   - local `storage`
   - `bootstrap/cache/*.php`
   - `public/storage`
   - local cert/key/test artifacts
2. Upload archive to `/home/propturk/deploy/`.
3. Extract to `/var/www/html/markest-test-release-YYYYMMDD-HHMMSS`.
4. Copy current test `.env` into the release.
5. Copy current test `storage` and `public/storage` link/content as needed.
6. Run composer with PHP 8.2:

```bash
cd /var/www/html/markest-test-release-YYYYMMDD-HHMMSS
php8.2 $(which composer) install --no-dev --optimize-autoloader --no-interaction --no-progress
php8.2 artisan migrate --force
php8.2 artisan optimize:clear
php8.2 artisan config:cache
php8.2 artisan view:cache
php8.2 artisan route:list >/tmp/markest-test-route-list.txt
```

7. Atomically switch:

```bash
mv /var/www/html/markest-test /var/www/html/markest-test-prev-YYYYMMDD-HHMMSS
mv /var/www/html/markest-test-release-YYYYMMDD-HHMMSS /var/www/html/markest-test
cd /var/www/html/markest-test
php8.2 artisan optimize:clear
php8.2 artisan config:cache
php8.2 artisan view:cache
php8.2 artisan storage:link || true
chmod -R ug+rwX storage bootstrap/cache
```

For a tiny hotfix, upload only the touched file to `/var/www/html/markest-test/...`, then clear/cache views and config.

## Post-Deploy Required Checks

Environment:

```bash
cd /var/www/html/markest-test
pwd
php8.2 -r 'echo PHP_VERSION, PHP_EOL;'
php8.2 artisan --version
grep -E '^(APP_ENV|APP_URL|DB_DATABASE|DB_USERNAME)=' .env
php8.2 artisan migrate:status
```

HTTP:

```powershell
curl.exe -k -I -s https://test.markest.com.tr/
curl.exe -k -I -s "https://test.markest.com.tr/search?tender_status=2"
curl.exe -k -I -s "https://test.markest.com.tr/search?tender_status=1"
curl.exe -k -I -s https://test.markest.com.tr/login
curl.exe -k -I -s https://test.markest.com.tr/admin/home
curl.exe -k -I -s https://test.markest.com.tr/api/v1/listings
```

Expected:
- Public pages return `200`.
- Admin pages redirect when not logged in.
- API without token returns `401`, not `500`.

Listing checks:
- Homepage must show more than one listing when test DB has many listings.
- Homepage should include multiple banks, not only `code=test`.
- Search `tender_status=2` should show waiting listings when data exists.
- Search `tender_status=1` should not fail; it may show fewer records if only future live auctions match.
- A known non-test-bank listing detail must return `200` on test domain after platform-domain fix.

API checks:
- Create a temporary API client in test DB only.
- Call `GET https://test.markest.com.tr/api/v1/listings?status=active&per_page=5` with bearer token.
- Expect `200`, `success=true`, and `meta.total` matching active tender count.
- Delete the temporary API client after test.
- Do not print or save the plain token in project files.

Visual checks:

```powershell
npx --yes playwright screenshot --viewport-size=1440,1000 --wait-for-timeout=2500 https://test.markest.com.tr/ storage/app/deploy-e2e/test-home.png
npx --yes playwright screenshot --viewport-size=390,900 --wait-for-timeout=2500 https://test.markest.com.tr/ storage/app/deploy-e2e/test-home-mobile.png
npx --yes playwright screenshot --viewport-size=1440,1000 --wait-for-timeout=2500 "https://test.markest.com.tr/search?tender_status=2" storage/app/deploy-e2e/test-search.png
```

Inspect screenshots for:
- CSS/assets loaded.
- Hero/search bar aligned.
- Listing cards visible and not overflowing.
- Slider arrows visible.
- Mobile layout readable.

Logs:

```bash
cd /var/www/html/markest-test
tail -120 storage/logs/laravel.log | grep -E 'staging.ERROR|production.ERROR|Exception' || true
```

Ignore log entries caused by Codex's own failed exploratory commands only if they are clearly from manual tinker/schema mistakes and not user HTTP traffic.

## Rollback

Use rollback only if test deploy breaks critical behavior:

```bash
mv /var/www/html/markest-test /var/www/html/markest-test-bad-YYYYMMDD-HHMMSS
mv /var/www/html/markest-test-prev-YYYYMMDD-HHMMSS /var/www/html/markest-test
cd /var/www/html/markest-test
php8.2 artisan optimize:clear
php8.2 artisan config:cache
php8.2 artisan view:cache
```

After rollback, re-run public page, login, API unauthorized, and listing checks.

## Final Report Format

Report briefly:
- What was changed.
- Whether live production was untouched.
- Backup path if a backup was created.
- Test domain deploy path.
- Laravel/PHP version seen on test.
- Migration status.
- HTTP results.
- API result.
- Listing/homepage result.
- Screenshots created.
- Any remaining risk or manual check needed.
