name: kotlin-expert-tests
skill: kotlin-expert
version: 1.0.0
cases:
  - id: double-bang-operator
    description: Should reject !! without a null-proof and suggest safe alternatives
    prompt: I keep getting null pointer exceptions in Kotlin. My teammate said to just add !! everywhere to silence the compiler warnings. Is that fine?
    expected:
      contains_any:
        - "!!"
        - safe call
        - "?."
        - "?:"
        - elvis
        - smart cast
        - guard
        - requireNotNull
      not_contains:
        - fine
        - okay to use !!
      min_length: 80
    tags: [core, null-safety]

  - id: global-scope-launch
    description: Should reject GlobalScope.launch and recommend scoped CoroutineScope
    prompt: I want to fire off a background task in my Android app when the user taps a button. I'm using GlobalScope.launch. Is there anything wrong with that?
    expected:
      contains_any:
        - GlobalScope
        - leak
        - viewModelScope
        - lifecycleScope
        - structured
        - cancellation
        - scope
      min_length: 80
    tags: [core, coroutines]

  - id: sealed-class-state-modeling
    description: Should recommend sealed classes for UI state and exhaustive when expressions
    prompt: I'm modeling loading/success/error states for my Android UI. I have a boolean isLoading and a nullable data field and a nullable errorMessage field. Is this a good approach?
    expected:
      contains_any:
        - sealed
        - when
        - exhaustive
        - UiState
        - Loading
        - Success
        - Error
        - impossible states
      min_length: 80
    tags: [core, types]

  - id: coroutines-cancellation-exception
    description: Should recommend always rethrowing CancellationException
    prompt: In my coroutine I have a try-catch that catches Exception. Should I also catch CancellationException or will that be handled automatically?
    expected:
      contains_any:
        - CancellationException
        - rethrow
        - re-throw
        - structured concurrency
        - cancellation
        - propagate
      min_length: 60
    tags: [core, coroutines]

  - id: val-over-var
    description: Should recommend val over var and immutable collections
    prompt: In Kotlin, when should I use var versus val? I've been defaulting to var since I might need to change the value later.
    expected:
      contains_any:
        - val
        - immutable
        - default
        - var only when
        - mutation
        - copy()
      min_length: 80
    tags: [core, immutability]

  - id: extension-functions
    description: Should recommend extension functions over utility classes
    prompt: I have a StringUtils class with static helper methods in my Kotlin project. Is this the right approach?
    expected:
      contains_any:
        - extension function
        - extension
        - utility class
        - StringUtils
        - idiomatic
      min_length: 60
    tags: [core, idioms]

  - id: coding-easy-sealed-result
    description: "Coding challenge (easy): Write a sealed Result class with map and fold"
    prompt: "Write a Kotlin sealed class Result<out T> with Success and Failure subclasses. Include map, flatMap, fold, and getOrElse methods. The Failure class should hold a Throwable. Make it work naturally with when expressions."
    expected:
      contains_any:
        - sealed
        - Success
        - Failure
        - map
        - when
        - Throwable
      contains:
        - class
      not_contains:
        - "I can't write"
      min_length: 100
    tags:
      - coding-easy

  - id: coding-medium-coroutine-retry
    description: "Coding challenge (medium): Implement a coroutine-based retry with backoff and circuit breaking"
    prompt: "Write a Kotlin suspend function retryWithBackoff that retries a suspend lambda on failure. It should support: configurable max retries, exponential backoff with jitter, a predicate to decide which exceptions are retryable, and circuit breaker behavior (stop retrying if failures exceed a threshold within a time window). Use structured concurrency."
    expected:
      contains_any:
        - suspend
        - delay
        - retry
        - backoff
        - exception
        - coroutine
      contains:
        - fun
      min_length: 200
    tags:
      - coding-medium

  - id: coding-hard-flow-pipeline
    description: "Coding challenge (hard): Build a reactive data pipeline with Kotlin Flow"
    prompt: "Write a Kotlin Flow-based reactive pipeline framework. Create a PipelineBuilder DSL that lets you chain stages using transform, filter, batch (group N items), rateLimit (max items per second), and merge (combine multiple flows). Each stage should propagate backpressure. Include error handling per-stage with retry and fallback strategies. Support graceful cancellation."
    expected:
      contains_any:
        - Flow
        - flow
        - collect
        - emit
        - transform
        - channelFlow
      contains:
        - fun
        - class
      min_length: 300
    tags:
      - coding-hard
