--check's throwaway pack copy seeded .claude-plugin/plugin.json and
.github/plugin/plugin.json from the real plugin dir, then packed without
--force -- apm pack silently skips regenerating a plugin.json that already
exists, so the diff always compared the copy against itself and never caught
drift in the compiled name/version/description/mcpServers. --force is now
always passed; in check mode it forces regeneration inside the throwaway copy
only, which sync_plugin_manifest() then diffs against the real committed
manifest.
sync_hooks_json() returned early whenever .apm/hooks/ was missing, without
checking whether a stale hooks.json was still sitting at the plugin root from
a prior sync -- unlike sync_dir(), which already detects that kind of orphaned
mirrored output. It now mirrors sync_dir()'s shape: flagged as drift in
--check, removed on a real sync.
Running the corrected --check --all against this repo's own plugins surfaced
3 real orphans: plugins/{git,gitea,core}/hooks.json, empty stubs added in
4edaaac only to satisfy an old plugin.json pointer-field check that no longer
exists (their compiled plugin.json has never had a hooks field, and none of
the three ever had .apm/hooks/). Removed as part of this fix since they're
exactly the drift the corrected check now catches -- leaving them would break
the sync-plugin-content pre-push gate on this branch.
Also extracts two shared helpers into scripts/lib/, sourced by this script and
others so a future bug fix doesn't need hand-applying three times:
- marketplace-plugins.sh: walks marketplace.json for local plugin dirs (this
script's --all branch and check-manifests.sh had near-identical copies)
- batch-run.sh: the bounded-batch concurrent job runner (this script,
tests/run-tests.sh, and tests/run-bats.sh each hand-rolled the same
core-count-capped wait loop independently)
Extended tests/test-sync-plugin-content.sh with coverage for both drift cases
(plugin.json version-bump drift, orphaned-hooks.json drift), including that a
re-sync clears each.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X7GvKuJfy2WrdBmUttV4DT
80 lines
2.6 KiB
Bash
Executable File
80 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Run all bats test files in the repo.
|
|
# Usage: bash tests/run-bats.sh
|
|
set -euo pipefail
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
BATS="$REPO_ROOT/tests/bats/bin/bats"
|
|
|
|
if [[ ! -x "$BATS" ]]; then
|
|
echo "bats not found at $BATS — initializing submodules..." >&2
|
|
git -C "$REPO_ROOT" submodule update --init --recursive
|
|
fi
|
|
|
|
if [[ ! -x "$BATS" ]]; then
|
|
echo "Error: bats still not found at $BATS after submodule init" >&2
|
|
exit 1
|
|
fi
|
|
|
|
mapfile -t TEST_FILES < <(
|
|
find "$REPO_ROOT" -name "*.bats" \
|
|
-not -path "*/tests/bats/*" \
|
|
-not -path "*/test_helper/*" \
|
|
-not -path "*/.claude/worktrees/*" \
|
|
| sort
|
|
)
|
|
|
|
if [[ ${#TEST_FILES[@]} -eq 0 ]]; then
|
|
echo "No .bats test files found." >&2
|
|
exit 0
|
|
fi
|
|
|
|
# Each file gets its own `bats` process, run concurrently (bounded by core
|
|
# count) instead of one `bats` invocation working through all files serially.
|
|
# A single test file is still serial internally -- this only overlaps the
|
|
# fixed per-process startup cost (git/apm subprocess spawns dominate several
|
|
# of these suites) across files, which is where the wall-clock actually goes.
|
|
# Output is buffered per file so concurrent TAP streams can't interleave, then
|
|
# flushed in stable sorted order once every job has finished.
|
|
#
|
|
# Dispatch and throttling is scripts/lib/batch-run.sh's batch_run -- shared
|
|
# with scripts/sync-plugin-content.sh and tests/run-tests.sh so a batching bug
|
|
# fix only needs to land once; see that file for why this is batched rather
|
|
# than a rolling `wait -n` pool.
|
|
SCRATCH_ROOT="$(mktemp -d)"
|
|
trap 'rm -rf "$SCRATCH_ROOT"' EXIT
|
|
# shellcheck source=../scripts/lib/batch-run.sh
|
|
source "$REPO_ROOT/scripts/lib/batch-run.sh"
|
|
|
|
declare -a batch_args=()
|
|
i=0
|
|
for f in "${TEST_FILES[@]}"; do
|
|
i=$((i + 1))
|
|
cmd="$(printf '%q %q; echo $? >%q' "$BATS" "$f" "$SCRATCH_ROOT/$i.status")"
|
|
batch_args+=("$i" "$cmd")
|
|
done
|
|
batch_run "$SCRATCH_ROOT" ${batch_args[@]+"${batch_args[@]}"}
|
|
|
|
FAIL=0
|
|
TOTAL_OK=0
|
|
TOTAL_NOT_OK=0
|
|
i=0
|
|
for f in "${TEST_FILES[@]}"; do
|
|
i=$((i + 1))
|
|
rel="${f#"$REPO_ROOT"/}"
|
|
echo "=== $rel ==="
|
|
cat "$SCRATCH_ROOT/$i.log"
|
|
echo ""
|
|
file_ok="$(grep -c '^ok ' "$SCRATCH_ROOT/$i.log" || true)"
|
|
file_not_ok="$(grep -c '^not ok ' "$SCRATCH_ROOT/$i.log" || true)"
|
|
status="$(cat "$SCRATCH_ROOT/$i.status" 2>/dev/null || echo 1)"
|
|
TOTAL_OK=$((TOTAL_OK + file_ok))
|
|
TOTAL_NOT_OK=$((TOTAL_NOT_OK + file_not_ok))
|
|
if [[ "$file_not_ok" -gt 0 || "$status" -ne 0 ]]; then
|
|
FAIL=1
|
|
fi
|
|
done
|
|
|
|
echo "$((TOTAL_OK + TOTAL_NOT_OK)) tests, $TOTAL_NOT_OK failures"
|
|
exit "$FAIL"
|