Branchwell

Jotley / app · jotley.ai / scripts / test-mcp.sh

Raw 4.0 KB on 0004e76b60187af1b51e974d64db6d5531ee0ab1
1#!/bin/zsh
2set -euo pipefail
3task_repo_root="$(cd "$(dirname "$0")/.." && pwd)"
4task_products="${JOTLEY_MAC_BUILD_PRODUCTS:?Set JOTLEY_MAC_BUILD_PRODUCTS to the Debug build products directory.}"
5task_output="${JOTLEY_MCP_TEST_OUTPUT:?Set JOTLEY_MCP_TEST_OUTPUT to an output directory on Expand.}"
6task_name=JotleyMCPTests
7task_sources=( "$task_repo_root/scripts/mcp-integration.swift" )
8task_flags=()
9if [[ "${1:-}" == --demo ]]; then
10 shift
11 task_name=JotleyMCPDemo
12 task_sources+=( "$task_repo_root/scripts/mcp-demo.swift" )
13 task_flags+=( -D JOTLEY_MCP_DEMO )
14fi
15task_contents="$task_output/$task_name.app/Contents"
16mkdir -p "$task_contents/MacOS" "$task_contents/Resources" "$task_contents/Frameworks"
17cp -R "$task_products/Jotley.app/Contents/Resources/." "$task_contents/Resources/"
18cp "$task_repo_root/scripts/mcp-desktop-bridge-check.cjs" "$task_contents/Resources/"
19if [[ -n "${JOTLEY_NODE_BINARY:-}" ]]; then
20 # A self-contained test runtime lives inside the harness so its sandbox does
21 # not need access to a user's Node installation or package-manager folders.
22 cp "$JOTLEY_NODE_BINARY" "$task_contents/MacOS/node"
23 codesign --force --sign - "$task_contents/MacOS/node"
24 export JOTLEY_NODE_BINARY="$task_contents/MacOS/node"
25fi
26cp "$task_products/Jotley.app/Contents/MacOS/Jotley.debug.dylib" "$task_contents/MacOS/"
27cp "$task_products/Jotley.app/Contents/MacOS/Jotley" "$task_contents/MacOS/JotleyBridge"
28codesign --force --sign - "$task_contents/MacOS/JotleyBridge"
29cp -R "$task_products/Jotley.app/Contents/Frameworks/Sparkle.framework" "$task_contents/Frameworks/"
30cat > "$task_contents/Info.plist" <<'PLIST'
31<?xml version="1.0" encoding="UTF-8"?>
32<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33<plist version="1.0"><dict>
34<key>CFBundleIdentifier</key><string>com.protomota.jotley.mcp-tests</string>
35<key>CFBundleExecutable</key><string>MCPIntegration</string>
36<key>CFBundleName</key><string>Jotley MCP Tests</string>
37<key>CFBundlePackageType</key><string>APPL</string>
38<key>LSMinimumSystemVersion</key><string>27.0</string>
39<key>LSUIElement</key><true/>
40</dict></plist>
41PLIST
42cat > "$task_output/entitlements.plist" <<'PLIST'
43<?xml version="1.0" encoding="UTF-8"?>
44<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
45<plist version="1.0"><dict>
46<key>com.apple.security.app-sandbox</key><true/>
47<key>com.apple.security.network.server</key><true/>
48<key>com.apple.security.network.client</key><true/>
49</dict></plist>
50PLIST
51task_checkouts="${JOTLEY_MCP_PACKAGE_CHECKOUTS:-$task_products/../../../SourcePackages/checkouts}"
52task_modules=( -I "$task_products" -F "$task_products" )
53for task_module_map in "$task_checkouts"/*/Sources/*/include/module.modulemap(N); do
54 task_modules+=( -Xcc "-fmodule-map-file=$task_module_map" -Xcc "-I${task_module_map:h}" )
55done
56for task_module_map in "$task_products/../../Intermediates.noindex/GeneratedModuleMaps/"*.modulemap(N); do
57 task_modules+=( -Xcc "-fmodule-map-file=$task_module_map" )
58done
59xcrun swiftc -parse-as-library -target "$(uname -m)-apple-macos27.0" \
60 "${task_modules[@]}" "${task_flags[@]}" "${task_sources[@]}" \
61 "$task_contents/MacOS/Jotley.debug.dylib" \
62 -Xlinker -rpath -Xlinker @executable_path \
63 -Xlinker -rpath -Xlinker @executable_path/../Frameworks \
64 -o "$task_contents/MacOS/MCPIntegration"
65codesign --force --sign - "$task_contents/MacOS/Jotley.debug.dylib"
66if [[ "$task_name" == JotleyMCPDemo ]]; then
67 # The view recorder writes directly to the requested Expand output. It uses
68 # an in-memory fixture and never opens the installed app's preferences/store.
69 plutil -replace CFBundleIdentifier -string com.protomota.jotley.mcp-demo "$task_contents/Info.plist"
70 codesign --force --sign - "$task_output/$task_name.app"
71else
72 codesign --force --sign - --entitlements "$task_output/entitlements.plist" "$task_output/$task_name.app"
73fi
74LLVM_PROFILE_FILE=/dev/null "$task_contents/MacOS/MCPIntegration" "$@"