MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / run

Method run

atomic-cli/src/commands/memory/validate.rs:31–94  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

memory_validateFunction · 0.85
parse_markdownFunction · 0.85
lift_memoryFunction · 0.85
find_repository_rootFunction · 0.85
open_readonly_repositoryFunction · 0.85
read_memoryFunction · 0.85
validate_memoryFunction · 0.85
is_path_shapedFunction · 0.70
load_attestationFunction · 0.70
liftFunction · 0.70
validation_failedFunction · 0.70
is_fileMethod · 0.45

Tested by

no test coverage detected