# Layering contracts for mgf-vm — enforces the dependency direction.
#
# Run locally:  lint-imports
# Run in CI:    see .woodpecker.yml
#
# Every contract is a hard MUST NOT — import-linter fails CI on any
# violation. When relaxing a rule, document why in a `reason` comment.

[importlinter]
root_packages =
    mgf.vm
# Required because the libvirt-isolation contract names `libvirt`
# (an external package) as forbidden.
include_external_packages = True

# ---------------------------------------------------------------------------
# Contract 1 — libvirt isolation (DP-02).
#
# The single most important invariant: no module outside
# `mgf.vm.providers.libvirt_provider` imports the libvirt binding.
# Breaking this drags the daemon dependency into the test suite and
# makes MockProvider useless.
# ---------------------------------------------------------------------------

[importlinter:contract:libvirt-isolation]
name = libvirt is only imported from providers.libvirt_provider
type = forbidden
source_modules =
    mgf.vm
forbidden_modules =
    libvirt
# LibvirtProvider.__init__ imports libvirt lazily so the module still
# IMPORTS on a host without python3-libvirt. The explicit allow keeps
# the contract intent ("nowhere ELSE imports libvirt") enforceable.
ignore_imports =
    mgf.vm.providers.libvirt_provider -> libvirt

# ---------------------------------------------------------------------------
# Contract 2 — exceptions and domain are leaves.
#
# `mgf.vm.exceptions` is the typed hierarchy every other module imports;
# `mgf.vm.domain` carries the lingua-franca types. Both MUST NOT import
# sibling mgf.vm modules or cycles become unavoidable. (`domain` may
# import `exceptions`; the reverse is forbidden.)
# ---------------------------------------------------------------------------

[importlinter:contract:exceptions-is-a-leaf]
name = exceptions does not import any other mgf.vm module
type = forbidden
source_modules =
    mgf.vm.exceptions
forbidden_modules =
    mgf.vm.common
    mgf.vm.configurator
    mgf.vm.creator
    mgf.vm.domain
    mgf.vm.environment
    mgf.vm.forensics
    mgf.vm.hooks
    mgf.vm.image
    mgf.vm.installer
    mgf.vm.interchange
    mgf.vm.lab
    mgf.vm.lifecycle
    mgf.vm.monitor
    mgf.vm.network
    mgf.vm.operations
    mgf.vm.profiles
    mgf.vm.providers
    mgf.vm.provisioning
    mgf.vm.scheduler
    mgf.vm.security
    mgf.vm.storage
    mgf.vm.vault
