mirror of
https://github.com/obra/superpowers.git
synced 2026-08-07 07:39:35 +00:00
5f8f500b1d
Register the Hermes YAML manifest alongside the existing JSON manifests. Route manifest reads and writes by extension through jq or Mike Farah yq v4, with field names and values passed as data. Preflight every present manifest before the mutating bump loop so a deterministic YAML read failure cannot leave earlier JSON manifests partially updated. Cover check, audit, bump, registry wiring, and byte-for-byte no-partial-write behavior with one focused fixture test.
77 lines
2.2 KiB
Bash
77 lines
2.2 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
SCRIPT_SOURCE="$REPO_ROOT/scripts/bump-version.sh"
|
|
TEST_ROOT="$(mktemp -d)"
|
|
|
|
cleanup() {
|
|
rm -rf "$TEST_ROOT"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
fail() {
|
|
echo "FAIL: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
make_fixture() {
|
|
local repo="$1"
|
|
local yaml_body="$2"
|
|
|
|
mkdir -p "$repo/scripts" "$repo/.hermes-plugin"
|
|
cp "$SCRIPT_SOURCE" "$repo/scripts/bump-version.sh"
|
|
cat >"$repo/.version-bump.json" <<'JSON'
|
|
{
|
|
"files": [
|
|
{ "path": "package.json", "field": "version" },
|
|
{ "path": ".hermes-plugin/plugin.yaml", "field": "version" }
|
|
],
|
|
"audit": { "exclude": [] }
|
|
}
|
|
JSON
|
|
cat >"$repo/package.json" <<'JSON'
|
|
{
|
|
"name": "fixture",
|
|
"version": "1.2.3"
|
|
}
|
|
JSON
|
|
printf '%s\n' "$yaml_body" >"$repo/.hermes-plugin/plugin.yaml"
|
|
}
|
|
|
|
happy_repo="$TEST_ROOT/happy"
|
|
make_fixture "$happy_repo" $'name: superpowers\nversion: 1.2.3'
|
|
|
|
/bin/bash "$happy_repo/scripts/bump-version.sh" --check >"$TEST_ROOT/check.out"
|
|
/bin/bash "$happy_repo/scripts/bump-version.sh" --audit >"$TEST_ROOT/audit.out"
|
|
/bin/bash "$happy_repo/scripts/bump-version.sh" 2.3.4 >"$TEST_ROOT/bump.out"
|
|
|
|
[[ "$(jq -r '.version' "$happy_repo/package.json")" == "2.3.4" ]] \
|
|
|| fail "JSON manifest was not bumped"
|
|
[[ "$(yq -r '.version' "$happy_repo/.hermes-plugin/plugin.yaml")" == "2.3.4" ]] \
|
|
|| fail "YAML manifest was not bumped"
|
|
|
|
jq -e '
|
|
any(.files[];
|
|
.path == ".hermes-plugin/plugin.yaml" and .field == "version")
|
|
' "$REPO_ROOT/.version-bump.json" >/dev/null \
|
|
|| fail "Hermes manifest is not registered"
|
|
|
|
invalid_repo="$TEST_ROOT/invalid"
|
|
make_fixture "$invalid_repo" $'name: superpowers\nversion: 123'
|
|
cp "$invalid_repo/package.json" "$TEST_ROOT/package.before"
|
|
cp "$invalid_repo/.hermes-plugin/plugin.yaml" "$TEST_ROOT/plugin.before"
|
|
|
|
if /bin/bash "$invalid_repo/scripts/bump-version.sh" 2.3.4 \
|
|
>"$TEST_ROOT/invalid.out" 2>&1; then
|
|
fail "bump accepted a non-string YAML version"
|
|
fi
|
|
|
|
cmp -s "$TEST_ROOT/package.before" "$invalid_repo/package.json" \
|
|
|| fail "JSON manifest changed before YAML validation failed"
|
|
cmp -s "$TEST_ROOT/plugin.before" "$invalid_repo/.hermes-plugin/plugin.yaml" \
|
|
|| fail "invalid YAML manifest changed"
|
|
|
|
echo "Version-bump tests passed"
|