ironflow-cli 0.1.60

CLI tool to drive the Ironflow workflow engine
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
//! Anti-drift test: every API route must be reachable from the CLI.
//!
//! The CLI once lagged four whole domains behind the API (secrets, API keys,
//! users, audit logs). This test makes that impossible to repeat silently:
//! adding a route to `openapi.json` without either a CLI command or a written
//! exemption fails the build.
//!
//! The mapping is not taken at face value. Every `Coverage::Command` entry is
//! fed to the real clap parser, so a route cannot be declared covered by a
//! command that does not exist.

use std::collections::BTreeSet;
use std::sync::LazyLock;

use clap::Parser;
use serde_json::{Value, from_str};

use ironflow_cli::cli::Cli;

/// The spec the SDK is generated from, and therefore the CLI's ground truth.
const OPENAPI: &str = include_str!("../../ironflow-sdk/openapi.json");

/// How a route is reachable -- or why it deliberately is not.
#[derive(Debug, Clone, Copy)]
enum Coverage {
    /// A full argument vector that must parse, proving the command exists.
    Command(&'static [&'static str]),
    /// A route with no CLI counterpart, and the reason why.
    Exempt(&'static str),
}

const UUID: &str = "01234567-89ab-cdef-0123-456789abcdef";

/// Every route of the spec, mapped to the command that drives it.
///
/// Adding a route to the API without touching this table fails
/// [`every_api_route_is_reachable_from_the_cli`].
const COVERAGE: &[(&str, &str, Coverage)] = &[
    // ── Runs ──
    ("GET", "/api/v1/runs", Coverage::Command(&["run", "list"])),
    (
        "POST",
        "/api/v1/runs",
        Coverage::Command(&["run", "create", "deploy"]),
    ),
    (
        "GET",
        "/api/v1/runs/{id}",
        Coverage::Command(&["run", "get", UUID]),
    ),
    (
        "GET",
        "/api/v1/runs/{id}/logs",
        Coverage::Command(&["logs", UUID]),
    ),
    (
        "POST",
        "/api/v1/runs/{id}/cancel",
        Coverage::Command(&["run", "cancel", UUID]),
    ),
    (
        "POST",
        "/api/v1/runs/{id}/pause",
        Coverage::Command(&["run", "pause", UUID]),
    ),
    (
        "POST",
        "/api/v1/runs/{id}/resume",
        Coverage::Command(&["run", "resume", UUID]),
    ),
    (
        "POST",
        "/api/v1/runs/{id}/approve",
        Coverage::Command(&["run", "approve", UUID]),
    ),
    (
        "POST",
        "/api/v1/runs/{id}/reject",
        Coverage::Command(&["run", "reject", UUID]),
    ),
    (
        "POST",
        "/api/v1/runs/{id}/steps/{step_id}/input",
        Coverage::Command(&["run", "input", UUID, UUID, "--value", "{}"]),
    ),
    (
        "POST",
        "/api/v1/runs/{id}/steps/{step_id}/reject",
        Coverage::Command(&["run", "reject-input", UUID, UUID]),
    ),
    (
        "POST",
        "/api/v1/runs/{id}/retry",
        Coverage::Command(&["run", "retry", UUID]),
    ),
    (
        "POST",
        "/api/v1/runs/{id}/replay",
        Coverage::Command(&["run", "replay", UUID]),
    ),
    (
        "GET",
        "/api/v1/runs/{id}/events",
        Coverage::Exempt("SSE stream; long-lived connection unsuitable for a CLI command"),
    ),
    // ── Workflows ──
    (
        "GET",
        "/api/v1/workflows",
        Coverage::Command(&["workflow", "list"]),
    ),
    (
        "GET",
        "/api/v1/workflows/{name}",
        Coverage::Command(&["workflow", "get", "deploy"]),
    ),
    (
        "POST",
        "/api/v1/workflows/{name}/plan",
        Coverage::Command(&["run", "plan", "deploy"]),
    ),
    (
        "POST",
        "/api/v1/workflows/{name}/pause",
        Coverage::Command(&["workflow", "pause", "deploy"]),
    ),
    (
        "POST",
        "/api/v1/workflows/{name}/resume",
        Coverage::Command(&["workflow", "resume", "deploy"]),
    ),
    // ── Stats ──
    ("GET", "/api/v1/stats", Coverage::Command(&["stats"])),
    (
        "GET",
        "/api/v1/stats/history",
        Coverage::Command(&["stats", "history"]),
    ),
    // ── Secrets ──
    (
        "GET",
        "/api/v1/secrets",
        Coverage::Command(&["secret", "list"]),
    ),
    (
        "POST",
        "/api/v1/secrets",
        Coverage::Command(&["secret", "set", "db/password", "value"]),
    ),
    (
        "PUT",
        "/api/v1/secrets/{key}",
        Coverage::Command(&["secret", "update", "db/password", "value"]),
    ),
    (
        "DELETE",
        "/api/v1/secrets/{key}",
        Coverage::Command(&["secret", "delete", "db/password", "--yes"]),
    ),
    (
        "POST",
        "/api/v1/secrets/rotate",
        Coverage::Command(&["secret", "rotate"]),
    ),
    (
        "GET",
        "/api/v1/secrets/key-versions",
        Coverage::Command(&["secret", "key-status"]),
    ),
    // -- Provider Accounts --
    (
        "GET",
        "/api/v1/provider-accounts",
        Coverage::Command(&["accounts", "list"]),
    ),
    (
        "POST",
        "/api/v1/provider-accounts",
        Coverage::Command(&["accounts", "add", "perso", "--token-stdin"]),
    ),
    (
        "GET",
        "/api/v1/provider-accounts/kinds",
        Coverage::Exempt("form metadata for the dashboard add flow"),
    ),
    (
        "GET",
        "/api/v1/provider-accounts/{id}",
        Coverage::Command(&["accounts", "show", "perso"]),
    ),
    (
        "PATCH",
        "/api/v1/provider-accounts/{id}",
        Coverage::Command(&["accounts", "update", "perso", "--disable"]),
    ),
    (
        "DELETE",
        "/api/v1/provider-accounts/{id}",
        Coverage::Command(&["accounts", "remove", "perso", "--yes"]),
    ),
    (
        "POST",
        "/api/v1/provider-accounts/{id}/test",
        Coverage::Command(&["accounts", "test", "perso"]),
    ),
    (
        "GET",
        "/api/v1/provider-accounts/{id}/usage",
        Coverage::Command(&["accounts", "usage", "perso"]),
    ),
    // ── API keys ──
    (
        "GET",
        "/api/v1/api-keys",
        Coverage::Command(&["api-key", "list"]),
    ),
    (
        "POST",
        "/api/v1/api-keys",
        Coverage::Command(&["api-key", "create", "ci", "--scope", "runs_read"]),
    ),
    (
        "GET",
        "/api/v1/api-keys/scopes",
        Coverage::Command(&["api-key", "scopes"]),
    ),
    (
        "DELETE",
        "/api/v1/api-keys/{id}",
        Coverage::Command(&["api-key", "delete", UUID, "--yes"]),
    ),
    // ── Users ──
    ("GET", "/api/v1/users", Coverage::Command(&["user", "list"])),
    (
        "POST",
        "/api/v1/users",
        Coverage::Command(&[
            "user",
            "create",
            "alice",
            "--email",
            "alice@example.com",
            "--password",
            "hunter2hunter2",
        ]),
    ),
    (
        "DELETE",
        "/api/v1/users/{id}",
        Coverage::Command(&["user", "delete", UUID, "--yes"]),
    ),
    (
        "PATCH",
        "/api/v1/users/{id}/role",
        Coverage::Command(&["user", "set-role", UUID, "--admin"]),
    ),
    (
        "GET",
        "/api/v1/users/{id}/groups",
        Coverage::Command(&["user", "groups", UUID]),
    ),
    (
        "PUT",
        "/api/v1/users/{id}/groups",
        Coverage::Command(&["user", "set-groups", UUID, "--group", "finance"]),
    ),
    // ── Audit logs ──
    (
        "GET",
        "/api/v1/audit-logs",
        Coverage::Command(&["audit-log", "list"]),
    ),
    // ── Schedules ──
    (
        "GET",
        "/api/v1/schedules",
        Coverage::Command(&["schedule", "list"]),
    ),
    (
        "POST",
        "/api/v1/schedules",
        Coverage::Command(&["schedule", "create", "deploy", "0 * * * *"]),
    ),
    (
        "GET",
        "/api/v1/schedules/{id}",
        Coverage::Exempt("detail view not exposed in CLI; `schedule list` shows all"),
    ),
    (
        "DELETE",
        "/api/v1/schedules/{id}",
        Coverage::Command(&["schedule", "delete", UUID, "--yes"]),
    ),
    (
        "POST",
        "/api/v1/schedules/{id}/pause",
        Coverage::Command(&["schedule", "pause", UUID]),
    ),
    (
        "POST",
        "/api/v1/schedules/{id}/resume",
        Coverage::Command(&["schedule", "resume", UUID]),
    ),
    (
        "POST",
        "/api/v1/schedules/{id}/trigger",
        Coverage::Command(&["schedule", "trigger", UUID]),
    ),
    // ── Approval delegations ──
    (
        "GET",
        "/api/v1/approval-delegations",
        Coverage::Command(&["delegation", "list"]),
    ),
    (
        "POST",
        "/api/v1/approval-delegations",
        Coverage::Command(&[
            "delegation",
            "create",
            UUID,
            "--until",
            "2026-12-31T23:59:59Z",
        ]),
    ),
    (
        "DELETE",
        "/api/v1/approval-delegations/{id}",
        Coverage::Command(&["delegation", "delete", UUID, "--yes"]),
    ),
    // ── Signals ──
    (
        "POST",
        "/api/v1/signals",
        Coverage::Command(&["signal", "send", "demo.done", "--key", "k1"]),
    ),
    (
        "GET",
        "/api/v1/signals",
        Coverage::Command(&["signal", "list"]),
    ),
    // ── Deliberately out of the CLI's reach ──
    (
        "GET",
        "/api/v1/health-check",
        Coverage::Exempt("infrastructure probe, not an administration action"),
    ),
    (
        "POST",
        "/api/v1/auth/sign-in",
        Coverage::Exempt("the CLI authenticates with an API key, not a browser session"),
    ),
    (
        "POST",
        "/api/v1/auth/sign-out",
        Coverage::Exempt("session-only; there is no CLI session to end"),
    ),
    (
        "POST",
        "/api/v1/auth/refresh",
        Coverage::Exempt("session-only; API keys do not expire mid-command"),
    ),
    (
        "POST",
        "/api/v1/auth/sign-up",
        Coverage::Exempt(
            "public self-registration belongs to the dashboard; `user create` is the CLI path",
        ),
    ),
    (
        "GET",
        "/api/v1/auth/me",
        Coverage::Exempt("introspects the caller's session, which the CLI does not hold"),
    ),
    (
        "PATCH",
        "/api/v1/auth/password",
        Coverage::Exempt("password change is session-based; the CLI uses API keys"),
    ),
    (
        "GET",
        "/api/v1/runs/{id}/steps/{step_id}/artifacts/{name}",
        Coverage::Exempt(
            "streams a raw file body, which the JSON-shaped SDK client cannot surface; \
             `run get` already lists the artifacts and their sizes",
        ),
    ),
];

/// Routes of the spec, parsed once for the whole test binary.
static SPEC_ROUTES: LazyLock<BTreeSet<(String, String)>> = LazyLock::new(spec_routes);

/// Routes declared by [`COVERAGE`], collected once for the whole test binary.
static DECLARED_ROUTES: LazyLock<BTreeSet<(String, String)>> = LazyLock::new(declared_routes);

/// Collect `(METHOD, path)` for every operation in the spec.
fn spec_routes() -> BTreeSet<(String, String)> {
    let spec: Value = from_str(OPENAPI).expect("openapi.json must be valid JSON");
    let paths = spec["paths"]
        .as_object()
        .expect("openapi.json must have a paths object");

    let mut routes = BTreeSet::new();
    for (path, operations) in paths {
        let operations = operations
            .as_object()
            .expect("each path must map to an object of operations");
        for method in operations.keys() {
            let upper = method.to_ascii_uppercase();
            if matches!(upper.as_str(), "GET" | "POST" | "PUT" | "PATCH" | "DELETE") {
                routes.insert((upper, path.clone()));
            }
        }
    }
    routes
}

/// Collect `(METHOD, path)` for every entry of [`COVERAGE`].
fn declared_routes() -> BTreeSet<(String, String)> {
    COVERAGE
        .iter()
        .map(|(method, path, _)| ((*method).to_string(), (*path).to_string()))
        .collect()
}

#[test]
fn every_api_route_is_reachable_from_the_cli() {
    let missing: Vec<_> = SPEC_ROUTES.difference(&DECLARED_ROUTES).cloned().collect();

    assert!(
        missing.is_empty(),
        "these API routes have no CLI command and no exemption: {missing:?}\n\
         add a command in ironflow-cli/src/commands/, then declare it in \
         tests/route_coverage.rs (or add a Coverage::Exempt with a reason)"
    );
}

#[test]
fn the_coverage_table_has_no_dead_entries() {
    let stale: Vec<_> = DECLARED_ROUTES.difference(&SPEC_ROUTES).cloned().collect();

    assert!(
        stale.is_empty(),
        "these entries of COVERAGE no longer match any API route: {stale:?}\n\
         remove them from tests/route_coverage.rs"
    );
}

#[test]
fn every_declared_command_really_parses() {
    for (method, path, coverage) in COVERAGE {
        let Coverage::Command(args) = coverage else {
            continue;
        };

        let mut argv = vec!["ironflow-cli"];
        argv.extend_from_slice(args);

        let parsed = Cli::try_parse_from(&argv);
        assert!(
            parsed.is_ok(),
            "{method} {path} claims to be covered by `{}`, which does not parse: {}",
            args.join(" "),
            parsed.unwrap_err()
        );
    }
}

#[test]
fn every_exemption_states_a_reason() {
    for (method, path, coverage) in COVERAGE {
        if let Coverage::Exempt(reason) = coverage {
            assert!(
                reason.len() > 20,
                "{method} {path} is exempt with a reason too vague to review: {reason:?}"
            );
        }
    }
}

#[test]
fn the_coverage_table_has_no_duplicate_routes() {
    assert_eq!(
        DECLARED_ROUTES.len(),
        COVERAGE.len(),
        "COVERAGE lists the same route twice"
    );
}