Files
Holocron/tests/test-install.sh
T
Defame1297andClaude Opus 5.5 aa8319a1db feat(install): merge user settings and turn off bundled skills
Copying the repo's settings.json over ~/.claude/settings.json would delete
most of the operator's settings, so the installer now merges it. The merge
and the new settings land together, so no overwriting installer ever
deploys them.

The merge runs before any other file is deployed, so an invalid settings
file stops the install with nothing changed. It writes a complete temporary
file and renames it, so a failure cannot truncate the user's settings.

Impact: removing a setting from the repo no longer removes it from a
machine that already has it.

ADR: 0035
Refs: #280
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-04 19:48:53 +00:00

185 lines
6.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PASS=0
FAIL=0
pass() { echo " PASS: $1"; PASS=$((PASS + 1)); }
fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); }
TEMP_HOME="$(mktemp -d)"
trap 'rm -rf "$TEMP_HOME"' EXIT
echo "Running install.sh..."
HOME="$TEMP_HOME" bash "$REPO_ROOT/scripts/install.sh" > /dev/null
echo ""
echo "--- providers/claude-code/ → ~/.claude/ ---"
while IFS= read -r -d '' src; do
rel="${src#"$REPO_ROOT/providers/claude-code/"}"
[[ "$rel" == "provider-manifest.sh" ]] && continue
dest="$TEMP_HOME/.claude/$rel"
if diff -q "$src" "$dest" > /dev/null 2>&1; then
pass "$rel deployed and matches source"
else
fail "$rel — missing or differs from source"
fi
done < <(find "$REPO_ROOT/providers/claude-code" -type f -print0)
echo ""
echo "--- core/ → ~/.claude/core/ ---"
while IFS= read -r -d '' src; do
rel="${src#"$REPO_ROOT/core/"}"
dest="$TEMP_HOME/.claude/core/$rel"
if diff -q "$src" "$dest" > /dev/null 2>&1; then
pass "$rel deployed and matches source"
else
fail "$rel — missing or differs from source"
fi
done < <(find "$REPO_ROOT/core" -type f -print0)
echo ""
echo "--- no orphaned files in core/ ---"
while IFS= read -r -d '' deployed; do
rel="${deployed#"$TEMP_HOME/.claude/core/"}"
src="$REPO_ROOT/core/$rel"
if [[ -f "$src" ]]; then
pass "core/$rel has a source file"
else
fail "core/$rel is orphaned — deleted from source but still deployed"
fi
done < <(find "$TEMP_HOME/.claude/core" -type f -print0)
echo ""
echo "--- core/AGENTS.md → ~/.agents/AGENTS.md (0015) ---"
if diff -q "$REPO_ROOT/core/AGENTS.md" "$TEMP_HOME/.agents/AGENTS.md" > /dev/null 2>&1; then
pass "core/AGENTS.md deployed and matches source"
else
fail "\$HOME/.agents/AGENTS.md — missing or differs from source"
fi
echo ""
echo "--- idempotency: second run state is correct ---"
if HOME="$TEMP_HOME" bash "$REPO_ROOT/scripts/install.sh" > /dev/null 2>&1; then
pass "second run exits zero"
else
fail "second run failed"
fi
# AGENTS.md still correct after second run
if diff -q "$REPO_ROOT/core/AGENTS.md" "$TEMP_HOME/.agents/AGENTS.md" > /dev/null 2>&1; then
pass "idempotent: ~/.agents/AGENTS.md correct after second install"
else
fail "idempotent: ~/.agents/AGENTS.md corrupted after second install"
fi
SETTINGS_SRC="$REPO_ROOT/providers/claude-code/settings.json"
if cmp -s "$SETTINGS_SRC" "$TEMP_HOME/.claude/settings.json"; then
pass "idempotent: settings.json still identical to source after second install"
else
fail "idempotent: settings.json changed by second install"
fi
echo ""
echo "--- settings.json is merged into an existing file (ADR-0035) ---"
new_home() {
local home
home="$(mktemp -d "$TEMP_HOME/merge.XXXXXX")"
mkdir -p "$home/.claude"
echo "$home"
}
install_into() {
HOME="$1" bash "$REPO_ROOT/scripts/install.sh" 2>&1
}
# Asserts a Python expression over the parsed JSON file, bound to `s`.
check_json() {
local file="$1" expr="$2" name="$3"
if python3 -c 'import json, sys; s = json.load(open(sys.argv[1], encoding="utf-8")); sys.exit(not eval(sys.argv[2]))' "$file" "$expr" 2> /dev/null; then
pass "$name"
else
fail "$name"
fi
}
check_json "$SETTINGS_SRC" \
's["disableBundledSkills"] is True and s["syncClaudeAiSkills"] is False and s["env"]["CLAUDE_CODE_DISABLE_SHIP"] == "1" and s["skillOverrides"]["init"] == "off"' \
"repo settings turn off bundled and synced skills"
MERGE_HOME="$(new_home)"
MERGED="$MERGE_HOME/.claude/settings.json"
cat > "$MERGED" << 'EOF'
{
"model": "opus",
"theme": "light",
"permissions": {"allow": ["Bash(ls:*)"]},
"env": {"MY_VAR": "kept", "CLAUDE_CODE_DISABLE_SHIP": "0"},
"skillOverrides": {"other": "off", "init": "on"}
}
EOF
chmod 640 "$MERGED"
install_into "$MERGE_HOME" > /dev/null || fail "install over existing settings exited non-zero"
check_json "$MERGED" 's["model"] == "opus" and s["permissions"] == {"allow": ["Bash(ls:*)"]}' \
"top-level settings the repo does not set are kept"
check_json "$MERGED" 's["env"]["MY_VAR"] == "kept" and s["skillOverrides"]["other"] == "off"' \
"nested entries the repo does not set are kept"
check_json "$MERGED" 's["theme"] == "dark" and s["env"]["CLAUDE_CODE_DISABLE_SHIP"] == "1" and s["skillOverrides"]["init"] == "off"' \
"the repo's value wins where both set one"
check_json "$MERGED" 's["disableBundledSkills"] is True and s["syncClaudeAiSkills"] is False' \
"settings only the repo has are added"
if [[ "$(find "$MERGED" -perm 640)" == "$MERGED" ]]; then
pass "the existing file's permissions are kept"
else
fail "the existing file's permissions changed"
fi
cp "$MERGED" "$MERGE_HOME/first-run.json"
install_into "$MERGE_HOME" > /dev/null || fail "second install exited non-zero"
if cmp -s "$MERGE_HOME/first-run.json" "$MERGED"; then
pass "a second run leaves the merged settings unchanged"
else
fail "a second run changed the merged settings"
fi
for invalid in '{"model": "opus",' '["not an object"]' ''; do
BAD_HOME="$(new_home)"
BAD="$BAD_HOME/.claude/settings.json"
printf '%s' "$invalid" > "$BAD"
printf '%s' "$invalid" > "$BAD_HOME/before"
if output="$(install_into "$BAD_HOME")"; then
fail "install accepted invalid settings: '$invalid'"
elif [[ "$output" == *"$BAD"* && "$output" != *Traceback* ]]; then
pass "invalid settings exit non-zero with an error naming the file: '$invalid'"
else
fail "invalid settings gave no clear error: '$invalid'"
fi
if cmp -s "$BAD_HOME/before" "$BAD"; then
pass "invalid settings are left untouched: '$invalid'"
else
fail "invalid settings were changed: '$invalid'"
fi
done
LINK_HOME="$(new_home)"
mkdir "$LINK_HOME/dotfiles"
echo '{"model": "opus"}' > "$LINK_HOME/dotfiles/settings.json"
ln -s ../dotfiles/settings.json "$LINK_HOME/.claude/settings.json"
install_into "$LINK_HOME" > /dev/null || fail "install through a symlink exited non-zero"
if [[ -L "$LINK_HOME/.claude/settings.json" ]]; then
pass "a symlinked settings file stays a symlink"
else
fail "a symlinked settings file was replaced by a regular file"
fi
check_json "$LINK_HOME/dotfiles/settings.json" 's["model"] == "opus" and s["theme"] == "dark"' \
"the symlink's target receives the merge"
echo ""
echo "Results: $PASS passed, $FAIL failed"
[[ $FAIL -eq 0 ]]