wasm-capability-contract 0.3.0

Generic, domain-agnostic capability pattern: CapabilityEngine/CapabilityRegistry/CapabilityDispatcher trait shapes + component/capability types. Trait definitions only -- see wasm-capability-core for this pattern's own default implementation, extracted from agent-runtime's ADR-001 (agent-runtime#31, ADR-011).
Documentation
//! Real-implementation tests for `ValidateComponentRequest`.

use wasm_capability_contract::{
    ArtifactProvenance, ComponentManifest, ResourceLimits, ValidateComponentRequest,
};

fn sample() -> ValidateComponentRequest {
    ValidateComponentRequest {
        manifest: ComponentManifest {
            component_id: "echo".to_string(),
            route_id: "/echo".to_string(),
            contract_version: "swe:edge-handler@0.2.0".to_string(),
            handler_export: "echo".to_string(),
            resource_limits: ResourceLimits {
                max_memory_bytes: 1024,
                invoke_timeout_ms: 1000,
                max_concurrency: 1,
                max_payload_bytes: 1024,
            },
            capabilities: vec![],
            artifact_provenance: ArtifactProvenance {
                source: "test".to_string(),
                checksum_sha256: "a".repeat(64),
                built_at: "2026-08-30T00:00:00Z".to_string(),
            },
        },
        component_bytes: vec![1, 2, 3],
        granted_capabilities: vec![],
    }
}

/// @covers: ValidateComponentRequest
/// Fields must be accessible exactly as constructed — proves
/// construction and field access aren't silently lossy.
#[test]
fn test_validate_component_request_fields_are_accessible_as_constructed() {
    let req = sample();
    assert_eq!(req.manifest.component_id, "echo");
    assert_eq!(req.component_bytes, vec![1, 2, 3]);
    assert!(req.granted_capabilities.is_empty());
}

/// @covers: ValidateComponentRequest
/// A round-trip through JSON must preserve every field, including the
/// nested manifest and grant list — not just the outer struct shape.
///
/// Checks the nested manifest's own fields explicitly rather than only
/// `assert_eq!(restored, original)`: `ComponentManifest`'s `PartialEq` is
/// identity-based (`component_id` only), so the outer struct comparison
/// alone would no longer prove the manifest's other fields survived.
#[test]
fn test_validate_component_request_json_round_trip_preserves_every_field() {
    let original = sample();
    let json =
        serde_json::to_string(&original).unwrap_or_else(|e| panic!("serialize must succeed: {e}"));
    let restored: ValidateComponentRequest =
        serde_json::from_str(&json).unwrap_or_else(|e| panic!("deserialize must succeed: {e}"));
    assert_eq!(restored, original);
    assert_eq!(restored.manifest.route_id, original.manifest.route_id);
    assert_eq!(
        restored.manifest.contract_version,
        original.manifest.contract_version
    );
    assert_eq!(
        restored.manifest.handler_export,
        original.manifest.handler_export
    );
    assert_eq!(
        restored.manifest.resource_limits,
        original.manifest.resource_limits
    );
    assert_eq!(
        restored.manifest.capabilities,
        original.manifest.capabilities
    );
    assert_eq!(
        restored.manifest.artifact_provenance,
        original.manifest.artifact_provenance
    );
}