Skip to content

test: expand test coverage for telemetry, multi-generation history. - #534

Open
Agbelomo wants to merge 1 commit into
ApexChainx:mainfrom
Agbelomo:issues-507-508-509-510
Open

test: expand test coverage for telemetry, multi-generation history.#534
Agbelomo wants to merge 1 commit into
ApexChainx:mainfrom
Agbelomo:issues-507-508-509-510

Conversation

@Agbelomo

Copy link
Copy Markdown

Refactor get_full_audit_state single-pass storage access, decouple telemetry resets, support multi-generation outage history, and validate prune_history_by_age

Closes #507
Closes #508
Closes #509
Closes #510

Summary

This PR addresses four technical debt items in the apexchainx_calculator contract across storage access efficiency, telemetry counter reset logic, outage history query semantics, and age-based retention pruning validation:

  1. get_full_audit_state performs about ten redundant version checks and re-reads the same instance storage per delegated getter #507 - Single-Pass Storage Access for get_full_audit_state: Refactored get_full_audit_state in apexchainx_calculator/src/lib.rs to execute a single check_version(&env) check and read storage keys (ADMIN_KEY, OPERATOR_KEY, PENDING_ADMIN_KEY, PENDING_OP_KEY, PAUSED_KEY, PAUSE_INFO_KEY, STATS_KEY, HISTORY_KEY) directly in one pass. Optimized get_config_snapshot and build_config_snapshot to read CONFIG_KEY once.
  2. The telemetry weekly reset wipes fresh violations: calc_stale OR violation_stale resets both lanes, losing a violation recorded a day ago #508 - Decoupled Telemetry Resets: Decoupled calc_stale and violation_stale counter reset logic in record_severity_telemetry (calculation.rs & lib.rs). Each lane counter is now evaluated and reset independently, ensuring fresh violation data survives stale calculation resets (and vice versa).
  3. get_history_by_outage returns entries across config generations with no distinguishing signal: consumers cannot isolate the current decision #509 - Multi-Generation Outage History: Documented and verified get_history_by_outage ordering (oldest-first, latest decision last). Each entry carries its config_version_hash, enabling consumers to distinguish entries across configuration generations.
  4. prune_history_by_age silently no-ops for min_age_seconds >= now: the cutoff saturates to 0 and no event fires, so callers cannot tell nothing was pruned #510 - prune_history_by_age Range Validation: Added explicit range validation to prune_history_by_age in history.rs and lib.rs. Invocations with min_age_seconds >= current_ledger_timestamp are rejected with Err(SLAError::InvalidInput) to prevent silent no-ops.

Changes Made

  • apexchainx_calculator/src/lib.rs: Single-pass get_full_audit_state, optimized build_config_snapshot, decoupled telemetry reset, min_age_seconds validation, updated docstrings.
  • apexchainx_calculator/src/calculation.rs: Decoupled calc_stale and violation_stale reset logic in record_severity_telemetry.
  • apexchainx_calculator/src/history.rs: Added min_age_seconds >= now validation returning Err(SLAError::InvalidInput), updated get_history_by_outage docstring.
  • apexchainx_calculator/src/tests.rs: Added unit tests test_get_full_audit_state_single_pass_efficiency, test_record_severity_telemetry_decoupled_lane_resets, test_get_history_by_outage_multi_generation_history, test_prune_by_age_rejects_min_age_equal_to_now, and test_prune_by_age_rejects_min_age_greater_than_now.

Verification

  • cargo check --tests: PASSED
  • cargo test: PASSED (all 594 test cases passing)

…nd history pruning, and remove parity baseline file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment