Skip to content

Commit ca7cfd1

Browse files
authored
Merge pull request #14 from jkdihenkar/fix/bash3-awk-field-offset
fix: strip PID field from awk fallback on bash < 4
2 parents a5a21c9 + 910f457 commit ca7cfd1

5 files changed

Lines changed: 71 additions & 8 deletions

File tree

.github/workflows/test.yml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,62 @@ permissions:
1313
jobs:
1414
test:
1515
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
bash: [bash, bash3.2]
20+
name: test (bash ${{ matrix.bash == 'bash' && '5' || '3.2' }})
1621
steps:
1722
- uses: actions/checkout@v4
1823
with:
1924
fetch-depth: 0
2025

26+
- uses: docker/setup-buildx-action@v3
27+
2128
- name: Build test image
22-
run: docker build -t tmux-assistant-resurrect-test -f test/Dockerfile .
29+
uses: docker/build-push-action@v6
30+
with:
31+
context: .
32+
file: test/Dockerfile
33+
load: true
34+
tags: tmux-assistant-resurrect-test
35+
cache-from: type=gha
36+
cache-to: type=gha,mode=max
2337

2438
- name: Run tests
2539
run: |
2640
mkdir -p test-results
27-
docker run --rm -v ${{ github.workspace }}/test-results:/tmp/test-results tmux-assistant-resurrect-test
41+
docker run --rm \
42+
-e TEST_BASH=${{ matrix.bash }} \
43+
-v ${{ github.workspace }}/test-results:/tmp/test-results \
44+
tmux-assistant-resurrect-test
2845
2946
- name: Publish test results
3047
uses: EnricoMi/publish-unit-test-result-action@v2
3148
if: always()
3249
with:
3350
files: test-results/junit.xml
3451
comment_mode: off
52+
check_name: tests (${{ matrix.bash == 'bash' && 'bash 5' || 'bash 3.2' }})
53+
54+
benchmark:
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v4
58+
with:
59+
fetch-depth: 0
60+
61+
- uses: docker/setup-buildx-action@v3
62+
63+
- name: Build test image
64+
uses: docker/build-push-action@v6
65+
with:
66+
context: .
67+
file: test/Dockerfile
68+
load: true
69+
tags: tmux-assistant-resurrect-test
70+
cache-from: type=gha
71+
cache-to: type=gha,mode=max
3572

3673
- name: Prepare benchmark baseline
3774
run: |

justfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,13 @@ status:
370370
fi
371371

372372
# Manually trigger a save of current assistant sessions
373+
# TEST_BASH overrides the interpreter (e.g. bash3.2 for compat testing).
373374
save:
374-
@bash "{{repo_dir}}/scripts/save-assistant-sessions.sh"
375+
@"${TEST_BASH:-bash}" "{{repo_dir}}/scripts/save-assistant-sessions.sh"
375376

376377
# Manually trigger a restore of saved assistant sessions
377378
restore:
378-
@bash "{{repo_dir}}/scripts/restore-assistant-sessions.sh"
379+
@"${TEST_BASH:-bash}" "{{repo_dir}}/scripts/restore-assistant-sessions.sh"
379380

380381
# Clean up stale state files (from dead processes)
381382
clean:

scripts/save-assistant-sessions.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ resolve_pane_candidates() {
348348
if [ "$has_assoc_cache" -eq 1 ]; then
349349
cached="${STATE_CACHE[$cand_pid]:-}"
350350
elif [ -s "$state_cache_file" ]; then
351-
cached=$(awk -F"$us" -v p="$cand_pid" '$1 == p {print; exit}' "$state_cache_file")
351+
cached=$(awk -F"$us" -v p="$cand_pid" '$1 == p {for(i=2;i<=NF;i++) printf "%s%s",$i,(i<NF?FS:""); print ""; exit}' "$state_cache_file")
352352
fi
353353
if [ -n "$cached" ]; then
354354
cached_sid="${cached%%"$us"*}"
@@ -391,7 +391,9 @@ resolve_pane_candidates() {
391391
fi
392392

393393
# Fallback: parse --model from CLI args if not in state file.
394-
if [ -z "$model" ] && [[ "$cand_args" =~ --model[=\ ]([^\ ]+) ]]; then
394+
# Regex stored in variable for bash 3.2 compat (inline capture groups fail).
395+
local _model_re='--model[= ]([^ ]+)'
396+
if [ -z "$model" ] && [[ "$cand_args" =~ $_model_re ]]; then
395397
model="${BASH_REMATCH[1]}"
396398
fi
397399

test/Dockerfile

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM ubuntu:24.04
22

33
ENV DEBIAN_FRONTEND=noninteractive
44

5-
# Core tools
5+
# Core tools + build deps for bash 3.2
66
RUN apt-get update && apt-get install -y \
77
tmux \
88
jq \
@@ -13,8 +13,24 @@ RUN apt-get update && apt-get install -y \
1313
nodejs \
1414
npm \
1515
python3 \
16+
gcc \
17+
make \
1618
&& rm -rf /var/lib/apt/lists/*
1719

20+
# Install bash 3.2 from source (macOS ships bash 3.2; needed for awk-fallback tests)
21+
# SHA256 pinned for reproducibility (GPG sig also at bash-3.2.tar.gz.sig on ftp.gnu.org).
22+
RUN BASH32_SHA256="26c99025b59e30779300b68adb764f824974d267a4d7cc1b347d14a2393f9fb4" && \
23+
curl -sSfL -o /tmp/bash-3.2.tar.gz https://ftp.gnu.org/gnu/bash/bash-3.2.tar.gz \
24+
&& echo "$BASH32_SHA256 /tmp/bash-3.2.tar.gz" | sha256sum -c - \
25+
&& tar xz -C /tmp -f /tmp/bash-3.2.tar.gz \
26+
&& ARCH=$(uname -m) \
27+
&& case "$ARCH" in x86_64) TRIPLE="x86_64-pc-linux-gnu";; aarch64) TRIPLE="aarch64-unknown-linux-gnu";; *) TRIPLE="$ARCH-pc-linux-gnu";; esac \
28+
&& cd /tmp/bash-3.2 \
29+
&& ./configure --build="$TRIPLE" --prefix=/usr/local --without-bash-malloc >/dev/null 2>&1 \
30+
&& make -j"$(nproc)" >/dev/null 2>&1 \
31+
&& cp bash /usr/local/bin/bash3.2 \
32+
&& rm -rf /tmp/bash-3.2 /tmp/bash-3.2.tar.gz
33+
1834
# Install just
1935
RUN curl -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin
2036

@@ -34,4 +50,8 @@ WORKDIR /home/testuser
3450
# Copy the repo in (done as testuser for correct ownership)
3551
COPY --chown=testuser:testuser . /home/testuser/tmux-assistant-resurrect
3652

37-
ENTRYPOINT ["bash", "/home/testuser/tmux-assistant-resurrect/test/run-tests.sh"]
53+
# TEST_BASH: override bash used by scripts under test (save/restore).
54+
# "bash" (default) = system bash 5; "bash3.2" = bash 3.2 awk-fallback path.
55+
# The test harness itself always runs under bash 5 (explicit in ENTRYPOINT).
56+
ENV TEST_BASH="bash"
57+
ENTRYPOINT ["/bin/bash", "/home/testuser/tmux-assistant-resurrect/test/run-tests.sh"]

test/run-tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ set -euo pipefail
55

66
REPO_DIR="$HOME/tmux-assistant-resurrect"
77
JUNIT_FILE="${JUNIT_FILE:-/tmp/test-results/junit.xml}"
8+
echo "Test harness bash: $BASH_VERSION"
9+
echo "Scripts under test: $(${TEST_BASH:-bash} --version | head -1)"
10+
echo ""
811
PASS=0
912
FAIL=0
1013
ERRORS=""

0 commit comments

Comments
 (0)