#!/usr/bin/env bash# Run one CI command with its temp directory in memory, not on the box's disk.## bash scripts/ci/job-tmp-in-memory.sh -- <command> [args…]## A fresh directory under /dev/shm is the command's TMPDIR (and TMP, TEMP),# and it is removed when the command ends, whatever its status, which is the# status this script exits with.## WHY (7 Nov 2026). guards-main's `checks` went red run after run (7678, 7680,# 7683, 7685, 7698, 7700) on apps/business Worker tests timing out at 5 s, a# different few hundred each run. Their Durable Objects are SQLite files that# miniflare keeps under os.tmpdir() (/tmp/miniflare-*/do/…), and /tmp is the# box's root filesystem: a mirror of two consumer NVMe drives that sat at 100%# busy, writing 80 MB/s with a 270 ms write wait, while rust-main and# box:cargo linked test binaries. Every object write waited on that disk (and# on ext4's shared journal, which no IO weight reorders). In memory, the# writes cost what the tests meant them to.## ONE COMMAND, NOT THE JOB: the root scripts suite measures the home volume# against its temp folders (scripts/lib/mac_disk_policy.py), and a TMPDIR on# another volume failed 26 of its tests (run 7713). So the job's Worker tests# (`pnpm turbo test`) run under this, and nothing else does.## /dev/shm is tmpfs (63 GB on the box, exec allowed); what the command writes# there is charged to the runner's memory cgroup until it is removed. A# directory a killed job left behind is swept by the next run once it is two# hours old.set -euo pipefailhere="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)". "$here/scripts/lib/owned-root.sh"[ "${1-}" = -- ] && [ "$#" -ge 2 ] || { echo "usage: job-tmp-in-memory.sh -- <command> [args…]" >&2; exit2; }shiftroot="${JOB_TMP_ROOT:-/dev/shm}"prefix="ci-tmp-"refuse_wide_root "the in-memory temp root""$root"[ -d "$root" ] && [ -w "$root" ] || { echo "job-tmp-in-memory: no writable $root" >&2; exit2; }for stale in"$root/$prefix"*; do [ -d "$stale" ] && [ ! -L "$stale" ] && [ -O "$stale" ] || continue [ -n "$(find "$stale" -maxdepth 0 -mmin +120)" ] || continue rm -rf -- "$stale"donedir="$(mktemp -d "$root/${prefix}XXXXXXXX")"trap'rm -rf -- "$dir"' EXITecho "job-tmp-in-memory: TMPDIR=$dir for: $*"set +eTMPDIR="$dir" TMP="$dir" TEMP="$dir""$@"status=$?set -eexit"$status"