|
1 | 1 | use assert_cmd::Command; |
2 | 2 | use predicates::str::contains; |
| 3 | +use serde_json::Value; |
3 | 4 | use std::fs; |
4 | 5 |
|
5 | 6 | #[test] |
@@ -136,6 +137,32 @@ fn review_pack_outputs_json() { |
136 | 137 | .stdout(contains("\"tx-psbt-counts-match\"")); |
137 | 138 | } |
138 | 139 |
|
| 140 | +#[test] |
| 141 | +fn review_pack_json_is_parseable_with_stable_schema() { |
| 142 | + let report = json_stdout([ |
| 143 | + "review-pack", |
| 144 | + "--input", |
| 145 | + "tests/fixtures/review-packs/complete", |
| 146 | + "--format", |
| 147 | + "json", |
| 148 | + ]); |
| 149 | + |
| 150 | + assert_eq!(report["schema_version"], "0.4"); |
| 151 | + assert!( |
| 152 | + report |
| 153 | + .get("artifacts_detected") |
| 154 | + .and_then(Value::as_array) |
| 155 | + .expect("artifacts_detected should be an array") |
| 156 | + .len() |
| 157 | + >= 4 |
| 158 | + ); |
| 159 | + assert!(!report |
| 160 | + .get("review_questions") |
| 161 | + .and_then(Value::as_array) |
| 162 | + .expect("review_questions should be an array") |
| 163 | + .is_empty()); |
| 164 | +} |
| 165 | + |
139 | 166 | #[test] |
140 | 167 | fn review_pack_outputs_markdown_file() { |
141 | 168 | let temp_dir = tempfile::tempdir().unwrap(); |
@@ -181,6 +208,36 @@ fn policy_pack_outputs_json() { |
181 | 208 | .stdout(contains("\"descriptor-psbt-multisig-mismatch\"")); |
182 | 209 | } |
183 | 210 |
|
| 211 | +#[test] |
| 212 | +fn policy_pack_json_is_parseable_with_stable_schema() { |
| 213 | + let report = json_stdout([ |
| 214 | + "policy-pack", |
| 215 | + "--input", |
| 216 | + "tests/fixtures/policy-packs/multisig-timelock", |
| 217 | + "--format", |
| 218 | + "json", |
| 219 | + ]); |
| 220 | + |
| 221 | + assert_eq!(report["schema_version"], "0.5"); |
| 222 | + assert_eq!(report["pack_type"], "policy_pack"); |
| 223 | + assert!(!report |
| 224 | + .get("evidence_documents") |
| 225 | + .and_then(Value::as_array) |
| 226 | + .expect("evidence_documents should be an array") |
| 227 | + .is_empty()); |
| 228 | + assert!(!report |
| 229 | + .get("missing_evidence") |
| 230 | + .and_then(Value::as_array) |
| 231 | + .expect("missing_evidence should be an array") |
| 232 | + .is_empty()); |
| 233 | +} |
| 234 | + |
| 235 | +fn json_stdout<const N: usize>(args: [&str; N]) -> Value { |
| 236 | + let mut cmd = Command::cargo_bin("btc-risk-lab").unwrap(); |
| 237 | + let assert = cmd.args(args).assert().success(); |
| 238 | + serde_json::from_slice(&assert.get_output().stdout).expect("stdout should be valid JSON") |
| 239 | +} |
| 240 | + |
184 | 241 | #[test] |
185 | 242 | fn policy_pack_outputs_markdown_file() { |
186 | 243 | let temp_dir = tempfile::tempdir().unwrap(); |
|
0 commit comments