0ba32c29dc
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
65 lines
1.8 KiB
Bash
65 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
set -u
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
|
source "$SCRIPT_DIR/lib/common.sh"
|
|
|
|
FAILURES=0
|
|
assert_eq() {
|
|
local expected="$1" actual="$2" name="$3"
|
|
if [ "$expected" = "$actual" ]; then
|
|
echo "PASS: $name"
|
|
else
|
|
echo "FAIL: $name (expected '$expected', got '$actual')"
|
|
FAILURES=$((FAILURES + 1))
|
|
fi
|
|
}
|
|
|
|
# Setup: temp consumer settings + brain fragment
|
|
tmpdir=$(mktemp -d)
|
|
cp "$SCRIPT_DIR/fixtures/sample-settings.json" "$tmpdir/settings.json"
|
|
cat > "$tmpdir/fragment.json" <<EOF2
|
|
{
|
|
"enabledPlugins": {
|
|
"new-plugin@new-mp": true
|
|
},
|
|
"permissions": {
|
|
"allow": ["Bash(new:*)"],
|
|
"deny": ["Bash(rm:*)"],
|
|
"ask": []
|
|
},
|
|
"hooks": {
|
|
"SessionStart": [{"hooks": [{"type": "command", "command": "echo new"}]}]
|
|
}
|
|
}
|
|
EOF2
|
|
|
|
# Run merge
|
|
bash "$SCRIPT_DIR/lib/merge-settings.sh" "$tmpdir/settings.json" "$tmpdir/fragment.json"
|
|
|
|
# Test 1: theme preserved
|
|
theme=$(jq -r '.theme' "$tmpdir/settings.json")
|
|
assert_eq "dark" "$theme" "theme preserved"
|
|
|
|
# Test 2: editorMode preserved
|
|
em=$(jq -r '.editorMode' "$tmpdir/settings.json")
|
|
assert_eq "vscode" "$em" "editorMode preserved"
|
|
|
|
# Test 3: enabledPlugins replaced (not merged)
|
|
plugins=$(jq -r '.enabledPlugins | keys[]' "$tmpdir/settings.json")
|
|
assert_eq "new-plugin@new-mp" "$plugins" "enabledPlugins replaced with brain version"
|
|
|
|
# Test 4: permissions.deny populated from fragment
|
|
deny=$(jq -r '.permissions.deny[0]' "$tmpdir/settings.json")
|
|
assert_eq "Bash(rm:*)" "$deny" "permissions.deny from fragment"
|
|
|
|
# Test 5: hooks replaced
|
|
hook_cmd=$(jq -r '.hooks.SessionStart[0].hooks[0].command' "$tmpdir/settings.json")
|
|
assert_eq "echo new" "$hook_cmd" "hooks replaced with brain version"
|
|
|
|
# Cleanup
|
|
rm -rf "$tmpdir"
|
|
|
|
echo "---"
|
|
echo "Failures: $FAILURES"
|
|
exit $FAILURES
|