artifactize-core 0.27.2

The library behind artifactize: Artifacts, evals, reviews, the monitor and review models, and the shared operations every interface calls.
Documentation
use super::*;
use serde_json::json;
#[test]
fn stored_payloads_preserve_schema_5_missing_null_and_owner_context() {
    for (value, instruction) in [
        (json!({}), ""),
        (json!({"instruction":null,"owner":[true,null,42]}), ""),
        (
            json!({"instruction":"Inspect {input}.","owner":{"nested":[]}}),
            "Inspect {input}.",
        ),
    ] {
        let stored: StoredPayload = serde_json::from_value(value.clone()).unwrap();
        assert_eq!(serde_json::to_value(&stored).unwrap(), value);
        assert_eq!(stored.instruction(), instruction);
        if value["instruction"].is_null() {
            assert!(serde_json::from_value::<super::super::EvalPayload>(value).is_err());
        }
    }
}

#[test]
fn stored_profiles_preserve_missing_and_null_without_weakening_config() {
    for value in [
        json!({"kind":"agent","backend":"openai","model":"fixture"}),
        json!({
            "kind":"agent",
            "backend":"openai",
            "model":"fixture",
            "reasoning":null,
            "timeoutMs":null,
            "maxToolCalls":null,
            "maxTokens":null,
        }),
        json!({"kind":"runtime","command":"fixture","args":[],"timeoutMs":null}),
        json!({"kind":"runtime","command":"fixture","args":[],"timeoutMs":1000}),
        json!({"kind":"human"}),
    ] {
        let stored: StoredProfile = serde_json::from_value(value.clone()).unwrap();
        assert_eq!(serde_json::to_value(&stored).unwrap(), value);
        if value
            .get("timeoutMs")
            .is_some_and(serde_json::Value::is_null)
        {
            let mut declaration = value;
            let object = declaration.as_object_mut().unwrap();
            for (camel, snake) in [
                ("timeoutMs", "timeout_ms"),
                ("maxToolCalls", "max_tool_calls"),
                ("maxTokens", "max_tokens"),
            ] {
                if let Some(value) = object.remove(camel) {
                    object.insert(snake.into(), value);
                }
            }
            // Only the timeout is invalid, so another optional field cannot mask it.
            for field in ["reasoning", "max_tool_calls", "max_tokens"] {
                object.remove(field);
            }
            let error = serde_json::from_value::<Profile>(declaration)
                .unwrap_err()
                .to_string();
            assert!(
                error.contains("null") && !error.contains("unknown field"),
                "{error}"
            );
        }
    }
    let missing: StoredProfile =
        serde_json::from_value(json!({"kind":"runtime","command":"fixture","args":[]})).unwrap();
    let null: StoredProfile = serde_json::from_value(
        json!({"kind":"runtime","command":"fixture","args":[],"timeoutMs":null}),
    )
    .unwrap();
    assert_ne!(missing, null);
    let config: Profile =
        serde_json::from_value(json!({"kind":"agent","backend":"openai","model":"fixture"}))
            .unwrap();
    assert_eq!(
        serde_json::to_value(StoredProfile::from(&config)).unwrap(),
        json!({
            "kind":"agent",
            "backend":"openai",
            "model":"fixture",
            "reasoning":null,
            "timeoutMs":null,
            "maxToolCalls":null,
            "maxTokens":null,
        })
    );
}