MCPcopy Create free account
hub / github.com/base/base / write

Method write

acceptance/src/report.rs:208–232  ·  view source on GitHub ↗

Writes the portable report bundle, leaving an existing evidence directory intact.

(run: &RunResult, directory: &Path)

Source from the content-addressed store, hash-verified

206
207 /// Writes the portable report bundle, leaving an existing evidence directory intact.
208 pub fn write(run: &RunResult, directory: &Path) -> Result<()> {
209 Self::validate(run)?;
210 fs::create_dir_all(directory).wrap_err("create report directory")?;
211 Self::validate_existing_evidence(run, directory)?;
212 for name in ["result.json", "report.html", "summary.md"] {
213 let destination = directory.join(name);
214 if destination
215 .symlink_metadata()
216 .is_ok_and(|metadata| metadata.file_type().is_symlink())
217 {
218 bail!("refusing to overwrite symlink report file {name}");
219 }
220 }
221 let json = serde_json::to_string_pretty(run).wrap_err("serialize result")?;
222 let temporary = directory.join(format!(".result.json.{}.tmp", std::process::id()));
223 if temporary.symlink_metadata().is_ok() {
224 bail!("temporary result path already exists");
225 }
226 fs::write(&temporary, format!("{json}\n")).wrap_err("write temporary result.json")?;
227 fs::rename(&temporary, directory.join("result.json")).wrap_err("commit result.json")?;
228 fs::write(directory.join("report.html"), Self::html(run)?).wrap_err("write report.html")?;
229 fs::write(directory.join("summary.md"), Self::markdown(run)?)
230 .wrap_err("write summary.md")?;
231 Ok(())
232 }
233
234 /// Validates reporting schema, resource bounds, identifiers, and artifact paths.
235 pub fn validate(run: &RunResult) -> Result<()> {

Callers 1

acquire_lockMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected