Files
insights/bin/dev-open-when-ready
zeekay 10e6fec4c0 debrand: the brand token is INSIGHTS_, and a wrong one stops the container
The rule table mapped HOG_ -> FN_ ahead of any POSTHOG rule, so POSTHOG_FOO
split into POST + HOG_ and came out POSTFN_FOO. Nothing sets that. The live
pods set INSIGHTS_SKIP_MIGRATION_CHECKS, which bin/migrate-check reads on the
container entrypoint, so the misspelling does not degrade a feature -- it runs
migrate --check against a database whose history this tree does not share and
the container never starts.

Both replacements are measured against the shipped tree rather than chosen:
every HOG_ name with a counterpart there is spelled INSIGHTS_ (HOG_QL ->
INSIGHTS_QL, HOG_FUNCTION_TEMPLATES -> INSIGHTS_FUNCTION_TEMPLATES, 12 of 12
determinate cases), and FN_ appears in it nowhere. Upstream carries 95 HOG_
tokens and zero FN_ ones, so repairing FN_ back out is exactly the inverse of
the bad rule and cannot collide with an upstream name.

The rule is fixed for the next convergence, and the tree it already produced is
repaired in the same commit -- the codemod is idempotent against its own output,
so it cannot undo this itself.
2026-08-01 17:42:28 -07:00

60 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Open a URL in the browser once its server is listening — from OUTSIDE the dev
# sandbox.
#
# Storybook (and other web procs) auto-open via `open`, but the macOS Seatbelt
# sandbox blocks that: the open → LaunchServices path reads $HOME, which the
# profile denies. Rather than widen the profile (which would hand untrusted
# dependency code a general app/URL launcher), the devenv generator peels this
# helper out to run unsandboxed (see _SANDBOX_UNSANDBOXED_PREFIXES). It backgrounds
# a poller and returns immediately, so the sandboxed server starts right after,
# then the poller fires a single fixed `open <url>` once the port answers.
#
# Usage: bin/dev-open-when-ready <url> # e.g. http://localhost:6006
#
# No-op (exit 0) in CI / under Insights Desktop, or when no opener is available.
set -euo pipefail
url="${1:?bin/dev-open-when-ready: expected a URL as the first argument}"
# Don't pop a browser in automated/headless contexts.
if [[ -n "${CI:-}" || -n "${INSIGHTS_CODE:-}" ]]; then
exit 0
fi
# Pick a platform opener; bail quietly if none (e.g. headless Linux).
if [[ "$(uname -s)" == "Darwin" ]] && command -v open >/dev/null 2>&1; then
opener="open"
elif command -v xdg-open >/dev/null 2>&1; then
opener="xdg-open"
else
exit 0
fi
# Derive host:port from the URL (strip scheme + path; default by scheme).
case "$url" in
https://*) _defport=443 ;;
*) _defport=80 ;;
esac
_hostport="${url#*://}"
_hostport="${_hostport%%/*}"
host="${_hostport%%:*}"
port="${_hostport##*:}"
[[ "$port" == "$host" ]] && port="$_defport" # no explicit port in the URL
# Background poller: wait (bounded) for the port to accept a connection, then open
# once. Detached so the caller returns immediately (the sandboxed server starts
# right after); the deadline keeps it from lingering if the server never comes up.
(
deadline=$(($(date +%s) + 180))
until (exec 3<>"/dev/tcp/$host/$port") 2>/dev/null; do
if (($(date +%s) >= deadline)); then exit 0; fi
sleep 0.5
done
"$opener" "$url" >/dev/null 2>&1 || true
) &
disown 2>/dev/null || true
exit 0