fix(scripts): 5 critical bugs from Phase 9 self-test
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>
This commit is contained in:
+46
-23
@@ -5,28 +5,51 @@
|
||||
"required_tools": ["jq", "python", "git", "bash"],
|
||||
"optional_tools": ["gh", "gitleaks", "claude"],
|
||||
"files": {
|
||||
"project-files/.mcp.json.template": "14dd78e8d4a795b85b444bbf7d51cf71b44c5614e3e041bf09d7eb9a6133f1d0",
|
||||
"project-files/CLAUDE.md.template": "eaee69ec015b07527400f2579192cc1e634ae3192e91e668393600d6e440f6c9",
|
||||
"project-files/README.md": "f91f0737ffffbd94f3fb84eeb856eb561b4759b62a57fcbf1c3b3f652a9505d8",
|
||||
"project-files/docs/CHANGELOG_claude_md.template.md": "c9a004af5defab9dfe5408f85b37a9024cc91d9c898d27421297ee590ea8f9e9",
|
||||
"project-files/docs/Plugin_stack_rules.template.md": "a6624d13bc1366c572d590a7ab125aaeea9cce091c00264797443b00eeefb864",
|
||||
"project-files/docs/Pravila_raboty_Claude.template.md": "33adaba80b311269861777422f378438bfd08e1a6b1114c49836dd74a096f14c",
|
||||
"project-files/docs/Tooling.template.md": "9ac1bde261de859760033d2cc22d8a848279ec540c409bf15b7735f39f8d8f99",
|
||||
"project-files/docs/visualizations/hooks-skills-plugins-map.html": "ad61c5069ac25c70f23315bf7d4c9bd80d2f55380f27f5a95d0e93b80dfe2532",
|
||||
"user-level-files/README.md": "1bca220f99df30ef1fbfb9314b8f5182784ba44e44e63e7ded10edd77e3c2cba",
|
||||
"user-level-files/hooks/economy-mode-test.py": "8e42f2137ca79206b8b205334cdf89f1ac991932fe9e773c828c8a1496fa2403",
|
||||
"user-level-files/hooks/economy-mode.py": "865f36bba142a717dec18fb1e5f055c17b157bd53cc5fdbc7ef1e8628b3c2f64",
|
||||
"user-level-files/hooks/economy-postcompact.py": "7b96abde074e2f17e0e95d26d7a7fc02f7c4617c0d9787e359c80b6e695716e6",
|
||||
"user-level-files/hooks/economy-self-check-test.py": "f0f668b88c684674473458d7364f54d537432dc1797ee939b948f635690289e0",
|
||||
"user-level-files/hooks/economy-self-check.py": "962db87b1abd05a8f783aa6e93d482750c14970ed5ab5229ea58582550f884d7",
|
||||
"user-level-files/hooks/economy-state-guard-test.py": "2c407af63a5356d051271ea9852485dd2265c593c6535f85c4055a6ebe480196",
|
||||
"user-level-files/hooks/economy-state-guard.py": "bb5278e356c33b8f99f05ad184b2b8b8d11692407b8e6216be7b0cfe3e11457c",
|
||||
"user-level-files/hooks/economy-verifier.py": "2b7431bcc1bf80179989e4f918a90de6b37627073cd04fa7a139757b18637a16",
|
||||
"user-level-files/hooks/skill-check.py": "5f708f412d4d6ea66cd2f14ba119cf784b602d79052bbb976f904339421a09ad",
|
||||
"user-level-files/hooks/skill-marker.py": "2d2ff205ae1390f87d1f8162e238729fa4d8c12340f02016ee1d54b3fff014a4",
|
||||
"user-level-files/marketplaces.json": "9017c313525cb78f2078ba79fd974260cb8016f69dbb9a099dcff7b4153af300",
|
||||
"user-level-files/mcp-user.template.json": "80cce6f971fa3dfca5533becab009060b703c914196a92ac3d6b2e3768b8b923",
|
||||
"user-level-files/plugins-manifest.json": "1374cf8f4206b972a9ef5be6692773f2b8eaf1016588470a32588539f347f324",
|
||||
"user-level-files/settings-fragment.json": "cbdda1e23034d0056db5165a85667d6a7d55de6e0629d7be4e9d9d7e4ebb4a7d"
|
||||
"project-mode": {
|
||||
".mcp.json": "14dd78e8d4a795b85b444bbf7d51cf71b44c5614e3e041bf09d7eb9a6133f1d0",
|
||||
"CLAUDE.md": "eaee69ec015b07527400f2579192cc1e634ae3192e91e668393600d6e440f6c9",
|
||||
"docs/CHANGELOG_claude_md.md": "c9a004af5defab9dfe5408f85b37a9024cc91d9c898d27421297ee590ea8f9e9",
|
||||
"docs/Plugin_stack_rules.md": "a6624d13bc1366c572d590a7ab125aaeea9cce091c00264797443b00eeefb864",
|
||||
"docs/Pravila_raboty_Claude.md": "33adaba80b311269861777422f378438bfd08e1a6b1114c49836dd74a096f14c",
|
||||
"docs/Tooling.md": "9ac1bde261de859760033d2cc22d8a848279ec540c409bf15b7735f39f8d8f99",
|
||||
"docs/visualizations/hooks-skills-plugins-map.html": "ad61c5069ac25c70f23315bf7d4c9bd80d2f55380f27f5a95d0e93b80dfe2532"
|
||||
},
|
||||
"user-mode": {
|
||||
"hooks/economy-mode-test.py": "8e42f2137ca79206b8b205334cdf89f1ac991932fe9e773c828c8a1496fa2403",
|
||||
"hooks/economy-mode.py": "865f36bba142a717dec18fb1e5f055c17b157bd53cc5fdbc7ef1e8628b3c2f64",
|
||||
"hooks/economy-postcompact.py": "7b96abde074e2f17e0e95d26d7a7fc02f7c4617c0d9787e359c80b6e695716e6",
|
||||
"hooks/economy-self-check-test.py": "f0f668b88c684674473458d7364f54d537432dc1797ee939b948f635690289e0",
|
||||
"hooks/economy-self-check.py": "962db87b1abd05a8f783aa6e93d482750c14970ed5ab5229ea58582550f884d7",
|
||||
"hooks/economy-state-guard-test.py": "2c407af63a5356d051271ea9852485dd2265c593c6535f85c4055a6ebe480196",
|
||||
"hooks/economy-state-guard.py": "bb5278e356c33b8f99f05ad184b2b8b8d11692407b8e6216be7b0cfe3e11457c",
|
||||
"hooks/economy-verifier.py": "2b7431bcc1bf80179989e4f918a90de6b37627073cd04fa7a139757b18637a16",
|
||||
"hooks/skill-check.py": "5f708f412d4d6ea66cd2f14ba119cf784b602d79052bbb976f904339421a09ad",
|
||||
"hooks/skill-marker.py": "2d2ff205ae1390f87d1f8162e238729fa4d8c12340f02016ee1d54b3fff014a4"
|
||||
},
|
||||
"brain-internal": {
|
||||
"project-files/.mcp.json.template": "14dd78e8d4a795b85b444bbf7d51cf71b44c5614e3e041bf09d7eb9a6133f1d0",
|
||||
"project-files/CLAUDE.md.template": "eaee69ec015b07527400f2579192cc1e634ae3192e91e668393600d6e440f6c9",
|
||||
"project-files/README.md": "f91f0737ffffbd94f3fb84eeb856eb561b4759b62a57fcbf1c3b3f652a9505d8",
|
||||
"project-files/docs/CHANGELOG_claude_md.template.md": "c9a004af5defab9dfe5408f85b37a9024cc91d9c898d27421297ee590ea8f9e9",
|
||||
"project-files/docs/Plugin_stack_rules.template.md": "a6624d13bc1366c572d590a7ab125aaeea9cce091c00264797443b00eeefb864",
|
||||
"project-files/docs/Pravila_raboty_Claude.template.md": "33adaba80b311269861777422f378438bfd08e1a6b1114c49836dd74a096f14c",
|
||||
"project-files/docs/Tooling.template.md": "9ac1bde261de859760033d2cc22d8a848279ec540c409bf15b7735f39f8d8f99",
|
||||
"project-files/docs/visualizations/hooks-skills-plugins-map.html": "ad61c5069ac25c70f23315bf7d4c9bd80d2f55380f27f5a95d0e93b80dfe2532",
|
||||
"user-level-files/README.md": "1bca220f99df30ef1fbfb9314b8f5182784ba44e44e63e7ded10edd77e3c2cba",
|
||||
"user-level-files/hooks/economy-mode-test.py": "8e42f2137ca79206b8b205334cdf89f1ac991932fe9e773c828c8a1496fa2403",
|
||||
"user-level-files/hooks/economy-mode.py": "865f36bba142a717dec18fb1e5f055c17b157bd53cc5fdbc7ef1e8628b3c2f64",
|
||||
"user-level-files/hooks/economy-postcompact.py": "7b96abde074e2f17e0e95d26d7a7fc02f7c4617c0d9787e359c80b6e695716e6",
|
||||
"user-level-files/hooks/economy-self-check-test.py": "f0f668b88c684674473458d7364f54d537432dc1797ee939b948f635690289e0",
|
||||
"user-level-files/hooks/economy-self-check.py": "962db87b1abd05a8f783aa6e93d482750c14970ed5ab5229ea58582550f884d7",
|
||||
"user-level-files/hooks/economy-state-guard-test.py": "2c407af63a5356d051271ea9852485dd2265c593c6535f85c4055a6ebe480196",
|
||||
"user-level-files/hooks/economy-state-guard.py": "bb5278e356c33b8f99f05ad184b2b8b8d11692407b8e6216be7b0cfe3e11457c",
|
||||
"user-level-files/hooks/economy-verifier.py": "2b7431bcc1bf80179989e4f918a90de6b37627073cd04fa7a139757b18637a16",
|
||||
"user-level-files/hooks/skill-check.py": "5f708f412d4d6ea66cd2f14ba119cf784b602d79052bbb976f904339421a09ad",
|
||||
"user-level-files/hooks/skill-marker.py": "2d2ff205ae1390f87d1f8162e238729fa4d8c12340f02016ee1d54b3fff014a4",
|
||||
"user-level-files/marketplaces.json": "9017c313525cb78f2078ba79fd974260cb8016f69dbb9a099dcff7b4153af300",
|
||||
"user-level-files/mcp-user.template.json": "80cce6f971fa3dfca5533becab009060b703c914196a92ac3d6b2e3768b8b923",
|
||||
"user-level-files/plugins-manifest.json": "1374cf8f4206b972a9ef5be6692773f2b8eaf1016588470a32588539f347f324",
|
||||
"user-level-files/settings-fragment.json": "cbdda1e23034d0056db5165a85667d6a7d55de6e0629d7be4e9d9d7e4ebb4a7d"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+33
-3
@@ -69,20 +69,47 @@ if [ "$dry_run" -eq 1 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Backup
|
||||
# Backup (Bug 4 fix): create backup dir AND actually copy existing target tree
|
||||
# into it BEFORE any modifications, so overwrites are recoverable.
|
||||
if [ "$force" -eq 0 ]; then
|
||||
backup=$(make_backup_dir "$target")
|
||||
log_info "Backup: $backup"
|
||||
# Copy entire target tree into backup, excluding .git/ and .brain-backup-*
|
||||
# rsync preferred; cp -r fallback for environments without rsync.
|
||||
if command -v rsync >/dev/null 2>&1; then
|
||||
rsync -a \
|
||||
--exclude '.git/' \
|
||||
--exclude '.brain-backup-*' \
|
||||
"$target/" "$backup/" 2>/dev/null || true
|
||||
else
|
||||
# cp -r fallback: copy every top-level entry except .git and .brain-backup-*
|
||||
for entry in "$target"/* "$target"/.[!.]* "$target"/..?*; do
|
||||
[ -e "$entry" ] || continue
|
||||
base=$(basename "$entry")
|
||||
case "$base" in
|
||||
.git|.brain-backup-*) continue ;;
|
||||
esac
|
||||
cp -r "$entry" "$backup/" 2>/dev/null || true
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
# Copy files per mode
|
||||
if [ "$mode" = "project" ]; then
|
||||
src="$BRAIN_ROOT/project-files"
|
||||
if [ -d "$src" ]; then
|
||||
# Copy all files; strip .template suffix on the way
|
||||
# Copy all files; strip .template suffix (BOTH middle and trailing — Bug 2 fix)
|
||||
while IFS= read -r -d '' f; do
|
||||
rel="${f#$src/}"
|
||||
dst="$target/${rel%.template}"
|
||||
# Bug 5: skip brain-internal README (it describes brain repo
|
||||
# structure, not consumer content); consumer's own README stays.
|
||||
case "$rel" in
|
||||
README.md) continue ;;
|
||||
esac
|
||||
# Bug 2: strip both middle '.template.' and trailing '.template'
|
||||
dst_rel="${rel//.template\./.}"
|
||||
dst_rel="${dst_rel%.template}"
|
||||
dst="$target/$dst_rel"
|
||||
mkdir -p "$(dirname "$dst")"
|
||||
cp "$f" "$dst"
|
||||
done < <(find "$src" -type f -print0)
|
||||
@@ -99,6 +126,9 @@ elif [ "$mode" = "user" ]; then
|
||||
src="$BRAIN_ROOT/user-level-files"
|
||||
# Hooks
|
||||
[ -d "$src/hooks" ] && mkdir -p "$target/hooks" && cp "$src/hooks"/*.py "$target/hooks/" 2>/dev/null || true
|
||||
# Bug 5: skip brain-internal README in user mode too (we never copy it
|
||||
# explicitly above, but state it defensively for any future bulk copy).
|
||||
# No-op currently — hooks are copied individually, README.md is not.
|
||||
# settings.json merge
|
||||
if [ -f "$src/settings-fragment.json" ]; then
|
||||
bash "$SCRIPT_DIR/lib/merge-settings.sh" "$target/settings.json" "$src/settings-fragment.json"
|
||||
|
||||
@@ -33,17 +33,19 @@ fi
|
||||
backup="${target}.bak.$(date +%s)"
|
||||
cp "$target" "$backup"
|
||||
|
||||
# CORRECTION A: use --slurpfile to bind brain file to $brain (array of docs);
|
||||
# $brain[0] accesses the single document. This avoids the broken
|
||||
# "jq -s '.[0] | ... .[1].mcpServers'" form (which inside the inner pipe makes
|
||||
# .[1] index the object — runtime error "Cannot index object with number").
|
||||
# CORRECTION B (Bug 1 fix): use --argjson with shell-read content instead of
|
||||
# --slurpfile. jq on Windows MSYS2 cannot open paths with non-ASCII characters
|
||||
# (Cyrillic etc.) via its C-level fopen, but cat is a shell builtin/coreutil
|
||||
# that handles UTF-8 paths fine. --argjson takes a pre-parsed JSON string, so
|
||||
# this works regardless of path encoding.
|
||||
#
|
||||
# Merge semantics: target.mcpServers (or {} if missing) UNION brain.mcpServers,
|
||||
# with brain entries overriding on key collision (laravel-boost stays — brain
|
||||
# template doesn't define it; magic gets replaced if brain defines it).
|
||||
brain_content=$(cat "$brain_mcp")
|
||||
tmp="${target}.tmp"
|
||||
jq --slurpfile brain "$brain_mcp" \
|
||||
'.mcpServers = ((.mcpServers // {}) + $brain[0].mcpServers)' \
|
||||
jq --argjson brain "$brain_content" \
|
||||
'.mcpServers = ((.mcpServers // {}) + $brain.mcpServers)' \
|
||||
"$target" > "$tmp"
|
||||
|
||||
# Validate
|
||||
|
||||
@@ -46,6 +46,83 @@ BRAIN_ROOT="$brain_dir" bash "$brain_dir/scripts/install.sh" --target="$tmpdir"
|
||||
|
||||
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
|
||||
|
||||
@@ -68,6 +68,29 @@ 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
|
||||
|
||||
@@ -25,6 +25,74 @@ BRAIN_ROOT="$brain_dir" bash "$SCRIPT_DIR/verify.sh" --target="$tmpdir" >/dev/nu
|
||||
assert_eq "0" "$?" "valid .brain-version returns exit 0"
|
||||
rm -rf "$tmpdir" "$brain_dir"
|
||||
|
||||
# Test 3: project-mode verify with real consumer layout (Bug 3 regression)
|
||||
# Manifest uses project-mode section with target-relative paths.
|
||||
tmpdir=$(mktemp -d)
|
||||
echo "brain-v1.0" > "$tmpdir/.brain-version"
|
||||
echo "sha: deadbeef" >> "$tmpdir/.brain-version"
|
||||
mkdir -p "$tmpdir/docs"
|
||||
echo "consumer CLAUDE" > "$tmpdir/CLAUDE.md"
|
||||
echo "consumer pravila" > "$tmpdir/docs/Pravila_raboty_Claude.md"
|
||||
|
||||
# Compute SHAs
|
||||
sha_claude=$(sha256sum "$tmpdir/CLAUDE.md" | cut -d' ' -f1)
|
||||
sha_pravila=$(sha256sum "$tmpdir/docs/Pravila_raboty_Claude.md" | cut -d' ' -f1)
|
||||
|
||||
brain_dir=$(mktemp -d)
|
||||
cat > "$brain_dir/manifest.json" <<EOF7
|
||||
{
|
||||
"version": "brain-v1.0",
|
||||
"files": {
|
||||
"project-mode": {
|
||||
"CLAUDE.md": "$sha_claude",
|
||||
"docs/Pravila_raboty_Claude.md": "$sha_pravila"
|
||||
},
|
||||
"user-mode": {},
|
||||
"brain-internal": {}
|
||||
}
|
||||
}
|
||||
EOF7
|
||||
|
||||
BRAIN_ROOT="$brain_dir" bash "$SCRIPT_DIR/verify.sh" --target="$tmpdir" >/tmp/verify_test3.log 2>&1
|
||||
exit_code=$?
|
||||
assert_eq "0" "$exit_code" "project-mode: verify passes on consumer layout"
|
||||
|
||||
# Verify it used the right section
|
||||
grep -q "Manifest section: project-mode" /tmp/verify_test3.log && \
|
||||
assert_eq "yes" "yes" "project-mode: section auto-detected" || \
|
||||
assert_eq "yes" "no" "project-mode: section auto-detected"
|
||||
|
||||
rm -rf "$tmpdir" "$brain_dir" /tmp/verify_test3.log
|
||||
|
||||
# Test 4: brain-internal verify when target is brain root itself
|
||||
brain_dir=$(mktemp -d)
|
||||
mkdir -p "$brain_dir/project-files"
|
||||
echo "brain-v1.0" > "$brain_dir/.brain-version"
|
||||
echo "sha: deadbeef" >> "$brain_dir/.brain-version"
|
||||
echo "internal" > "$brain_dir/project-files/CLAUDE.md.template"
|
||||
sha_internal=$(sha256sum "$brain_dir/project-files/CLAUDE.md.template" | cut -d' ' -f1)
|
||||
cat > "$brain_dir/manifest.json" <<EOF8
|
||||
{
|
||||
"version": "brain-v1.0",
|
||||
"files": {
|
||||
"project-mode": {},
|
||||
"user-mode": {},
|
||||
"brain-internal": {
|
||||
"project-files/CLAUDE.md.template": "$sha_internal"
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF8
|
||||
|
||||
BRAIN_ROOT="$brain_dir" bash "$SCRIPT_DIR/verify.sh" --target="$brain_dir" >/tmp/verify_test4.log 2>&1
|
||||
exit_code=$?
|
||||
assert_eq "0" "$exit_code" "brain-internal: verify passes on brain root"
|
||||
grep -q "Manifest section: brain-internal" /tmp/verify_test4.log && \
|
||||
assert_eq "yes" "yes" "brain-internal: section auto-detected" || \
|
||||
assert_eq "yes" "no" "brain-internal: section auto-detected"
|
||||
|
||||
rm -rf "$brain_dir" /tmp/verify_test4.log
|
||||
|
||||
echo "---"
|
||||
echo "Failures: $FAILURES"
|
||||
exit $FAILURES
|
||||
|
||||
+22
-3
@@ -40,8 +40,27 @@ log_info "Found .brain-version: $version"
|
||||
manifest="$BRAIN_ROOT/manifest.json"
|
||||
[ -f "$manifest" ] || { log_error "manifest.json missing in BRAIN_ROOT=$BRAIN_ROOT"; exit 1; }
|
||||
|
||||
# Check 3: sha256 per file in manifest (если manifest содержит files)
|
||||
files_count=$(jq -r '(.files // {}) | length' "$manifest")
|
||||
# Bug 3 fix: manifest.files now has three sub-maps with target-relative paths:
|
||||
# project-mode — paths as they appear in consumer project target
|
||||
# user-mode — paths as they appear in ~/.claude/ target
|
||||
# brain-internal — brain-repo paths (for self-verify when target == brain root)
|
||||
#
|
||||
# We pick the map based on detected target type:
|
||||
# - target is the brain root itself (contains project-files/ AND manifest.json) → brain-internal
|
||||
# - target is ~/.claude or has hooks/ or settings.json → user-mode
|
||||
# - everything else (project-mode default)
|
||||
manifest_section=""
|
||||
if [ -d "$target/project-files" ] && [ -f "$target/manifest.json" ]; then
|
||||
manifest_section="brain-internal"
|
||||
elif [ "$target" = "$HOME/.claude" ] || [ -d "$target/hooks" ] || [ -f "$target/settings.json" ]; then
|
||||
manifest_section="user-mode"
|
||||
else
|
||||
manifest_section="project-mode"
|
||||
fi
|
||||
log_info "Manifest section: $manifest_section"
|
||||
|
||||
# Check 3: sha256 per file in chosen section
|
||||
files_count=$(jq -r --arg s "$manifest_section" '(.files[$s] // {}) | length' "$manifest")
|
||||
if [ "$files_count" -gt 0 ]; then
|
||||
log_info "Verifying $files_count file hashes..."
|
||||
while IFS= read -r entry; do
|
||||
@@ -64,7 +83,7 @@ if [ "$files_count" -gt 0 ]; then
|
||||
log_error "SHA mismatch: $rel_path (expected $expected_sha, got $actual_sha)"
|
||||
exit 2
|
||||
fi
|
||||
done < <(jq -c '(.files // {}) | to_entries[]' "$manifest")
|
||||
done < <(jq -c --arg s "$manifest_section" '(.files[$s] // {}) | to_entries[]' "$manifest")
|
||||
fi
|
||||
|
||||
# Check 4: strict secrets — no unresolved <<*>> placeholders
|
||||
|
||||
Reference in New Issue
Block a user