Skip to content

Commit 1a03fa4

Browse files
committed
Added spot artificer
1 parent 1a98972 commit 1a03fa4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/src/assert/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,29 @@ pub fn assert_impl(
406406
id: String,
407407
details: &Value,
408408
) {
409+
// Spot artificer
410+
let spot_artifact = || -> Option<Value> {
411+
if hit && !condition {
412+
let mut details = details.as_object()?.clone();
413+
let artifact_path = details.get("artifact_path")?.as_str()?;
414+
let artifact_dir = std::env::var(crate::internal::ARTIFICER_DIR).ok()?;
415+
let nonce = format!("{:016x}", crate::random::get_random());
416+
let mut artificer = std::fs::OpenOptions::new()
417+
.write(true)
418+
.append(true)
419+
.create(true)
420+
.open(std::path::Path::new(&artifact_dir).join(&nonce)).ok()?;
421+
use std::io::Write;
422+
writeln!(artificer, "{artifact_path}").ok()?;
423+
details.insert("artifact_id".to_owned(), Value::String(nonce));
424+
Some(Value::Object(details))
425+
} else {
426+
None
427+
}
428+
};
429+
let new_details = spot_artifact();
430+
let details = new_details.as_ref().unwrap_or(details);
431+
409432
let assertion = AssertionInfo::new(
410433
assert_type,
411434
display_type,

lib/src/internal/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const SDK_VERSION: &str = env!("CARGO_PKG_VERSION");
5151

5252
pub const LOCAL_OUTPUT: &str = "ANTITHESIS_SDK_LOCAL_OUTPUT";
5353

54+
pub const ARTIFICER_DIR: &str = "ANTITHESIS_ARTIFICER_DIR";
55+
5456
#[cfg(feature = "full")]
5557
fn get_handler() -> Box<dyn LibHandler + Sync + Send> {
5658
match VoidstarHandler::try_load() {

0 commit comments

Comments
 (0)