provenance-cli 0.2.3

Command-line interface for Provenance requirements traceability
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
use assert_cmd::Command;
use provenance_macros::verifies;

#[allow(clippy::too_many_lines)]
#[test]
fn cli_creates_and_exports_enriched_sources_and_resolutions() {
    let dir = tempfile::tempdir().unwrap();
    let repo = dir.path().to_string_lossy().to_string();
    let export_path = dir.path().join("export.json");
    let export_path = export_path.to_string_lossy().to_string();

    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "init",
            "--path",
            &repo,
            "--scope",
            "default",
            "--path-prefix",
            ".",
        ])
        .assert()
        .success();
    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "sources",
            "create",
            "--repo",
            &repo,
            "--scope",
            "default",
            "--id",
            "source_sah_2025",
            "--name",
            "Support at Home 2025",
            "--source-type",
            "legislation",
        ])
        .assert()
        .success();
    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "sources",
            "create",
            "--repo",
            &repo,
            "--scope",
            "default",
            "--id",
            "source_sah",
            "--name",
            "Support at Home",
            "--source-type",
            "legislation",
            "--reference",
            "Department guidance",
            "--commit-pin",
            "5e1f2a9c4b6d8e0f1234567890abcdef12345678",
            "--effective-date",
            "1714521600000",
            "--review-date",
            "1717200000000",
            "--supersedes",
            "source_sah_2025",
            "--format",
            "json",
        ])
        .assert()
        .success()
        .stdout(predicates::str::contains(
            r#""effective_date": 1714521600000"#,
        ))
        .stdout(predicates::str::contains(
            r#""commit_pin": "5e1f2a9c4b6d8e0f1234567890abcdef12345678""#,
        ))
        .stdout(predicates::str::contains(r#""supersedes": ["#))
        .stdout(predicates::str::contains(r#""source_sah_2025""#));
    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "requirements",
            "create",
            "--repo",
            &repo,
            "--scope",
            "default",
            "--id",
            "req_sah",
            "--statement",
            "Support at Home shall be traceable",
            "--format",
            "json",
        ])
        .assert()
        .success();
    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "resolutions",
            "create",
            "--repo",
            &repo,
            "--scope",
            "default",
            "--id",
            "res_sah_2025",
            "--title",
            "SAH extraction, revised",
            "--requirement-id",
            "req_sah",
            "--position",
            "Revised extraction",
            "--rationale",
            "Reviewed",
            "--status",
            "draft",
        ])
        .assert()
        .success();
    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "resolutions",
            "create",
            "--repo",
            &repo,
            "--scope",
            "default",
            "--id",
            "res_sah",
            "--title",
            "SAH extraction",
            "--requirement-id",
            "req_sah",
            "--position",
            "Keep as draft extraction",
            "--rationale",
            "Needs human review",
            "--status",
            "draft",
            "--context",
            "Codebase scan",
            "--enforcement",
            "specification",
            "--confidence",
            "0.91",
            "--input-type",
            "regulatory",
            "--input-reference",
            "SAH program manual",
            "--input-summary",
            "Program rules reviewed",
            "--made-by",
            "Analyst One",
            "--approved-by",
            "Approver Two",
            "--approved-at",
            "1714780800000",
            "--supersedes",
            "res_sah_2025",
            "--format",
            "json",
        ])
        .assert()
        .success()
        .stdout(predicates::str::contains(r#""input_type": "regulatory""#))
        .stdout(predicates::str::contains(r#""made_by": "Analyst One""#))
        .stdout(predicates::str::contains(r#""supersedes": ["#))
        .stdout(predicates::str::contains(r#""res_sah_2025""#));

    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "export",
            "--repo",
            &repo,
            "--scope",
            "default",
            "--format",
            "json",
            "--output",
            &export_path,
        ])
        .assert()
        .success();

    let exported = std::fs::read_to_string(export_path).unwrap();
    assert!(exported.contains(r#""commit_pin": "5e1f2a9c4b6d8e0f1234567890abcdef12345678""#));
    assert!(exported.contains(r#""effective_date": 1714521600000"#));
    assert!(exported.contains(r#""review_date": 1717200000000"#));
    assert!(exported.contains(r#""input_type": "regulatory""#));
    assert!(exported.contains(r#""approved_at": 1714780800000"#));
}

#[test]
fn cli_rejects_invalid_source_commit_pin() {
    let dir = tempfile::tempdir().unwrap();
    let repo = dir.path().to_string_lossy().to_string();

    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "init",
            "--path",
            &repo,
            "--scope",
            "default",
            "--path-prefix",
            ".",
        ])
        .assert()
        .success();
    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "sources",
            "create",
            "--repo",
            &repo,
            "--scope",
            "default",
            "--id",
            "source_codebase",
            "--name",
            "Codebase",
            "--source-type",
            "project_artifact",
            "--commit-pin",
            "main",
            "--format",
            "json",
        ])
        .assert()
        .failure()
        .stderr(predicates::str::contains("commit pin must"));
}

/// An input has to name where it came from and say what it told the decision.
/// The create path refuses a blank field rather than storing an input that
/// locates nothing.
#[test]
#[verifies("rule_resolution_input_content", examples)]
fn cli_rejects_a_resolution_input_with_a_blank_reference() {
    let dir = tempfile::tempdir().unwrap();
    let repo = dir.path().to_string_lossy().to_string();
    init_repo(&repo);

    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "requirements",
            "create",
            "--repo",
            &repo,
            "--scope",
            "default",
            "--id",
            "req_sah",
            "--statement",
            "SAH applies",
        ])
        .assert()
        .success();
    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "resolutions",
            "create",
            "--repo",
            &repo,
            "--scope",
            "default",
            "--id",
            "res_sah",
            "--requirement-id",
            "req_sah",
            "--title",
            "SAH extraction",
            "--position",
            "Keep as draft extraction",
            "--rationale",
            "Needs human review",
            "--status",
            "draft",
            "--input-type",
            "regulatory",
            "--input-reference",
            "   ",
            "--input-summary",
            "Program rules reviewed",
            "--format",
            "json",
        ])
        .assert()
        .failure()
        .stderr(predicates::str::contains(
            "resolution input reference must not be blank",
        ));
}

/// The same refusal on the way in from a file. An export edited to blank an
/// input summary does not import, so the hole cannot be walked around by
/// writing JSON instead of running `resolutions create`.
#[test]
#[verifies("rule_resolution_input_content", examples)]
fn cli_rejects_an_imported_resolution_input_with_a_blank_summary() {
    let dir = tempfile::tempdir().unwrap();
    let repo = dir.path().to_string_lossy().to_string();
    let export_path = dir.path().join("export.json");
    init_repo(&repo);

    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "requirements",
            "create",
            "--repo",
            &repo,
            "--scope",
            "default",
            "--id",
            "req_sah",
            "--statement",
            "SAH applies",
        ])
        .assert()
        .success();
    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "resolutions",
            "create",
            "--repo",
            &repo,
            "--scope",
            "default",
            "--id",
            "res_sah",
            "--requirement-id",
            "req_sah",
            "--title",
            "SAH extraction",
            "--position",
            "Keep as draft extraction",
            "--rationale",
            "Needs human review",
            "--status",
            "draft",
            "--input-type",
            "regulatory",
            "--input-reference",
            "SAH program manual",
            "--input-summary",
            "Program rules reviewed",
            "--format",
            "json",
        ])
        .assert()
        .success();
    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "export",
            "--repo",
            &repo,
            "--scope",
            "default",
            "--format",
            "json",
            "--output",
            export_path.to_str().unwrap(),
        ])
        .assert()
        .success();

    let mut exported: serde_json::Value =
        serde_json::from_slice(&std::fs::read(&export_path).unwrap()).unwrap();
    exported["resolutions"][0]["inputs"][0]["summary"] = serde_json::json!("");
    std::fs::write(&export_path, serde_json::to_vec(&exported).unwrap()).unwrap();

    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "import",
            "--repo",
            &repo,
            "--scope",
            "default",
            "--input",
            export_path.to_str().unwrap(),
        ])
        .assert()
        .failure()
        .stderr(predicates::str::contains(
            "resolution input summary must not be blank",
        ));
}

fn init_repo(repo: &str) {
    Command::cargo_bin("provenance")
        .unwrap()
        .args([
            "init",
            "--path",
            repo,
            "--scope",
            "default",
            "--path-prefix",
            ".",
        ])
        .assert()
        .success();
}