ignition-cli 1.7.1

ign — operate Ignition 8.3+ gateways from the 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
//! Golden-file contract tests for `ign jvm …` — the SPECIAL-MODE
//! profiling family's binary surface. The pins that matter here are
//! the GATES, in order:
//!
//! 1. The intrusive verbs refuse WITHOUT `--i-accept-the-risk` — exit
//!    2, `profiling_risk_not_accepted`, ZERO HTTP requests (the gate
//!    precedes even the secret handshake).
//! 2. The global `--yes` deliberately does NOT satisfy that gate
//!    (the anti-bypass pin — a blanket confirm must never cover
//!    ACTIVE JVM instrumentation).
//! 3. Over-cap durations refuse `invalid_input` (exit 2, profile
//!    null) BEFORE profile resolution — the caps are refused, never
//!    clamped (usage errors lead, the 03-03 put convention).
//! 4. The ungated halves (`jfr status`, `jfr stop`) reach the
//!    gateway with no flag at all — checking and cleaning up must
//!    always be cheap to reach.
//!
//! The success goldens ride the contract_script harness shape:
//! isolated config with a persisted `webdev_secret`, a wiremock
//! scriptExec route, snapbox inline goldens. Every success carries
//! the `warning` field FIRST (the production caution rides every
//! envelope) and the human renders lead with the stderr banner.

use std::path::{Path, PathBuf};

use assert_cmd::Command;
use base64::Engine as _;

/// The scriptExec route path inside any wiremock server.
const ROUTE_PATH: &str = "/system/webdev/ign-cli/cli/scriptExec";

/// Isolated config dir + the config path inside it (file need not exist).
fn isolated_config() -> (tempfile::TempDir, PathBuf) {
    let dir = tempfile::tempdir().expect("tempdir");
    let path = dir.path().join("config.toml");
    (dir, path)
}

/// Write the one-profile dev config whose URL points at `url`, token
/// from `IGNITION_TOKEN`, and the persisted scriptExec secret (the
/// structural opt-in's deployed state).
fn write_profile_config(config: &Path, url: &str) {
    std::fs::write(
        config,
        format!(
            "active = \"dev\"\n\n[profiles.dev]\nurl = \"{url}\"\n\
             auth = {{ token_env = \"IGNITION_TOKEN\" }}\n\
             webdev_secret = \"cafebabe1234\"\n"
        ),
    )
    .expect("write config");
}

/// Spawn `ign` with an isolated config, the mock token in the env, and args.
fn ign(config: &Path, url: &str, args: &[&str]) -> std::process::Output {
    let mut command = Command::cargo_bin("ign").expect("binary 'ign' not found");
    command
        .env("IGNITION_CLI_CONFIG", config)
        .env("IGNITION_TOKEN", "mock:name-key")
        .env("IGNITION_URL", url);
    command.args(args).output().expect("spawn ign")
}

/// stdout minus the single trailing newline `println!` appends.
fn stdout_for_golden(out: &std::process::Output) -> &str {
    let stdout = std::str::from_utf8(&out.stdout).expect("utf-8 stdout");
    stdout.strip_suffix('\n').unwrap_or(stdout)
}

/// stderr's JSON envelope starting at the first `{` (log-tolerant parse).
fn stderr_envelope(out: &std::process::Output) -> String {
    let stderr = String::from_utf8_lossy(&out.stderr);
    let start = stderr.find('{').unwrap_or(0);
    stderr[start..].to_string()
}

/// Mount the version handshake + ONE exec answering `payload` (the
/// Jython's jsonEncode string — the route returns it as
/// `data.result`), both gated on the secret header.
async fn mount_exec_round(server: &wiremock::MockServer, payload: &str) {
    wiremock::Mock::given(wiremock::matchers::method("POST"))
        .and(wiremock::matchers::path(ROUTE_PATH))
        .and(wiremock::matchers::body_json(
            serde_json::json!({"action": "version"}),
        ))
        .and(wiremock::matchers::header(
            "x-ignition-cli-secret",
            "cafebabe1234",
        ))
        .respond_with(
            wiremock::ResponseTemplate::new(200).set_body_json(serde_json::json!({
                "ok": true,
                "data": {"routeVersion": "1.3.0", "minCli": "1.0"},
            })),
        )
        .expect(1)
        .mount(server)
        .await;
    wiremock::Mock::given(wiremock::matchers::method("POST"))
        .and(wiremock::matchers::path(ROUTE_PATH))
        .and(wiremock::matchers::body_string_contains(
            "\"action\":\"exec\"",
        ))
        .and(wiremock::matchers::header(
            "x-ignition-cli-secret",
            "cafebabe1234",
        ))
        .respond_with(
            wiremock::ResponseTemplate::new(200).set_body_json(serde_json::json!({
                "ok": true,
                "data": {"stdout": "", "result": payload, "elapsedMs": 12},
            })),
        )
        .expect(1)
        .mount(server)
        .await;
}

/// The sample payload the mock route returns (the Jython's
/// jsonEncode output — a JSON STRING riding `data.result`).
const SAMPLE_PAYLOAD: &str = r#"{"samples":100,"threadPeak":42,"observations":100,"wallMs":5012,"hot":[{"frame":"com.foo.Bar.baz","count":61},{"frame":"java.net.SocketInputStream.socketRead0","count":20}],"stacks":[{"stack":"java.lang.Thread.run;com.foo.Bar.baz","count":61}],"folded":"java.lang.Thread.run;com.foo.Bar.baz 61"}"#;

// ── Gate 1: no flag → refusal, ZERO HTTP ────────────────────────────

/// THE special-mode gate at the binary level: `ign jvm sample`
/// WITHOUT `--i-accept-the-risk` refuses exit 2
/// `profiling_risk_not_accepted` — BEFORE any HTTP (the gate
/// precedes even the secret handshake), with the hint stating that
/// --yes cannot satisfy it.
#[tokio::test]
async fn sample_without_risk_flag_refuses_zero_http() {
    let server = wiremock::MockServer::start().await;
    let (_config_dir, config) = isolated_config();
    write_profile_config(&config, &server.uri());
    let out = ign(&config, &server.uri(), &["jvm", "sample", "--compact"]);
    assert_eq!(out.status.code(), Some(2), "usage class");
    assert!(out.stdout.is_empty(), "errors never touch stdout");
    let body: serde_json::Value =
        serde_json::from_str(&stderr_envelope(&out)).expect("error envelope parses");
    assert_eq!(
        body["error"]["code"],
        serde_json::Value::String("profiling_risk_not_accepted".into())
    );
    let hint = body["error"]["hint"].as_str().expect("hint rides");
    assert!(
        hint.contains("--i-accept-the-risk"),
        "the hint names the flag: {hint}"
    );
    assert!(
        hint.contains("--yes deliberately does NOT"),
        "the hint states the --yes non-equivalence: {hint}"
    );
    assert!(
        server
            .received_requests()
            .await
            .expect("received requests")
            .is_empty(),
        "the refusal performs ZERO HTTP requests"
    );
}

/// Gate 2 — THE ANTI-BYPASS PIN: the global `--yes` does NOT satisfy
/// the risk gate. A generic destructive-ops blanket must never cover
/// ACTIVE JVM instrumentation.
#[tokio::test]
async fn sample_yes_flag_does_not_satisfy_the_gate() {
    let server = wiremock::MockServer::start().await;
    let (_config_dir, config) = isolated_config();
    write_profile_config(&config, &server.uri());
    let out = ign(
        &config,
        &server.uri(),
        &["jvm", "sample", "--yes", "--compact"],
    );
    assert_eq!(out.status.code(), Some(2), "still the usage class");
    let body: serde_json::Value =
        serde_json::from_str(&stderr_envelope(&out)).expect("error envelope parses");
    assert_eq!(
        body["error"]["code"],
        serde_json::Value::String("profiling_risk_not_accepted".into()),
        "--yes never satisfies the profiling gate"
    );
    assert!(
        server
            .received_requests()
            .await
            .expect("received requests")
            .is_empty(),
        "still ZERO HTTP requests"
    );
}

/// `ign jvm jfr start` carries the same gate (the other intrusive verb).
#[tokio::test]
async fn jfr_start_without_risk_flag_refuses() {
    let server = wiremock::MockServer::start().await;
    let (_config_dir, config) = isolated_config();
    write_profile_config(&config, &server.uri());
    let out = ign(
        &config,
        &server.uri(),
        &["jvm", "jfr", "start", "--compact"],
    );
    assert_eq!(out.status.code(), Some(2));
    let body: serde_json::Value =
        serde_json::from_str(&stderr_envelope(&out)).expect("error envelope parses");
    assert_eq!(
        body["error"]["code"],
        serde_json::Value::String("profiling_risk_not_accepted".into())
    );
    assert!(
        server
            .received_requests()
            .await
            .expect("received requests")
            .is_empty(),
        "ZERO HTTP requests"
    );
}

// ── Gate 3: the caps refuse (never clamp), usage leads ─────────────

/// An over-cap duration refuses `invalid_input` (exit 2, profile
/// NULL) BEFORE profile resolution — no config file exists and no
/// server is reachable, so any resolution work would fail differently.
#[test]
fn sample_above_the_hard_cap_refuses_invalid_input_profile_null() {
    let (_config_dir, config) = isolated_config();
    let out = ign(
        &config,
        "http://127.0.0.1:1",
        &[
            "jvm",
            "sample",
            "--duration-secs",
            "600",
            "--i-accept-the-risk",
            "--compact",
        ],
    );
    assert_eq!(out.status.code(), Some(2), "usage class");
    assert!(out.stdout.is_empty(), "errors never touch stdout");
    let body: serde_json::Value =
        serde_json::from_str(&stderr_envelope(&out)).expect("error envelope parses");
    assert_eq!(body["profile"], serde_json::Value::Null, "usage leads");
    assert_eq!(
        body["error"]["code"],
        serde_json::Value::String("invalid_input".into())
    );
    let message = body["error"]["message"].as_str().expect("message");
    assert!(
        message.contains("600s") && message.contains("120s"),
        "the refusal names the ask AND the cap: {message}"
    );
}

/// The JFR cap refuses the same way.
#[test]
fn jfr_start_above_the_hard_cap_refuses_invalid_input() {
    let (_config_dir, config) = isolated_config();
    let out = ign(
        &config,
        "http://127.0.0.1:1",
        &[
            "jvm",
            "jfr",
            "start",
            "--duration-secs",
            "999",
            "--i-accept-the-risk",
            "--compact",
        ],
    );
    assert_eq!(out.status.code(), Some(2));
    let body: serde_json::Value =
        serde_json::from_str(&stderr_envelope(&out)).expect("error envelope parses");
    assert_eq!(body["profile"], serde_json::Value::Null);
    assert_eq!(
        body["error"]["code"],
        serde_json::Value::String("invalid_input".into())
    );
    assert!(
        body["error"]["message"]
            .as_str()
            .expect("message")
            .contains("300s"),
        "names the JFR cap"
    );
}

/// `--follow` + `--folded-out` refuse together — the sidecar writes
/// ONE window's stacks; in continuous mode each window would
/// overwrite it. Exit 2 `invalid_input`, profile null, BEFORE any
/// resolution (no config, no reachable server).
#[test]
fn sample_follow_and_folded_out_refuse_together() {
    let (_config_dir, config) = isolated_config();
    let out = ign(
        &config,
        "http://127.0.0.1:1",
        &[
            "jvm",
            "sample",
            "--follow",
            "--folded-out",
            "profile.folded",
            "--i-accept-the-risk",
            "--compact",
        ],
    );
    assert_eq!(out.status.code(), Some(2), "usage class");
    assert!(out.stdout.is_empty(), "errors never touch stdout");
    let body: serde_json::Value =
        serde_json::from_str(&stderr_envelope(&out)).expect("error envelope parses");
    assert_eq!(body["profile"], serde_json::Value::Null, "usage leads");
    assert_eq!(
        body["error"]["code"],
        serde_json::Value::String("invalid_input".into())
    );
    let message = body["error"]["message"].as_str().expect("message");
    assert!(
        message.contains("--folded-out") && message.contains("--follow"),
        "the reason names both flags: {message}"
    );
}

// ── Success paths ───────────────────────────────────────────────────

/// `ign jvm sample` success COMPACT JSON golden: `warning` leads the
/// data (the production caution rides every envelope), the rollup
/// fields follow in declaration order — `[..]` elides the dynamic
/// elapsedMs.
#[tokio::test]
async fn sample_success_compact_json_golden() {
    let server = wiremock::MockServer::start().await;
    mount_exec_round(&server, SAMPLE_PAYLOAD).await;
    let (_config_dir, config) = isolated_config();
    write_profile_config(&config, &server.uri());
    let out = ign(
        &config,
        &server.uri(),
        &["jvm", "sample", "--i-accept-the-risk", "--compact"],
    );
    assert_eq!(
        out.status.code(),
        Some(0),
        "stderr: {}",
        String::from_utf8_lossy(&out.stderr)
    );
    snapbox::Assert::new().action_env("SNAPSHOTS").eq(
        stdout_for_golden(&out),
        snapbox::str![[
            r#"{"ok":true,"profile":"dev","data":{"warning":"JVM PROFILING ACTIVELY INSTRUMENTS THE GATEWAY: sampling adds CPU overhead proportional to thread count x frequency; flight recordings buffer in JVM memory and dump to gateway disk. NEVER use this on a production server outside an approved change window with a rollback plan — and always use the shortest duration that answers the question.","duration_secs":30,"interval_ms":20,"samples":100,"thread_peak":42,"observations":100,"wall_ms":5012,"hot_methods":[{"frame":"com.foo.Bar.baz","count":61,"pct":61.0},{"frame":"java.net.SocketInputStream.socketRead0","count":20,"pct":20.0}],"top_stacks":[{"stack":"java.lang.Thread.run;com.foo.Bar.baz","count":61,"pct":61.0}],"folded":"java.lang.Thread.run;com.foo.Bar.baz 61","elapsedMs":[..]}}"#
        ]],
    );
}

/// The success HUMAN golden: the report on stdout, the banner on
/// STDERR (the pipe never swallows the caution).
#[tokio::test]
async fn sample_success_human_golden_and_stderr_banner() {
    let server = wiremock::MockServer::start().await;
    mount_exec_round(&server, SAMPLE_PAYLOAD).await;
    let (_config_dir, config) = isolated_config();
    write_profile_config(&config, &server.uri());
    let out = ign(
        &config,
        &server.uri(),
        &["jvm", "sample", "--i-accept-the-risk"],
    );
    assert_eq!(
        out.status.code(),
        Some(0),
        "stderr: {}",
        String::from_utf8_lossy(&out.stderr)
    );
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(
        stderr.contains("JVM PROFILING — ACTIVE GATEWAY INSTRUMENTATION"),
        "the stderr banner rides the human render: {stderr}"
    );
    assert!(
        stderr.contains("production"),
        "the banner carries the production caution: {stderr}"
    );
    snapbox::Assert::new().action_env("SNAPSHOTS").eq(
        stdout_for_golden(&out),
        snapbox::str![[r#"
[profile: dev]
sampled 100 times over a 30s window (wall 5012 ms — the 20ms interval rides on dump cost; 100 thread stacks observed, peak 42 live)

hot methods (self):
   61.0%      61  com.foo.Bar.baz
   20.0%      20  java.net.SocketInputStream.socketRead0

heaviest stacks:
   61.0%      61  java.lang.Thread.run;com.foo.Bar.baz"#]],
    );
}

/// The folded sidecar: `--folded-out` writes the flamegraph input
/// byte-exactly.
#[tokio::test]
async fn sample_folded_out_writes_the_sidecar() {
    let server = wiremock::MockServer::start().await;
    mount_exec_round(&server, SAMPLE_PAYLOAD).await;
    let (_config_dir, config) = isolated_config();
    write_profile_config(&config, &server.uri());
    let out_dir = tempfile::tempdir().expect("tempdir");
    let folded = out_dir.path().join("profile.folded");
    let out = ign(
        &config,
        &server.uri(),
        &[
            "jvm",
            "sample",
            "--i-accept-the-risk",
            "--folded-out",
            folded.to_str().expect("utf-8 path"),
            "--compact",
        ],
    );
    assert_eq!(
        out.status.code(),
        Some(0),
        "stderr: {}",
        String::from_utf8_lossy(&out.stderr)
    );
    assert_eq!(
        std::fs::read_to_string(&folded).expect("sidecar written"),
        "java.lang.Thread.run;com.foo.Bar.baz 61"
    );
}

/// Gate 4: `ign jvm jfr status` is UNGATED — no flag, straight to
/// the gateway (checking is how you confirm cleanup).
#[tokio::test]
async fn jfr_status_is_ungated_human_golden() {
    let server = wiremock::MockServer::start().await;
    mount_exec_round(
        &server,
        r#"{"recordings":"Recording 1: name=ign-cli duration=60s (running)","active":true}"#,
    )
    .await;
    let (_config_dir, config) = isolated_config();
    write_profile_config(&config, &server.uri());
    let out = ign(&config, &server.uri(), &["jvm", "jfr", "status"]);
    assert_eq!(
        out.status.code(),
        Some(0),
        "stderr: {}",
        String::from_utf8_lossy(&out.stderr)
    );
    snapbox::Assert::new().action_env("SNAPSHOTS").eq(
        stdout_for_golden(&out),
        snapbox::str![[r#"
[profile: dev]
ign-cli recording: ACTIVE
recordings (jfrCheck verbatim):
  Recording 1: name=ign-cli duration=60s (running)"#]],
    );
}

/// `ign jvm jfr start` success: the recording's terms + the cleanup
/// path named.
#[tokio::test]
async fn jfr_start_success_human_golden() {
    let server = wiremock::MockServer::start().await;
    mount_exec_round(
        &server,
        r#"{"output":"Started recording 1.","recordings":"Recording 1: name=ign-cli (running)"}"#,
    )
    .await;
    let (_config_dir, config) = isolated_config();
    write_profile_config(&config, &server.uri());
    let out = ign(
        &config,
        &server.uri(),
        &["jvm", "jfr", "start", "--i-accept-the-risk"],
    );
    assert_eq!(
        out.status.code(),
        Some(0),
        "stderr: {}",
        String::from_utf8_lossy(&out.stderr)
    );
    snapbox::Assert::new().action_env("SNAPSHOTS").eq(
        stdout_for_golden(&out),
        snapbox::str![[r#"
[profile: dev]
started flight recording 'ign-cli' (60s, settings=default) — memory-buffered, auto-stops at the deadline
jfr: Started recording 1.
fetch + clean up with: ign jvm jfr stop   (check: ign jvm jfr status)"#]],
    );
}

/// `ign jvm jfr stop` (UNGATED): the dump streams back base64, lands
/// byte-exact at `-o`, and the remote delete is reported.
#[tokio::test]
async fn jfr_stop_fetches_byte_exact_and_reports_remote_delete() {
    let payload = format!(
        r#"{{"remoteFile":"/tmp/ign-cli-123.jfr","bytes":11,"tooLarge":false,"data":"{}","deleted":true}}"#,
        base64::engine::general_purpose::STANDARD.encode(b"hello jfr!!")
    );
    let server = wiremock::MockServer::start().await;
    mount_exec_round(&server, &payload).await;
    let (_config_dir, config) = isolated_config();
    write_profile_config(&config, &server.uri());
    let out_dir = tempfile::tempdir().expect("tempdir");
    let jfr = out_dir.path().join("capture.jfr");
    let out = ign(
        &config,
        &server.uri(),
        &[
            "jvm",
            "jfr",
            "stop",
            "-o",
            jfr.to_str().expect("utf-8 path"),
        ],
    );
    assert_eq!(
        out.status.code(),
        Some(0),
        "stderr: {}",
        String::from_utf8_lossy(&out.stderr)
    );
    assert_eq!(
        std::fs::read(&jfr).expect("dump written"),
        b"hello jfr!!",
        "the .jfr lands byte-exact"
    );
    let stdout = String::from_utf8_lossy(&out.stdout);
    assert!(
        stdout.contains("stopped flight recording 'ign-cli'"),
        "the stop reports: {stdout}"
    );
    assert!(
        stdout.contains("/tmp/ign-cli-123.jfr: deleted"),
        "the remote delete is reported: {stdout}"
    );
}

/// The over-cap stop: exit 0, `fetched: false`, the dump LEFT IN
/// PLACE with its path reported on stderr — never silently truncated.
#[tokio::test]
async fn jfr_stop_over_cap_leaves_the_dump_in_place() {
    let server = wiremock::MockServer::start().await;
    mount_exec_round(
        &server,
        r#"{"remoteFile":"/tmp/ign-cli-big.jfr","bytes":40000000,"tooLarge":true,"data":null,"deleted":false}"#,
    )
    .await;
    let (_config_dir, config) = isolated_config();
    write_profile_config(&config, &server.uri());
    let out_dir = tempfile::tempdir().expect("tempdir");
    let jfr = out_dir.path().join("capture.jfr");
    let out = ign(
        &config,
        &server.uri(),
        &[
            "jvm",
            "jfr",
            "stop",
            "-o",
            jfr.to_str().expect("utf-8 path"),
            "--compact",
        ],
    );
    assert_eq!(
        out.status.code(),
        Some(0),
        "stderr: {}",
        String::from_utf8_lossy(&out.stderr)
    );
    assert!(!jfr.exists(), "no local file — nothing was fetched");
    let stdout = String::from_utf8_lossy(&out.stdout);
    assert!(
        stdout.contains(r#""fetched":false"#),
        "the envelope says fetched:false: {stdout}"
    );
    assert!(
        stdout.contains("/tmp/ign-cli-big.jfr"),
        "the remote path rides the envelope: {stdout}"
    );
}

/// The structural gate reaches this family too: no persisted secret
/// (the route was never deployed) refuses exit 6
/// `script_exec_not_configured` — WITH the risk flag passed (the
/// deploy opt-in is the outer gate; zero HTTP).
#[tokio::test]
async fn sample_missing_secret_refuses_exit_6_zero_http() {
    let server = wiremock::MockServer::start().await;
    let (_config_dir, config) = isolated_config();
    std::fs::write(
        &config,
        format!(
            "active = \"dev\"\n\n[profiles.dev]\nurl = \"{}\"\n\
             auth = {{ token_env = \"IGNITION_TOKEN\" }}\n",
            server.uri()
        ),
    )
    .expect("write config");
    let out = ign(
        &config,
        &server.uri(),
        &["jvm", "sample", "--i-accept-the-risk", "--compact"],
    );
    assert_eq!(out.status.code(), Some(6), "target state");
    let body: serde_json::Value =
        serde_json::from_str(&stderr_envelope(&out)).expect("error envelope parses");
    assert_eq!(
        body["error"]["code"],
        serde_json::Value::String("script_exec_not_configured".into())
    );
    assert!(
        server
            .received_requests()
            .await
            .expect("received requests")
            .is_empty(),
        "ZERO HTTP requests"
    );
}