|
| 1 | +# CrabNebula Tauri Driver Integration Analysis |
| 2 | + |
| 3 | +## Executive Summary |
| 4 | + |
| 5 | +This document analyzes the feasibility of integrating CrabNebula's `@crabnebula/tauri-driver` into the `@wdio/tauri-service` to enable macOS testing support. CrabNebula provides a fork of the official tauri-driver with macOS support via a proprietary WebDriver implementation. |
| 6 | + |
| 7 | +## Current State Analysis |
| 8 | + |
| 9 | +### Tauri Service Architecture |
| 10 | + |
| 11 | +The current `@wdio/tauri-service` implementation: |
| 12 | + |
| 13 | +1. **Launcher Service** ([`launcher.ts`](packages/tauri-service/src/launcher.ts:1)): |
| 14 | + - Manages tauri-driver process lifecycle |
| 15 | + - Handles platform-specific driver detection (Windows: msedgedriver, Linux: webkit2gtk-driver) |
| 16 | + - Explicitly **blocks macOS** with an error message (lines 173-180) |
| 17 | + - Supports per-worker and multiremote modes |
| 18 | + - Auto-installs official tauri-driver via cargo |
| 19 | + |
| 20 | +2. **Driver Manager** ([`driverManager.ts`](packages/tauri-service/src/driverManager.ts:1)): |
| 21 | + - Finds or installs official `tauri-driver` from crates.io |
| 22 | + - Uses cargo install for automatic installation |
| 23 | + - No support for npm-based driver packages |
| 24 | + |
| 25 | +3. **Types** ([`native-types/src/tauri.ts`](packages/native-types/src/tauri.ts:1)): |
| 26 | + - Defines service options and capabilities |
| 27 | + - No CrabNebula-specific configuration options |
| 28 | + |
| 29 | +4. **Platform Support** ([`docs/platform-support.md`](packages/tauri-service/docs/platform-support.md:1)): |
| 30 | + - Documents macOS as unsupported due to WKWebView limitations |
| 31 | + - Windows: msedgedriver auto-management |
| 32 | + - Linux: webkit2gtk-driver manual installation |
| 33 | + |
| 34 | +### CrabNebula Requirements Analysis |
| 35 | + |
| 36 | +Based on the documentation provided: |
| 37 | + |
| 38 | +#### 1. NPM Package Distribution |
| 39 | +- `@crabnebula/tauri-driver` - Main driver package (npm-based, not cargo) |
| 40 | +- `@crabnebula/test-runner-backend` - Required for local macOS testing |
| 41 | +- `@crabnebula/webdriverio-cloud-reporter` - Optional cloud reporter |
| 42 | + |
| 43 | +#### 2. macOS Prerequisites |
| 44 | +- **tauri-plugin-automation** must be installed in the Tauri app |
| 45 | +- Plugin must be conditionally compiled (debug builds only) |
| 46 | +- **CN_API_KEY** environment variable required for macOS tests |
| 47 | + |
| 48 | +#### 3. Architecture Differences |
| 49 | + |
| 50 | +| Aspect | Official tauri-driver | CrabNebula tauri-driver | |
| 51 | +|--------|----------------------|-------------------------| |
| 52 | +| Distribution | Cargo (crates.io) | NPM (@crabnebula) | |
| 53 | +| macOS Support | ❌ No | ✅ Yes (via subscription) | |
| 54 | +| Linux Support | ✅ webkit2gtk-driver | ✅ webkit2gtk-driver | |
| 55 | +| Windows Support | ✅ msedgedriver | ✅ msedgedriver | |
| 56 | +| Backend Service | None | test-runner-backend (macOS) | |
| 57 | +| API Key Required | No | Yes (CN_API_KEY for macOS) | |
| 58 | + |
| 59 | +#### 4. Configuration Complexity |
| 60 | + |
| 61 | +CrabNebula requires significantly more setup: |
| 62 | + |
| 63 | +```javascript |
| 64 | +// CrabNebula wdio.conf.js structure |
| 65 | +exports.config = { |
| 66 | + onPrepare: async () => { |
| 67 | + // Build the app |
| 68 | + spawnSync("pnpm", ["tauri", "build", "--debug", "--no-bundle"]); |
| 69 | + |
| 70 | + if (process.platform === "darwin") { |
| 71 | + // Validate API key |
| 72 | + if (!process.env.CN_API_KEY) { |
| 73 | + console.error("CN_API_KEY is not set"); |
| 74 | + process.exit(1); |
| 75 | + } |
| 76 | + |
| 77 | + // Start test-runner-backend |
| 78 | + testRunnerBackend = spawn("pnpm", ["test-runner-backend"]); |
| 79 | + await waitTestRunnerBackendReady(); |
| 80 | + |
| 81 | + // Set remote WebDriver URL |
| 82 | + process.env.REMOTE_WEBDRIVER_URL = `http://127.0.0.1:3000`; |
| 83 | + } |
| 84 | + }, |
| 85 | + |
| 86 | + beforeSession: async () => { |
| 87 | + // Start tauri-driver |
| 88 | + tauriDriver = spawn("pnpm", ["tauri-driver"]); |
| 89 | + await waitTauriDriverReady(); |
| 90 | + } |
| 91 | +}; |
| 92 | +``` |
| 93 | + |
| 94 | +## Integration Points & Required Changes |
| 95 | + |
| 96 | +### 1. Driver Detection & Installation |
| 97 | + |
| 98 | +**Current**: [`driverManager.ts`](packages/tauri-service/src/driverManager.ts:34) searches for cargo-installed binary |
| 99 | + |
| 100 | +**Required Changes**: |
| 101 | +- Add detection for `@crabnebula/tauri-driver` in node_modules/.bin |
| 102 | +- Support npm-based driver execution (npx/pnpm style) |
| 103 | +- Maintain backward compatibility with official driver |
| 104 | + |
| 105 | +### 2. macOS Platform Support |
| 106 | + |
| 107 | +**Current**: [`launcher.ts`](packages/tauri-service/src/launcher.ts:173) explicitly throws error on macOS |
| 108 | + |
| 109 | +**Required Changes**: |
| 110 | +- Conditionally allow macOS when CrabNebula driver is configured |
| 111 | +- Add validation for tauri-plugin-automation presence |
| 112 | +- Check CN_API_KEY environment variable |
| 113 | + |
| 114 | +### 3. Test Runner Backend Management (macOS only) |
| 115 | + |
| 116 | +**Current**: No backend service management |
| 117 | + |
| 118 | +**Required Changes**: |
| 119 | +- Add `@crabnebula/test-runner-backend` process management |
| 120 | +- Implement `waitTestRunnerBackendReady()` functionality |
| 121 | +- Handle REMOTE_WEBDRIVER_URL environment variable |
| 122 | +- Lifecycle management (start before driver, stop on complete) |
| 123 | + |
| 124 | +### 4. Configuration Schema |
| 125 | + |
| 126 | +**Current**: [`TauriServiceOptions`](packages/native-types/src/tauri.ts:139) |
| 127 | + |
| 128 | +**Proposed Additions**: |
| 129 | +```typescript |
| 130 | +interface TauriServiceOptions { |
| 131 | + // Existing options... |
| 132 | + |
| 133 | + // CrabNebula-specific options |
| 134 | + driverProvider?: 'official' | 'crabnebula'; |
| 135 | + crabnebulaApiKey?: string; // Or use CN_API_KEY env var |
| 136 | + crabnebulaTestRunnerBackend?: boolean; // Auto-manage backend |
| 137 | +} |
| 138 | +``` |
| 139 | + |
| 140 | +### 5. Plugin Validation |
| 141 | + |
| 142 | +**New Requirement**: Verify tauri-plugin-automation is installed for macOS builds |
| 143 | + |
| 144 | +**Implementation Options**: |
| 145 | +- Parse Cargo.toml for plugin dependency |
| 146 | +- Check compiled binary for automation symbols |
| 147 | +- Runtime detection (attempt connection and report meaningful error) |
| 148 | + |
| 149 | +### 6. Documentation Updates |
| 150 | + |
| 151 | +Files requiring updates: |
| 152 | +- [`docs/platform-support.md`](packages/tauri-service/docs/platform-support.md:11) - Update macOS status |
| 153 | +- [`docs/configuration.md`](packages/tauri-service/docs/configuration.md:1) - Add CrabNebula options |
| 154 | +- New doc: `docs/crabnebula-setup.md` - Complete setup guide |
| 155 | + |
| 156 | +## Feasibility Assessment |
| 157 | + |
| 158 | +### ✅ High Feasibility Items |
| 159 | + |
| 160 | +1. **Driver Detection**: Straightforward to add npm binary detection alongside cargo |
| 161 | +2. **Configuration Options**: Simple type additions to existing interfaces |
| 162 | +3. **Documentation**: Clear path for updates |
| 163 | +4. **Windows/Linux**: CrabNebula supports these platforms with same drivers as official |
| 164 | + |
| 165 | +### ⚠️ Medium Complexity Items |
| 166 | + |
| 167 | +1. **Backend Process Management**: Requires new process lifecycle management similar to tauri-driver |
| 168 | +2. **macOS Platform Enablement**: Need to carefully conditionalize the platform check |
| 169 | +3. **API Key Handling**: Secure handling of CN_API_KEY (env var vs config) |
| 170 | + |
| 171 | +### 🔴 High Complexity / Blockers |
| 172 | + |
| 173 | +1. **Plugin Validation**: Detecting tauri-plugin-automation requires build-time or binary analysis |
| 174 | +2. **OSS License Dependency**: Testing requires CrabNebula subscription/OSS license |
| 175 | +3. **Conditional Compilation**: Users must properly configure debug-only plugin inclusion |
| 176 | + |
| 177 | +## Implementation Recommendations |
| 178 | + |
| 179 | +### Phase 1: Foundation (Minimal Viable Support) |
| 180 | + |
| 181 | +1. **Add driver provider selection**: |
| 182 | + ```typescript |
| 183 | + services: [['@wdio/tauri-service', { |
| 184 | + driverProvider: 'crabnebula', // 'official' | 'crabnebula' |
| 185 | + }]] |
| 186 | + ``` |
| 187 | + |
| 188 | +2. **Update driver detection** in [`driverManager.ts`](packages/tauri-service/src/driverManager.ts:34): |
| 189 | + - Check for `@crabnebula/tauri-driver` in node_modules |
| 190 | + - Fall back to npx execution |
| 191 | + |
| 192 | +3. **Conditional macOS support** in [`launcher.ts`](packages/tauri-service/src/launcher.ts:173): |
| 193 | + - Only throw error if `driverProvider !== 'crabnebula'` |
| 194 | + |
| 195 | +### Phase 2: macOS Backend Support |
| 196 | + |
| 197 | +1. **Add test-runner-backend management**: |
| 198 | + - New module: `crabnebulaBackend.ts` |
| 199 | + - Process lifecycle similar to tauri-driver |
| 200 | + - Port readiness checking |
| 201 | + |
| 202 | +2. **Environment variable handling**: |
| 203 | + - REMOTE_WEBDRIVER_URL injection |
| 204 | + - CN_API_KEY validation |
| 205 | + |
| 206 | +### Phase 3: Developer Experience |
| 207 | + |
| 208 | +1. **Plugin validation**: |
| 209 | + - Cargo.toml parsing helper |
| 210 | + - Pre-test validation warnings |
| 211 | + |
| 212 | +2. **Documentation**: |
| 213 | + - Complete setup guide |
| 214 | + - Troubleshooting section |
| 215 | + - CI/CD examples |
| 216 | + |
| 217 | +## OSS License Considerations |
| 218 | + |
| 219 | +To enable testing and CI for this repository: |
| 220 | + |
| 221 | +1. **Request OSS License** from CrabNebula for the tauri-service repo |
| 222 | +2. **Test Strategy**: |
| 223 | + - Unit tests for driver detection (mocked) |
| 224 | + - Integration tests require valid CN_API_KEY |
| 225 | + - Consider scheduled tests vs PR tests |
| 226 | + |
| 227 | +3. **CI Configuration**: |
| 228 | + ```yaml |
| 229 | + # GitHub Actions example |
| 230 | + - name: Run macOS tests |
| 231 | + if: secrets.CN_API_KEY != '' |
| 232 | + env: |
| 233 | + CN_API_KEY: ${{ secrets.CN_API_KEY }} |
| 234 | + run: pnpm test:macos |
| 235 | + ``` |
| 236 | +
|
| 237 | +## Alternative Approaches |
| 238 | +
|
| 239 | +### Option A: Direct Integration (Recommended) |
| 240 | +Integrate CrabNebula support directly into `@wdio/tauri-service` as outlined above. |
| 241 | + |
| 242 | +**Pros**: |
| 243 | +- Single service for all Tauri testing |
| 244 | +- Seamless user experience |
| 245 | +- Platform abstraction |
| 246 | + |
| 247 | +**Cons**: |
| 248 | +- Adds complexity to core service |
| 249 | +- Requires OSS license for testing |
| 250 | + |
| 251 | +### Option B: Separate Package |
| 252 | +Create `@wdio/crabnebula-service` as a separate package. |
| 253 | + |
| 254 | +**Pros**: |
| 255 | +- Clean separation of concerns |
| 256 | +- No OSS license needed for core service |
| 257 | +- Optional dependency |
| 258 | + |
| 259 | +**Cons**: |
| 260 | +- User must choose/configure separately |
| 261 | +- Potential code duplication |
| 262 | +- Fragmented ecosystem |
| 263 | + |
| 264 | +### Option C: Plugin Architecture |
| 265 | +Make driver providers pluggable. |
| 266 | + |
| 267 | +**Pros**: |
| 268 | +- Extensible for future drivers |
| 269 | +- Clean abstraction |
| 270 | + |
| 271 | +**Cons**: |
| 272 | +- Significant refactoring required |
| 273 | +- Over-engineering for current needs |
| 274 | + |
| 275 | +## Conclusion |
| 276 | + |
| 277 | +**Integration is highly feasible** with the following key points: |
| 278 | + |
| 279 | +1. **Architecture Compatibility**: CrabNebula follows the same WebDriver protocol as official tauri-driver |
| 280 | +2. **Minimal Breaking Changes**: Can be added as opt-in configuration |
| 281 | +3. **Clear Implementation Path**: Phased approach reduces risk |
| 282 | +4. **OSS License**: Recommended to obtain for proper CI testing |
| 283 | + |
| 284 | +**Estimated Effort**: 2-3 weeks for full implementation including: |
| 285 | +- Code changes (1 week) |
| 286 | +- Documentation (3-4 days) |
| 287 | +- Testing & validation (3-4 days) |
| 288 | + |
| 289 | +**Priority Recommendation**: Medium-High. macOS support is a significant gap in Tauri testing ecosystem that CrabNebula uniquely solves. |
0 commit comments