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>
97 lines
3.4 KiB
Bash
97 lines
3.4 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: user-mode merge — magic replaced, laravel-boost preserved
|
|
tmpdir=$(mktemp -d)
|
|
cp "$SCRIPT_DIR/fixtures/sample-claude-json.json" "$tmpdir/.claude.json"
|
|
cat > "$tmpdir/brain-mcp.json" <<EOF2
|
|
{
|
|
"mcpServers": {
|
|
"magic": {
|
|
"type": "stdio",
|
|
"command": "cmd",
|
|
"args": ["/c", "npx", "-y", "@21st-dev/magic@latest", "API_KEY=<<MAGIC_API_KEY>>"]
|
|
}
|
|
}
|
|
}
|
|
EOF2
|
|
|
|
bash "$SCRIPT_DIR/lib/merge-mcp.sh" --mode=user "$tmpdir/.claude.json" "$tmpdir/brain-mcp.json"
|
|
|
|
# magic args should now contain placeholder
|
|
magic_api_key=$(jq -r '.mcpServers.magic.args[-1]' "$tmpdir/.claude.json")
|
|
assert_eq "API_KEY=<<MAGIC_API_KEY>>" "$magic_api_key" "user-mode: magic API_KEY replaced with placeholder"
|
|
|
|
# laravel-boost preserved
|
|
lb_cmd=$(jq -r '.mcpServers["laravel-boost"].command' "$tmpdir/.claude.json")
|
|
assert_eq "php" "$lb_cmd" "user-mode: laravel-boost preserved"
|
|
|
|
# preserveMe key still present (other keys unchanged)
|
|
preserve=$(jq -r '.preserveMe' "$tmpdir/.claude.json")
|
|
assert_eq "yes" "$preserve" "user-mode: other top-level keys preserved"
|
|
|
|
rm -rf "$tmpdir"
|
|
|
|
# Test 2: project-mode merge — playwright/github/semgrep added, laravel-boost preserved
|
|
tmpdir=$(mktemp -d)
|
|
cp "$SCRIPT_DIR/fixtures/sample-mcp.json" "$tmpdir/.mcp.json"
|
|
cat > "$tmpdir/brain-mcp.json" <<EOF3
|
|
{
|
|
"mcpServers": {
|
|
"playwright": {"command": "npx", "args": ["-y", "@playwright/mcp"]},
|
|
"github": {"type": "http", "url": "https://api.githubcopilot.com/mcp"},
|
|
"semgrep": {"command": "npx", "args": ["-y", "semgrep-mcp"]}
|
|
}
|
|
}
|
|
EOF3
|
|
|
|
bash "$SCRIPT_DIR/lib/merge-mcp.sh" --mode=project "$tmpdir/.mcp.json" "$tmpdir/brain-mcp.json"
|
|
|
|
# Should have 4 servers total
|
|
count=$(jq '.mcpServers | length' "$tmpdir/.mcp.json")
|
|
assert_eq "4" "$count" "project-mode: 4 servers after merge"
|
|
|
|
# laravel-boost preserved
|
|
lb=$(jq -r '.mcpServers["laravel-boost"].command' "$tmpdir/.mcp.json")
|
|
assert_eq "php" "$lb" "project-mode: laravel-boost preserved"
|
|
|
|
# playwright added
|
|
pw=$(jq -r '.mcpServers.playwright.command' "$tmpdir/.mcp.json")
|
|
assert_eq "npx" "$pw" "project-mode: playwright added"
|
|
|
|
rm -rf "$tmpdir"
|
|
|
|
# Test 3: Cyrillic path (Bug 1 regression) — jq must handle non-ASCII paths
|
|
# On Windows MSYS2 jq's fopen cannot open Cyrillic paths via --slurpfile.
|
|
# Fix uses --argjson with $(cat …) — shell handles UTF-8 paths fine.
|
|
cyr_dir="/tmp/тест-merge-$$"
|
|
mkdir -p "$cyr_dir"
|
|
cat > "$cyr_dir/brain.json" <<'EOF4'
|
|
{"mcpServers":{"playwright":{"command":"npx","args":["-y","@playwright/mcp"]}}}
|
|
EOF4
|
|
echo '{"mcpServers":{"laravel-boost":{"command":"php"}}}' > "$cyr_dir/target.json"
|
|
|
|
bash "$SCRIPT_DIR/lib/merge-mcp.sh" --mode=project "$cyr_dir/target.json" "$cyr_dir/brain.json" 2>/dev/null
|
|
merge_exit=$?
|
|
assert_eq "0" "$merge_exit" "cyrillic-path: merge-mcp.sh exits 0"
|
|
|
|
if [ "$merge_exit" -eq 0 ]; then
|
|
pw=$(jq -r '.mcpServers.playwright.command' "$cyr_dir/target.json" 2>/dev/null || echo "")
|
|
assert_eq "npx" "$pw" "cyrillic-path: playwright merged from Cyrillic brain path"
|
|
lb=$(jq -r '.mcpServers["laravel-boost"].command' "$cyr_dir/target.json" 2>/dev/null || echo "")
|
|
assert_eq "php" "$lb" "cyrillic-path: laravel-boost preserved"
|
|
fi
|
|
|
|
rm -rf "$cyr_dir"
|
|
|
|
echo "---"
|
|
echo "Failures: $FAILURES"
|
|
exit $FAILURES
|