get.sh: install and update the stable channel, the latest published release; --edge follows main

The one command no longer resets the clone to origin/main: it installs the
latest published release, on a branch of its own (stable), and main becomes
the edge channel, opted into with --edge (back with --stable). The choice is
kept in ~/.config/qwen38/channel; a box installed before, on main, migrates at
its next update without downloading anything the tags do not already need.
The release is found from GitHub's release API, then the remote's tags, then
the tags the update itself fetched; nothing is touched when none answers.

The channels are exercised by a real git fixture with two tagged releases and
a curl shim standing in for the API: the update from N-1 to N, the switch to
edge and back, the fallbacks, the refusals. The older get.sh tests run on the
edge channel, which behaves exactly as get.sh always did.

Generated by Mistral Vibe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hasan Basbunar committed 2026-11-20 05:05:16 +01:00
1 parent 26a7912aa9
commit d7da3801cc
6 files changed
+373 -28

No files matched your search

+9
View File
@@ -915,6 +915,15 @@ jobs:
- name: get.sh guards (git fixture, stubbed installer)
run: python3 tests/test_get_sh.py
- name: get.sh channels (stable by default, N-1 updated to N, edge and back)
run: |
# The one command installs the stable channel now: the latest published release,
# not main (decision 1529, 2026-11-19). The fixture is a bare origin with two
# tagged releases, a box cloned at N-1, and a curl shim standing in for GitHub's
# release API: the update from N-1 to N, the switch to edge and back, and the
# fallbacks when the API answers nothing. No step here reaches the network.
python3 tests/test_get_sh_channels.py
- name: bench.sh names the lane it measures (fake engine)
run: python3 tests/test_bench_lane.py
+125 -27
View File
@@ -9,6 +9,8 @@
# prints the cockpit URL when it is done.
# Pass install.sh options after `bash -s --`, e.g.:
# curl -fsSL https://get.alzeo.ai | bash -s -- --no-service
# The channel: stable by default (the latest published release), --edge to follow main:
# curl -fsSL https://get.alzeo.ai | bash -s -- --edge
# Env overrides pass through (PORT=, HF_CACHE=, DIR= for a custom clone location).
# Everything is wrapped in main() so nothing runs on a partial download.
set -euo pipefail
@@ -62,6 +64,13 @@ main() {
esac
return 1
}
# The highest vX.Y.Z of what it reads, numbers compared left to right: sort -V is a GNU
# extension the BSD sort of a mac does not have, and plain sort reads v1.10 below v1.9.
highest_tag() {
awk '$0 ~ /^v[0-9]+\.[0-9]+(\.[0-9]+)?$/ { split(substr($0, 2), p, ".")
n = p[1] * 1000000 + p[2] * 1000 + p[3]
if (t == "" || n > m) { m = n; t = $0 } } END { print t }'
}
command -v git >/dev/null || { echo "ERROR: git is required (stock on DGX OS)." >&2; exit 1; }
# Case 1: running from inside an existing clone of this repo (any path) -> use it.
@@ -108,6 +117,35 @@ main() {
fi
echo "── Repo: $DIR"
# ── The channel: stable (the latest published release) by default, edge (main) opted into ──
# --stable and --edge are consumed here (never passed to install.sh) and the choice is kept in
# ~/.config/qwen38/channel: a file of the config dir, which no reset of the clone touches (a
# tracked file of the clone would be reset over, an untracked one copied aside by keep_aside).
# No file yet: stable, which is also what a box installed before this channel exists migrates
# to at its next update, from main, without downloading anything the tags do not already need.
CHANNEL_FILE="$HOME/.config/qwen38/channel"
CHANNEL=""; ARGS=()
for a in "$@"; do
case "$a" in
--stable) CHANNEL=stable ;;
--edge) CHANNEL=edge ;;
*) ARGS+=("$a") ;;
esac
done
if [ -z "$CHANNEL" ]; then
CHANNEL=stable
if [ -r "$CHANNEL_FILE" ]; then
case "$(tr -d '[:space:]' < "$CHANNEL_FILE")" in edge) CHANNEL=edge ;; esac
fi
fi
# the choice is written before anything moves: a run that fails later has still kept it,
# which is what the one who made it asked for (and the file is one word, read above)
if [ ! -s "$CHANNEL_FILE" ] || [ "$(tr -d '[:space:]' < "$CHANNEL_FILE" 2>/dev/null)" != "$CHANNEL" ]; then
mkdir -p "$HOME/.config/qwen38" && printf '%s\n' "$CHANNEL" > "$CHANNEL_FILE" \
|| echo "── NOTE: could not write the channel to $CHANNEL_FILE (this update still follows $CHANNEL)"
fi
git -C "$DIR" fetch -q origin main
# The release tags too. A fetch of main alone brings none, and the cockpit's release check
# and `git describe` read them: a box updated by this command kept naming the release it
@@ -116,14 +154,58 @@ main() {
git -C "$DIR" fetch -q --tags origin 2>/dev/null \
|| echo "── NOTE: the release tags did not all come (a tag of the same name exists here?); the update goes on"
# Must be on main (a detached HEAD or a side branch would silently pin an old version).
CUR=$(git -C "$DIR" symbolic-ref -q --short HEAD || echo DETACHED)
if [ "$CUR" != "main" ] && [ "${FORCE_UPDATE:-0}" != "1" ]; then
echo "ERROR: $DIR is on '$CUR', not 'main'; refusing to install from it." >&2
echo " rerun with FORCE_UPDATE=1 to switch to main (your branch/commit is kept)" >&2
exit 1
# What this update installs: origin/main on the edge channel, the latest published release on
# the stable one. Three sources in order (DESIGN, decision 1529): GitHub's own "latest
# release", the same answer the cockpit reads (published releases, prereleases excluded,
# anonymous, no token); then the tags of the remote itself, which no API budget limits; then
# what the fetch above already brought, for a box whose API call and ls-remote both fail.
TAG=""
if [ "$CHANNEL" = stable ]; then
if command -v curl >/dev/null 2>&1; then
TAG=$(curl -fsSL --max-time 8 -H 'Accept: application/vnd.github+json' \
https://api.github.com/repos/hasso5703/alzeo/releases/latest 2>/dev/null \
| sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\(v[0-9][0-9.]*\)".*/\1/p') || TAG=""
fi
if [ -z "$TAG" ]; then
TAG=$(git -C "$DIR" ls-remote --tags origin 2>/dev/null \
| sed -n 's#.*[[:space:]]refs/tags/\(v[0-9]*\.[0-9]*\(\.[0-9]*\)\)$#\1#p' | highest_tag) || TAG=""
fi
if [ -z "$TAG" ]; then
TAG=$(git -C "$DIR" tag -l | sed -n 's/^\(v[0-9]*\.[0-9]*\(\.[0-9]*\)\)$/\1/p' | highest_tag)
fi
# the tag must be one this clone has: the API can name a release the fetch above did not
# bring (its fetch of the tags failed, or the cache of a redirect served an older list)
if [ -n "$TAG" ] && ! git -C "$DIR" rev-parse -q --verify "refs/tags/$TAG" >/dev/null 2>&1; then
git -C "$DIR" fetch -q origin "refs/tags/$TAG:refs/tags/$TAG" 2>/dev/null || true
fi
if [ -z "$TAG" ] || ! git -C "$DIR" rev-parse -q --verify "refs/tags/$TAG" >/dev/null 2>&1; then
echo "ERROR: could not find the latest published release of this repo (no answer from GitHub's" >&2
echo " release API, none from the remote's tags, none in this clone). Nothing was touched." >&2
echo " try again online, or follow main instead: bash -s -- --edge" >&2
exit 1
fi
TARGET_BRANCH=stable
TARGET_REF="refs/tags/$TAG"
echo "── Channel: stable (the latest published release, $TAG)"
else
TARGET_BRANCH=main
TARGET_REF=origin/main
echo "── Channel: edge (main)"
fi
# Must be on a branch this script follows (a detached HEAD or a side branch would silently
# pin an old version): the channel's own, or the other one, which a switch of channel or a
# box installed before the stable channel existed is on.
CUR=$(git -C "$DIR" symbolic-ref -q --short HEAD || echo DETACHED)
case "$CUR" in
main|stable) ;;
*) if [ "${FORCE_UPDATE:-0}" != "1" ]; then
echo "ERROR: $DIR is on '$CUR', not 'main' or 'stable'; refusing to install from it." >&2
echo " rerun with FORCE_UPDATE=1 to switch to $TARGET_BRANCH (your branch/commit is kept)" >&2
exit 1
fi ;;
esac
# Invariant: if this script completes, you ARE on the latest origin/main.
# Only TRACKED modifications can make the checkout stale or altered. Untracked
# files cannot, and `git reset --hard` below leaves them alone, so blocking on
@@ -202,41 +284,57 @@ main() {
printf '%s' "$KEPTLIST" | sed -n '1,5s/^/ /p'
[ "$NKEPT" -le 5 ] || echo " ... and $((NKEPT - 5)) more, in that folder"
}
# Off main under FORCE_UPDATE, the switch comes after the stash, and a detached HEAD's
# commit is put on a branch first. Switched first, a change that conflicted with main
# ended the run (rc 128), and a commit made on a detached HEAD was left on no branch
# (found in review, 2026-09-24).
if [ "$CUR" != "main" ]; then
# Off the target branch, the switch comes after the stash, and a detached HEAD's
# commit is put on a branch first. Switched first, a change that conflicted with the
# target ended the run (rc 128), and a commit made on a detached HEAD was left on no branch
# (found in review, 2026-09-24). It runs under FORCE_UPDATE from a side branch, and without
# it for a change of channel or a box on main taking the stable one for the first time.
if [ "$CUR" != "$TARGET_BRANCH" ]; then
if [ "$CUR" = "DETACHED" ]; then
BK="backup-$(git -C "$DIR" rev-parse --short HEAD)"
git -C "$DIR" branch -f "$BK" >/dev/null
echo "── FORCE_UPDATE=1: the detached commit is kept on branch '$BK'"
fi
# the checkout below writes local main over ignored files too, and the reset then origin/main: both are looked
# at from here, before either (code review of v1.45.0)
if git -C "$DIR" rev-parse -q --verify main >/dev/null; then keep_aside_against origin/main main
else keep_aside_against origin/main; fi
echo "── FORCE_UPDATE=1: switching from '$CUR' to main (your branch is kept)"
# forced: the tracked changes are stashed above and every file of the user's in its way copied aside, and an
# untracked one at a path main tracks made the checkout fail, then its fallback (-b main: "a branch named main
# already exists"), rc 128 (code review of v1.45.0)
if git -C "$DIR" rev-parse -q --verify main >/dev/null; then git -C "$DIR" checkout -qf main
else git -C "$DIR" checkout -qfb main origin/main; fi
# a stable branch that holds commits of its own (past origin/main, which a stable clone at
# its tag never has) would be moved by the checkout below: they are kept on a branch first
if [ "$TARGET_BRANCH" = stable ] && git -C "$DIR" rev-parse -q --verify stable >/dev/null 2>&1; then
if [ "$(git -C "$DIR" rev-list --count origin/main..stable 2>/dev/null || echo 1)" != "0" ]; then
BK="backup-$(git -C "$DIR" rev-parse --short stable)"
git -C "$DIR" branch -f "$BK" stable >/dev/null
echo "── the branch 'stable' held commits of its own: kept on branch '$BK'"
fi
fi
# the checkout below writes the target branch over ignored files too, and the reset then
# the release: both are looked at from here, before either (code review of v1.45.0)
if git -C "$DIR" rev-parse -q --verify "$TARGET_BRANCH" >/dev/null 2>&1; then
keep_aside_against "$TARGET_REF" "$TARGET_BRANCH"
else
keep_aside_against "$TARGET_REF"
fi
echo "── switching from '$CUR' to $TARGET_BRANCH (your branch is kept)"
# forced from a side branch, or a change of channel: the tracked changes are stashed above
# and every file of the user's in its way copied aside
if [ "$TARGET_BRANCH" = main ]; then
if git -C "$DIR" rev-parse -q --verify main >/dev/null 2>&1; then git -C "$DIR" checkout -qf main
else git -C "$DIR" checkout -qfb main origin/main; fi
else
git -C "$DIR" checkout -qB stable "$TARGET_REF"
fi
fi
AHEAD=$(git -C "$DIR" rev-list --count origin/main..HEAD 2>/dev/null || echo 1)
if [ "$AHEAD" != "0" ]; then
if [ "${FORCE_UPDATE:-0}" = "1" ]; then
BK="backup-$(git -C "$DIR" rev-parse --short HEAD)"
git -C "$DIR" branch -f "$BK" >/dev/null
echo "── FORCE_UPDATE=1: local commits kept on branch '$BK', resetting to origin/main"
echo "── FORCE_UPDATE=1: local commits kept on branch '$BK', resetting to $TARGET_BRANCH"
else
echo "ERROR: $DIR has local commits not on origin/main, refusing to install a stale version." >&2
echo " keep your commits aside : FORCE_UPDATE=1 then rerun (they stay on a backup branch)" >&2
exit 1
fi
fi
# Copied aside, then said: here when the clone is on main; off main, before the switch above.
[ "$CUR" != "main" ] || keep_aside_against origin/main
# Copied aside, then said: here when the clone is on the target branch; off it, before the switch above.
[ "$CUR" != "$TARGET_BRANCH" ] || keep_aside_against "$TARGET_REF"
# Untracked files are kept, but say so: neither those copied aside, which the release's own replace, nor a folder
# the release puts a file in place of (drafts/, removed by the reset: code review of v1.45.0). A folder untracked
# whole is named once (--directory): a .venv-mirror/ in the clone, as MIRROR.md makes one, listed its thousands of
@@ -257,14 +355,14 @@ main() {
fi
# Tree verified clean and no local commits (or backed up): hard sync is lossless
# and, unlike ff-only, immune to shallow-clone ancestry gaps.
git -C "$DIR" reset -q --hard origin/main
git -C "$DIR" reset -q --hard "$TARGET_REF"
echo "── At: $(git -C "$DIR" log -1 --format='%h %s')"
cd "$DIR"
# exec from a real file. stdin is still the pipe this script came through (read to
# its end by now), so nothing in install.sh may read from it; sudo prompts on the tty
# it opens itself.
exec bash ./install.sh "$@"
# it opens itself. The channel flags never reach install.sh: they were consumed above.
exec bash ./install.sh ${ARGS[@]+"${ARGS[@]}"}
}
main "$@"
+6 -1
View File
@@ -820,12 +820,17 @@ class TheWholeScripts(unittest.TestCase):
'case "$*" in\n'
' *"remote get-url origin"*) echo https://github.com/hasso5703/dgx-spark-qwen38 ;;\n'
' *"symbolic-ref"*) echo main ;;\n'
' *"ls-remote --tags"*) echo "0000000 refs/tags/v1.55.0" ;;\n'
' *"rev-list --count"*) echo 0 ;;\n'
' *"log -1"*) echo "abc1234 the release" ;;\n'
'esac\nexit 0\n')
(box.bin / "git").chmod(0o755)
# the stable channel's release API, answered as offline: get.sh falls back to the
# remote's tags, which the fake git above serves (no step of this test reaches the network)
(box.bin / "curl").write_text("#!/bin/bash\nexit 22\n")
(box.bin / "curl").chmod(0o755)
env, record = wall.fenced_env(first=str(box.bin), DIR=str(clone))
r = subprocess.run(["bash", wall.walled("get.sh", at=' exec bash ./install.sh "$@"\n'), "--help"],
r = subprocess.run(["bash", wall.walled("get.sh", at=' exec bash ./install.sh ${ARGS[@]+"${ARGS[@]}"}\n'), "--help"],
capture_output=True, text=True, env=env, cwd=wall.cwd(), timeout=60,
stdin=subprocess.DEVNULL, start_new_session=True)
out = r.stdout + r.stderr
+6
View File
@@ -49,6 +49,12 @@ def fixture(base):
os.chmod(os.path.join(work, "install.sh"), 0o755)
git("add", "-A", cwd=work); git("commit", "-qm", "v1", cwd=work)
git("push", "-q", "origin", "main", cwd=work)
# the edge channel: these tests exercise the update machinery (the refusal of a stale or
# altered clone, the copies aside, the untracked files), which edge runs exactly as get.sh
# always did on main. The stable channel, the default, has its own file: test_get_sh_channels.py
os.makedirs(os.path.join(base, ".config", "qwen38"))
with open(os.path.join(base, ".config", "qwen38", "channel"), "w") as f:
f.write("edge\n")
return origin, work
+222
View File
@@ -0,0 +1,222 @@
#!/usr/bin/env python3
"""get.sh's channels, offline, against a real git fixture (decision 1529, 2026-11-19).
The one command installs and updates the stable channel: the latest published release,
not main anymore. --edge opts a box into main, --stable back, and the choice is kept in
~/.config/qwen38/channel. The fixture is a bare origin whose path carries the project's
slug (so get.sh's origin check passes), a box cloned from it one release behind, and a
curl shim on PATH: the release API is answered from a file, never the network, and its
failure is what exercises the ls-remote fallback. This is the update from N-1 to N the
CI runs on every push."""
import os
import shutil
import subprocess
import sys
import tempfile
REPO_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
GET = os.path.join(REPO_DIR, "get.sh")
STUB = '#!/usr/bin/env bash\necho "INSTALL_RAN args=$*"\n'
# git here never inherits the variables that point it at a repository (GIT_DIR, GIT_WORK_TREE,
# GIT_INDEX_FILE, the rest of `git rev-parse --local-env-vars`: a git hook or `rebase -x` exports
# them), which would turn the fixture's commands onto that repository, and keeps the others,
# GIT_CONFIG_GLOBAL among them, which a caller may set to keep a personal config out
# (code review, 2026-11-01)
LOCAL_VARS = set(subprocess.run(["git", "rev-parse", "--local-env-vars"], capture_output=True, text=True).stdout.split()) or {
"GIT_ALTERNATE_OBJECT_DIRECTORIES", "GIT_CONFIG", "GIT_CONFIG_PARAMETERS", "GIT_CONFIG_COUNT", "GIT_OBJECT_DIRECTORY",
"GIT_DIR", "GIT_WORK_TREE", "GIT_IMPLICIT_WORK_TREE", "GIT_GRAFT_FILE", "GIT_INDEX_FILE", "GIT_NO_REPLACE_OBJECTS",
"GIT_REPLACE_REF_BASE", "GIT_PREFIX", "GIT_SHALLOW_FILE", "GIT_COMMON_DIR"}
CLEAN = {k: v for k, v in os.environ.items() if k not in LOCAL_VARS}
def git(*a, cwd, check=True):
return subprocess.run(["git", *a], cwd=cwd, capture_output=True, text=True, check=check, env=CLEAN)
def fixture(base):
"""A bare 'origin' whose URL carries the slug, a publisher clone, and the box: a clone of
the origin as it stands, which is main at release N-1 once the publisher moves it to N."""
origin = os.path.join(base, "hasso5703", "dgx-spark-qwen38.git")
os.makedirs(origin)
git("init", "-q", "--bare", "-b", "main", ".", cwd=origin)
pub = os.path.join(base, "pub")
git("clone", "-q", origin, pub, cwd=base)
for k, v in (("user.email", "t@t"), ("user.name", "t")):
git("config", k, v, cwd=pub)
with open(os.path.join(pub, "install.sh"), "w") as f:
f.write(STUB)
os.chmod(os.path.join(pub, "install.sh"), 0o755)
git("add", "-A", cwd=pub); git("commit", "-qm", "the N-1 release", cwd=pub)
git("tag", "v1.54.0", cwd=pub)
git("push", "-q", "origin", "main", "v1.54.0", cwd=pub)
box = os.path.join(base, "box")
git("clone", "-q", origin, box, cwd=base)
for k, v in (("user.email", "t@t"), ("user.name", "t")):
git("config", k, v, cwd=box)
return pub, box
def publish(pub, subject, tag):
"""The next release on main, tagged: what the stable channel updates to."""
with open(os.path.join(pub, "CHANGELOG.md"), "a") as f:
f.write(f"## {tag}\n{subject}\n")
git("add", "-A", cwd=pub); git("commit", "-qm", subject, cwd=pub)
git("tag", tag, cwd=pub)
git("push", "-q", "origin", "main", tag, cwd=pub)
return git("rev-parse", "HEAD", cwd=pub).stdout.strip()
def curl_shim(base, tag=None):
"""A curl first on PATH: the release API answering `tag`, or failing (its anonymous budget
spent, no network), which is what sends get.sh to the remote's tags. The real curl never
runs, so no test here reaches the network."""
bin_dir = os.path.join(base, "bin")
os.makedirs(bin_dir, exist_ok=True)
shim = os.path.join(bin_dir, "curl")
with open(shim, "w") as f:
if tag:
f.write('#!/usr/bin/env bash\nprintf \'{"tag_name":"%s"}\\n\' "' + tag + '"\n')
else:
f.write("#!/usr/bin/env bash\nexit 22\n")
os.chmod(shim, 0o755)
return bin_dir
def isolated(base, bin_dir, extra=None):
"""What every run of get.sh here gets: PATH (the shim's folder first) and nothing else of
this shell's environment, English messages, the fixture's folder for HOME, git with no
network protocol but local paths, and no repository looked for above that folder. So no
run reaches the network, a real clone of this repo or a real installer."""
return {"PATH": bin_dir + os.pathsep + os.environ["PATH"], "LANG": "C.UTF-8", "HOME": base,
"GIT_ALLOW_PROTOCOL": "file", "GIT_CEILING_DIRECTORIES": os.path.dirname(base), **(extra or {})}
def run_get(box, bin_dir, args=(), env_extra=None):
base = os.path.dirname(os.path.abspath(box))
return subprocess.run(["bash", GET, *args], cwd=base, capture_output=True, text=True,
env=isolated(base, bin_dir, env_extra) | {"DIR": box})
def state(box, *a):
return git(*a, cwd=box).stdout.strip()
def main() -> None:
base = tempfile.mkdtemp()
try:
pub, box = fixture(base)
channel_file = os.path.join(base, ".config", "qwen38", "channel")
# 1. A box on main at N-1, no channel file: the update takes the stable channel, the
# latest published release, on a branch of its own. The old code stayed on main and
# reset to its tip: this is the migration of every box installed before.
n = publish(pub, "the N release", "v1.55.0")
r = run_get(box, curl_shim(base, "v1.55.0"))
assert r.returncode == 0, f"the first stable update failed: {r.stderr}"
assert "INSTALL_RAN" in r.stdout, r.stdout
assert "Channel: stable" in r.stdout and "v1.55.0" in r.stdout, r.stdout
assert state(box, "symbolic-ref", "-q", "--short", "HEAD") == "stable", "not on the stable branch"
assert state(box, "rev-parse", "HEAD") == n, "not at the release the tag names"
assert open(channel_file).read().strip() == "stable", "the channel file was not written"
assert state(box, "rev-parse", "--short", "main") == state(box, "rev-parse", "--short", "v1.54.0"), \
"the main branch was moved by a stable update"
# 2. The update from N-1 to N on the stable branch: a new release out, the same command.
n1 = publish(pub, "the N+1 release", "v1.56.0")
r = run_get(box, curl_shim(base, "v1.56.0"))
assert r.returncode == 0 and "INSTALL_RAN" in r.stdout, f"the stable update failed: {r.stderr}"
assert state(box, "symbolic-ref", "-q", "--short", "HEAD") == "stable"
assert state(box, "rev-parse", "HEAD") == n1, "the stable clone did not move to the new release"
# 3. --edge: main, and the choice kept.
r = run_get(box, curl_shim(base, "v1.56.0"), args=["--edge"])
assert r.returncode == 0 and "Channel: edge" in r.stdout, r.stdout + r.stderr
assert state(box, "symbolic-ref", "-q", "--short", "HEAD") == "main"
assert state(box, "rev-parse", "HEAD") == n1, "edge did not install main's tip"
assert open(channel_file).read().strip() == "edge", "the edge choice was not kept"
# 4. --stable: back to the latest published release, on the stable branch.
r = run_get(box, curl_shim(base, "v1.56.0"), args=["--stable"])
assert r.returncode == 0 and "INSTALL_RAN" in r.stdout, f"back to stable failed: {r.stderr}"
assert state(box, "symbolic-ref", "-q", "--short", "HEAD") == "stable"
assert state(box, "rev-parse", "HEAD") == n1
assert open(channel_file).read().strip() == "stable"
# 5. The channel flags never reach install.sh; everything else does.
r = run_get(box, curl_shim(base, "v1.56.0"), args=["--edge", "--no-service"])
assert r.returncode == 0, r.stderr
assert "INSTALL_RAN args=--no-service" in r.stdout, r.stdout
run_get(box, curl_shim(base, "v1.56.0"), args=["--stable"])
# 6. The release API failing (no network, its anonymous budget spent): the remote's own
# tags answer, which no API limit touches.
n2 = publish(pub, "the N+2 release", "v1.57.0")
r = run_get(box, curl_shim(base))
assert r.returncode == 0 and "INSTALL_RAN" in r.stdout, f"the ls-remote fallback failed: {r.stderr}"
assert state(box, "rev-parse", "HEAD") == n2, "the fallback did not find the newest tag"
# 7. A channel file that says nothing get.sh knows: stable, the default.
os.makedirs(os.path.dirname(channel_file), exist_ok=True)
with open(channel_file, "w") as f:
f.write("nonsense\n")
r = run_get(box, curl_shim(base, "v1.57.0"))
assert r.returncode == 0 and "Channel: stable" in r.stdout, r.stdout + r.stderr
assert state(box, "symbolic-ref", "-q", "--short", "HEAD") == "stable"
# 8. A commit of the user's own on the stable branch: the same refusal as on main.
with open(os.path.join(box, "my-change.txt"), "w") as f:
f.write("mine\n")
git("add", "my-change.txt", cwd=box); git("commit", "-qm", "mine", cwd=box)
r = run_get(box, curl_shim(base, "v1.57.0"))
assert r.returncode == 1, "a local commit on stable did not stop the update"
assert "local commits not on origin/main" in r.stderr, r.stderr
# and --edge leaves the commit where it is, on the stable branch, and installs main
r = run_get(box, curl_shim(base, "v1.57.0"), args=["--edge"])
assert r.returncode == 0 and "INSTALL_RAN" in r.stdout, f"the switch to edge failed: {r.stderr}"
assert state(box, "symbolic-ref", "-q", "--short", "HEAD") == "main"
assert state(box, "rev-list", "--count", "origin/main..stable") == "1", \
"the commit left on the stable branch was lost by the switch to edge"
# a stable branch that holds commits of its own is never moved without a backup either
r = run_get(box, curl_shim(base, "v1.57.0"), args=["--stable"])
assert r.returncode == 0 and "kept on branch" in r.stdout, r.stdout + r.stderr
assert state(box, "for-each-ref", "--format=%(refname:short)", "refs/heads/backup-*"), \
"no backup branch keeps the commit the stable branch held"
assert state(box, "symbolic-ref", "-q", "--short", "HEAD") == "stable"
assert state(box, "rev-parse", "HEAD") == n2, "stable did not return to the release"
# 9. A modified tracked file on stable: the same refusal as on main.
with open(os.path.join(box, "install.sh"), "a") as f:
f.write("# touched\n")
r = run_get(box, curl_shim(base, "v1.57.0"))
assert r.returncode == 1 and "modified tracked files" in r.stderr, r.stderr
git("checkout", "--", "install.sh", cwd=box)
# 10. No published release to find (a repo with no tag, the API down): nothing is touched.
bare = os.path.join(base, "hasso5703", "alzeo.git")
os.makedirs(bare)
git("init", "-q", "--bare", "-b", "main", ".", cwd=bare)
empty = os.path.join(base, "empty")
git("clone", "-q", bare, empty, cwd=base)
with open(os.path.join(empty, "install.sh"), "w") as f:
f.write(STUB)
os.chmod(os.path.join(empty, "install.sh"), 0o755)
git("add", "-A", cwd=empty); git("commit", "-qm", "no release yet", cwd=empty)
git("push", "-q", "origin", "main", cwd=empty)
before = state(empty, "rev-parse", "HEAD")
r = run_get(empty, curl_shim(base))
assert r.returncode == 1, "a repo with no release updated anyway"
assert "could not find the latest published release" in r.stderr, r.stderr
assert "Nothing was touched" in r.stderr, r.stderr
assert state(empty, "rev-parse", "HEAD") == before, "the clone moved"
assert state(empty, "symbolic-ref", "-q", "--short", "HEAD") == "main", "the clone left main"
assert not state(empty, "branch", "--list", "stable"), "a stable branch was created"
print("test_get_sh_channels: OK")
finally:
shutil.rmtree(base, ignore_errors=True)
if __name__ == "__main__":
sys.exit(main())
+5
View File
@@ -56,6 +56,11 @@ class Fixture(unittest.TestCase):
def run_get(self, force=True):
home = self.base / "home"
home.mkdir(exist_ok=True)
# the edge channel: these tests exercise the update machinery (the stash, the copies
# aside, the backup branches), which edge runs exactly as get.sh always did on main.
# The stable channel, the default, has its own file: test_get_sh_channels.py
(home / ".config" / "qwen38").mkdir(parents=True, exist_ok=True)
(home / ".config" / "qwen38" / "channel").write_text("edge\n")
env = {"PATH": os.environ["PATH"], "HOME": str(home), "DIR": str(self.work), "GIT_ALLOW_PROTOCOL": "file"}
if force:
env["FORCE_UPDATE"] = "1"