CtrlK
BlogDocsLog inGet started
Tessl Logo
PluginPublic

gamussa/coding-policy

Coding policy for Viktor Gamov's AI agents: language-agnostic quality rules, autonomous shipping discipline, and stack defaults for JVM, Swift, TypeScript, and Python

1.47x
Quality

93%

Does it follow best practices?

Impact

99%

1.47x

Average score across 10 eval scenarios

SecuritybySnyk

Low

Low-risk findings worth noting

Overview
Quality
Evals
Security
Files

test_registry_version.shskills/release/tests/

#!/usr/bin/env bash
# Outcome-based tests for registry-version.sh.
#
# The contract: read the tile's latest published version from the versions API
# and emit it as JSON, distinguishing three outcomes — a published version
# ({"version":"x.y.z"}), a never-published tile ({"version":null}, exit 0), and
# a tool/parse failure (exit 2, empty stdout, diagnostic on stderr). The
# load-bearing properties are (a) NUMERIC max selection (0.3.119 outranks
# 0.3.20), (b) a tessl stderr warning must not poison the parse, and (c) a
# non-JSON body / tessl failure must exit 2, never emit a bogus version.
#
# Approach: run the script as a subprocess with a `tessl` fake first on PATH
# (real jq stays reachable), so the real `set -euo pipefail`, the EXIT trap,
# and the exit codes are exercised end-to-end. The fake selects its fixture
# via MOCK_MODE, exported through the invocation so it reaches the fake.
#
# Run: bash skills/release/tests/test_registry_version.sh
# Exit 0 on all-pass; 1 with a per-test diagnostic on failure.

set -uo pipefail

# The runner's per-suite token binds this suite's summary line to this
# suite (scripts/run-tests.sh header). Unset it so a harness run from
# here prints an empty token and never stands in for this one.
SUMMARY_TOKEN="${TEST_SUMMARY_TOKEN:-}"
unset TEST_SUMMARY_TOKEN

SCRIPT="$(cd "$(dirname "$0")/.." && pwd)/registry-version.sh"
[[ -f "$SCRIPT" && -r "$SCRIPT" ]] || { echo "fatal: registry-version.sh not readable at $SCRIPT" >&2; exit 2; }

FAIL_COUNT=0
PASS_COUNT=0
pass() { PASS_COUNT=$((PASS_COUNT + 1)); echo "  pass: $1"; }
fail() { FAIL_COUNT=$((FAIL_COUNT + 1)); echo "  FAIL: $1" >&2; }

# `set -e` is deliberately off (a failure-counting harness must not die on its
# first red), so guard mktemp -d explicitly: an empty STUBDIR would put "" on
# PATH and cascade confusing failures.
STUBDIR="$(mktemp -d)" || { echo "fatal: mktemp -d failed — cannot stage the tessl stub; check TMPDIR" >&2; exit 2; }
[[ -n "$STUBDIR" && -d "$STUBDIR" ]] || { echo "fatal: mktemp -d returned no usable directory (got '${STUBDIR}')" >&2; exit 2; }
cleanup_stubdir() {
  if [[ -n "${STUBDIR:-}" ]]; then
    if ! rm -rf "$STUBDIR"; then
      echo "warning: could not remove stub dir ${STUBDIR} — remove it by hand" >&2
    fi
  fi
  return 0
}
trap cleanup_stubdir EXIT
export PATH="$STUBDIR:$PATH"

# Fake tessl. Handles `tessl api <endpoint>`; selects a fixture via MOCK_MODE.
# The `ok` fixture lists versions oldest-first with a double-digit and a
# triple-digit patch so the script's NUMERIC max selection is genuinely
# exercised (a lexical sort would pick 0.3.20).
cat > "$STUBDIR/tessl" <<'STUB' || { echo "fatal: cannot write the tessl stub to ${STUBDIR}/tessl — check that TMPDIR is writable and not full" >&2; exit 2; }
#!/usr/bin/env bash
case "$1" in
  api)
    case "${MOCK_MODE:-}" in
      ok)
        printf '{"data":[{"attributes":{"version":"0.3.20"}},{"attributes":{"version":"0.3.119"}},{"attributes":{"version":"0.0.1"}}]}\n' ;;
      empty)
        printf '{"data":[]}\n' ;;
      warning_on_stderr)
        echo "warn: registry cache stale, refetching" >&2
        printf '{"data":[{"attributes":{"version":"0.3.31"}}]}\n' ;;
      non_json)
        printf '<html>502 Bad Gateway</html>\n' ;;
      tessl_fails)
        echo "error: not authenticated" >&2
        exit 1 ;;
      no_data)
        printf '{}\n' ;;
      absent)
        printf '{"error":{"title":"Not Found","status":404,"message":"Not Found"}}\n'
        exit 1 ;;
      absent_rc2|absent_rc126|absent_rc137)
        # The exact not-found body, but a status other than tessl's
        # documented 1 for it: a crashed or killed CLI, not a registry answer.
        printf '{"error":{"title":"Not Found","status":404,"message":"Not Found"}}\n'
        exit "${MOCK_MODE#absent_rc}" ;;
      absent_rc0)
        printf '{"error":{"title":"Not Found","status":404,"message":"Not Found"}}\n' ;;
      entry_no_version)
        printf '%s\n' '{"data":[{"attributes":{}}]}' ;;
      entry_null_version)
        printf '%s\n' '{"data":[{"attributes":{"version":null}}]}' ;;
      ver_empty)
        printf '%s\n' '{"data":[{"attributes":{"version":""}}]}' ;;
      ver_short)
        printf '%s\n' '{"data":[{"attributes":{"version":"1.2"}}]}' ;;
      ver_vprefix)
        printf '%s\n' '{"data":[{"attributes":{"version":"v1.2.3"}}]}' ;;
      ver_prerelease)
        printf '%s\n' '{"data":[{"attributes":{"version":"1.2.3-rc1"}}]}' ;;
      ver_mixed_vprefix)
        printf '%s\n' '{"data":[{"attributes":{"version":"v1.2.3"}},{"attributes":{"version":"2.0.0"}}]}' ;;
      ver_mixed_empty)
        printf '%s\n' '{"data":[{"attributes":{"version":""}},{"attributes":{"version":"2.0.0"}}]}' ;;
      ver_mixed_short)
        printf '%s\n' '{"data":[{"attributes":{"version":"1.2"}},{"attributes":{"version":"2.0.0"}}]}' ;;
      entry_numeric_version)
        printf '%s\n' '{"data":[{"attributes":{"version":123}}]}' ;;
      entry_no_attributes)
        printf '%s\n' '{"data":[{}]}' ;;
      entry_not_object)
        printf '%s\n' '{"data":[1]}' ;;
      entry_mixed)
        printf '%s\n' '{"data":[{"attributes":{"version":"0.1.0"}},{"attributes":{}}]}' ;;
      absent_404_bare)
        printf '{"error":{"status":404}}\n'
        exit 1 ;;
      absent_404_with_data)
        printf '{"error":{"title":"Not Found","status":404},"data":[]}\n'
        exit 1 ;;
      server_error)
        printf '{"error":{"title":"Internal Server Error","status":500}}\n'
        exit 1 ;;
      malformed_version)
        printf '{"data":[{"attributes":{"version":"not-a-version"}}]}\n' ;;
      *) echo "stub tessl: unknown MOCK_MODE='${MOCK_MODE:-}'" >&2; exit 99 ;;
    esac
    ;;
  *) echo "stub tessl: unsupported invocation: $*" >&2; exit 2 ;;
esac
STUB
chmod +x "$STUBDIR/tessl" || { echo "fatal: cannot make ${STUBDIR}/tessl executable — check the filesystem allows chmod there (TMPDIR mounted noexec?)" >&2; exit 2; }

# Invoke with MOCK_MODE exported so it reaches the fake tessl subprocess.
invoke() {
  local mode="$1"
  OUT="$(MOCK_MODE="$mode" bash "$SCRIPT" gamussa coding-policy 2>"$STUBDIR/err")"
  CODE=$?
  ERR="$(cat "$STUBDIR/err")" || { echo "fatal: cannot read captured stderr at ${STUBDIR}/err — check that TMPDIR is readable" >&2; exit 2; }
}

echo "== registry-version.sh tests =="

# --- happy path: NUMERIC max across the page, emitted as JSON ---
invoke ok
if [[ "$CODE" == 0 ]] && [[ "$OUT" == '{"version":"0.3.119"}' ]]; then
  pass "numeric max selection: 0.3.20 / 0.3.119 / 0.0.1 -> {\"version\":\"0.3.119\"}"
else
  fail "happy path: code=$CODE out='$OUT' err='$ERR'"
fi

# --- never published: empty .data -> {"version":null}, exit 0 (valid baseline) ---
invoke empty
if [[ "$CODE" == 0 ]] && [[ "$OUT" == '{"version":null}' ]]; then
  pass "never-published (empty data) -> exit 0, {\"version\":null}"
else
  fail "empty data: code=$CODE out='$OUT' err='$ERR'"
fi

# --- never published: the versions API's structured not-found body, which
#     tessl answers with exit 1, is a first-publish baseline ---
invoke absent
if [[ "$CODE" == 0 ]] && [[ "$OUT" == '{"version":null}' ]]; then
  pass "structured Not Found/404 (exit 1) -> exit 0, {\"version\":null}"
else
  fail "structured 404: code=$CODE out='$OUT' err='$ERR'"
fi

# --- any other error body stays a failure, never a fabricated baseline ---
for mode in absent_rc0 ver_empty ver_short ver_vprefix ver_prerelease ver_mixed_vprefix ver_mixed_empty ver_mixed_short entry_no_version entry_null_version entry_numeric_version entry_no_attributes entry_not_object entry_mixed absent_rc2 absent_rc126 absent_rc137 absent_404_bare absent_404_with_data server_error; do
  invoke "$mode"
  if [[ "$CODE" == 2 ]] && [[ -z "$OUT" ]] && [[ -n "$ERR" ]]; then
    pass "$mode -> exit 2, never a first-publish baseline"
  else
    fail "$mode: code=$CODE out='$OUT' err='$ERR'"
  fi
done

# --- a tessl warning on stderr must not poison the parsed version ---
invoke warning_on_stderr
if [[ "$CODE" == 0 ]] && [[ "$OUT" == '{"version":"0.3.31"}' ]]; then
  pass "stderr warning does not poison the parsed version"
else
  fail "stderr warning: code=$CODE out='$OUT' err='$ERR'"
fi

# --- non-JSON body -> exit 2, 'not valid JSON', NO bogus version emitted ---
invoke non_json
if [[ "$CODE" == 2 ]] && [[ -z "$OUT" ]] && [[ "$ERR" == *"not valid JSON"* ]]; then
  pass "non-JSON body -> exit 2, empty stdout, actionable diagnostic"
else
  fail "non-JSON: code=$CODE out='$OUT' err='$ERR'"
fi

# --- tessl itself failing -> exit 2 with the tool's stderr surfaced ---
invoke tessl_fails
if [[ "$CODE" == 2 ]] && [[ -z "$OUT" ]] && [[ "$ERR" == *"not authenticated"* ]]; then
  pass "tessl failure -> exit 2, tool stderr surfaced"
else
  fail "tessl failure: code=$CODE out='$OUT' err='$ERR'"
fi

# --- valid JSON with no .data array ({}) -> exit 2, NOT a fabricated empty
#     baseline (a registry error body must not read as never-published) ---
invoke no_data
if [[ "$CODE" == 2 ]] && [[ -z "$OUT" ]] && [[ "$ERR" == *"no .data array"* ]]; then
  pass "no .data array ({}) -> exit 2 (not a fabricated first-publish baseline)"
else
  fail "no-data: code=$CODE out='$OUT' err='$ERR'"
fi

# --- a non-numeric latest version -> exit 2 (a version_gt input must be numeric) ---
invoke malformed_version
if [[ "$CODE" == 2 ]] && [[ -z "$OUT" ]] && [[ "$ERR" == *"not numeric"* ]]; then
  pass "malformed (non-numeric) version -> exit 2"
else
  fail "malformed-version: code=$CODE out='$OUT' err='$ERR'"
fi

# --- wrong arity is a usage error, not a silent default ---
OUT="$(bash "$SCRIPT" gamussa 2>"$STUBDIR/err")"; CODE=$?; ERR="$(cat "$STUBDIR/err")"
if [[ "$CODE" == 2 ]] && [[ "$ERR" == *"usage:"* ]]; then
  pass "wrong arity -> exit 2 with usage"
else
  fail "arity: code=$CODE out='$OUT' err='$ERR'"
fi

echo ""
echo "== summary: ${PASS_COUNT} passed, ${FAIL_COUNT} failed =="
echo "test-summary: passed=${PASS_COUNT} failed=${FAIL_COUNT} token=${SUMMARY_TOKEN}"
[[ $FAIL_COUNT -eq 0 ]]

skills

README.md

tile.json