From ea6f921d5ee76c8ab627659784f3aff1c092a5c4 Mon Sep 17 00:00:00 2001 From: RaghavaAlajangi Date: Mon, 26 Oct 2026 16:06:57 +0100 Subject: [PATCH 1/3] enh: add tomo_process --upgrade to pull updates and keep local edits --- README.md | 12 +++++++++++- tomo_process | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2cea496..b024624 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,16 @@ tomo_process --resume tomo_20260729_143201 # continue from where it stopped --- +## Updating to the latest version + +```bash +tomo_process --upgrade +``` + +This pulls the newest code and keeps your local edits (such as the email in `config.sh`). If the update ever conflicts with your edits, your changes stay safe in `git stash list` and the command tells you so. Runs already in progress keep using the old code until you run `tomo_process --restart `. + +--- + ## Data requirements The pipeline accepts two kinds of folder layout — use whichever matches how your experiment was recorded. @@ -448,7 +458,7 @@ Shell tests need only bash (`squeue`, `rsync`, `sbatch` and `matlab` are mocked) | `tests/test_orchestrator.sh` | Failure handling in `scripts/orchestrator.sh`: retry/bisection, salvage copy, lost-job detection, TIFF index | | `tests/test_submit_chunk.sh` | Staging and submission: background/sample copy, skipped files, job-script filling, TIFF offset/index | | `tests/test_job_template.sh` | The real `scripts/bash_template.sh` against a fake `matlab`: DONE/FAIL markers, Stage 1 crash handling, SIGTERM | -| `tests/test_tomo_process.sh` | `tomo_process --restart/--resume/--cancel` and argument handling | +| `tests/test_tomo_process.sh` | `tomo_process --restart/--resume/--cancel/--upgrade` and argument handling | MATLAB unit tests run automatically if `matlab` is on `PATH`, or manually with `runtests('tests')` from the repo root: diff --git a/tomo_process b/tomo_process index 66e9d6b..f07fb20 100644 --- a/tomo_process +++ b/tomo_process @@ -10,6 +10,7 @@ # tomo_process --status # tomo_process --list # tomo_process --cancel +# tomo_process --upgrade set -euo pipefail @@ -32,6 +33,8 @@ Usage: (jobs keep running; picks up updated scripts) tomo_process --list List all runs tomo_process --cancel Cancel an active run + tomo_process --upgrade Update this installation to the latest code + (keeps your local edits, e.g. config.sh) Examples: tomo_process --path "ProjectA/20260715_experiment" @@ -511,6 +514,56 @@ cmd_restart() { cmd_resume "${run_id}" } +# ── Sub-command: upgrade ────────────────────────────────────────────────────── +# Pull the latest code while keeping local edits (e.g. EMAIL in config.sh): +# stash them, fast-forward, re-apply. Only the stash created here is touched. +cmd_upgrade() { + command -v git &>/dev/null || die "git is not installed" + cd "${SCRIPT_DIR}" + git rev-parse --is-inside-work-tree &>/dev/null \ + || die "${SCRIPT_DIR} is not a git checkout — cannot upgrade" + + local before after stashed=0 + before="$(git rev-parse --short HEAD)" + + if [[ -n "$(git status --porcelain --untracked-files=no)" ]]; then + info "Saving your local changes ..." + git stash push -m "tomo_process-upgrade" >/dev/null || die "could not stash local changes" + stashed=1 + fi + + info "Pulling latest code ..." + if ! git pull --ff-only; then + if [[ "${stashed}" -eq 1 ]]; then + git stash pop >/dev/null && info "Your local changes were restored." + fi + die "git pull failed — nothing was upgraded. Ask the maintainer for help." + fi + + if [[ "${stashed}" -eq 1 ]]; then + if git stash pop >/dev/null; then + info "Your local changes were re-applied." + else + cat >&2 < ${after}." + info "Runs already in progress keep the old code; to switch one over:" + info " tomo_process --restart " + fi +} + # ── Dispatch ────────────────────────────────────────────────────────────────── [[ $# -eq 0 ]] && { usage; exit 1; } @@ -519,6 +572,7 @@ case "$1" in --list) cmd_list ;; --resume) [[ $# -ge 2 ]] || die "--resume requires a run_id"; cmd_resume "$2" ;; --restart) [[ $# -ge 2 ]] || die "--restart requires a run_id"; cmd_restart "$2" ;; + --upgrade) cmd_upgrade ;; --status) [[ $# -ge 2 ]] || die "--status requires a run_id"; cmd_status "$2" ;; --cancel) [[ $# -ge 2 ]] || die "--cancel requires a run_id"; cmd_cancel "$2" ;; *) cmd_start "$@" ;; From d7acc45f87e4f3442096513df039829a38b86ccf Mon Sep 17 00:00:00 2001 From: RaghavaAlajangi Date: Mon, 26 Oct 2026 16:06:57 +0100 Subject: [PATCH 2/3] test: cover tomo_process --upgrade --- tests/test_tomo_process.sh | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/test_tomo_process.sh b/tests/test_tomo_process.sh index 8a5dede..804b013 100644 --- a/tests/test_tomo_process.sh +++ b/tests/test_tomo_process.sh @@ -121,4 +121,58 @@ test_no_arguments_prints_usage_and_fails() { assert_contains "${TEST_DIR}/out" "Usage:" } +# ── --upgrade (real git repos: an "origin" plus a user clone) ───────────────── +upgrade_setup() { + die() { echo "ERROR: $*" >&2; exit 1; } + info() { echo "[tomo_process] $*"; } + load_fns cmd_upgrade + g="git -c user.name=t -c user.email=t@example.org -c core.autocrlf=false" + ORIGIN="${TEST_DIR}/origin"; SCRIPT_DIR="${TEST_DIR}/clone" + git init -q "${ORIGIN}" + echo 'EMAIL=""' > "${ORIGIN}/config.sh"; echo v1 > "${ORIGIN}/code.txt" + ( cd "${ORIGIN}" && git add . && ${g} commit -qm one ) + git clone -q "${ORIGIN}" "${SCRIPT_DIR}" + GIT_PUBLISH() { # file content: commit a change upstream + ( cd "${ORIGIN}" && echo "$2" > "$1" && git add . && ${g} commit -qm up ) + } +} +test_upgrade_pulls_and_keeps_local_edits() { + upgrade_setup + echo 'EMAIL="me@example.org"' > "${SCRIPT_DIR}/config.sh" + GIT_PUBLISH code.txt v2 + ( cmd_upgrade ) > "${TEST_DIR}/out" 2>&1 + assert_eq "v2" "$(cat "${SCRIPT_DIR}/code.txt")" + assert_contains "${SCRIPT_DIR}/config.sh" 'me@example.org' + [[ -z "$(git -C "${SCRIPT_DIR}" stash list)" ]] # nothing left behind +} +test_upgrade_with_no_local_edits() { + upgrade_setup + GIT_PUBLISH code.txt v2 + ( cmd_upgrade ) > "${TEST_DIR}/out" 2>&1 + assert_eq "v2" "$(cat "${SCRIPT_DIR}/code.txt")" +} +test_upgrade_when_already_up_to_date() { + upgrade_setup + ( cmd_upgrade ) > "${TEST_DIR}/out" 2>&1 + assert_contains "${TEST_DIR}/out" "Already up to date" +} +test_upgrade_conflict_keeps_changes_in_stash() { + upgrade_setup + echo 'EMAIL="me@example.org"' > "${SCRIPT_DIR}/config.sh" + GIT_PUBLISH config.sh 'EMAIL="other"' + ( cmd_upgrade ) > "${TEST_DIR}/out" 2>&1 && return 1 + assert_contains "${TEST_DIR}/out" "conflict" + git -C "${SCRIPT_DIR}" stash list | grep -q tomo_process-upgrade +} +test_upgrade_outside_git_checkout_fails() { + upgrade_setup + rm -rf "${SCRIPT_DIR}/.git" + ( cmd_upgrade ) > "${TEST_DIR}/out" 2>&1 && return 1 + assert_contains "${TEST_DIR}/out" "not a git checkout" +} +test_help_lists_upgrade() { + bash "${REPO_ROOT}/tomo_process" --help > "${TEST_DIR}/out" 2>&1 + assert_contains "${TEST_DIR}/out" "--upgrade" +} + run_all "tomo_process" From b78ab8120883467a623caddbc6eb31618e7e1cb0 Mon Sep 17 00:00:00 2001 From: RaghavaAlajangi Date: Mon, 26 Oct 2026 16:06:57 +0100 Subject: [PATCH 3/3] ci: run shell tests on GitHub Actions --- .github/workflows/tests.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..7b36652 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,15 @@ +name: Tests + +on: + push: + branches: [main] + pull_request: + +jobs: + shell-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # MATLAB tests are skipped automatically (no matlab on PATH) + - name: Run tests + run: bash tests/run_tests.sh