hot-dev: isolate mock data dir so mock/real switching is clean
Some checks are pending
Build and Test / Secret Scan (push) Waiting to run
Build and Test / Frontend & Backend (push) Waiting to run

Mock and real mode shared tmp/dev-config, so toggling between them left
residue each way: real connections (and a live local agent) showed in
Settings during mock, and mock-cluster alerts lingered in real mode.
The toggle script had an isolation flag but it only reached the
standalone runtime, never managed-hot-dev.

hot-dev.sh now routes mock mode to tmp/mock-data and real mode to
tmp/dev-config, choosing the dir from the canonical PULSE_MOCK_MODE flag
that toggle-mock writes to tmp/dev-config/.env. The flag is read from
that file authoritatively rather than from the environment, because a
stale PULSE_MOCK_MODE exported into the hot-dev supervisor from a prior
mock run would otherwise keep real mode pinned to the mock dir.

toggle-mock status now reports the isolated mock dir for hot-dev
runtimes so it matches what the backend actually uses.

Verified a full round trip: real -> dev-config (real connections only),
mock -> mock-data (mock data only, no real bleed), real -> dev-config
(no mock-cluster residue). Trade-off: real metrics history no longer
accrues during mock UI sessions, which is the right call for clean
dev switching.
This commit is contained in:
rcourtman 2026-05-30 19:28:25 +01:00
parent 4f52ef88da
commit af358ef365
2 changed files with 39 additions and 9 deletions

View file

@ -356,18 +356,38 @@ PULSE_AUTH_PASS="$(hot_dev_resolve_auth_pass)"
export FRONTEND_PORT PULSE_DEV_API_PORT PORT PULSE_DEV ALLOW_ADMIN_BYPASS PULSE_AUTH_USER PULSE_AUTH_PASS LOG_LEVEL PULSE_DEV_DISABLE_BACKGROUND_AI
# Data Directory Setup
# Keep one persistent data directory in both mock and real modes so real
# metrics history continues to accumulate while mock UI mode is active.
# Mock and real mode use SEPARATE data directories so switching between them
# (scripts/toggle-mock.sh on|off) is clean in both directions: mock data never
# leaks into the real connection ledger, and real connections/alerts never show
# up under mock. The canonical PULSE_MOCK_MODE flag is persisted to
# tmp/dev-config/.env by toggle-mock, so read it before choosing the directory.
if [[ -n ${PULSE_DATA_DIR:-} ]]; then
log_info "Using preconfigured data directory: ${PULSE_DATA_DIR}"
elif [[ ${HOT_DEV_USE_PROD_DATA:-false} == "true" ]]; then
export PULSE_DATA_DIR=/etc/pulse
log_info "HOT_DEV_USE_PROD_DATA=true using production data directory: ${PULSE_DATA_DIR}"
else
DEV_CONFIG_DIR="${ROOT_DIR}/tmp/dev-config"
mkdir -p "$DEV_CONFIG_DIR"
export PULSE_DATA_DIR="${DEV_CONFIG_DIR}"
log_info "Using dev config directory: ${PULSE_DATA_DIR}"
# Read the canonical mock flag from tmp/dev-config/.env, which toggle-mock
# writes authoritatively on every switch. A stale PULSE_MOCK_MODE exported
# into the environment (e.g. inherited by the hot-dev supervisor from a prior
# mock run) must NOT win here, or real mode would keep reading the mock dir.
HOT_DEV_MOCK_FLAG=""
if [[ -f "${ROOT_DIR}/tmp/dev-config/.env" ]]; then
HOT_DEV_MOCK_FLAG="$(grep -E '^[[:space:]]*PULSE_MOCK_MODE=' "${ROOT_DIR}/tmp/dev-config/.env" | tail -1 | cut -d= -f2 | tr -dc 'a-z')"
fi
if [[ -z "${HOT_DEV_MOCK_FLAG}" ]]; then
HOT_DEV_MOCK_FLAG="${PULSE_MOCK_MODE:-}"
fi
if [[ "${HOT_DEV_MOCK_FLAG}" == "true" ]]; then
export PULSE_DATA_DIR="${ROOT_DIR}/tmp/mock-data"
mkdir -p "$PULSE_DATA_DIR"
log_info "Mock mode: using isolated mock data directory: ${PULSE_DATA_DIR}"
else
DEV_CONFIG_DIR="${ROOT_DIR}/tmp/dev-config"
mkdir -p "$DEV_CONFIG_DIR"
export PULSE_DATA_DIR="${DEV_CONFIG_DIR}"
log_info "Using dev config directory: ${PULSE_DATA_DIR}"
fi
fi
sync_runtime_auth_env_overrides
@ -380,7 +400,7 @@ if [[ "${PULSE_DATA_DIR}" == "${ROOT_DIR}/tmp/dev-config" ]] && [[ ${PULSE_MOCK_
fi
if [[ ${PULSE_MOCK_MODE:-false} == "true" ]]; then
log_info "Mock mode enabled: retaining shared data directory (${PULSE_DATA_DIR}) to preserve real history"
log_info "Mock mode enabled (isolated data directory: ${PULSE_DATA_DIR})"
TOTAL_GUESTS=$((${PULSE_MOCK_NODES:-3} * (${PULSE_MOCK_VMS_PER_NODE:-3} + ${PULSE_MOCK_LXCS_PER_NODE:-3})))
echo "Mock mode ENABLED with ${PULSE_MOCK_NODES:-3} nodes (${TOTAL_GUESTS} total guests)"
fi

View file

@ -745,8 +745,18 @@ show_status() {
echo "Mock Data Mode Control for Pulse"
echo ""
local status_data_dir="$DEV_DATA_DIR"
if [[ "${PULSE_MOCK_MODE:-false}" == "true" ]] && use_isolated_mock_data_dir; then
status_data_dir="$MOCK_DATA_DIR"
if [[ "${PULSE_MOCK_MODE:-false}" == "true" ]]; then
# hot-dev runtimes isolate mock data into MOCK_DATA_DIR unconditionally
# (see scripts/hot-dev.sh); the standalone runtime only isolates when
# PULSE_TOGGLE_ISOLATE_MOCK_DATA is set.
case "${runtime_mode}" in
managed-hot-dev | hot-dev | systemd-hot-dev)
status_data_dir="$MOCK_DATA_DIR"
;;
*)
use_isolated_mock_data_dir && status_data_dir="$MOCK_DATA_DIR"
;;
esac
fi
if [[ "${PULSE_MOCK_MODE:-false}" == "true" ]]; then
echo -e "${GREEN}Mock Mode: ENABLED${NC}"