Skip to content

Commit 9d7aa45

Browse files
yasinBursaliclaude
andcommitted
test(dream-cli): regression for _check_version_compat pipefail tolerance
Maintainer audit on PR Light-Heart-Labs#998 (Lightheartdevs, 2026-04-28) flagged that under `set -euo pipefail`, `_check_version_compat` must tolerate a `.env` lacking `DREAM_VERSION` and fall back to `.version` / `manifest.json`. The audit-required form is the trailing `|| true` on the DREAM_VERSION grep pipeline: _COMPAT_INSTALLED_VER=$(grep '^DREAM_VERSION=' "$INSTALL_DIR/.env" 2>/dev/null \ | sed -n '1p' | cut -d= -f2 | tr -d '[:space:]' || true) The rebase onto current main (which carries Light-Heart-Labs#1008's tolerance fix) preserved this form via conflict resolution; this test locks it in. `tests/test-dream-cli-version-compat-pipefail.sh` (4 cases, wired into `make test`): 1. dream-cli runs under strict mode (set -e or stricter). 2. The DREAM_VERSION grep pipeline ends with `|| true` (matched against active code; comment lines stripped before grep so the rationale block can't satisfy the assertion on its own). 3. `.version` and `manifest.json` fallback branches still exist (they are the destinations the `|| true` enables reaching). 4. Anti-regression: the bare-close form (no trailing `|| true`) does NOT appear — catches a future "cleanup" PR removing the guard. Behavioural test was attempted but rejected: `_check_version_compat` depends on `warn`/`log`/`_manifest_field`/`_semver_*` and several file-scope color vars, so isolating it requires too much harness setup. The dream-cli BATS suite (Light-Heart-Labs#1018) carries the behavioural coverage at the right layer. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 04a43e9 commit 9d7aa45

2 files changed

Lines changed: 120 additions & 0 deletions

File tree

dream-server/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ test: ## Run unit and contract tests
3333
@echo "=== Overlay/plist contracts ==="
3434
@bash tests/contracts/test-overlay-map-coherence.sh
3535
@bash tests/contracts/test-plist-log-paths.sh
36+
@echo ""
37+
@echo "=== _check_version_compat pipefail tolerance ==="
38+
@bash tests/test-dream-cli-version-compat-pipefail.sh
3639

3740
bats: ## Run BATS unit tests for shell libraries
3841
@echo "=== BATS unit tests ==="
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env bash
2+
# ============================================================================
3+
# Regression: `_check_version_compat` must tolerate missing DREAM_VERSION
4+
# under `set -euo pipefail`.
5+
# ============================================================================
6+
# Maintainer audit on PR #998 (Lightheartdevs, 2026-04-28):
7+
#
8+
# "_check_version_compat must tolerate a `.env` without `DREAM_VERSION`
9+
# and fall back to `.version`/`manifest.json` instead of exiting under
10+
# pipefail."
11+
#
12+
# The bug pattern: piping `grep '^DREAM_VERSION='` (which exits 1 when
13+
# the line is absent) into `cut`/`tr` under `set -euo pipefail`
14+
# propagates the failure as the pipeline's exit status. Without `|| true`
15+
# at the end, a fresh-install `.env` would short-circuit the surrounding
16+
# command-substitution and abort the script before the .version /
17+
# manifest.json fallback branches run.
18+
#
19+
# This test locks in the canonical `|| true` form. Behavioural coverage
20+
# is covered by the dream-cli BATS suite (#1018) which sources the full
21+
# CLI; here we use source-pattern to keep the test isolated and fast.
22+
# ============================================================================
23+
24+
set -euo pipefail
25+
26+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
27+
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
28+
DREAM_CLI="$ROOT_DIR/dream-cli"
29+
30+
GREEN='\033[0;32m'
31+
RED='\033[0;31m'
32+
NC='\033[0m'
33+
34+
PASSED=0
35+
FAILED=0
36+
37+
pass() { echo -e " ${GREEN}✓ PASS${NC} $1"; PASSED=$((PASSED + 1)); }
38+
fail() { echo -e " ${RED}✗ FAIL${NC} $1"; FAILED=$((FAILED + 1)); }
39+
40+
echo ""
41+
echo "╔═══════════════════════════════════════════════╗"
42+
echo "║ _check_version_compat — pipefail tolerance ║"
43+
echo "╚═══════════════════════════════════════════════╝"
44+
echo ""
45+
46+
if [[ ! -x "$DREAM_CLI" ]]; then
47+
fail "dream-cli not found at $DREAM_CLI"
48+
echo ""; echo "Result: $PASSED passed, $FAILED failed"; exit 1
49+
fi
50+
51+
# 1. dream-cli has `set -euo pipefail` (or `set -e` + pipefail) at the
52+
# top, so the audit precondition holds.
53+
if grep -qE '^set -euo? pipefail' "$DREAM_CLI" || grep -qE '^set -o pipefail' "$DREAM_CLI" || grep -qE '^set -e' "$DREAM_CLI"; then
54+
pass "dream-cli runs under strict mode (set -e or stricter)"
55+
else
56+
fail "dream-cli is not under strict mode — audit precondition is moot"
57+
fi
58+
59+
# 2. Extract the _check_version_compat() body and strip comments so
60+
# grep matches active code, not the rationale comment block.
61+
fn_block=$(awk '
62+
/^_check_version_compat\(\)/ { in_block=1 }
63+
in_block { print }
64+
in_block && /^}$/ { exit }
65+
' "$DREAM_CLI")
66+
67+
if [[ -z "$fn_block" ]]; then
68+
fail "could not extract _check_version_compat() body"
69+
echo ""; echo "Result: $PASSED passed, $FAILED failed"; exit 1
70+
fi
71+
72+
fn_code=$(grep -v '^[[:space:]]*#' <<<"$fn_block")
73+
74+
# 3. The DREAM_VERSION grep pipeline must end with `|| true` so a
75+
# missing match (grep exit 1) does not abort under pipefail.
76+
#
77+
# The canonical pipeline shape (broken across two lines via `\`):
78+
# _COMPAT_INSTALLED_VER=$(grep '^DREAM_VERSION=' "$INSTALL_DIR/.env" 2>/dev/null \
79+
# | sed -n '1p' | cut -d= -f2 | tr -d '[:space:]' || true)
80+
#
81+
# We require:
82+
# - the grep -DREAM_VERSION-= line is present (the bug-prone pipeline source),
83+
# - `|| true` literal appears on the next non-blank line (the audit-required tolerance).
84+
if grep -A1 "grep '\^DREAM_VERSION=' \"\$INSTALL_DIR/\.env\"" <<<"$fn_code" \
85+
| grep -q '|| true'; then
86+
pass "DREAM_VERSION grep pipeline ends with '|| true' tolerance"
87+
else
88+
fail "DREAM_VERSION grep pipeline missing '|| true' (audit blocker)"
89+
echo " --- function code (comments stripped) ---"
90+
awk '{print " " $0}' <<<"$fn_code"
91+
fi
92+
93+
# 4. The .version and manifest.json fallback branches must still exist.
94+
# The whole point of `|| true` is to let execution reach these.
95+
if grep -q '\.version' <<<"$fn_code" && grep -q 'manifest\.json' <<<"$fn_code"; then
96+
pass ".version and manifest.json fallback branches present"
97+
else
98+
fail "missing fallback branches (would defeat the '|| true' fix)"
99+
fi
100+
101+
# 5. Anti-regression: the bare-pipe form
102+
# _COMPAT_INSTALLED_VER=$(... | tr -d '[:space:]')
103+
# (no trailing `|| true`) MUST NOT appear. This catches a future
104+
# PR that "cleans up" the `|| true` thinking it's redundant.
105+
#
106+
# We grep for the pipeline source line followed by a closing `)` on
107+
# the next line WITHOUT a `|| true` between them.
108+
if grep -A1 "grep '\^DREAM_VERSION=' \"\$INSTALL_DIR/\.env\"" <<<"$fn_code" \
109+
| grep -qE "tr -d '\[:space:\]'\\)$"; then
110+
fail "DREAM_VERSION pipeline regressed to bare-close (no '|| true')"
111+
else
112+
pass "no bare-close regression in DREAM_VERSION pipeline"
113+
fi
114+
115+
echo ""
116+
echo "Result: $PASSED passed, $FAILED failed"
117+
[[ $FAILED -eq 0 ]]

0 commit comments

Comments
 (0)