-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathTestBackends.swift
More file actions
executable file
Β·148 lines (125 loc) Β· 4.77 KB
/
TestBackends.swift
File metadata and controls
executable file
Β·148 lines (125 loc) Β· 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env swift
//
// TestBackends.swift
// Manual test script for dual-backend architecture
//
// Run with: swift TestBackends.swift
//
import Foundation
// This script tests the dual-backend architecture
// You'll need to build the package first: swift build
print("π§ͺ ClaudeCodeSDK Backend Testing\n")
// Test 1: Check if claude CLI is available
print("π Step 1: Checking for claude CLI...")
let whichClaude = Process()
whichClaude.executableURL = URL(fileURLWithPath: "/bin/zsh")
whichClaude.arguments = ["-l", "-c", "which claude"]
let claudePipe = Pipe()
whichClaude.standardOutput = claudePipe
whichClaude.standardError = Pipe()
try? whichClaude.run()
whichClaude.waitUntilExit()
if whichClaude.terminationStatus == 0 {
let data = claudePipe.fileHandleForReading.readDataToEndOfFile()
if let path = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) {
print(" β
claude CLI found at: \(path)")
}
} else {
print(" β claude CLI not found")
print(" Install with: npm install -g @anthropic-ai/claude-code")
}
// Test 2: Check if Node.js is available
print("\nπ Step 2: Checking for Node.js...")
let whichNode = Process()
whichNode.executableURL = URL(fileURLWithPath: "/bin/zsh")
whichNode.arguments = ["-l", "-c", "which node"]
let nodePipe = Pipe()
whichNode.standardOutput = nodePipe
whichNode.standardError = Pipe()
try? whichNode.run()
whichNode.waitUntilExit()
if whichNode.terminationStatus == 0 {
let data = nodePipe.fileHandleForReading.readDataToEndOfFile()
if let path = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) {
print(" β
Node.js found at: \(path)")
// Check Node version
let nodeVersion = Process()
nodeVersion.executableURL = URL(fileURLWithPath: "/bin/zsh")
nodeVersion.arguments = ["-l", "-c", "node --version"]
let versionPipe = Pipe()
nodeVersion.standardOutput = versionPipe
try? nodeVersion.run()
nodeVersion.waitUntilExit()
let versionData = versionPipe.fileHandleForReading.readDataToEndOfFile()
if let version = String(data: versionData, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) {
print(" π¦ Node version: \(version)")
}
}
} else {
print(" β Node.js not found")
print(" Install from: https://nodejs.org/")
}
// Test 3: Check if Agent SDK is installed
print("\nπ Step 3: Checking for Claude Agent SDK...")
let npmList = Process()
npmList.executableURL = URL(fileURLWithPath: "/bin/zsh")
npmList.arguments = ["-l", "-c", "npm list -g @anthropic-ai/claude-agent-sdk --depth=0"]
let npmPipe = Pipe()
npmList.standardOutput = npmPipe
npmList.standardError = Pipe()
try? npmList.run()
npmList.waitUntilExit()
if npmList.terminationStatus == 0 {
print(" β
Claude Agent SDK installed")
let data = npmPipe.fileHandleForReading.readDataToEndOfFile()
if let output = String(data: data, encoding: .utf8) {
// Extract version if possible
if let versionLine = output.split(separator: "\n").first(where: { $0.contains("claude-agent-sdk") }) {
print(" π¦ \(versionLine)")
}
}
} else {
print(" β Claude Agent SDK not installed")
print(" Install with: npm install -g @anthropic-ai/claude-agent-sdk")
}
// Test 4: Check if sdk-wrapper.mjs exists
print("\nπ Step 4: Checking for sdk-wrapper.mjs...")
let wrapperPath = "/Users/jamesrochabrun/Desktop/git/ClaudeCodeSDK/Resources/sdk-wrapper.mjs"
if FileManager.default.fileExists(atPath: wrapperPath) {
print(" β
sdk-wrapper.mjs found at: \(wrapperPath)")
// Check if executable
if FileManager.default.isExecutableFile(atPath: wrapperPath) {
print(" β
sdk-wrapper.mjs is executable")
} else {
print(" β οΈ sdk-wrapper.mjs is not executable")
print(" Run: chmod +x \(wrapperPath)")
}
} else {
print(" β sdk-wrapper.mjs not found")
}
// Summary
print("\n" + String(repeating: "=", count: 60))
print("π SUMMARY\n")
var canUseHeadless = whichClaude.terminationStatus == 0
var canUseAgentSDK = whichNode.terminationStatus == 0 && npmList.terminationStatus == 0
print("Backend Availability:")
print(" β’ Headless Backend: \(canUseHeadless ? "β
Ready" : "β Not Available")")
print(" β’ Agent SDK Backend: \(canUseAgentSDK ? "β
Ready" : "β Not Available")")
print("\nπ Next Steps:\n")
if canUseHeadless {
print("1. Test Headless Backend:")
print(" swift run TestHeadlessBackend")
} else {
print("1. Install claude CLI:")
print(" npm install -g @anthropic-ai/claude-code")
}
if canUseAgentSDK {
print("\n2. Test Agent SDK Backend:")
print(" swift run TestAgentSDKBackend")
} else {
print("\n2. Install Agent SDK:")
print(" npm install -g @anthropic-ai/claude-agent-sdk")
}
print("\n3. Run the example:")
print(" cd Example/ClaudeCodeSDKExample && open ClaudeCodeSDKExample.xcodeproj")
print("\n" + String(repeating: "=", count: 60))