Files
ruflo/plugins/ruflo-adr/scripts/smoke.sh
T
rUvandReuven cd0b66f0d4 feat(ruflo-adr): one-shot import + verify scripts (v0.3.0) (#1758)
The /ruflo-adr:adr-index skill previously instructed the agent to
issue per-ADR MCP tool calls (agentdb_hierarchical-store +
agentdb_causal-edge + memory_store) — for the Ruflo monorepo's 70+
ADRs that's hundreds of round-trips, no dedup, no false-positive
guard for issue numbers, and no support for the v3-vs-plugin format
divergence.

This commit packages the logic as a reusable script.

What lands:

- scripts/import.mjs (~200 LOC) — walks the working dir (or ADR_ROOT
  override), parses every ADR under */docs/adr/ or */docs/adrs/,
  handles both formats:
    * v3-style: `# ADR-097: Title` heading + `**Status**:` line
    * plugin-style: YAML frontmatter (id/title/status/date/tags)
  Persists to `adr-patterns` (records) + `adr-edges` (relationships)
  via spawnSync over `npx @claude-flow/cli memory store`. JSON or
  markdown output. IMPORT_DRY_RUN=1 supported.

- scripts/verify.mjs (~80 LOC) — companion read-back validator that
  surfaces dangling refs, supersede cycles, status mismatches.
  Exits 1 on cycles (always corruption); exits 1 on any issue with
  VERIFY_STRICT=1 (CI fail-closed).

- skills/adr-index/SKILL.md — rewritten to call import.mjs in one
  Bash invocation instead of looping MCP calls.

- skills/adr-verify/SKILL.md — new sibling skill wrapping verify.mjs.

- scripts/smoke.sh — extended from 10 to 15 checks: verifies both
  scripts are executable + syntax-clean, validates the import
  script's dual-format support + issue-number false-positive guard,
  validates verify.mjs has cycle detection + fail-closed exit, and
  asserts both skills reference their respective scripts.

Live verified on the Ruflo monorepo:
  - 73 ADRs across 39 source dirs imported to adr-patterns
  - 13 'related' edges to adr-edges
  - 0 dangling refs (was 17 false positives on issue numbers before
    the script's extractAdrRefs() guard stripped #1697 / commit /
    PR / backtick-quoted patterns)
  - 0 status mismatches
  - 0 storage errors

False-positive fix detail: the skill's old prose said "extract ADR-NNN
references from ## Links section". The reality is ADRs reference
GitHub issues (#1697), commits, PRs all the time, and a naive regex
captures those as ADR-1697. extractAdrRefs() strips known non-ADR
patterns before the regex pass.

Plugin-only change. No npm publish needed (loaded directly from the
repo via /plugin install or claude --plugin-dir).

Version: 0.2.0 → 0.3.0. Smoke: 10 → 15 checks (~85ms).

Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
2026-05-05 11:01:31 -04:00

131 lines
5.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Structural smoke test for ruflo-adr v0.2.0 (ADR-0001).
set -u
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
PASS=0
FAIL=0
step() { printf "→ %s ... " "$1"; }
ok() { printf "PASS\n"; PASS=$((PASS+1)); }
bad() { printf "FAIL: %s\n" "$1"; FAIL=$((FAIL+1)); }
# 1. plugin.json bump + new keywords
step "1. plugin.json declares 0.3.0 with new keywords"
v=$(grep -E '"version"' "$ROOT/.claude-plugin/plugin.json" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
if [[ "$v" != "0.3.0" ]]; then
bad "expected 0.3.0, got '$v'"
else
miss=""
for k in lifecycle compliance causal-graph mcp; do
grep -q "\"$k\"" "$ROOT/.claude-plugin/plugin.json" || miss="$miss $k"
done
[[ -z "$miss" ]] && ok || bad "missing keywords:$miss"
fi
# 2. All 4 skills present with valid frontmatter
step "2. skills (adr-create, adr-index, adr-review, adr-verify) present with name/description/allowed-tools"
miss=""
for s in adr-create adr-index adr-review adr-verify; do
f="$ROOT/skills/$s/SKILL.md"
[[ -f "$f" ]] || { miss="$miss missing-$s"; continue; }
for k in 'name:' 'description:' 'allowed-tools:'; do
grep -q "^$k" "$f" || miss="$miss $s-no-$k"
done
done
[[ -z "$miss" ]] && ok || bad "$miss"
# 3. command covers all 7 subcommands
step "3. /adr command covers all 7 subcommands"
F="$ROOT/commands/adr.md"
miss=""
for sub in 'adr create' 'adr list' 'adr status' 'adr supersede' 'adr check' 'adr graph' 'adr search'; do
grep -q "$sub" "$F" || miss="$miss '${sub#adr }'"
done
[[ -z "$miss" ]] && ok || bad "missing:$miss"
# 4. Agent references REFERENCE.md (ADR-098 Part 2 token-diet pattern)
step "4. agent references REFERENCE.md (token-optimization pattern)"
grep -q "REFERENCE.md" "$ROOT/agents/adr-architect.md" \
&& ok || bad "REFERENCE.md cross-reference missing"
# 5. adr-patterns namespace used consistently
step "5. adr-patterns namespace referenced in agent + skills"
miss=""
grep -q "adr-patterns" "$ROOT/agents/adr-architect.md" || miss="$miss agent"
grep -q "adr-patterns" "$ROOT/skills/adr-create/SKILL.md" || miss="$miss adr-create"
grep -q "adr-patterns" "$ROOT/skills/adr-index/SKILL.md" || miss="$miss adr-index"
[[ -z "$miss" ]] && ok || bad "missing in:$miss"
# 6. README pins to @claude-flow/cli v3.6
step "6. README pins @claude-flow/cli to v3.6"
grep -qE "@claude-flow/cli.*v3\.6|v3\.6.*claude-flow/cli" "$ROOT/README.md" \
&& ok || bad "Compatibility pin to v3.6 missing"
# 7. README has namespace coordination section
step "7. README defers to ruflo-agentdb ADR-0001 namespace convention"
grep -q "Namespace coordination" "$ROOT/README.md" \
&& grep -q "ruflo-agentdb" "$ROOT/README.md" \
&& grep -q "Namespace convention" "$ROOT/README.md" \
&& ok || bad "namespace coordination block incomplete"
# 8. ADR file exists with status Proposed
step "8. ADR-0001 exists with status Proposed"
ADR="$ROOT/docs/adrs/0001-adr-plugin-pattern.md"
[[ -f "$ADR" ]] && grep -qE "^status:[[:space:]]*Proposed" "$ADR" \
&& ok || bad "ADR missing or status != Proposed"
# 9. REFERENCE.md exists and is non-empty
step "9. REFERENCE.md exists and is non-empty"
[[ -s "$ROOT/REFERENCE.md" ]] && ok || bad "REFERENCE.md missing or empty"
# 10. No wildcard tool grants
step "10. no skill grants wildcard tool access"
bad_skills=""
for f in "$ROOT"/skills/*/SKILL.md; do
grep -q '^allowed-tools:[[:space:]]*\*' "$f" && bad_skills="$bad_skills $(basename $(dirname "$f"))"
done
[[ -z "$bad_skills" ]] && ok || bad "wildcard:$bad_skills"
# 11. import + verify scripts present, executable, parse cleanly
step "11. scripts/import.mjs and verify.mjs executable + syntax-clean"
miss=""
for s in import.mjs verify.mjs; do
f="$ROOT/scripts/$s"
[[ -x "$f" ]] || miss="$miss $s-not-executable"
node --check "$f" 2>/dev/null || miss="$miss $s-syntax-error"
done
[[ -z "$miss" ]] && ok || bad "$miss"
# 12. import.mjs handles both ADR formats + has issue-number false-positive guard
step "12. import.mjs supports v3 + plugin formats and strips issue numbers"
F="$ROOT/scripts/import.mjs"
miss=""
grep -q "extractAdrRefs" "$F" || miss="$miss no-extractAdrRefs"
grep -q "frontmatter\|YAML\|^---" "$F" || miss="$miss no-frontmatter-handling"
grep -q "#\\\\d+\|issue\|PR\\\\s*\\\\d" "$F" || miss="$miss no-issue-strip"
grep -q '\*\*Status\*\*' "$F" || miss="$miss no-v3-status-pattern"
[[ -z "$miss" ]] && ok || bad "$miss"
# 13. verify.mjs reports cycles + dangling refs and exits 1 on cycles
step "13. verify.mjs detects cycles + has fail-closed exit"
F="$ROOT/scripts/verify.mjs"
miss=""
grep -q "cycles" "$F" || miss="$miss no-cycle-detection"
grep -q "danglingRefs" "$F" || miss="$miss no-dangling-detection"
grep -q "process.exit(1)" "$F" || miss="$miss no-fail-exit"
[[ -z "$miss" ]] && ok || bad "$miss"
# 14. adr-index skill references the script (not direct MCP loop)
step "14. adr-index skill calls scripts/import.mjs"
F="$ROOT/skills/adr-index/SKILL.md"
grep -q "scripts/import\.mjs\|import\.mjs" "$F" \
&& ok || bad "skill does not invoke import.mjs"
# 15. adr-verify skill references verify.mjs
step "15. adr-verify skill calls scripts/verify.mjs"
F="$ROOT/skills/adr-verify/SKILL.md"
grep -q "scripts/verify\.mjs\|verify\.mjs" "$F" \
&& ok || bad "skill does not invoke verify.mjs"
printf "\n%s passed, %s failed\n" "$PASS" "$FAIL"
[[ $FAIL -eq 0 ]] || exit 1