Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Route mock toggle npm scripts through toggle-mock.sh

rcourtman3a24d9694f3b
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index da02498604..43f6f90e01 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -2341,6 +2341,18 @@ local dev path, including explicit status, log, stop, backend-restart, and
verification wrappers, instead of requiring developers to remember
lane-specific shell paths or continue discovering the runtime through a stale
unmanaged `5173` process by accident.
+That same repo-root entry surface owns the mock-mode controls. The
+`mock:on`, `mock:off`, `mock:status`, and `mock:edit` wrappers in
+`package.json` must delegate to `scripts/toggle-mock.sh`, which is the single
+authority for the canonical `PULSE_MOCK_MODE` flag in `tmp/dev-config/.env`.
+They may not reimplement the flag write inline. An inline rewrite targets the
+repo-root `.env`, which `scripts/hot-dev.sh` does not consult when choosing
+the data directory, so the wrapper silently fails to switch modes while
+leaving the operator believing it worked. Inline `sed -i` rewrites are also
+GNU-only and fail on the default macOS BSD `sed`, and an appending fallback
+then accumulates contradictory duplicate flag lines on every invocation.
+Any mock control advertised by the `scripts/hot-dev.sh` startup banner must
+exist as a wrapper in `package.json`.
That same canonical dev-entry boundary also includes the frontend workspace
package and developer health helper. `frontend-modern/package.json` may not
advertise raw `vite` as the default `dev` command, and `scripts/dev-check.sh`
diff --git a/package.json b/package.json
index 877e38cb93..0fc1d10184 100644
--- a/package.json
+++ b/package.json
@@ -23,8 +23,10 @@
"dev:foreground:lab": "PULSE_DEV_LAB_AGENTS=true ./scripts/hot-dev.sh",
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "husky",
- "mock:on": "sed -i 's/PULSE_MOCK_MODE=.*/PULSE_MOCK_MODE=true/' .env || echo 'PULSE_MOCK_MODE=true' >> .env",
- "mock:off": "sed -i 's/PULSE_MOCK_MODE=.*/PULSE_MOCK_MODE=false/' .env || echo 'PULSE_MOCK_MODE=false' >> .env"
+ "mock:on": "./scripts/toggle-mock.sh on",
+ "mock:off": "./scripts/toggle-mock.sh off",
+ "mock:status": "./scripts/toggle-mock.sh status",
+ "mock:edit": "./scripts/toggle-mock.sh edit"
},
"repository": {
"type": "git",
diff --git a/scripts/tests/test-toggle-mock.sh b/scripts/tests/test-toggle-mock.sh
index 1d175c2946..5d283b824d 100755
--- a/scripts/tests/test-toggle-mock.sh
+++ b/scripts/tests/test-toggle-mock.sh
@@ -289,6 +289,42 @@ test_set_mock_mode_does_not_recreate_legacy_sidecars() {
assert_file_absent "set_mock_mode does not recreate runtime legacy mock sidecar" "${state}/runtime/mock.env"
}
+test_package_json_mock_wrappers_delegate_to_toggle_mock() {
+ local script name value
+ for name in mock:on mock:off mock:status mock:edit; do
+ value="$(node -e '
+ const pkg = require(process.argv[1]);
+ process.stdout.write((pkg.scripts || {})[process.argv[2]] || "");
+ ' "${ROOT_DIR}/package.json" "${name}")"
+
+ assert_contains "package.json ${name} delegates to toggle-mock.sh" \
+ "${value}" "scripts/toggle-mock.sh"
+
+ # An inline flag rewrite targets the repo-root .env, which hot-dev.sh does
+ # not consult, and GNU `sed -i` fails outright on the default macOS BSD sed.
+ if [[ "${value}" == *"PULSE_MOCK_MODE="* || "${value}" == *"sed -i"* ]]; then
+ echo "[FAIL] package.json ${name} must not rewrite the mock flag inline" >&2
+ echo "Got: ${value}" >&2
+ ((failures++))
+ else
+ echo "[PASS] package.json ${name} does not rewrite the mock flag inline"
+ fi
+ done
+
+ # Anything the hot-dev startup banner tells operators to run must exist.
+ while read -r script; do
+ [[ -n "${script}" ]] || continue
+ value="$(node -e '
+ const pkg = require(process.argv[1]);
+ process.stdout.write((pkg.scripts || {})[process.argv[2]] === undefined ? "" : "present");
+ ' "${ROOT_DIR}/package.json" "${script}")"
+
+ assert_contains "hot-dev banner advertises existing npm script ${script}" \
+ "${value}" "present"
+ done < <(grep -oE 'npm run (mock:[a-z]+)' "${ROOT_DIR}/scripts/hot-dev.sh" \
+ | sed 's/^npm run //' | sort -u)
+}
+
main() {
test_detects_managed_hot_dev_runtime
test_managed_hot_dev_start_uses_takeover
@@ -297,6 +333,7 @@ main() {
test_ensure_mock_env_file_seeds_canonical_demo_defaults
test_ensure_mock_env_file_migrates_legacy_sidecar
test_set_mock_mode_does_not_recreate_legacy_sidecars
+ test_package_json_mock_wrappers_delegate_to_toggle_mock
if (( failures > 0 )); then
echo "Total failures: ${failures}" >&2