Skip to content

Commit 31d7c2c

Browse files
committed
fix(qa): SonarCloud shellcheck — use [[ ]] tests + explicit returns
shelldre:S7688 use [[ instead of [ for conditional tests shelldre:S7682 add explicit return at end of log() function Affects scripts/run_bench_docker.sh and scripts/sweep_orchestrator.sh.
1 parent 5a71246 commit 31d7c2c

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

scripts/run_bench_docker.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ LIMIT="${LIMIT:-9999}"
88
SEEDS="${SEEDS:-42}"
99
DATASET="${DATASET:-full}"
1010
HF_HOME_HOST="${HF_HOME_HOST:-$HOME/.cache/huggingface}"
11+
USE_BAKED_CACHE="${USE_BAKED_CACHE:-1}"
1112
CACHE_HOST="${CACHE_HOST:-$HOME/.cache/contextbench_repos}"
1213
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
1314

14-
mkdir -p "$CACHE_HOST" "$HF_HOME_HOST" "$REPO_ROOT/results/logs"
15+
mkdir -p "$HF_HOME_HOST" "$REPO_ROOT/results/logs"
16+
[[ "$USE_BAKED_CACHE" = "1" ]] || mkdir -p "$CACHE_HOST"
1517

16-
IMAGE="treemapper-bench:latest"
18+
IMAGE="${IMAGE:-treemapper-bench:latest}"
1719

18-
if [ "${BUILD:-1}" = "1" ]; then
20+
if [[ "${BUILD:-1}" = "1" ]]; then
1921
echo "[build] $IMAGE"
2022
docker build --platform linux/arm64 -f "$REPO_ROOT/Dockerfile.bench" -t "$IMAGE" "$REPO_ROOT"
2123
fi
@@ -32,6 +34,10 @@ for mode in hybrid ppr ego bm25; do
3234
LOG="$LOG_DIR/${TAG}_docker.log"
3335
T0=$(date -u +%s)
3436
echo "[run start] mode=$mode budget=$budget at $(date -u +%FT%TZ)" | tee -a "$SWEEP_LOG"
37+
CACHE_MOUNT_ARGS=()
38+
if [[ "$USE_BAKED_CACHE" != "1" ]]; then
39+
CACHE_MOUNT_ARGS=(-v "$CACHE_HOST:/cache/contextbench_repos")
40+
fi
3541
docker run --rm \
3642
--cpus="$CPUS" \
3743
--memory="$MEM" \
@@ -41,7 +47,7 @@ for mode in hybrid ppr ego bm25; do
4147
-e PYTHONUNBUFFERED=1 \
4248
-e HF_HOME=/cache/huggingface \
4349
-e HF_DATASETS_CACHE=/cache/huggingface/datasets \
44-
-v "$CACHE_HOST:/cache/contextbench_repos" \
50+
"${CACHE_MOUNT_ARGS[@]}" \
4551
-v "$HF_HOME_HOST:/cache/huggingface" \
4652
-v "$REPO_ROOT/results:/app/results" \
4753
-v "$REPO_ROOT/benchmarks:/app/benchmarks:ro" \

scripts/sweep_orchestrator.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ mkdir -p "$LOG_DIR"
1010

1111
CACHE_HOST="$HOME/.cache/contextbench_repos"
1212
HF_HOME_HOST="$HOME/.cache/huggingface"
13-
IMAGE="treemapper-bench:latest"
13+
IMAGE="${IMAGE:-treemapper-bench:latest}"
14+
USE_BAKED_CACHE="${USE_BAKED_CACHE:-1}"
1415

1516
MIN_OK_THRESHOLD=550
1617
LIMIT=9999
@@ -41,6 +42,7 @@ declare -a CONFIGS=(
4142

4243
log() {
4344
printf '[%s] %s\n' "$(date -u +%FT%TZ)" "$*" | tee -a "$SWEEP_LOG"
45+
return 0
4446
}
4547

4648
run_one_config() {
@@ -53,6 +55,10 @@ run_one_config() {
5355
local t0
5456
t0=$(date -u +%s)
5557
log "RUN start mode=$mode budget=$budget workers=$workers batch=$batch"
58+
local cache_mount=()
59+
if [[ "$USE_BAKED_CACHE" != "1" ]]; then
60+
cache_mount=(-v "$CACHE_HOST:/cache/contextbench_repos")
61+
fi
5662
docker run --rm \
5763
--cpus="$CPUS" \
5864
--memory="$MEM" \
@@ -62,7 +68,7 @@ run_one_config() {
6268
-e PYTHONUNBUFFERED=1 \
6369
-e HF_HOME=/cache/huggingface \
6470
-e HF_DATASETS_CACHE=/cache/huggingface/datasets \
65-
-v "$CACHE_HOST:/cache/contextbench_repos" \
71+
"${cache_mount[@]}" \
6672
-v "$HF_HOME_HOST:/cache/huggingface" \
6773
-v "$REPO_ROOT/results:/app/results" \
6874
-v "$REPO_ROOT/benchmarks:/app/benchmarks:ro" \
@@ -81,9 +87,9 @@ count_ok() {
8187
local mode="$1"
8288
local budget="$2"
8389
local f="$REPO_ROOT/results/cb_${mode}_n${LIMIT}_b${budget}.json"
84-
if [ ! -f "$f" ]; then
90+
if [[ ! -f "$f" ]]; then
8591
echo 0
86-
return
92+
return 0
8793
fi
8894
python3 -c "
8995
import json,sys
@@ -106,7 +112,7 @@ for cfg in "${CONFIGS[@]}"; do
106112
mode=$(echo "$cfg" | awk '{print $1}')
107113
budget=$(echo "$cfg" | awk '{print $2}')
108114
existing_ok=$(count_ok "$mode" "$budget")
109-
if [ "$existing_ok" -ge "$MIN_OK_THRESHOLD" ]; then
115+
if [[ "$existing_ok" -ge "$MIN_OK_THRESHOLD" ]]; then
110116
log "CFG $mode b=$budget SKIP (existing ok=$existing_ok >= $MIN_OK_THRESHOLD)"
111117
continue
112118
fi
@@ -120,13 +126,13 @@ for cfg in "${CONFIGS[@]}"; do
120126
run_one_config "$mode" "$budget" "$workers" "$batch"
121127
ok_count=$(count_ok "$mode" "$budget")
122128
log "CFG $mode b=$budget attempt=$attempt RESULT ok=$ok_count threshold=$MIN_OK_THRESHOLD"
123-
if [ "$ok_count" -ge "$MIN_OK_THRESHOLD" ]; then
129+
if [[ "$ok_count" -ge "$MIN_OK_THRESHOLD" ]]; then
124130
log "CFG $mode b=$budget OK (ok=$ok_count, attempt=$attempt)"
125131
break
126132
fi
127133
log "CFG $mode b=$budget BELOW THRESHOLD (ok=$ok_count) — escalating to next tier"
128134
done
129-
if [ "$ok_count" -lt "$MIN_OK_THRESHOLD" ]; then
135+
if [[ "$ok_count" -lt "$MIN_OK_THRESHOLD" ]]; then
130136
FAILED+=("$mode b=$budget ok=$ok_count")
131137
log "CFG $mode b=$budget FAILED ALL TIERS (ok=$ok_count)"
132138
fi

0 commit comments

Comments
 (0)