From 9cc418c68f243e9cd29ff1524629d579a0dfd026 Mon Sep 17 00:00:00 2001 From: Seth Freiberg Date: Wed, 29 Apr 2026 10:18:12 -0400 Subject: [PATCH] feat: add compute-version.sh + bats tests Emits -seth to stdout. Pure logic, no side effects. 5/5 bats tests pass; output verified as 3.99-master618-seth1. Co-Authored-By: Claude Sonnet 4.6 --- scripts/compute-version.sh | 15 +++++++ tests-impl/test-compute-version.bats | 58 ++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100755 scripts/compute-version.sh create mode 100644 tests-impl/test-compute-version.bats diff --git a/scripts/compute-version.sh b/scripts/compute-version.sh new file mode 100755 index 0000000..a32938a --- /dev/null +++ b/scripts/compute-version.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# Emit "-seth" version string to stdout. +# Pure logic: no side effects. +# +# CALLER RESPONSIBILITY (per spec §5.4): the local tag db must be fresh. +# If invoked outside the release flow, run `git fetch origin --tags` first +# or risk a stale value. +# +# Spec: sethlabels-docs/specs/2026-04-29-packaging-design.md §5.4 (D4) +set -euo pipefail + +upstream_tag=$(git describe --tags --abbrev=0 upstream/master) +existing_count=$(git tag --list "${upstream_tag}-seth*" | wc -l | tr -d ' ') +next_n=$((existing_count + 1)) +echo "${upstream_tag}-seth${next_n}" diff --git a/tests-impl/test-compute-version.bats b/tests-impl/test-compute-version.bats new file mode 100644 index 0000000..7a84026 --- /dev/null +++ b/tests-impl/test-compute-version.bats @@ -0,0 +1,58 @@ +#!/usr/bin/env bats + +# Tests for scripts/compute-version.sh +# Invokes the real script against the real repo state. + +setup() { + REPO_ROOT="$(git rev-parse --show-toplevel)" + SCRIPT="$REPO_ROOT/scripts/compute-version.sh" +} + +@test "script exists and is executable" { + [ -x "$SCRIPT" ] +} + +@test "output matches '-seth' format" { + run "$SCRIPT" + [ "$status" -eq 0 ] + [[ "$output" =~ ^[0-9].+-seth[0-9]+$ ]] +} + +@test "N=1 when no prior seth-tags exist" { + # This test assumes a clean tag db. If there ARE existing seth-tags, this + # test will report N>1 and that's the correct value. Skipped if any + # upstream-tag-seth* tag already exists. + upstream_tag=$(git describe --tags --abbrev=0 upstream/master) + existing=$(git tag --list "${upstream_tag}-seth*" | wc -l) + if [ "$existing" -gt 0 ]; then + skip "seth-tags already exist (count=$existing); N=1 invariant only holds on first release" + fi + run "$SCRIPT" + [ "$status" -eq 0 ] + [[ "$output" == "${upstream_tag}-seth1" ]] +} + +@test "N increments past existing seth-tags" { + upstream_tag=$(git describe --tags --abbrev=0 upstream/master) + # Create a fake seth-tag for this test, then clean up. + fake_tag="${upstream_tag}-seth99" + git tag "$fake_tag" 2>/dev/null || true + run "$SCRIPT" + git tag -d "$fake_tag" >/dev/null 2>&1 || true + [ "$status" -eq 0 ] + # Existing count was at least 1 (our fake), so N >= 2. + n="${output##*-seth}" + [ "$n" -ge 2 ] +} + +@test "fails cleanly when upstream/master ref is missing" { + # Run in a temp git repo with no upstream remote. + tmp=$(mktemp -d) + cd "$tmp" + git init -q + git commit --allow-empty -m "init" -q + run "$SCRIPT" + cd "$REPO_ROOT" + rm -rf "$tmp" + [ "$status" -ne 0 ] +}