# Instar v0.12.23 — WhatsApp Setup Bug Fixes & Regression Tests

## What Changed

Three critical WhatsApp setup bugs fixed with comprehensive regression tests:

1. **Baileys peer dependency resolution** — Replaced `require.resolve()` with dynamic `import()` for Baileys detection. `require.resolve()` fails in npx contexts because it resolves relative to the npx cache, not the user's project. Now tries both v6 (`@whiskeysockets/baileys`) and v7 (`baileys`) package names everywhere.

2. **Baileys 405 infinite reconnect loop** — When WhatsApp returns HTTP 405 (protocol version mismatch), the backend now logs a clear error with upgrade instructions and does NOT attempt to reconnect. Previously this caused an infinite reconnect loop since 405 errors never resolve by retrying.

3. **Dashboard QR polling silent failures** — The dashboard QR code polling now surfaces errors instead of silently returning null. Handles 401/403 with authentication failure messages, other HTTP errors with status codes, and network errors with connection failure messages.

Added 22 regression tests covering all three issues.

## What to Tell Your User

- **WhatsApp setup reliability**: "WhatsApp pairing should work much more smoothly now — we fixed several issues that could cause the setup to fail silently or get stuck in loops."

## Summary of New Capabilities

| Capability | How to Use |
|-----------|-----------|
| Improved Baileys detection | Automatic — works in npx and global install contexts |
| 405 error handling | Automatic — clear error message instead of infinite retry |
| Dashboard QR error visibility | Automatic — errors now shown in dashboard UI |

## Files Changed

- `src/commands/whatsapp.ts` — New `isBaileysInstalled()` helper using dynamic import
- `src/messaging/backends/BaileysBackend.ts` — v6/v7 import fallback + 405 error handling
- `src/messaging/shared/EncryptedAuthStore.ts` — v6/v7 import fallback
- `dashboard/index.html` — QR polling error surfacing
- `src/server/AgentServer.ts` — Warning log for missing dashboard auth config
- `tests/unit/whatsapp-setup-issues.test.ts` — 22 regression tests covering all 3 issues

## How to Upgrade

Updates are applied automatically via the AutoUpdater's shadow install mechanism. For manual upgrade:

```bash
npx instar@latest
```

No configuration changes required. All fixes are internal improvements to error handling and dependency resolution.
