Pulse/docs/development/MOCK_MODE.md
rcourtman 6eb1a10d9b Refactor: Code cleanup and localStorage consolidation
This commit includes comprehensive codebase cleanup and refactoring:

## Code Cleanup
- Remove dead TypeScript code (types/monitoring.ts - 194 lines duplicate)
- Remove unused Go functions (GetClusterNodes, MigratePassword, GetClusterHealthInfo)
- Clean up commented-out code blocks across multiple files
- Remove unused TypeScript exports (helpTextClass, private tag color helpers)
- Delete obsolete test files and components

## localStorage Consolidation
- Centralize all storage keys into STORAGE_KEYS constant
- Update 5 files to use centralized keys:
  * utils/apiClient.ts (AUTH, LEGACY_TOKEN)
  * components/Dashboard/Dashboard.tsx (GUEST_METADATA)
  * components/Docker/DockerHosts.tsx (DOCKER_METADATA)
  * App.tsx (PLATFORMS_SEEN)
  * stores/updates.ts (UPDATES)
- Benefits: Single source of truth, prevents typos, better maintainability

## Previous Work Committed
- Docker monitoring improvements and disk metrics
- Security enhancements and setup fixes
- API refactoring and cleanup
- Documentation updates
- Build system improvements

## Testing
- All frontend tests pass (29 tests)
- All Go tests pass (15 packages)
- Production build successful
- Zero breaking changes

Total: 186 files changed, 5825 insertions(+), 11602 deletions(-)
2025-11-04 21:50:46 +00:00

106 lines
3.2 KiB
Markdown

# Mock Mode Development Guide
Pulse ships with a mock data pipeline so you can iterate on UI and backend
changes without touching real infrastructure. This guide collects everything you
need to know about running in mock mode during development.
---
## Why Mock Mode?
- Exercise dashboards, alert timelines, and charts with predictable sample data.
- Reproduce edge cases (offline nodes, noisy containers, backup failures) by
tweaking configuration values rather than waiting for production incidents.
- Swap between synthetic and live data without rebuilding services.
---
## Starting the Dev Stack
```bash
# Launch backend + frontend with hot reload
./scripts/hot-dev.sh
```
The script exposes:
- Frontend: `http://localhost:7655` (Vite hot module reload)
- Backend API: `http://localhost:7656`
---
## Toggling Mock Data
The npm helpers and `toggle-mock.sh` wrapper point the backend at different
`.env` files and restart the relevant services automatically.
```bash
npm run mock:on # Enable mock mode
npm run mock:off # Return to real data
npm run mock:status # Display current state
npm run mock:edit # Open mock.env in $EDITOR
```
Equivalent shell invocations:
```bash
./scripts/toggle-mock.sh on
./scripts/toggle-mock.sh off
./scripts/toggle-mock.sh status
```
When switching:
- `mock.env` (or `mock.env.local`) feeds configuration values to the backend.
- `PULSE_DATA_DIR` swaps between `/opt/pulse/tmp/mock-data` (synthetic) and
`/etc/pulse` (real data) so test credentials never mix with production ones.
- The backend process restarts; the frontend stays hot-reloading.
---
## Customising Mock Fixtures
`mock.env` exposes the knobs most developers care about:
```bash
PULSE_MOCK_MODE=false # Enable/disable mock mode
PULSE_MOCK_NODES=7 # Number of synthetic nodes
PULSE_MOCK_VMS_PER_NODE=5 # Average VM count per node
PULSE_MOCK_LXCS_PER_NODE=8 # Average container count per node
PULSE_MOCK_RANDOM_METRICS=true # Toggle metric jitter
PULSE_MOCK_STOPPED_PERCENT=20 # Percentage of guests stopped/offline
```
Create `mock.env.local` for personal tweaks that should not be committed:
```bash
cp mock.env mock.env.local
$EDITOR mock.env.local
```
The toggle script prioritises `.local` files, falling back to the shared
defaults when none are present.
---
## Troubleshooting
- **Backend did not restart:** flip mock mode off/on again (`npm run mock:off`,
then `npm run mock:on`) to force a reload.
- **Ports already in use:** confirm nothing else is listening on `7655`/`7656`
(`lsof -i :7655` / `lsof -i :7656`) and kill stray processes.
- **Data feels stale:** delete `/opt/pulse/tmp/mock-data` and toggle mock mode
back on to regenerate fixtures.
---
## Limitations
- Mock data focuses on happy-path flows; use real Proxmox/PBS environments
before shipping changes that touch API integrations.
- Webhook payloads are synthetically generated and omit provider-specific
quirks—test with real channels for production rollouts.
- Encrypt/decrypt flows still use the local crypto stack; do not treat mock mode
as a sandbox for experimenting with credential formats.
For more advanced scenarios, inspect `scripts/hot-dev.sh` and the mock seeders
under `internal/mock` for additional entry points.