prodigy 0.4.4

Turn ad-hoc Claude sessions into reproducible development pipelines with parallel AI agents
Documentation
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
//! Reader pattern helpers for environment access
//!
//! This module provides helper functions for accessing environment values using
//! Stillwater's Effect pattern. These helpers implement the Reader pattern for
//! clean dependency injection without manual parameter threading.
//!
//! # Architecture
//!
//! Instead of passing configuration and dependencies through function parameters:
//!
//! ```ignore
//! // Before: Manual threading
//! async fn execute_agent(
//!     item: &Value,
//!     config: &MapConfig,
//!     worktree_manager: &WorktreeManager,
//!     executor: &CommandExecutor,
//!     storage: &Storage,
//! ) -> Result<AgentResult> { ... }
//! ```
//!
//! Use Effect::asks to extract them from the environment:
//!
//! ```ignore
//! // After: Reader pattern
//! fn execute_agent(item: Value) -> Effect<AgentResult, AgentError, MapEnv> {
//!     get_worktree_manager()
//!         .and_then(|wt_mgr| create_worktree_effect(&item.id))
//!         .and_then(|worktree| execute_commands_effect(&item, &worktree))
//! }
//! ```
//!
//! # Local Overrides
//!
//! Use the `with_*` functions to temporarily modify environment values:
//!
//! ```ignore
//! // Increase timeout for long-running operation
//! let effect = with_timeout(
//!     Duration::from_secs(600),
//!     execute_setup_commands(commands),
//! );
//! ```
//!
//! # Testing
//!
//! Use `MockMapEnvBuilder` for unit testing:
//!
//! ```ignore
//! let env = MockMapEnvBuilder::new()
//!     .with_max_parallel(4)
//!     .build();
//!
//! let effect = get_max_parallel();
//! assert_eq!(effect.run(&env).unwrap(), 4);
//! ```

use crate::cook::execution::errors::MapReduceError;
use crate::cook::execution::mapreduce::agent_command_executor::AgentCommandExecutor;
use crate::cook::execution::mapreduce::checkpoint::storage::CheckpointStorage;
use crate::cook::execution::mapreduce::environment::{MapEnv, PhaseEnv};
use crate::cook::workflow::WorkflowStep;
use crate::worktree::WorktreeManager;
use serde_json::Value;
use std::collections::HashMap;
use std::sync::Arc;
use stillwater::{asks, local, Effect};

// =============================================================================
// MapEnv Reader Helpers
// =============================================================================

/// Get the worktree manager from the map environment.
///
/// # Example
///
/// ```ignore
/// let effect = get_worktree_manager()
///     .and_then(|mgr| {
///         // Use worktree manager
///         Effect::pure(())
///     });
/// ```
pub fn get_worktree_manager(
) -> impl Effect<Output = Arc<WorktreeManager>, Error = MapReduceError, Env = MapEnv> {
    asks(|env: &MapEnv| env.worktree_manager.clone())
}

/// Get the command executor from the map environment.
///
/// # Example
///
/// ```ignore
/// let effect = get_command_executor()
///     .and_then(|executor| {
///         // Execute commands with executor
///         Effect::pure(())
///     });
/// ```
pub fn get_command_executor(
) -> impl Effect<Output = Arc<AgentCommandExecutor>, Error = MapReduceError, Env = MapEnv> {
    asks(|env: &MapEnv| env.command_executor.clone())
}

/// Get the checkpoint storage from the map environment.
///
/// # Example
///
/// ```ignore
/// let effect = get_storage()
///     .and_then(|storage| {
///         // Save checkpoint
///         Effect::pure(())
///     });
/// ```
pub fn get_storage(
) -> impl Effect<Output = Arc<dyn CheckpointStorage>, Error = MapReduceError, Env = MapEnv> {
    asks(|env: &MapEnv| env.storage.clone())
}

/// Get the agent template from the map environment.
///
/// # Example
///
/// ```ignore
/// let effect = get_agent_template()
///     .and_then(|template| {
///         // Use template for agent
///         Effect::pure(())
///     });
/// ```
pub fn get_agent_template(
) -> impl Effect<Output = Vec<WorkflowStep>, Error = MapReduceError, Env = MapEnv> {
    asks(|env: &MapEnv| env.agent_template.clone())
}

/// Get the job ID from the map environment.
///
/// # Example
///
/// ```ignore
/// let effect = get_job_id()
///     .and_then(|job_id| {
///         info!("Processing job: {}", job_id);
///         Effect::pure(())
///     });
/// ```
pub fn get_job_id() -> impl Effect<Output = String, Error = MapReduceError, Env = MapEnv> {
    asks(|env: &MapEnv| env.job_id.clone())
}

/// Get the maximum parallel agents setting from the map environment.
///
/// # Example
///
/// ```ignore
/// let effect = get_max_parallel()
///     .and_then(|max| {
///         // Limit concurrency
///         Effect::pure(max)
///     });
/// ```
pub fn get_max_parallel() -> impl Effect<Output = usize, Error = MapReduceError, Env = MapEnv> {
    asks(|env: &MapEnv| env.max_parallel)
}

/// Get workflow environment variables from the map environment.
///
/// # Example
///
/// ```ignore
/// let effect = get_workflow_env()
///     .and_then(|vars| {
///         // Access workflow variables
///         Effect::pure(())
///     });
/// ```
pub fn get_workflow_env(
) -> impl Effect<Output = HashMap<String, Value>, Error = MapReduceError, Env = MapEnv> {
    asks(|env: &MapEnv| env.workflow_env.clone())
}

/// Get additional configuration from the map environment.
///
/// # Example
///
/// ```ignore
/// let effect = get_config()
///     .and_then(|config| {
///         if let Some(debug) = config.get("debug") {
///             // Handle debug mode
///         }
///         Effect::pure(())
///     });
/// ```
pub fn get_config(
) -> impl Effect<Output = HashMap<String, Value>, Error = MapReduceError, Env = MapEnv> {
    asks(|env: &MapEnv| env.config.clone())
}

/// Get a specific configuration value from the map environment.
///
/// # Example
///
/// ```ignore
/// let effect = get_config_value("debug")
///     .and_then(|debug_value| {
///         // Use debug value
///         Effect::pure(())
///     });
/// ```
pub fn get_config_value(
    key: &str,
) -> impl Effect<Output = Option<Value>, Error = MapReduceError, Env = MapEnv> {
    let key = key.to_string();
    asks(move |env: &MapEnv| env.config.get(&key).cloned())
}

/// Compose multiple environment accesses into a single effect.
///
/// # Example
///
/// ```ignore
/// let effect = get_execution_context()
///     .and_then(|(job_id, max_parallel, storage)| {
///         // Use all three values together
///         Effect::pure(())
///     });
/// ```
pub fn get_execution_context() -> impl Effect<
    Output = (String, usize, Arc<dyn CheckpointStorage>),
    Error = MapReduceError,
    Env = MapEnv,
> {
    asks(|env: &MapEnv| (env.job_id.clone(), env.max_parallel, env.storage.clone()))
}

// =============================================================================
// PhaseEnv Reader Helpers
// =============================================================================

/// Get the command executor from the phase environment.
pub fn get_phase_command_executor(
) -> impl Effect<Output = Arc<AgentCommandExecutor>, Error = MapReduceError, Env = PhaseEnv> {
    asks(|env: &PhaseEnv| env.command_executor.clone())
}

/// Get the checkpoint storage from the phase environment.
pub fn get_phase_storage(
) -> impl Effect<Output = Arc<dyn CheckpointStorage>, Error = MapReduceError, Env = PhaseEnv> {
    asks(|env: &PhaseEnv| env.storage.clone())
}

/// Get variables from the phase environment.
pub fn get_variables(
) -> impl Effect<Output = HashMap<String, Value>, Error = MapReduceError, Env = PhaseEnv> {
    asks(|env: &PhaseEnv| env.variables.clone())
}

/// Get a specific variable from the phase environment.
pub fn get_variable(
    name: &str,
) -> impl Effect<Output = Option<Value>, Error = MapReduceError, Env = PhaseEnv> {
    let name = name.to_string();
    asks(move |env: &PhaseEnv| env.variables.get(&name).cloned())
}

/// Get workflow environment variables from the phase environment.
pub fn get_phase_workflow_env(
) -> impl Effect<Output = HashMap<String, Value>, Error = MapReduceError, Env = PhaseEnv> {
    asks(|env: &PhaseEnv| env.workflow_env.clone())
}

// =============================================================================
// Local Override Utilities for MapEnv
// =============================================================================

/// Configuration for local environment overrides.
#[derive(Clone, Debug, Default)]
pub struct MapEnvOverrides {
    /// Override max parallel agents
    pub max_parallel: Option<usize>,
    /// Override or merge additional config values
    pub config_overrides: Option<HashMap<String, Value>>,
    /// Override or merge workflow environment
    pub workflow_env_overrides: Option<HashMap<String, Value>>,
}

impl MapEnvOverrides {
    /// Create a new empty overrides instance.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set max parallel override.
    pub fn with_max_parallel(mut self, max_parallel: usize) -> Self {
        self.max_parallel = Some(max_parallel);
        self
    }

    /// Set config override.
    pub fn with_config(mut self, key: impl Into<String>, value: Value) -> Self {
        self.config_overrides
            .get_or_insert_with(HashMap::new)
            .insert(key.into(), value);
        self
    }

    /// Set workflow env override.
    pub fn with_workflow_env(mut self, key: impl Into<String>, value: Value) -> Self {
        self.workflow_env_overrides
            .get_or_insert_with(HashMap::new)
            .insert(key.into(), value);
        self
    }
}

/// Run an effect with a modified max_parallel setting.
///
/// This allows temporarily increasing or decreasing concurrency for
/// specific operations without affecting the rest of the workflow.
///
/// # Example
///
/// ```ignore
/// // Run with reduced concurrency for risky operations
/// let effect = with_max_parallel(
///     2,
///     execute_agents(work_items),
/// );
/// ```
pub fn with_max_parallel<E>(
    max_parallel: usize,
    effect: E,
) -> impl Effect<Output = E::Output, Error = MapReduceError, Env = MapEnv>
where
    E: Effect<Error = MapReduceError, Env = MapEnv>,
{
    local(
        move |env: &MapEnv| MapEnv {
            max_parallel,
            ..env.clone()
        },
        effect,
    )
}

/// Run an effect with additional config values.
///
/// Merges the provided config values with the existing config,
/// with new values taking precedence.
///
/// # Example
///
/// ```ignore
/// let effect = with_config(
///     [("debug".to_string(), json!(true))].into_iter().collect(),
///     execute_setup(commands),
/// );
/// ```
pub fn with_config<E>(
    config_overrides: HashMap<String, Value>,
    effect: E,
) -> impl Effect<Output = E::Output, Error = MapReduceError, Env = MapEnv>
where
    E: Effect<Error = MapReduceError, Env = MapEnv>,
{
    local(
        move |env: &MapEnv| {
            let mut config = env.config.clone();
            config.extend(config_overrides.clone());
            MapEnv {
                config,
                ..env.clone()
            }
        },
        effect,
    )
}

/// Run an effect with debug mode enabled.
///
/// Sets the "debug" config value to true for the duration of the effect.
///
/// # Example
///
/// ```ignore
/// let effect = with_debug(execute_commands(commands));
/// ```
pub fn with_debug<E>(
    effect: E,
) -> impl Effect<Output = E::Output, Error = MapReduceError, Env = MapEnv>
where
    E: Effect<Error = MapReduceError, Env = MapEnv>,
{
    local(
        |env: &MapEnv| {
            let mut config = env.config.clone();
            config.insert("debug".to_string(), serde_json::json!(true));
            MapEnv {
                config,
                ..env.clone()
            }
        },
        effect,
    )
}

/// Run an effect with verbose mode enabled.
///
/// Sets the "verbose" config value to true for the duration of the effect.
///
/// # Example
///
/// ```ignore
/// let effect = with_verbose(execute_agent(item));
/// ```
pub fn with_verbose<E>(
    effect: E,
) -> impl Effect<Output = E::Output, Error = MapReduceError, Env = MapEnv>
where
    E: Effect<Error = MapReduceError, Env = MapEnv>,
{
    local(
        |env: &MapEnv| {
            let mut config = env.config.clone();
            config.insert("verbose".to_string(), serde_json::json!(true));
            MapEnv {
                config,
                ..env.clone()
            }
        },
        effect,
    )
}

/// Run an effect with custom overrides.
///
/// Applies all overrides from MapEnvOverrides to the environment.
///
/// # Example
///
/// ```ignore
/// let overrides = MapEnvOverrides::new()
///     .with_max_parallel(2)
///     .with_config("debug", json!(true));
///
/// let effect = with_overrides(overrides, execute_agents(items));
/// ```
pub fn with_overrides<E>(
    overrides: MapEnvOverrides,
    effect: E,
) -> impl Effect<Output = E::Output, Error = MapReduceError, Env = MapEnv>
where
    E: Effect<Error = MapReduceError, Env = MapEnv>,
{
    local(
        move |env: &MapEnv| {
            let mut new_env = env.clone();

            if let Some(max_parallel) = overrides.max_parallel {
                new_env.max_parallel = max_parallel;
            }

            if let Some(ref config_overrides) = overrides.config_overrides {
                new_env.config.extend(config_overrides.clone());
            }

            if let Some(ref workflow_env_overrides) = overrides.workflow_env_overrides {
                new_env.workflow_env.extend(workflow_env_overrides.clone());
            }

            new_env
        },
        effect,
    )
}

// =============================================================================
// Local Override Utilities for PhaseEnv
// =============================================================================

/// Configuration for phase environment overrides.
#[derive(Clone, Debug, Default)]
pub struct PhaseEnvOverrides {
    /// Override or merge variables
    pub variable_overrides: Option<HashMap<String, Value>>,
    /// Override or merge workflow environment
    pub workflow_env_overrides: Option<HashMap<String, Value>>,
}

impl PhaseEnvOverrides {
    /// Create a new empty overrides instance.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set variable override.
    pub fn with_variable(mut self, name: impl Into<String>, value: Value) -> Self {
        self.variable_overrides
            .get_or_insert_with(HashMap::new)
            .insert(name.into(), value);
        self
    }

    /// Set workflow env override.
    pub fn with_workflow_env(mut self, key: impl Into<String>, value: Value) -> Self {
        self.workflow_env_overrides
            .get_or_insert_with(HashMap::new)
            .insert(key.into(), value);
        self
    }
}

/// Run a phase effect with additional variables.
///
/// # Example
///
/// ```ignore
/// let effect = with_variables(
///     [("result".to_string(), json!({"count": 10}))].into_iter().collect(),
///     execute_reduce(commands),
/// );
/// ```
pub fn with_variables<E>(
    variable_overrides: HashMap<String, Value>,
    effect: E,
) -> impl Effect<Output = E::Output, Error = MapReduceError, Env = PhaseEnv>
where
    E: Effect<Error = MapReduceError, Env = PhaseEnv>,
{
    local(
        move |env: &PhaseEnv| {
            let mut variables = env.variables.clone();
            variables.extend(variable_overrides.clone());
            PhaseEnv {
                variables,
                ..env.clone()
            }
        },
        effect,
    )
}

/// Run a phase effect with custom overrides.
///
/// # Example
///
/// ```ignore
/// let overrides = PhaseEnvOverrides::new()
///     .with_variable("result", json!({"count": 10}));
///
/// let effect = with_phase_overrides(overrides, execute_reduce(commands));
/// ```
pub fn with_phase_overrides<E>(
    overrides: PhaseEnvOverrides,
    effect: E,
) -> impl Effect<Output = E::Output, Error = MapReduceError, Env = PhaseEnv>
where
    E: Effect<Error = MapReduceError, Env = PhaseEnv>,
{
    local(
        move |env: &PhaseEnv| {
            let mut new_env = env.clone();

            if let Some(ref variable_overrides) = overrides.variable_overrides {
                new_env.variables.extend(variable_overrides.clone());
            }

            if let Some(ref workflow_env_overrides) = overrides.workflow_env_overrides {
                new_env.workflow_env.extend(workflow_env_overrides.clone());
            }

            new_env
        },
        effect,
    )
}

// =============================================================================
// Tests
// =============================================================================

#[cfg(test)]
mod tests {
    use super::*;
    use crate::cook::execution::mapreduce::mock_environment::{
        MockMapEnvBuilder, MockPhaseEnvBuilder,
    };
    use stillwater::{Effect, EffectExt};

    #[tokio::test]
    async fn test_get_max_parallel() {
        let env = MockMapEnvBuilder::new().with_max_parallel(10).build();

        let effect = get_max_parallel();
        let result = effect.run(&env).await;

        assert!(result.is_ok());
        assert_eq!(result.unwrap(), 10);
    }

    #[tokio::test]
    async fn test_get_job_id() {
        let env = MockMapEnvBuilder::new().with_job_id("my-job-456").build();

        let effect = get_job_id();
        let result = effect.run(&env).await;

        assert!(result.is_ok());
        assert_eq!(result.unwrap(), "my-job-456");
    }

    #[tokio::test]
    async fn test_get_config_value() {
        let env = MockMapEnvBuilder::new()
            .with_config("debug", serde_json::json!(true))
            .with_config("timeout", serde_json::json!(30))
            .build();

        // Test existing key
        let effect = get_config_value("debug");
        let result = effect.run(&env).await.unwrap();
        assert_eq!(result, Some(serde_json::json!(true)));

        // Test missing key
        let effect = get_config_value("nonexistent");
        let result = effect.run(&env).await.unwrap();
        assert_eq!(result, None);
    }

    #[tokio::test]
    async fn test_with_max_parallel_local_override() {
        let env = MockMapEnvBuilder::new().with_max_parallel(5).build();

        // Without override
        let effect = get_max_parallel();
        assert_eq!(effect.run(&env).await.unwrap(), 5);

        // With local override
        let effect = with_max_parallel(20, get_max_parallel());
        assert_eq!(effect.run(&env).await.unwrap(), 20);

        // Original environment unchanged
        let effect = get_max_parallel();
        assert_eq!(effect.run(&env).await.unwrap(), 5);
    }

    #[tokio::test]
    async fn test_with_debug_local_override() {
        let env = MockMapEnvBuilder::new().build();

        // Without debug
        let effect = get_config_value("debug");
        assert_eq!(effect.run(&env).await.unwrap(), None);

        // With debug enabled
        let effect = with_debug(get_config_value("debug"));
        assert_eq!(
            effect.run(&env).await.unwrap(),
            Some(serde_json::json!(true))
        );

        // Original environment unchanged
        let effect = get_config_value("debug");
        assert_eq!(effect.run(&env).await.unwrap(), None);
    }

    #[tokio::test]
    async fn test_local_changes_dont_leak() {
        let env = MockMapEnvBuilder::new().with_max_parallel(5).build();

        // Execute with local override
        let inner_effect = with_max_parallel(100, get_max_parallel());
        let inner_result = inner_effect.run(&env).await.unwrap();
        assert_eq!(inner_result, 100); // Override applied inside

        // Check environment unchanged outside
        let outer_effect = get_max_parallel();
        let outer_result = outer_effect.run(&env).await.unwrap();
        assert_eq!(outer_result, 5); // Original value preserved
    }

    #[tokio::test]
    async fn test_nested_local_overrides() {
        let env = MockMapEnvBuilder::new().with_max_parallel(5).build();

        // Nested local overrides
        let effect = with_debug(with_max_parallel(
            50,
            get_max_parallel()
                .and_then(|max| get_config_value("debug").map(move |debug| (max, debug))),
        ));

        let (max, debug) = effect.run(&env).await.unwrap();
        assert_eq!(max, 50);
        assert_eq!(debug, Some(serde_json::json!(true)));

        // Original environment still unchanged
        let effect = get_max_parallel();
        assert_eq!(effect.run(&env).await.unwrap(), 5);
    }

    #[tokio::test]
    async fn test_with_overrides() {
        let env = MockMapEnvBuilder::new().with_max_parallel(5).build();

        let overrides = MapEnvOverrides::new()
            .with_max_parallel(25)
            .with_config("verbose", serde_json::json!(true));

        let effect = with_overrides(
            overrides,
            get_max_parallel()
                .and_then(|max| get_config_value("verbose").map(move |verbose| (max, verbose))),
        );

        let (max, verbose) = effect.run(&env).await.unwrap();
        assert_eq!(max, 25);
        assert_eq!(verbose, Some(serde_json::json!(true)));
    }

    #[tokio::test]
    async fn test_phase_env_get_variables() {
        let env = MockPhaseEnvBuilder::new()
            .with_variable("count", serde_json::json!(42))
            .with_variable("name", serde_json::json!("test"))
            .build();

        let effect = get_variable("count");
        let result = effect.run(&env).await.unwrap();
        assert_eq!(result, Some(serde_json::json!(42)));

        let effect = get_variable("missing");
        let result = effect.run(&env).await.unwrap();
        assert_eq!(result, None);
    }

    #[tokio::test]
    async fn test_phase_with_variables_override() {
        let env = MockPhaseEnvBuilder::new()
            .with_variable("count", serde_json::json!(10))
            .build();

        // Without override
        let effect = get_variable("count");
        assert_eq!(effect.run(&env).await.unwrap(), Some(serde_json::json!(10)));

        // With override
        let new_vars = [("count".to_string(), serde_json::json!(100))]
            .into_iter()
            .collect();
        let effect = with_variables(new_vars, get_variable("count"));
        assert_eq!(
            effect.run(&env).await.unwrap(),
            Some(serde_json::json!(100))
        );

        // Original unchanged
        let effect = get_variable("count");
        assert_eq!(effect.run(&env).await.unwrap(), Some(serde_json::json!(10)));
    }
}