ortho_config 0.9.0

A configuration management library for Rust, inspired by esbuild.
Documentation
//! Assertion helpers and expected JSON for agent-context schema tests.

use super::{field, first_array_item};
use crate::agent_context::{
    AGENT_CONTEXT_KIND_SUFFIX, AgentCommand, AgentContext, InteractionMode, MutationEffect,
    ORTHO_AGENT_CONTEXT_SCHEMA_VERSION, PolicyMode,
};
use crate::docs::ORTHO_DOCS_IR_VERSION;
use serde_json::Value;

/// Asserts the schema identity constants and their independence from the
/// documentation IR version.
pub(super) fn assert_agent_context_version_metadata() {
    assert_agent_context_schema_identity();
    assert_agent_context_schema_independence();
}

fn assert_agent_context_schema_identity() {
    assert_eq!(ORTHO_AGENT_CONTEXT_SCHEMA_VERSION, "1");
    assert_eq!(AGENT_CONTEXT_KIND_SUFFIX, "agent_context");
}

fn assert_agent_context_schema_independence() {
    assert!(
        AgentContext::new("example-cli")
            .kind
            .ends_with(AGENT_CONTEXT_KIND_SUFFIX)
    );
    assert_ne!(
        ORTHO_AGENT_CONTEXT_SCHEMA_VERSION, ORTHO_DOCS_IR_VERSION,
        "agent context must not share the documentation IR version"
    );
}

/// Asserts the complete legacy-compatible state produced by
/// [`AgentContext::new`].
pub(super) fn assert_legacy_default_context(context: &AgentContext) {
    assert_legacy_default_identity(context);
    assert_legacy_default_support_declarations(context);
    assert_legacy_default_policy_and_skills(context);
}

fn assert_legacy_default_identity(context: &AgentContext) {
    assert_eq!(context.schema_version, ORTHO_AGENT_CONTEXT_SCHEMA_VERSION);
    assert_eq!(context.kind, "example-cli.agent_context");
    assert_eq!(context.package, "example-cli");
}

fn assert_legacy_default_support_declarations(context: &AgentContext) {
    assert!(context.commands.is_empty());
    assert!(!context.profiles.supported);
    assert!(!context.feedback.supported);
}

fn assert_legacy_default_policy_and_skills(context: &AgentContext) {
    assert_eq!(context.policy.agent_native, PolicyMode::Warn);
    assert!(context.skill_manifests.is_empty());
}

/// Asserts the schema-v1 serialization contract for absent optional command,
/// input, and example fields.
pub(super) fn assert_optional_command_fields_are_null(value: &Value) {
    let serialized_command = first_array_item(field(value, "commands"));
    let input = first_array_item(field(serialized_command, "inputs"));
    let example = first_array_item(field(serialized_command, "examples"));

    assert_optional_command_presence_fields_are_null(serialized_command);
    assert_optional_command_route_fields_are_null(serialized_command);
    assert_optional_command_nested_fields_are_null(input, example);
}

fn assert_optional_command_presence_fields_are_null(serialized_command: &Value) {
    assert!(serialized_command.get("summary").is_none());
    assert!(field(serialized_command, "canonical_verb").is_null());
    assert!(field(serialized_command, "async_submission").is_null());
}

fn assert_optional_command_route_fields_are_null(serialized_command: &Value) {
    assert!(field(serialized_command, "delivery_route").is_null());
    assert!(field(serialized_command, "pagination").is_null());
}

fn assert_optional_command_nested_fields_are_null(input: &Value, example: &Value) {
    assert!(field(input, "default").is_null());
    assert!(field(example, "output_mode").is_null());
}

/// Asserts the schema-v1 defaults applied when legacy JSON omits optional
/// command and context metadata.
pub(super) fn assert_legacy_omission_defaults(context: &AgentContext, command: &AgentCommand) {
    assert_legacy_command_modes(command);
    assert_legacy_command_optional_metadata(command);
    assert_legacy_command_collections(command);
    assert_legacy_context_support_defaults(context);
    assert_legacy_context_policy_defaults(context);
}

fn assert_legacy_command_modes(command: &AgentCommand) {
    assert_eq!(command.interaction_mode, InteractionMode::Unknown);
    assert_eq!(command.mutation_effect, MutationEffect::Unknown);
}

fn assert_legacy_command_optional_metadata(command: &AgentCommand) {
    assert!(command.summary.is_none());
    assert!(command.async_submission.is_none());
    assert!(command.delivery_route.is_none());
}

fn assert_legacy_command_collections(command: &AgentCommand) {
    assert!(command.inputs.is_empty());
}

fn assert_legacy_context_support_defaults(context: &AgentContext) {
    assert!(!context.profiles.supported);
    assert!(!context.feedback.supported);
}

fn assert_legacy_context_policy_defaults(context: &AgentContext) {
    assert_eq!(context.policy.agent_native, PolicyMode::Warn);
    assert!(context.skill_manifests.is_empty());
}

/// Canonical pretty-printed schema-v1 JSON used by the wire-contract test.
pub(super) const AGENT_CONTEXT_WIRE_CONTRACT_JSON: &str =
    include_str!("fixtures/agent_context_wire_contract.json").trim_ascii_end();