Files
Kevin Veen-Birkenbach ccac936015 feat: port to Python and package as pip-installable distribution
Replaces main.sh with the 'cli-gnome-extension-manager' distribution in a src layout, shipping both the cli-gnome-extension-manager and the older goexma command.

sync_repository keeps the three states of the shell original apart: clone when the folder is missing, pull when it is a checkout, leave it alone otherwise, so a manually installed extension is never overwritten. build_extension still moves the checkout away before make install, but into a TemporaryDirectory instead of a fixed /tmp/<name>, which removes the collision between parallel runs and cleans up on abort.

Every step passes through the exit code of the failing tool, replacing the shell chain of || exit 1; a missing gnome-extensions aborts with exit 127. The e2e suite builds a real git repository, clones it with real git and runs real make install.

Adds --extensions-dir, unit, integration and container-based e2e tests, ruff and markdown/mermaid linting, CodeQL and Dependabot, and pins the core metadata to 2.4 so twine accepts the artifacts.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-14 14:41:17 +02:00

148 lines
6.1 KiB
Bash

#!/bin/sh
# gnome-extensions is stubbed on purpose: pulling in GNOME Shell would dwarf
# the package under test. git and make are the real binaries.
set -eu
fail() {
echo "FAIL: $1" >&2
exit 1
}
stub_gnome_extensions() {
mkdir -p /tmp/bin
printf '%s\n' "#!/bin/sh" 'echo "$@" >>/tmp/gnome.log' "$1" >/tmp/bin/gnome-extensions
chmod +x /tmp/bin/gnome-extensions
: >/tmp/gnome.log
}
make_source_repo() {
mkdir -p "$1"
echo '{"uuid": "ext@example"}' >"$1/metadata.json"
if [ "$2" = "with-makefile" ]; then
printf 'install:\n\ttouch /tmp/built.marker\n' >"$1/Makefile"
fi
git -C "$1" init -q -b main
git -C "$1" add -A
git -C "$1" -c user.email=e2e@example.com -c user.name=E2E commit -qm initial
}
MANAGER="$(command -v cli-gnome-extension-manager)" || fail "cli-gnome-extension-manager is not on PATH after install"
echo "ok: cli-gnome-extension-manager installed at ${MANAGER}"
command -v goexma >/dev/null || fail "the goexma alias is not on PATH after install"
echo "ok: goexma alias installed"
case "${MANAGER}" in
/usr/local/bin/*) ;;
*) fail "cli-gnome-extension-manager resolved to ${MANAGER}, outside the install prefix" ;;
esac
echo "ok: resolved from the installed package, not the source tree"
command -v git >/dev/null || fail "git is missing from the image"
command -v make >/dev/null || fail "make is missing from the image"
echo "ok: real git and make present"
cli-gnome-extension-manager --help | grep -q "GNOME shell extensions" || fail "--help does not describe the tool"
echo "ok: --help"
set +e
output="$(cli-gnome-extension-manager restart ext@example 2>&1)"
status=$?
set -e
[ "${status}" -eq 2 ] || fail "an unknown action exited ${status}, expected 2"
echo "${output}" | grep -q "invalid choice" || fail "unknown action message wrong"
echo "ok: an unknown action exits 2"
set +e
output="$(env PATH=/nonexistent-bin "${MANAGER}" disable ext@example 2>&1)"
status=$?
set -e
[ "${status}" -eq 127 ] || fail "missing gnome-extensions exited ${status}, expected 127"
echo "${output}" | grep -q "required command 'gnome-extensions' is not installed" || fail "missing gnome-extensions message wrong"
if echo "${output}" | grep -q "Traceback"; then
fail "missing gnome-extensions produced a traceback"
fi
echo "ok: missing gnome-extensions exits 127 with a clean message"
stub_gnome_extensions "exit 0"
make_source_repo /tmp/source with-makefile
env PATH="/tmp/bin:${PATH}" cli-gnome-extension-manager \
enable ext@example /tmp/source --extensions-dir /tmp/extensions >/tmp/first.log 2>&1 \
|| fail "the first enable run failed: $(cat /tmp/first.log)"
[ -f /tmp/built.marker ] || fail "make install did not run"
grep -q "enable ext@example" /tmp/gnome.log || fail "gnome-extensions enable was not called"
grep -q "Installation complete." /tmp/first.log || fail "the completion banner is missing"
echo "ok: real git clone, real make install, extension enabled"
stub_gnome_extensions "exit 0"
make_source_repo /tmp/source2 without-makefile
env PATH="/tmp/bin:${PATH}" cli-gnome-extension-manager \
enable plain@example /tmp/source2 --extensions-dir /tmp/extensions >/tmp/plain.log 2>&1 \
|| fail "the plain enable run failed: $(cat /tmp/plain.log)"
grep -q "No Makefile found" /tmp/plain.log || fail "the missing Makefile was not reported"
[ -f /tmp/extensions/plain@example/metadata.json ] || fail "the extension without a Makefile was not kept"
echo "ok: an extension without a Makefile stays installed"
env PATH="/tmp/bin:${PATH}" cli-gnome-extension-manager \
enable plain@example /tmp/source2 --extensions-dir /tmp/extensions >/tmp/second.log 2>&1 \
|| fail "the second enable run failed: $(cat /tmp/second.log)"
grep -q "Pulling changes from git..." /tmp/second.log || fail "the second run did not pull"
echo "ok: a second run pulls instead of cloning"
stub_gnome_extensions "exit 0"
set +e
env PATH="/tmp/bin:${PATH}" cli-gnome-extension-manager \
enable broken@example /nonexistent/repo --extensions-dir /tmp/extensions >/tmp/clone.log 2>&1
status=$?
set -e
[ "${status}" -ne 0 ] || fail "a failing git clone was reported as success"
[ ! -s /tmp/gnome.log ] || fail "gnome-extensions ran even though the clone failed"
[ ! -d /tmp/extensions/broken@example ] || fail "a failed clone left an extension folder behind"
echo "ok: a failing git clone stops before enabling and leaves nothing behind"
stub_gnome_extensions "exit 0"
mkdir -p /tmp/source3
echo '{"uuid": "bad@example"}' >/tmp/source3/metadata.json
printf 'install:\n\tfalse\n' >/tmp/source3/Makefile
git -C /tmp/source3 init -q -b main
git -C /tmp/source3 add -A
git -C /tmp/source3 -c user.email=e2e@example.com -c user.name=E2E commit -qm initial
set +e
env PATH="/tmp/bin:${PATH}" cli-gnome-extension-manager \
enable bad@example /tmp/source3 --extensions-dir /tmp/extensions >/tmp/build.log 2>&1
status=$?
set -e
[ "${status}" -ne 0 ] || fail "a failing make install was reported as success"
grep -q "Compilation failed." /tmp/build.log || fail "the build failure was not reported"
[ ! -s /tmp/gnome.log ] || fail "gnome-extensions ran even though the build failed"
echo "ok: a failing make install stops before enabling"
stub_gnome_extensions "exit 0"
mkdir -p /tmp/extensions/manual@example
echo '{"uuid": "manual@example"}' >/tmp/extensions/manual@example/metadata.json
env PATH="/tmp/bin:${PATH}" cli-gnome-extension-manager \
enable manual@example /tmp/source2 --extensions-dir /tmp/extensions >/tmp/manual.log 2>&1 \
|| fail "enabling a manually installed extension failed: $(cat /tmp/manual.log)"
grep -q "No git repository. Extension will not be updated." /tmp/manual.log \
|| fail "a non-git extension folder was not detected"
grep -q "enable manual@example" /tmp/gnome.log || fail "the manual extension was not enabled"
echo "ok: a manually installed extension is not overwritten but still enabled"
stub_gnome_extensions "exit 3"
set +e
env PATH="/tmp/bin:${PATH}" cli-gnome-extension-manager disable ext@example >/dev/null 2>&1
status=$?
set -e
[ "${status}" -eq 3 ] || fail "a failing gnome-extensions exited ${status}, expected 3"
echo "ok: a failing gnome-extensions propagates its exit code"
echo "ALL E2E CHECKS PASSED"