52584df34e
Bug 1: merge-mcp.sh fails on Cyrillic brain repo paths (jq fopen UTF-8 issue)
→ use --argjson with $(cat ...) instead of --slurpfile
Bug 2: install.sh stripped only trailing .template, missed middle .template.
→ strip both '.template.' middle and '.template' trailing patterns
Bug 3: manifest.json used brain-repo paths but verify.sh checked target paths
→ restructure manifest.files into {project-mode, user-mode, brain-internal} maps
→ verify.sh now picks map based on detected target mode
Bug 4: make_backup_dir created empty backup dir, no file preservation
→ rsync/cp -r target tree to backup before any modifications
Bug 5: brain's project-files/README.md overwrote consumer's README.md
→ install.sh now skips brain-internal READMEs in project/user copy loops
Phase 9 self-test re-run on c:/tmp/test-consumer-fix: install + verify both PASS.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
129 lines
6.5 KiB
Bash
129 lines
6.5 KiB
Bash
#!/usr/bin/env bash
|
|
set -u
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
|
source "$SCRIPT_DIR/lib/common.sh"
|
|
|
|
FAILURES=0
|
|
assert_eq() {
|
|
if [ "$1" = "$2" ]; then echo "PASS: $3"; else echo "FAIL: $3 (expected '$1', got '$2')"; FAILURES=$((FAILURES + 1)); fi
|
|
}
|
|
|
|
# Test 1: --dry-run does not modify target
|
|
tmpdir=$(mktemp -d)
|
|
mkdir "$tmpdir/docs"
|
|
echo "marker" > "$tmpdir/marker.txt"
|
|
|
|
bash "$SCRIPT_DIR/install.sh" --target="$tmpdir" --version=brain-v1.0 --dry-run --with-plugins=no --with-mcp=no --skip-secrets >/dev/null 2>&1
|
|
|
|
# marker.txt should still exist
|
|
[ -f "$tmpdir/marker.txt" ] && assert_eq "yes" "yes" "dry-run preserves target" || assert_eq "yes" "no" "dry-run preserves target"
|
|
|
|
rm -rf "$tmpdir"
|
|
|
|
# Test 2: missing --target → exit 1
|
|
bash "$SCRIPT_DIR/install.sh" --version=brain-v1.0 >/dev/null 2>&1
|
|
assert_eq "1" "$?" "missing --target returns exit 1"
|
|
|
|
# Test 3: install to fresh project target — files copied
|
|
tmpdir=$(mktemp -d)
|
|
mkdir "$tmpdir/docs" # detect as project mode (has docs/)
|
|
# Эмулируем brain repo с минимальным manifest
|
|
brain_dir=$(mktemp -d)
|
|
mkdir -p "$brain_dir/project-files/docs" "$brain_dir/scripts"
|
|
echo "# template" > "$brain_dir/project-files/CLAUDE.md.template"
|
|
echo '{"version":"brain-v1.0","files":{}}' > "$brain_dir/manifest.json"
|
|
cp "$SCRIPT_DIR/install.sh" "$brain_dir/scripts/"
|
|
cp "$SCRIPT_DIR/verify.sh" "$brain_dir/scripts/"
|
|
mkdir -p "$brain_dir/scripts/lib"
|
|
cp "$SCRIPT_DIR/lib/common.sh" "$brain_dir/scripts/lib/"
|
|
# Также делаем чтобы install.sh видел свой BRAIN_ROOT — переопределяем через env
|
|
BRAIN_ROOT="$brain_dir" bash "$brain_dir/scripts/install.sh" --target="$tmpdir" --version=brain-v1.0 --with-plugins=no --with-mcp=no --skip-secrets --force >/dev/null 2>&1
|
|
|
|
# Should have CLAUDE.md
|
|
[ -f "$tmpdir/CLAUDE.md" ] && assert_eq "yes" "yes" "project mode: CLAUDE.md copied" || assert_eq "yes" "no" "project mode: CLAUDE.md copied"
|
|
# Should have .brain-version
|
|
[ -f "$tmpdir/.brain-version" ] && assert_eq "yes" "yes" "project mode: .brain-version written" || assert_eq "yes" "no" "project mode: .brain-version written"
|
|
|
|
rm -rf "$tmpdir" "$brain_dir"
|
|
|
|
# Test 4: template strip handles BOTH middle .template. and trailing .template
|
|
# Bug 2 regression: files like docs/CHANGELOG_claude_md.template.md must become
|
|
# docs/CHANGELOG_claude_md.md, not be left with .template. in the middle.
|
|
tmpdir=$(mktemp -d)
|
|
mkdir "$tmpdir/docs"
|
|
brain_dir=$(mktemp -d)
|
|
mkdir -p "$brain_dir/project-files/docs" "$brain_dir/scripts/lib"
|
|
echo "# trailing" > "$brain_dir/project-files/CLAUDE.md.template"
|
|
echo "# middle" > "$brain_dir/project-files/docs/CHANGELOG_claude_md.template.md"
|
|
echo '{"version":"brain-v1.0","files":{}}' > "$brain_dir/manifest.json"
|
|
cp "$SCRIPT_DIR/install.sh" "$brain_dir/scripts/"
|
|
cp "$SCRIPT_DIR/verify.sh" "$brain_dir/scripts/"
|
|
cp "$SCRIPT_DIR/lib/common.sh" "$brain_dir/scripts/lib/"
|
|
|
|
BRAIN_ROOT="$brain_dir" bash "$brain_dir/scripts/install.sh" --target="$tmpdir" --version=brain-v1.0 --with-plugins=no --with-mcp=no --skip-secrets --force >/dev/null 2>&1
|
|
|
|
# Trailing .template stripped → CLAUDE.md
|
|
[ -f "$tmpdir/CLAUDE.md" ] && assert_eq "yes" "yes" "template strip: trailing .template removed (CLAUDE.md)" || assert_eq "yes" "no" "template strip: trailing .template removed (CLAUDE.md)"
|
|
|
|
# Middle .template. stripped → docs/CHANGELOG_claude_md.md
|
|
[ -f "$tmpdir/docs/CHANGELOG_claude_md.md" ] && assert_eq "yes" "yes" "template strip: middle .template. removed (CHANGELOG_claude_md.md)" || assert_eq "yes" "no" "template strip: middle .template. removed (CHANGELOG_claude_md.md)"
|
|
|
|
# Negative: file with .template. in middle must NOT exist with .template. still in name
|
|
[ ! -f "$tmpdir/docs/CHANGELOG_claude_md.template.md" ] && assert_eq "yes" "yes" "template strip: no leftover .template. in name" || assert_eq "yes" "no" "template strip: no leftover .template. in name"
|
|
|
|
rm -rf "$tmpdir" "$brain_dir"
|
|
|
|
# Test 5: backup directory actually contains pre-existing consumer files (Bug 4)
|
|
tmpdir=$(mktemp -d)
|
|
mkdir "$tmpdir/docs"
|
|
echo "ORIGINAL_README_CONTENT" > "$tmpdir/README.md"
|
|
echo "ORIGINAL_MARKER" > "$tmpdir/CONSUMER_KEEP.txt"
|
|
brain_dir=$(mktemp -d)
|
|
mkdir -p "$brain_dir/project-files/docs" "$brain_dir/scripts/lib"
|
|
echo "# brain template" > "$brain_dir/project-files/CLAUDE.md.template"
|
|
echo '{"version":"brain-v1.0","files":{}}' > "$brain_dir/manifest.json"
|
|
cp "$SCRIPT_DIR/install.sh" "$brain_dir/scripts/"
|
|
cp "$SCRIPT_DIR/verify.sh" "$brain_dir/scripts/"
|
|
cp "$SCRIPT_DIR/lib/common.sh" "$brain_dir/scripts/lib/"
|
|
|
|
BRAIN_ROOT="$brain_dir" bash "$brain_dir/scripts/install.sh" --target="$tmpdir" --version=brain-v1.0 --with-plugins=no --with-mcp=no --skip-secrets >/dev/null 2>&1
|
|
|
|
# Backup dir should exist
|
|
backup_count=$(find "$tmpdir" -maxdepth 1 -type d -name ".brain-backup-*" | wc -l)
|
|
assert_eq "1" "$backup_count" "backup: .brain-backup-<ts>/ created"
|
|
|
|
# Backup should contain consumer's original README.md
|
|
backup_dir=$(find "$tmpdir" -maxdepth 1 -type d -name ".brain-backup-*" | head -1)
|
|
[ -f "$backup_dir/README.md" ] && assert_eq "yes" "yes" "backup: README.md preserved" || assert_eq "yes" "no" "backup: README.md preserved"
|
|
backup_readme_content=$(cat "$backup_dir/README.md" 2>/dev/null || echo "")
|
|
assert_eq "ORIGINAL_README_CONTENT" "$backup_readme_content" "backup: README.md content matches original"
|
|
|
|
# Backup should also contain CONSUMER_KEEP.txt
|
|
[ -f "$backup_dir/CONSUMER_KEEP.txt" ] && assert_eq "yes" "yes" "backup: CONSUMER_KEEP.txt preserved" || assert_eq "yes" "no" "backup: CONSUMER_KEEP.txt preserved"
|
|
|
|
rm -rf "$tmpdir" "$brain_dir"
|
|
|
|
# Test 6: consumer's pre-existing README.md is NOT overwritten by brain's project-files/README.md (Bug 5)
|
|
tmpdir=$(mktemp -d)
|
|
mkdir "$tmpdir/docs"
|
|
echo "CONSUMER_ORIGINAL_README" > "$tmpdir/README.md"
|
|
brain_dir=$(mktemp -d)
|
|
mkdir -p "$brain_dir/project-files/docs" "$brain_dir/scripts/lib"
|
|
echo "# brain template" > "$brain_dir/project-files/CLAUDE.md.template"
|
|
echo "BRAIN_INTERNAL_README" > "$brain_dir/project-files/README.md"
|
|
echo '{"version":"brain-v1.0","files":{}}' > "$brain_dir/manifest.json"
|
|
cp "$SCRIPT_DIR/install.sh" "$brain_dir/scripts/"
|
|
cp "$SCRIPT_DIR/verify.sh" "$brain_dir/scripts/"
|
|
cp "$SCRIPT_DIR/lib/common.sh" "$brain_dir/scripts/lib/"
|
|
|
|
BRAIN_ROOT="$brain_dir" bash "$brain_dir/scripts/install.sh" --target="$tmpdir" --version=brain-v1.0 --with-plugins=no --with-mcp=no --skip-secrets >/dev/null 2>&1
|
|
|
|
readme_content=$(cat "$tmpdir/README.md")
|
|
assert_eq "CONSUMER_ORIGINAL_README" "$readme_content" "consumer README.md preserved (not overwritten by brain's internal README.md)"
|
|
|
|
rm -rf "$tmpdir" "$brain_dir"
|
|
|
|
echo "---"
|
|
echo "Failures: $FAILURES"
|
|
exit $FAILURES
|