:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(devenv): single-source mprocs shell generation (#73644)
Phil Haack5a0a63c00184
diff --git a/bin/mprocs-e2e.yaml b/bin/mprocs-e2e.yamlindex 0db0f6ed02c7..9d12ee9b7290 100644--- a/bin/mprocs-e2e.yaml+++ b/bin/mprocs-e2e.yaml@@ -42,7 +42,7 @@ procs:E2E_TESTING: '1'docker-compose:- shell: 'docker compose -f docker-compose.dev.yml -f docker-compose.profiles.yml up --pull always -d && docker compose -f docker-compose.dev.yml -f docker-compose.profiles.yml --profile ingestion up -d personhog-replica personhog-router && echo "docker-compose ready" && docker compose -f docker-compose.dev.yml -f docker-compose.profiles.yml logs --tail=100 -f'+ shell: 'docker compose -p posthog -f docker-compose.dev.yml -f docker-compose.profiles.yml up --pull always -d && docker compose -p posthog -f docker-compose.dev.yml -f docker-compose.profiles.yml --profile ingestion up -d personhog-replica personhog-router && echo "docker-compose ready" && docker compose -p posthog -f docker-compose.dev.yml -f docker-compose.profiles.yml logs --tail=100 -f'ready_pattern: 'docker-compose ready'reset-db:diff --git a/bin/mprocs.yaml b/bin/mprocs.yamlindex b51dd5fd29a9..2e01e4d85818 100755--- a/bin/mprocs.yaml+++ b/bin/mprocs.yaml@@ -245,11 +245,11 @@ procs:layer: Processingtech: Python+ # The shell below is generated by build_static_docker_compose_shell in+ # tools/hogli-commands/hogli_commands/devenv/generator.py. Edit it there and run+ # `hogli dev:regenerate-mprocs`; CI pre-flight fails if the two drift apart.docker-compose:- # Keep the sandbox guard and failure message in sync with- # _generate_docker_compose_config in- # tools/hogli-commands/hogli_commands/devenv/generator.py (the generated config).- shell: 'if [ "${POSTHOG_SANDBOX:-}" = "1" ]; then echo "Sandbox: infra managed by docker compose externally" && echo "docker-compose ready" && sleep infinity; else docker compose -f docker-compose.dev.yml up --pull always -d || { echo "docker compose up failed (see the error above). A common cause: another stack or process holding a required port (see the pre-flight output from bin/start). Inspect with: docker ps --all"; exit 1; } && echo "docker-compose ready" && docker compose -f docker-compose.dev.yml logs --tail=100 -f; fi'+ shell: 'if [ "${POSTHOG_SANDBOX:-}" = "1" ]; then echo "Sandbox: infra managed by docker compose externally" && echo "docker-compose ready" && sleep infinity; else docker compose -p posthog -f docker-compose.dev.yml -f docker-compose.profiles.yml --profile dev_tools --profile etcd --profile localstack --profile observability --profile replay --profile temporal up --pull always -d || { echo "docker compose up failed (see the error above). A common cause: another stack or process holding a required port (see the pre-flight output from bin/start). Inspect with: docker ps --all"; exit 1; } && echo "docker-compose ready" && docker compose -p posthog -f docker-compose.dev.yml -f docker-compose.profiles.yml --profile dev_tools --profile etcd --profile localstack --profile observability --profile replay --profile temporal logs --tail=100 -f; fi'capability: core_infraready_pattern: 'docker-compose ready'groups:diff --git a/hogli.yaml b/hogli.yamlindex 3d08a50fc457..259965ed0b55 100644--- a/hogli.yaml+++ b/hogli.yaml@@ -238,6 +238,9 @@ devenv:dev:intents:click: hogli_commands.devenv.cli:dev_intentsdescription: List available intents+ dev:regenerate-mprocs:+ click: hogli_commands.devenv.cli:dev_regenerate_mprocs+ description: Sync bin/mprocs.yaml and bin/mprocs-e2e.yaml's docker-compose shells with generator.pydev:list-units:click: hogli_commands.devenv.cli:dev_list_unitsdescription: List autostart units for given intents (used by phrocs)diff --git a/tools/hogli-commands/hogli_commands/ci_preflight.py b/tools/hogli-commands/hogli_commands/ci_preflight.pyindex 4f6242c368f3..edcc4c74e8d6 100644--- a/tools/hogli-commands/hogli_commands/ci_preflight.py+++ b/tools/hogli-commands/hogli_commands/ci_preflight.py@@ -45,6 +45,7 @@ from hogli_commands.build import (_match_commands,)from hogli_commands.change_detection import changed_files, matches_globs+from hogli_commands.devenv.generator import TRACKED_MPROCS_FILESRequirement = Literal["node", "stack", "clickhouse"]@@ -138,6 +139,17 @@ DIFF_CHECKS: list[DiffCheck] = [triggers=[".github/workflows/*.yml", ".github/workflows/*.yaml"],verify=["hogli", "lint:workflows"],),+ DiffCheck(+ key="mprocs",+ label="bin/mprocs*.yaml docker-compose shell out of sync with generator.py",+ # From TRACKED_MPROCS_FILES so preflight can't drift on which files need a regen.+ triggers=[+ "tools/hogli-commands/hogli_commands/devenv/generator.py",+ *(t.name for t in TRACKED_MPROCS_FILES),+ ],+ verify=["hogli", "dev:regenerate-mprocs", "--check"],+ fix=["hogli", "dev:regenerate-mprocs"],+ ),DiffCheck(key="openapi",label="OpenAPI types out of date (frontend/MCP drift)",diff --git a/tools/hogli-commands/hogli_commands/devenv/cli.py b/tools/hogli-commands/hogli_commands/devenv/cli.pyindex 9beddba51bda..ca86e81e94ad 100644--- a/tools/hogli-commands/hogli_commands/devenv/cli.py+++ b/tools/hogli-commands/hogli_commands/devenv/cli.py@@ -8,11 +8,14 @@ from __future__ import annotationsimport clickfrom .generator import (+ TRACKED_MPROCS_FILES,DevenvConfig,MprocsGenerator,build_docker_compose_command,get_generated_mprocs_path,+ is_mprocs_shell_up_to_date,load_devenv_config,+ regenerate_mprocs_shell,)from .registry import create_mprocs_registryfrom .resolver import IntentResolver, load_intent_map@@ -302,6 +305,28 @@ def dev_setup(log_to_files: bool) -> None:run_setup_wizard(intent_map, log_to_files=log_to_files)+ name="dev:regenerate-mprocs",+ help="Sync bin/mprocs.yaml and bin/mprocs-e2e.yaml's docker-compose shells with generator.py",+)[email protected]("--check", is_flag=True, help="Report staleness without rewriting the files; exit 1 if any are stale")+def dev_regenerate_mprocs(check: bool) -> None:+ """Write each TRACKED_MPROCS_FILES entry's built shell into its file."""+ if check:+ stale = [t for t in TRACKED_MPROCS_FILES if not is_mprocs_shell_up_to_date(t.path, t.build_shell())]+ if not stale:+ click.echo(f"{', '.join(t.name for t in TRACKED_MPROCS_FILES)} are up to date")+ return+ for target in stale:+ click.echo(f"{target.path} is stale", err=True)+ click.echo("run `hogli dev:regenerate-mprocs` to fix", err=True)+ raise SystemExit(1)++ for target in TRACKED_MPROCS_FILES:+ rewrote = regenerate_mprocs_shell(target.path, target.build_shell())+ click.echo(f"Regenerated {target.path}" if rewrote else f"{target.path} was already up to date")++def _get_docker_profiles_from_config() -> list[str]:"""Get docker profiles from saved intent config."""try:diff --git a/tools/hogli-commands/hogli_commands/devenv/generator.py b/tools/hogli-commands/hogli_commands/devenv/generator.pyindex b4a8f18d3c2a..10870c5851ad 100644--- a/tools/hogli-commands/hogli_commands/devenv/generator.py+++ b/tools/hogli-commands/hogli_commands/devenv/generator.py@@ -12,12 +12,16 @@ import sysimport shleximport shutilfrom abc import ABC, abstractmethod+from collections.abc import Callable+from dataclasses import dataclassfrom pathlib import Pathfrom typing import TYPE_CHECKING, Anyimport yamlfrom pydantic import BaseModel+from .registry import create_mprocs_registry, find_repo_file+if TYPE_CHECKING:from .registry import ProcessRegistryfrom .resolver import ResolvedEnvironment@@ -70,6 +74,104 @@ def build_docker_compose_command(profiles: list[str], action: str = "up -d") ->return f"{base} {action}"+# The proc's ready_pattern in bin/mprocs.yaml and bin/mprocs-e2e.yaml must match+# this literal, or mprocs waits forever for a signal that never comes.+_READY_MARKER = "docker-compose ready"+++def _build_docker_compose_shell(profiles: list[str]) -> str:+ """Sandboxes have no docker CLI, so the shell short-circuits instead of failing on `docker compose`."""+ up_cmd = build_docker_compose_command(profiles, "up --pull always -d")+ logs_cmd = build_docker_compose_command(profiles, "logs --tail=100 -f")+ sandbox_cmd = (+ f'echo "Sandbox: infra managed by docker compose externally" && echo "{_READY_MARKER}" && sleep infinity'+ )+ # The `exit 1` is load-bearing: without it the `{ ...; }` group exits 0, the `||`+ # is satisfied, and the ready marker fires against a stack that never came up.+ fail_cmd = (+ 'echo "docker compose up failed (see the error above). A common cause: another stack or process '+ 'holding a required port (see the pre-flight output from bin/start). Inspect with: docker ps --all"; '+ "exit 1"+ )+ dev_cmd = f'{up_cmd} || {{ {fail_cmd}; }} && echo "{_READY_MARKER}" && {logs_cmd}'+ return f'if [ "${{POSTHOG_SANDBOX:-}}" = "1" ]; then {sandbox_cmd}; else {dev_cmd}; fi'+++# bin/mprocs.yaml has no intent resolution: every proc in it autostarts, so it+# needs every profile those procs depend on (temporal-worker and+# recording-rasterizer wait on `temporal`; personhog-etcd-init docker-execs+# into `etcd`; session replay needs `replay`) — this reproduces master's+# unprofiled `docker-compose.dev.yml` service set exactly.+_STATIC_MPROCS_PROFILES = ["dev_tools", "etcd", "localstack", "observability", "replay", "temporal"]+++def build_static_docker_compose_shell() -> str:+ """bin/mprocs.yaml's docker-compose shell — every proc autostarts, so every legacy profile is active."""+ return _build_docker_compose_shell(_STATIC_MPROCS_PROFILES)+++def build_e2e_docker_compose_shell() -> str:+ """bin/mprocs-e2e.yaml's docker-compose shell: never sandboxed, plus an explicit+ `up` for personhog-replica/router under the ingestion profile."""+ up_cmd = build_docker_compose_command([], "up --pull always -d")+ personhog_cmd = build_docker_compose_command(["ingestion"], "up -d personhog-replica personhog-router")+ logs_cmd = build_docker_compose_command([], "logs --tail=100 -f")+ return f'{up_cmd} && {personhog_cmd} && echo "{_READY_MARKER}" && {logs_cmd}'+++# Matches the docker-compose proc's `shell:` scalar in a checked-in mprocs YAML+# file (bin/mprocs.yaml or bin/mprocs-e2e.yaml). Anchored on the exact+# indentation/key ordering of that block rather than parsed as YAML, so+# regeneration can rewrite just this one line and leave the rest of the+# hand-maintained file (comments, formatting, other procs) untouched.+_DOCKER_COMPOSE_SHELL_LINE_RE = re.compile(r"(?P<prefix>^ docker-compose:\n shell: )'[^\n]*'$", re.M)+++def is_mprocs_shell_up_to_date(mprocs_path: Path, expected: str) -> bool:+ """Whether mprocs_path's docker-compose proc shell already matches expected."""+ current_shell = create_mprocs_registry(mprocs_path).get_processes()["docker-compose"].shell+ return current_shell == expected+++def regenerate_mprocs_shell(mprocs_path: Path, expected: str) -> bool:+ """Sync mprocs_path's docker-compose proc shell with expected.++ Returns True if the file was rewritten, False if it was already up to date.+ """+ if is_mprocs_shell_up_to_date(mprocs_path, expected):+ return False+ # The entry is single-quoted YAML; a literal `'` would need escaping this+ # substitution doesn't do.+ if "'" in expected:+ raise ValueError("Generated docker-compose shell contains a single quote; update the YAML quoting logic")+ text = mprocs_path.read_text()+ new_text, replaced = _DOCKER_COMPOSE_SHELL_LINE_RE.subn(lambda m: f"{m.group('prefix')}'{expected}'", text, count=1)+ if not replaced:+ raise ValueError(+ f"{mprocs_path}: no docker-compose `shell:` line matched _DOCKER_COMPOSE_SHELL_LINE_RE. "+ "The proc's key order, indentation, or quoting changed; update the pattern."+ )+ mprocs_path.write_text(new_text)+ return True+++@dataclass(frozen=True)+class TrackedMprocsFile:+ """A checked-in mprocs YAML file whose docker-compose proc shell is kept in+ sync with a Python-built string, by `hogli dev:regenerate-mprocs` and the+ ci_preflight "mprocs" check."""++ name: str # repo-relative path, for display and as a preflight trigger glob+ path: Path+ build_shell: Callable[[], str]+++TRACKED_MPROCS_FILES: list[TrackedMprocsFile] = [+ TrackedMprocsFile("bin/mprocs.yaml", find_repo_file("bin/mprocs.yaml"), build_static_docker_compose_shell),+ TrackedMprocsFile("bin/mprocs-e2e.yaml", find_repo_file("bin/mprocs-e2e.yaml"), build_e2e_docker_compose_shell),+]++class ConfigGenerator(ABC):"""Abstract generator for process manager configurations."""@@ -328,26 +430,8 @@ printf ' {gray}Run {reset}{blue}hogli dev:setup{reset}{gray} to tailor this toelse:message = "echo '▶ docker-compose: core services only (configure via: hogli dev:setup)' && "- up_cmd = build_docker_compose_command(profiles, "up --pull always -d")- logs_cmd = build_docker_compose_command(profiles, "logs --tail=100 -f")- # Keep the sandbox guard and failure message in sync with the- # docker-compose proc's shell in bin/mprocs.yaml (the static fallback- # used when hogli is unavailable).- fail_cmd = (- 'echo "docker compose up failed (see the error above). A common cause: another stack or process '- 'holding a required port (see the pre-flight output from bin/start). Inspect with: docker ps --all"; '- "exit 1"- )- sandbox_cmd = (- 'echo "Sandbox: infra managed by docker compose externally" '- '&& echo "docker-compose ready" && sleep infinity'- )- dev_cmd = f"{up_cmd} || {{ {fail_cmd}; }} && echo 'docker-compose ready' && {logs_cmd}"-- # Sandboxes have no docker CLI; without this guard the generated shell- # would fail there and misreport the cause as a port collision.- proc_config["shell"] = f'{message}if [ "${{POSTHOG_SANDBOX:-}}" = "1" ]; then {sandbox_cmd}; else {dev_cmd}; fi'- proc_config["ready_pattern"] = "docker-compose ready"+ proc_config["shell"] = message + _build_docker_compose_shell(profiles)+ proc_config["ready_pattern"] = _READY_MARKERreturn proc_configdef _add_nodejs_capability_groups(diff --git a/tools/hogli-commands/hogli_commands/devenv/registry.py b/tools/hogli-commands/hogli_commands/devenv/registry.pyindex 717b74c763ee..d9b039628ea6 100644--- a/tools/hogli-commands/hogli_commands/devenv/registry.py+++ b/tools/hogli-commands/hogli_commands/devenv/registry.py@@ -120,15 +120,20 @@ class MprocsRegistry(ProcessRegistry):return [name for name, proc in self.processes.items() if proc.config.get("ask_skip") is True]-def get_default_mprocs_path() -> Path:- """Get the default path to mprocs.yaml."""+def find_repo_file(relative_path: str) -> Path:+ """Walk up from this module to the repo copy of relative_path; cwd-relative if absent."""current = Path(__file__).resolve()for parent in current.parents:- mprocs_path = parent / "bin" / "mprocs.yaml"- if mprocs_path.exists():- return mprocs_path+ candidate = parent / relative_path+ if candidate.exists():+ return candidate++ return Path.cwd() / relative_path- return Path.cwd() / "bin" / "mprocs.yaml"++def get_default_mprocs_path() -> Path:+ """Get the default path to mprocs.yaml."""+ return find_repo_file("bin/mprocs.yaml")def create_mprocs_registry(path: Path | None = None) -> MprocsRegistry:diff --git a/tools/hogli-commands/hogli_commands/tests/test_devenv.py b/tools/hogli-commands/hogli_commands/tests/test_devenv.pyindex fd665ee8c6e6..046a4cb47e04 100644--- a/tools/hogli-commands/hogli_commands/tests/test_devenv.py+++ b/tools/hogli-commands/hogli_commands/tests/test_devenv.py@@ -8,6 +8,7 @@ import shleximport shutilimport tempfileimport subprocess+from dataclasses import replacefrom pathlib import Pathfrom typing import Any@@ -15,12 +16,21 @@ import pytestfrom unittest import mockimport yaml+from click.testing import CliRunner+from hogli_commands.devenv.cli import dev_regenerate_mprocsfrom hogli_commands.devenv.generator import (+ _READY_MARKER,+ TRACKED_MPROCS_FILES,DevenvConfig,MprocsConfig,MprocsGenerator,+ TrackedMprocsFile,+ _build_docker_compose_shell,build_docker_compose_command,+ build_e2e_docker_compose_shell,+ build_static_docker_compose_shell,load_devenv_config,+ regenerate_mprocs_shell,)from hogli_commands.devenv.registry import ProcessRegistry, create_mprocs_registryfrom hogli_commands.devenv.resolver import Capability, Intent, IntentMap, IntentResolver, load_intent_map@@ -481,6 +491,130 @@ class TestDockerComposeProjectName:assert tokens[tokens.index("-p") + 1] == expected_value+class TestMprocsDockerComposeShellSync:+ """Each checked-in file's shell must equal its generator function's output, and+ regenerating a drifted copy must rewrite only that one line."""++ @parameterized.expand([(t.name, t) for t in TRACKED_MPROCS_FILES])+ def test_checked_in_file_matches_generator_output(self, _name: str, target: TrackedMprocsFile) -> None:+ proc = create_mprocs_registry(target.path).get_processes()["docker-compose"]++ assert proc.shell == target.build_shell()+ assert proc.config["ready_pattern"] == _READY_MARKER++ @parameterized.expand([(t.name, t) for t in TRACKED_MPROCS_FILES])+ def test_regenerate_rewrites_a_drifted_file_and_only_that_line(self, _name: str, target: TrackedMprocsFile) -> None:+ real_path = target.path+ original = real_path.read_text()+ current_shell = create_mprocs_registry(real_path).get_processes()["docker-compose"].shell+ drifted_shell = current_shell.replace("docker-compose ready", "DRIFTED")+ with tempfile.TemporaryDirectory() as tmp:+ drifted_path = Path(tmp) / "mprocs.yaml"+ drifted_path.write_text(original.replace(current_shell, drifted_shell))++ was_rewritten = regenerate_mprocs_shell(drifted_path, target.build_shell())++ assert was_rewritten is True+ assert drifted_path.read_text() == original+++class TestRegenerateMprocsCheckFlag:+ """--check backs ci:preflight's verify step, so it must report staleness without writing."""++ def test_passes_without_writing_when_up_to_date(self) -> None:+ originals = {target.path: target.path.read_text() for target in TRACKED_MPROCS_FILES}++ result = CliRunner().invoke(dev_regenerate_mprocs, ["--check"])++ assert result.exit_code == 0+ assert "up to date" in result.output+ assert all(path.read_text() == text for path, text in originals.items())++ def test_fails_without_writing_when_stale(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:+ static_target = TRACKED_MPROCS_FILES[0]+ original = static_target.path.read_text()+ drifted_path = tmp_path / "mprocs.yaml"+ drifted_path.write_text(original.replace(static_target.build_shell(), "echo drifted"))+ drifted_text = drifted_path.read_text()+ patched_targets = [replace(static_target, path=drifted_path), *TRACKED_MPROCS_FILES[1:]]+ monkeypatch.setattr("hogli_commands.devenv.cli.TRACKED_MPROCS_FILES", patched_targets)++ result = CliRunner().invoke(dev_regenerate_mprocs, ["--check"])++ assert result.exit_code == 1+ assert str(drifted_path) in result.output+ assert drifted_path.read_text() == drifted_text+++class TestDockerComposeShellBehavior:+ """The static and e2e shells must only report ready after `docker compose up`+ (and, for e2e, the personhog step) succeeds, and must never invoke docker at+ all when POSTHOG_SANDBOX=1 (e2e never sandboxes, so it has no such case).++ The failing-`up` cases specifically guard the `exit 1` in the static shell's+ `up_cmd || { fail_cmd; exit 1; }`: drop it and the `{ ...; }` group exits 0,+ the `||` is satisfied, and the ready marker fires even though `up` failed —+ every dependent proc then starts against a dead stack."""++ def test_generated_shell_delegates_to_the_shared_docker_compose_helper(self) -> None:+ # The hogli-generated shell shares its up/logs/sandbox-guard logic with the+ # static one via _build_docker_compose_shell, so its branching behavior is+ # already covered below; this just guards against that delegation being+ # replaced with a reimplementation that drifts.+ generated = MprocsGenerator(MockRegistry({}))._generate_docker_compose_config({}, [])["shell"]++ assert generated.endswith(_build_docker_compose_shell([]))++ _SHELL_BUILDERS = {"static": build_static_docker_compose_shell, "e2e": build_e2e_docker_compose_shell}++ @classmethod+ def _shell(cls, source: str) -> str:+ return cls._SHELL_BUILDERS[source]()++ @staticmethod+ def _run_shell(+ shell: str, up_exit: int, personhog_exit: int = 0, *, sandbox: bool+ ) -> subprocess.CompletedProcess[str]:+ with tempfile.TemporaryDirectory() as tmp:+ fake_docker = Path(tmp) / "docker"+ fake_docker.write_text(+ f'#!/bin/sh\ncase "$*" in *personhog*) exit {personhog_exit};; *" up "*) exit {up_exit};; esac\nexit 0\n'+ )+ fake_docker.chmod(0o755)+ fake_sleep = Path(tmp) / "sleep"+ fake_sleep.write_text("#!/bin/sh\nexit 0\n")+ fake_sleep.chmod(0o755)+ env = {**os.environ, "PATH": f"{tmp}:{os.environ['PATH']}"}+ if sandbox:+ env["POSTHOG_SANDBOX"] = "1"+ else:+ env.pop("POSTHOG_SANDBOX", None)+ return subprocess.run(+ ["bash", "-c", shell], env=env, capture_output=True, text=True, timeout=10, check=False+ )++ @parameterized.expand(+ [+ ("static", False, 0, 0, True),+ ("static", False, 1, 0, False),+ ("static", True, 1, 0, True),+ ("e2e", False, 0, 0, True),+ ("e2e", False, 0, 1, False),+ ]+ )+ def test_ready_marker_tracks_up_result_unless_sandboxed(+ self, source: str, sandbox: bool, up_exit: int, personhog_exit: int, expect_ready: bool+ ) -> None:+ # Sandbox cases pass up_exit=1 and still expect ready, proving docker's `up`+ # call is never reached once POSTHOG_SANDBOX=1 short-circuits the shell. The+ # e2e personhog_exit=1 case proves a failed personhog step (its own `&&` in+ # the chain) blocks ready too, not just a failed main `up`.+ result = self._run_shell(self._shell(source), up_exit, personhog_exit, sandbox=sandbox)++ assert ("docker-compose ready" in result.stdout) == expect_ready+ assert (result.returncode == 0) == expect_ready++class TestIntentMapLoading:"""Test intent map loading from YAML."""@@ -979,64 +1113,3 @@ class TestParseExcludeInput:excluded, out_of_range = _parse_exclude_input(raw, self.UNITS)assert excluded == expected_excludedassert out_of_range == expected_out_of_range---class TestDockerComposeShellFailurePath:- """The docker-compose proc shell must not emit the ready marker when `up` fails.-- `up_cmd || { fail_cmd; exit 1; } && echo 'docker-compose ready'` only adds- a friendlier failure message over a plain `up_cmd && echo ready` chain —- both already skip the ready marker on failure. What this guards against is- someone dropping the `exit 1` from `fail_cmd`: then the `{ ...; }` group- exits 0, the `||` is satisfied, and `docker-compose ready` fires even- though `up` failed, so every dependent proc starts against a dead stack.- Covers both the generated shell and its independently maintained twin in- bin/mprocs.yaml (the static fallback used when hogli is unavailable).- """-- @staticmethod- def _shells() -> list[tuple[str, str]]:- generated = MprocsGenerator(MockRegistry({}))._generate_docker_compose_config({}, [])["shell"]- repo_root = Path(__file__).resolve().parents[4]- static = yaml.safe_load((repo_root / "bin" / "mprocs.yaml").read_text())["procs"]["docker-compose"]["shell"]- return [("generated", generated), ("static", static)]-- @parameterized.expand(- [- ("generated", 0, True),- ("generated", 1, False),- ("static", 0, True),- ("static", 1, False),- ]- )- def test_ready_marker_tracks_up_result(self, source: str, up_exit: int, expect_ready: bool) -> None:- shell = dict(self._shells())[source]- with tempfile.TemporaryDirectory() as tmp:- fake = Path(tmp) / "docker"- fake.write_text(f'#!/bin/sh\ncase "$*" in *" up "*) exit {up_exit};; esac\nexit 0\n')- fake.chmod(0o755)- env = {**os.environ, "PATH": f"{tmp}:{os.environ['PATH']}"}- env.pop("POSTHOG_SANDBOX", None)- result = subprocess.run(- ["bash", "-c", shell], env=env, capture_output=True, text=True, timeout=10, check=False- )- assert ("docker-compose ready" in result.stdout) == expect_ready- assert (result.returncode == 0) == expect_ready-- @parameterized.expand([("generated",), ("static",)])- def test_sandbox_guard_short_circuits_before_docker(self, source: str) -> None:- # Sandboxes have no docker CLI; the shell must report ready without- # invoking docker at all. A fake docker that always fails proves the- # guard short-circuits; a fake sleep lets the sandbox branch terminate.- shell = dict(self._shells())[source]- with tempfile.TemporaryDirectory() as tmp:- for name, body in [("docker", "#!/bin/sh\nexit 1\n"), ("sleep", "#!/bin/sh\nexit 0\n")]:- fake = Path(tmp) / name- fake.write_text(body)- fake.chmod(0o755)- env = {**os.environ, "PATH": f"{tmp}:{os.environ['PATH']}", "POSTHOG_SANDBOX": "1"}- result = subprocess.run(- ["bash", "-c", shell], env=env, capture_output=True, text=True, timeout=10, check=False- )- assert "docker-compose ready" in result.stdout- assert result.returncode == 0