test-contract
Generate protocol/interface test suites that any implementation must pass. Define the contract once, test every implementation. Use when designing protocols or swapping implementations.
What this skill does
# Test Contract
Define behavioral contracts as test suites. Any class conforming to a protocol must pass the contract tests. Ensures consistent behavior across implementations — human-written, AI-generated, or mock.
## When This Skill Activates
Use this skill when the user:
- Designs a protocol and wants to ensure conformance quality
- Has multiple implementations of the same interface (e.g., real + mock + in-memory)
- Says "test the protocol" or "contract test"
- Wants to swap implementations safely (e.g., CoreData → SwiftData)
- Wants to ensure AI-generated implementations meet the spec
## Why Contract Tests
```
Protocol: DataStore
├── SQLiteDataStore → must pass contract tests
├── InMemoryDataStore → must pass contract tests
├── MockDataStore → must pass contract tests
└── CloudDataStore → must pass contract tests
```
Write the contract once. Every implementation proves it works by passing the same tests.
## Process
### Phase 1: Identify the Protocol
```
Grep: "protocol.*\\{" to find protocols
Read: protocol definition
```
Understand:
- [ ] All required methods and properties
- [ ] Expected behavior for each method
- [ ] Error conditions and edge cases
- [ ] Thread safety requirements
- [ ] State invariants (e.g., count matches items.count)
### Phase 2: Define Contract Behaviors
For each protocol method, define required behaviors:
```markdown
## DataStore Contract
### save(_ item:)
- Saving a new item increases count by 1
- Saving an existing item (same ID) updates it, count unchanged
- Saved item is retrievable by ID
- Throws on invalid item (empty title)
### fetch(id:)
- Returns item when it exists
- Returns nil when item doesn't exist
- Returns most recently saved version
### delete(id:)
- Deleting existing item decreases count by 1
- Deleting non-existent item does nothing (no throw)
- Deleted item is no longer fetchable
### fetchAll()
- Returns all saved items
- Returns empty array when store is empty
- Items are in consistent order (insertion or specified)
### Invariants
- count == fetchAll().count (always)
- save then fetch returns same item
- delete then fetch returns nil
```
### Phase 3: Generate Contract Test Suite
#### Pattern: Generic Test Suite
```swift
import Testing
/// Contract tests for any DataStore implementation.
/// Subclass or call with your concrete implementation.
struct DataStoreContractTests<Store: DataStore> {
let makeStore: () -> Store
init(makeStore: @escaping () -> Store) {
self.makeStore = makeStore
}
// MARK: - save(_ item:)
@Test("save increases count")
func saveIncreasesCount() async throws {
let store = makeStore()
let item = Item(id: "1", title: "Test")
try await store.save(item)
#expect(store.count == 1)
}
@Test("save then fetch returns same item")
func saveAndFetch() async throws {
let store = makeStore()
let item = Item(id: "1", title: "Test")
try await store.save(item)
let fetched = try await store.fetch(id: "1")
#expect(fetched?.title == "Test")
}
@Test("save existing item updates it")
func saveUpdates() async throws {
let store = makeStore()
try await store.save(Item(id: "1", title: "Original"))
try await store.save(Item(id: "1", title: "Updated"))
let fetched = try await store.fetch(id: "1")
#expect(fetched?.title == "Updated")
#expect(store.count == 1)
}
@Test("save throws on invalid item")
func saveInvalidThrows() async {
let store = makeStore()
let invalid = Item(id: "1", title: "")
await #expect(throws: DataStoreError.invalidItem) {
try await store.save(invalid)
}
}
// MARK: - fetch(id:)
@Test("fetch returns nil for non-existent ID")
func fetchNonExistent() async throws {
let store = makeStore()
let result = try await store.fetch(id: "nonexistent")
#expect(result == nil)
}
// MARK: - delete(id:)
@Test("delete removes item")
func deleteRemoves() async throws {
let store = makeStore()
try await store.save(Item(id: "1", title: "Test"))
try await store.delete(id: "1")
#expect(store.count == 0)
let fetched = try await store.fetch(id: "1")
#expect(fetched == nil)
}
@Test("delete non-existent does nothing")
func deleteNonExistent() async throws {
let store = makeStore()
try await store.delete(id: "nonexistent")
#expect(store.count == 0)
}
// MARK: - fetchAll()
@Test("fetchAll returns all items")
func fetchAll() async throws {
let store = makeStore()
try await store.save(Item(id: "1", title: "A"))
try await store.save(Item(id: "2", title: "B"))
let all = try await store.fetchAll()
#expect(all.count == 2)
}
@Test("fetchAll returns empty when store is empty")
func fetchAllEmpty() async throws {
let store = makeStore()
let all = try await store.fetchAll()
#expect(all.isEmpty)
}
// MARK: - Invariants
@Test("count matches fetchAll count")
func countInvariant() async throws {
let store = makeStore()
try await store.save(Item(id: "1", title: "A"))
try await store.save(Item(id: "2", title: "B"))
try await store.delete(id: "1")
let all = try await store.fetchAll()
#expect(store.count == all.count)
}
}
```
#### Running Contract Tests Per Implementation
```swift
@Suite("InMemoryDataStore Contract")
struct InMemoryDataStoreContractTests {
let contract = DataStoreContractTests { InMemoryDataStore() }
@Test("save increases count")
func saveIncreasesCount() async throws {
try await contract.saveIncreasesCount()
}
@Test("save then fetch returns same item")
func saveAndFetch() async throws {
try await contract.saveAndFetch()
}
// ... all contract tests
}
@Suite("SQLiteDataStore Contract")
struct SQLiteDataStoreContractTests {
let contract = DataStoreContractTests { SQLiteDataStore(path: ":memory:") }
@Test("save increases count")
func saveIncreasesCount() async throws {
try await contract.saveIncreasesCount()
}
// ... all contract tests
}
```
#### Alternative: Parameterized by Implementation
```swift
@Suite("DataStore Contract")
struct DataStoreContractSuite {
enum StoreType: String, CaseIterable {
case inMemory, sqlite, cloud
}
func makeStore(_ type: StoreType) -> any DataStore {
switch type {
case .inMemory: return InMemoryDataStore()
case .sqlite: return SQLiteDataStore(path: ":memory:")
case .cloud: return MockCloudDataStore()
}
}
@Test("save increases count", arguments: StoreType.allCases)
func saveIncreasesCount(type: StoreType) async throws {
let store = makeStore(type)
try await store.save(Item(id: "1", title: "Test"))
#expect(store.count == 1)
}
@Test("fetch non-existent returns nil", arguments: StoreType.allCases)
func fetchNonExistent(type: StoreType) async throws {
let store = makeStore(type)
let result = try await store.fetch(id: "nonexistent")
#expect(result == nil)
}
}
```
## Common Contract Categories
### Repository / Data Store
- CRUD operations (create, read, update, delete)
- Query/filter behavior
- Ordering guarantees
- Uniqueness constraints
- Empty state handling
### Network Client
- Successful response parsing
- Error response handling (4xx, 5xx)
- Timeout behavior
- Retry logic
- Request construction (headers, body)
### Cache
- Store and retrieve
- Expiration/TTL
- Eviction policy (LRU, size limit)
- Thread safety
- Persistence across init
### Authentication
- Login with valid credentials
- Reject invalid credentials
- Token refresh
- Session expiration
- Logout clears state
## ORelated in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.