From 2fea4d5cd29d46e03c4f46a3f9b87fe3c13fe3b0 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 22 May 2026 01:03:20 +0000 Subject: [PATCH] fix(cron): keep helpful diagnostics under pipefail / shared snippet - run_daily.sh: append '|| true' to the claude --version pipeline so a non-matching grep doesn't get propagated by pipefail+set -e, aborting before the '[[ -n CLAUDE_CODE_VERSION ]] || die' diagnostic fires. - test_run_daily_release_pagination.py: the resolution-snippet extracted from run_daily.sh starts AFTER log/die are defined. Define stubs in the test preamble so an empty LITELLM_VERSION surfaces the intended error message instead of 'bash: die: command not found' (exit 127). Co-authored-by: Yassin Kortam --- .../test_run_daily_release_pagination.py | 23 +++++++++++++++---- tests/claude_code/cron_vm/run_daily.sh | 6 ++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/claude_code/_publisher_unit_tests/test_run_daily_release_pagination.py b/tests/claude_code/_publisher_unit_tests/test_run_daily_release_pagination.py index 473e30bea1a..9d6a6e343bb 100644 --- a/tests/claude_code/_publisher_unit_tests/test_run_daily_release_pagination.py +++ b/tests/claude_code/_publisher_unit_tests/test_run_daily_release_pagination.py @@ -35,6 +35,17 @@ import pytest REPO_ROOT = Path(__file__).resolve().parents[3] RUN_DAILY = REPO_ROOT / "tests" / "claude_code" / "cron_vm" / "run_daily.sh" +# The extracted snippet starts AFTER `log`/`die` are defined in run_daily.sh, +# so the test harness has to provide its own stubs. Without them, a failure +# inside the snippet (e.g. jq returning an empty LITELLM_VERSION) would crash +# with `bash: die: command not found` (exit 127) instead of the intended +# diagnostic, making test failures unnecessarily hard to debug. +_PREAMBLE = ( + "set -Eeuo pipefail\n" + "log() { printf '==> %s\\n' \"$*\" >&2; }\n" + "die() { printf 'ERROR: %s\\n' \"$*\" >&2; exit 1; }\n" +) + def test_run_daily_does_not_early_break_on_first_stable_page() -> None: """The regex pattern `select(test("...stable$"))] | length > 0` followed @@ -211,8 +222,10 @@ def test_run_daily_resolves_highest_semver_across_pages(tmp_path: Path) -> None: snippet = _extract_resolution_snippet() script = ( - "set -Eeuo pipefail\n" - f"WORKDIR={workdir!s}\n" + snippet + 'printf "%s" "${LITELLM_VERSION}"\n' + _PREAMBLE + + f"WORKDIR={workdir!s}\n" + + snippet + + 'printf "%s" "${LITELLM_VERSION}"\n' ) env = { @@ -249,8 +262,10 @@ def test_run_daily_terminates_on_empty_page(tmp_path: Path) -> None: snippet = _extract_resolution_snippet() script = ( - "set -Eeuo pipefail\n" - f"WORKDIR={workdir!s}\n" + snippet + 'printf "%s" "${LITELLM_VERSION}"\n' + _PREAMBLE + + f"WORKDIR={workdir!s}\n" + + snippet + + 'printf "%s" "${LITELLM_VERSION}"\n' ) env = { diff --git a/tests/claude_code/cron_vm/run_daily.sh b/tests/claude_code/cron_vm/run_daily.sh index db51a316fe1..7a53e90d750 100755 --- a/tests/claude_code/cron_vm/run_daily.sh +++ b/tests/claude_code/cron_vm/run_daily.sh @@ -194,7 +194,11 @@ CLAUDE_CODE_VERSION="$(env -i \ TMPDIR="${TMPDIR:-/tmp}" \ claude --version 2>/dev/null \ | grep -oE '[0-9]+\.[0-9]+\.[0-9]+([.-][A-Za-z0-9.-]+)?' \ - | head -n1)" + | head -n1 || true)" +# `|| true` above keeps `set -Eeuo pipefail` from aborting silently when +# `grep` finds no match (exit 1) — without it the assignment inherits the +# pipeline's non-zero exit, `set -e` kills the script, and the operator +# never sees the helpful diagnostic below. [[ -n "${CLAUDE_CODE_VERSION}" ]] || die "could not parse semver from 'claude --version'" log "local claude code: ${CLAUDE_CODE_VERSION}"