Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <run_id>`.

---

## Data requirements

The pipeline accepts two kinds of folder layout — use whichever matches how your experiment was recorded.
Expand Down Expand Up @@ -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:

Expand Down
54 changes: 54 additions & 0 deletions tests/test_tomo_process.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
54 changes: 54 additions & 0 deletions tomo_process
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# tomo_process --status <run_id>
# tomo_process --list
# tomo_process --cancel <run_id>
# tomo_process --upgrade

set -euo pipefail

Expand All @@ -32,6 +33,8 @@ Usage:
(jobs keep running; picks up updated scripts)
tomo_process --list List all runs
tomo_process --cancel <run_id> 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"
Expand Down Expand Up @@ -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 <<EOF

ERROR: the update changed the same lines as your local changes (conflict).
Your changes are safe in 'git stash list' (entry: tomo_process-upgrade).
Ask the maintainer for help before continuing.
EOF
exit 1
fi
fi

after="$(git rev-parse --short HEAD)"
if [[ "${before}" == "${after}" ]]; then
info "Already up to date (${after})."
else
info "Upgraded ${before} -> ${after}."
info "Runs already in progress keep the old code; to switch one over:"
info " tomo_process --restart <run_id>"
fi
}

# ── Dispatch ──────────────────────────────────────────────────────────────────
[[ $# -eq 0 ]] && { usage; exit 1; }

Expand All @@ -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 "$@" ;;
Expand Down
Loading