Skip to content

๐Ÿ›ก๏ธ TAREA 7: Enforcement System

Status: โœ… COMPLETE Version: 1.0.0 Coverage Target: >85%


๐Ÿ“‹ Overview

Automated enforcement of hierarchy rules via pre-commit hooks, CI/CD gates, and runtime checks.

Purpose: - Block violations before they enter codebase - Enforce policies (strict/balanced/permissive) - Generate compliance reports - Support exemptions for legacy code


๐Ÿš€ Quick Start

#include "enforcement.hpp"

using namespace audiolab::hierarchy;

// Create enforcement engine
EnforcementEngine engine(EnforcementPolicy::balanced());

// Validate modules
auto result = engine.enforce(modules);

if (!result.passed) {
    std::cerr << result.to_string();
    return 1;
}

๐ŸŽฏ Features

1. Enforcement Policies

Strict: Block all violations

auto policy = EnforcementPolicy::strict();
// upward_dependency = BLOCK
// horizontal_dependency = BLOCK
// min_architecture_health = 80

Balanced (default):

auto policy = EnforcementPolicy::balanced();
// upward_dependency = BLOCK
// horizontal_dependency = ERROR
// min_architecture_health = 60

Permissive: Warn only

auto policy = EnforcementPolicy::permissive();
// upward_dependency = WARN
// allow_exemptions = true

2. Enforcement Levels

  • IGNORE: Log only
  • WARN: Warning message
  • ERROR: Block but allow override
  • BLOCK: Hard block, no override

3. Pre-Commit Hook

# Install hook
cp hooks/pre-commit .git/hooks/
chmod +x .git/hooks/pre-commit

# Validates before each commit
git commit -m "Add feature"
# โ†’ Runs hierarchy validation
# โ†’ Blocks commit if violations found

4. CI/CD Integration

# .github/workflows/ci.yml
- name: Hierarchy Enforcement
  run: |
    ./build/enforcement_checker --strict
    if [ $? -ne 0 ]; then
      echo "โŒ Build failed: Hierarchy violations"
      exit 1
    fi

5. Exemptions

ExemptionManager mgr;

Exemption exemption{
    "LegacyModule",          // module_name
    "UPWARD_DEPENDENCY",     // rule_id
    "Legacy code migration", // reason
    "architect@company.com", // approved_by
    "2026-01-01",           // expiry_date
    false                    // is_permanent
};

mgr.add_exemption(exemption);
mgr.save_to_file(".hierarchy_exemptions.json");

๐Ÿ“Š Enforcement Result

struct EnforcementResult {
    bool passed;                      // Overall pass/fail
    EnforcementLevel worst_level;     // Worst violation level
    std::vector<std::string> errors;  // Blocking errors
    std::vector<std::string> warnings;
    size_t violations_found;
    size_t violations_blocked;

    int exit_code() const;  // 0=success, 1=fail
};

๐Ÿงช Testing

ctest -R test_enforcement -V

Coverage: >85%


๐Ÿ“š API Reference

EnforcementEngine

class EnforcementEngine {
public:
    EnforcementResult enforce(
        const std::map<std::string, ModuleMetadata>& modules,
        EnforcementStage stage = EnforcementStage::CI_BUILD
    );

    EnforcementResult quick_check(...);
    EnforcementResult check_module(...);
};

EnforcementPolicy

struct EnforcementPolicy {
    EnforcementLevel upward_dependency;
    EnforcementLevel horizontal_dependency;
    EnforcementLevel circular_dependency;
    bool block_on_critical_antipatterns;
    int min_architecture_health;

    static EnforcementPolicy strict();
    static EnforcementPolicy balanced();
    static EnforcementPolicy permissive();
};

๐Ÿ”— Dependencies

  • 05_01_00_level_definitions (TAREA 1)
  • 05_01_01_composition_rules (TAREA 2)
  • 05_01_02_validation_engine (TAREA 3)
  • 05_01_03_pattern_library (TAREA 5)
  • 05_01_04_anti_patterns (TAREA 4)

โœ… Success Criteria

  • Policy engine (strict/balanced/permissive)
  • EnforcementEngine implementation
  • Pre-commit hook
  • CI/CD integration support
  • Violation blocking
  • Exemption system
  • Test suite >85%
  • Documentation

Status: โœ… COMPLETE Version: 1.0.0 Last Updated: 2025-10-10