#!/bin/sh
# Warm launches compile nothing (WARMZERO): per package, with a fresh app home,
# session 0 (prep): one launch on a run home of its own, so the app's own state (saved settings, a
# model it writes at quit) is a used one: a first-ever launch runs other code;
# session 1 (cold): on a fresh run home (its own disk cache): launch hidden + muted, first present, wait until the JIT is idle (3 idle
# `inspect jit` looks in a row: the ring stopped), quit (SIGTERM, as a close);
# session 2 (warm): the same launch on the same home: it must reach idle with 0 first compiles on
# the program's threads (`inspect jit`'s session line: everything the first session
# compiled was stored and installed again). Background tier-ups are reported, not failed.
# Sandbox with a Play: local/agent_state/relax-campaign/warmzero-tools/wz.py (same rule, real Play click).
# Run from the workspace root after `cargo build --release -p makepad-run`.
# PACKAGES (default "makepad-app-calculator"; each word is a `makepad run` argument list with ',' for
# spaces), WAIT (seconds to the first present / to idle, default 300), TARGET (default target/release).
# Prints "warm_zero: OK ..." or "warm_zero: FAIL ..." per package; exit 1 on any failure.
T=${TARGET:-target/release}
B=$(cd "$(dirname "$T/makepad")" && pwd)/makepad
PACKAGES=${PACKAGES:-makepad-app-calculator,--no-default-features,--features,standalone}
WAIT=${WAIT:-300}
dir=$(mktemp -d "${TMPDIR:-/tmp}/warm_zero.XXXXXX") || exit 1
fails=0
k=0
session() { # session