Skip to content

validation

πŸ€– AI-Generated Content

This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.

flavor.psp.format_2025.validation

PSPF build validation helpers.

All validation functions are pure and return lists of error messages.

Classes

Functions

validate_build_options

validate_build_options(spec: BuildSpec) -> list[str]

Validate build options.

Checks that build options are consistent and valid.

Source code in flavor/psp/format_2025/validation.py
def validate_build_options(spec: BuildSpec) -> list[str]:
    """
    Validate build options.

    Checks that build options are consistent and valid.
    """
    errors = []
    options = spec.options

    # Check compression level
    if options.compression_level < 0 or options.compression_level > 9:
        errors.append(f"πŸ—œοΈ Compression level must be 0-9, got {options.compression_level}")

    # Check page alignment consistency
    if options.page_aligned and not options.enable_mmap:
        errors.append("⚠️ Page-aligned option should be used with memory mapping enabled")

    return errors

validate_complete

validate_complete(spec: BuildSpec) -> list[str]

Complete validation of build specification.

Runs all validation checks and returns combined errors.

Source code in flavor/psp/format_2025/validation.py
def validate_complete(spec: BuildSpec) -> list[str]:
    """
    Complete validation of build specification.

    Runs all validation checks and returns combined errors.
    """
    errors = []

    # Run all validations
    errors.extend(validate_spec(spec))
    errors.extend(validate_key_config(spec))
    errors.extend(validate_build_options(spec))

    return errors

validate_key_config

validate_key_config(spec: BuildSpec) -> list[str]

Validate key configuration.

Checks that key configuration is consistent and valid.

Source code in flavor/psp/format_2025/validation.py
def validate_key_config(spec: BuildSpec) -> list[str]:
    """
    Validate key configuration.

    Checks that key configuration is consistent and valid.
    """
    errors = []
    key_config = spec.keys

    # If explicit keys provided, both must be present
    if key_config.private_key or key_config.public_key:
        if not (key_config.private_key and key_config.public_key):
            errors.append("πŸ”‘ When providing explicit keys, both private and public keys are required")

        # Check key sizes (Ed25519 keys)
        if key_config.private_key and len(key_config.private_key) != 32:
            errors.append(f"πŸ”‘ Private key must be 32 bytes for Ed25519, got {len(key_config.private_key)}")
        if key_config.public_key and len(key_config.public_key) != 32:
            errors.append(f"πŸ”‘ Public key must be 32 bytes for Ed25519, got {len(key_config.public_key)}")

    # If key path provided, check it exists
    if key_config.key_path:
        if not key_config.key_path.exists():
            errors.append(f"πŸ”‘ Key path does not exist: {key_config.key_path}")
        elif not key_config.key_path.is_dir():
            errors.append(f"πŸ”‘ Key path must be a directory: {key_config.key_path}")

    return errors

validate_metadata

validate_metadata(metadata: dict[str, Any]) -> list[str]

Validate package metadata.

Ensures required fields are present and valid.

Source code in flavor/psp/format_2025/validation.py
def validate_metadata(metadata: dict[str, Any]) -> list[str]:
    """
    Validate package metadata.

    Ensures required fields are present and valid.
    """
    errors: list[str] = []

    # Check for package name (required)
    has_name, name = _extract_metadata_field(metadata, "name")
    if not has_name:
        errors.append("πŸ“› Package name is required but not found in metadata")
    elif not name or not str(name).strip():
        errors.append("πŸ“› Package name cannot be empty")

    # Validate version if present
    has_version, version = _extract_metadata_field(metadata, "version")
    if has_version and version and not str(version).strip():
        errors.append("🏷️ Package version cannot be empty if provided")

    # Validate format if specified
    if "format" in metadata:
        format_str = metadata["format"]
        if format_str not in ["PSPF/2025", "PSPF/2024"]:
            errors.append(f"πŸ“ Invalid format '{format_str}', expected 'PSPF/2025'")

    return errors

validate_slots

validate_slots(slots: list[SlotMetadata]) -> list[str]

Validate slot configurations.

Checks for: - Unique indices - Valid paths - Valid codec - Valid sizes - Valid names

Source code in flavor/psp/format_2025/validation.py
def validate_slots(slots: list[SlotMetadata]) -> list[str]:
    """
    Validate slot configurations.

    Checks for:
    - Unique indices
    - Valid paths
    - Valid codec
    - Valid sizes
    - Valid names
    """
    if not slots:
        return []

    errors: list[str] = []
    seen_indices: set[int] = set()
    seen_names: set[str] = set()

    for slot in slots:
        errors.extend(_validate_single_slot(slot, seen_indices, seen_names))

    return errors

validate_spec

validate_spec(spec: BuildSpec) -> list[str]

Validate a complete build specification.

Returns list of validation errors, empty if valid.

Source code in flavor/psp/format_2025/validation.py
def validate_spec(spec: BuildSpec) -> list[str]:
    """
    Validate a complete build specification.

    Returns list of validation errors, empty if valid.
    """
    errors = []

    # Validate metadata
    metadata_errors = validate_metadata(spec.metadata)
    errors.extend(metadata_errors)

    # Validate slots
    slot_errors = validate_slots(spec.slots)
    errors.extend(slot_errors)

    # Validate that we have at least something to package
    if not spec.slots and not spec.metadata.get("allow_empty", False):
        errors.append("πŸ“¦ Package must have at least one slot unless allow_empty is set")

    return errors