shellfirm 0.3.8

`shellfirm` will intercept any risky patterns (default or defined by you) and prompt you a small challenge for double verification, kinda like a captcha for your terminal.
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
//! Tier 2: Sandboxed integration tests — full pipeline with MockEnvironment + MockPrompter.
//!
//! These test the complete command processing pipeline end-to-end with
//! **zero real system access**. The mock environment provides virtual
//! filesystem, env vars, and command outputs.

use std::{collections::HashMap, path::PathBuf};

use serde_json;
use shellfirm::{
    checks,
    context::{self, ContextConfig},
    env::MockEnvironment,
    policy::{self, MergedPolicy, ProjectPolicy},
    prompt::{ChallengeResult, MockPrompter},
    Challenge, Settings,
};

// ---------------------------------------------------------------------------
// Test helpers — mock environment builders
// ---------------------------------------------------------------------------

fn default_settings() -> Settings {
    Settings {
        enabled_groups: vec![
            "base".into(),
            "fs".into(),
            "git".into(),
            "kubernetes".into(),
            "docker".into(),
            "aws".into(),
        ],
        audit_enabled: false,
        ..Settings::default()
    }
}

fn mock_env_production_ssh() -> MockEnvironment {
    let mut env_vars = HashMap::new();
    env_vars.insert("SSH_CONNECTION".into(), "10.0.0.1 22 10.0.0.2 54321".into());
    env_vars.insert("NODE_ENV".into(), "production".into());

    let mut command_outputs = HashMap::new();
    command_outputs.insert("git rev-parse --abbrev-ref HEAD".into(), "main".into());
    command_outputs.insert(
        "kubectl config current-context".into(),
        "prod-us-east-1".into(),
    );

    MockEnvironment {
        env_vars,
        cwd: PathBuf::from("/var/app/deploy"),
        existing_paths: Default::default(),
        command_outputs,
        files: Default::default(),
        home: Some(PathBuf::from("/home/deploy")),
    }
}

fn mock_env_local_dev() -> MockEnvironment {
    let mut env_vars = HashMap::new();
    env_vars.insert("NODE_ENV".into(), "development".into());

    let mut command_outputs = HashMap::new();
    command_outputs.insert(
        "git rev-parse --abbrev-ref HEAD".into(),
        "feature/my-thing".into(),
    );
    command_outputs.insert("kubectl config current-context".into(), "minikube".into());

    MockEnvironment {
        env_vars,
        cwd: PathBuf::from("/Users/dev/project"),
        existing_paths: Default::default(),
        command_outputs,
        files: Default::default(),
        home: Some(PathBuf::from("/Users/dev")),
    }
}

/// Run the full challenge pipeline and return the display context and result.
fn run_pipeline(
    command: &str,
    settings: &Settings,
    env: &MockEnvironment,
    prompter: &MockPrompter,
    project_policy: Option<&ProjectPolicy>,
) -> Option<ChallengeResult> {
    let all_checks = settings.get_active_checks().unwrap();

    // Split and check
    let parts = checks::split_command(command);
    let matches: Vec<&checks::Check> = parts
        .iter()
        .flat_map(|c| checks::run_check_on_command_with_env(&all_checks, c, env))
        .collect();

    if matches.is_empty() {
        return None; // No risky patterns found
    }

    // Detect context
    let runtime_context = context::detect(env, &settings.context);

    // Merge project policy
    let merged_policy = if let Some(pp) = project_policy {
        policy::merge_into_settings(settings, pp, runtime_context.git_branch.as_deref())
    } else {
        MergedPolicy::default()
    };

    // Run challenge
    let result = checks::challenge_with_context(
        settings,
        &matches,
        &runtime_context,
        &merged_policy,
        prompter,
        &[],
    )
    .unwrap();

    Some(result)
}

// ---------------------------------------------------------------------------
// Context detection tests
// ---------------------------------------------------------------------------

#[test]
fn test_context_production_ssh_is_critical() {
    let env = mock_env_production_ssh();
    let ctx = context::detect(&env, &ContextConfig::default());

    assert!(ctx.is_ssh);
    assert_eq!(ctx.git_branch, Some("main".into()));
    assert_eq!(ctx.k8s_context, Some("prod-us-east-1".into()));
    assert_eq!(ctx.risk_level, context::RiskLevel::Critical);
    assert!(!ctx.labels.is_empty());
}

#[test]
fn test_context_local_dev_is_normal() {
    let env = mock_env_local_dev();
    let ctx = context::detect(&env, &ContextConfig::default());

    assert!(!ctx.is_ssh);
    assert_eq!(ctx.git_branch, Some("feature/my-thing".into()));
    assert_eq!(ctx.k8s_context, Some("minikube".into()));
    assert_eq!(ctx.risk_level, context::RiskLevel::Normal);
}

// ---------------------------------------------------------------------------
// Full pipeline tests
// ---------------------------------------------------------------------------

#[test]
fn test_pipeline_local_dev_force_push_passes() {
    let env = mock_env_local_dev();
    let prompter = MockPrompter::passing();
    let settings = default_settings();

    let result = run_pipeline(
        "git push -f origin feature/my-thing",
        &settings,
        &env,
        &prompter,
        None,
    );

    assert_eq!(result, Some(ChallengeResult::Passed));

    // Verify the display showed Enter challenge (High severity → Enter, no context escalation)
    let displays = prompter.captured_displays.borrow();
    assert_eq!(displays.len(), 1);
    assert_eq!(displays[0].effective_challenge, Challenge::Enter);
    assert!(!displays[0].is_denied);
}

#[test]
fn test_pipeline_production_ssh_force_push_escalates() {
    let env = mock_env_production_ssh();
    let prompter = MockPrompter::passing();
    let settings = default_settings();

    let result = run_pipeline("git push -f origin main", &settings, &env, &prompter, None);

    assert_eq!(result, Some(ChallengeResult::Passed));

    let displays = prompter.captured_displays.borrow();
    assert_eq!(displays.len(), 1);
    // Should be escalated from Math to Yes due to Critical context (main branch + prod k8s)
    assert_eq!(displays[0].effective_challenge, Challenge::Yes);
    assert!(!displays[0].context_labels.is_empty());
}

#[test]
fn test_pipeline_safe_command_no_challenge() {
    let env = mock_env_local_dev();
    let prompter = MockPrompter::passing();
    let settings = default_settings();

    let result = run_pipeline("git status", &settings, &env, &prompter, None);
    assert!(result.is_none()); // No risky patterns
    assert!(prompter.captured_displays.borrow().is_empty());
}

#[test]
fn test_pipeline_project_policy_denies_force_push() {
    let env = mock_env_local_dev();
    let prompter = MockPrompter::passing();
    let settings = default_settings();
    let policy = ProjectPolicy {
        version: 1,
        deny: vec!["git:force_push".into()],
        ..Default::default()
    };

    let result = run_pipeline(
        "git push -f origin feature/my-thing",
        &settings,
        &env,
        &prompter,
        Some(&policy),
    );

    // Should be denied because project policy denies git:force_push
    assert_eq!(result, Some(ChallengeResult::Denied));

    let displays = prompter.captured_displays.borrow();
    assert_eq!(displays.len(), 1);
    assert!(displays[0].is_denied);
}

#[test]
fn test_pipeline_global_deny_blocks() {
    let env = mock_env_local_dev();
    let prompter = MockPrompter::passing();
    let mut settings = default_settings();
    settings.deny_patterns_ids = vec!["git:force_push".into()];

    let result = run_pipeline(
        "git push -f origin feature/my-thing",
        &settings,
        &env,
        &prompter,
        None,
    );

    assert_eq!(result, Some(ChallengeResult::Denied));
}

#[test]
fn test_pipeline_alternative_shown_for_force_push() {
    let env = mock_env_local_dev();
    let prompter = MockPrompter::passing();
    let settings = default_settings();

    let result = run_pipeline("git push -f origin main", &settings, &env, &prompter, None);

    assert_eq!(result, Some(ChallengeResult::Passed));

    let displays = prompter.captured_displays.borrow();
    assert_eq!(displays.len(), 1);
    assert!(
        displays[0]
            .alternatives
            .iter()
            .any(|a| a.suggestion.contains("--force-with-lease")),
        "Expected --force-with-lease alternative, got: {:?}",
        displays[0].alternatives
    );
}

#[test]
fn test_pipeline_compound_command_detects_risky_part() {
    let env = mock_env_local_dev();
    let prompter = MockPrompter::passing();
    let settings = default_settings();

    // The risky command is after &&
    let result = run_pipeline(
        "cd /tmp && git push -f origin main",
        &settings,
        &env,
        &prompter,
        None,
    );

    assert_eq!(result, Some(ChallengeResult::Passed));
    let displays = prompter.captured_displays.borrow();
    assert_eq!(displays.len(), 1);
}

// ---------------------------------------------------------------------------
// Policy discovery in virtual filesystem
// ---------------------------------------------------------------------------

#[test]
fn test_policy_discovery_walks_up() {
    let mut files = HashMap::new();
    files.insert(
        PathBuf::from("/repo/.shellfirm.yaml"),
        "version: 1\ndeny:\n  - git:force_push\n".into(),
    );
    let env = MockEnvironment {
        cwd: PathBuf::from("/repo/src/deep/nested"),
        files,
        ..Default::default()
    };

    let p = policy::discover(&env, &env.cwd);
    assert!(p.is_some());
    assert!(p.unwrap().deny.contains(&"git:force_push".to_string()));
}

#[test]
fn test_policy_discovery_no_file() {
    let env = MockEnvironment {
        cwd: PathBuf::from("/home/user/project"),
        ..Default::default()
    };

    let p = policy::discover(&env, &env.cwd);
    assert!(p.is_none());
}

// ---------------------------------------------------------------------------
// Custom checks loading
// ---------------------------------------------------------------------------

#[test]
fn test_custom_checks_loaded_from_temp_dir() {
    let temp = tree_fs::TreeBuilder::default()
        .add(
            "checks/custom.yaml",
            r#"
- from: custom
  test: my-dangerous-tool deploy
  description: "Custom deploy command is risky."
  id: custom:deploy
"#,
        )
        .create()
        .expect("create tree");

    let custom = checks::load_custom_checks(&temp.root.join("checks")).unwrap();
    assert_eq!(custom.len(), 1);
    assert_eq!(custom[0].id, "custom:deploy");

    let matches = checks::run_check_on_command(&custom, "my-dangerous-tool deploy prod");
    assert_eq!(matches.len(), 1);
    assert_eq!(matches[0].id, "custom:deploy");
}

// ---------------------------------------------------------------------------
// Audit log tests
// ---------------------------------------------------------------------------

#[test]
fn test_audit_log_written_to_temp_dir() {
    let temp = tree_fs::TreeBuilder::default()
        .create()
        .expect("create tree");
    let path = temp.root.join("audit.log");

    let event = shellfirm::audit::AuditEvent {
        event_id: "test-integration-1".into(),
        timestamp: "2026-02-15T10:00:00Z".into(),
        command: "git push -f".into(),
        matched_ids: vec!["git:force_push".into()],
        challenge_type: "Math".into(),
        outcome: shellfirm::audit::AuditOutcome::Allowed,
        context_labels: vec!["branch=main".into()],
        severity: shellfirm::checks::Severity::High,
        agent_name: None,
        agent_session_id: None,
        blast_radius_scope: None,
        blast_radius_detail: None,
    };

    shellfirm::audit::log_event(&path, &event).unwrap();
    let content = shellfirm::audit::read_log(&path).unwrap();
    // JSON lines format — parse to verify structure
    let parsed: serde_json::Value = serde_json::from_str(content.trim()).unwrap();
    assert_eq!(parsed["command"], "git push -f");
    assert_eq!(parsed["outcome"], "Allowed");
    assert_eq!(parsed["matched_ids"][0], "git:force_push");
    assert_eq!(parsed["context_labels"][0], "branch=main");
    assert_eq!(parsed["severity"], "High");
}

#[test]
fn test_audit_clear() {
    let temp = tree_fs::TreeBuilder::default()
        .create()
        .expect("create tree");
    let path = temp.root.join("audit.log");

    let event = shellfirm::audit::AuditEvent {
        event_id: "test-integration-2".into(),
        timestamp: "2026-02-15T10:00:00Z".into(),
        command: "rm -rf /".into(),
        matched_ids: vec!["fs:recursively_delete".into()],
        challenge_type: "Math".into(),
        outcome: shellfirm::audit::AuditOutcome::Denied,
        context_labels: vec![],
        severity: shellfirm::checks::Severity::Critical,
        agent_name: None,
        agent_session_id: None,
        blast_radius_scope: None,
        blast_radius_detail: None,
    };

    shellfirm::audit::log_event(&path, &event).unwrap();
    assert!(path.exists());

    shellfirm::audit::clear_log(&path).unwrap();
    assert!(!path.exists());
}

// ---------------------------------------------------------------------------
// Context-specific escalation scenarios
// ---------------------------------------------------------------------------

#[test]
fn test_ssh_only_elevates_to_enter() {
    let mut env_vars = HashMap::new();
    env_vars.insert("SSH_TTY".into(), "/dev/pts/0".into());
    let env = MockEnvironment {
        env_vars,
        cwd: "/home/user".into(),
        ..Default::default()
    };
    let ctx = context::detect(&env, &ContextConfig::default());
    assert_eq!(ctx.risk_level, context::RiskLevel::Elevated);
}

#[test]
fn test_root_escalates_to_critical() {
    let mut env_vars = HashMap::new();
    env_vars.insert("EUID".into(), "0".into());
    let env = MockEnvironment {
        env_vars,
        cwd: "/root".into(),
        ..Default::default()
    };
    let ctx = context::detect(&env, &ContextConfig::default());
    assert_eq!(ctx.risk_level, context::RiskLevel::Critical);
}

#[test]
fn test_multiple_critical_signals() {
    let mut env_vars = HashMap::new();
    env_vars.insert("SSH_CONNECTION".into(), "10.0.0.1 22".into());
    env_vars.insert("EUID".into(), "0".into());
    env_vars.insert("NODE_ENV".into(), "production".into());

    let mut cmd_outputs = HashMap::new();
    cmd_outputs.insert("git rev-parse --abbrev-ref HEAD".into(), "main".into());

    let env = MockEnvironment {
        env_vars,
        cwd: "/var/app".into(),
        command_outputs: cmd_outputs,
        ..Default::default()
    };
    let ctx = context::detect(&env, &ContextConfig::default());
    assert_eq!(ctx.risk_level, context::RiskLevel::Critical);
    assert!(ctx.is_ssh);
    assert!(ctx.is_root);
}

// ---------------------------------------------------------------------------
// Command-aware context filtering (relevant_context) tests
// ---------------------------------------------------------------------------

// ---------------------------------------------------------------------------
// Severity-based escalation tests
// ---------------------------------------------------------------------------

#[test]
fn test_pipeline_high_severity_escalates_to_enter() {
    // git push -f is High severity → Enter on a normal local dev environment
    let env = mock_env_local_dev();
    let prompter = MockPrompter::passing();
    let settings = default_settings();

    let result = run_pipeline(
        "git push -f origin feature/my-thing",
        &settings,
        &env,
        &prompter,
        None,
    );

    assert_eq!(result, Some(ChallengeResult::Passed));
    let displays = prompter.captured_displays.borrow();
    assert_eq!(displays.len(), 1);
    assert_eq!(displays[0].effective_challenge, Challenge::Enter);
}

#[test]
fn test_pipeline_severity_disabled_stays_math() {
    // With severity escalation disabled, High severity stays at Math
    let env = mock_env_local_dev();
    let prompter = MockPrompter::passing();
    let mut settings = default_settings();
    settings.severity_escalation.enabled = false;

    let result = run_pipeline(
        "git push -f origin feature/my-thing",
        &settings,
        &env,
        &prompter,
        None,
    );

    assert_eq!(result, Some(ChallengeResult::Passed));
    let displays = prompter.captured_displays.borrow();
    assert_eq!(displays.len(), 1);
    assert_eq!(displays[0].effective_challenge, Challenge::Math);
}

#[test]
fn test_pipeline_group_escalation() {
    // Group escalation: git → Yes
    let env = mock_env_local_dev();
    let prompter = MockPrompter::passing();
    let mut settings = default_settings();
    settings.severity_escalation.enabled = false; // disable severity to isolate group
    settings
        .group_escalation
        .insert("git".into(), Challenge::Yes);

    let result = run_pipeline(
        "git push -f origin feature/my-thing",
        &settings,
        &env,
        &prompter,
        None,
    );

    assert_eq!(result, Some(ChallengeResult::Passed));
    let displays = prompter.captured_displays.borrow();
    assert_eq!(displays.len(), 1);
    assert_eq!(displays[0].effective_challenge, Challenge::Yes);
}

#[test]
fn test_pipeline_check_id_escalation() {
    // Check-ID escalation: git:force_push → Yes
    let env = mock_env_local_dev();
    let prompter = MockPrompter::passing();
    let mut settings = default_settings();
    settings.severity_escalation.enabled = false; // disable severity to isolate check-id
    settings
        .check_escalation
        .insert("git:force_push".into(), Challenge::Yes);

    let result = run_pipeline(
        "git push -f origin feature/my-thing",
        &settings,
        &env,
        &prompter,
        None,
    );

    assert_eq!(result, Some(ChallengeResult::Passed));
    let displays = prompter.captured_displays.borrow();
    assert_eq!(displays.len(), 1);
    assert_eq!(displays[0].effective_challenge, Challenge::Yes);
}

#[test]
fn test_pipeline_all_layers_compose() {
    // All layers composing: severity(Enter) + group(ignored, less than Enter) + context(Yes)
    let env = mock_env_production_ssh();
    let prompter = MockPrompter::passing();
    let mut settings = default_settings();
    settings
        .group_escalation
        .insert("git".into(), Challenge::Enter); // less than severity

    let result = run_pipeline("git push -f origin main", &settings, &env, &prompter, None);

    assert_eq!(result, Some(ChallengeResult::Passed));
    let displays = prompter.captured_displays.borrow();
    assert_eq!(displays.len(), 1);
    // max(Enter from severity, Enter from group, Yes from context) = Yes
    assert_eq!(displays[0].effective_challenge, Challenge::Yes);
}

fn strip_quotes_regex() -> regex::Regex {
    regex::Regex::new(r#"'[^']*'|"[^"]*""#).unwrap()
}

#[test]
fn test_relevant_context_rm_rf_hides_branch_and_k8s() {
    // Environment has branch=main + k8s=prod, but `rm -rf /` is an "fs" check
    // so relevant_context should NOT include branch or k8s labels.
    let mut env = mock_env_production_ssh();
    // PathExists filters need `/` to exist in the mock
    env.existing_paths.insert(PathBuf::from("/"));
    let settings = default_settings();
    let all_checks = settings.get_active_checks().unwrap();
    let re = strip_quotes_regex();

    let pipeline = checks::analyze_command("rm -rf /", &settings, &all_checks, &env, &re).unwrap();

    // Should have matched at least one fs check
    assert!(
        !pipeline.active_matches.is_empty(),
        "rm -rf / should match checks"
    );

    // Full context has branch and k8s
    assert!(pipeline.context.git_branch.is_some());
    assert!(pipeline.context.k8s_context.is_some());

    // Relevant context should NOT have branch or k8s (fs command)
    assert!(
        pipeline.relevant_context.git_branch.is_none(),
        "branch should be hidden for fs command"
    );
    assert!(
        pipeline.relevant_context.k8s_context.is_none(),
        "k8s should be hidden for fs command"
    );
    assert!(
        !pipeline
            .relevant_context
            .labels
            .iter()
            .any(|l| l.starts_with("branch=")),
        "branch label should be hidden"
    );
    assert!(
        !pipeline
            .relevant_context
            .labels
            .iter()
            .any(|l| l.starts_with("k8s=")),
        "k8s label should be hidden"
    );
    // Global signals (SSH, env_signals) still present
    assert!(pipeline.relevant_context.is_ssh);
}

#[test]
fn test_relevant_context_git_push_shows_branch_hides_k8s() {
    // `git push --force` is a "git" check — branch should be shown, k8s hidden.
    let env = mock_env_production_ssh();
    let settings = default_settings();
    let all_checks = settings.get_active_checks().unwrap();
    let re = strip_quotes_regex();

    let pipeline =
        checks::analyze_command("git push --force", &settings, &all_checks, &env, &re).unwrap();

    assert!(
        !pipeline.active_matches.is_empty(),
        "git push --force should match checks"
    );

    // Relevant context: branch shown, k8s hidden
    assert_eq!(
        pipeline.relevant_context.git_branch,
        Some("main".into()),
        "branch should be visible for git command"
    );
    assert!(
        pipeline.relevant_context.k8s_context.is_none(),
        "k8s should be hidden for git command"
    );
    assert!(pipeline
        .relevant_context
        .labels
        .iter()
        .any(|l| l.starts_with("branch=")));
    assert!(!pipeline
        .relevant_context
        .labels
        .iter()
        .any(|l| l.starts_with("k8s=")),);
}

#[test]
fn test_relevant_context_kubectl_shows_k8s_hides_branch() {
    // `kubectl delete ns kube-system` is a "kubernetes" check
    let env = mock_env_production_ssh();
    let settings = default_settings();
    let all_checks = settings.get_active_checks().unwrap();
    let re = strip_quotes_regex();

    let pipeline = checks::analyze_command(
        "kubectl delete ns kube-system",
        &settings,
        &all_checks,
        &env,
        &re,
    )
    .unwrap();

    assert!(
        !pipeline.active_matches.is_empty(),
        "kubectl delete ns should match checks"
    );

    // Relevant context: k8s shown, branch hidden
    assert!(
        pipeline.relevant_context.git_branch.is_none(),
        "branch should be hidden for kubernetes command"
    );
    assert_eq!(
        pipeline.relevant_context.k8s_context,
        Some("prod-us-east-1".into()),
        "k8s should be visible for kubernetes command"
    );
}