|
2 | 2 |
|
3 | 3 | 🤖 **AI Agent Instructions** |
4 | 4 |
|
5 | | -Please read the `AGENT_README.md` file for comprehensive project information, development workflow, and testing procedures. |
| 5 | +## Project Overview |
| 6 | +This is the **Iterable Swift SDK** for iOS/macOS integration. The SDK provides: |
| 7 | +- Push notification handling |
| 8 | +- In-app messaging |
| 9 | +- Event tracking |
| 10 | +- User management |
| 11 | +- Unknown user tracking |
6 | 12 |
|
7 | | -All the information you need to work on this Iterable Swift SDK project is documented there. |
| 13 | +## Key Architecture |
| 14 | +- **Core SDK**: `swift-sdk/` - Main SDK implementation |
| 15 | +- **Sample Apps**: `sample-apps/` - Example integrations |
| 16 | +- **Tests**: `tests/` - Unit tests, UI tests, and integration tests |
| 17 | +- **Notification Extension**: `notification-extension/` - Rich push support |
| 18 | + |
| 19 | +## Development Workflow |
| 20 | + |
| 21 | +### 🔨 Building the SDK |
| 22 | +```bash |
| 23 | +./agent_build.sh |
| 24 | +``` |
| 25 | +- Validates compilation on iOS Simulator |
| 26 | +- Shows build errors with context |
| 27 | +- Requires macOS with Xcode |
| 28 | + |
| 29 | +### Listing All Available Tests |
| 30 | + |
| 31 | +# List all available test suites |
| 32 | +```bash |
| 33 | +./agent_test.sh --list |
| 34 | +``` |
| 35 | + |
| 36 | +### 🧪 Running Tests |
| 37 | +```bash |
| 38 | +# Run all tests |
| 39 | +./agent_test.sh |
| 40 | + |
| 41 | +# Run specific test suite |
| 42 | +./agent_test.sh IterableApiCriteriaFetchTests |
| 43 | + |
| 44 | +# Run specific unit test (dot notation - recommended) |
| 45 | +./agent_test.sh "IterableApiCriteriaFetchTests.testForegroundCriteriaFetchWhenConditionsMet" |
| 46 | + |
| 47 | +# Run any specific test with path |
| 48 | +./agent_test.sh "unit-tests/IterableApiCriteriaFetchTests/testForegroundCriteriaFetchWhenConditionsMet" |
| 49 | +``` |
| 50 | +- Executes on iOS Simulator with accurate pass/fail reporting |
| 51 | +- Returns exit code 0 for success, 1 for failures |
| 52 | +- Shows detailed test counts and failure information |
| 53 | +- `--list` shows all test suites with test counts |
| 54 | +- Requires password for xcpretty installation (first run) |
| 55 | + |
| 56 | +## Project Structure |
| 57 | +``` |
| 58 | +swift-sdk/ |
| 59 | +├── swift-sdk/ # Main SDK source |
| 60 | +│ ├── Core/ # Public APIs and models |
| 61 | +│ ├── Internal/ # Internal implementation |
| 62 | +│ ├── SDK/ # Main SDK entry points |
| 63 | +│ └── ui-components/ # SwiftUI/UIKit components |
| 64 | +├── tests/ # Test suites |
| 65 | +│ ├── unit-tests/ # Unit tests |
| 66 | +│ ├── ui-tests/ # UI automation tests |
| 67 | +│ └── endpoint-tests/ # API endpoint tests |
| 68 | +├── sample-apps/ # Example applications |
| 69 | +└── notification-extension/ # Push notification extension |
| 70 | +``` |
| 71 | + |
| 72 | +## Key Classes |
| 73 | +- **IterableAPI**: Main SDK interface |
| 74 | +- **IterableConfig**: Configuration management |
| 75 | +- **InternalIterableAPI**: Core implementation |
| 76 | +- **UnknownUserManager**: Unknown user tracking |
| 77 | +- **LocalStorage**: Data persistence |
| 78 | + |
| 79 | +## Common Tasks |
| 80 | + |
| 81 | +### Adding New Features |
| 82 | +1. Build first: `./agent_build.sh` |
| 83 | +2. Implement in `swift-sdk/Internal/` or `swift-sdk/SDK/` |
| 84 | +3. Add tests in `tests/unit-tests/` |
| 85 | +4. Verify: `./agent_test.sh` (all tests) or `./agent_test.sh YourTestSuite` (specific suite) |
| 86 | + |
| 87 | +### Debugging Build Issues |
| 88 | +- Build script shows compilation errors with file paths |
| 89 | +- Check Xcode project references in `swift-sdk.xcodeproj/project.pbxproj` |
| 90 | +- Verify file renames are reflected in project file |
| 91 | + |
| 92 | +### Test Failures |
| 93 | +- Test script shows specific failures with line numbers and detailed error messages |
| 94 | +- Run failing tests individually: `./agent_test.sh "TestSuite.testMethod"` |
| 95 | +- Mock classes available in `tests/common/` |
| 96 | +- Update parameter names when refactoring APIs |
| 97 | + |
| 98 | +## Requirements |
| 99 | +- **macOS**: Required for Xcode builds |
| 100 | +- **Xcode**: Latest stable version |
| 101 | +- **Ruby**: For xcpretty (auto-installed) |
| 102 | +- **iOS Simulator**: For testing |
| 103 | + |
| 104 | +## Quick Start for AI Agents |
| 105 | +1. Run `./agent_build.sh` to verify project builds |
| 106 | +2. Run `./agent_test.sh` to check test health (or `./agent_test.sh TestSuite` for specific suite) |
| 107 | +3. Make changes to source files |
| 108 | +4. Re-run both scripts to validate |
| 109 | +5. Debug failing tests: `./agent_test.sh "TestSuite.testMethod"` |
| 110 | +6. Commit when both pass ✅ |
| 111 | + |
| 112 | +## Test Filtering Examples |
| 113 | +```bash |
| 114 | +# Debug specific failing tests |
| 115 | +./agent_test.sh "IterableApiCriteriaFetchTests.testForegroundCriteriaFetchWhenConditionsMet" |
| 116 | + |
| 117 | +# Run a problematic test suite |
| 118 | +./agent_test.sh ValidateCustomEventUserUpdateAPITest |
| 119 | + |
| 120 | +# Check auth-related tests |
| 121 | +./agent_test.sh AuthTests |
| 122 | +``` |
| 123 | + |
| 124 | +## AI Agent Memory System |
| 125 | + |
| 126 | +### 🧠 Update Instructions for AI Agents |
| 127 | +**IMPORTANT**: When you discover something useful while working on this codebase, update this README to help future AI agents. Add learnings to the sections below. |
| 128 | + |
| 129 | +### 📍 Code Location Map |
| 130 | +- **Auth Logic**: `swift-sdk/Internal/AuthManager.swift` (main auth manager), `swift-sdk/Internal/Auth.swift` (auth models) |
| 131 | +- **API Calls**: `swift-sdk/Internal/api-client/ApiClient.swift` (main client), `swift-sdk/Internal/Network/NetworkHelper.swift` (networking) |
| 132 | +- **Models**: `swift-sdk/Core/Models/` (all data structures - CommerceItem, IterableInAppMessage, etc.) |
| 133 | +- **Main Entry**: `swift-sdk/SDK/IterableAPI.swift` (public-facing methods), `swift-sdk/Internal/InternalIterableAPI.swift` (core implementation) — note: public API surface lives in `IterableAPI.swift`, implementation details in `ApiClient.swift` |
| 134 | +- **Request Handling**: `swift-sdk/Internal/api-client/Request/` (online/offline processors) |
| 135 | + |
| 136 | +### 🛠️ Common Task Recipes |
| 137 | + |
| 138 | +**Add New API Endpoint:** |
| 139 | +1. Add path constant to `swift-sdk/Core/Constants.swift` in `Const.Path` |
| 140 | +2. Add method to `ApiClientProtocol.swift` and implement in `ApiClient.swift` |
| 141 | +3. Create request in `swift-sdk/Internal/api-client/Request/RequestCreator.swift` |
| 142 | +4. Add to `RequestHandlerProtocol.swift` and `RequestHandler.swift` |
| 143 | + |
| 144 | +**Modify Auth Logic:** |
| 145 | +- Main logic: `swift-sdk/Internal/AuthManager.swift` |
| 146 | +- Token storage: `swift-sdk/Internal/Utilities/Keychain/IterableKeychain.swift` |
| 147 | +- Auth failures: Handle in `RequestProcessorUtil.swift` |
| 148 | + |
| 149 | +**Add New Model:** |
| 150 | +- Create in `swift-sdk/Core/Models/YourModel.swift` |
| 151 | +- Make it `@objcMembers public class` for Objective-C compatibility |
| 152 | +- Implement `Codable` if it needs JSON serialization |
| 153 | + |
| 154 | +### 🐛 Common Failure Solutions |
| 155 | + |
| 156 | +**"Test X failed"** → Check test file in `tests/unit-tests/` - often parameter name mismatches after refactoring |
| 157 | + |
| 158 | +**"Build failed: file not found"** → Update `swift-sdk.xcodeproj/project.pbxproj` to include new/renamed files |
| 159 | + |
| 160 | +**"Auth token issues"** → Check `AuthManager.swift` and ensure JWT format is correct in tests |
| 161 | + |
| 162 | +**"Network request fails"** → Check endpoint in `Constants.swift` and request creation in `RequestCreator.swift` |
| 163 | + |
| 164 | +## Notes |
| 165 | +- Always test builds after refactoring |
| 166 | +- Parameter name changes require test file updates |
| 167 | +- Project file (`*.pbxproj`) may need manual updates for file renames |
| 168 | +- Sample apps demonstrate SDK usage patterns |
0 commit comments