Files
My-Brain-Is-Full-Crew/tests/adapters/opencode/adapter.test.sh
Giacomo Nunziati 53b605379e feat: multi-platform adapter architecture (Claude Code, Gemini CLI, OpenCode) (#32)
* Fix istall/update scripts

* test: capture pre-refactor install snapshot for regression

Adds take-snapshot.sh script and the resulting snapshot/ directory,
capturing the exact vault state produced by launchme.sh before the
framework-agnosticity refactor begins.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Summary: Refactor agents/skills/hooks/mcp in agentic-platform-agnostic templates.

refactor: rename source CLAUDE.md → DISPATCHER.md (framework-neutral)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

refactor: convert agent frontmatter from tools: to neutral capabilities:

Replace Claude Code-specific `tools:` frontmatter with framework-agnostic
`mode: subagent` and `capabilities: [...]` in all 8 agent files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

refactor: add neutral hook trigger manifests (.hook.yaml)

refactor: hooks read neutral JSON schema (args.* instead of tool_input.*)

refactor: convert .mcp.json to neutral mcp/servers.yaml

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Implement agentic-platform adapters skeleton.

build: add adapters/lib.sh skeleton with vocabulary constants

test: bash test runner for adapter helpers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(adapters): parse_frontmatter helper with tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(adapters): parse_capabilities helper with tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(adapters): should_include helper with tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(adapters): parse_hook_yaml helper with tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(adapters): agent_body helper with tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(adapters): enumerate_agents and enumerate_hooks helpers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Implement agentic-platform adapter for Claude Code.

build(adapters): claude-code adapter skeleton with capability/event tables

build(claude-code): adapter_translate_dispatcher with test

build(claude-code): adapter_translate_references with test

build(claude-code): adapter_translate_skills with tests

build(claude-code): adapter_translate_agents with capability→tools mapping

build(claude-code): hook wrapper template (CC native → neutral schema)

build(claude-code): adapter_translate_hooks with wrapper generation

build(claude-code): adapter_translate_mcp with hand-rolled YAML parser

build(claude-code): adapter_finalize and complete adapter_build wiring

build: scripts/build.sh dispatches to per-framework adapter

Also fix adapter_translate_hooks and adapter_translate_agents to use
while-read loops (avoiding word-splitting on paths with spaces) and
guard grep calls with || true to survive set -eo pipefail when hooks
have no match-tool field. Remove scripts/build.sh from .gitignore.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Refactor install/update scripts to support agentic-platform agnosticity.

refactor(lib.sh): generalize install_claude_md → install_dispatcher

New signature takes the full destination path instead of just the vault
dir, allowing callers to install CLAUDE.md, AGENTS.md, or any dispatcher
file to an explicit location.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat(launchme): support --framework flag, build dist/ before install

Add --framework and --target arg parsing. Run build.sh before installing
to populate dist/<framework>/. All install_* calls now read from
dist/<framework>/ instead of the raw source dirs. MCP is now handled
automatically by the adapter (no interactive prompt). Replaced
install_claude_md with install_dispatcher.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat(updateme): support --framework flag, build dist/ before update

Add --framework and --target arg parsing. Run build.sh before installing
to populate dist/<framework>/. All install_* calls now read from
dist/<framework>/ instead of raw source dirs. Replaced install_claude_md
with install_dispatcher.

Also fix set -e compatibility in lib.sh: add || true to all conditional
[[ ... ]] && info "..." logging lines so they don't abort the script
when VERBOSE_COPY=0.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test: regression runner diffs dist/claude-code against pre-refactor snapshot

- Add tests/regression/run.sh that builds dist/claude-code and compares
  against snapshot, excluding runtime-only artifacts (.mbifc-manifest,
  .mcp.json, .claude-plugin/plugin.json)
- Fix adapters/lib.sh agent_body: preserve '---' section dividers in body
  (awk now only skips '---' while still inside frontmatter, fm < 2)
- Fix adapters/claude-code/adapter.sh: change 'read' capability to expand
  to only 'Read', appending 'Glob, Grep' at end of tools list to match
  snapshot ordering
- Update snapshot to reflect intentional refactor changes: hook JSON schema
  (.args.* instead of .tool_input.*), wrapper scripts, settings.json with
  wrapper paths, and consistent tool ordering for postman/sorter

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Implement opencode adapter.

Co-Authored-By: win0na <winnie@winneon.moe>

feat(lib.sh): add install_plugins helper for opencode JS plugins

build(adapters): opencode adapter skeleton with capability/event tables

build(opencode): adapter_translate_dispatcher (DISPATCHER.md → AGENTS.md)

build(opencode): adapter_translate_references and adapter_translate_skills

Implements Task 4 and Task 5:
- adapter_translate_references: Copies reference markdown files to .opencode/references/
- adapter_translate_skills: Copies skill SKILL.md files to .opencode/skills/<name>/ with exclude filtering

Both functions respect framework filtering via should_include().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(opencode): adapter_translate_agents with capability→permission mapping

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(opencode): bash-executor template for spawning hook scripts

build(opencode): plugin-stub template for mbifc-hooks.js

build(opencode): adapter_translate_hooks with JS plugin generation

Implements _oc_hook_registry_json and adapter_translate_hooks in the
opencode adapter. Copies hook scripts to .opencode/hooks/, generates a
single .opencode/plugins/mbifc-hooks.js by inlining bash-executor.js and
synthesising a hook registry from *.hook.yaml files. Uses python3 for
template substitution to safely handle multi-line JS content. Adds 3
unit tests (copies scripts, registry entries, noop when no hooks dir).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(opencode): adapter_translate_mcp with local/remote handling

build(opencode): adapter_finalize and complete adapter_build wiring

Add adapter_finalize placeholder and wire adapter_translate_mcp into
adapter_build; add end-to-end integration test (14/14 pass).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat(launchme): branch on --framework for opencode install layout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat(updateme): branch on --framework for opencode install layout

Mirror the same case "$FRAMEWORK" block from launchme.sh: framework-specific
DIST_COMPONENTS_DIR, VAULT_COMPONENTS_DIR, DISPATCHER_SRC/DST, MCP_SRC/DST,
HAS_PLUGINS; conditional install_plugins; conditional install_settings;
framework-aware vault-setup check; framework-neutral summary messages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix adapters to follow the same template.

fix: restore adapter_build() contract, revert function renames

Both adapters now export adapter_build() and adapter_translate_*() as
the uniform public contract. scripts/build.sh sources one adapter and
calls adapter_build uniformly. Private helpers (_oc_*) and vocabulary
tables (cc_capability_to_tools, oc_capability_to_permission, etc.)
retain their prefixes. CC regression and OC unit tests all pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

fix(tests): restore test_oc_ prefix on adapter_build end-to-end test

* Fix agent format in opencode adapter

* refactor: rename --framework to --platform across all scripts and tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Modify generic name for model tiers

Co-Authored-By: win0na <winnie@winneon.moe>

refactor: neutral model vocabulary (low/mid/high) in source agents

feat(claude-code): cc_model_to_native() maps low/mid/high to haiku/sonnet/opus

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat(opencode): update oc_model_to_provider() for low/mid/high vocabulary

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add gemini-cli adapter

Co-Authored-By: win0na <winnie@winneon.moe>

build(gemini-cli): adapter skeleton with capability/event/model tables

build(gemini-cli): adapter_translate_dispatcher (DISPATCHER.md → GEMINI.md)

build(gemini-cli): adapter_translate_references and adapter_translate_skills

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(gemini-cli): adapter_translate_agents with capability→tools mapping

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

build(gemini-cli): adapter_translate_hooks with wrapper scripts

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

feat(install): add gemini-cli platform to launchme.sh and updateme.sh

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Implement preserving config merge for opencode.

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>

* Add mcp files to gitignore.

* Fix claude-specific references in agents, skills and references

* Fix: remove claude-specific reference from hooks.

build: add platform_dir and dispatcher_name to all hook wrapper/plugin templates

feat(hooks): platform-aware path checks using platform_dir and dispatcher_name from JSON input

test: update regression snapshot for platform-aware hook wrappers and scripts

* Added interactive platform choice in launchme, and platform auto-detection in updateme.

* Fix: remove claude-specific references from documentation

* Update documentation to reflect the new platform-agnostic architecture

* fix: address Copilot review feedback on PR #32

- tests/run.sh: check source return code, report failures
- tests/regression/run.sh: use mktemp + trap cleanup instead of fixed /tmp paths
- tests/regression/run.sh: include .mcp.json in regression comparison
- tests/regression/take-snapshot.sh: use --platform flag instead of stale scripted input
- adapters/opencode/templates/plugin-stub.js.tmpl: include stdout in hook block error message

* fix: address Copilot review round 2

- config-merge.sh: reword comment to only promise indentation preservation (not full formatting)
- take-snapshot.sh: copy required artifacts explicitly, optional ones with existence check
- adapters/lib.sh: document parse_hook_yaml single-trigger limitation

* fix: address Copilot review round 3

- adapters/opencode/adapter.sh: replace python3 template substitution with
  pure bash (while-read loop with case matching), removing python3 dependency
- adapters/lib.sh: should_include now falls back to plain YAML key read for
  files without frontmatter delimiters (fixes hook .yaml exclude: support)

* fix: address Copilot review round 4

- scripts/launchme.sh: fix double-dot in FW_DIR_NAME display (basename
  already includes the dot, e.g. ".claude")
- scripts/launchme.sh: replace undefined MCP_ANSWER with check on MCP_DST
  existence for summary banner

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 23:28:28 +02:00

407 lines
13 KiB
Bash
Executable File

#!/usr/bin/env bash
# Tests for adapters/opencode/adapter.sh
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
source "$ROOT/adapters/lib.sh"
source "$ROOT/adapters/opencode/adapter.sh"
test_oc_translate_dispatcher_renames_to_agents_md() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
cat > "$src/DISPATCHER.md" <<'EOF'
# Dispatcher
See .platform/agents/ for agents. Consult DISPATCHER.md for rules.
EOF
adapter_translate_dispatcher "$src/DISPATCHER.md" "$dst"
local result=0
[[ -f "$dst/AGENTS.md" ]] || { echo "AGENTS.md not created"; result=1; }
[[ ! -f "$dst/CLAUDE.md" ]] || { echo "CLAUDE.md should not exist"; result=1; }
local content; content="$(cat "$dst/AGENTS.md")"
[[ "$content" == *".opencode/agents/"* ]] || { echo ".opencode/agents/ not found: $content"; result=1; }
[[ "$content" == *"AGENTS.md"* ]] || { echo "AGENTS.md ref not rewritten: $content"; result=1; }
[[ "$content" != *".claude/"* ]] || { echo ".claude/ still present: $content"; result=1; }
[[ "$content" != *"CLAUDE.md"* ]] || { echo "CLAUDE.md still present: $content"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_references_copies_md_files() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/references"
echo "ref1" > "$src/references/one.md"
echo "ref2" > "$src/references/two.md"
adapter_translate_references "$src/references" "$dst"
local result=0
[[ -f "$dst/.opencode/references/one.md" ]] || { echo "one.md missing"; result=1; }
[[ -f "$dst/.opencode/references/two.md" ]] || { echo "two.md missing"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_references_rewrites_paths() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/references"
printf 'See .platform/agents/ and DISPATCHER.md for details.\n' > "$src/references/guide.md"
adapter_translate_references "$src/references" "$dst"
local content; content="$(cat "$dst/.opencode/references/guide.md")"
local result=0
[[ "$content" == *".opencode/agents/"* ]] || { echo ".opencode/agents/ not found: $content"; result=1; }
[[ "$content" == *"AGENTS.md"* ]] || { echo "AGENTS.md not found: $content"; result=1; }
[[ "$content" != *".claude/"* ]] || { echo ".claude/ still present: $content"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_skills_copies_skill_md() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/skills/foo" "$src/skills/bar"
cat > "$src/skills/foo/SKILL.md" <<'SKILLEOF'
---
name: foo
description: Foo skill
---
body
SKILLEOF
cat > "$src/skills/bar/SKILL.md" <<'SKILLEOF'
---
name: bar
description: Bar skill
---
body
SKILLEOF
adapter_translate_skills "$src/skills" "$dst"
local result=0
[[ -f "$dst/.opencode/skills/foo/SKILL.md" ]] || { echo "foo missing"; result=1; }
[[ -f "$dst/.opencode/skills/bar/SKILL.md" ]] || { echo "bar missing"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_skills_rewrites_paths() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/skills/create-agent"
cat > "$src/skills/create-agent/SKILL.md" <<'SKILLEOF'
---
name: create-agent
description: Create a new agent
---
Save to .platform/agents/ and update DISPATCHER.md.
SKILLEOF
adapter_translate_skills "$src/skills" "$dst"
local content; content="$(cat "$dst/.opencode/skills/create-agent/SKILL.md")"
local result=0
[[ "$content" == *".opencode/agents/"* ]] || { echo ".opencode/agents/ not found: $content"; result=1; }
[[ "$content" == *"AGENTS.md"* ]] || { echo "AGENTS.md not found: $content"; result=1; }
[[ "$content" != *".claude/"* ]] || { echo ".claude/ still present: $content"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_skills_honors_exclude() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/skills/foo"
cat > "$src/skills/foo/SKILL.md" <<'SKILLEOF'
---
name: foo
description: Foo
exclude: [opencode]
---
SKILLEOF
adapter_translate_skills "$src/skills" "$dst"
local result=0
[[ ! -f "$dst/.opencode/skills/foo/SKILL.md" ]] || { echo "foo should be excluded"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_agents_basic() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/agents"
cat > "$src/agents/scribe.md" <<'EOF'
---
name: scribe
description: Test scribe
model: mid
mode: subagent
capabilities: [read, write, edit]
---
You are the Scribe.
EOF
adapter_translate_agents "$src/agents" "$dst"
local out="$dst/.opencode/agents/scribe.md"
local result=0
[[ -f "$out" ]] || { echo "agent file missing"; result=1; }
grep -q '^description: Test scribe' "$out" || { echo "description missing or wrong format"; cat "$out"; result=1; }
grep -q '^mode: subagent' "$out" || { echo "mode missing"; result=1; }
grep -q '^model: anthropic/claude-sonnet-4-5' "$out" || { echo "model not mapped"; result=1; }
grep -q '^permission:' "$out" || { echo "permission block missing"; result=1; }
grep -q '^ edit: allow' "$out" || { echo "edit permission missing"; result=1; }
grep -q '^You are the Scribe' "$out" || { echo "body missing"; result=1; }
grep -q '^name:' "$out" && { echo "name: should be dropped"; result=1; }
grep -q '^capabilities:' "$out" && { echo "capabilities: should be dropped"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_agents_rewrites_body_paths() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/agents"
cat > "$src/agents/scribe.md" <<'EOF'
---
name: scribe
description: Test scribe
model: sonnet
capabilities: [read, write]
---
See .platform/references/agents.md and DISPATCHER.md for context.
EOF
adapter_translate_agents "$src/agents" "$dst"
local out="$dst/.opencode/agents/scribe.md"
local result=0
local content; content="$(cat "$out")"
[[ "$content" == *".opencode/references/agents.md"* ]] || { echo ".opencode/references/ not found: $content"; result=1; }
[[ "$content" == *"AGENTS.md"* ]] || { echo "AGENTS.md not found: $content"; result=1; }
[[ "$content" != *".claude/"* ]] || { echo ".claude/ still present: $content"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_agents_bash_capability() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/agents"
cat > "$src/agents/architect.md" <<'EOF'
---
name: architect
description: Test arch
model: high
capabilities: [read, write, edit, bash]
---
body
EOF
adapter_translate_agents "$src/agents" "$dst"
local out="$dst/.opencode/agents/architect.md"
local result=0
grep -q '^ edit: allow' "$out" || { echo "edit missing"; result=1; }
grep -q '^ bash: allow' "$out" || { echo "bash missing"; result=1; }
grep -q '^model: anthropic/claude-opus-4-5' "$out" || { echo "model not mapped"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_agents_read_only_emits_empty_permission() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/agents"
cat > "$src/agents/seeker.md" <<'EOF'
---
name: seeker
description: Search only
model: mid
capabilities: [read]
---
body
EOF
adapter_translate_agents "$src/agents" "$dst"
local out="$dst/.opencode/agents/seeker.md"
local result=0
grep -q '^permission: {}' "$out" || { echo "expected 'permission: {}'"; cat "$out"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_agents_dedupes_edit() {
# write+edit both map to "edit: allow" — must appear once, not twice.
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/agents"
cat > "$src/agents/scribe.md" <<'EOF'
---
name: scribe
description: Dedupe test
model: mid
capabilities: [read, write, edit]
---
body
EOF
adapter_translate_agents "$src/agents" "$dst"
local out="$dst/.opencode/agents/scribe.md"
local count; count="$(grep -c '^ edit: allow' "$out")"
rm -rf "$src" "$dst"
[[ "$count" == "1" ]] || { echo "expected 1 edit line, got $count"; return 1; }
}
test_oc_translate_hooks_copies_scripts() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/hooks"
cat > "$src/hooks/protect.hook.yaml" <<'EOF'
name: protect
script: protect.sh
triggers:
- event: before-tool-use
match-tool: [edit, write]
EOF
cat > "$src/hooks/protect.sh" <<'EOF'
#!/usr/bin/env bash
exit 0
EOF
adapter_translate_hooks "$src/hooks" "$dst"
local result=0
[[ -f "$dst/.opencode/hooks/protect.sh" ]] || { echo "protect.sh not copied"; result=1; }
[[ -f "$dst/.opencode/plugins/mbifc-hooks.js" ]] || { echo "mbifc-hooks.js not generated"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_hooks_registry_has_entries() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/hooks"
cat > "$src/hooks/protect.hook.yaml" <<'EOF'
name: protect
script: protect.sh
triggers:
- event: before-tool-use
match-tool: [edit, write]
EOF
cat > "$src/hooks/notify.hook.yaml" <<'EOF'
name: notify
script: notify.sh
triggers:
- event: on-notification
EOF
touch "$src/hooks/protect.sh" "$src/hooks/notify.sh"
adapter_translate_hooks "$src/hooks" "$dst"
local plugin="$dst/.opencode/plugins/mbifc-hooks.js"
local result=0
grep -q '"name": "protect"' "$plugin" || { echo "protect not in registry"; result=1; }
grep -q '"name": "notify"' "$plugin" || { echo "notify not in registry"; result=1; }
grep -q '"event": "tool.execute.before"' "$plugin" || { echo "tool.execute.before event missing"; result=1; }
grep -q '"event": "session.idle"' "$plugin" || { echo "session.idle event missing"; result=1; }
grep -q '"matchTool":' "$plugin" || { echo "matchTool field missing"; result=1; }
grep -q 'spawn("bash"' "$plugin" || { echo "bash-executor not inlined"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_hooks_no_hooks_dir_is_noop() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
# src has no hooks/ — should not error, should not create plugin file
adapter_translate_hooks "$src/hooks" "$dst"
local result=0
[[ ! -f "$dst/.opencode/plugins/mbifc-hooks.js" ]] || { echo "plugin should not exist when no hooks"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_mcp_local() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/mcp"
cat > "$src/mcp/servers.yaml" <<'EOF'
servers:
- name: gmail
type: local
command: [npx, -y, "@anthropic-ai/gmail-mcp"]
env: {}
EOF
adapter_translate_mcp "$src/mcp" "$dst"
local out="$dst/opencode.json"
local result=0
[[ -f "$out" ]] || { echo "opencode.json missing"; result=1; }
jq -e '.mcp.gmail.type == "local"' "$out" >/dev/null || { echo "type wrong"; cat "$out"; result=1; }
jq -e '.mcp.gmail.command | startswith("npx")' "$out" >/dev/null || { echo "command wrong"; cat "$out"; result=1; }
jq -e '.mcp.gmail.environment == {}' "$out" >/dev/null || { echo "environment key missing"; cat "$out"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_translate_mcp_remote() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
mkdir -p "$src/mcp"
cat > "$src/mcp/servers.yaml" <<'EOF'
servers:
- name: Gmail
type: http
url: "https://gmail.mcp.claude.com/mcp"
env: {}
EOF
adapter_translate_mcp "$src/mcp" "$dst"
local out="$dst/opencode.json"
local result=0
jq -e '.mcp.Gmail.type == "remote"' "$out" >/dev/null || { echo "type should be remote"; cat "$out"; result=1; }
jq -e '.mcp.Gmail.url == "https://gmail.mcp.claude.com/mcp"' "$out" >/dev/null || { echo "url wrong"; cat "$out"; result=1; }
rm -rf "$src" "$dst"
return $result
}
test_oc_adapter_build_end_to_end() {
local src; src="$(mktemp -d)"
local dst; dst="$(mktemp -d)"
# Minimal source tree
echo "# Dispatcher" > "$src/DISPATCHER.md"
mkdir -p "$src/agents" "$src/hooks" "$src/skills/onboarding" "$src/references" "$src/mcp"
cat > "$src/agents/scribe.md" <<'EOF'
---
name: scribe
description: Test scribe
model: mid
capabilities: [read, write, edit]
---
body
EOF
cat > "$src/hooks/protect.hook.yaml" <<'EOF'
name: protect
script: protect.sh
triggers:
- event: before-tool-use
match-tool: [edit]
EOF
echo "#!/usr/bin/env bash" > "$src/hooks/protect.sh"
cat > "$src/skills/onboarding/SKILL.md" <<'EOF'
---
name: onboarding
description: Onboarding skill
---
body
EOF
echo "reference content" > "$src/references/policy.md"
cat > "$src/mcp/servers.yaml" <<'EOF'
servers:
- name: gmail
type: local
command: [npx, -y, "@anthropic-ai/gmail-mcp"]
env: {}
EOF
adapter_build "$src" "$dst"
local result=0
[[ -f "$dst/AGENTS.md" ]] || { echo "AGENTS.md missing"; result=1; }
[[ -f "$dst/.opencode/agents/scribe.md" ]] || { echo "agent missing"; result=1; }
[[ -f "$dst/.opencode/skills/onboarding/SKILL.md" ]] || { echo "skill missing"; result=1; }
[[ -f "$dst/.opencode/references/policy.md" ]] || { echo "reference missing"; result=1; }
[[ -f "$dst/.opencode/hooks/protect.sh" ]] || { echo "hook script missing"; result=1; }
[[ -f "$dst/.opencode/plugins/mbifc-hooks.js" ]] || { echo "plugin missing"; result=1; }
[[ -f "$dst/opencode.json" ]] || { echo "opencode.json missing"; result=1; }
rm -rf "$src" "$dst"
return $result
}