Jotley / app · jotley.ai / scripts / test-mcp.sh
| 1 | #!/bin/zsh |
| 2 | set -euo pipefail |
| 3 | task_repo_root="$(cd "$(dirname "$0")/.." && pwd)" |
| 4 | task_products="${JOTLEY_MAC_BUILD_PRODUCTS:?Set JOTLEY_MAC_BUILD_PRODUCTS to the Debug build products directory.}" |
| 5 | task_output="${JOTLEY_MCP_TEST_OUTPUT:?Set JOTLEY_MCP_TEST_OUTPUT to an output directory on Expand.}" |
| 6 | task_name=JotleyMCPTests |
| 7 | task_sources=( "$task_repo_root/scripts/mcp-integration.swift" ) |
| 8 | task_flags=() |
| 9 | if [[ "${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 ) |
| 14 | fi |
| 15 | task_contents="$task_output/$task_name.app/Contents" |
| 16 | mkdir -p "$task_contents/MacOS" "$task_contents/Resources" "$task_contents/Frameworks" |
| 17 | cp -R "$task_products/Jotley.app/Contents/Resources/." "$task_contents/Resources/" |
| 18 | cp "$task_repo_root/scripts/mcp-desktop-bridge-check.cjs" "$task_contents/Resources/" |
| 19 | if [[ -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" |
| 25 | fi |
| 26 | cp "$task_products/Jotley.app/Contents/MacOS/Jotley.debug.dylib" "$task_contents/MacOS/" |
| 27 | cp "$task_products/Jotley.app/Contents/MacOS/Jotley" "$task_contents/MacOS/JotleyBridge" |
| 28 | codesign --force --sign - "$task_contents/MacOS/JotleyBridge" |
| 29 | cp -R "$task_products/Jotley.app/Contents/Frameworks/Sparkle.framework" "$task_contents/Frameworks/" |
| 30 | cat > "$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> |
| 41 | PLIST |
| 42 | cat > "$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> |
| 50 | PLIST |
| 51 | task_checkouts="${JOTLEY_MCP_PACKAGE_CHECKOUTS:-$task_products/../../../SourcePackages/checkouts}" |
| 52 | task_modules=( -I "$task_products" -F "$task_products" ) |
| 53 | for 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}" ) |
| 55 | done |
| 56 | for task_module_map in "$task_products/../../Intermediates.noindex/GeneratedModuleMaps/"*.modulemap(N); do |
| 57 | task_modules+=( -Xcc "-fmodule-map-file=$task_module_map" ) |
| 58 | done |
| 59 | xcrun 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" |
| 65 | codesign --force --sign - "$task_contents/MacOS/Jotley.debug.dylib" |
| 66 | if [[ "$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" |
| 71 | else |
| 72 | codesign --force --sign - --entitlements "$task_output/entitlements.plist" "$task_output/$task_name.app" |
| 73 | fi |
| 74 | LLVM_PROFILE_FILE=/dev/null "$task_contents/MacOS/MCPIntegration" "$@" |