(&self)
| 29 | |
| 30 | impl Command for MemoryValidate { |
| 31 | fn run(&self) -> CliResult<()> { |
| 32 | // A path-shaped argument (ends in `.md` or contains a separator) is |
| 33 | // loaded as a file; a missing file is reported as FileNotFound rather |
| 34 | // than misreported as a bad id. Otherwise it is a memory id read |
| 35 | // through the vault bridge; a FRESH attestation gates the attested node |
| 36 | // (so a previously-attested memory reports conforms), a STALE one warns |
| 37 | // and falls back to the raw node. |
| 38 | let node = if is_path_shaped(&self.id_or_path) { |
| 39 | let path = Path::new(&self.id_or_path); |
| 40 | if !path.is_file() { |
| 41 | return Err(CliError::FileNotFound { |
| 42 | path: path.to_path_buf(), |
| 43 | }); |
| 44 | } |
| 45 | let doc = std::fs::read_to_string(path).map_err(CliError::Io)?; |
| 46 | let (fm, body) = parse_markdown(&doc).map_err(|e| CliError::InvalidArgument { |
| 47 | message: format!("could not parse markdown frontmatter: {e}"), |
| 48 | })?; |
| 49 | lift_memory(&fm, &body).map_err(|e| CliError::InvalidArgument { |
| 50 | message: format!("could not lift memory: {e}"), |
| 51 | })? |
| 52 | } else { |
| 53 | let root = find_repository_root()?; |
| 54 | let repo = Repository::open(&root).map_err(CliError::Repository)?; |
| 55 | let inputs = bridge::read_memory(&repo, &self.id_or_path)?; |
| 56 | match bridge::load_attestation(&repo, &self.id_or_path, &inputs)? { |
| 57 | bridge::Attestation::Fresh(node) => *node, |
| 58 | bridge::Attestation::Stale(_) => { |
| 59 | eprintln!( |
| 60 | "warning: the attestation for {} is stale (the memory changed since it \ |
| 61 | was signed); re-run `atomic memory attest {}`.", |
| 62 | self.id_or_path, self.id_or_path |
| 63 | ); |
| 64 | bridge::lift(&inputs)? |
| 65 | } |
| 66 | bridge::Attestation::None => bridge::lift(&inputs)?, |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | let report = validate_memory(&node); |
| 71 | |
| 72 | if self.json { |
| 73 | println!( |
| 74 | "{}", |
| 75 | serde_json::to_string_pretty(&report_json(&report)).unwrap() |
| 76 | ); |
| 77 | } else { |
| 78 | print!("{report}"); |
| 79 | } |
| 80 | |
| 81 | if report.conforms { |
| 82 | Ok(()) |
| 83 | } else { |
| 84 | Err(validation_failed(format!( |
| 85 | "memory does not conform ({} violation(s))", |
| 86 | report.results.len() |
| 87 | ))) |
| 88 | } |
nothing calls this directly
no test coverage detected