Liking cljdoc? Tell your friends :D

boundary.core.validation.coverage

Pure coverage computation and reporting for validation rules.

All functions are pure with no side effects. Data is injected via function parameters. File I/O belongs in test helpers or Kaocha plugins.

Example usage:

;; Compute coverage (def result (compute {:registered #{:user.email/required :user.name/required} :executed #{:user.email/required} :by-module {:user #{:user.email/required :user.name/required}}})) ;; => {:total 2 :executed 1 :pct 50.0 :per-module {...} :missing #{:user.name/required}}

;; Generate human-readable report (human-report result) ;; => "Coverage: 50.0% (1/2) Module: user - 50.0% (1/2) Missing: :user.name/required"

;; Generate EDN report for file export (edn-report result) ;; => {:coverage 50.0 :total 2 :executed 1 :timestamp "..." ...}

Pure coverage computation and reporting for validation rules.

All functions are pure with no side effects. Data is injected via function parameters.
File I/O belongs in test helpers or Kaocha plugins.

Example usage:

  ;; Compute coverage
  (def result (compute {:registered #{:user.email/required :user.name/required}
                       :executed #{:user.email/required}
                       :by-module {:user #{:user.email/required :user.name/required}}}))
  ;; => {:total 2 :executed 1 :pct 50.0 :per-module {...} :missing #{:user.name/required}}

  ;; Generate human-readable report
  (human-report result)
  ;; => "Coverage: 50.0% (1/2)
Module: user - 50.0% (1/2)
Missing: :user.name/required"

  ;; Generate EDN report for file export
  (edn-report result)
  ;; => {:coverage 50.0 :total 2 :executed 1 :timestamp "..." ...}
raw docstring

compare-coverageclj

(compare-coverage before after)

Compare two coverage results.

Args: before - Coverage map from earlier run after - Coverage map from later run

Returns: Comparison map: {:delta-pct float - Change in percentage :delta-executed int - Change in executed count :improved? bool - Whether coverage improved :new-rules set - Newly executed rules :lost-rules set - Previously executed but now missing}

Example: (compare-coverage {:total 10 :executed 8 :missing #{:rule1 :rule2}} {:total 10 :executed 9 :missing #{:rule1}}) ;; => {:delta-pct 10.0 :delta-executed 1 :improved? true ;; :new-rules #{:rule2} :lost-rules #{}}

Compare two coverage results.

Args:
  before - Coverage map from earlier run
  after  - Coverage map from later run

Returns:
  Comparison map:
  {:delta-pct float      - Change in percentage
   :delta-executed int   - Change in executed count
   :improved? bool       - Whether coverage improved
   :new-rules set        - Newly executed rules
   :lost-rules set       - Previously executed but now missing}

Example:
  (compare-coverage
    {:total 10 :executed 8 :missing #{:rule1 :rule2}}
    {:total 10 :executed 9 :missing #{:rule1}})
  ;; => {:delta-pct 10.0 :delta-executed 1 :improved? true
  ;;     :new-rules #{:rule2} :lost-rules #{}}
sourceraw docstring

computeclj

(compute {:keys [registered executed by-module] :or {by-module {}}})

Compute validation rule coverage statistics.

Pure function that computes coverage metrics from registered and executed rule sets.

Args: data - Map with: :registered - Set of all registered rule IDs :executed - Set of executed rule IDs :by-module - Map of {module-kw #{rule-ids...}} (optional)

Returns: Coverage map: {:total int - Total registered rules :executed int - Number of executed rules :pct float - Percentage (0-100) :per-module map - Per-module breakdown {module {:total n :executed n :pct float}} :missing set - Set of unexecuted rule IDs}

Example: (compute {:registered #{:user.email/required :user.name/required :billing.amount/positive} :executed #{:user.email/required} :by-module {:user #{:user.email/required :user.name/required} :billing #{:billing.amount/positive}}}) ;; => {:total 3 :executed 1 :pct 33.33 ;; :per-module {:user {:total 2 :executed 1 :pct 50.0} ;; :billing {:total 1 :executed 0 :pct 0.0}} ;; :missing #{:user.name/required :billing.amount/positive}}

Compute validation rule coverage statistics.

Pure function that computes coverage metrics from registered and executed rule sets.

Args:
  data - Map with:
         :registered - Set of all registered rule IDs
         :executed   - Set of executed rule IDs
         :by-module  - Map of {module-kw #{rule-ids...}} (optional)

Returns:
  Coverage map:
  {:total int       - Total registered rules
   :executed int    - Number of executed rules
   :pct float       - Percentage (0-100)
   :per-module map  - Per-module breakdown {module {:total n :executed n :pct float}}
   :missing set     - Set of unexecuted rule IDs}

Example:
  (compute {:registered #{:user.email/required :user.name/required :billing.amount/positive}
            :executed #{:user.email/required}
            :by-module {:user #{:user.email/required :user.name/required}
                       :billing #{:billing.amount/positive}}})
  ;; => {:total 3 :executed 1 :pct 33.33
  ;;     :per-module {:user {:total 2 :executed 1 :pct 50.0}
  ;;                  :billing {:total 1 :executed 0 :pct 0.0}}
  ;;     :missing #{:user.name/required :billing.amount/positive}}
sourceraw docstring

edn-reportclj

(edn-report coverage opts)

Generate EDN-serializable coverage report.

Args: coverage - Coverage map from compute opts - Options map: :timestamp - Timestamp string (optional) :metadata - Additional metadata (optional)

Returns: EDN-serializable map ready for writing to disk.

Example: (edn-report {:total 10 :executed 8 :pct 80.0 ...} {:timestamp "2025-01-04T13:47:21Z" :metadata {:run-id "test-1"}}) ;; => {:coverage 80.0 :total 10 :executed 8 :timestamp "..." :metadata {...}}

Generate EDN-serializable coverage report.

Args:
  coverage - Coverage map from compute
  opts     - Options map:
             :timestamp - Timestamp string (optional)
             :metadata  - Additional metadata (optional)

Returns:
  EDN-serializable map ready for writing to disk.

Example:
  (edn-report {:total 10 :executed 8 :pct 80.0 ...}
              {:timestamp "2025-01-04T13:47:21Z" :metadata {:run-id "test-1"}})
  ;; => {:coverage 80.0 :total 10 :executed 8 :timestamp "..." :metadata {...}}
sourceraw docstring

filter-by-moduleclj

(filter-by-module coverage modules)

Filter coverage data to specific modules.

Args: coverage - Coverage map from compute modules - Set or sequence of module keywords

Returns: Filtered coverage map.

Example: (filter-by-module coverage #{:user :billing}) ;; => Coverage map with only user and billing modules

Filter coverage data to specific modules.

Args:
  coverage - Coverage map from compute
  modules  - Set or sequence of module keywords

Returns:
  Filtered coverage map.

Example:
  (filter-by-module coverage #{:user :billing})
  ;; => Coverage map with only user and billing modules
sourceraw docstring

human-reportclj

(human-report coverage
              {:keys [show-missing show-modules]
               :or {show-missing true show-modules true}})

Generate human-readable coverage report.

Args: coverage - Coverage map from compute opts - Options map: :show-missing - Show missing rules (default true) :show-modules - Show per-module breakdown (default true)

Returns: Formatted string report.

Example: (human-report {:total 10 :executed 8 :pct 80.0 :per-module {:user {:total 5 :executed 4 :pct 80.0}} :missing #{:user.email/format}}) ;; => "Validation Coverage Report ;; ======================== ;; Overall: 80.0% (8/10) ;;
;; By Module: ;; user: 80.0% (4/5) ;;
;; Missing Rules: ;; :user.email/format"

Generate human-readable coverage report.

Args:
  coverage - Coverage map from compute
  opts     - Options map:
             :show-missing - Show missing rules (default true)
             :show-modules - Show per-module breakdown (default true)

Returns:
  Formatted string report.

Example:
  (human-report {:total 10 :executed 8 :pct 80.0
                 :per-module {:user {:total 5 :executed 4 :pct 80.0}}
                 :missing #{:user.email/format}})
  ;; => "Validation Coverage Report
  ;;     ========================
  ;;     Overall: 80.0% (8/10)
  ;;     
  ;;     By Module:
  ;;       user: 80.0% (4/5)
  ;;     
  ;;     Missing Rules:
  ;;       :user.email/format"
sourceraw docstring

merge-executionsclj

(merge-executions execution-sets)

Merge multiple execution sets deterministically.

Args: execution-sets - Sequence of sets containing executed rule IDs

Returns: Merged set of all executed rule IDs.

Example: (merge-executions [#{:user.email/required} #{:user.name/required}]) ;; => #{:user.email/required :user.name/required}

Merge multiple execution sets deterministically.

Args:
  execution-sets - Sequence of sets containing executed rule IDs

Returns:
  Merged set of all executed rule IDs.

Example:
  (merge-executions [#{:user.email/required} #{:user.name/required}])
  ;; => #{:user.email/required :user.name/required}
sourceraw docstring

summary-lineclj

(summary-line coverage)

Generate a single-line coverage summary.

Args: coverage - Coverage map from compute

Returns: Single-line string summary.

Example: (summary-line {:total 10 :executed 8 :pct 80.0}) ;; => "Coverage: 80.0% (8/10 rules executed)"

Generate a single-line coverage summary.

Args:
  coverage - Coverage map from compute

Returns:
  Single-line string summary.

Example:
  (summary-line {:total 10 :executed 8 :pct 80.0})
  ;; => "Coverage: 80.0% (8/10 rules executed)"
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close