mirror of
https://github.com/gnekt/My-Brain-Is-Full-Crew.git
synced 2026-09-05 15:00:49 +00:00
Co-Authored-By: win0na <winnie@winneon.moe> feat(opencode): config-merge.sh with formatting-preserving JSON merge Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> build(opencode): source config-merge.sh from adapter Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> feat(install): use oc_config_merge for opencode.json instead of overwrite Source config-merge.sh from install scripts for opencode platform so user keys in opencode.json are preserved on reinstall and update. Fix in-place merge by writing to a temp file before moving to output. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
173 lines
4.4 KiB
Bash
Executable File
173 lines
4.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Tests for adapters/opencode/config-merge.sh
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
|
|
source "$ROOT/adapters/lib.sh"
|
|
source "$ROOT/adapters/opencode/config-merge.sh"
|
|
|
|
test_oc_merge_fresh_install() {
|
|
local built; built="$(mktemp)"
|
|
local existing; existing="$(mktemp)"
|
|
local output; output="$(mktemp)"
|
|
rm "$existing"
|
|
cat > "$built" <<'HEREDOC'
|
|
{
|
|
"mcp": {
|
|
"Gmail": {
|
|
"type": "remote",
|
|
"url": "https://gmail.mcp.claude.com/mcp"
|
|
}
|
|
}
|
|
}
|
|
HEREDOC
|
|
oc_config_merge "$built" "$existing" "$output"
|
|
local result=0
|
|
[[ -f "$output" ]] || { echo "output not created"; result=1; }
|
|
jq -e '.mcp.Gmail.url' "$output" >/dev/null || { echo "Gmail not in output"; result=1; }
|
|
rm -f "$built" "$output"
|
|
return $result
|
|
}
|
|
|
|
test_oc_merge_preserves_user_keys() {
|
|
local built; built="$(mktemp)"
|
|
local existing; existing="$(mktemp)"
|
|
local output; output="$(mktemp)"
|
|
cat > "$built" <<'HEREDOC'
|
|
{
|
|
"mcp": {
|
|
"Gmail": {
|
|
"type": "remote",
|
|
"url": "https://gmail.mcp.claude.com/mcp"
|
|
}
|
|
}
|
|
}
|
|
HEREDOC
|
|
cat > "$existing" <<'HEREDOC'
|
|
{
|
|
"model": "anthropic/claude-sonnet-4-5",
|
|
"small_model": "anthropic/claude-haiku-4-5",
|
|
"mcp": {
|
|
"MyCustomServer": {
|
|
"type": "local",
|
|
"command": "my-server"
|
|
}
|
|
}
|
|
}
|
|
HEREDOC
|
|
oc_config_merge "$built" "$existing" "$output"
|
|
local result=0
|
|
jq -e '.mcp.Gmail.url' "$output" >/dev/null || { echo "Gmail missing"; result=1; }
|
|
jq -e '.model == "anthropic/claude-sonnet-4-5"' "$output" >/dev/null || { echo "model key lost"; result=1; }
|
|
jq -e '.small_model == "anthropic/claude-haiku-4-5"' "$output" >/dev/null || { echo "small_model key lost"; result=1; }
|
|
jq -e '.mcp.MyCustomServer.command == "my-server"' "$output" >/dev/null || { echo "user MCP server lost"; result=1; }
|
|
rm -f "$built" "$existing" "$output"
|
|
return $result
|
|
}
|
|
|
|
test_oc_merge_our_mcp_overwrites_same_name() {
|
|
local built; built="$(mktemp)"
|
|
local existing; existing="$(mktemp)"
|
|
local output; output="$(mktemp)"
|
|
cat > "$built" <<'HEREDOC'
|
|
{
|
|
"mcp": {
|
|
"Gmail": {
|
|
"type": "remote",
|
|
"url": "https://gmail.mcp.claude.com/mcp"
|
|
}
|
|
}
|
|
}
|
|
HEREDOC
|
|
cat > "$existing" <<'HEREDOC'
|
|
{
|
|
"mcp": {
|
|
"Gmail": {
|
|
"type": "remote",
|
|
"url": "https://old-url.example.com"
|
|
}
|
|
}
|
|
}
|
|
HEREDOC
|
|
oc_config_merge "$built" "$existing" "$output"
|
|
local result=0
|
|
local url; url="$(jq -r '.mcp.Gmail.url' "$output")"
|
|
[[ "$url" == "https://gmail.mcp.claude.com/mcp" ]] || { echo "our url should win: got $url"; result=1; }
|
|
rm -f "$built" "$existing" "$output"
|
|
return $result
|
|
}
|
|
|
|
test_oc_merge_detects_indentation() {
|
|
local built; built="$(mktemp)"
|
|
local existing; existing="$(mktemp)"
|
|
local output; output="$(mktemp)"
|
|
cat > "$built" <<'HEREDOC'
|
|
{
|
|
"mcp": {
|
|
"Gmail": {
|
|
"type": "remote",
|
|
"url": "https://gmail.mcp.claude.com/mcp"
|
|
}
|
|
}
|
|
}
|
|
HEREDOC
|
|
cat > "$existing" <<'HEREDOC'
|
|
{
|
|
"model": "anthropic/claude-sonnet-4-5",
|
|
"mcp": {}
|
|
}
|
|
HEREDOC
|
|
oc_config_merge "$built" "$existing" "$output"
|
|
local result=0
|
|
grep -q '^ "model"' "$output" || { echo "expected 4-space indent"; cat "$output"; result=1; }
|
|
rm -f "$built" "$existing" "$output"
|
|
return $result
|
|
}
|
|
|
|
test_oc_merge_malformed_existing_falls_back() {
|
|
local built; built="$(mktemp)"
|
|
local existing; existing="$(mktemp)"
|
|
local output; output="$(mktemp)"
|
|
cat > "$built" <<'HEREDOC'
|
|
{
|
|
"mcp": {
|
|
"Gmail": {
|
|
"type": "remote",
|
|
"url": "https://gmail.mcp.claude.com/mcp"
|
|
}
|
|
}
|
|
}
|
|
HEREDOC
|
|
echo "this is not json" > "$existing"
|
|
oc_config_merge "$built" "$existing" "$output" 2>/dev/null
|
|
local result=0
|
|
jq -e '.mcp.Gmail.url' "$output" >/dev/null || { echo "fallback failed"; result=1; }
|
|
rm -f "$built" "$existing" "$output"
|
|
return $result
|
|
}
|
|
|
|
test_oc_merge_no_mcp_in_existing() {
|
|
local built; built="$(mktemp)"
|
|
local existing; existing="$(mktemp)"
|
|
local output; output="$(mktemp)"
|
|
cat > "$built" <<'HEREDOC'
|
|
{
|
|
"mcp": {
|
|
"Gmail": {
|
|
"type": "remote",
|
|
"url": "https://gmail.mcp.claude.com/mcp"
|
|
}
|
|
}
|
|
}
|
|
HEREDOC
|
|
cat > "$existing" <<'HEREDOC'
|
|
{
|
|
"model": "anthropic/claude-sonnet-4-5"
|
|
}
|
|
HEREDOC
|
|
oc_config_merge "$built" "$existing" "$output"
|
|
local result=0
|
|
jq -e '.model == "anthropic/claude-sonnet-4-5"' "$output" >/dev/null || { echo "model key lost"; result=1; }
|
|
jq -e '.mcp.Gmail.url' "$output" >/dev/null || { echo "Gmail not added"; result=1; }
|
|
rm -f "$built" "$existing" "$output"
|
|
return $result
|
|
}
|